Created
October 31, 2017 07:43
-
-
Save anonymous/85f73244f943d55cc9ac7a9b69444ed7 to your computer and use it in GitHub Desktop.
test_find_all_indexes_with_non_matching_patterns.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!python | |
from strings import contains, find_index, find_all_indexes | |
import unittest | |
class StringsTest(unittest.TestCase): | |
def test_find_all_indexes_with_matching_patterns(self): | |
# Positive test cases (examples) with matching patterns | |
assert find_all_indexes('abc', '') == [0, 1, 2] # all strings contain empty string | |
assert find_all_indexes('abc', 'a') == [0] # single letters are easy | |
assert find_all_indexes('abc', 'b') == [1] | |
assert find_all_indexes('abc', 'c') == [2] | |
assert find_all_indexes('abc', 'ab') == [0] # multiple letters are harder | |
assert find_all_indexes('abc', 'bc') == [1] | |
assert find_all_indexes('abc', 'abc') == [0] # all strings contain themselves | |
assert find_all_indexes('aaa', 'a') == [0, 1, 2] # multiple occurrences | |
assert find_all_indexes('aaa', 'aa') == [0, 1] # overlapping pattern | |
def test_find_all_indexes_with_non_matching_patterns(self): | |
# Negative test cases (counterexamples) with non-matching patterns | |
assert find_all_indexes('abc', 'z') == [] # remember to test other letters | |
assert find_all_indexes('abc', 'ac') == [] # important to test close cases | |
assert find_all_indexes('abc', 'az') == [] # first letter, but not last | |
assert find_all_indexes('abc', 'abz') == [] # first 2 letters, but not last | |
def test_find_all_indexes_with_complex_patterns(self): | |
# Difficult test cases (examples) with complex patterns | |
assert find_all_indexes('ababc', 'abc') == [2] # overlapping prefix | |
assert find_all_indexes('bananas', 'nas') == [4] # overlapping prefix | |
assert find_all_indexes('abcabcabc', 'abc') == [0, 3, 6] # multiple occurrences | |
assert find_all_indexes('abcabcab', 'abc') == [0, 3] # multiple occurrences | |
assert find_all_indexes('abcabcdef', 'abcd') == [3] # overlapping prefix | |
assert find_all_indexes('abcabcdef', 'abcdef') == [3] # overlapping prefix | |
assert find_all_indexes('abcabcdabcde', 'abcde') == [7] # overlapping prefix | |
assert find_all_indexes('abcabcdabcde', 'abcd') == [3, 7] # multiple occurrences, overlapping prefix | |
assert find_all_indexes('abra cadabra', 'abra') == [0, 8] # multiple occurrences | |
assert find_all_indexes('abra cadabra', 'adab') == [6] # overlapping prefix | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment