File tree Expand file tree Collapse file tree 2 files changed +42
-12
lines changed Expand file tree Collapse file tree 2 files changed +42
-12
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,17 @@ def __len__(self):
21
21
"""
22
22
return self ._count
23
23
24
+ def __getitem__ (self , key ):
25
+ """Return value bu key.
26
+
27
+ Args:
28
+ key: key for find value
29
+
30
+ Returns:
31
+ value: value if key exist else None
32
+ """
33
+ return self .find (key )
34
+
24
35
def is_empty (self ):
25
36
"""Return True if tree is empty.
26
37
Original file line number Diff line number Diff line change @@ -54,17 +54,24 @@ def test_add_node3():
54
54
def test_find_value1 ():
55
55
bst = BinaryTree ()
56
56
57
- result = bst .find ('Key' )
58
- assert result is None
57
+ result1 = bst .find ('Key' )
58
+ result2 = bst ['key' ]
59
+
60
+ assert result1 is None
61
+ assert result2 is None
62
+
59
63
60
64
61
65
def test_find_value2 ():
62
66
bst = BinaryTree ()
63
67
64
68
bst .add (10 , 'Denis' )
65
69
66
- result = bst .find (10 )
67
- assert result == 'Denis'
70
+ result1 = bst .find (10 )
71
+ result2 = bst .find (10 )
72
+
73
+ assert result1 == 'Denis'
74
+ assert result2 == 'Denis'
68
75
69
76
70
77
def test_find_value3 ():
@@ -74,8 +81,11 @@ def test_find_value3():
74
81
bst .add (11 , 'Dima' )
75
82
bst .add (9 , 'Egor' )
76
83
77
- result = bst .find (11 )
78
- assert result == 'Dima'
84
+ result1 = bst .find (11 )
85
+ result2 = bst [11 ]
86
+
87
+ assert result1 == 'Dima'
88
+ assert result2 == 'Dima'
79
89
80
90
81
91
def test_find_value4 ():
@@ -85,8 +95,11 @@ def test_find_value4():
85
95
bst .add (11 , 'Dima' )
86
96
bst .add (9 , 'Egor' )
87
97
88
- result = bst .find (9 )
89
- assert result == 'Egor'
98
+ result1 = bst .find (9 )
99
+ result2 = bst [9 ]
100
+
101
+ assert result1 == 'Egor'
102
+ assert result2 == 'Egor'
90
103
91
104
92
105
def test_find_value5 ():
@@ -96,8 +109,11 @@ def test_find_value5():
96
109
bst .add (11 , 'Dima' )
97
110
bst .add (9 , 'Egor' )
98
111
99
- result = bst .find (11 )
100
- assert result == 'Dima'
112
+ result1 = bst .find (11 )
113
+ result2 = bst [11 ]
114
+
115
+ assert result1 == 'Dima'
116
+ assert result2 == 'Dima'
101
117
102
118
103
119
def test_find_value6 ():
@@ -107,8 +123,11 @@ def test_find_value6():
107
123
bst .add (11 , 'Dima' )
108
124
bst .add (9 , 'Egor' )
109
125
110
- result = bst .find (13 )
111
- assert result is None
126
+ result1 = bst .find (13 )
127
+ result2 = bst [13 ]
128
+
129
+ assert result1 is None
130
+ assert result2 is None
112
131
113
132
114
133
def test_min1 ():
You can’t perform that action at this time.
0 commit comments