summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorflywind <43030857+xflywind@users.noreply.github.com>2021-01-02 07:32:37 -0600
committerGitHub <noreply@github.com>2021-01-02 14:32:37 +0100
commitd8b1ffc85733a2189a91deafe00d67af690028de (patch)
tree046e8d24f10b186437caaa7266f396708d9ecb59 /tests
parent854ff26ac5a140b2f2cb509cef5a7aac551f6c34 (diff)
downloadNim-d8b1ffc85733a2189a91deafe00d67af690028de.tar.gz
fix #16542 (#16549)
* fix #16542
Diffstat (limited to 'tests')
-rw-r--r--tests/stdlib/thashes.nim31
1 files changed, 30 insertions, 1 deletions
diff --git a/tests/stdlib/thashes.nim b/tests/stdlib/thashes.nim
index 520b27e26..9c9287784 100644
--- a/tests/stdlib/thashes.nim
+++ b/tests/stdlib/thashes.nim
@@ -2,7 +2,7 @@ discard """
   targets: "c cpp js"
 """
 
-import hashes
+import std/hashes
 
 block hashes:
   block hashing:
@@ -75,3 +75,32 @@ block largeSize: # longer than 4 characters
   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)
+
+proc main() =
+  doAssert hash(0.0) == hash(0)
+  when sizeof(int) == 8:
+    block:
+      var s: seq[Hash]
+      for a in [0.0, 1.0, -1.0, 1000.0, -1000.0]:
+        let b = hash(a)
+        doAssert b notin s
+        s.add b
+    when defined(js):
+      doAssert hash(0.345602) == 2035867618
+      doAssert hash(234567.45) == -20468103
+      doAssert hash(-9999.283456) == -43247422
+      doAssert hash(84375674.0) == 707542256
+    else:
+      doAssert hash(0.345602) == 387936373221941218
+      doAssert hash(234567.45) == -8179139172229468551
+      doAssert hash(-9999.283456) == 5876943921626224834
+      doAssert hash(84375674.0) == 1964453089107524848
+  else:
+    doAssert hash(0.345602) != 0
+    doAssert hash(234567.45) != 0
+    doAssert hash(-9999.283456) != 0
+    doAssert hash(84375674.0) != 0
+
+
+static: main()
+main()