mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 17:34:43 +00:00
@@ -122,3 +122,7 @@ proc hash*[T: tuple](x: T): THash =
|
||||
result = result !& hash(f)
|
||||
result = !$result
|
||||
|
||||
proc hash*(x: float): THash {.inline.} =
|
||||
var y = x + 1.0
|
||||
result = cast[ptr THash](addr(y))[]
|
||||
|
||||
|
||||
8
tests/run/thashes.nim
Normal file
8
tests/run/thashes.nim
Normal file
@@ -0,0 +1,8 @@
|
||||
import unittest
|
||||
import hashes
|
||||
|
||||
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)
|
||||
@@ -25,14 +25,12 @@ suite "random int":
|
||||
check rand >= 100
|
||||
|
||||
suite "random float":
|
||||
# Enable this once #197 has been resolved
|
||||
# test "there might be some randomness":
|
||||
# var set = initSet[float](128)
|
||||
# for i in 1..10:
|
||||
# for j in 1..10:
|
||||
# randomize()
|
||||
# incl(set, random(1.0))
|
||||
# check len(set) == 100
|
||||
test "there might be some randomness":
|
||||
var set = initSet[float](128)
|
||||
randomize()
|
||||
for i in 1..100:
|
||||
incl(set, random(1.0))
|
||||
check len(set) == 100
|
||||
test "single number bounds work":
|
||||
randomize()
|
||||
var rand: float
|
||||
|
||||
Reference in New Issue
Block a user