From 6865212b9e3caa2a50b64e2e88907371090db4c9 Mon Sep 17 00:00:00 2001 From: Ashish Gupta Date: Sun, 14 Apr 2019 00:32:10 +0530 Subject: [PATCH 1/3] added necessary and unique tests --- tests/test_utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test_utils.py b/tests/test_utils.py index 12bfd1f6b..eca9714dd 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -15,16 +15,19 @@ def test_removeall_list(): assert removeall(4, []) == [] assert removeall(4, [1, 2, 3, 4]) == [1, 2, 3] assert removeall(4, [4, 1, 4, 2, 3, 4, 4]) == [1, 2, 3] + assert removeall(1,[2,3,4,5,6]) == [2,3,4,5,6] def test_removeall_string(): assert removeall('s', '') == '' assert removeall('s', 'This is a test. Was a test.') == 'Thi i a tet. Wa a tet.' + assert removeall('a','artificial intelligence: a modern approach') == 'rtificil intelligence: modern pproch' def test_unique(): assert unique([1, 2, 3, 2, 1]) == [1, 2, 3] assert unique([1, 5, 6, 7, 6, 5]) == [1, 5, 6, 7] + assert unique([1,2,3,4,5]) == [1,2,3,4,5] def test_count(): @@ -32,6 +35,7 @@ def test_count(): assert count("aldpeofmhngvia") == 14 assert count([True, False, True, True, False]) == 3 assert count([5 > 1, len("abc") == 3, 3+1 == 5]) == 2 + assert count("aima") == 4 def test_multimap(): assert multimap([(1, 2),(1, 3),(1, 4),(2, 3),(2, 4),(4, 5)]) == \ @@ -54,6 +58,7 @@ def test_first(): assert first(x for x in range(10) if x > 3) == 4 assert first(x for x in range(10) if x > 100) is None assert first((1, 2, 3)) == 1 + assert first(range(2,10)) == 2 assert first([(1, 2),(1, 3),(1, 4)]) == (1, 2) assert first({1:"one", 2:"two", 3:"three"}) == 1 @@ -67,6 +72,7 @@ def test_is_in(): def test_mode(): assert mode([12, 32, 2, 1, 2, 3, 2, 3, 2, 3, 44, 3, 12, 4, 9, 0, 3, 45, 3]) == 3 assert mode("absndkwoajfkalwpdlsdlfllalsflfdslgflal") == 'l' + assert mode("artificialintelligence") == 'i' def test_powerset(): @@ -75,6 +81,7 @@ def test_powerset(): def test_argminmax(): assert argmin([-2, 1], key=abs) == 1 + assert argmin(['one', 'to', 'three'], key=len) == 'to' assert argmax([-2, 1], key=abs) == -2 assert argmax(['one', 'to', 'three'], key=len) == 'three' @@ -93,6 +100,7 @@ def test_histogram(): def test_dotproduct(): assert dotproduct([1, 2, 3], [1000, 100, 10]) == 1230 + assert dotproduct([1,2,3],[0,0,0]) == 0 def test_element_wise_product(): From 15cade51167be2e32f8c7d3b36d32dd5021d1cc4 Mon Sep 17 00:00:00 2001 From: Ashish Gupta Date: Mon, 15 Apr 2019 17:56:20 +0530 Subject: [PATCH 2/3] some required changes --- tests/test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index eca9714dd..abcb5b4c7 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -15,7 +15,7 @@ def test_removeall_list(): assert removeall(4, []) == [] assert removeall(4, [1, 2, 3, 4]) == [1, 2, 3] assert removeall(4, [4, 1, 4, 2, 3, 4, 4]) == [1, 2, 3] - assert removeall(1,[2,3,4,5,6]) == [2,3,4,5,6] + assert removeall(1, [2,3,4,5,6]) == [2,3,4,5,6] def test_removeall_string(): From bb5e04edc9a8648ef896cb35e644d889d2d61ae1 Mon Sep 17 00:00:00 2001 From: Ashish Gupta Date: Mon, 15 Apr 2019 19:39:51 +0530 Subject: [PATCH 3/3] required changes --- tests/test_utils.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index abcb5b4c7..70eb857e9 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -21,13 +21,13 @@ def test_removeall_list(): def test_removeall_string(): assert removeall('s', '') == '' assert removeall('s', 'This is a test. Was a test.') == 'Thi i a tet. Wa a tet.' - assert removeall('a','artificial intelligence: a modern approach') == 'rtificil intelligence: modern pproch' + assert removeall('a', 'artificial intelligence: a modern approach') == 'rtificil intelligence: modern pproch' def test_unique(): assert unique([1, 2, 3, 2, 1]) == [1, 2, 3] assert unique([1, 5, 6, 7, 6, 5]) == [1, 5, 6, 7] - assert unique([1,2,3,4,5]) == [1,2,3,4,5] + assert unique([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_count(): @@ -58,7 +58,7 @@ def test_first(): assert first(x for x in range(10) if x > 3) == 4 assert first(x for x in range(10) if x > 100) is None assert first((1, 2, 3)) == 1 - assert first(range(2,10)) == 2 + assert first(range(2, 10)) == 2 assert first([(1, 2),(1, 3),(1, 4)]) == (1, 2) assert first({1:"one", 2:"two", 3:"three"}) == 1 @@ -100,7 +100,7 @@ def test_histogram(): def test_dotproduct(): assert dotproduct([1, 2, 3], [1000, 100, 10]) == 1230 - assert dotproduct([1,2,3],[0,0,0]) == 0 + assert dotproduct([1, 2, 3], [0, 0, 0]) == 0 def test_element_wise_product(): @@ -133,11 +133,12 @@ def test_vector_to_diagonal(): def test_vector_add(): assert vector_add((0, 1), (8, 9)) == (8, 10) + assert vector_add((1, 1, 1), (2, 2, 2)) == (3, 3, 3) def test_scalar_vector_product(): assert scalar_vector_product(2, [1, 2, 3]) == [2, 4, 6] - + assert scalar_vector_product(0, [9, 9, 9]) == [0, 0, 0] def test_scalar_matrix_product(): assert rounder(scalar_matrix_product(-5, [[1, 2], [3, 4], [0, 6]])) == [[-5, -10], [-15, -20],