-
Notifications
You must be signed in to change notification settings - Fork 167
/
Copy pathloop_12.py
67 lines (51 loc) · 1.16 KB
/
loop_12.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
def test_for_dict_int():
dict_int: dict[i32, i32] = {1:2, 2:3, 3:4}
key: i32
s1: i32 = 0
s2: i32 = 0
for key in dict_int:
print(key)
s1 += key
s2 += dict_int[key]
assert s1 == 6
assert s2 == 9
def test_for_dict_str():
dict_str: dict[str, str] = {"a":"b", "c":"d"}
key: str
s1: str = ""
s2: str = ""
for key in dict_str:
print(key)
s1 += key
s2 += dict_str[key]
assert (s1 == "ac" or s1 == "ca")
assert ((s1 == "ac" and s2 == "bd") or (s1 == "ca" and s2 == "db"))
def test_for_set_int():
set_int: set[i32] = {1, 2, 3}
el: i32
s: i32 = 0
for el in set_int:
print(el)
s += el
assert s == 6
def test_for_set_str():
set_str: set[str] = {'a', 'b'}
el: str
s: str = ""
for el in set_str:
print(el)
s += el
assert (s == "ab" or s == "ba")
def test_nested():
graph: dict[i32, set[i32]] = {1: {2, 3}}
el: i32
s: i32 = 0
for el in graph[1]:
print(el)
s += el
assert s == 5
test_for_dict_int()
test_for_set_int()
test_for_dict_str()
test_for_set_str()
test_nested()