Skip to content

Commit aa90206

Browse files
📝 Add docstrings to feat/algorithms-tournament-winner
Docstrings generation was requested by @BrianLusina. * #93 (comment) The following files were modified: * `algorithms/arrays/sorted_squared_array/test_sorted_squared_array.py` * `puzzles/arrays/tournament_winner/__init__.py` * `puzzles/arrays/tournament_winner/test_tournament_winner.py`
1 parent 36dfa6e commit aa90206

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

algorithms/arrays/sorted_squared_array/test_sorted_squared_array.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ def test_1(self):
1111
self.assertEqual(expected, actual)
1212

1313
def test_2(self):
14-
"""for an input of [1] it should return [1]"""
14+
"""
15+
Tests that `sorted_squared_array` returns `[1]` when given a single-element input `[1]`.
16+
"""
1517
input_array = [1]
1618
expected = [1]
1719
actual = sorted_squared_array(input_array)
1820
self.assertEqual(expected, actual)
1921

2022
def test_3(self):
21-
"""for an input of [-7,-3,2,3,11] it should return [4,9,9,49,121]"""
23+
"""
24+
Test that `sorted_squared_array` correctly returns a sorted list of squares for an input containing both negative and positive integers.
25+
"""
2226
input_array = [-7,-3,2,3,11]
2327
expected = [4,9,9,49,121]
2428
actual = sorted_squared_array(input_array)
@@ -27,21 +31,27 @@ def test_3(self):
2731

2832
class SortedSquaredArray2TestCases(unittest.TestCase):
2933
def test_1(self):
30-
"""for an input of [1,2,3,5,6,8,9] it should return [1, 4, 9,25, 36, 64, 81]"""
34+
"""
35+
Test that `sorted_squared_array_2` returns the sorted squares of a list of positive integers.
36+
"""
3137
input_array = [1, 2, 3, 5, 6, 8, 9]
3238
expected = [1, 4, 9, 25, 36, 64, 81]
3339
actual = sorted_squared_array_2(input_array)
3440
self.assertEqual(expected, actual)
3541

3642
def test_2(self):
37-
"""for an input of [1] it should return [1]"""
43+
"""
44+
Test that `sorted_squared_array_2` returns `[1]` when given a single-element input `[1]`.
45+
"""
3846
input_array = [1]
3947
expected = [1]
4048
actual = sorted_squared_array_2(input_array)
4149
self.assertEqual(expected, actual)
4250

4351
def test_3(self):
44-
"""for an input of [-7,-3,2,3,11] it should return [4,9,9,49,121]"""
52+
"""
53+
Test that sorted_squared_array_2 correctly returns the sorted squares of a mixed-sign integer array.
54+
"""
4555
input_array = [-7,-3,2,3,11]
4656
expected = [4,9,9,49,121]
4757
actual = sorted_squared_array_2(input_array)

puzzles/arrays/tournament_winner/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
def tournament_winner(competitions: List[List[str]], results: List[int]) -> str:
55
# We need to store a dictionary with the name of the team as the key and the number of points as the value
66
# 3 points for a win, 0 points for a loss
7+
"""
8+
Determines the winner of a tournament based on match results.
9+
10+
Parameters:
11+
competitions (List[List[str]]): Each sublist contains two team names, representing a match between a home and away team.
12+
results (List[int]): Each integer corresponds to the outcome of the match at the same index in `competitions` (0 for away team win, 1 for home team win).
13+
14+
Returns:
15+
str: The name of the team with the highest total points at the end of the tournament.
16+
"""
717
winner = ""
818
teams: Dict[str, int] = {}
919
for competition, result in zip(competitions, results):

puzzles/arrays/tournament_winner/test_tournament_winner.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
class TournamentWinnerTestCase(unittest.TestCase):
55
def test_1(self):
6+
"""
7+
Test that `tournament_winner` returns the correct winner for a sample set of competitions and results.
8+
"""
69
competitions = [["HTML", "C#"], ["C#", "Python"], ["Python", "HTML"]]
710
results = [0, 0, 1]
811
expected = "Python"

0 commit comments

Comments
 (0)