-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopensimplex_cli_test.py
86 lines (66 loc) · 2.39 KB
/
opensimplex_cli_test.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
from time import time
from opensimplex_cli import OpenSimplexCLI, OpenSimplexConfig
SEED = 309482037420
def test_cli_random_seed():
c = OpenSimplexConfig()
assert c.seed is None
n = OpenSimplexCLI(config=c, silent=True)
assert isinstance(n.cnf.seed, int)
def test_extended_2d():
n = OpenSimplexCLI(config=OpenSimplexConfig(seed=SEED), silent=True)
a = n.get_2d_array(size=1)
assert isinstance(a, tuple)
assert isinstance(a[0], list)
assert isinstance(a[0][2], float)
assert isinstance(a[1], float)
assert isinstance(a[2], float)
assert a[1] == 83.10225 == a[2] == a[0][2]
time_start = time()
b = n.get_2d_array(size=50)
assert isinstance(b, tuple)
assert isinstance(b[0], list)
assert isinstance(b[0][2], float)
assert isinstance(b[1], float)
assert isinstance(b[2], float)
assert b[0][2] == 83.10225
assert b[0][-7] == 80.59629
assert b[1] == 84.60377
assert b[2] == 46.347794
assert time() - time_start < 1
def test_extended_2d_speed():
n = OpenSimplexCLI(config=OpenSimplexConfig(seed=SEED), silent=True)
time_start = time()
n.get_2d_array(size=1000)
assert time() - time_start < 5
def test_cli_seed():
n = OpenSimplexCLI(config=OpenSimplexConfig(seed=SEED), silent=True)
a = n.get_2d_array(size=20)
b = n.get_2d_array(size=20)
assert a[0][2] == b[0][2]
assert a[0][-7] == b[0][-7]
def test_extended_2d_sink():
n = OpenSimplexCLI(config=OpenSimplexConfig(seed=SEED), silent=True)
a = n.get_2d_array(size=100)
assert a[0][2] == 83.10225
assert a[0][-7] == 80.478264
assert a[1] == 101.29977
assert a[2] == 46.347794
b = n.get_2d_array(size=100, sink_down=True)
assert b[0][2] == 36.754456
assert b[0][-7] == 34.13047
assert b[1] == 54.951973
assert b[2] == 0
def test_extended_2d_lower():
n = OpenSimplexCLI(config=OpenSimplexConfig(seed=SEED), silent=True)
a = n.get_2d_array(size=100)
assert a[0][2] == 83.10225
assert a[0][-7] == 80.478264
assert a[1] == 101.29977
assert a[2] == 46.347794
lower_by = 40
rel = 0.001 # floating-points..
b = n.get_2d_array(size=100, lower_by=lower_by)
assert -rel < b[0][2] - (83.10225 - lower_by) < rel
assert -rel < b[0][-7] - (80.478264 - lower_by) < rel
assert -rel < b[1] - (101.29977 - lower_by) < rel
assert -rel < b[2] - (46.347794 - lower_by) < rel