diff --git a/README.md b/README.md index 58025fbb44ec342680b815924844e19162ee3540..bb71c4d7dd27e2eac0b29af64ba04d4097076fc8 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,11 @@ pip install . pytest ``` +#### Test with coverage +``` +pytest --cov=b_asic --cov-report html test +``` + ## Usage How to build and use the library as a user. diff --git a/setup.py b/setup.py index 0b591cbb8cabf6164d19c6a714c9d2c5d08319ea..cfe8605f8badf543b947f1d2b1f15d0ddcacd7aa 100644 --- a/setup.py +++ b/setup.py @@ -71,7 +71,8 @@ setuptools.setup( "pybind11>=2.3.0", "numpy", "install_qt_binding", - "pytest==5.3.4" + "pytest==5.3.4", + "pytest-cov==2.8.1" ], packages = ["b_asic"], ext_modules = [CMakeExtension("b_asic")], diff --git a/test/test_inputport.py b/test/test_inputport.py new file mode 100644 index 0000000000000000000000000000000000000000..0cb3cab9ead9862de4a3f16f42a47cd26bf81a15 --- /dev/null +++ b/test/test_inputport.py @@ -0,0 +1,28 @@ +""" +B-ASIC test suite for Inputport +TODO: More info +""" +from b_asic import InputPort, Signal, SignalSource, SignalDestination, Addition +import pytest + +@pytest.fixture +def signal(): + source = SignalSource(Addition(0), 1) + dest = SignalDestination(Addition(1),2) + return Signal(source, dest) + +def test_connect_multple_signals(signal): + """ + make sure we can only connect one signal to an input port + """ + inp_port = InputPort(0) + inp_port.connect(signal) + + # create new signal + source = SignalSource(Addition(0), 3) + dest = SignalDestination(Addition(1),4) + new_signal = Signal(source, dest) + + inp_port.connect(new_signal) + inp_port.signal_count() == 1 + assert inp_port.signals() == [new_signal] \ No newline at end of file diff --git a/test/test_outputport.py b/test/test_outputport.py new file mode 100644 index 0000000000000000000000000000000000000000..35331670f829da40fa060142f9e68e06aaba2fa5 --- /dev/null +++ b/test/test_outputport.py @@ -0,0 +1,28 @@ +""" +B-ASIC test suite for InputPort +TODO: More info +""" +from b_asic import OutputPort, Signal, SignalSource, SignalDestination, Addition +import pytest + +@pytest.fixture +def signal(): + source = SignalSource(Addition(0), 1) + dest = SignalDestination(Addition(1),2) + return Signal(source, dest) + +def test_connect_multiple_signals(signal): + """ + make sure we can connect multiple signals to an output port + """ + outp_port = OutputPort(0) + outp_port.connect(signal) + + # create new signal + source = SignalSource(Addition(0), 3) + dest = SignalDestination(Addition(1),4) + new_signal = Signal(source, dest) + + outp_port.connect(new_signal) + outp_port.signal_count() == 2 + assert outp_port.signals() == [signal, new_signal] \ No newline at end of file diff --git a/test/test_port.py b/test/test_port.py index 62e17ea5af20a50031b2cae26ad15119b041ae5b..f4e039a98c48828b99285525d359c89dd51b140d 100644 --- a/test/test_port.py +++ b/test/test_port.py @@ -1,9 +1,31 @@ -import b_asic +""" +B-ASIC test suite for Port interface, place all general test cases for abstract class Port here +TODO: More info +""" + +from b_asic import InputPort, OutputPort, Signal, SignalSource, SignalDestination, Addition import pytest @pytest.fixture -def outp_port(): - return b_asic.InputPort(0) +def signal(): + source = SignalSource(Addition(0), 1) + dest = SignalDestination(Addition(1),2) + return Signal(source, dest) + +def test_connect_one_signal_to_port(signal): + port = InputPort(0) + port.connect(signal) + assert len(port.signals()) == 1 + assert port.signal() == signal + +def test_change_port_signal(): + source = SignalSource(Addition(0), 1) + dest = SignalDestination(Addition(1),2) + signal1 = Signal(source, dest) + signal2 = Signal(source, dest) -def test_port(outp_port): - assert outp_port.signals() == [] \ No newline at end of file + port = InputPort(0) + port.connect(signal1) + assert port.signal() == signal1 + port.connect(signal2) + assert port.signal() == signal2 \ No newline at end of file diff --git a/test/test_signal.py b/test/test_signal.py new file mode 100644 index 0000000000000000000000000000000000000000..35d51eb51eb75ec0c619b9137457e95d263dc580 --- /dev/null +++ b/test/test_signal.py @@ -0,0 +1,28 @@ +from b_asic import Signal, SignalSource, SignalDestination +from b_asic.core_operations import Addition +import pytest + +# TODO mock operation +# Use port index + +@pytest.fixture +def operation(): + return Addition(0) + +@pytest.fixture +def signal_dest(operation): + return SignalDestination(operation, 0) + +@pytest.fixture +def signal_src(operation): + return SignalSource(operation, 0) + +def test_construct_source_signal(operation): + s = SignalSource(operation, 0) + assert True + + +def test_construct_signal(): + s = Signal(signal_src, signal_dest) + assert True +