Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion homework_1/sample_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]), []),
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.

Междудругото така както си го написал работи да, но и преди твоите промени тестът си е бил верен. Тези А, B, C реферират променливите, декларирани малко по-нагоре, а не са string-ове ( имена на лекарства). Не успях по-рано това да го забележа в snippet-a, който беше цитирал в issue-то си, но като цяло по-добре да си използваме вече дефинираните променливи, от колкото да преписваме нещо, което вече имаме.

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.

Аааа ок. Моя грешка тогава - съжалявам :(

(("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]]
Expand Down
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 solution import group_by_f

from solution import has_same_ingredients
from solution import is_stronger, least_stronger, strong_relation

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 solution import max_notes, 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(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(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(is_stronger(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(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)])
medicine2 = ("medicine2", [("p", 4), ("q", 3)])
medicine3 = ("medicine3", [("p", 3)])
medicine4 = ("medicine4", [("p", 4.5), ("q", 3), ("r", 1)])

expected_result = []

self.assertEqual(least_stronger(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(strong_relation([medicine1, medicine2, medicine3]), expected_result)


class TestMaxNotes(unittest.TestCase):
def test_function_when_result_must_be_the_max_notes(self):
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 = 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 = max_notes([[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 = 2

self.assertEqual(true_result, expected_result)


if __name__ == "__main__":
unittest.main()