From 74c9159a0148f88375e461fe6d8bd707c7e2f669 Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Sun, 6 Sep 2015 17:51:59 -0600 Subject: [PATCH] add unittests for Constant --- migen/test/test_constant.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 migen/test/test_constant.py diff --git a/migen/test/test_constant.py b/migen/test/test_constant.py new file mode 100644 index 00000000..11ac5f6b --- /dev/null +++ b/migen/test/test_constant.py @@ -0,0 +1,28 @@ +import unittest + +from migen.fhdl.std import * +from migen.test.support import SimCase, SimBench + + +class ConstantCase(SimCase, unittest.TestCase): + class TestBench(SimBench): + def __init__(self): + self.sigs = [ + (Signal(3), Constant(0), 0), + (Signal(3), Constant(5), 5), + (Signal(3), Constant(1, 2), 1), + (Signal(3), Constant(-1, 7), 7), + (Signal(3), Constant(0b10101)[:3], 0b101), + (Signal(3), Constant(0b10101)[1:4], 0b10), + ] + self.comb += [a.eq(b) for a, b, c in self.sigs] + + def test_comparisons(self): + def cb(tb, tbp): + for s, l, v in tb.sigs: + s = tbp.simulator.rd(s) + self.assertEqual( + s, int(v), + "got {}, want {} from literal {}".format( + s, v, l)) + self.run_with(cb, 1) -- 2.30.2