-
Notifications
You must be signed in to change notification settings - Fork 167
/
Copy pathtest_dict_04.py
80 lines (62 loc) · 2.1 KB
/
test_dict_04.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
from lpython import i32, i64, f64
from math import pi, sin, cos
def test_dict():
terms2poly: dict[tuple[i32, i32], i64] = {}
rtheta2coords: dict[tuple[i64, i64], tuple[f64, f64]] = {}
i: i32
n: i64
size: i32 = 7000
size1: i32
theta: f64
r: f64
coords: tuple[f64, f64]
eps: f64 = 1e-12
n = i64(0)
for i in range(1000, 1000 + size, 7):
terms2poly[(i, i*i)] = int(i + i*i)
theta = float(n) * pi
r = float(i)
rtheta2coords[(int(i), n)] = (r * sin(theta), r * cos(theta))
n += int(1)
size1 = i32(size/7)
n = i64(0)
for i in range(1000, 1000 + size//2, 7):
assert terms2poly.pop((i, i*i)) == int(i + i*i)
theta = float(n) * pi
r = float(i)
coords = rtheta2coords.pop((int(i), n))
assert abs(coords[0] - r * sin(theta)) <= eps
assert abs(coords[1] - r * cos(theta)) <= eps
size1 = size1 - 1
assert len(terms2poly) == size1
n += int(1)
n = i64(0)
for i in range(1000, 1000 + size//2, 7):
terms2poly[(i, i*i)] = int(1 + 2*i + i*i)
theta = float(n) * pi
r = float(i)
rtheta2coords[(int(i), n)] = (r * cos(theta), r * sin(theta))
n += int(1)
n = i64(0)
for i in range(1000, 1000 + size//2, 7):
assert terms2poly[(i, i*i)] == i64((i + 1)*(i + 1))
theta = float(n) * pi
r = float(i)
assert abs(rtheta2coords[(int(i), n)][0] - r * cos(theta)) <= eps
assert abs(rtheta2coords[(int(i), n)][1] - r * sin(theta)) <= eps
n += int(1)
n = i64(0)
for i in range(1000, 1000 + size, 7):
terms2poly[(i, i*i)] = int(1 + 2*i + i*i)
theta = float(n) * pi
r = float(i)
rtheta2coords[(int(i), n)] = (r * cos(theta), r * sin(theta))
n += int(1)
n = i64(0)
for i in range(1000, 1000 + size, 7):
assert terms2poly[(i, i*i)] == i64((i + 1)*(i + 1))
theta = float(n) * pi
r = float(i)
assert abs(r**2.0 - rtheta2coords[(int(i), n)][0]**2.0 - r**2.0 * sin(theta)**2.0) <= eps
n += int(1)
test_dict()