Skip to content

Commit

Permalink
Update test_advice.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Dec 15, 2024
1 parent 32b642d commit 9ddafe3
Showing 1 changed file with 33 additions and 39 deletions.
72 changes: 33 additions & 39 deletions kyu_5/find_the_safest_places_in_town/test_advice.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import unittest
import allure
from parameterized import parameterized
from utils.log_func import print_log
from kyu_5.find_the_safest_places_in_town.advice \
import advice, create_city_map, agents_cleanup
Expand All @@ -29,7 +30,12 @@
class FirstAdviceTestCase(unittest.TestCase):
"""Testing advice and all related help functions."""

def test_create_city_map(self):
@parameterized.expand([
(2, {(0, 0), (0, 1), (1, 0), (1, 1)}),
(0, set()),
(3, {(0, 0), (0, 1), (0, 2), (1, 0), (1, 1),
(1, 2), (2, 0), (2, 1), (2, 2)})])
def test_create_city_map(self, n, expected):
"""
Testing a function named create_city_map.
Expand All @@ -48,31 +54,33 @@ def test_create_city_map(self):
'<h3>Test Description:</h3>'
"<p>The function should generate city map with coordinates.</p>")
# pylint: enable-msg=R0801
with allure.step("Enter test data and verify the output"):
test_data: tuple = (
(2, {(0, 0), (0, 1), (1, 0), (1, 1)}),
(0, set()),
(3, {(0, 0), (0, 1), (0, 2), (1, 0), (1, 1),
(1, 2), (2, 0), (2, 1), (2, 2)}))

for data in test_data:
# test data
n: int = data[0]
expected: set = data[1]
actual: set = create_city_map(n)
# test log
print_log(n=n, expected=expected, actual=actual)
# assertion
self.assertEqual(expected, actual)
with allure.step(f"Enter test data: {n} "
f"and verify the output: {expected}"):
actual: set = create_city_map(n)
# test log
print_log(n=n, expected=expected, actual=actual)
# assertion
self.assertEqual(expected, actual)

def test_agents_cleanup(self):
@parameterized.expand([
({(0, 0), (1, 5), (5, 1)}, 6, {(0, 0), (1, 5), (5, 1)}),
({(0, 0), (1, 1), (99, 99)}, 2, {(0, 0), (1, 1)}),
({(22, 23), (56, 35), (15, 7), (40, 15), (36, 30), (52, 47),
(9, 59), (65, 40), (28, 53), (19, 15),
(2, 30), (58, 40), (60, 36), (2, 67), (16, 58), (53, 13),
(36, 38), (29, 54), (50, 15), (14, 28),
(23, 30), (0, 64), (58, 57), (38, 2), (28, 40), (22, 6),
(12, 46), (50, 35), (56, 27)}, 10, set())
])
def test_agents_cleanup(self, agents, n, expected):
"""
Testing a function named agents_cleanup.
agents: is an array of agent coordinates
n: defines the size of the city that Bassi needs to hide in,
in other words the side length of the square grid.
The function should remove all agents that are outside of the city boundaries.
The function should remove all agents that are outside
the city boundaries.
:return:
"""
# pylint: disable-msg=R0801
Expand All @@ -87,26 +95,12 @@ def test_agents_cleanup(self):
"outside of the city boundaries.</p>")
# pylint: enable-msg=R0801
with allure.step("Enter test data and verify the output"):
test_data: tuple = (
({(0, 0), (1, 5), (5, 1)}, 6, {(0, 0), (1, 5), (5, 1)}),
({(0, 0), (1, 1), (99, 99)}, 2, {(0, 0), (1, 1)}),
({(22, 23), (56, 35), (15, 7), (40, 15), (36, 30), (52, 47),
(9, 59), (65, 40), (28, 53), (19, 15),
(2, 30), (58, 40), (60, 36), (2, 67), (16, 58), (53, 13),
(36, 38), (29, 54), (50, 15), (14, 28),
(23, 30), (0, 64), (58, 57), (38, 2), (28, 40), (22, 6),
(12, 46), (50, 35), (56, 27)}, 10, set()))

for data in test_data:
# test data
agents: set = data[0]
n: int = data[1]
expected: set = data[2]
actual: set = agents_cleanup(agents, n)
# test log
print_log(agents=agents, n=n, expected=expected, actual=actual)
# assertion
self.assertEqual(expected, actual)
# test data
actual: set = agents_cleanup(agents, n)
# test log
print_log(agents=agents, n=n, expected=expected, actual=actual)
# assertion
self.assertEqual(expected, actual)

def test_first_non_repeating_letter(self):
"""
Expand Down

0 comments on commit 9ddafe3

Please sign in to comment.