Skip to content

Commit 03a7ada

Browse files
committed
test: Add test_anagram.py
1 parent 1b29a1a commit 03a7ada

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

test/test_anagram.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import unittest
2+
3+
from src.anagram import are_anagrams_array, are_anagrams_dict, are_anagrams_sorting
4+
5+
6+
class TestAnagramMethods(unittest.TestCase):
7+
def setUp(self):
8+
self.test_cases = [
9+
("listen", "silent", True),
10+
("triangle", "integral", True),
11+
("apple", "papel", True),
12+
("rat", "car", False),
13+
("night", "thing", True),
14+
("dusty", "study", True),
15+
("hello", "bello", False),
16+
]
17+
18+
def test_are_anagrams_sorting(self):
19+
for str1, str2, expected in self.test_cases:
20+
with self.subTest(str1=str1, str2=str2):
21+
self.assertEqual(
22+
are_anagrams_sorting(str1, str2),
23+
expected,
24+
f"Failed for {str1} and {str2}",
25+
)
26+
27+
def test_are_anagrams_dict(self):
28+
for str1, str2, expected in self.test_cases:
29+
with self.subTest(str1=str1, str2=str2):
30+
self.assertEqual(
31+
are_anagrams_dict(str1, str2),
32+
expected,
33+
f"Failed for {str1} and {str2}",
34+
)
35+
36+
def test_are_anagrams_array(self):
37+
for str1, str2, expected in self.test_cases:
38+
with self.subTest(str1=str1, str2=str2):
39+
self.assertEqual(
40+
are_anagrams_array(str1, str2),
41+
expected,
42+
f"Failed for {str1} and {str2}",
43+
)

0 commit comments

Comments
 (0)