summaryrefslogtreecommitdiff
path: root/lib/std/test
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-11-02 10:52:42 -0700
committerOri Bernstein <ori@markovcorp.com>2017-11-14 13:50:39 -0800
commit5d40b4ead1f20776f23bed271412af829bbe0e96 (patch)
treebfeb9d8ef26b8415ee543d75a4c1ba38c3f76f37 /lib/std/test
parent83d26331a5419033927800760e8a59f1bd84d2b9 (diff)
downloadmc-5d40b4ead1f20776f23bed271412af829bbe0e96.tar.gz
Fix tests to use new hashable/comparable traits.
Diffstat (limited to 'lib/std/test')
-rw-r--r--lib/std/test/bitset.myr6
-rw-r--r--lib/std/test/hashfuncs.myr24
-rw-r--r--lib/std/test/htab.myr48
-rw-r--r--lib/std/test/striter.myr2
4 files changed, 39 insertions, 41 deletions
diff --git a/lib/std/test/bitset.myr b/lib/std/test/bitset.myr
index 6936cba..31e2cdc 100644
--- a/lib/std/test/bitset.myr
+++ b/lib/std/test/bitset.myr
@@ -49,11 +49,11 @@ const main = {
}],
[.name="hash", .fn={ctx
var bs = mkset([][:])
- testr.check(ctx, std.bshash(bs) == 0x726fdb47dd0e0e31, "wrong hash, got {}", std.bshash(bs))
+ testr.check(ctx, std.hash(bs) == 0x726fdb47dd0e0e31, "wrong hash, got {}", std.hash(bs))
std.bsput(bs, 123456)
- testr.check(ctx, std.bshash(bs) == 0x778abc1d7706143b, "wrong hash, got {}", std.bshash(bs))
+ testr.check(ctx, std.hash(bs) == 0x778abc1d7706143b, "wrong hash, got {}", std.hash(bs))
std.bsdel(bs, 123456)
- testr.check(ctx, std.bshash(bs) == 0x726fdb47dd0e0e31, "wrong hash, got {}", std.bshash(bs))
+ testr.check(ctx, std.hash(bs) == 0x726fdb47dd0e0e31, "wrong hash, got {}", std.hash(bs))
std.bsfree(bs)
}]
][:])
diff --git a/lib/std/test/hashfuncs.myr b/lib/std/test/hashfuncs.myr
index f1684f9..5813663 100644
--- a/lib/std/test/hashfuncs.myr
+++ b/lib/std/test/hashfuncs.myr
@@ -4,28 +4,20 @@ use testr
const main = {
testr.run([
[.name="string hash and equality", .fn={ctx
- testr.check(ctx, std.strhash("abc") == 0x5dbcfa53aa2007a5, "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")
+ testr.check(ctx, std.hash("abc") == 0x5dbcfa53aa2007a5, "wrong hash\n")
+ testr.check(ctx, std.cmp("abc\0def", "abc\0def"), "equal strings not equal\n")
+ testr.check(ctx, !std.cmp("abc\0def", "abcdef"), "unequal strings are equal\n")
}],
[.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")
+ testr.check(ctx, std.cmp(&x, &x), "equal pointers not equal")
+ testr.check(ctx, !std.cmp(&x, &y), "unequal pointers are equal")
}],
[.name="int hash and equality", .fn={ctx
- testr.check(ctx, std.inthash(123) == 0x5671db246859d5b6, "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")
+ testr.check(ctx, std.hash(123) == 0x5671db246859d5b6, "wrong int hash")
+ testr.check(ctx, std.cmp(123, 123), "equal integers not equal")
+ testr.check(ctx, !std.cmp(123, 456), "unequal integers are equal")
}],
[.name="siphash test", .fn={ctx
siphashreferencetestvector(ctx)
diff --git a/lib/std/test/htab.myr b/lib/std/test/htab.myr
index 1801d76..b2612c4 100644
--- a/lib/std/test/htab.myr
+++ b/lib/std/test/htab.myr
@@ -28,22 +28,22 @@ const deletion = {
var ht
var i
- ht = std.mkht(idhash, ideq)
+ ht = std.mkht()
/* create a hash table with a few hundred values */
for i = 0; i < 4000; i++
- std.htput(ht, i, i)
+ std.htput(ht, (i : collisionprone), (i : collisionprone))
;;
for i = 0; i < 200; i++
- std.htdel(ht, i*2)
+ std.htdel(ht, (i*2 : collisionprone))
;;
for i = 0; i < 200; i++
- std.assert(!std.hthas(ht, i*2), "deleted item still present")
+ std.assert(!std.hthas(ht, (i*2 : collisionprone)), "deleted item still present")
;;
for i = 0; i < 200; i++
- std.assert(std.hthas(ht, i*2+1), "undeleted item missing")
+ std.assert(std.hthas(ht, (i*2+1 : collisionprone)), "undeleted item missing")
;;
for i = 400; i < 4000; i++
- std.assert(std.hthas(ht, i), "undeleted item missing")
+ std.assert(std.hthas(ht, (i : collisionprone)), "undeleted item missing")
;;
}
@@ -52,34 +52,34 @@ const collision = {
var ht
var i
- ht = std.mkht(idhash, ideq)
+ ht = std.mkht()
/* insert an element a few hundred times */
for i = 0; i < 500; i++
- std.htput(ht, 0, i)
+ std.htput(ht, 0, (i : collisionprone))
;;
- std.assert(std.hthas(ht, 0), "inserted element not present")
- std.assert(std.htgetv(ht, 0, -1) == 499, "inserted element has wrong value")
+ std.assert(std.hthas(ht, (0 : collisionprone)), "inserted element not present")
+ std.assert(std.htgetv(ht, (0 : collisionprone), -1) == 499, "inserted element has wrong value")
std.htdel(ht, 0)
- std.assert(!std.hthas(ht, 0), "element left in table")
+ std.assert(!std.hthas(ht, (0 : collisionprone)), "element left in table")
}
const tombstonefill = {
var ht
var i
- ht = std.mkht(idhash, ideq)
+ ht = std.mkht()
/*
insert an element into each slot in the hash table, and
delete it. With direct hashing, this is guaranteed to have
put a tombstone into each slot.
*/
for i = 0; i <= ht.keys.len; i++
- std.htput(ht, i, i)
- std.htdel(ht, i)
+ std.htput(ht, (i : collisionprone), i)
+ std.htdel(ht, (i : collisionprone))
;;
/* make sure we haven't actually got anything in the table */
std.assert(ht.nelt == 0, "elements left in hash table")
- std.assert(!std.hthas(ht, 1), "found phantom element")
+ std.assert(!std.hthas(ht, (1 : collisionprone)), "found phantom element")
}
const main = {
@@ -95,10 +95,16 @@ const main = {
tombstonefill()
}
-const idhash = {x
- -> x
-}
+type collisionprone = int
-const ideq = {a, b
- -> a == b
-}
+impl std.hashable collisionprone =
+ hash = {x
+ -> (x : uint64)
+ }
+;;
+
+impl std.comparable collisionprone =
+ cmp = {a, b
+ -> a == b
+ }
+;;
diff --git a/lib/std/test/striter.myr b/lib/std/test/striter.myr
index 90b38ed..8a4397e 100644
--- a/lib/std/test/striter.myr
+++ b/lib/std/test/striter.myr
@@ -13,7 +13,7 @@ const main = {
i = 0
for sp : std.bysplit("foo+++bar", "++")
- std.assert(std.streq(splits[i++], sp), "wrong split {}", sp)
+ std.assert(std.cmp(splits[i++], sp), "wrong split {}", sp)
;;
std.assert(i == splits.len, "wrong split count")
}