@@ -15,23 +15,27 @@ def test_removeall_list():
15
15
assert removeall (4 , []) == []
16
16
assert removeall (4 , [1 , 2 , 3 , 4 ]) == [1 , 2 , 3 ]
17
17
assert removeall (4 , [4 , 1 , 4 , 2 , 3 , 4 , 4 ]) == [1 , 2 , 3 ]
18
+ assert removeall (1 , [2 ,3 ,4 ,5 ,6 ]) == [2 ,3 ,4 ,5 ,6 ]
18
19
19
20
20
21
def test_removeall_string ():
21
22
assert removeall ('s' , '' ) == ''
22
23
assert removeall ('s' , 'This is a test. Was a test.' ) == 'Thi i a tet. Wa a tet.'
24
+ assert removeall ('a' , 'artificial intelligence: a modern approach' ) == 'rtificil intelligence: modern pproch'
23
25
24
26
25
27
def test_unique ():
26
28
assert unique ([1 , 2 , 3 , 2 , 1 ]) == [1 , 2 , 3 ]
27
29
assert unique ([1 , 5 , 6 , 7 , 6 , 5 ]) == [1 , 5 , 6 , 7 ]
30
+ assert unique ([1 , 2 , 3 , 4 , 5 ]) == [1 , 2 , 3 , 4 , 5 ]
28
31
29
32
30
33
def test_count ():
31
34
assert count ([1 , 2 , 3 , 4 , 2 , 3 , 4 ]) == 7
32
35
assert count ("aldpeofmhngvia" ) == 14
33
36
assert count ([True , False , True , True , False ]) == 3
34
37
assert count ([5 > 1 , len ("abc" ) == 3 , 3 + 1 == 5 ]) == 2
38
+ assert count ("aima" ) == 4
35
39
36
40
def test_multimap ():
37
41
assert multimap ([(1 , 2 ),(1 , 3 ),(1 , 4 ),(2 , 3 ),(2 , 4 ),(4 , 5 )]) == \
@@ -54,6 +58,7 @@ def test_first():
54
58
assert first (x for x in range (10 ) if x > 3 ) == 4
55
59
assert first (x for x in range (10 ) if x > 100 ) is None
56
60
assert first ((1 , 2 , 3 )) == 1
61
+ assert first (range (2 , 10 )) == 2
57
62
assert first ([(1 , 2 ),(1 , 3 ),(1 , 4 )]) == (1 , 2 )
58
63
assert first ({1 :"one" , 2 :"two" , 3 :"three" }) == 1
59
64
@@ -67,6 +72,7 @@ def test_is_in():
67
72
def test_mode ():
68
73
assert mode ([12 , 32 , 2 , 1 , 2 , 3 , 2 , 3 , 2 , 3 , 44 , 3 , 12 , 4 , 9 , 0 , 3 , 45 , 3 ]) == 3
69
74
assert mode ("absndkwoajfkalwpdlsdlfllalsflfdslgflal" ) == 'l'
75
+ assert mode ("artificialintelligence" ) == 'i'
70
76
71
77
72
78
def test_powerset ():
@@ -75,6 +81,7 @@ def test_powerset():
75
81
76
82
def test_argminmax ():
77
83
assert argmin ([- 2 , 1 ], key = abs ) == 1
84
+ assert argmin (['one' , 'to' , 'three' ], key = len ) == 'to'
78
85
assert argmax ([- 2 , 1 ], key = abs ) == - 2
79
86
assert argmax (['one' , 'to' , 'three' ], key = len ) == 'three'
80
87
@@ -93,6 +100,7 @@ def test_histogram():
93
100
94
101
def test_dotproduct ():
95
102
assert dotproduct ([1 , 2 , 3 ], [1000 , 100 , 10 ]) == 1230
103
+ assert dotproduct ([1 , 2 , 3 ], [0 , 0 , 0 ]) == 0
96
104
97
105
98
106
def test_element_wise_product ():
@@ -125,11 +133,12 @@ def test_vector_to_diagonal():
125
133
126
134
def test_vector_add ():
127
135
assert vector_add ((0 , 1 ), (8 , 9 )) == (8 , 10 )
136
+ assert vector_add ((1 , 1 , 1 ), (2 , 2 , 2 )) == (3 , 3 , 3 )
128
137
129
138
130
139
def test_scalar_vector_product ():
131
140
assert scalar_vector_product (2 , [1 , 2 , 3 ]) == [2 , 4 , 6 ]
132
-
141
+ assert scalar_vector_product ( 0 , [ 9 , 9 , 9 ]) == [ 0 , 0 , 0 ]
133
142
134
143
def test_scalar_matrix_product ():
135
144
assert rounder (scalar_matrix_product (- 5 , [[1 , 2 ], [3 , 4 ], [0 , 6 ]])) == [[- 5 , - 10 ], [- 15 , - 20 ],
0 commit comments