def testZeroLength(self): """ The function should raise when given an empty string """ error = 'Empty original string passed.' with six.assertRaisesRegex(self, ValueError, error): mutateString('', 1)
def testReplacementLengthOneAppearsInOriginal(self): """ The function should raise when given a replacement string that contains just one letter if that letter also appears in the original. """ error = 'Impossible replacement' with six.assertRaisesRegex(self, ValueError, error): mutateString('x', 1, 'x')
def testDuplicateReplacementLetter(self): """ The function should raise when given a replacement string that contains a duplicate letter. """ error = 'Replacement string contains duplicates' with six.assertRaisesRegex(self, ValueError, error): mutateString('x', 1, 'aa')
def testTooManyMutationsRequested(self): """ The function should raise when asked to perform more mutations than there are in the original string. """ error = 'Cannot make 2 mutations in a string of length 1' with six.assertRaisesRegex(self, ValueError, error): mutateString('x', 2)
def testOneReplacement(self): """ The function should return all possible correct results (and only those results) when one mutation is requested and two outcomes are possible. NOTE: this test is a bit bad because it's non-deterministic. """ possible = set(['ab', 'ba']) seen = set() for _ in range(100): result = mutateString('aa', 1, 'ab') self.assertTrue(result in possible) seen.add(result) self.assertEqual(seen, possible)
def testOneDeterministicReplacement(self): """ The function should return the correct result when one mutation is requested and only one mutation is possible. """ self.assertEqual('c', mutateString('a', 1, 'ac'))
def testZeroReplacements(self): """ The function should return the original string when zero mutations are requested. """ self.assertEqual('acgt', mutateString('acgt', 0, 'x'))
def testFiveDeterminsticReplacements(self): """ The function should return the correct result when five mutations are requested and only one outcome is possible. """ self.assertEqual('ccccc', mutateString('aaaaa', 5, 'ac'))