-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_mutate.py
36 lines (28 loc) · 983 Bytes
/
test_mutate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import unittest
import mutate
from bitstring import Bitstring
class TestMutate(unittest.TestCase):
def test_mutation_rate(self):
mutate.mutation_rate = 0.0
for _ in range(10):
x = mutate.mutate(0)
self.assertEqual(x, 0)
mutate.mutation_rate = 1.0
def test_mutate_int(self):
for _ in range(10):
x = mutate.mutate(0)
self.assertIn(x, [-1, 1])
def test_mutate_bitstring(self):
for _ in range(10):
b = Bitstring("1010101")
mutant = mutate.shift_by_bit(b)
self.assertEqual(b.hamming_distance(mutant), 1)
def test_shift_by_one(self):
for _ in range(10):
x = mutate.shift_by_one(0)
self.assertIn(x, [-1, 1])
def test_shift_by_bit(self):
for _ in range(10):
b = Bitstring("1010101")
mutant = mutate.shift_by_bit(b)
self.assertEqual(b.hamming_distance(mutant), 1)