def testUniqueCodeWords(self): """ Check that all codewords occur exactly once """ def test(B, G, width): actual = [] for i in range(2**width): B.next = intbv(i) yield delay(10) actual.append(int(G)) actual.sort() expected = list(range(2**width)) self.assertEqual(actual, expected) for width in range(1, MAX_WIDTH): B = Signal(intbv(1)) G = Signal(intbv(0)) dut = bin2gray(B, G, width) check = test(B, G, width) sim = Simulation(dut, check) sim.run(quiet=1)
def testSingleBitChange(self): """ Check that only one bit changes in successive codewords """ def test(B, G, width): B.next = intbv(0) yield delay(10) for i in range(1, 2**width): G_Z.next = G B.next = intbv(i) yield delay(10) diffcode = bin(G ^ G_Z) self.assertEqual(diffcode.count('1'), 1) for width in range(1, MAX_WIDTH): B = Signal(intbv(1)) G = Signal(intbv(0)) G_Z = Signal(intbv(0)) dut = bin2gray(B, G, width) check = test(B, G, width) sim = Simulation(dut, check) sim.run(quiet=1)