import unittest
from permute import permute
from myhdl import Signal, delay, Simulation, intbv, concat
class TestPermute(unittest.TestCase):
def testA(self):
self.do_a_test(3, (0, 1, 2))
self.do_a_test(4, (3, 2, 0, 1))
self.do_a_test(5, (3, 2, 0, 1, 4))
def do_a_test(self, width, mapping):
def test(a, x, mapping):
for i in range(2 ** len(a)):
a.next = i
yield delay(10)
print "a:", a, "x:", x
for j in range(len(mapping)):
expected_value = 0;
if (i & (1 << mapping[j])):
expected_value = 1;
self.assertEqual(x[j], expected_value)
a = Signal(intbv(0)[width:])
x = Signal(intbv(0)[width:])
dut = permute(a, x, mapping)
check = test(a, x, mapping)
sim = Simulation(dut, check)
sim.run(quiet=1)
unittest.main()