22from bispy .dovier_piazza_policriti .ranked_partition import RankedPartition
33from .dovier_piazza_policriti_test_cases import graphs
44from bispy .utilities .graph_decorator import decorate_nx_graph
5+ import networkx as nx
6+ from bispy .utilities .graph_entities import _QBlock
7+
58
69@pytest .mark .parametrize (
710 "rank, expected" , zip ([float ("-inf" ), * (range (5 ))], range (6 ))
811)
912def test_rank_to_partition_idx (rank , expected ):
1013 assert RankedPartition .rank_to_partition_idx (rank ) == expected
1114
15+
1216@pytest .mark .parametrize ("graph" , graphs )
1317def test_create_initial_partition (graph ):
1418 vertexes , _ = decorate_nx_graph (graph )
1519 partition = RankedPartition (vertexes )
1620
17- # at least block per rank
18- assert all (len (partition [idx ]) for idx in range (1 ,len (partition )))
21+ # at least one block per rank, except for float('-inf')
22+ assert all (len (partition [idx ]) for idx in range (1 , len (partition )))
1923
2024 # right vertexes in the right place
2125 for idx in range (len (partition )):
@@ -25,7 +29,62 @@ def test_create_initial_partition(graph):
2529 assert partition [idx ][0 ].vertexes .size == [
2630 vertex .rank == rank for vertex in vertexes
2731 ].count (True )
28- # only right vertexes
32+ # right rank
2933 assert all (
3034 vertex .rank == rank for vertex in partition [idx ][0 ].vertexes
3135 )
36+
37+
38+ @pytest .mark .parametrize ("graph" , graphs )
39+ def test_nvertexes (graph ):
40+ vertexes , _ = decorate_nx_graph (graph )
41+ partition = RankedPartition (vertexes )
42+ assert partition .nvertexes == len (graph .nodes )
43+
44+
45+ def test_get_item ():
46+ vertexes , _ = decorate_nx_graph (nx .balanced_tree (2 , 3 ))
47+ partition = RankedPartition (vertexes )
48+ assert partition [0 ] == partition ._partition [0 ]
49+
50+
51+ def test_append_at_rank ():
52+ vertexes , _ = decorate_nx_graph (nx .balanced_tree (2 , 3 ))
53+ partition = RankedPartition (vertexes )
54+ block = _QBlock ([], None )
55+ partition .append_at_rank (block , 1 )
56+ assert partition [2 ][- 1 ] == block
57+
58+
59+ def test_append_at_index ():
60+ vertexes , _ = decorate_nx_graph (nx .balanced_tree (2 , 3 ))
61+ partition = RankedPartition (vertexes )
62+ block = _QBlock ([], None )
63+ partition .append_at_index (block , 1 )
64+ assert partition [1 ][- 1 ] == block
65+
66+
67+ def test_len ():
68+ vertexes , _ = decorate_nx_graph (nx .balanced_tree (2 , 3 ))
69+ partition = RankedPartition (vertexes )
70+ assert len (partition ) == 5
71+
72+
73+ def test_scc_leaf_length ():
74+ vertexes , _ = decorate_nx_graph (nx .balanced_tree (2 , 3 ))
75+ partition = RankedPartition (vertexes )
76+ assert partition [0 ][0 ].size == 0
77+
78+
79+ def test_clear_rank ():
80+ vertexes , _ = decorate_nx_graph (nx .balanced_tree (2 , 3 ))
81+ partition = RankedPartition (vertexes )
82+ partition .clear_rank (1 )
83+ assert len (partition [2 ]) == 0
84+
85+
86+ def test_clear_index ():
87+ vertexes , _ = decorate_nx_graph (nx .balanced_tree (2 , 3 ))
88+ partition = RankedPartition (vertexes )
89+ partition .clear_index (1 )
90+ assert len (partition [1 ]) == 0
0 commit comments