def test_first_index_in_set(self): """first_index_in_set should return index of first occurrence """ vowels = 'aeiou' s1 = 'ebcua' s2 = 'bcbae' s3 = '' s4 = 'cbd' self.assertEqual(first_index_in_set(s1, vowels), 0) self.assertEqual(first_index_in_set(s2, vowels), 3) self.assertEqual(first_index_in_set(s3, vowels), None) self.assertEqual(first_index_in_set(s4, vowels), None)
def test_first_index_in_set(self): """first_index_in_set should return index of first occurrence """ vowels = "aeiou" s1 = "ebcua" s2 = "bcbae" s3 = "" s4 = "cbd" self.assertEqual(first_index_in_set(s1, vowels), 0) self.assertEqual(first_index_in_set(s2, vowels), 3) self.assertEqual(first_index_in_set(s3, vowels), None) self.assertEqual(first_index_in_set(s4, vowels), None)
def firstNotInAlphabet(self, sequence, alphabet=None): """Returns index of first item not in alphabet, or None. Defaults to self.Alphabet if alphabet not supplied. """ if alphabet is None: alphabet = self.Alphabet return first_index_in_set(sequence, alphabet)
def isValidOnAlphabet(self, sequence, alphabet=None): """Returns True if sequence contains only items in alphabet. Alphabet can actually be anything that implements __contains__. Defaults to self.Alphabet if not supplied. """ if alphabet is None: alphabet = self.Alphabet return first_index_in_set(sequence, alphabet) is not None