def test_mux8(self): a = Bus(8) b = Bus(8) select = Wire() out = Bus(8) inputs = Bus([a, b, select]) Mux8(a=a, b=b, select=select, out=out) for x in [0, 1, 2, 10, 42, 64, 77, 99, 100, 127, 128, 196, 254, 255]: for y in [ 0, 1, 2, 3, 5, 20, 25, 33, 50, 101, 127, 128, 250, 254, 255 ]: inputs.reset() a.value = x b.value = y select.value = False # print("test_mux8 SELECT = 0 A =", a.value, "B =", b.value, "OUT =", out.value) self.assertEqual(a.value, out.value, "OUT == A") inputs.reset() a.value = x b.value = y select.value = True # print("test_mux8 SELECT = 1 A =", a.value, "B =", b.value, "OUT =", out.value) self.assertEqual(b.value, out.value, "OUT == B")
def test_add8(self): a = Bus(8) b = Bus(8) out = Bus(8) cin = Wire() cout = Wire() inputs = Bus([a, b, cin]) Add8(a=a, b=b, cin=cin, out=out, cout=cout) a.value = 2 b.value = 3 cin.value = False self.assertEqual(out.value, 5) for x in [0, 1, 2, 10, 42, 64, 77, 99, 100, 127, 128, 196, 254, 255]: for y in [ 0, 1, 2, 3, 5, 20, 25, 33, 50, 101, 127, 128, 250, 254, 255 ]: for z in [0, 1]: inputs.reset() a.value = x b.value = y cin.value = bool(z) # print("test_add8", x, "+", y, "+", z, "=", out.value) self.assertEqual(out.value, (x + y + z) % 256) self.assertIs(cout.value, x + y + z >= 256)
def test_and8(self): a = Bus(8) b = Bus(8) out = Bus(8) And8(a=a, b=b, out=out) a.value = 3 b.value = 6 self.assertEqual(out.value, 2)
def test_not8(self): inp = Bus(8) out = Bus(8) Not8(inp=inp, out=out) inp.value = 42 self.assertEqual(out.value, 213)