diff --git a/.vscode/settings.json b/.vscode/settings.json index 20b19131b..4ab96e711 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,127 +1,126 @@ { - // 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", + // 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, - "editor.codeActionsOnSave": { - "source.fixAll.ruff": "explicit", - "source.organizeImports.ruff": "explicit" + + // 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/count_vowels.py b/solutions/count_vowels.py index 6b98c023f..61c19e7da 100644 --- a/solutions/count_vowels.py +++ b/solutions/count_vowels.py @@ -1,29 +1,46 @@ -def count_vowels(input_string): +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +A module for counting the number of vowels in a given string. + +Created on 29 Dec 2024 +@author: Daniel Oluwaluyi +""" + + +def count_vowels(input_string: str) -> int: """ - Counts the number of vowels in a given string. + Count the number of vowels in the provided string. + + This function takes a string as input and counts the occurrences + of vowels (a, e, i, o, u), including both lowercase and uppercase letters. Args: - input_string (str): The string to analyze for vowels. + input_string (str): The input string to process. 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 + int: The count of vowels in the input string. + + Raises: + AssertionError: If the input is not a string. + + Doctests: + >>> count_vowels("hello") + 2 + >>> count_vowels("HELLO") + 2 + >>> count_vowels("12345!@#$%^&*()") + 0 + >>> count_vowels("aeiouAEIOU") + 10 + >>> count_vowels("") + 0 """ - 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)) + # Defensive assertion to ensure the input is a string + assert isinstance(input_string, str), "Input must be a string" + + # Define a set of vowels for quick lookup + vowels = set("aeiouAEIOU") + + # Count and return the number of vowels in the string + return sum(1 for char in input_string if char in vowels) diff --git a/solutions/tests/test_count_vowels.py b/solutions/tests/test_count_vowels.py index c52ec8633..cc99106c2 100644 --- a/solutions/tests/test_count_vowels.py +++ b/solutions/tests/test_count_vowels.py @@ -1,32 +1,51 @@ -import unittest +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +A module for testing the count_vowels function. + +Created on 29 Dec 2024 +@author: Daniel Oluwaluyi +""" -from count_vowels import count_vowels +import unittest +from solutions.count_vowels import count_vowels class TestCountVowels(unittest.TestCase): + """A class for testing the count_vowels function.""" + def test_empty_string(self): - """Test that an empty string returns 0.""" + """Test the count_vowels function with an empty string.""" self.assertEqual(count_vowels(""), 0) def test_no_vowels(self): - """Test a string with no vowels.""" + """Test the count_vowels function with a string containing no vowels.""" self.assertEqual(count_vowels("bcdfghjklmnpqrstvwxyz"), 0) def test_all_vowels(self): - """Test a string with all vowels (lowercase and uppercase).""" + """Test the count_vowels function with a string containing all vowels.""" self.assertEqual(count_vowels("aeiouAEIOU"), 10) def test_mixed_string(self): - """Test a string with a mix of vowels and consonants.""" + """Test the count_vowels function with a string containing 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.""" + """Test the count_vowels function with a string containing 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) + """Test the count_vowels function with a string containing multiple words.""" + self.assertEqual(count_vowels("Python programming is fun!"), 6) + + def test_string_with_whitespace(self): + """Test the count_vowels function with a string containing leading and trailing whitespace.""" + self.assertEqual(count_vowels(" aeiou "), 5) + + def test_non_string_input(self): + """Test the count_vowels function with a non-string input.""" + with self.assertRaises(AssertionError): + count_vowels(12345) if __name__ == "__main__":