-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from transactron.testing import * | ||
from transactron.utils.amaranth_ext import min_value | ||
import random | ||
|
||
|
||
class MinValueCircuit(Elaboratable): | ||
def __init__(self, bits: int, num: int): | ||
self.inputs = [Signal(bits) for _ in range(num)] | ||
self.output = Signal(bits) | ||
|
||
def elaborate(self, platform): | ||
m = Module() | ||
|
||
m.d.comb += self.output.eq(min_value(m, self.inputs)) | ||
|
||
return m | ||
|
||
|
||
class TestMinValue(TestCaseWithSimulator): | ||
def test_min_value(self): | ||
bits = 4 | ||
num = 3 | ||
num_tests = 100 | ||
|
||
circ = MinValueCircuit(bits, num) | ||
|
||
async def testbench(sim: TestbenchContext): | ||
for _ in range(num_tests): | ||
vals = [random.randrange(2**bits) for _ in circ.inputs] | ||
for sig, val in zip(circ.inputs, vals): | ||
sim.set(sig, val) | ||
assert sim.get(circ.output) == min(vals) | ||
await sim.tick() | ||
|
||
with self.run_simulation(circ) as sim: | ||
sim.add_testbench(testbench) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters