hdl.mem: coerce memory init values to integers.
The coercion is carefully chosen to accept (other than normal ints) instances of e.g. np.int64, but reject instances of e.g. float. See https://stackoverflow.com/a/48940855/254415 for details. Fixes #93.
This commit is contained in:
parent
2423eabc15
commit
58e39f90ce
2 changed files with 18 additions and 6 deletions
|
|
@ -29,11 +29,17 @@ class MemoryTestCase(FHDLTestCase):
|
|||
m = Memory(width=8, depth=4, init=range(4))
|
||||
self.assertEqual(m.init, [0, 1, 2, 3])
|
||||
|
||||
def test_init_wrong(self):
|
||||
def test_init_wrong_count(self):
|
||||
with self.assertRaises(ValueError,
|
||||
msg="Memory initialization value count exceed memory depth (8 > 4)"):
|
||||
m = Memory(width=8, depth=4, init=range(8))
|
||||
|
||||
def test_init_wrong_type(self):
|
||||
with self.assertRaises(TypeError,
|
||||
msg="Memory initialization value at address 1: "
|
||||
"'str' object cannot be interpreted as an integer"):
|
||||
m = Memory(width=8, depth=4, init=[1, "0"])
|
||||
|
||||
def test_read_port_transparent(self):
|
||||
mem = Memory(width=8, depth=4)
|
||||
rdport = mem.read_port()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue