Skip to content

Commit

Permalink
adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fandreuz committed Dec 30, 2020
1 parent f14e04e commit 6f29e68
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
29 changes: 6 additions & 23 deletions tests/fba/algorithm/test_fba.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_rank_to_partition_idx(rank, expected):
),
)
def test_build_block_counterimage(graph, counterimaged_block_indexes):
vertexes, _ = prepare_graph(graph)
vertexes = prepare_graph(graph)
counterimaged_block = _Block(
map(lambda idx: vertexes[idx], counterimaged_block_indexes), None
)
Expand All @@ -59,35 +59,16 @@ def test_build_block_counterimage(graph, counterimaged_block_indexes):
)


@pytest.mark.parametrize(
"graph",
test_cases.graphs,
)
def test_prepare_graph_max_rank(graph):
_, max_rank = prepare_graph(graph)
assert max_rank == max(
map(lambda node: graph.nodes[node]["rank"], graph.nodes)
)


@pytest.mark.parametrize(
"graph",
test_cases.graphs,
)
def test_prepare_graph_vertexes(graph):
vertexes, _ = prepare_graph(graph)
vertexes = prepare_graph(graph)

# same length
assert len(vertexes) == len(graph.nodes)

# same rank
assert all(
map(
lambda idx: vertexes[idx].rank == graph.nodes[idx]["rank"],
range(len(vertexes)),
)
)

# counterimage
my_counterimage = [
map(attrgetter("label"), vertex.counterimage) for vertex in vertexes
Expand All @@ -101,7 +82,8 @@ def test_prepare_graph_vertexes(graph):

@pytest.mark.parametrize("graph", test_cases.graphs)
def test_create_initial_partition(graph):
vertexes, max_rank = prepare_graph(graph)
vertexes = prepare_graph(graph)
max_rank = max(vertex.rank for vertex in vertexes)
partition = create_initial_partition(vertexes, max_rank)

# at most one block per rank
Expand All @@ -122,7 +104,8 @@ def test_create_initial_partition(graph):

@pytest.mark.parametrize("graph", test_cases.graphs)
def test_split_upper_ranks(graph):
vertexes, max_rank = prepare_graph(graph)
vertexes = prepare_graph(graph)
max_rank = max(vertex.rank for vertex in vertexes)
partition_length = 0 if max_rank == float("-inf") else max_rank + 2

for idx in range(partition_length):
Expand Down
2 changes: 1 addition & 1 deletion tests/fba/test_fba_rscp_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def build_test_blocks(graph, partition, expected):
# this is needed to avoid an error
for node in graph.nodes:
graph.nodes[node]["rank"] = 0
(vertexes, _) = to_normal_graph(graph)
vertexes = to_normal_graph(graph)
return (
_Block([vertexes[idx] for idx in partition[0]], None),
_Block([vertexes[idx] for idx in partition[1]], None),
Expand Down

0 comments on commit 6f29e68

Please sign in to comment.