summary refs log tree commit diff stats
path: root/tests/run
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-09-08 15:43:40 +0200
committerAraq <rumpf_a@web.de>2012-09-08 15:43:40 +0200
commite2ecfb843885ba5e2fc27c5579b1be1df797cb09 (patch)
tree398ce885a551736e849d8b572be92893efef1874 /tests/run
parentb64eeeb4303953f9fe1135cb9c3c61e23ec55afa (diff)
parentdf04150c9c8d5a969d2c799b7bc274ef9546c581 (diff)
downloadNim-e2ecfb843885ba5e2fc27c5579b1be1df797cb09.tar.gz
Merge branch 'master' of github.com:Araq/Nimrod
Diffstat (limited to 'tests/run')
-rw-r--r--tests/run/tmath.nim49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/run/tmath.nim b/tests/run/tmath.nim
new file mode 100644
index 000000000..65124306e
--- /dev/null
+++ b/tests/run/tmath.nim
@@ -0,0 +1,49 @@
+import math
+import unittest
+import sets
+
+suite "random int":
+  test "there might be some randomness":
+    var set = initSet[int](128)
+    randomize()
+    for i in 1..1000:
+      incl(set, random(high(int)))
+    check len(set) == 1000
+  test "single number bounds work":
+    randomize()
+    var rand: int
+    for i in 1..1000:
+      rand = random(1000)
+      check rand < 1000
+      check rand > -1
+  test "slice bounds work":
+    randomize()
+    var rand: int
+    for i in 1..1000:
+      rand = random(100..1000)
+      check rand < 1000
+      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 "single number bounds work":
+    randomize()
+    var rand: float
+    for i in 1..1000:
+      rand = random(1000.0)
+      check rand < 1000.0
+      check rand > -1.0
+  test "slice bounds work":
+    randomize()
+    var rand: float
+    for i in 1..1000:
+      rand = random(100.0..1000.0)
+      check rand < 1000.0
+      check rand >= 100.0