summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-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
ends <behrends@gmail.com> 2014-09-10 01:22:20 +0200 Properly handle staticExec() generating large output.' href='/ahoang/Nim/commit/compiler/vmdeps.nim?h=devel&id=f9c46b04a61c2ea1362b33e69c6e211f2d225354'>f9c46b04a ^
ef975d277 ^









92b8fac94 ^
ef975d277 ^




2f43fdb83 ^
92b8fac94 ^
6ea538cec ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38