Merge pull request #198 from Tass/master

Implements hash(float)
This commit is contained in:
Araq
2012-09-08 14:11:00 -07:00
3 changed files with 18 additions and 8 deletions

View File

@@ -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
View 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)

View File

@@ -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