Skip to content

Commit

Permalink
Fixed AndOrBlock tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DiamondJoseph committed Aug 16, 2023
1 parent d613667 commit e7e9a62
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions tests/zebra/zebra.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from tickit.core.typedefs import ComponentID, SimTime

from tickit_devices.zebra.and_or_block import AndOrBlockConfig
from tickit_devices.zebra.and_or_block import AndOrBlock

all_true = 15
one_false = 14
Expand All @@ -17,10 +17,10 @@
@pytest.mark.parametrize("inverted", varying_values_of_true)
def test_and_block_enabled_or_inverted(enabled: int, inverted: int):
name = ComponentID("AND1")
params = {f"{name}_ENA": enabled, f"{name}_INV": inverted}
mux = {f"INP{i + 1}": True for i in range(4)}
block = AndOrBlockConfig(name, params)()
out = block.on_tick(SimTime(0), mux)
block = AndOrBlock(name=name)
block.params = {f"{name}_ENA": enabled, f"{name}_INV": inverted}
out = block.update(SimTime(0), mux)
assert out.outputs == {
"OUT": enabled + inverted == all_true
} # All devices either enabled or inverted
Expand All @@ -30,10 +30,10 @@ def test_and_block_enabled_or_inverted(enabled: int, inverted: int):
@pytest.mark.parametrize("inverted", varying_values_of_true)
def test_or_block_enabled_or_inverted(enabled: int, inverted: int):
name = ComponentID("OR1")
params = {f"{name}_ENA": enabled, f"{name}_INV": inverted}
block = AndOrBlock(name=name)
block.params = {f"{name}_ENA": enabled, f"{name}_INV": inverted}
mux = {f"INP{i + 1}": True for i in range(4)}
block = AndOrBlockConfig(name, params)()
out = block.on_tick(SimTime(0), mux)
out = block.update(SimTime(0), mux)
assert out.outputs == {
"OUT": enabled != inverted
} # At least one device exclusively enabled or inverted
Expand All @@ -42,18 +42,18 @@ def test_or_block_enabled_or_inverted(enabled: int, inverted: int):
@pytest.mark.parametrize("high", varying_values_of_true)
def test_all_enabled_and_block_for_inputs(high: int):
name = ComponentID("AND1")
params = {f"{name}_ENA": 15, f"{name}_INV": 0}
block = AndOrBlock(name=name)
block.params = {f"{name}_ENA": all_true, f"{name}_INV": all_false}
mux = {f"INP{i + 1}": bool(high & (1 << i)) for i in range(4)}
block = AndOrBlockConfig(name, params)()
out = block.on_tick(SimTime(0), mux)
out = block.update(SimTime(0), mux)
assert out.outputs == {"OUT": high == all_true} # All inputs high


@pytest.mark.parametrize("high", varying_values_of_true)
def test_all_enabled_or_block_for_inputs(high: int):
name = ComponentID("OR1")
params = {f"{name}_ENA": 15, f"{name}_INV": 0}
block = AndOrBlock(name=name)
block.params = {f"{name}_ENA": all_true, f"{name}_INV": all_false}
mux = {f"INP{i + 1}": bool(high & (1 << i)) for i in range(4)}
block = AndOrBlockConfig(name, params)()
out = block.on_tick(SimTime(0), mux)
out = block.update(SimTime(0), mux)
assert out.outputs == {"OUT": high != all_false} # At least one input high

0 comments on commit e7e9a62

Please sign in to comment.