-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopensimplex_cli_test.py
144 lines (110 loc) · 4.65 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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_2d():
n = OpenSimplexCLI(config=OpenSimplexConfig(seed=SEED), silent=True)
a = n.get_2d_array(size=1)
assert isinstance(a, dict)
assert isinstance(a['data'], list)
assert isinstance(a['data'][2], float)
assert isinstance(a['max'], float)
assert isinstance(a['min'], float)
assert a['max'] == 83.10225 == a['min'] == a['data'][2]
time_start = time()
b = n.get_2d_array(size=50)
assert isinstance(b, dict)
assert isinstance(b['data'], list)
assert isinstance(b['data'][2], float)
assert isinstance(b['max'], float)
assert isinstance(b['min'], float)
assert b['data'][2] == 83.10225
assert b['data'][-7] == 80.59629
assert b['max'] == 84.60377
assert b['min'] == 46.347794
assert time() - time_start < 1
def test_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_2d_no_coords():
n = OpenSimplexCLI(config=OpenSimplexConfig(seed=SEED), silent=True)
a = n.get_2d_array(size=10)
b = n.get_2d_array(size=10, no_coords=True)
assert a['data'][2] == b['data'][0]
assert len(a['data']) == 10 * 10 * 3
assert len(b['data']) == 10 * 10
def test_seed():
n = OpenSimplexCLI(config=OpenSimplexConfig(seed=SEED), silent=True)
a = n.get_2d_array(size=20, no_coords=True)
b = n.get_2d_array(size=20, no_coords=True)
assert a['data'][0] == b['data'][0]
assert a['data'][-2] == b['data'][-2]
def test_2d_sink():
n = OpenSimplexCLI(config=OpenSimplexConfig(seed=SEED), silent=True)
a = n.get_2d_array(size=100, no_coords=True)
assert a['data'][0] == 83.10225
assert a['data'][-3] == 80.478264
assert a['max'] == 101.29977
assert a['min'] == 46.347794
b = n.get_2d_array(size=100, sink_down=True, no_coords=True)
assert b['data'][0] == 36.754456
assert b['data'][-3] == 34.13047
assert b['max'] == 54.951973
assert b['min'] == 0
def test_2d_lower():
n = OpenSimplexCLI(config=OpenSimplexConfig(seed=SEED), silent=True)
a = n.get_2d_array(size=100, no_coords=True)
assert a['data'][0] == 83.10225
assert a['data'][-3] == 80.478264
assert a['max'] == 101.29977
assert a['min'] == 46.347794
lower_by = 40
rel = 0.001 # floating-points..
b = n.get_2d_array(size=100, lower_by=lower_by, no_coords=True)
assert -rel < b['data'][0] - (a['data'][0] - lower_by) < rel
assert -rel < b['data'][-3] - (a['data'][-3] - lower_by) < rel
assert -rel < b['max'] - (a['max'] - lower_by) < rel
assert -rel < b['min'] - (a['min'] - lower_by) < rel
def test_2d_mirror_x():
n = OpenSimplexCLI(config=OpenSimplexConfig(seed=SEED), silent=True)
a = n.get_2d_array(size=3, no_coords=True)
b = n.get_2d_array(size=3, mirror='x', no_coords=True)
assert a['data'][3 * 2 + 1] == b['data'][1]
assert a['data'][1] == b['data'][3 * 2 + 1]
def test_2d_mirror_y():
n = OpenSimplexCLI(config=OpenSimplexConfig(seed=SEED), silent=True)
a = n.get_2d_array(size=3, no_coords=True)
b = n.get_2d_array(size=3, mirror='y', no_coords=True)
assert a['data'][0] == b['data'][2]
assert a['data'][6] == b['data'][-1]
def test_2d_mirror_reverse():
n = OpenSimplexCLI(config=OpenSimplexConfig(seed=SEED), silent=True)
a = n.get_2d_array(size=3, no_coords=True)
b = n.get_2d_array(size=3, no_coords=True, mirror='reverse')
assert a['data'][0] == b['data'][-1]
assert a['data'][4] == b['data'][4]
def test_2d_rotate_90cw():
n = OpenSimplexCLI(config=OpenSimplexConfig(seed=SEED), silent=True)
a = n.get_2d_array(size=3, no_coords=True)
b = n.get_2d_array(size=3, rotate='90cw', no_coords=True)
assert a['data'][0] == b['data'][2]
assert a['data'][-3] == b['data'][0]
assert a['data'][-1] == b['data'][-3]
def test_2d_rotate_90ccw():
n = OpenSimplexCLI(config=OpenSimplexConfig(seed=SEED), silent=True)
a = n.get_2d_array(size=3, no_coords=True)
b = n.get_2d_array(size=3, rotate='90ccw', no_coords=True)
assert a['data'][0] == b['data'][-3]
assert a['data'][2] == b['data'][0]
def test_2d_rotate_180():
n = OpenSimplexCLI(config=OpenSimplexConfig(seed=SEED), silent=True)
a = n.get_2d_array(size=3, no_coords=True)
b = n.get_2d_array(size=3, rotate='180', no_coords=True)
assert a['data'][0] == b['data'][-1]
assert a['data'][2] == b['data'][-3]