From e8a3dacecb370510157819920ec00e8377a8ca20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A?= =?UTF-8?q?=D1=80=20=D0=A1=D1=82=D0=BE=D0=B8=D1=87=D0=BA=D0=BE=D0=B2?= Date: Wed, 6 Nov 2019 11:44:36 +0200 Subject: [PATCH 1/4] Add tests for homework_1 --- homework_1/test_hw_tasks.py | 132 ++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 homework_1/test_hw_tasks.py diff --git a/homework_1/test_hw_tasks.py b/homework_1/test_hw_tasks.py new file mode 100644 index 0000000..ee595e7 --- /dev/null +++ b/homework_1/test_hw_tasks.py @@ -0,0 +1,132 @@ +from task1 import group_by_f + +from task2 import has_same_ingredients +from task2 import isStronger, leastStronger, strongRelation + +from task3 import maxNotes, leading + +import unittest + + +class TestGroupByF(unittest.TestCase): + def test_function_with_lambda_function(self): + true_result = group_by_f(lambda a: a % 2 == 0, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + expected_result = {False: [1, 3, 5, 7, 9], True: [2, 4, 6, 8, 10]} + + self.assertEqual(true_result, expected_result) + + def test_function_with_standard_len_function(self): + true_result = group_by_f(len, [[1], [7, 8], [1, 2, 3, 4], [4], ["random", "words"]]) + expected_result = {1: [[1], [4]], 2: [[7, 8], ['random', 'words']], 4: [[1, 2, 3, 4]]} + + self.assertEqual(true_result, expected_result) + +class TestHasSameIngredients(unittest.TestCase): + def test_function_when_result_must_be_true(self): + medicine1 = ("medicine1", [("p", 5), ("q", 3)]) + medicine2 = ("medicine2", [("p", 4), ("q", 3)]) + + self.assertTrue(has_same_ingredients(medicine1, medicine2)) + + def test_function_when_result_must_be_true_with_swapped_names(self): + medicine1 = ("medicine1", [("q", 5), ("p", 3)]) + medicine2 = ("medicine2", [("p", 4), ("q", 3)]) + + self.assertTrue(has_same_ingredients(medicine1, medicine2)) + + def test_function_when_result_must_be_false(self): + medicine1 = ("medicine1", [("p", 5)]) + medicine2 = ("medicine2", [("p", 4), ("q", 3)]) + + self.assertTrue(has_same_ingredients(medicine1, medicine2)) + + +class TestIsStronger(unittest.TestCase): + def test_function_when_medicines_are_equal_strength(self): + medicine1 = ("medicine1", [("p", 5), ("q", 3)]) + medicine2 = ("medicine2", [("p", 4), ("q", 4)]) + + self.assertFalse(isStronger(medicine1, medicine2)) + + def test_function_when_first_medicine_is_stronger_than_the_second(self): + medicine1 = ("medicine1", [("p", 5), ("q", 3)]) + medicine2 = ("medicine2", [("p", 4), ("q", 3)]) + + self.assertTrue(isStronger(medicine1, medicine2)) + + def test_function_when_first_medicine_is_not_stronger_than_the_second(self): + medicine1 = ("medicine1", [("p", 5), ("q", 3)]) + medicine2 = ("medicine2", [("p", 4), ("q", 3)]) + + self.assertFalse(isStronger(medicine2, medicine1)) + + +class TestLeastStronger(unittest.TestCase): + def test_function_when_medicine_is_stronger_than_return_it(self): + medicine1 = ("medicine1", [("p", 5), ("q", 3)]) + medicine2 = ("medicine2", [("p", 4), ("q", 3)]) + medicine3 = ("medicine3", [("p", 3)]) + medicine4 = ("medicine4", [("p", 4.5), ("q", 3), ("r", 1)]) + + expected_result = ("medicine4", [("p", 4.5), ("q", 3), ("r", 1)]) + + self.assertEqual(leastStronger(medicine2, [medicine1, medicine3, medicine4]), expected_result) + + def test_function_when_no_medicine_is_stronger_than_return_empty_list(self): + medicine1 = ("medicine1", [("p", 5), ("q", 3)]) + medicine2 = ("medicine2", [("p", 4), ("q", 3)]) + medicine3 = ("medicine3", [("p", 3)]) + medicine4 = ("medicine4", [("p", 4.5), ("q", 3), ("r", 1)]) + + expected_result = [] + + self.assertEqual(leastStronger(medicine1, [medicine2, medicine3, medicine4]), expected_result) + + +class TestStrongRelation(unittest.TestCase): + def test_function_when_result_must_be_list_of_tuples(self): + medicine1 = ("medicine1", [("p", 5), ("q", 3)]) + medicine2 = ("medicine2", [("p", 4), ("q", 3)]) + medicine3 = ("medicine3", [("p", 3)]) + + expected_result = [(('medicine1', [('p', 5), ('q', 3)]), []), (('medicine2', [('p', 4), ('q', 3)]), ['medicine1']), (('medicine3', [('p', 3)]), ['medicine1', 'medicine2'])] + + self.assertEqual(strongRelation([medicine1, medicine2, medicine3]), expected_result) + + +class TestMaxNotes(unittest.TestCase): + def test_function_when_result_must_be_the_max_notes(self): + true_result = maxNotes([[1, 2, 3], [2, 2, 2], [9, 7, 3]]) + expected_result = 19 + + self.assertEqual(true_result, expected_result) + + def test_function_when_result_must_be_zero(self): + true_result = maxNotes([]) + expected_result = 0 + + self.assertEqual(true_result, expected_result) + + def test_function_when_max_notes_are_equal_then_return_result(self): + true_result = maxNotes([[1, 2, 3], [2, 2, 2]]) + expected_result = 6 + + self.assertEqual(true_result, expected_result) + + +class TestLeading(unittest.TestCase): + def test_function_when_result_must_be_the_leading_note(self): + true_result = leading([[1, 10, 2], [2, 2, 2], [9, 7, 3]]) + expected_result = 2 + + self.assertEqual(true_result, expected_result) + + def test_function_when_result_must_be_the_first_leading_note(self): + true_result = leading([[1, 2, 3], [2, 2, 2], [9, 7, 3]]) + expected_result = 0 + + self.assertEqual(true_result, expected_result) + + +if __name__ == "__main__": + unittest.main() From c3bdd0d35ea781b697630612770324ea20524aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A?= =?UTF-8?q?=D1=80=20=D0=A1=D1=82=D0=BE=D0=B8=D1=87=D0=BA=D0=BE=D0=B2?= Date: Wed, 6 Nov 2019 18:28:22 +0200 Subject: [PATCH 2/4] Update test_hw_tasks.py --- homework_1/test_hw_tasks.py | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/homework_1/test_hw_tasks.py b/homework_1/test_hw_tasks.py index ee595e7..c7023bc 100644 --- a/homework_1/test_hw_tasks.py +++ b/homework_1/test_hw_tasks.py @@ -1,9 +1,7 @@ -from task1 import group_by_f +from solution import group_by_f +from solution import isStronger, leastStronger, strongRelation +from solution import maxNotes, leading -from task2 import has_same_ingredients -from task2 import isStronger, leastStronger, strongRelation - -from task3 import maxNotes, leading import unittest @@ -21,25 +19,6 @@ def test_function_with_standard_len_function(self): self.assertEqual(true_result, expected_result) -class TestHasSameIngredients(unittest.TestCase): - def test_function_when_result_must_be_true(self): - medicine1 = ("medicine1", [("p", 5), ("q", 3)]) - medicine2 = ("medicine2", [("p", 4), ("q", 3)]) - - self.assertTrue(has_same_ingredients(medicine1, medicine2)) - - def test_function_when_result_must_be_true_with_swapped_names(self): - medicine1 = ("medicine1", [("q", 5), ("p", 3)]) - medicine2 = ("medicine2", [("p", 4), ("q", 3)]) - - self.assertTrue(has_same_ingredients(medicine1, medicine2)) - - def test_function_when_result_must_be_false(self): - medicine1 = ("medicine1", [("p", 5)]) - medicine2 = ("medicine2", [("p", 4), ("q", 3)]) - - self.assertTrue(has_same_ingredients(medicine1, medicine2)) - class TestIsStronger(unittest.TestCase): def test_function_when_medicines_are_equal_strength(self): From 4b8d1c0de6f880f5be2b7addfead025b4587d04a Mon Sep 17 00:00:00 2001 From: SashoStoichkov Date: Fri, 8 Nov 2019 09:46:34 +0200 Subject: [PATCH 3/4] Update tests to snake_case --- homework_1/sample_test.py | 4 +++- homework_1/test_hw_tasks.py | 43 +++++++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/homework_1/sample_test.py b/homework_1/sample_test.py index 294fdf2..eb9b882 100644 --- a/homework_1/sample_test.py +++ b/homework_1/sample_test.py @@ -42,7 +42,9 @@ def test_strong_relation(self): B = ("B", [("p", 4), ("q", 3)]) C = ("C", [("p", 3)]) self.assertEqual(solution.strong_relation([A, B, C]), [ - (A, []), (B, ['A']), (C, ['A', 'B'])]) + (("A", [("p", 5), ("q", 3)]), []), + (("B", [("p", 4), ("q", 3)]), ['A']), + (("C", [("p", 3)]), ['A', 'B'])]) def test_max_notes(self): P = [[1, 2, 3], [2, 2, 2], [9, 7, 3]] diff --git a/homework_1/test_hw_tasks.py b/homework_1/test_hw_tasks.py index c7023bc..f5d2216 100644 --- a/homework_1/test_hw_tasks.py +++ b/homework_1/test_hw_tasks.py @@ -1,7 +1,9 @@ from solution import group_by_f -from solution import isStronger, leastStronger, strongRelation -from solution import maxNotes, leading +from solution import has_same_ingredients +from solution import is_stronger, least_stronger, strong_relation + +from solution import max_notes, leading import unittest @@ -19,25 +21,44 @@ def test_function_with_standard_len_function(self): self.assertEqual(true_result, expected_result) +class TestHasSameIngredients(unittest.TestCase): + def test_function_when_result_must_be_true(self): + medicine1 = ("medicine1", [("p", 5), ("q", 3)]) + medicine2 = ("medicine2", [("p", 4), ("q", 3)]) + + self.assertTrue(has_same_ingredients(medicine1, medicine2)) + + def test_function_when_result_must_be_true_with_swapped_names(self): + medicine1 = ("medicine1", [("q", 5), ("p", 3)]) + medicine2 = ("medicine2", [("p", 4), ("q", 3)]) + + self.assertTrue(has_same_ingredients(medicine1, medicine2)) + + def test_function_when_result_must_be_false(self): + medicine1 = ("medicine1", [("p", 5)]) + medicine2 = ("medicine2", [("p", 4), ("q", 3)]) + + self.assertTrue(has_same_ingredients(medicine1, medicine2)) + class TestIsStronger(unittest.TestCase): def test_function_when_medicines_are_equal_strength(self): medicine1 = ("medicine1", [("p", 5), ("q", 3)]) medicine2 = ("medicine2", [("p", 4), ("q", 4)]) - self.assertFalse(isStronger(medicine1, medicine2)) + self.assertFalse(is_stronger(medicine1, medicine2)) def test_function_when_first_medicine_is_stronger_than_the_second(self): medicine1 = ("medicine1", [("p", 5), ("q", 3)]) medicine2 = ("medicine2", [("p", 4), ("q", 3)]) - self.assertTrue(isStronger(medicine1, medicine2)) + self.assertTrue(is_stronger(medicine1, medicine2)) def test_function_when_first_medicine_is_not_stronger_than_the_second(self): medicine1 = ("medicine1", [("p", 5), ("q", 3)]) medicine2 = ("medicine2", [("p", 4), ("q", 3)]) - self.assertFalse(isStronger(medicine2, medicine1)) + self.assertFalse(is_stronger(medicine2, medicine1)) class TestLeastStronger(unittest.TestCase): @@ -49,7 +70,7 @@ def test_function_when_medicine_is_stronger_than_return_it(self): expected_result = ("medicine4", [("p", 4.5), ("q", 3), ("r", 1)]) - self.assertEqual(leastStronger(medicine2, [medicine1, medicine3, medicine4]), expected_result) + self.assertEqual(least_stronger(medicine2, [medicine1, medicine3, medicine4]), expected_result) def test_function_when_no_medicine_is_stronger_than_return_empty_list(self): medicine1 = ("medicine1", [("p", 5), ("q", 3)]) @@ -59,7 +80,7 @@ def test_function_when_no_medicine_is_stronger_than_return_empty_list(self): expected_result = [] - self.assertEqual(leastStronger(medicine1, [medicine2, medicine3, medicine4]), expected_result) + self.assertEqual(least_stronger(medicine1, [medicine2, medicine3, medicine4]), expected_result) class TestStrongRelation(unittest.TestCase): @@ -70,24 +91,24 @@ def test_function_when_result_must_be_list_of_tuples(self): expected_result = [(('medicine1', [('p', 5), ('q', 3)]), []), (('medicine2', [('p', 4), ('q', 3)]), ['medicine1']), (('medicine3', [('p', 3)]), ['medicine1', 'medicine2'])] - self.assertEqual(strongRelation([medicine1, medicine2, medicine3]), expected_result) + self.assertEqual(strong_relation([medicine1, medicine2, medicine3]), expected_result) class TestMaxNotes(unittest.TestCase): def test_function_when_result_must_be_the_max_notes(self): - true_result = maxNotes([[1, 2, 3], [2, 2, 2], [9, 7, 3]]) + true_result = max_notes([[1, 2, 3], [2, 2, 2], [9, 7, 3]]) expected_result = 19 self.assertEqual(true_result, expected_result) def test_function_when_result_must_be_zero(self): - true_result = maxNotes([]) + true_result = max_notes([]) expected_result = 0 self.assertEqual(true_result, expected_result) def test_function_when_max_notes_are_equal_then_return_result(self): - true_result = maxNotes([[1, 2, 3], [2, 2, 2]]) + true_result = max_notes([[1, 2, 3], [2, 2, 2]]) expected_result = 6 self.assertEqual(true_result, expected_result) From 16e1d1e6ff90185e248f1e0ea258cd559ec79521 Mon Sep 17 00:00:00 2001 From: SashoStoichkov Date: Sun, 10 Nov 2019 16:11:31 +0200 Subject: [PATCH 4/4] fixed typo --- homework_1/test_hw_tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homework_1/test_hw_tasks.py b/homework_1/test_hw_tasks.py index f5d2216..8aa38aa 100644 --- a/homework_1/test_hw_tasks.py +++ b/homework_1/test_hw_tasks.py @@ -123,7 +123,7 @@ def test_function_when_result_must_be_the_leading_note(self): def test_function_when_result_must_be_the_first_leading_note(self): true_result = leading([[1, 2, 3], [2, 2, 2], [9, 7, 3]]) - expected_result = 0 + expected_result = 2 self.assertEqual(true_result, expected_result)