From 2d9e3f96c94ffcf1a51646bbb5864fe3b05f62c5 Mon Sep 17 00:00:00 2001 From: SEMIRATESFAI Date: Thu, 2 Jan 2025 17:25:19 -0500 Subject: [PATCH 01/10] create the folders and the init files --- solutions/challenge_9/__init__.py | 0 solutions/tests/challenge_9/__init__.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 solutions/challenge_9/__init__.py create mode 100644 solutions/tests/challenge_9/__init__.py diff --git a/solutions/challenge_9/__init__.py b/solutions/challenge_9/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/solutions/tests/challenge_9/__init__.py b/solutions/tests/challenge_9/__init__.py new file mode 100644 index 000000000..e69de29bb From a14db69279e2a5c62cc72206dcc9432d9d372829 Mon Sep 17 00:00:00 2001 From: SEMIRATESFAI Date: Sat, 4 Jan 2025 21:14:23 -0500 Subject: [PATCH 02/10] add the solution to the sum_of_digits_challenge and the test --- solutions/challenge_9/sum_of_digits.py | 27 +++++++++++++++++++ .../tests/challenge_9/test_sum_of_digits.py | 19 +++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 solutions/challenge_9/sum_of_digits.py create mode 100644 solutions/tests/challenge_9/test_sum_of_digits.py diff --git a/solutions/challenge_9/sum_of_digits.py b/solutions/challenge_9/sum_of_digits.py new file mode 100644 index 000000000..9fd89574c --- /dev/null +++ b/solutions/challenge_9/sum_of_digits.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +A module for calculating the sum of the digits of a positive integer. +Module contents: +sum_of_digits: calculates the sum of the digits of a positive integer. +Created on January 3rd, 2025 +@author: Semira Tesfai +""" + + +def sum_of_digits(n: int) -> int: + """Calculate the sum of the digits of a positive integer. + Parameters: + n: int, the positive integer whose digits will be summed + Returns -> int: the sum of the digits of the given integer + Raises: + AssertionError: if the argument is not a positive integer + >>> sum_of_digits(123) + 6 + >>> sum_of_digits(4567) + 22 + >>> sum_of_digits(0) + 0 + """ + assert isinstance(n, int) and n >= 0, "input must be a positive integer" + return sum(int(digit) for digit in str(n)) diff --git a/solutions/tests/challenge_9/test_sum_of_digits.py b/solutions/tests/challenge_9/test_sum_of_digits.py new file mode 100644 index 000000000..1594e3353 --- /dev/null +++ b/solutions/tests/challenge_9/test_sum_of_digits.py @@ -0,0 +1,19 @@ +import unittest + +from solutions.challenge_9.sum_of_digits import sum_of_digits + + +class TestSumOfDigits(unittest.TestCase): + def test_single_digit(self): + self.assertEqual(sum_of_digits(5), 5) + + def test_multi_digit(self): + self.assertEqual(sum_of_digits(123), 6) + self.assertEqual(sum_of_digits(4567), 22) + + def test_edge_case(self): + self.assertEqual(sum_of_digits(0), 0) + + +if __name__ == "__main__": + unittest.main() From 9b9018bbca2f2e0296aa4ee23795673455b72be7 Mon Sep 17 00:00:00 2001 From: SEMIRATESFAI Date: Fri, 10 Jan 2025 01:13:42 -0500 Subject: [PATCH 03/10] Update sum_of_digits.py Refined sum_of_digits code and tests: added docstrings, improved test cases, and ensured all linting checks passed. --- solutions/challenge_9/sum_of_digits.py | 28 +++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/solutions/challenge_9/sum_of_digits.py b/solutions/challenge_9/sum_of_digits.py index 9fd89574c..b45202a86 100644 --- a/solutions/challenge_9/sum_of_digits.py +++ b/solutions/challenge_9/sum_of_digits.py @@ -2,20 +2,34 @@ # -*- coding: utf-8 -*- """ A module for calculating the sum of the digits of a positive integer. + Module contents: -sum_of_digits: calculates the sum of the digits of a positive integer. + sum_of_digits: calculates the sum of the digits of a positive integer. + Created on January 3rd, 2025 @author: Semira Tesfai """ - def sum_of_digits(n: int) -> int: """Calculate the sum of the digits of a positive integer. - Parameters: - n: int, the positive integer whose digits will be summed - Returns -> int: the sum of the digits of the given integer - Raises: - AssertionError: if the argument is not a positive integer + + Parameters + ---------- + n : int + The positive integer whose digits will be summed. + + Returns + ------- + int + The sum of the digits of the given integer. + + Raises + ------ + AssertionError + If the argument is not a positive integer. + + Examples + -------- >>> sum_of_digits(123) 6 >>> sum_of_digits(4567) From 95d1b7b2ab9d8d4a81feda3e37b6f60180fdd5de Mon Sep 17 00:00:00 2001 From: SEMIRATESFAI Date: Fri, 10 Jan 2025 01:15:25 -0500 Subject: [PATCH 04/10] Update test_sum_of_digits.py Refined sum_of_digits code and tests: added docstrings, improved test cases, and ensured all linting checks passed. --- .../tests/challenge_9/test_sum_of_digits.py | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/solutions/tests/challenge_9/test_sum_of_digits.py b/solutions/tests/challenge_9/test_sum_of_digits.py index 1594e3353..4c10939a3 100644 --- a/solutions/tests/challenge_9/test_sum_of_digits.py +++ b/solutions/tests/challenge_9/test_sum_of_digits.py @@ -1,19 +1,37 @@ -import unittest - -from solutions.challenge_9.sum_of_digits import sum_of_digits +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Unit tests for the sum_of_digits function. +Created on January 3rd, 2025 +""" +import unittest +from sum_of_digits import sum_of_digits class TestSumOfDigits(unittest.TestCase): - def test_single_digit(self): - self.assertEqual(sum_of_digits(5), 5) + """Tests for the sum_of_digits function.""" - def test_multi_digit(self): + def test_positive_integer(self): + """Ensure that the sum of digits of a positive integer is calculated correctly.""" self.assertEqual(sum_of_digits(123), 6) + + def test_large_integer(self): + """Ensure that the sum of digits of a large positive integer is calculated correctly.""" self.assertEqual(sum_of_digits(4567), 22) - def test_edge_case(self): + def test_zero(self): + """Ensure that the sum of digits of zero is zero.""" self.assertEqual(sum_of_digits(0), 0) + def test_invalid_input(self): + """Ensure that the function raises an assertion error for invalid inputs.""" + with self.assertRaises(AssertionError): + sum_of_digits(-5) + with self.assertRaises(AssertionError): + sum_of_digits(4.5) + with self.assertRaises(AssertionError): + sum_of_digits('123') -if __name__ == "__main__": +if __name__ == '__main__': unittest.main() + From 1455cd130a8982483bf0214bb5d3849dd6a08619 Mon Sep 17 00:00:00 2001 From: SEMIRATESFAI Date: Fri, 10 Jan 2025 12:02:21 -0500 Subject: [PATCH 05/10] made changes to the code by adding headings to the steps --- solutions/challenge_9/sum_of_digits.py | 1 + solutions/tests/challenge_9/test_sum_of_digits.py | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/solutions/challenge_9/sum_of_digits.py b/solutions/challenge_9/sum_of_digits.py index b45202a86..587c53d13 100644 --- a/solutions/challenge_9/sum_of_digits.py +++ b/solutions/challenge_9/sum_of_digits.py @@ -10,6 +10,7 @@ @author: Semira Tesfai """ + def sum_of_digits(n: int) -> int: """Calculate the sum of the digits of a positive integer. diff --git a/solutions/tests/challenge_9/test_sum_of_digits.py b/solutions/tests/challenge_9/test_sum_of_digits.py index 4c10939a3..1c7cd8393 100644 --- a/solutions/tests/challenge_9/test_sum_of_digits.py +++ b/solutions/tests/challenge_9/test_sum_of_digits.py @@ -6,7 +6,8 @@ """ import unittest -from sum_of_digits import sum_of_digits +from solutions.challenge_9.sum_of_digits import sum_of_digits + class TestSumOfDigits(unittest.TestCase): """Tests for the sum_of_digits function.""" @@ -30,8 +31,8 @@ def test_invalid_input(self): with self.assertRaises(AssertionError): sum_of_digits(4.5) with self.assertRaises(AssertionError): - sum_of_digits('123') + sum_of_digits("123") -if __name__ == '__main__': - unittest.main() +if __name__ == "__main__": + unittest.main() From 76ba3627d8a75b14c18b97b461ac2c9be3181b67 Mon Sep 17 00:00:00 2001 From: SEMIRATESFAI Date: Sat, 11 Jan 2025 23:04:30 -0500 Subject: [PATCH 06/10] Update test_sum_of_digits.py adding "with" in the test names provides a bit more context about what inputs are being tested against, making the test scenarios clearer and more descriptive for people to read it --- solutions/tests/challenge_9/test_sum_of_digits.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/solutions/tests/challenge_9/test_sum_of_digits.py b/solutions/tests/challenge_9/test_sum_of_digits.py index 1c7cd8393..6539f4613 100644 --- a/solutions/tests/challenge_9/test_sum_of_digits.py +++ b/solutions/tests/challenge_9/test_sum_of_digits.py @@ -12,15 +12,15 @@ class TestSumOfDigits(unittest.TestCase): """Tests for the sum_of_digits function.""" - def test_positive_integer(self): + def test_with_positive_integer(self): """Ensure that the sum of digits of a positive integer is calculated correctly.""" self.assertEqual(sum_of_digits(123), 6) - def test_large_integer(self): + def test_with_large_integer(self): """Ensure that the sum of digits of a large positive integer is calculated correctly.""" self.assertEqual(sum_of_digits(4567), 22) - def test_zero(self): + def test_with_zero(self): """Ensure that the sum of digits of zero is zero.""" self.assertEqual(sum_of_digits(0), 0) From fa9d0449dd92ca71f314a224b392f8f360892773 Mon Sep 17 00:00:00 2001 From: SEMIRATESFAI Date: Sat, 11 Jan 2025 23:23:46 -0500 Subject: [PATCH 07/10] Update sum_of_digits.py Replace the assert statement with an explicit if statement and raise a ValueError in the sum_of_digits function --- solutions/challenge_9/sum_of_digits.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/solutions/challenge_9/sum_of_digits.py b/solutions/challenge_9/sum_of_digits.py index 587c53d13..97849b4e6 100644 --- a/solutions/challenge_9/sum_of_digits.py +++ b/solutions/challenge_9/sum_of_digits.py @@ -38,5 +38,7 @@ def sum_of_digits(n: int) -> int: >>> sum_of_digits(0) 0 """ - assert isinstance(n, int) and n >= 0, "input must be a positive integer" + if not isinstance(n, int) or n < 0: + raise ValueError("input must be a positive integer") + return sum(int(digit) for digit in str(n)) From 8d5f24c30832993f316f86659ec283557eaebaa8 Mon Sep 17 00:00:00 2001 From: SEMIRATESFAI Date: Sun, 12 Jan 2025 10:41:46 -0500 Subject: [PATCH 08/10] replaced the assert statement used for input validation by an explicite if statement and a valueError --- solutions/challenge_9/sum_of_digits.py | 6 ++++-- solutions/tests/challenge_9/test_sum_of_digits.py | 15 ++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/solutions/challenge_9/sum_of_digits.py b/solutions/challenge_9/sum_of_digits.py index 587c53d13..7bb4d7df2 100644 --- a/solutions/challenge_9/sum_of_digits.py +++ b/solutions/challenge_9/sum_of_digits.py @@ -26,7 +26,7 @@ def sum_of_digits(n: int) -> int: Raises ------ - AssertionError + ValueError If the argument is not a positive integer. Examples @@ -38,5 +38,7 @@ def sum_of_digits(n: int) -> int: >>> sum_of_digits(0) 0 """ - assert isinstance(n, int) and n >= 0, "input must be a positive integer" + if not isinstance(n, int) or n < 0: + raise ValueError("input must be a positive integer") + return sum(int(digit) for digit in str(n)) diff --git a/solutions/tests/challenge_9/test_sum_of_digits.py b/solutions/tests/challenge_9/test_sum_of_digits.py index 1c7cd8393..a509212cf 100644 --- a/solutions/tests/challenge_9/test_sum_of_digits.py +++ b/solutions/tests/challenge_9/test_sum_of_digits.py @@ -6,31 +6,32 @@ """ import unittest + from solutions.challenge_9.sum_of_digits import sum_of_digits class TestSumOfDigits(unittest.TestCase): """Tests for the sum_of_digits function.""" - def test_positive_integer(self): + def test_with_positive_integer(self): """Ensure that the sum of digits of a positive integer is calculated correctly.""" self.assertEqual(sum_of_digits(123), 6) - def test_large_integer(self): + def test_with_large_integer(self): """Ensure that the sum of digits of a large positive integer is calculated correctly.""" self.assertEqual(sum_of_digits(4567), 22) - def test_zero(self): + def test_with_zero(self): """Ensure that the sum of digits of zero is zero.""" self.assertEqual(sum_of_digits(0), 0) - def test_invalid_input(self): + def test_with_invalid_input(self): """Ensure that the function raises an assertion error for invalid inputs.""" - with self.assertRaises(AssertionError): + with self.assertRaises(ValueError): sum_of_digits(-5) - with self.assertRaises(AssertionError): + with self.assertRaises(ValueError): sum_of_digits(4.5) - with self.assertRaises(AssertionError): + with self.assertRaises(ValueError): sum_of_digits("123") From 30b0ccec21a2be9cc7b2315809884097b4e2ad72 Mon Sep 17 00:00:00 2001 From: SEMIRATESFAI Date: Sun, 12 Jan 2025 13:21:06 -0500 Subject: [PATCH 09/10] updated changes that were recomended by reviewer --- solutions/challenge_9/sum_of_digits.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/solutions/challenge_9/sum_of_digits.py b/solutions/challenge_9/sum_of_digits.py index c8b58d1cf..a758eaf37 100644 --- a/solutions/challenge_9/sum_of_digits.py +++ b/solutions/challenge_9/sum_of_digits.py @@ -17,7 +17,7 @@ def sum_of_digits(n: int) -> int: Parameters ---------- n : int - The positive integer whose digits will be summed. + The non-negative integer whose digits will be summed. Returns ------- @@ -27,7 +27,7 @@ def sum_of_digits(n: int) -> int: Raises ------ ValueError - If the argument is not a positive integer. + If the argument is not a non-negative integer. Examples -------- @@ -38,13 +38,8 @@ def sum_of_digits(n: int) -> int: >>> sum_of_digits(0) 0 """ -<<<<<<< HEAD + if not isinstance(n, int) or n < 0: - raise ValueError("input must be a positive integer") + raise ValueError("input must be a non-negative integer.") -======= - if not isinstance(n, int) or n < 0: - raise ValueError("input must be a positive integer") - ->>>>>>> fa9d0449dd92ca71f314a224b392f8f360892773 return sum(int(digit) for digit in str(n)) From 12030cf08b3d7c317b6457eb7a00e6afbedee511 Mon Sep 17 00:00:00 2001 From: likechrisss Date: Sun, 12 Jan 2025 18:53:42 -0500 Subject: [PATCH 10/10] Updating name --- collaboration/learning_goals.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collaboration/learning_goals.md b/collaboration/learning_goals.md index 636fbfde0..e8b358af8 100644 --- a/collaboration/learning_goals.md +++ b/collaboration/learning_goals.md @@ -86,7 +86,7 @@ --- -### Chrismy +### Chrismy Augustin - Gain more knowledge and hands-on experience with industry-standard tools and technologies like VS Code, Python, GitHub.