From faf0f394dd6973e86fcb914c8c669ab463f2caf4 Mon Sep 17 00:00:00 2001
From: Kevin Scott <kevsc634@student.liu.se>
Date: Wed, 26 Feb 2020 15:57:24 +0100
Subject: [PATCH] Updated README, added package for test coverage and added
 some test files

---
 README.md               |  5 +++++
 setup.py                |  3 ++-
 test/test_inputport.py  | 28 ++++++++++++++++++++++++++++
 test/test_outputport.py | 28 ++++++++++++++++++++++++++++
 test/test_port.py       | 32 +++++++++++++++++++++++++++-----
 test/test_signal.py     | 28 ++++++++++++++++++++++++++++
 6 files changed, 118 insertions(+), 6 deletions(-)
 create mode 100644 test/test_inputport.py
 create mode 100644 test/test_outputport.py
 create mode 100644 test/test_signal.py

diff --git a/README.md b/README.md
index 58025fbb..bb71c4d7 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 0b591cbb..cfe8605f 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 00000000..0cb3cab9
--- /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 00000000..35331670
--- /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 62e17ea5..f4e039a9 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 00000000..35d51eb5
--- /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
+
-- 
GitLab