From f3831edb78ab29cb5ef8449b24526dc5f8af3a23 Mon Sep 17 00:00:00 2001 From: Daniel Oluwaluyi Date: Tue, 7 Jan 2025 23:24:32 +0100 Subject: [PATCH 01/15] counting vowels --- solutions/count_vowels.py | 29 ++++++++++++++++++++++++ solutions/tests/test_count_vowels.py | 33 ++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 solutions/count_vowels.py create mode 100644 solutions/tests/test_count_vowels.py diff --git a/solutions/count_vowels.py b/solutions/count_vowels.py new file mode 100644 index 000000000..6b98c023f --- /dev/null +++ b/solutions/count_vowels.py @@ -0,0 +1,29 @@ +def count_vowels(input_string): + """ + Counts the number of vowels in a given string. + + Args: + input_string (str): The string to analyze for vowels. + + Returns: + int: The total number of vowels (a, e, i, o, u) in the string, + including both uppercase and lowercase vowels. + + Example: + >>> count_vowels("Hello, World!") + 3 + >>> count_vowels("Python") + 1 + """ + vowels = "aeiouAEIOU" # List of vowels (both uppercase and lowercase) + count = 0 + for char in input_string: + if char in vowels: + count += 1 + return count + + +# Example usage +if __name__ == "__main__": + input_string = "Hello, how many vowels are here?" + print("Number of vowels:", count_vowels(input_string)) diff --git a/solutions/tests/test_count_vowels.py b/solutions/tests/test_count_vowels.py new file mode 100644 index 000000000..c52ec8633 --- /dev/null +++ b/solutions/tests/test_count_vowels.py @@ -0,0 +1,33 @@ +import unittest + +from count_vowels import count_vowels + + +class TestCountVowels(unittest.TestCase): + def test_empty_string(self): + """Test that an empty string returns 0.""" + self.assertEqual(count_vowels(""), 0) + + def test_no_vowels(self): + """Test a string with no vowels.""" + self.assertEqual(count_vowels("bcdfghjklmnpqrstvwxyz"), 0) + + def test_all_vowels(self): + """Test a string with all vowels (lowercase and uppercase).""" + self.assertEqual(count_vowels("aeiouAEIOU"), 10) + + def test_mixed_string(self): + """Test a string with a mix of vowels and consonants.""" + self.assertEqual(count_vowels("Hello, World!"), 3) + + def test_numeric_and_special_characters(self): + """Test a string with numbers and special characters.""" + self.assertEqual(count_vowels("12345!@#$%^&*()"), 0) + + def test_vowels_in_words(self): + """Test a string with words containing vowels.""" + self.assertEqual(count_vowels("Python programming is fun!"), 8) + + +if __name__ == "__main__": + unittest.main() From 0fd755882caeb99fc880c5f01f4a95a3e8604eab Mon Sep 17 00:00:00 2001 From: Daniel Oluwaluyi Date: Tue, 7 Jan 2025 23:36:35 +0100 Subject: [PATCH 02/15] Temperature converter --- solutions/temperature_converter.py | 35 +++++++++++++++++++ solutions/tests/test_temperature_converter.py | 17 +++++++++ 2 files changed, 52 insertions(+) create mode 100644 solutions/temperature_converter.py create mode 100644 solutions/tests/test_temperature_converter.py diff --git a/solutions/temperature_converter.py b/solutions/temperature_converter.py new file mode 100644 index 000000000..b1a497c76 --- /dev/null +++ b/solutions/temperature_converter.py @@ -0,0 +1,35 @@ +<<<<<<< HEAD +# Function that converts celsius to Fahrenheit +def celsius_to_fahrenheit(celsius): + """ + Converts the inputted temperature from Celsius to Fahrenheit. + + Input: Value in Celsius + Output: Value in Fahrenheit + """ + return (celsius * 9 / 5) + 32 + + +# Get user input +celsius = float(input("Enter temperature in Celsius: ")) + +# Call the function and get the Fahrenheit value +fahrenheit = celsius_to_fahrenheit(celsius) + +# Display the result +print(f"{celsius}°C is equal to {fahrenheit}°F.") +======= +# Program that converts Celsius to Fahrenheit + +# Get input in Celcius + +celsius = float(input("Enter temperature in Celsius: ")) + +# Formular for the conversion + +fahrenheit = (celsius * 9 / 5) + 32 + +# Display result + +print(f"{celsius}C is equal to {fahrenheit}F.") +>>>>>>> 4da8b7b7b62f8b69e442318d1095eb2038729a38 diff --git a/solutions/tests/test_temperature_converter.py b/solutions/tests/test_temperature_converter.py new file mode 100644 index 000000000..82d1eb215 --- /dev/null +++ b/solutions/tests/test_temperature_converter.py @@ -0,0 +1,17 @@ +import unittest + +from temperature_converter import celsius_to_fahrenheit + + +class TestConverter(unittest.TestCase): + def test_positive_temperature(self): + self.assertEqual(celsius_to_fahrenheit(1), 33.8) + + def test_negative_temperature(self): + self.assertEqual(celsius_to_fahrenheit(-1), 30.2) + + def test_float_temperature(self): + self.assertEqual(celsius_to_fahrenheit(32.77), 90.986) + + def test_zero_temperature(self): + self.assertEqual(celsius_to_fahrenheit(0), 32) From f8c3257b78bcbf58adfd157ffd9a0bfc1e92aaa2 Mon Sep 17 00:00:00 2001 From: Daniel Oluwaluyi Date: Sat, 11 Jan 2025 06:18:18 +0100 Subject: [PATCH 03/15] Corrected temperature converter unittest --- .vscode/settings.json | 15 ++++++++++++++- solutions/temperature_converter.py | 15 --------------- solutions/tests/test_count_vowels.py | 2 +- solutions/tests/test_temperature_converter.py | 2 +- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 20b19131b..0667abd28 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -123,5 +123,18 @@ "source.organizeImports.ruff": "explicit" } }, - "cSpell.words": ["doctests", "Hussaini", "Pylint"] + "cSpell.words": [ + "doctests", + "Hussaini", + "Pylint" + ], + "python.testing.unittestArgs": [ + "-v", + "-s", + ".", + "-p", + "test_*.py" + ], + "python.testing.pytestEnabled": false, + "python.testing.unittestEnabled": true } diff --git a/solutions/temperature_converter.py b/solutions/temperature_converter.py index b1a497c76..963743386 100644 --- a/solutions/temperature_converter.py +++ b/solutions/temperature_converter.py @@ -1,4 +1,3 @@ -<<<<<<< HEAD # Function that converts celsius to Fahrenheit def celsius_to_fahrenheit(celsius): """ @@ -18,18 +17,4 @@ def celsius_to_fahrenheit(celsius): # Display the result print(f"{celsius}°C is equal to {fahrenheit}°F.") -======= # Program that converts Celsius to Fahrenheit - -# Get input in Celcius - -celsius = float(input("Enter temperature in Celsius: ")) - -# Formular for the conversion - -fahrenheit = (celsius * 9 / 5) + 32 - -# Display result - -print(f"{celsius}C is equal to {fahrenheit}F.") ->>>>>>> 4da8b7b7b62f8b69e442318d1095eb2038729a38 diff --git a/solutions/tests/test_count_vowels.py b/solutions/tests/test_count_vowels.py index c52ec8633..511c63fb5 100644 --- a/solutions/tests/test_count_vowels.py +++ b/solutions/tests/test_count_vowels.py @@ -1,6 +1,6 @@ import unittest -from count_vowels import count_vowels +from ..count_vowels import count_vowels class TestCountVowels(unittest.TestCase): diff --git a/solutions/tests/test_temperature_converter.py b/solutions/tests/test_temperature_converter.py index 82d1eb215..9a0abae63 100644 --- a/solutions/tests/test_temperature_converter.py +++ b/solutions/tests/test_temperature_converter.py @@ -1,6 +1,6 @@ import unittest -from temperature_converter import celsius_to_fahrenheit +from ..temperature_converter import celsius_to_fahrenheit class TestConverter(unittest.TestCase): From f110ba7441b075b03663ba4f8441c6657b9d3f36 Mon Sep 17 00:00:00 2001 From: Daniel Oluwaluyi Date: Sat, 11 Jan 2025 06:49:31 +0100 Subject: [PATCH 04/15] fixed test errors --- solutions/tests/test_count_vowels.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/tests/test_count_vowels.py b/solutions/tests/test_count_vowels.py index 511c63fb5..09896f86f 100644 --- a/solutions/tests/test_count_vowels.py +++ b/solutions/tests/test_count_vowels.py @@ -26,7 +26,7 @@ def test_numeric_and_special_characters(self): def test_vowels_in_words(self): """Test a string with words containing vowels.""" - self.assertEqual(count_vowels("Python programming is fun!"), 8) + self.assertEqual(count_vowels("Python programming is fun!"), 6) if __name__ == "__main__": From b1ea27870b26b6e8f1cf31c03a6fbabd5ea89277 Mon Sep 17 00:00:00 2001 From: Daniel Oluwaluyi Date: Sat, 11 Jan 2025 07:14:04 +0100 Subject: [PATCH 05/15] Added unittest.main() to the unit test --- solutions/tests/test_temperature_converter.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/solutions/tests/test_temperature_converter.py b/solutions/tests/test_temperature_converter.py index 9a0abae63..48c43a98c 100644 --- a/solutions/tests/test_temperature_converter.py +++ b/solutions/tests/test_temperature_converter.py @@ -15,3 +15,7 @@ def test_float_temperature(self): def test_zero_temperature(self): self.assertEqual(celsius_to_fahrenheit(0), 32) + + +if __name__ == "__main__": + unittest.main() From 1aa2b9d2f0ae0e0bff90f629a8455f6b49abb28d Mon Sep 17 00:00:00 2001 From: Daniel Oluwaluyi Date: Sat, 11 Jan 2025 07:21:11 +0100 Subject: [PATCH 06/15] Added unittest.main() to the main script --- solutions/temperature_converter.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/solutions/temperature_converter.py b/solutions/temperature_converter.py index 963743386..9db1fa47c 100644 --- a/solutions/temperature_converter.py +++ b/solutions/temperature_converter.py @@ -9,11 +9,12 @@ def celsius_to_fahrenheit(celsius): return (celsius * 9 / 5) + 32 -# Get user input -celsius = float(input("Enter temperature in Celsius: ")) +if __name__ == "__main__": + # Get user input + celsius = float(input("Enter temperature in Celsius: ")) -# Call the function and get the Fahrenheit value -fahrenheit = celsius_to_fahrenheit(celsius) + # Call the function and get the Fahrenheit value + fahrenheit = celsius_to_fahrenheit(celsius) # Display the result print(f"{celsius}°C is equal to {fahrenheit}°F.") From 6f2d35c6c68a1018683d28392071a825a00c5565 Mon Sep 17 00:00:00 2001 From: Daniel Oluwaluyi Date: Sat, 11 Jan 2025 07:31:34 +0100 Subject: [PATCH 07/15] Fix import and test issues --- solutions/temperature_converter.py | 8 ++++---- solutions/tests/test_temperature_converter.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/solutions/temperature_converter.py b/solutions/temperature_converter.py index 9db1fa47c..32335d486 100644 --- a/solutions/temperature_converter.py +++ b/solutions/temperature_converter.py @@ -1,4 +1,4 @@ -# Function that converts celsius to Fahrenheit +# Function that converts Celsius to Fahrenheit def celsius_to_fahrenheit(celsius): """ Converts the inputted temperature from Celsius to Fahrenheit. @@ -9,6 +9,7 @@ def celsius_to_fahrenheit(celsius): return (celsius * 9 / 5) + 32 +# Ensure this code block only executes when the script is run directly if __name__ == "__main__": # Get user input celsius = float(input("Enter temperature in Celsius: ")) @@ -16,6 +17,5 @@ def celsius_to_fahrenheit(celsius): # Call the function and get the Fahrenheit value fahrenheit = celsius_to_fahrenheit(celsius) -# Display the result -print(f"{celsius}°C is equal to {fahrenheit}°F.") -# Program that converts Celsius to Fahrenheit + # Display the result + print(f"{celsius}°C is equal to {fahrenheit}°F.") diff --git a/solutions/tests/test_temperature_converter.py b/solutions/tests/test_temperature_converter.py index 48c43a98c..795c410f7 100644 --- a/solutions/tests/test_temperature_converter.py +++ b/solutions/tests/test_temperature_converter.py @@ -1,6 +1,6 @@ import unittest -from ..temperature_converter import celsius_to_fahrenheit +from solutions.temperature_converter import celsius_to_fahrenheit class TestConverter(unittest.TestCase): From 25b24b22f80a46eb0735d286f55f7f6940d2fc6f Mon Sep 17 00:00:00 2001 From: Daniel Oluwaluyi Date: Sat, 11 Jan 2025 07:36:45 +0100 Subject: [PATCH 08/15] testing2 --- solutions/temperature_converter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/temperature_converter.py b/solutions/temperature_converter.py index 32335d486..fc990932d 100644 --- a/solutions/temperature_converter.py +++ b/solutions/temperature_converter.py @@ -12,7 +12,7 @@ def celsius_to_fahrenheit(celsius): # Ensure this code block only executes when the script is run directly if __name__ == "__main__": # Get user input - celsius = float(input("Enter temperature in Celsius: ")) + celsius = float(input("Kindly Enter temperature in Celsius: ")) # Call the function and get the Fahrenheit value fahrenheit = celsius_to_fahrenheit(celsius) From 1085afaf5a3aa7cff3ff608a9a13cb59ee260ad2 Mon Sep 17 00:00:00 2001 From: Daniel Oluwaluyi Date: Sat, 11 Jan 2025 21:26:28 +0100 Subject: [PATCH 09/15] Final temperature converter code --- solutions/temperature_converter.py | 4 ++-- solutions/tests/test_temperature_converter.py | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/solutions/temperature_converter.py b/solutions/temperature_converter.py index fc990932d..b1b0baba4 100644 --- a/solutions/temperature_converter.py +++ b/solutions/temperature_converter.py @@ -1,5 +1,5 @@ # Function that converts Celsius to Fahrenheit -def celsius_to_fahrenheit(celsius): +def temperature_converter(celsius): """ Converts the inputted temperature from Celsius to Fahrenheit. @@ -15,7 +15,7 @@ def celsius_to_fahrenheit(celsius): celsius = float(input("Kindly Enter temperature in Celsius: ")) # Call the function and get the Fahrenheit value - fahrenheit = celsius_to_fahrenheit(celsius) + fahrenheit = temperature_converter(celsius) # Display the result print(f"{celsius}°C is equal to {fahrenheit}°F.") diff --git a/solutions/tests/test_temperature_converter.py b/solutions/tests/test_temperature_converter.py index 795c410f7..d1229b0bf 100644 --- a/solutions/tests/test_temperature_converter.py +++ b/solutions/tests/test_temperature_converter.py @@ -1,20 +1,26 @@ import unittest -from solutions.temperature_converter import celsius_to_fahrenheit +from solutions.temperature_converter import temperature_converter class TestConverter(unittest.TestCase): + """Test to convert temperature""" + def test_positive_temperature(self): - self.assertEqual(celsius_to_fahrenheit(1), 33.8) + """It should return a a positive value""" + self.assertEqual(temperature_converter(1), 33.8) def test_negative_temperature(self): - self.assertEqual(celsius_to_fahrenheit(-1), 30.2) + """It should return a value even when negative inputs are made""" + self.assertEqual(temperature_converter(-1), 30.2) def test_float_temperature(self): - self.assertEqual(celsius_to_fahrenheit(32.77), 90.986) + """It should give an output in spite of the float value""" + self.assertEqual(temperature_converter(32.77), 90.986) def test_zero_temperature(self): - self.assertEqual(celsius_to_fahrenheit(0), 32) + """It gives an output for when input is 0""" + self.assertEqual(temperature_converter(0), 32) if __name__ == "__main__": From 110df48e0cb440836b15b116ec8ebc4cbd6a10fa Mon Sep 17 00:00:00 2001 From: Daniel Oluwaluyi Date: Sat, 11 Jan 2025 21:37:02 +0100 Subject: [PATCH 10/15] Temperature converter final codes --- solutions/temperature_converter.py | 2 +- solutions/tests/test_temperature_converter.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/solutions/temperature_converter.py b/solutions/temperature_converter.py index b1b0baba4..b8b772761 100644 --- a/solutions/temperature_converter.py +++ b/solutions/temperature_converter.py @@ -12,7 +12,7 @@ def temperature_converter(celsius): # Ensure this code block only executes when the script is run directly if __name__ == "__main__": # Get user input - celsius = float(input("Kindly Enter temperature in Celsius: ")) + celsius = float(input("Enter temperature in Celsius: ")) # Call the function and get the Fahrenheit value fahrenheit = temperature_converter(celsius) diff --git a/solutions/tests/test_temperature_converter.py b/solutions/tests/test_temperature_converter.py index d1229b0bf..646b40828 100644 --- a/solutions/tests/test_temperature_converter.py +++ b/solutions/tests/test_temperature_converter.py @@ -19,7 +19,7 @@ def test_float_temperature(self): self.assertEqual(temperature_converter(32.77), 90.986) def test_zero_temperature(self): - """It gives an output for when input is 0""" + """It gives an output for when the input is 0""" self.assertEqual(temperature_converter(0), 32) From 776cb5328437a595ba224a1c4692bf74de3bd21e Mon Sep 17 00:00:00 2001 From: Daniel Oluwaluyi Date: Sun, 12 Jan 2025 09:35:55 +0100 Subject: [PATCH 11/15] Delete solutions/count_vowels.py --- solutions/count_vowels.py | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 solutions/count_vowels.py diff --git a/solutions/count_vowels.py b/solutions/count_vowels.py deleted file mode 100644 index 6b98c023f..000000000 --- a/solutions/count_vowels.py +++ /dev/null @@ -1,29 +0,0 @@ -def count_vowels(input_string): - """ - Counts the number of vowels in a given string. - - Args: - input_string (str): The string to analyze for vowels. - - Returns: - int: The total number of vowels (a, e, i, o, u) in the string, - including both uppercase and lowercase vowels. - - Example: - >>> count_vowels("Hello, World!") - 3 - >>> count_vowels("Python") - 1 - """ - vowels = "aeiouAEIOU" # List of vowels (both uppercase and lowercase) - count = 0 - for char in input_string: - if char in vowels: - count += 1 - return count - - -# Example usage -if __name__ == "__main__": - input_string = "Hello, how many vowels are here?" - print("Number of vowels:", count_vowels(input_string)) From facc34c8bddc7f79bf0aec853865fae7b2516c9b Mon Sep 17 00:00:00 2001 From: Daniel Oluwaluyi Date: Sun, 12 Jan 2025 09:36:31 +0100 Subject: [PATCH 12/15] Delete solutions/tests/test_count_vowels.py --- solutions/tests/test_count_vowels.py | 33 ---------------------------- 1 file changed, 33 deletions(-) delete mode 100644 solutions/tests/test_count_vowels.py diff --git a/solutions/tests/test_count_vowels.py b/solutions/tests/test_count_vowels.py deleted file mode 100644 index 09896f86f..000000000 --- a/solutions/tests/test_count_vowels.py +++ /dev/null @@ -1,33 +0,0 @@ -import unittest - -from ..count_vowels import count_vowels - - -class TestCountVowels(unittest.TestCase): - def test_empty_string(self): - """Test that an empty string returns 0.""" - self.assertEqual(count_vowels(""), 0) - - def test_no_vowels(self): - """Test a string with no vowels.""" - self.assertEqual(count_vowels("bcdfghjklmnpqrstvwxyz"), 0) - - def test_all_vowels(self): - """Test a string with all vowels (lowercase and uppercase).""" - self.assertEqual(count_vowels("aeiouAEIOU"), 10) - - def test_mixed_string(self): - """Test a string with a mix of vowels and consonants.""" - self.assertEqual(count_vowels("Hello, World!"), 3) - - def test_numeric_and_special_characters(self): - """Test a string with numbers and special characters.""" - self.assertEqual(count_vowels("12345!@#$%^&*()"), 0) - - def test_vowels_in_words(self): - """Test a string with words containing vowels.""" - self.assertEqual(count_vowels("Python programming is fun!"), 6) - - -if __name__ == "__main__": - unittest.main() From 75c7462746596f6a793df5192ba645f1972d712f Mon Sep 17 00:00:00 2001 From: Daniel Oluwaluyi Date: Sun, 12 Jan 2025 09:36:48 +0100 Subject: [PATCH 13/15] Delete .vscode/settings.json --- .vscode/settings.json | 140 ------------------------------------------ 1 file changed, 140 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 0667abd28..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,140 +0,0 @@ -{ - // https://vscode-docs.readthedocs.io/en/stable/customization/userandworkspace/#default-settings - //-------- Editor configuration -------- - - // Controls auto save of editors that have unsaved changes.: https://code.visualstudio.com/docs/editor/codebasics#_save-auto-save - "files.autoSave": "onFocusChange", - - // Format a file on save. A formatter must be available. - "editor.formatOnSave": true, - - // Controls whether the editor should automatically format the pasted content. A formatter must be available. - "editor.formatOnPaste": true, - - // Controls whether the editor should render indent quides - "editor.guides.indentation": true, - - // Controls whether the editor should highlight the active indent guide. - "editor.guides.highlightActiveIndentation": true, - - // Controls the rendering size of tabs in characters. Accepted values: "auto", 2, 4, 6, etc. If set to "auto", the value will be guessed when a file is opened. - "editor.tabSize": 2, - - // Defines a default formatter which takes precedence over all other formatter settings. Must be the identifier of an extension contributing a formatter - "editor.defaultFormatter": "esbenp.prettier-vscode", - - // Controls bracket pair colorization is enabled or not - "editor.bracketPairColorization.enabled": true, - - // Controls whether bracket pair guides are enabled or not. (true, active, false) - "editor.guides.bracketPairs": "active", - - // Controls whether horizontal bracket pair guides are enabled or not. - "editor.guides.bracketPairsHorizontal": "active", - - // Controls whether the editor should highlight the active bracket pair. - "editor.guides.highlightActiveBracketPair": true, - - // Controls whether the editor has linked editing enabled. - "editor.linkedEditing": true, - - //-------- HTML configuration -------- - - // Enable/disable auto closing of HTML tags - "html.autoClosingTags": true, - - // Configures if the built-in HTML language suggests HTML5 tags, properties and values. - "html.suggest.html5": true, - - // Defines a default HTML formatter which takes precedence over all other formatter settings. Must be the identifier of an extension contributing a formatter - "[html]": { - "editor.defaultFormatter": "vscode.html-language-features" - }, - - //-------- Emmet configuration -------- - - // Enables completion when you are writing Emmet appreveation. - "html-css-class-completion.enableEmmetSupport": true, - - //-------- JavaScript configuration -------- - - // Enable/disable auto closing of JSX tags. - "javascript.autoClosingTags": true, - - // Enable/disable auto import suggestions. - "javascript.suggest.autoImports": true, - - // Enable/disable automatic updating of import paths when you rename or move a file in VS Code. - "javascript.updateImportsOnFileMove.enabled": "always", - - // Enable/disable suggestoins for paths in import statement and require calls. (change it to false to be able to use Path Intellisense extension) - "javascript.suggest.paths": false, - - //-------- TypeScript configuration -------- - - // Enable/disable auto closing of JSX tags. - "typescript.autoClosingTags": true, - - // Enable/disable auto import suggestions. - "typescript.suggest.autoImports": true, - - // Enable/disable automatic updating of import paths when you rename or move a file in VS Code. - "typescript.updateImportsOnFileMove.enabled": "always", - - // Enable/disable suggestoins for paths in import statement and require calls. (change it to false to be able to use Path Intellisense extension) - "typescript.suggest.paths": false, - - //-------- Work Bench configuration -------- - - // Controls whether a top border is drawn on tabs for editors that have unsaved changes. - "workbench.editor.highlightModifiedTabs": true, - - //-------- Files configuration -------- - - // When enabled, will trim all new lines after the final new line at the end of the file when saving it. - "files.trimFinalNewlines": true, - - // When enabled, insert a new final line at the end of the file when saving it. - "files.insertFinalNewline": true, - - //-------- Live Server configuration -------- - - // Set Custom Port Number of Live Server. Set 0 if you want random port. - "liveServer.settings.port": 5504, - - //-------- Markdown configuration -------- - - // Enable path suggestoins while writing links in markdown files - "markdown.suggest.paths.enabled": true, - - // Defines a default markdown formatter which takes precedence over all other formatter settings. Must be the identifier of an extension contributing a formatter - "[markdown]": { - "editor.defaultFormatter": "DavidAnson.vscode-markdownlint" - }, - - // 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": "explicit", - "source.organizeImports.ruff": "explicit" - } - }, - "cSpell.words": [ - "doctests", - "Hussaini", - "Pylint" - ], - "python.testing.unittestArgs": [ - "-v", - "-s", - ".", - "-p", - "test_*.py" - ], - "python.testing.pytestEnabled": false, - "python.testing.unittestEnabled": true -} From a1b893626318049e9d653ab4b66464695020cf60 Mon Sep 17 00:00:00 2001 From: Daniel Oluwaluyi Date: Sun, 12 Jan 2025 10:25:39 +0100 Subject: [PATCH 14/15] Ammendments madeto the code --- solutions/temperature_converter.py | 54 +++++++++++++------ solutions/tests/test_temperature_converter.py | 48 ++++++++++++----- 2 files changed, 74 insertions(+), 28 deletions(-) diff --git a/solutions/temperature_converter.py b/solutions/temperature_converter.py index b8b772761..948d3ac54 100644 --- a/solutions/temperature_converter.py +++ b/solutions/temperature_converter.py @@ -1,21 +1,45 @@ -# Function that converts Celsius to Fahrenheit -def temperature_converter(celsius): - """ - Converts the inputted temperature from Celsius to Fahrenheit. +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +A module for converting temperatures from Celsius to Fahrenheit. + +Created on 01 Jan 2025 +@author: Daniel Oluwaluyi +""" + +from typing import Union + - Input: Value in Celsius - Output: Value in Fahrenheit +def temperature_converter(celsius: Union[int, float]) -> float: """ - return (celsius * 9 / 5) + 32 + Convert a temperature from Celsius to Fahrenheit. + The formula used is: + Fahrenheit = (Celsius * 9/5) + 32 -# Ensure this code block only executes when the script is run directly -if __name__ == "__main__": - # Get user input - celsius = float(input("Enter temperature in Celsius: ")) + Args: + celsius (int or float): The temperature in Celsius to be converted. - # Call the function and get the Fahrenheit value - fahrenheit = temperature_converter(celsius) + Returns: + float: The equivalent temperature in Fahrenheit. + + Raises: + AssertionError: If the input is not an integer or float. + + Doctests: + >>> celsius_to_fahrenheit(0) + 32.0 + >>> celsius_to_fahrenheit(100) + 212.0 + >>> celsius_to_fahrenheit(-40) + -40.0 + >>> celsius_to_fahrenheit(37) + 98.6 + >>> celsius_to_fahrenheit(15.5) + 59.9 + """ + # Defensive assertion to ensure the input is numeric + assert isinstance(celsius, (int, float)), "Input must be an integer or a float" - # Display the result - print(f"{celsius}°C is equal to {fahrenheit}°F.") + # Convert Celsius to Fahrenheit using the formula + return round((celsius * 9 / 5) + 32, 2) diff --git a/solutions/tests/test_temperature_converter.py b/solutions/tests/test_temperature_converter.py index 646b40828..d5e6f5dcb 100644 --- a/solutions/tests/test_temperature_converter.py +++ b/solutions/tests/test_temperature_converter.py @@ -1,26 +1,48 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Unit tests for the celsius_to_fahrenheit function. + +Created on 01 Jan 2025 +@author: Daniel Oluwaluyi +""" + import unittest from solutions.temperature_converter import temperature_converter -class TestConverter(unittest.TestCase): - """Test to convert temperature""" +class TestCelsiusToFahrenheit(unittest.TestCase): + """A class for testing the celsius_to_fahrenheit function.""" + + def test_freezing_point(self): + """Test the freezing point of water.""" + self.assertEqual(temperature_converter(0), 32.0) - def test_positive_temperature(self): - """It should return a a positive value""" - self.assertEqual(temperature_converter(1), 33.8) + def test_boiling_point(self): + """Test the boiling point of water.""" + self.assertEqual(temperature_converter(100), 212.0) def test_negative_temperature(self): - """It should return a value even when negative inputs are made""" - self.assertEqual(temperature_converter(-1), 30.2) + """Test a negative temperature (Celsius and Fahrenheit are the same at -40).""" + self.assertEqual(temperature_converter(-40), -40.0) + + def test_body_temperature(self): + """Test normal human body temperature.""" + self.assertEqual(temperature_converter(37), 98.6) + + def test_fractional_temperature(self): + """Test a fractional Celsius temperature.""" + self.assertEqual(temperature_converter(15.5), 59.9) - def test_float_temperature(self): - """It should give an output in spite of the float value""" - self.assertEqual(temperature_converter(32.77), 90.986) + def test_large_temperature(self): + """Test a very large Celsius temperature.""" + self.assertEqual(temperature_converter(1000), 1832.0) - def test_zero_temperature(self): - """It gives an output for when the input is 0""" - self.assertEqual(temperature_converter(0), 32) + def test_non_numeric_input(self): + """Test a non-numeric input.""" + with self.assertRaises(AssertionError): + temperature_converter("not a number") if __name__ == "__main__": From 3c6f9ca501150f1360dd4b183213eff82d828ff5 Mon Sep 17 00:00:00 2001 From: Daniel Oluwaluyi Date: Sun, 12 Jan 2025 10:33:27 +0100 Subject: [PATCH 15/15] Adjustments to code --- solutions/temperature_converter.py | 2 +- solutions/tests/test_temperature_converter.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/solutions/temperature_converter.py b/solutions/temperature_converter.py index 948d3ac54..9332422e6 100644 --- a/solutions/temperature_converter.py +++ b/solutions/temperature_converter.py @@ -3,7 +3,7 @@ """ A module for converting temperatures from Celsius to Fahrenheit. -Created on 01 Jan 2025 +Created on 02 Jan 2025 @author: Daniel Oluwaluyi """ diff --git a/solutions/tests/test_temperature_converter.py b/solutions/tests/test_temperature_converter.py index d5e6f5dcb..52803773f 100644 --- a/solutions/tests/test_temperature_converter.py +++ b/solutions/tests/test_temperature_converter.py @@ -3,7 +3,7 @@ """ Unit tests for the celsius_to_fahrenheit function. -Created on 01 Jan 2025 +Created on 02 Jan 2025 @author: Daniel Oluwaluyi """