blob: 581308a7ee170118525ff830899dd579945068fc (
plain) (
blame)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
discard """
action: run
output: '''[Suite] random int
[Suite] random float
[Suite] ^
'''
"""
import math, random, os
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
test "randomize() again gives new numbers":
randomize()
var rand1 = random(1000000)
os.sleep(200)
randomize()
var rand2 = random(1000000)
check rand1 != rand2
suite "random float":
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
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
test "randomize() again gives new numbers":
randomize()
var rand1:float = random(1000000.0)
os.sleep(200)
randomize()
var rand2:float = random(1000000.0)
check rand1 != rand2
suite "^":
test "compiles for valid types":
check: compiles(5 ^ 2)
check: compiles(5.5 ^ 2)
check: compiles(5.5 ^ 2.int8)
check: compiles(5.5 ^ 2.uint)
check: compiles(5.5 ^ 2.uint8)
check: not compiles(5.5 ^ 2.2)
|