diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 20b19131b..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,127 +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"] -} diff --git a/solutions/temperature_converter.py b/solutions/temperature_converter.py new file mode 100644 index 000000000..9332422e6 --- /dev/null +++ b/solutions/temperature_converter.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +A module for converting temperatures from Celsius to Fahrenheit. + +Created on 02 Jan 2025 +@author: Daniel Oluwaluyi +""" + +from typing import Union + + +def temperature_converter(celsius: Union[int, float]) -> float: + """ + Convert a temperature from Celsius to Fahrenheit. + + The formula used is: + Fahrenheit = (Celsius * 9/5) + 32 + + Args: + celsius (int or float): The temperature in Celsius to be converted. + + 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" + + # 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 new file mode 100644 index 000000000..52803773f --- /dev/null +++ b/solutions/tests/test_temperature_converter.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Unit tests for the celsius_to_fahrenheit function. + +Created on 02 Jan 2025 +@author: Daniel Oluwaluyi +""" + +import unittest + +from solutions.temperature_converter import temperature_converter + + +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_boiling_point(self): + """Test the boiling point of water.""" + self.assertEqual(temperature_converter(100), 212.0) + + def test_negative_temperature(self): + """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_large_temperature(self): + """Test a very large Celsius temperature.""" + self.assertEqual(temperature_converter(1000), 1832.0) + + def test_non_numeric_input(self): + """Test a non-numeric input.""" + with self.assertRaises(AssertionError): + temperature_converter("not a number") + + +if __name__ == "__main__": + unittest.main()