Skip to content

Commit

Permalink
added deterministic test and fixed naming
Browse files Browse the repository at this point in the history
  • Loading branch information
ntalluri committed Aug 17, 2023
1 parent 6064b32 commit a257f74
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
3 changes: 3 additions & 0 deletions test/AllPairs/expected/correctness-expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
A B
A E
B C
File renamed without changes.
4 changes: 3 additions & 1 deletion test/AllPairs/input/correctness-network.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#Node1 Node2
A B 1
B C 1
C D 1
C D 1
D E 1
A E 1
2 changes: 1 addition & 1 deletion test/AllPairs/input/correctness-nodetypes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
A source
B source
C target
D target
E target
32 changes: 17 additions & 15 deletions test/AllPairs/test_ap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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



0 comments on commit a257f74

Please sign in to comment.