diff --git a/test/AllPairs/expected/correctness-expected.txt b/test/AllPairs/expected/correctness-expected.txt new file mode 100644 index 00000000..ff26bb2f --- /dev/null +++ b/test/AllPairs/expected/correctness-expected.txt @@ -0,0 +1,3 @@ +A B +A E +B C \ No newline at end of file diff --git a/test/AllPairs/expected/out.txt b/test/AllPairs/expected/sample-out-expected.txt similarity index 100% rename from test/AllPairs/expected/out.txt rename to test/AllPairs/expected/sample-out-expected.txt diff --git a/test/AllPairs/input/correctness-network.txt b/test/AllPairs/input/correctness-network.txt index cb602119..2857ee44 100644 --- a/test/AllPairs/input/correctness-network.txt +++ b/test/AllPairs/input/correctness-network.txt @@ -1,4 +1,6 @@ #Node1 Node2 A B 1 B C 1 -C D 1 \ No newline at end of file +C D 1 +D E 1 +A E 1 \ No newline at end of file diff --git a/test/AllPairs/input/correctness-nodetypes.txt b/test/AllPairs/input/correctness-nodetypes.txt index 5799a50d..5a1e231d 100644 --- a/test/AllPairs/input/correctness-nodetypes.txt +++ b/test/AllPairs/input/correctness-nodetypes.txt @@ -2,4 +2,4 @@ A source B source C target -D target \ No newline at end of file +E target \ No newline at end of file diff --git a/test/AllPairs/test_ap.py b/test/AllPairs/test_ap.py index 24bfe40f..97ba0179 100644 --- a/test/AllPairs/test_ap.py +++ b/test/AllPairs/test_ap.py @@ -6,22 +6,22 @@ from src.allpairs import AllPairs TEST_DIR = 'test/AllPairs/' -OUT_FILE = TEST_DIR+'output/out.txt' +OUT_DIR = TEST_DIR+'output/' -EXPECTED_FILE = TEST_DIR+'/expected/out.txt' ## TODO not currently checked. +EXPECTED_DIR = TEST_DIR+'/expected/' class TestAllPairs: """ Run all pairs shortest paths (AllPairs) tests in the Docker image """ def test_allpairs(self): - out_path = Path(OUT_FILE) + out_path = Path(OUT_DIR+'sample-out.txt') out_path.unlink(missing_ok=True) # Only include required arguments AllPairs.run( nodetypes=TEST_DIR+'input/sample-in-nodetypes.txt', network=TEST_DIR+'input/sample-in-net.txt', - output_file=OUT_FILE + output_file=OUT_DIR+'sample-out.txt' ) assert out_path.exists() @@ -31,20 +31,20 @@ def test_allpairs_missing(self): # No nodetypes AllPairs.run( network=TEST_DIR + 'input/sample-in-net.txt', - output_file=OUT_FILE) + output_file=OUT_DIR+'sample-out.txt') # Only run Singularity test if the binary is available on the system # spython is only available on Unix, but do not explicitly skip non-Unix platforms @pytest.mark.skipif(not shutil.which('singularity'), reason='Singularity not found on system') def test_allpairs_singularity(self): - out_path = Path(OUT_FILE) + out_path = Path(OUT_DIR+'sample-out.txt') out_path.unlink(missing_ok=True) # Only include required arguments and run with Singularity AllPairs.run( nodetypes=TEST_DIR+'input/sample-in-nodetypes.txt', network=TEST_DIR+'input/sample-in-net.txt', - output_file=OUT_FILE, + output_file=OUT_DIR+'sample-out.txt', singularity=True ) assert out_path.exists() @@ -53,13 +53,13 @@ def test_correctness(self): """ Tests algorithm correctness of all_pairs_shortest_path.py by using AllPairs.run """ - out_path = Path(OUT_FILE) + out_path = Path(OUT_DIR+'correctness.txt') out_path.unlink(missing_ok=True) AllPairs.run( nodetypes=TEST_DIR+'input/correctness-nodetypes.txt', network=TEST_DIR+'input/correctness-network.txt', - output_file=OUT_FILE + output_file=OUT_DIR+'correctness.txt' ) assert out_path.exists() @@ -72,13 +72,15 @@ def test_correctness(self): output_edges.append((node1, node2)) output_edges.sort() - expected_output = [ - ('A', 'B'), - ('B', 'C'), - ('C', 'D'), - ] + with open(EXPECTED_DIR+"correctness-expected.txt", 'r') as file: + correctness_edge_pairs = file.readlines() + correctness_edges = [] + for edge in correctness_edge_pairs: + node1, node2 = edge.split() + correctness_edges.append((node1, node2)) + + assert output_edges == correctness_edges - assert output_edges == expected_output