Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions homework_1/test_hw_tasks.py
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

Copy link
Copy Markdown
Collaborator

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сгрешил съм файла, съжалявам - сега ще кача правилния

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):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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()