uCBQN/test/hash.bqn
2022-08-05 03:08:39 +03:00

26 lines
865 B
BQN
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# note: tests only bit/i8/i16/i32 arrays; no f64/c8/c16/c32/generic array tests
u 100×(•UnixTime+1|100וMonoTime)@
R (•MakeRand •Show u).Range
M (232)×+´
Test { 𝕊:
width 181632˜R 4
count 1+R (width=1)32256
data (width×count) R 2
n 1+R count
cast {width=1? ; 1width'i' •bit._cast}
iota data
shifts 1+count-n
exp >(-shifts)(width/)¨<n>count
got >1¨¨<˘>{
a Cast data𝕩iota
shifts (M•Hash n)¨ <a
}¨¯1iota
+´¨ exp(><)got
}
fails 00
{𝕊: fails+ Test@}¨1000
•Out "Collisions: " •Repr 0fails " (expected 0, assuming no actual hash collisions)"
•Out "Mismatches: " •Repr 1fails " (expected 0)"