Skip to content

Commit d9b44e8

Browse files
committed
fix tests
1 parent c4999a7 commit d9b44e8

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

lib/pure/collections/sets.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,9 +1019,9 @@ when isMainModule and not defined(release):
10191019
# --> {1, 3, 5}
10201020

10211021
block toSeqAndString:
1022-
var a = toHashSet([2, 4, 5])
1022+
var a = toHashSet([2, 7, 5])
10231023
var b = initHashSet[int]()
1024-
for x in [2, 4, 5]: b.incl(x)
1024+
for x in [2, 7, 5]: b.incl(x)
10251025
assert($a == $b)
10261026
#echo a
10271027
#echo toHashSet(["no", "esc'aping", "is \" provided"])

lib/pure/hashes.nim

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,31 +113,31 @@ proc hash*[T: proc](x: T): Hash {.inline.} =
113113
result = hash(pointer(x))
114114

115115
const
116-
prime = 31
116+
prime = uint(11)
117117

118118
proc hash*(x: int): Hash {.inline.} =
119119
## Efficient hashing of integers.
120-
result = x * prime
120+
result = cast[Hash](cast[uint](x) * prime)
121121

122122
proc hash*(x: int64): Hash {.inline.} =
123123
## Efficient hashing of `int64` integers.
124-
result = cast[int](x) * prime
124+
result = cast[Hash](cast[uint](x) * prime)
125125

126126
proc hash*(x: uint): Hash {.inline.} =
127127
## Efficient hashing of unsigned integers.
128-
result = cast[int](x) * prime
128+
result = cast[Hash](x * prime)
129129

130130
proc hash*(x: uint64): Hash {.inline.} =
131131
## Efficient hashing of `uint64` integers.
132-
result = cast[int](x) * prime
132+
result = cast[Hash](cast[uint](x) * prime)
133133

134134
proc hash*(x: char): Hash {.inline.} =
135135
## Efficient hashing of characters.
136-
result = ord(x) * prime
136+
result = cast[Hash](cast[uint](ord(x)) * prime)
137137

138138
proc hash*[T: Ordinal](x: T): Hash {.inline.} =
139139
## Efficient hashing of other ordinal types (e.g. enums).
140-
result = ord(x) * prime
140+
result = cast[Hash](cast[uint](ord(x)) * prime)
141141

142142
proc hash*(x: float): Hash {.inline.} =
143143
## Efficient hashing of floats.

tests/collections/ttables.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ block tablesref:
233233
for y in 0..1:
234234
assert t[(x,y)] == $x & $y
235235
assert($t ==
236-
"{(x: 0, y: 1): \"01\", (x: 0, y: 0): \"00\", (x: 1, y: 0): \"10\", (x: 1, y: 1): \"11\"}")
236+
"{(x: 1, y: 1): \"11\", (x: 0, y: 0): \"00\", (x: 0, y: 1): \"01\", (x: 1, y: 0): \"10\"}")
237237

238238
block tableTest2:
239239
var t = newTable[string, float]()
@@ -340,7 +340,7 @@ block tablesref:
340340
block anonZipTest:
341341
let keys = @['a','b','c']
342342
let values = @[1, 2, 3]
343-
doAssert "{'a': 1, 'b': 2, 'c': 3}" == $ toTable zip(keys, values)
343+
doAssert "{'c': 3, 'a': 1, 'b': 2}" == $ toTable zip(keys, values)
344344

345345
block clearTableTest:
346346
var t = newTable[string, float]()

tests/collections/ttablesthreads.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ block tableTest1:
4848
for y in 0..1:
4949
assert t[(x,y)] == $x & $y
5050
assert($t ==
51-
"{(x: 0, y: 1): \"01\", (x: 0, y: 0): \"00\", (x: 1, y: 0): \"10\", (x: 1, y: 1): \"11\"}")
51+
"{(x: 1, y: 1): \"11\", (x: 0, y: 0): \"00\", (x: 0, y: 1): \"01\", (x: 1, y: 0): \"10\"}")
5252

5353
block tableTest2:
5454
var t = initTable[string, float]()

0 commit comments

Comments
 (0)