-
Notifications
You must be signed in to change notification settings - Fork 11
Add tests for homework_1 #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Подобно на предния ми коментар тук ползваш някаква твоя helper функция предполагам, чрез която да решиш някоя задача. Такава функция не се изисква в условието, съответно твоите съученици не са длъжни да са се сетили да използват точно такава helper функция. |
||
| 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) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. плс фиксни го и в sample_test.py |
||
|
|
||
|
|
||
| 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() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
По условие решението на задачите трябва да се пише в solution.py файл. Идеята на това да има конкретни инструкции за предаване на решения е да можем, сваляйки чието и да е решение директно да можем да изпълним тестовете върху това решение. В тестовете, които ти си добавил си import-вал функции от модули, които ти си си дефинирал, но твоите съученици не са длъжни да имат същите модули (би трябвало да имат само solution.py) и когато за чуждо решение се опитаме да изпълним тези тестовете, те ще гръмнат заради липсата на модулите task1, task2 etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Сгрешил съм файла, съжалявам - сега ще кача правилния