Skip to content

Commit 6a96b9d

Browse files
committed
Add more tests
1 parent 84004ad commit 6a96b9d

File tree

3 files changed

+102
-90
lines changed

3 files changed

+102
-90
lines changed

test/random.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@ end;
8484
RandomOrder(StableRNG(0), 0); postprocessing=false, decompression=:direct
8585
),
8686
GreedyColoringAlgorithm(
87-
RandomOrder(StableRNG(0), 0); postprocessing=true, decompression=:direct
87+
RandomOrder(StableRNG(0), 0); postprocessing=true, postprocessing_minimizes=:all_colors, decompression=:direct
88+
),
89+
GreedyColoringAlgorithm(
90+
RandomOrder(StableRNG(0), 0); postprocessing=true, postprocessing_minimizes=:row_colors, decompression=:direct
91+
),
92+
GreedyColoringAlgorithm(
93+
RandomOrder(StableRNG(0), 0); postprocessing=true, postprocessing_minimizes=:column_colors, decompression=:direct
8894
),
8995
)
9096
@testset "$((; m, n, p))" for (m, n, p) in asymmetric_params
@@ -105,7 +111,13 @@ end;
105111
RandomOrder(StableRNG(0), 0); postprocessing=false, decompression=:substitution
106112
),
107113
GreedyColoringAlgorithm(
108-
RandomOrder(StableRNG(0), 0); postprocessing=true, decompression=:substitution
114+
RandomOrder(StableRNG(0), 0); postprocessing=true, postprocessing_minimizes=:all_colors, decompression=:substitution
115+
),
116+
GreedyColoringAlgorithm(
117+
RandomOrder(StableRNG(0), 0); postprocessing=true, postprocessing_minimizes=:row_colors, decompression=:substitution
118+
),
119+
GreedyColoringAlgorithm(
120+
RandomOrder(StableRNG(0), 0); postprocessing=true, postprocessing_minimizes=:column_colors, decompression=:substitution
109121
),
110122
)
111123
@testset "$((; m, n, p))" for (m, n, p) in asymmetric_params

test/small.jl

Lines changed: 86 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -88,100 +88,100 @@ end;
8888
end;
8989

9090
@testset "Bidirectional coloring" begin
91-
problem = ColoringProblem(; structure=:nonsymmetric, partition=:bidirectional)
92-
order = RandomOrder(StableRNG(0), 0)
93-
94-
@testset "Anti-diagonal" begin
95-
A = sparse([0 0 0 1; 0 0 1 0; 0 1 0 0; 1 0 0 0])
96-
97-
result = coloring(
98-
A, problem, GreedyColoringAlgorithm{:direct}(; postprocessing=false)
99-
)
100-
@test ncolors(result) == 2
101-
102-
result = coloring(
103-
A, problem, GreedyColoringAlgorithm{:direct}(; postprocessing=true)
104-
)
105-
@test ncolors(result) == 1
106-
107-
result = coloring(
108-
A, problem, GreedyColoringAlgorithm{:substitution}(; postprocessing=false)
109-
)
110-
@test ncolors(result) == 2
111-
112-
result = coloring(
113-
A, problem, GreedyColoringAlgorithm{:substitution}(; postprocessing=true)
114-
)
115-
@test ncolors(result) == 1
116-
end
91+
@testset "postprocessing_minimizes = $target" for target in (:all_colors, :row_colors, :column_colors)
92+
problem = ColoringProblem(; structure=:nonsymmetric, partition=:bidirectional)
93+
order = RandomOrder(StableRNG(0), 0)
11794

118-
@testset "Triangle" begin
119-
A = sparse([1 1 0; 0 1 1; 1 0 1])
95+
@testset "Anti-diagonal" begin
96+
A = sparse([0 0 0 1; 0 0 1 0; 0 1 0 0; 1 0 0 0])
12097

121-
result = coloring(
122-
A, problem, GreedyColoringAlgorithm{:direct}(; postprocessing=true)
123-
)
124-
@test ncolors(result) == 3
98+
result = coloring(
99+
A, problem, GreedyColoringAlgorithm{:direct}(; postprocessing=false),
100+
)
101+
@test ncolors(result) == 2
125102

126-
result = coloring(
127-
A, problem, GreedyColoringAlgorithm{:substitution}(; postprocessing=true)
128-
)
129-
@test ncolors(result) == 3
130-
end
103+
result = coloring(
104+
A, problem, GreedyColoringAlgorithm{:direct}(; postprocessing=true, postprocessing_minimizes=target),
105+
)
106+
@test ncolors(result) == 1
131107

132-
@testset "Rectangle" begin
133-
A = spzeros(Bool, 10, 20)
134-
A[:, 1] .= 1
135-
A[:, end] .= 1
136-
A[1, :] .= 1
137-
A[end, :] .= 1
138-
139-
result = coloring(
140-
A, problem, GreedyColoringAlgorithm{:direct}(order; postprocessing=false)
141-
)
142-
@test ncolors(result) == 6 # two more than necessary
143-
result = coloring(
144-
A, problem, GreedyColoringAlgorithm{:direct}(order; postprocessing=true)
145-
)
146-
@test ncolors(result) == 4 # optimal number
147-
148-
result = coloring(
149-
A, problem, GreedyColoringAlgorithm{:substitution}(order; postprocessing=false)
150-
)
151-
@test ncolors(result) == 6 # two more than necessary
152-
result = coloring(
153-
A, problem, GreedyColoringAlgorithm{:substitution}(order; postprocessing=true)
154-
)
155-
@test ncolors(result) == 4 # optimal number
156-
end
108+
result = coloring(
109+
A, problem, GreedyColoringAlgorithm{:substitution}(; postprocessing=false),
110+
)
111+
@test ncolors(result) == 2
157112

158-
@testset "Arrowhead" begin
159-
A = spzeros(Bool, 10, 10)
160-
for i in axes(A, 1)
161-
A[1, i] = 1
162-
A[i, 1] = 1
163-
A[i, i] = 1
113+
result = coloring(
114+
A, problem, GreedyColoringAlgorithm{:substitution}(; postprocessing=true, postprocessing_minimizes=target),
115+
)
116+
@test ncolors(result) == 1
164117
end
165118

166-
result = coloring(
167-
A, problem, GreedyColoringAlgorithm{:direct}(order; postprocessing=true)
168-
)
169-
@test ncolors(coloring(A, problem, GreedyColoringAlgorithm{:substitution}(order))) <
170-
ncolors(coloring(A, problem, GreedyColoringAlgorithm{:direct}(order)))
119+
@testset "Triangle" begin
120+
A = sparse([1 1 0; 0 1 1; 1 0 1])
121+
122+
result = coloring(
123+
A, problem, GreedyColoringAlgorithm{:direct}(; postprocessing=true, postprocessing_minimizes=target),
124+
)
125+
@test ncolors(result) == 3
126+
127+
result = coloring(
128+
A, problem, GreedyColoringAlgorithm{:substitution}(; postprocessing=true, postprocessing_minimizes=target),
129+
)
130+
@test ncolors(result) == 3
131+
end
132+
133+
@testset "Rectangle" begin
134+
A = spzeros(Bool, 10, 20)
135+
A[:, 1] .= 1
136+
A[:, end] .= 1
137+
A[1, :] .= 1
138+
A[end, :] .= 1
139+
140+
result = coloring(
141+
A, problem, GreedyColoringAlgorithm{:direct}(order; postprocessing=false),
142+
)
143+
@test ncolors(result) == 6 # two more than necessary
144+
result = coloring(
145+
A, problem, GreedyColoringAlgorithm{:direct}(order; postprocessing=true, postprocessing_minimizes=target),
146+
)
147+
@test ncolors(result) == 4 # optimal number
148+
149+
result = coloring(
150+
A, problem, GreedyColoringAlgorithm{:substitution}(order; postprocessing=false),
151+
)
152+
@test ncolors(result) == 6 # two more than necessary
153+
result = coloring(
154+
A, problem, GreedyColoringAlgorithm{:substitution}(order; postprocessing=true, postprocessing_minimizes=target),
155+
)
156+
@test ncolors(result) == 4 # optimal number
157+
end
158+
159+
@testset "Arrowhead" begin
160+
A = spzeros(Bool, 10, 10)
161+
for i in axes(A, 1)
162+
A[1, i] = 1
163+
A[i, 1] = 1
164+
A[i, i] = 1
165+
end
166+
167+
result = coloring(
168+
A, problem, GreedyColoringAlgorithm{:direct}(order; postprocessing=true, postprocessing_minimizes=target),
169+
)
170+
@test ncolors(coloring(A, problem, GreedyColoringAlgorithm{:substitution}(order))) <
171+
ncolors(coloring(A, problem, GreedyColoringAlgorithm{:direct}(order)))
172+
173+
@test ncolors(
174+
coloring(
175+
A,
176+
problem,
177+
GreedyColoringAlgorithm{:substitution}(order; postprocessing=true, postprocessing_minimizes=target),
178+
),
179+
) < ncolors(
180+
coloring(
181+
A, problem, GreedyColoringAlgorithm{:direct}(order; postprocessing=true, postprocessing_minimizes=target),
182+
),
183+
)
171184

172-
@test ncolors(
173-
coloring(
174-
A,
175-
problem,
176-
GreedyColoringAlgorithm{:substitution}(order; postprocessing=true),
177-
),
178-
) < ncolors(
179-
coloring(
180-
A, problem, GreedyColoringAlgorithm{:direct}(order; postprocessing=true)
181-
),
182-
)
183-
184-
@testset "postprocessing_minimizes = $target" for target in (:all_colors, :row_colors, :column_colors)
185185
test_bicoloring_decompression(
186186
A,
187187
problem,

test/utils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,10 @@ function test_bicoloring_decompression(
240240
@testset "More orders is better" begin
241241
more_orders = (algo.orders..., _ALL_ORDERS...)
242242
better_algo = GreedyColoringAlgorithm{decompression}(
243-
more_orders; algo.postprocessing
243+
more_orders; algo.postprocessing, algo.postprocessing_minimizes,
244244
)
245245
all_algos = [
246-
GreedyColoringAlgorithm{decompression}(order; algo.postprocessing) for
246+
GreedyColoringAlgorithm{decompression}(order; algo.postprocessing, algo.postprocessing_minimizes) for
247247
order in more_orders
248248
]
249249
result = coloring(A0, problem, algo)

0 commit comments

Comments
 (0)