test/constant: use new API
[litex.git] / migen / test / test_constant.py
1 import unittest
2
3 from migen import *
4 from migen.test.support import SimCase
5
6
7 class ConstantCase(SimCase, unittest.TestCase):
8 class TestBench(Module):
9 def __init__(self):
10 self.sigs = [
11 (Signal(3), Constant(0), 0),
12 (Signal(3), Constant(5), 5),
13 (Signal(3), Constant(1, 2), 1),
14 (Signal(3), Constant(-1, 7), 7),
15 (Signal(3), Constant(0b10101)[:3], 0b101),
16 (Signal(3), Constant(0b10101)[1:4], 0b10),
17 ]
18 self.comb += [a.eq(b) for a, b, c in self.sigs]
19
20 def test_comparisons(self):
21 def gen():
22 for s, l, v in self.tb.sigs:
23 s = yield s
24 self.assertEqual(
25 s, int(v),
26 "got {}, want {} from literal {}".format(
27 s, v, l))
28 self.run_with(gen())