-
Notifications
You must be signed in to change notification settings - Fork 167
/
Copy pathtest_random.py
94 lines (82 loc) · 1.85 KB
/
test_random.py
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
83
84
85
86
87
88
89
90
91
92
93
94
from lpython import i32, f64
import random
def test_random():
r: f64
r = random.random()
assert r >= 0.0 and r < 1.0
r = random.random()
assert r >= 0.0 and r < 1.0
def test_randrange():
r: i32
r = random.randrange(0, 10) # [0, 10)
assert r >= 0 and r < 10
r = random.randrange(-50, 76) # [-50, 76)
assert r >= -50 and r < 76
def test_randint():
ri1: i32
ri2: i32
ri1 = random.randint(0, 10) # [0, 10]
assert ri1 >= 0 and ri1 <= 10
ri2 = random.randint(-50, 76) # [-50, 76]
assert ri2 >= -50 and ri2 <= 76
def test_uniform():
r: f64
r = random.uniform(5., 76.)
assert r >= 5. and r <= 76.
r = random.uniform(-50., 76.)
assert r >= -50. and r <= 76.
def test_paretovariate():
r: f64
r = random.paretovariate(2.0)
print(r)
r = random.paretovariate(-5.6)
print(r)
def test_expovariate():
r: f64
r = random.expovariate(2.0)
print(r)
r = random.expovariate(-5.6)
print(r)
def test_weibullvariate():
r: f64
r = random.weibullvariate(2.0, 3.0)
print(r)
r = random.weibullvariate(-5.6, 1.2)
print(r)
def test_seed():
random.seed()
t6: f64 = random.random()
random.seed(123)
t1: f64
t1 = random.random()
random.seed(321)
t2: f64
t2 = random.random()
random.seed(123)
t3: f64
t3 = random.random()
random.seed(0)
t4: f64
t4 = random.random()
random.seed(0)
t5: f64
t5 = random.random()
random.seed()
t7: f64 = random.random()
print(t1, t2, t3, t4, t5, t6, t7)
assert t1 != t2
assert t1 == t3
assert t1 != t4
assert t1 != t5
assert t4 == t5
# assert t6 != t7
def check():
test_random()
test_randrange()
test_randint()
test_uniform()
test_paretovariate()
test_expovariate()
test_weibullvariate()
test_seed()
check()