summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLucas Gabriel Vuotto <lvuotto92@gmail.com>2017-09-08 01:19:40 -0300
committerOri Bernstein <ori@mmarkovcorp.com>2017-09-08 11:00:40 -0700
commit1ee90265d5f764cb54b49531c4b247c5f404491c (patch)
tree4e17b4d6f09b3c97a598d0b06687e29eef58e051 /lib
parent13a8561e53b259ab1bd6592df857b7a59b7a2a2b (diff)
downloadmc-1ee90265d5f764cb54b49531c4b247c5f404491c.tar.gz
Use testr in lib/std/test/hashfuncs.myr
Signed-off-by: Lucas Gabriel Vuotto <lvuotto92@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/std/test/hashfuncs.myr46
1 files changed, 27 insertions, 19 deletions
diff --git a/lib/std/test/hashfuncs.myr b/lib/std/test/hashfuncs.myr
index d2b1161..5322c8e 100644
--- a/lib/std/test/hashfuncs.myr
+++ b/lib/std/test/hashfuncs.myr
@@ -1,24 +1,32 @@
use std
+use testr
const main = {
- var x, y: int
-
- std.assert(std.strhash("abc") == 1241861192, "wrong hash\n")
- std.assert(std.streq("abc\0def", "abc\0def"), "equal strings not equal\n")
- std.assert(!std.streq("abc\0def", "abcdef"), "unstrings are equal\n")
-
- std.assert(std.strcasehash("abc") == std.strcasehash("AbC"), "wrong case insensitive hash\n")
- std.assert(std.strcaseeq("abc", "AbC"), "equal case insensitive strings not equal")
- std.assert(!std.strcaseeq("abc", "AbCd"), "unequal case insensitive strings equal")
-
- /* can't sanely test ptrhash; it will change every time */
- std.assert(std.ptreq(&x, &x), "equal pointers not equal")
- std.assert(!std.ptreq(&x, &y), "unequal pointers are equal")
-
- std.assert(std.inthash(123) == 3497506805, "wrong int hash")
- std.assert(std.inteq(123, 123), "equal integers not equal")
- std.assert(!std.inteq(123, 456), "unequal integers are equal")
-
- std.assert(std.murmurhash2("foobar", 1234) == 2203212445, "wrong murmurhash value")
+ testr.run([
+ [.name="string hash and equality", .fn={ctx
+ testr.check(ctx, std.strhash("abc") == 1241861192, "wrong hash\n")
+ testr.check(ctx, std.streq("abc\0def", "abc\0def"), "equal strings not equal\n")
+ testr.check(ctx, !std.streq("abc\0def", "abcdef"), "unequal strings are equal\n")
+ }],
+ [.name="case insensitive hash and equality", .fn={ctx
+ testr.check(ctx, std.strcasehash("abc") == std.strcasehash("AbC"), "wrong case insensitive hash\n")
+ testr.check(ctx, std.strcaseeq("abc", "AbC"), "equal case insensitive strings not equal")
+ testr.check(ctx, !std.strcaseeq("abc", "AbCd"), "unequal case insensitive strings equal")
+ }],
+ [.name="pointer equality", .fn={ctx
+ var x, y: int
+ /* can't sanely test ptrhash; it will change every time */
+ testr.check(ctx, std.ptreq(&x, &x), "equal pointers not equal")
+ testr.check(ctx, !std.ptreq(&x, &y), "unequal pointers are equal")
+ }],
+ [.name="int hash and equality", .fn={ctx
+ testr.check(ctx, std.inthash(123) == 3497506805, "wrong int hash")
+ testr.check(ctx, std.inteq(123, 123), "equal integers not equal")
+ testr.check(ctx, !std.inteq(123, 456), "unequal integers are equal")
+ }],
+ [.name="murmurhash test", .fn={ctx
+ testr.check(ctx, std.murmurhash2("foobar", 1234) == 2203212445, "wrong murmurhash value")
+ }],
+ ][:])
}