14
14
15
15
16
16
@pytest .fixture
17
- def contiguous_partition ():
17
+ def contiguous_partition_with_flips ():
18
18
graph = nx .Graph ()
19
19
graph .add_nodes_from (range (4 ))
20
20
graph .add_edges_from ([(0 , 1 ), (1 , 2 ), (2 , 3 ), (3 , 0 )])
21
21
partition = Partition (graph , {0 : 0 , 1 : 1 , 2 : 1 , 3 : 0 })
22
22
23
23
# This flip will maintain contiguity.
24
- partition .test_flips = {0 : 1 }
25
- return partition
24
+ return partition , {0 : 1 }
26
25
27
26
28
27
@pytest .fixture
29
- def discontiguous_partition ():
28
+ def discontiguous_partition_with_flips ():
30
29
graph = nx .Graph ()
31
30
graph .add_nodes_from (range (4 ))
32
31
graph .add_edges_from ([(0 , 1 ), (1 , 2 ), (2 , 3 )])
33
32
partition = Partition (graph , {0 : 0 , 1 : 1 , 2 : 1 , 3 : 0 })
34
33
35
34
# This flip will maintain discontiguity.
36
- partition .test_flips = {1 : 0 }
37
- return partition
35
+ return partition , {1 : 0 }
36
+
37
+
38
+ @pytest .fixture
39
+ def contiguous_partition (contiguous_partition_with_flips ):
40
+ return contiguous_partition_with_flips [0 ]
41
+
42
+
43
+ @pytest .fixture
44
+ def discontiguous_partition (discontiguous_partition_with_flips ):
45
+ return discontiguous_partition_with_flips [0 ]
38
46
39
47
40
48
def test_contiguous_with_contiguity_no_flips_is_true (contiguous_partition ):
@@ -43,8 +51,9 @@ def test_contiguous_with_contiguity_no_flips_is_true(contiguous_partition):
43
51
assert contiguous_bfs (contiguous_partition )
44
52
45
53
46
- def test_contiguous_with_contiguity_flips_is_true (contiguous_partition ):
47
- contiguous_partition2 = contiguous_partition .flip (contiguous_partition .test_flips )
54
+ def test_contiguous_with_contiguity_flips_is_true (contiguous_partition_with_flips ):
55
+ contiguous_partition , test_flips = contiguous_partition_with_flips
56
+ contiguous_partition2 = contiguous_partition .flip (test_flips )
48
57
assert contiguous (contiguous_partition2 )
49
58
assert single_flip_contiguous (contiguous_partition2 )
50
59
assert contiguous_bfs (contiguous_partition2 )
@@ -64,10 +73,11 @@ def test_discontiguous_with_contiguous_bfs_no_flips_is_false(discontiguous_parti
64
73
assert not contiguous_bfs (discontiguous_partition )
65
74
66
75
67
- def test_discontiguous_with_contiguous_flips_is_false (discontiguous_partition ):
68
- discontiguous_partition2 = discontiguous_partition .flip (
69
- discontiguous_partition .test_flips
70
- )
76
+ def test_discontiguous_with_contiguous_flips_is_false (
77
+ discontiguous_partition_with_flips
78
+ ):
79
+ part , test_flips = discontiguous_partition_with_flips
80
+ discontiguous_partition2 = part .flip (test_flips )
71
81
assert not contiguous (discontiguous_partition2 )
72
82
73
83
@@ -76,18 +86,18 @@ def test_discontiguous_with_contiguous_flips_is_false(discontiguous_partition):
76
86
"when the previous partition is discontiguous"
77
87
)
78
88
def test_discontiguous_with_single_flip_contiguous_flips_is_false (
79
- discontiguous_partition
89
+ discontiguous_partition_with_flips
80
90
):
81
- discontiguous_partition2 = discontiguous_partition .flip (
82
- discontiguous_partition .test_flips
83
- )
91
+ part , test_flips = discontiguous_partition_with_flips
92
+ discontiguous_partition2 = part .flip (test_flips )
84
93
assert not single_flip_contiguous (discontiguous_partition2 )
85
94
86
95
87
- def test_discontiguous_with_contiguous_bfs_flips_is_false (discontiguous_partition ):
88
- discontiguous_partition2 = discontiguous_partition .flip (
89
- discontiguous_partition .test_flips
90
- )
96
+ def test_discontiguous_with_contiguous_bfs_flips_is_false (
97
+ discontiguous_partition_with_flips
98
+ ):
99
+ part , test_flips = discontiguous_partition_with_flips
100
+ discontiguous_partition2 = part .flip (test_flips )
91
101
assert not contiguous_bfs (discontiguous_partition2 )
92
102
93
103
0 commit comments