|
| 1 | +import unittest |
| 2 | +from parameterized import parameterized |
| 3 | +from . import group_anagrams, group_anagrams_naive |
| 4 | + |
| 5 | + |
| 6 | +class GroupAnagramsTestCase(unittest.TestCase): |
| 7 | + @parameterized.expand([ |
| 8 | + ("test_1", ["eat", "beat", "neat", "tea"], [["eat", "tea"], ["beat"], ["neat"]]), |
| 9 | + ("test_2", ["duel", "dule", "speed", "spede", "deul", "cars"], [["duel", "dule", "deul"], ["speed", "spede"], ["cars"]]), |
| 10 | + ("test_3", ["eat","tea","tan","ate","nat","bat"], [["eat","tea","ate"],["tan","nat"],["bat"]]), |
| 11 | + ("test_4", ["word","sword","drow","rowd","iced","dice"], [["word","drow","rowd"],["sword"],["iced","dice"]]), |
| 12 | + ("test_5", ["eat","drink","sleep","repeat"], [["eat"],["drink"],["sleep"],["repeat"]]), |
| 13 | + ("test_6", ["hello","ohlle","dark"], [["hello","ohlle"],["dark"]]) |
| 14 | + ]) |
| 15 | + def test1(self, _, strs, expected): |
| 16 | + actual = group_anagrams(strs) |
| 17 | + self.assertEqual(actual, expected) |
| 18 | + |
| 19 | + @parameterized.expand([ |
| 20 | + ("test_1", ["eat", "beat", "neat", "tea"], [["eat", "tea"], ["beat"], ["neat"]]), |
| 21 | + ("test_2", ["duel", "dule", "speed", "spede", "deul", "cars"], [["duel", "dule", "deul"], ["speed", "spede"], ["cars"]]), |
| 22 | + ("test_3", ["eat","tea","tan","ate","nat","bat"], [["eat","tea","ate"],["tan","nat"],["bat"]]), |
| 23 | + ("test_4", ["word","sword","drow","rowd","iced","dice"], [["word","drow","rowd"],["sword"],["iced","dice"]]), |
| 24 | + ("test_5", ["eat","drink","sleep","repeat"], [["eat"],["drink"],["sleep"],["repeat"]]), |
| 25 | + ("test_6", ["hello","ohlle","dark"], [["hello","ohlle"],["dark"]]) |
| 26 | + ]) |
| 27 | + def test2(self, _, strs, expected): |
| 28 | + actual = group_anagrams_naive(strs) |
| 29 | + self.assertEqual(actual, expected) |
| 30 | + |
| 31 | + def test_1(self): |
| 32 | + strs = ["eat", "beat", "neat", "tea"] |
| 33 | + expected = [["eat", "tea"], ["beat"], ["neat"]] |
| 34 | + actual = group_anagrams(strs) |
| 35 | + self.assertEqual(expected, actual) |
| 36 | + |
| 37 | + def test_2(self): |
| 38 | + strs = ["duel", "dule", "speed", "spede", "deul", "cars"] |
| 39 | + expected = [["duel", "dule", "deul"], ["speed", "spede"], ["cars"]] |
| 40 | + actual = group_anagrams(strs) |
| 41 | + self.assertEqual(expected, actual) |
| 42 | + |
| 43 | + def test_3(self): |
| 44 | + strs = ["eat","tea","tan","ate","nat","bat"] |
| 45 | + expected = [["eat","tea","ate"],["tan","nat"],["bat"]] |
| 46 | + actual = group_anagrams(strs) |
| 47 | + self.assertEqual(expected, actual) |
| 48 | + |
| 49 | + def test_4(self): |
| 50 | + strs = ["word","sword","drow","rowd","iced","dice"] |
| 51 | + expected = [["word","drow","rowd"],["sword"],["iced","dice"]] |
| 52 | + actual = group_anagrams(strs) |
| 53 | + self.assertEqual(expected, actual) |
| 54 | + |
| 55 | + def test_5(self): |
| 56 | + strs = ["eat","drink","sleep","repeat"] |
| 57 | + expected = [["eat"],["drink"],["sleep"],["repeat"]] |
| 58 | + actual = group_anagrams(strs) |
| 59 | + self.assertEqual(expected, actual) |
| 60 | + |
| 61 | + def test_6(self): |
| 62 | + strs = ["hello","ohlle","dark"] |
| 63 | + expected = [["hello","ohlle"],["dark"]] |
| 64 | + actual = group_anagrams(strs) |
| 65 | + self.assertEqual(expected, actual) |
| 66 | + |
| 67 | + |
| 68 | +if __name__ == '__main__': |
| 69 | + unittest.main() |
0 commit comments