Skip to content

Commit 4c5bfca

Browse files
committed
Refactoring
1 parent 0fd5f05 commit 4c5bfca

File tree

23 files changed

+75
-78
lines changed

23 files changed

+75
-78
lines changed

kyu_5/alphabet_wars_nuclear_strike/test_alphabet_war.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_alphabet_war(self, battlefield, expected):
9696
'<h3>Test Description:</h3>'
9797
"<p>Test a function that accepts battlefield string and "
9898
"returns letters that survived the nuclear strike.</p>")
99-
99+
# pylint: enable-msg=R0801
100100
result: str = alphabet_war(battlefield)
101101
with allure.step(f"Enter test string ({battlefield}) "
102102
f"and verify the output ({result}) "

kyu_5/count_ip_addresses/test_ips_between.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ def test_ips_between(self, start, end, expected):
7171
"of strings. The last address will always be greater "
7272
"than the first one.</p>")
7373
# pylint: enable-msg=R0801
74-
7574
result = ips_between(start, end)
7675
with allure.step(f"Enter test data (start: {start}, "
7776
f"end: {end}) and verify "

kyu_5/diophantine_equation/test_solution.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ def test_solution_basic(self, num, expected):
5050
(9001, [[4501, 2250]]),
5151
(9004, [[2252, 1125]]),
5252
(9008, [[1128, 562]]),
53-
(9009, [[4505, 2252], [1503, 750], [647, 320], [505, 248],
54-
[415, 202], [353, 170], [225, 102], [153, 60],
55-
[135, 48], [103, 20], [97, 10], [95, 2]])])
53+
(9009, [[4505, 2252], [1503, 750], [647, 320],
54+
[505, 248], [415, 202], [353, 170],
55+
[225, 102], [153, 60], [135, 48],
56+
[103, 20], [97, 10], [95, 2]])])
5657
def test_solution_medium(self, num, expected):
5758
"""
5859
Testing using medium test data.
@@ -62,14 +63,20 @@ def test_solution_medium(self, num, expected):
6263
self.assertEqual(num, expected)
6364

6465
@parameterized.expand([
65-
(900000, [[112502, 56249], [56254, 28123], [37506, 18747],
66-
[22510, 11245], [18762, 9369], [12518, 6241],
67-
[11270, 5615], [7530, 3735], [6286, 3107], [4550, 2225],
68-
[3810, 1845], [2590, 1205], [2350, 1075], [1650, 675],
69-
[1430, 535], [1150, 325], [1050, 225], [950, 25]]),
66+
(900000, [[112502, 56249], [56254, 28123],
67+
[37506, 18747], [22510, 11245],
68+
[18762, 9369], [12518, 6241],
69+
[11270, 5615], [7530, 3735],
70+
[6286, 3107], [4550, 2225],
71+
[3810, 1845], [2590, 1205],
72+
[2350, 1075], [1650, 675],
73+
[1430, 535], [1150, 325],
74+
[1050, 225], [950, 25]]),
7075
(90004, [[22502, 11250]]),
71-
(90005, [[45003, 22501], [9003, 4499], [981, 467], [309, 37]]),
72-
(90009, [[45005, 22502], [15003, 7500], [5005, 2498],
76+
(90005, [[45003, 22501], [9003, 4499],
77+
[981, 467], [309, 37]]),
78+
(90009, [[45005, 22502], [15003, 7500],
79+
[5005, 2498],
7380
[653, 290], [397, 130], [315, 48]])])
7481
def test_solution_big(self, num, expected):
7582
"""

kyu_5/directions_reduction/test_directions_reduction.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ class DirectionsReductionTestCase(unittest.TestCase):
4646
'WEST', 'NORTH', 'WEST', 'SOUTH', 'SOUTH']),
4747
(['WEST', 'NORTH', 'EAST', 'EAST', 'EAST', 'EAST', 'WEST', 'WEST',
4848
'WEST', 'WEST', 'NORTH', 'NORTH', 'SOUTH', 'EAST'],
49-
['WEST', 'NORTH', 'NORTH', 'EAST'])
50-
])
49+
['WEST', 'NORTH', 'NORTH', 'EAST'])])
5150
def test_directions_reduction(self, test_array, expected):
5251
"""
5352
dir_reduc function test suite.
@@ -78,7 +77,6 @@ def test_directions_reduction(self, test_array, expected):
7877
"strings and returns an array of strings with the needless "
7978
"directions removed (W<->E or S<->N side by side).</p>")
8079
# pylint: enable-msg=R0801
81-
8280
result = dir_reduc(test_array)
8381
with allure.step(f"Enter test data ({test_array}) "
8482
f"and verify the output ({result}) "

kyu_5/extract_the_domain_name_from_url/test_domain_name.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# DECLARATIVE PROGRAMMING ADVANCED LANGUAGE FEATURES
1111

1212
import unittest
13+
from parameterized import parameterized
1314
import allure
1415
from utils.log_func import print_log
1516
from kyu_5.extract_the_domain_name_from_url.extract_domain_from_url \
@@ -37,7 +38,12 @@
3738
class DomainNameTestCase(unittest.TestCase):
3839
"""Testing domain_name function."""
3940

40-
def test_domain_name(self):
41+
@parameterized.expand([
42+
("http://google.com", "google"),
43+
("http://google.co.jp", "google"),
44+
("www.xakep.ru", "xakep"),
45+
("https://youtube.com", "youtube")])
46+
def test_domain_name(self, url, expected):
4147
"""
4248
domain_name function testing.
4349
@@ -56,14 +62,7 @@ def test_domain_name(self):
5662
"<p>Assert that 'domain_name' function "
5763
"returns domain name from given URL string.</p>")
5864
# pylint: enable-msg=R0801
59-
test_data: tuple = (
60-
("http://google.com", "google"),
61-
("http://google.co.jp", "google"),
62-
("www.xakep.ru", "xakep"),
63-
("https://youtube.com", "youtube"))
64-
65-
for url, expected in test_data:
66-
with allure.step("Enter test string and verify the output"):
67-
actual = domain_name(url)
68-
print_log(url=url, expected=expected, actual=actual)
69-
self.assertEqual(expected, actual)
65+
with allure.step("Enter test string and verify the output"):
66+
actual = domain_name(url)
67+
print_log(url=url, expected=expected, actual=actual)
68+
self.assertEqual(expected, actual)

kyu_5/find_the_safest_places_in_town/test_advice.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ def test_create_city_map(self, n, expected):
7070
(2, 30), (58, 40), (60, 36), (2, 67), (16, 58), (53, 13),
7171
(36, 38), (29, 54), (50, 15), (14, 28),
7272
(23, 30), (0, 64), (58, 57), (38, 2), (28, 40), (22, 6),
73-
(12, 46), (50, 35), (56, 27)}, 10, set())
74-
])
73+
(12, 46), (50, 35), (56, 27)}, 10, set())])
7574
def test_agents_cleanup(self, agents, n, expected):
7675
"""
7776
Testing a function named agents_cleanup.

kyu_5/find_the_smallest/test_smallest.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ def test_smallest(self, n, expected):
6464
'<h3>Test Description:</h3>'
6565
"<p></p>")
6666
# pylint: enable-msg=R0801
67-
68-
with allure.step(f"Enter test data: {n} "
69-
f"and verify the output vs expected: {expected}."):
67+
with allure.step(f"Enter test data: {n} \
68+
and verify the output vs expected: {expected}."):
7069
result = smallest(n)
7170
print_log(n=n, expected=expected, result=result)
7271
self.assertListEqual(expected, result)

kyu_5/first_non_repeating_character/test_first_non_repeating_letter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_first_non_repeating_letter(self, string, expected):
7474
'<h3>Test Description:</h3>'
7575
"<p></p>")
7676
# pylint: enable-msg=R0801
77-
with allure.step(f"Enter test string: {string} "
78-
f"and verify the output: {expected}"):
77+
with allure.step(f"Enter test string: {string} \
78+
and verify the output: {expected}"):
7979
print_log(string=string, expected=expected)
8080
self.assertEqual(expected, first_non_repeating_letter(string))

kyu_5/human_readable_time/test_make_readable.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_make_readable(self, seconds, expected):
6464
'<h3>Test Description:</h3>'
6565
"<p></p>")
6666
# pylint: enable-msg=R0801
67-
with allure.step(f"Enter test number: {seconds} "
68-
f"and verify the output: {expected}"):
67+
with allure.step(f"Enter test number: {seconds} \
68+
and verify the output: {expected}"):
6969
print_log(seconds=seconds, expected=expected)
7070
self.assertEqual(expected, make_readable(seconds))

kyu_5/integers_recreation_one/test_list_squared.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ class ListSquaredTestCase(unittest.TestCase):
5454
(689, 5666, [[728, 722500], [1434, 2856100], [1673, 2856100],
5555
[1880, 4884100], [4264, 24304900]]),
5656
(257, 4195, [[287, 84100], [728, 722500], [1434, 2856100],
57-
[1673, 2856100], [1880, 4884100]])
58-
])
57+
[1673, 2856100], [1880, 4884100]])])
5958
def test_flatten(self, m, n, expected):
6059
"""
6160
Testing list_squared function.
@@ -74,7 +73,6 @@ def test_flatten(self, m, n, expected):
7473
"all integers between m and n whose sum of squared divisors "
7574
"is itself a square.</p>")
7675
# pylint: enable-msg=R0801
77-
7876
with allure.step("Enter test data and verify the output..."):
7977
actual_result = list_squared(m, n)
8078
print_log(m=m, n=n, expected=expected, actual_result=actual_result)

kyu_5/josephus_survivor/test_josephus_survivor.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,14 @@ def test_josephus_survivor(self, test_data, expected):
6262
"correctly returns who is the \"survivor\", ie: the "
6363
"last element of a Josephus permutation.</p>")
6464
# pylint: enable-msg=R0801
65-
6665
total = test_data[0]
6766
eliminated = test_data[1]
6867
result = josephus_survivor(total, eliminated)
69-
with allure.step(f"Enter test data "
70-
f"(n: {total}, "
71-
f"k: {eliminated}) and verify "
72-
f"the output ({result}) "
73-
f"vs expected ({expected})"):
68+
with allure.step(f"Enter test data \
69+
(n: {total}, \
70+
k: {eliminated}) and verify \
71+
the output ({result}) \
72+
vs expected ({expected})"):
7473

7574
print_log(total=total,
7675
eliminated=eliminated,

kyu_5/master_your_primes_sieve_with_memoization/test_primes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def test_is_primes(self, number, expected):
7676
'<h3>Test Description:</h3>'
7777
"<p></p>")
7878
# pylint: enable-msg=R0801
79-
with allure.step(f"Enter test number: {number} "
80-
f"and verify the output: {expected}."):
79+
with allure.step(f"Enter test number: {number} \
80+
and verify the output: {expected}."):
8181
print_log(number=number, expected=expected)
8282
self.assertEqual(expected, is_prime(number))

kyu_5/moving_zeros_to_the_end/test_move_zeros.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_move_zeros(self, array, expected):
6767
'<h3>Test Description:</h3>'
6868
"<p></p>")
6969
# pylint: enable-msg=R0801
70-
with allure.step(f"Enter test data: {array} "
71-
f"and verify the output: {expected}"):
70+
with allure.step(f"Enter test data: {array} \
71+
and verify the output: {expected}"):
7272
print_log(array=array, expected=expected)
7373
self.assertEqual(expected, move_zeros(array))

kyu_5/not_very_secure/test_alphanumeric.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_alphanumeric(self, password, expected):
6060
'/badges/large">'
6161
'<h3>Test Description:</h3>'
6262
"<p></p>")
63-
# pylint: enable-msg=R0801
63+
# pylint: enable-msg=R0801
6464
with allure.step("Enter test string and verify the output"):
6565
print_log(password=password, expected=expected)
6666
self.assertEqual(expected, alphanumeric(password))

kyu_5/number_of_trailing_zeros_of_n/test_zeros.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_zeros(self, number, expected, message):
5555
'<h3>Test Description:</h3>'
5656
"<p></p>")
5757
# pylint: enable-msg=R0801
58-
with allure.step(f"Enter test number: {number} "
59-
f"and verify the result: {expected}"):
58+
with allure.step(f"Enter test number: {number} \
59+
and verify the result: {expected}"):
6060
print_log(message=message, number=number, expected=expected)
6161
self.assertEqual(expected, zeros(number))

kyu_5/simple_pig_latin/test_pig_it.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_pig_it(self, text, expected):
5353
'<h3>Test Description:</h3>'
5454
"<p></p>")
5555
# pylint: enable-msg=R0801
56-
with allure.step(f"Enter test string: {text} "
57-
f"and verify the output: {expected}"):
56+
with allure.step(f"Enter test string: {text} \
57+
and verify the output: {expected}"):
5858
print_log(expected=expected, text=text)
5959
self.assertEqual(expected, pig_it(text))

kyu_5/sports_league_table_ranking/test_compute_ranks.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,11 @@ def test_compute_ranks(self, number, games, expected):
9696
"scored and those conceded)</li>"
9797
"<li>- Goals scored</li></ul>")
9898
# pylint: enable-msg=R0801
99-
100-
with allure.step(f"Enter a test data: {number, games}"
101-
f" and verify the result: {expected}"):
99+
with allure.step(f"Enter a test data: {number, games}\
100+
and verify the result: {expected}"):
102101
actual_result: list = compute_ranks(number, games)
103102
print_log(number=number,
104103
games=games,
105104
expected=expected,
106105
actual_result=actual_result)
107-
108106
self.assertEqual(expected, actual_result)

kyu_5/string_incrementer/test_increment_string.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ def test_increment_string(self, string, expected):
6767
"should be appended to the new string."
6868
"</p>")
6969
# pylint: enable-msg=R0801
70-
with allure.step(f"Enter test string: {string} "
71-
f"and verify the output: {expected}"):
70+
with allure.step(f"Enter test string: {string} \
71+
and verify the output: {expected}"):
7272
result = increment_string(string)
7373
print_log(string=string, expected=expected, result=result)
7474
self.assertEqual(expected, result)

kyu_5/sum_of_pairs/test_sum_pairs.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ def test_sum_pairs(self, ints, s, expected, message):
7272
"from the left please) in order of appearance that add up "
7373
"to form the sum.</p>")
7474
# pylint: enable-msg=R0801
75-
76-
with allure.step(f"Enter a test list {ints}"
77-
f"and verify the output {expected}."):
75+
with allure.step(f"Enter a test list {ints}\
76+
and verify the output {expected}."):
7877
result = sum_pairs(ints, s)
7978
print_log(ints=ints,
8079
s=s,

kyu_5/the_hashtag_generator/test_generate_hashtag.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ def test_generate_hashtag(self, string, expected, message):
7878
"If the input or the result is an empty string it "
7979
"must return false."
8080
"</p>")
81-
8281
with allure.step("Enter a test string and verify the output:"):
8382
actual_result = generate_hashtag(string)
8483
print_log(string=string,

kyu_5/tic_tac_toe_checker/test_checker.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,16 @@ class IsSolvedTestCase(unittest.TestCase):
2929
"""Testing is_solved function."""
3030

3131
@parameterized.expand([
32-
([[0, 0, 1], [0, 1, 2], [2, 1, 0]], -1, 'not yet finished'),
33-
([[1, 1, 1], [0, 2, 2], [0, 0, 0]], 1, 'winning row'),
34-
([[2, 1, 2], [2, 1, 1], [1, 1, 2]], 1, 'winning column'),
35-
([[2, 1, 2], [2, 1, 1], [1, 2, 1]], 0, 'draw'),
36-
([[1, 2, 0], [0, 1, 2], [0, 0, 1]], 1, 'wining diagonal')])
32+
([[0, 0, 1], [0, 1, 2], [2, 1, 0]], -1,
33+
'not yet finished'),
34+
([[1, 1, 1], [0, 2, 2], [0, 0, 0]], 1,
35+
'winning row'),
36+
([[2, 1, 2], [2, 1, 1], [1, 1, 2]], 1,
37+
'winning column'),
38+
([[2, 1, 2], [2, 1, 1], [1, 2, 1]], 0,
39+
'draw'),
40+
([[1, 2, 0], [0, 1, 2], [0, 0, 1]], 1,
41+
'wining diagonal')])
3742
def test_is_solved(self, board, expected, message):
3843
"""
3944
Testing is_solved function with various test data.
@@ -61,9 +66,8 @@ def test_is_solved(self, board, expected, message):
6166
"<p>The function should return whether the board's "
6267
"current state is solved.</p>")
6368
# pylint: enable-msg=R0801
64-
65-
with allure.step(f"Enter Tic-Tac-Toe board {board}"
66-
f" and verify the output {expected}."):
69+
with allure.step(f"Enter Tic-Tac-Toe board {board}\
70+
and verify the output {expected}."):
6771
result: int = is_solved(board)
6872
print_log(expected=expected, result=result, message=message)
6973
self.assertEqual(expected, result, msg=message)

kyu_5/valid_parentheses/test_valid_parentheses.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_valid_parentheses(self, test_input, expected):
6060
'<h3>Test Description:</h3>'
6161
"<p></p>")
6262
# pylint: enable-msg=R0801
63-
with allure.step(f"Enter test string: {test_input}"
64-
f"and verify the expected output: {expected}."):
63+
with allure.step(f"Enter test string: {test_input}\
64+
and verify the expected output: {expected}."):
6565
print_log(test_input=test_input, expected=expected)
6666
self.assertEqual(expected, valid_parentheses(test_input))

kyu_5/where_my_anagrams_at/test_anagrams.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ class AnagramsTestCase(unittest.TestCase):
3636
['aabb', 'bbaa']),
3737
('racer',
3838
['crazer', 'carer', 'racar', 'caers', 'racer'],
39-
['carer', 'racer'])
40-
])
39+
['carer', 'racer'])])
4140
def test_anagrams(self, string, array, expected):
4241
"""
4342
Testing anagrams function with various test data.
@@ -57,7 +56,7 @@ def test_anagrams(self, string, array, expected):
5756
'<h3>Test Description:</h3>'
5857
"<p></p>")
5958
# pylint: enable=R0801
60-
with allure.step(f"Enter test data: {string, array}"
61-
f" and verify the expected output: {expected}"):
59+
with allure.step(f"Enter test data: {string, array}\
60+
and verify the expected output: {expected}"):
6261
print_log(string=string, array=array, expected=expected)
6362
self.assertListEqual(expected, anagrams(string, array))

0 commit comments

Comments
 (0)