Skip to content

Commit 769e283

Browse files
committed
docs: Add docstring
1 parent a1ba775 commit 769e283

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/anagram.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
This module contains functions to determine if two strings are anagrams.
3+
"""
4+
15
from collections import defaultdict
26

37

@@ -16,9 +20,7 @@ def are_anagrams_sorting(str1, str2):
1620

1721
# Method 2: Using Character Count with defaultdict for both strings
1822
def are_anagrams_dict(str1, str2):
19-
"""
20-
Determines if two strings are anagrams by counting characters with defaultdict for both strings.
21-
"""
23+
"""Determines if two strings are anagrams by counting characters with defaultdict for both strings."""
2224
# Remove whitespace and convert to lowercase for case-insensitive comparison
2325
str1 = str1.replace(" ", "").lower()
2426
str2 = str2.replace(" ", "").lower()
@@ -42,8 +44,8 @@ def are_anagrams_dict(str1, str2):
4244

4345
# Method 3: Using Character Count with Array (assuming ASCII characters)
4446
def are_anagrams_array(str1, str2):
45-
"""
46-
Determines if two strings are anagrams by counting characters with an array.
47+
"""Determines if two strings are anagrams by counting characters with an array.
48+
4749
Assumes only ASCII characters.
4850
"""
4951
# Remove whitespace and convert to lowercase for case-insensitive comparison

test/test_anagram.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
"""Test cases for the anagram module."""
2+
13
import unittest
24

35
from src.anagram import are_anagrams_array, are_anagrams_dict, are_anagrams_sorting
46

57

68
class TestAnagramMethods(unittest.TestCase):
9+
"""Test cases for the anagram module."""
10+
711
def setUp(self):
12+
"""Set up the test cases."""
813
self.test_cases = [
914
("listen", "silent", True),
1015
("triangle", "integral", True),
@@ -16,6 +21,7 @@ def setUp(self):
1621
]
1722

1823
def test_are_anagrams_sorting(self):
24+
"""Test the are_anagrams_sorting function."""
1925
for str1, str2, expected in self.test_cases:
2026
with self.subTest(str1=str1, str2=str2):
2127
self.assertEqual(
@@ -25,6 +31,7 @@ def test_are_anagrams_sorting(self):
2531
)
2632

2733
def test_are_anagrams_dict(self):
34+
"""Test the are_anagrams_dict function."""
2835
for str1, str2, expected in self.test_cases:
2936
with self.subTest(str1=str1, str2=str2):
3037
self.assertEqual(
@@ -34,6 +41,7 @@ def test_are_anagrams_dict(self):
3441
)
3542

3643
def test_are_anagrams_array(self):
44+
"""Test the are_anagrams_array function."""
3745
for str1, str2, expected in self.test_cases:
3846
with self.subTest(str1=str1, str2=str2):
3947
self.assertEqual(

0 commit comments

Comments
 (0)