Add tests for equals, hashCode, toString in String and Number

This commit is contained in:
Zalim Bashorov
2020-01-14 22:03:33 +03:00
parent 8e788e2169
commit c8efe8c4ec
8 changed files with 90 additions and 0 deletions
@@ -0,0 +1,17 @@
fun test(n: Number) {
if (!n.equals(n)) throw Error("fail 1 for $n")
if (n.equals(1)) throw Error("fail 2 for $n")
if (n.equals(1L)) throw Error("fail 3 for $n")
if (n != n) throw Error("fail 4 for $n")
if (n == 1) throw Error("fail 5 for $n")
if (n == 1L) throw Error("fail 6 for $n")
if (n.hashCode() != n.toInt()) throw Error("fail 7 for $n")
if (n.toString() != "$n") throw Error("fail 8 for $n")
}
fun box(): String {
test(234)
test(546L)
return "OK"
}
@@ -0,0 +1,13 @@
fun test(s: String) {
if (!s.equals(s)) throw Error("fail 1 for $s")
if (s.equals(1)) throw Error("fail 2 for $s")
if (s != s) throw Error("fail 4 for $s")
if (s == "111") throw Error("fail 5 for $s")
if (s.hashCode() != -1268878963) throw Error("fail 7 for $s")
if (s.toString() != "$s") throw Error("fail 8 for $s")
}
fun box(): String {
test("foobar")
return "OK"
}