Example #1
0
 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)
Example #2
0
 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)
Example #3
0
 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')
Example #4
0
 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')
Example #5
0
 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)
Example #6
0
 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')
Example #7
0
 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')
Example #8
0
 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)
Example #9
0
    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)
Example #10
0
    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)
Example #11
0
 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'))
Example #12
0
 def testZeroReplacements(self):
     """
     The function should return the original string when zero mutations
     are requested.
     """
     self.assertEqual('acgt', mutateString('acgt', 0, 'x'))
Example #13
0
 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'))
Example #14
0
 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'))
Example #15
0
 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'))
Example #16
0
 def testZeroReplacements(self):
     """
     The function should return the original string when zero mutations
     are requested.
     """
     self.assertEqual('acgt', mutateString('acgt', 0, 'x'))