-
Notifications
You must be signed in to change notification settings - Fork 167
/
Copy pathtest_dict_increment.py
66 lines (57 loc) · 1.41 KB
/
test_dict_increment.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
from lpython import i32, f64
def test_dict_increment():
d_int_int: dict[i32, i32]
d_int_float: dict[i32, f64]
d_bool_float: dict[bool, f64]
d_str_float: dict[str, f64]
d_int_str: dict[i32, str]
i1: i32
i2: i32
j1: f64
j2: f64
s1: str
d_int_int = {0: 1}
d_int_int[0] += 1000
assert d_int_int[0] == 1001
i2 = 1
d_int_int = {1: i2}
for i1 in range(10):
d_int_int[1] += i1
i2 += i1
assert d_int_int[1] == i2
i2 = 10
d_int_int = {0: 0, 1: 0}
for i1 in range(i2):
d_int_int[i1 % 2] += 1
assert d_int_int[0] == d_int_int[1]
assert d_int_int[0] == i2 // 2
j1 = 2.0
d_int_float = {2: j1}
while j1 < 4.0:
d_int_float[2] += 0.1
j1 += 0.1
assert d_int_float[2] == j1
j1 = 0.0
j2 = 0.0
d_bool_float = {True: 0.0, False: 0.0}
while j1 < 4.0:
d_bool_float[j1 < 2.0] += 0.1
if j1 < 2.0:
j2 += 0.1
j1 += 0.1
assert d_bool_float[j1 < 2.0] == d_bool_float[j1 > 2.0]
assert d_bool_float[True] == j2
j1 = 2.0
d_str_float = {'key': j1}
s1 = "ke"
while j1 < 4.0:
d_str_float[s1 + 'y'] += 0.1
j1 += 0.1
assert d_str_float['key'] == j1
s1 = "0"
d_int_str = {-1: s1}
for i1 in range(10):
d_int_str[-1] += str(i1)
s1 += str(i1)
assert d_int_str[-1] == s1
test_dict_increment()