Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anagram finder #44

Merged
merged 39 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4da5808
Updated test_dummy and fixed Pylint warnings for Anagram-Finder tests
Frank2446-dotcom Jan 7, 2025
8bfcdb5
Updated test_dummy and fixed Pylint warnings for Anagram-Finder tests
Frank2446-dotcom Jan 7, 2025
29e7a74
Complete Anagram Finder implementation with tests and docstrings
Frank2446-dotcom Jan 11, 2025
a61371f
Complete Anagram Finder implementation with tests and docstrings
Frank2446-dotcom Jan 11, 2025
2a7afa2
Complete Anagram Finder implementation with tests and docstrings
Frank2446-dotcom Jan 11, 2025
6815cdc
Complete Anagram Finder implementation with tests and docstrings
Frank2446-dotcom Jan 12, 2025
56e58cc
Complete Anagram Finder implementation with tests and docstrings
Frank2446-dotcom Jan 12, 2025
bbbd711
Added anagram finder files
Frank2446-dotcom Jan 12, 2025
0f321a8
Added anagram finder files
Frank2446-dotcom Jan 12, 2025
5576042
Merge branch 'main' into Anagram-Finder
Frank2446-dotcom Jan 12, 2025
3fd6e39
Delete solutions/Remove_Duplicates.py
Frank2446-dotcom Jan 12, 2025
596e83c
Delete solutions/Swap_letters.py
Frank2446-dotcom Jan 12, 2025
ee3ed85
Delete solutions/Time_Conversion.py
Frank2446-dotcom Jan 12, 2025
5cf7986
Delete solutions/calculate_square_area.py
Frank2446-dotcom Jan 12, 2025
b1f5b2f
Delete solutions/check_number_type.py
Frank2446-dotcom Jan 12, 2025
b8e7d65
Delete solutions/convert_hours_to_minutes.py
Frank2446-dotcom Jan 12, 2025
ff41e76
Delete solutions/convert_to_capital.py
Frank2446-dotcom Jan 12, 2025
8d92e71
Delete solutions/convert_to_uppercase.py
Frank2446-dotcom Jan 12, 2025
de406f7
Delete solutions/is_palindrome.py
Frank2446-dotcom Jan 12, 2025
23ceae8
Delete solutions/sum_of_list.py
Frank2446-dotcom Jan 12, 2025
87cc3be
Delete solutions/merge_dictionaries.py
Frank2446-dotcom Jan 12, 2025
07f01e1
Delete solutions/word_frequency.py
Frank2446-dotcom Jan 12, 2025
4307189
Delete solutions/largest_number.py
Frank2446-dotcom Jan 12, 2025
99b9c12
Delete solutions/tests/test_Remove_Duplicate.py
Frank2446-dotcom Jan 12, 2025
d3d477c
Delete solutions/tests/test_Swap_letters.py
Frank2446-dotcom Jan 12, 2025
3eb1709
Delete solutions/tests/test_Time_Conversion.py
Frank2446-dotcom Jan 12, 2025
2891407
Delete solutions/tests/test_calculate_square_area.py
Frank2446-dotcom Jan 12, 2025
596938d
Delete solutions/tests/test_check_number_type.py
Frank2446-dotcom Jan 12, 2025
9f42d3c
Delete solutions/tests/test_convert_hours_to_minutes.py
Frank2446-dotcom Jan 12, 2025
b206050
Delete solutions/tests/test_convert_to_capital.py
Frank2446-dotcom Jan 12, 2025
d63ba20
Delete solutions/tests/test_convert_to_uppercase.py
Frank2446-dotcom Jan 12, 2025
6435bd1
Delete solutions/tests/test_is_palindrome.py
Frank2446-dotcom Jan 12, 2025
138c90a
Delete solutions/tests/test_largest_number.py
Frank2446-dotcom Jan 12, 2025
bf19fc9
Delete solutions/tests/test_merge_dictionaries.py
Frank2446-dotcom Jan 12, 2025
f0f54b7
Delete solutions/tests/test_sum_of_list.py
Frank2446-dotcom Jan 12, 2025
8512058
Delete solutions/tests/test_word_frequency.py
Frank2446-dotcom Jan 12, 2025
2beadd6
Update README.md
Frank2446-dotcom Jan 12, 2025
e7c7486
Update README.md
Frank2446-dotcom Jan 12, 2025
5908452
Update README.md
Frank2446-dotcom Jan 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,6 @@
"source.fixAll.ruff": "explicit",
"source.organizeImports.ruff": "explicit"
}
}
},
"cSpell.words": ["dcbae"]
}
18 changes: 18 additions & 0 deletions solutions/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
# Solutions

# Solutions Folder

Check failure on line 3 in solutions/README.md

View workflow job for this annotation

GitHub Actions / md_formatting

Multiple top-level headings in the same document [Context: "# Solutions Folder"]

This folder contains implementations for various challenges.

## Challenges

1. **Merge Dictionaries**:
- A utility to merge two dictionaries with conflict resolution.
- See `merge_dictionaries.py` for the implementation.

2. **Anagram Finder**:
- A function to check if two strings are anagrams.
- See `anagram_finder.py` for the implementation.

## Usage

To use any solution, simply import the required function and pass the appropriate arguments.
34 changes: 34 additions & 0 deletions solutions/anagram_finder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Anagram Finder
This script provides a function to determine if two strings are anagrams.
"""


def is_anagram(string1: str, string2: str) -> bool:
Frank2446-dotcom marked this conversation as resolved.
Show resolved Hide resolved
"""
Frank2446-dotcom marked this conversation as resolved.
Show resolved Hide resolved
Check if two strings are anagrams of each other.
Args:
string1 (str): The first string.
string2 (str): The second string.
Returns:
bool: True if the strings are anagrams, False otherwise.
"""
# Normalize strings: convert to lowercase and remove spaces
string1 = "".join(string1.lower().split())
string2 = "".join(string2.lower().split())

# Compare sorted characters
return sorted(string1) == sorted(string2)


Frank2446-dotcom marked this conversation as resolved.
Show resolved Hide resolved
if __name__ == "__main__":
# Example usage
word1 = "listen"
word2 = "silent"
print(f"Are '{word1}' and '{word2}' anagrams? {is_anagram(word1, word2)}")

word3 = "hello"
word4 = "world"
print(f"Are '{word3}' and '{word4}' anagrams? {is_anagram(word3, word4)}")
14 changes: 14 additions & 0 deletions solutions/tests/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
# Tests

This folder contains unit tests for the challenges in the `solutions` module.

## Test Files

- `test_merge_dictionaries.py`: Tests for the Merge Dictionaries challenge.
- `test_anagram_finder.py`: Tests for the Anagram Finder challenge.

## Running Tests

Run the following command to execute all tests:

```bash
python -m unittest discover -s solutions/tests -p "test_*.py"
65 changes: 65 additions & 0 deletions solutions/tests/test_anagram_finder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import unittest

from solutions.anagram_finder import is_anagram
Frank2446-dotcom marked this conversation as resolved.
Show resolved Hide resolved


class TestAnagramFinder(unittest.TestCase):
"""Test cases for the is_anagram function."""

def test_anagrams(self):
"""Test cases for valid anagrams."""
self.assertTrue(is_anagram("listen", "silent"))
self.assertTrue(is_anagram("evil", "vile"))
self.assertTrue(is_anagram("dusty", "study"))
self.assertTrue(is_anagram("night", "thing"))
self.assertTrue(is_anagram("brag", "grab"))
Frank2446-dotcom marked this conversation as resolved.
Show resolved Hide resolved

def test_not_anagrams(self):
"""Test cases for invalid anagrams."""
self.assertFalse(is_anagram("hello", "world"))
self.assertFalse(is_anagram("python", "java"))
self.assertFalse(is_anagram("test", "tess"))
self.assertFalse(is_anagram("abcd", "dcbae"))

def test_case_insensitivity(self):
"""Test that the function is case-insensitive."""
self.assertTrue(is_anagram("Listen", "Silent"))
self.assertTrue(is_anagram("Evil", "Vile"))

def test_different_lengths(self):
"""Test cases where the strings have different lengths."""
self.assertFalse(is_anagram("abc", "ab"))
self.assertFalse(is_anagram("abcd", "abcde"))

def test_empty_strings(self):
"""Test edge cases with empty strings."""
self.assertTrue(is_anagram("", ""))
self.assertFalse(is_anagram("a", ""))
self.assertFalse(is_anagram("", "a"))

def test_special_characters(self):
"""Test cases with special characters and spaces."""
self.assertTrue(is_anagram("a gentleman", "elegant man"))
self.assertTrue(is_anagram("clint eastwood", "old west action"))
self.assertFalse(is_anagram("hello world", "world hello!"))

def test_dummy(self):
"""Dummy test to ensure the test suite runs without errors."""
self.assertEqual(1, 1) # Trivial assertion to satisfy the test framework


if __name__ == "__main__":
# Run the tests and capture results
result = unittest.TextTestRunner().run(
unittest.TestLoader().loadTestsFromTestCase(TestAnagramFinder)
)

# Print the results summary with "Failed: 0"
print("\nTest Summary:")
print(f"Tests Run: {result.testsRun}")
print(f"Failed: {len(result.failures)}")
print(f"Errors: {len(result.errors)}")
if result.wasSuccessful():
print("All tests passed!")
else:
print("Some tests failed.")
Loading