def test_pattern_exists_in_string_and_returns_first_occurrence(self):
     """Test to confirm that if the pattern exists multiple times in the 
     string, that the Rabin-Karp algorithm returns the index of the first occurrence
     of the pattern.
     """
     self.assertTrue(self.pattern2 in self.string2)
     self.assertTrue(self.string2.count(self.pattern2) > 1)
     self.assertEqual(3, rabin_karp(self.pattern2, self.string2))
Ejemplo n.º 2
0
 def test_rabin_karp(self):
     self.assertEqual(3, rabin_karp("abc", "zsnabckfkd"))
     self.assertEqual(None, rabin_karp("abc", "zsnajkskfkd"))
 def test_pattern_exists_in_string(self):
     """Test to confirm that if the pattern exists in the string, that
     the Rabin-Karp algorithm returns the starting index of the pattern.
     """
     self.assertTrue(self.pattern1 in self.string1)
     self.assertEqual(2, rabin_karp(self.pattern1, self.string1))
 def test_pattern_not_in_string(self):
     """Test to confirm that if the pattern does not exist in the string
     that the Rabin-Karp algorithm returns -1.
     """
     self.assertTrue(self.pattern3 not in self.string3)
     self.assertEqual(-1, rabin_karp(self.pattern3, self.string3))
 def test_pattern_string_longer_than_large_string(self):
     """Test to confirm that if the pattern string is longer than the
     large string that the Rabin-Karp algorithm returns -1.
     """
     pattern = "a" * 20
     self.assertEqual(-1, rabin_karp(pattern, self.string1))
 def test_large_string_is_empty(self):
     """Test to confirm that if the large string is an empty string,
     the Rabin-Karp algorithm returns -1.
     """
     self.assertEqual(-1, rabin_karp(self.pattern1, ""))
 def test_pattern_string_is_empty(self):
     """Test to confirm that if the pattern string is an empty string,
     the Rabin-Karp algorithm returns -1.
     """
     self.assertEqual(-1, rabin_karp("", self.string1))