Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dd17371

Browse files
ashishgit7antmarakis
authored andcommitted
added necessary and unique tests (aimacode#1071)
* added necessary and unique tests * some required changes * required changes
1 parent 17bcde1 commit dd17371

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

tests/test_utils.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,27 @@ def test_removeall_list():
1515
assert removeall(4, []) == []
1616
assert removeall(4, [1, 2, 3, 4]) == [1, 2, 3]
1717
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]
1819

1920

2021
def test_removeall_string():
2122
assert removeall('s', '') == ''
2223
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'
2325

2426

2527
def test_unique():
2628
assert unique([1, 2, 3, 2, 1]) == [1, 2, 3]
2729
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]
2831

2932

3033
def test_count():
3134
assert count([1, 2, 3, 4, 2, 3, 4]) == 7
3235
assert count("aldpeofmhngvia") == 14
3336
assert count([True, False, True, True, False]) == 3
3437
assert count([5 > 1, len("abc") == 3, 3+1 == 5]) == 2
38+
assert count("aima") == 4
3539

3640
def test_multimap():
3741
assert multimap([(1, 2),(1, 3),(1, 4),(2, 3),(2, 4),(4, 5)]) == \
@@ -54,6 +58,7 @@ def test_first():
5458
assert first(x for x in range(10) if x > 3) == 4
5559
assert first(x for x in range(10) if x > 100) is None
5660
assert first((1, 2, 3)) == 1
61+
assert first(range(2, 10)) == 2
5762
assert first([(1, 2),(1, 3),(1, 4)]) == (1, 2)
5863
assert first({1:"one", 2:"two", 3:"three"}) == 1
5964

@@ -67,6 +72,7 @@ def test_is_in():
6772
def test_mode():
6873
assert mode([12, 32, 2, 1, 2, 3, 2, 3, 2, 3, 44, 3, 12, 4, 9, 0, 3, 45, 3]) == 3
6974
assert mode("absndkwoajfkalwpdlsdlfllalsflfdslgflal") == 'l'
75+
assert mode("artificialintelligence") == 'i'
7076

7177

7278
def test_powerset():
@@ -75,6 +81,7 @@ def test_powerset():
7581

7682
def test_argminmax():
7783
assert argmin([-2, 1], key=abs) == 1
84+
assert argmin(['one', 'to', 'three'], key=len) == 'to'
7885
assert argmax([-2, 1], key=abs) == -2
7986
assert argmax(['one', 'to', 'three'], key=len) == 'three'
8087

@@ -93,6 +100,7 @@ def test_histogram():
93100

94101
def test_dotproduct():
95102
assert dotproduct([1, 2, 3], [1000, 100, 10]) == 1230
103+
assert dotproduct([1, 2, 3], [0, 0, 0]) == 0
96104

97105

98106
def test_element_wise_product():
@@ -125,11 +133,12 @@ def test_vector_to_diagonal():
125133

126134
def test_vector_add():
127135
assert vector_add((0, 1), (8, 9)) == (8, 10)
136+
assert vector_add((1, 1, 1), (2, 2, 2)) == (3, 3, 3)
128137

129138

130139
def test_scalar_vector_product():
131140
assert scalar_vector_product(2, [1, 2, 3]) == [2, 4, 6]
132-
141+
assert scalar_vector_product(0, [9, 9, 9]) == [0, 0, 0]
133142

134143
def test_scalar_matrix_product():
135144
assert rounder(scalar_matrix_product(-5, [[1, 2], [3, 4], [0, 6]])) == [[-5, -10], [-15, -20],

0 commit comments

Comments
 (0)