def testFuzzableIsFalse(self): uut = BitFlip(b'\x00\x00', num_bits=3, fuzzable=False) self.assertEqual(uut.num_mutations(), 0) self.assertEqual(self.get_all_mutations(uut), [])
def testExceptionIfNumOfBitsIsNegative(self): with self.assertRaises(KittyException): value = b'\x00' BitFlip(value=value, num_bits=-1)
def testExceptionIfNumOfBitsIsBiggerThanValue(self): with self.assertRaises(KittyException): value = b'\x00' max_len = len(value) * 8 BitFlip(value=value, num_bits=max_len + 1)
def get_field(self, value=b'\x12\x34', num_bits=3): return BitFlip(value=value, num_bits=num_bits)
def _testBase(self, value, num_bits_to_flip, expected_mutations): len_in_bits = len(value) * 8 uut = BitFlip(value=value, num_bits=num_bits_to_flip) self.assertEqual(uut.num_mutations(), len_in_bits - num_bits_to_flip + 1) mutations = map(lambda x: x.tobytes(), self.get_all_mutations(uut)) self.assertEqual(set(mutations), set(expected_mutations))