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