From e07dc5a3ff440d89938bbc2547f0ed2d12646402 Mon Sep 17 00:00:00 2001 From: Luyando Chitindi Date: Sun, 22 Dec 2024 22:30:33 +0200 Subject: [PATCH 1/7] Add is_even and is_positive functions to solutions --- solutions/is_even.py | 58 ++++++++++++++++++++++++++++++++++++++++ solutions/is_positive.py | 58 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 solutions/is_even.py create mode 100644 solutions/is_positive.py diff --git a/solutions/is_even.py b/solutions/is_even.py new file mode 100644 index 000000000..bc2b96d6c --- /dev/null +++ b/solutions/is_even.py @@ -0,0 +1,58 @@ +""" +A module for checking if a number is even. + + +Author: Luyando Ennie Chitindi +Date: 12/22/2024 + + +This module has a function that checks if a number is even. +The function takes an integer as an input and returns a boolean value that +indicates whether the number is divisible by 2. + + +Function: +- is_even(number: int) -> bool + + +Exception: +- Raises TypeError if an input is not an integer. + + +Example: +>>> is_even(4) +True +>>> is_even(3) +False +>>> is_even(0) +True +""" + +def is_even(number: int) -> bool: + """ + This will check if number is even. + + + Argument: + number (int): The number to use to check if it is even. + + + Returns: + bool: Only true if the number is even, false otherwise. + + + Raises: + TypeError: If the argument provided is not an integer. + + + Example: + >>> is_even(6) + True + >>> is_even(7) + False + >>> is_even(0) + True + """ + if not isinstance(number, int): + raise TypeError("Input must be an integer.") + return number % 2 == 0 diff --git a/solutions/is_positive.py b/solutions/is_positive.py new file mode 100644 index 000000000..2a8e7bce2 --- /dev/null +++ b/solutions/is_positive.py @@ -0,0 +1,58 @@ +""" +A module for checking if a number is positive. + + +Author: Luyando Chitindi +Date: 12/22/2024 + + +This module contains a function that deals with checking if a number is positive. +The function will take an integer as an input and returns a boolean value indicating +whether the number is greater than zero. + +Function: +- is positive(number: int) -> bool + + +Exceptions: +-Raises TypeError if the input is not an integer. + + +For Example: +>>> is_positive(5) +True +>>> is_positive(-3) +False +>>> is_positive(0) +False +""" + + +def is_positive(number: int) -> bool: + """ + This will check if the number is positive. + + + Arguments: + number (int): The number to check if it is positive. + + + Returns: + bool: True if the number is positive, false otherwise. + + + Raises: + TypeError: If the argument that is provided is not an integer. + + + Example: + >>> is_positive(10) + True + >>> is_positive(-5) + False + >>> is_positive(0) + False + """ + if not isinstance(number, int): + raise TypeError("Input must be an integer.") + return number > 0 From 84280de25c4dd4fb393d7420f7598f186d534f46 Mon Sep 17 00:00:00 2001 From: Luyando Chitindi Date: Mon, 23 Dec 2024 01:30:33 +0200 Subject: [PATCH 2/7] Removed is_even.py from positive-number-function branch --- solutions/is_even.py | 58 -------------------------------------------- 1 file changed, 58 deletions(-) delete mode 100644 solutions/is_even.py diff --git a/solutions/is_even.py b/solutions/is_even.py deleted file mode 100644 index bc2b96d6c..000000000 --- a/solutions/is_even.py +++ /dev/null @@ -1,58 +0,0 @@ -""" -A module for checking if a number is even. - - -Author: Luyando Ennie Chitindi -Date: 12/22/2024 - - -This module has a function that checks if a number is even. -The function takes an integer as an input and returns a boolean value that -indicates whether the number is divisible by 2. - - -Function: -- is_even(number: int) -> bool - - -Exception: -- Raises TypeError if an input is not an integer. - - -Example: ->>> is_even(4) -True ->>> is_even(3) -False ->>> is_even(0) -True -""" - -def is_even(number: int) -> bool: - """ - This will check if number is even. - - - Argument: - number (int): The number to use to check if it is even. - - - Returns: - bool: Only true if the number is even, false otherwise. - - - Raises: - TypeError: If the argument provided is not an integer. - - - Example: - >>> is_even(6) - True - >>> is_even(7) - False - >>> is_even(0) - True - """ - if not isinstance(number, int): - raise TypeError("Input must be an integer.") - return number % 2 == 0 From 8e42c8768ebeadede5391f31dc632e3693f995f2 Mon Sep 17 00:00:00 2001 From: colevandersWands <18554853+colevandersWands@users.noreply.github.com> Date: Sat, 28 Dec 2024 14:02:25 -0500 Subject: [PATCH 3/7] use ruff as formatter --- .vscode/settings.json | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 5a90e202f..bbda5188d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -113,5 +113,14 @@ }, // Enable/disable update table of contents on save - "markdown.extension.toc.updateOnSave": false + "markdown.extension.toc.updateOnSave": false, + + "[python]": { + "editor.defaultFormatter": "charliermarsh.ruff", + "editor.formatOnSave": true, + "editor.codeActionsOnSave": { + "source.fixAll.ruff": true, + "source.organizeImports.ruff": true + } + } } From 462809144520f72929459c3d1fc6e350cd25bc7e Mon Sep 17 00:00:00 2001 From: Luyando Chitindi Date: Sun, 29 Dec 2024 20:18:34 +0200 Subject: [PATCH 4/7] Add test_is_positive.py from is-even branch --- solutions/tests/test_is_positive.py | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 solutions/tests/test_is_positive.py diff --git a/solutions/tests/test_is_positive.py b/solutions/tests/test_is_positive.py new file mode 100644 index 000000000..cadb586d0 --- /dev/null +++ b/solutions/tests/test_is_positive.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Unit tests for the is_positive function. + +@author: Luyando .E. Chitindi +""" + +import unittest +from solutions.is_positive import is_positive + + +class TestIsPositive(unittest.TestCase): + """Test the is_positive function""" + + def test_positive_number(self): + """It should evaluate 4 to True""" + actual = is_positive(4) + expected = True + self.assertEqual(actual, expected) + + def test_negative_number(self): + """It should evaluate -3 to False""" + actual = is_positive(-3) + expected = False + self.assertEqual(actual, expected) + + def test_zero(self): + """It should evaluate 0 to False""" + actual = is_positive(0) + expected = False + self.assertEqual(actual, expected) + + def test_non_integer_input(self): + """It should raise an assertion error if the argument is not an integer""" + with self.assertRaises(AssertionError): + is_positive(3.5) + + with self.assertRaises(AssertionError): + is_positive("string") + + +if __name__ == "__main__": + unittest.main() From f94e33e3a59a69b563382a9c37c62b9988bdb5db Mon Sep 17 00:00:00 2001 From: Luyando Chitindi Date: Sun, 29 Dec 2024 20:32:02 +0200 Subject: [PATCH 5/7] updated is_positive.py --- solutions/is_positive.py | 76 +++++++++++++++------------------------- 1 file changed, 28 insertions(+), 48 deletions(-) diff --git a/solutions/is_positive.py b/solutions/is_positive.py index 2a8e7bce2..37cb1015c 100644 --- a/solutions/is_positive.py +++ b/solutions/is_positive.py @@ -1,58 +1,38 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- """ -A module for checking if a number is positive. +Created on XX XX XX +A module for checking if an integer is positive. -Author: Luyando Chitindi -Date: 12/22/2024 - - -This module contains a function that deals with checking if a number is positive. -The function will take an integer as an input and returns a boolean value indicating -whether the number is greater than zero. - -Function: -- is positive(number: int) -> bool - - -Exceptions: --Raises TypeError if the input is not an integer. - - -For Example: ->>> is_positive(5) -True ->>> is_positive(-3) -False ->>> is_positive(0) -False +@author: Luyando .E. Chitindi """ def is_positive(number: int) -> bool: """ - This will check if the number is positive. - - - Arguments: - number (int): The number to check if it is positive. - - - Returns: - bool: True if the number is positive, false otherwise. - - - Raises: - TypeError: If the argument that is provided is not an integer. - - - Example: - >>> is_positive(10) - True - >>> is_positive(-5) - False - >>> is_positive(0) - False + This checks if an integer is positive. + + Parameters: + number: int, the number to check + + Returns -> bool: + True if the number is positive, false otherwise. + + Raises: + AssertionError: if the input is not an integer + + Example: + >>> is_positive(4) + True + >>> is_positive(-3) + False + >>> is_positive(0) + False + >>> is_positive("hello") + Traceback (most recent call last): + ... + AssertionError: Input must be an integer. """ - if not isinstance(number, int): - raise TypeError("Input must be an integer.") + assert isinstance(number, int), "Input must be an integer" return number > 0 From ae50aad0427d6c81585183e1ca5e262275fdbbc3 Mon Sep 17 00:00:00 2001 From: Luyando Chitindi Date: Sun, 29 Dec 2024 21:50:57 +0200 Subject: [PATCH 6/7] Resolve conflicts in .vscode/settings.json --- .vscode/settings.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index bbda5188d..c25cbf91b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -122,5 +122,8 @@ "source.fixAll.ruff": true, "source.organizeImports.ruff": true } + }, + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter" } } From f84a739d797934ce79960efb9e84bb3aef80a868 Mon Sep 17 00:00:00 2001 From: Luyando Chitindi Date: Sun, 29 Dec 2024 21:59:48 +0200 Subject: [PATCH 7/7] Resolve conflicts in .vscode/settings.json --- .vscode/settings.json | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index c25cbf91b..058679944 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -114,15 +114,6 @@ // Enable/disable update table of contents on save "markdown.extension.toc.updateOnSave": false, - - "[python]": { - "editor.defaultFormatter": "charliermarsh.ruff", - "editor.formatOnSave": true, - "editor.codeActionsOnSave": { - "source.fixAll.ruff": true, - "source.organizeImports.ruff": true - } - }, "[python]": { "editor.defaultFormatter": "ms-python.black-formatter" }