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
def contains(subseq, inseq): | |
return any(inseq[pos:pos + len(subseq)] == subseq for pos in range(0, len(inseq) - len(subseq) + 1)) | |
class TestContainsForString(unittest.TestCase): | |
def test_smoketest(self): | |
self.assertTrue(contains('abc', 'abc cde fgi')) | |
def testcontains_middle_seq(self): | |
self.assertTrue(contains('cde', 'abc cde fgi')) | |
def testcontains_end_seq(self): | |
self.assertTrue(contains('fgi', 'abc cde fgi')) | |
def testcontains_oversized_seq(self): | |
self.assertFalse(contains('abc cde fgi!', 'abc cde fgi')) | |
def testcontains_iteslf(self): | |
self.assertTrue(contains('abc cde fgi', 'abc cde fgi')) | |
class TestContainsForList(unittest.TestCase): | |
def test_smoketest(self): | |
self.assertTrue(contains('ab c'.split(' '), 'ab c cde fgi'.split(' '))) | |
def testcontains_middle_seq(self): | |
self.assertTrue(contains('cd e'.split(' '), 'abc cd e fgi'.split(' '))) | |
def testcontains_end_seq(self): | |
self.assertTrue(contains('f gi'.split(' '), 'abc cde f gi'.split(' '))) | |
def testcontains_oversized_seq(self): | |
self.assertFalse(contains('abc cde fgi fgi'.split(' '), 'abc cde fgi'.split(' '))) | |
def testcontains_iteslf(self): | |
self.assertTrue(contains(*['abc cde fgi'] * 2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment