move tests to testament (#16101)
* move tests to testament * minor * fix random * disable test random
This commit is contained in:
parent
d306a04466
commit
cbc793b30b
56 changed files with 2205 additions and 2232 deletions
|
|
@ -1,34 +1,71 @@
|
|||
import hashes
|
||||
|
||||
discard """
|
||||
output: '''
|
||||
[Suite] hashes
|
||||
block hashes:
|
||||
block hashing:
|
||||
var dummy = 0.0
|
||||
doAssert hash(dummy) == hash(-dummy)
|
||||
|
||||
[Suite] hashing
|
||||
# "VM and runtime should make the same hash value (hashIdentity)"
|
||||
block:
|
||||
const hi123 = hashIdentity(123)
|
||||
doAssert hashIdentity(123) == hi123
|
||||
|
||||
'''
|
||||
"""
|
||||
# "VM and runtime should make the same hash value (hashWangYi1)"
|
||||
block:
|
||||
const wy123 = hashWangYi1(123)
|
||||
doAssert hashWangYi1(123) == wy123
|
||||
|
||||
import unittest, hashes
|
||||
# "hashIdentity value incorrect at 456"
|
||||
block:
|
||||
doAssert hashIdentity(456) == 456
|
||||
|
||||
suite "hashes":
|
||||
suite "hashing":
|
||||
test "0.0 and -0.0 should have the same hash value":
|
||||
var dummy = 0.0
|
||||
check hash(dummy) == hash(-dummy)
|
||||
# "hashWangYi1 value incorrect at 456"
|
||||
block:
|
||||
when Hash.sizeof < 8:
|
||||
doAssert hashWangYi1(456) == 1293320666
|
||||
else:
|
||||
doAssert hashWangYi1(456) == -6421749900419628582
|
||||
|
||||
test "VM and runtime should make the same hash value (hashIdentity)":
|
||||
const hi123 = hashIdentity(123)
|
||||
check hashIdentity(123) == hi123
|
||||
block empty:
|
||||
var
|
||||
a = ""
|
||||
b = newSeq[char]()
|
||||
c = newSeq[int]()
|
||||
d = cstring""
|
||||
e = "abcd"
|
||||
doAssert hash(a) == 0
|
||||
doAssert hash(b) == 0
|
||||
doAssert hash(c) == 0
|
||||
doAssert hash(d) == 0
|
||||
doAssert hashIgnoreCase(a) == 0
|
||||
doAssert hashIgnoreStyle(a) == 0
|
||||
doAssert hash(e, 3, 2) == 0
|
||||
|
||||
test "VM and runtime should make the same hash value (hashWangYi1)":
|
||||
const wy123 = hashWangYi1(123)
|
||||
check hashWangYi1(123) == wy123
|
||||
block sameButDifferent:
|
||||
doAssert hash("aa bb aaaa1234") == hash("aa bb aaaa1234", 0, 13)
|
||||
doAssert hash("aa bb aaaa1234") == hash(cstring"aa bb aaaa1234")
|
||||
doAssert hashIgnoreCase("aA bb aAAa1234") == hashIgnoreCase("aa bb aaaa1234")
|
||||
doAssert hashIgnoreStyle("aa_bb_AAaa1234") == hashIgnoreCase("aaBBAAAa1234")
|
||||
|
||||
test "hashIdentity value incorrect at 456":
|
||||
check hashIdentity(456) == 456
|
||||
block smallSize: # no multibyte hashing
|
||||
let
|
||||
xx = @['H', 'i']
|
||||
ii = @[72'u8, 105]
|
||||
ss = "Hi"
|
||||
doAssert hash(xx) == hash(ii)
|
||||
doAssert hash(xx) == hash(ss)
|
||||
doAssert hash(xx) == hash(xx, 0, xx.high)
|
||||
doAssert hash(ss) == hash(ss, 0, ss.high)
|
||||
|
||||
test "hashWangYi1 value incorrect at 456":
|
||||
when Hash.sizeof < 8:
|
||||
check hashWangYi1(456) == 1293320666
|
||||
else:
|
||||
check hashWangYi1(456) == -6421749900419628582
|
||||
block largeSize: # longer than 4 characters
|
||||
let
|
||||
xx = @['H', 'e', 'l', 'l', 'o']
|
||||
xxl = @['H', 'e', 'l', 'l', 'o', 'w', 'e', 'e', 'n', 's']
|
||||
ssl = "Helloweens"
|
||||
doAssert hash(xxl) == hash(ssl)
|
||||
doAssert hash(xxl) == hash(xxl, 0, xxl.high)
|
||||
doAssert hash(ssl) == hash(ssl, 0, ssl.high)
|
||||
doAssert hash(xx) == hash(xxl, 0, 4)
|
||||
doAssert hash(xx) == hash(ssl, 0, 4)
|
||||
doAssert hash(xx, 0, 3) == hash(xxl, 0, 3)
|
||||
doAssert hash(xx, 0, 3) == hash(ssl, 0, 3)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue