|
9 | 9 | int_to_roman, |
10 | 10 | is_palindrome, is_palindrome_reverse, |
11 | 11 | is_palindrome_two_pointer, is_palindrome_stack, |
12 | | - is_rotated, |
| 12 | + is_rotated, is_rotated_v1, |
13 | 13 | license_number, |
14 | 14 | make_sentence, |
15 | 15 | is_merge_recursive, is_merge_iterative, |
|
32 | 32 | count_binary_substring, |
33 | 33 | repeat_string, |
34 | 34 | text_justification, |
35 | | - min_distance |
| 35 | + min_distance, |
| 36 | + longest_common_prefix_v1, longest_common_prefix_v2, longest_common_prefix_v3, |
| 37 | + rotate, |
| 38 | + first_unique_char, |
| 39 | + repeat_substring |
36 | 40 | ) |
37 | 41 |
|
38 | 42 | import unittest |
@@ -201,6 +205,21 @@ def test_is_rotated(self): |
201 | 205 | self.assertFalse(is_rotated("hello", "lloh")) |
202 | 206 | self.assertTrue(is_rotated("", "")) |
203 | 207 |
|
| 208 | + def test_is_rotated_v1(self): |
| 209 | + self.assertTrue(is_rotated_v1("hello", "hello")) |
| 210 | + self.assertTrue(is_rotated_v1("hello", "llohe")) |
| 211 | + self.assertFalse(is_rotated_v1("hello", "helol")) |
| 212 | + self.assertFalse(is_rotated_v1("hello", "lloh")) |
| 213 | + self.assertTrue(is_rotated_v1("", "")) |
| 214 | + |
| 215 | + |
| 216 | +class TestRotated(unittest.TestCase): |
| 217 | + def test_rotate(self): |
| 218 | + self.assertEqual("llohe", rotate("hello", 2)) |
| 219 | + self.assertEqual("hello", rotate("hello", 5)) |
| 220 | + self.assertEqual("elloh", rotate("hello", 6)) |
| 221 | + self.assertEqual("llohe", rotate("hello", 7)) |
| 222 | + |
204 | 223 |
|
205 | 224 | class TestLicenseNumber(unittest.TestCase): |
206 | 225 | """[summary] |
@@ -475,6 +494,29 @@ def test_min_distance(self): |
475 | 494 | self.assertEqual(2, min_distance("sea", "eat")) |
476 | 495 | self.assertEqual(6, min_distance("abAlgocrithmf", "Algorithmmd")) |
477 | 496 |
|
| 497 | +class TestLongestCommonPrefix(unittest.TestCase): |
| 498 | + def test_longest_common_prefix(self): |
| 499 | + # Test first solution |
| 500 | + self.assertEqual("fl", longest_common_prefix_v1(["flower","flow","flight"])) |
| 501 | + self.assertEqual("", longest_common_prefix_v1(["dog","racecar","car"])) |
| 502 | + # Test second solution |
| 503 | + self.assertEqual("fl", longest_common_prefix_v2(["flower","flow","flight"])) |
| 504 | + self.assertEqual("", longest_common_prefix_v2(["dog","racecar","car"])) |
| 505 | + # Test third solution |
| 506 | + self.assertEqual("fl", longest_common_prefix_v3(["flower","flow","flight"])) |
| 507 | + self.assertEqual("", longest_common_prefix_v3(["dog","racecar","car"])) |
| 508 | + |
| 509 | +class TestFirstUniqueChar(unittest.TestCase): |
| 510 | + def test_first_unique_char(self): |
| 511 | + self.assertEqual(0, first_unique_char("leetcode")) |
| 512 | + self.assertEqual(2, first_unique_char("loveleetcode")) |
| 513 | + |
| 514 | +class TestRepeatSubstring(unittest.TestCase): |
| 515 | + def test_repeat_substring(self): |
| 516 | + self.assertTrue(repeat_substring("abab")) |
| 517 | + self.assertFalse(repeat_substring("aba")) |
| 518 | + self.assertTrue(repeat_substring("abcabcabcabc")) |
| 519 | + |
478 | 520 |
|
479 | 521 | if __name__ == "__main__": |
480 | 522 | unittest.main() |
0 commit comments