diff --git a/test/fixtures/graph_id.py b/test/fixtures/graph_id.py index af6a37f89d2f9eeab21361a388a608e2c038d182..8cc438a0ce280d4e4d09ad8d63856c79c3453971 100644 --- a/test/fixtures/graph_id.py +++ b/test/fixtures/graph_id.py @@ -16,4 +16,8 @@ def graph_ids(): GraphID("ÅÄÖ", 2), GraphID("", 3), \ GraphID("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 4)] + +@pytest.fixture +def graph_id_generator(): + return GraphIDGenerator() diff --git a/test/graph_id/test_graph_id.py b/test/graph_id/test_graph_id.py index 3de26ca910d58a6ce56a7fb6c9bc3c4c583a35f7..9554c04ce78b6578f256710c0ffefa450587e794 100644 --- a/test/graph_id/test_graph_id.py +++ b/test/graph_id/test_graph_id.py @@ -11,24 +11,26 @@ from b_asic.graph_id import GraphID import pytest def test_create_graph_id(): - """ - Tests creation + """Tests creation of graph ID objects.""" graph_id = GraphID("add", 1) assert graph_id.graph_id_type == "add" assert graph_id.graph_id_number == 1 +def test_create_graph_id_empty_string(): graph_id2 = GraphID("", 2) assert graph_id2.graph_id_type == "" assert graph_id2.graph_id_number == 2 +def test_create_graph_id_long_string(): graph_id3 = GraphID("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 3) assert graph_id3.graph_id_type == "ABCDEFGHIJKLMNOPQRSTUVWXYZ" assert graph_id3.graph_id_number == 3 def test_graph_id_str(graph_ids): + """Test the str() function of graph ids.""" assert str(graph_ids[0]) == "add1" assert str(graph_ids[1]) == "add2" assert str(graph_ids[2]) == "sig1" @@ -39,6 +41,7 @@ def test_graph_id_str(graph_ids): assert str(graph_ids[7]) == "ABCDEFGHIJKLMNOPQRSTUVWXYZ4" def test_graph_id_repr(graph_ids): + """Test the repr() function of graph ids.""" assert repr(graph_ids[0]) == "add1" assert repr(graph_ids[1]) == "add2" assert repr(graph_ids[2]) == "sig1" @@ -49,6 +52,7 @@ def test_graph_id_repr(graph_ids): assert repr(graph_ids[7]) == "ABCDEFGHIJKLMNOPQRSTUVWXYZ4" def test_graph_id_eq(graph_ids): + """Test the equality of graph ids.""" assert graph_ids[0] == graph_ids[0] assert graph_ids[0] != graph_ids[1] assert graph_ids[2] == graph_ids[3] diff --git a/test/graph_id/test_graph_id_generator.py b/test/graph_id/test_graph_id_generator.py new file mode 100644 index 0000000000000000000000000000000000000000..71eb02b0fb369cd1c9b9eb44c1fdbdb0b30c02b7 --- /dev/null +++ b/test/graph_id/test_graph_id_generator.py @@ -0,0 +1,26 @@ +""" +B-ASIC test suite for graph id generator. +""" + +from b_asic.graph_id import GraphIDGenerator, GraphID + +import pytest + +def test_empty_string_generator(graph_id_generator): + """Test the graph id generator for an empty string type.""" + assert graph_id_generator.get_next_id("") == GraphID("", 1) + assert graph_id_generator.get_next_id("") == GraphID("", 2) + + +def test_normal_string_generator(graph_id_generator): + """"Test the graph id generator for a normal string type.""" + assert graph_id_generator.get_next_id("add") == GraphID("add", 1) + assert graph_id_generator.get_next_id("add") == GraphID("add", 2) + +def test_different_strings_generator(graph_id_generator): + """Test the graph id generator for different strings.""" + assert graph_id_generator.get_next_id("sub") == GraphID("sub", 1) + assert graph_id_generator.get_next_id("mul") == GraphID("mul", 1) + assert graph_id_generator.get_next_id("sub") == GraphID("sub", 2) + assert graph_id_generator.get_next_id("mul") == GraphID("mul", 2) + \ No newline at end of file diff --git a/test/port/test_port.py b/test/port/test_port.py index 56cb9be227149c957bf77f73ed4f1301e54fac16..5fcf563d8f6897eb00863e781bff0dfd994801b3 100644 --- a/test/port/test_port.py +++ b/test/port/test_port.py @@ -13,8 +13,8 @@ def test_connect_one_signal_to_port(signal): assert port.signal() == signal def test_change_port_signal(): - source = SignalSource(Addition(0), 1) - dest = SignalDestination(Addition(1),2) + source = SignalSource(Addition, 1) + dest = SignalDestination(Addition,2) signal1 = Signal(1, source, dest) signal2 = Signal(2, source, dest)