Skip to content

Commit 77b920a

Browse files
committed
Better tests
1 parent c104a53 commit 77b920a

3 files changed

Lines changed: 37 additions & 17 deletions

File tree

docs/src/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ problem = ColoringProblem()
3131

3232
The algorithm defines how you want to solve it. It can be either a [`GreedyColoringAlgorithm`](@ref) or a [`ConstantColoringAlgorithm`](@ref). For `GreedyColoringAlgorithm`, you can select options such as
3333

34-
- the order in which vertices are processed (a subtype of [`AbstractOrder`](@ref SparseMatrixColorings.AbstractOrder))
34+
- the order in which vertices are processed (a subtype of [`AbstractOrder`](@ref SparseMatrixColorings.AbstractOrder) , or a tuple of such objects)
3535
- the type of decompression you want (`:direct` or `:substitution`)
3636

3737
```@example tutorial

test/type_stability.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,21 @@ rng = StableRNG(63)
4040
ColoringProblem(; structure, partition),
4141
GreedyColoringAlgorithm(order; decompression),
4242
)
43+
@test_opt coloring(
44+
A,
45+
ColoringProblem(; structure, partition),
46+
GreedyColoringAlgorithm((NaturalOrder(), order); decompression),
47+
)
4348
@inferred coloring(
4449
A,
4550
ColoringProblem(; structure, partition),
4651
GreedyColoringAlgorithm(order; decompression),
4752
)
53+
@inferred coloring(
54+
A,
55+
ColoringProblem(; structure, partition),
56+
GreedyColoringAlgorithm((NaturalOrder(), order); decompression),
57+
)
4858
end
4959
end
5060
end;

test/utils.jl

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,19 @@ function test_coloring_decompression(
175175
end
176176

177177
@testset "More orders is better" begin
178-
if algo.orders _ALL_ORDERS
179-
better_algo = GreedyColoringAlgorithm{decompression}(
180-
_ALL_ORDERS; algo.postprocessing
181-
)
182-
result = coloring(A0, problem, algo)
183-
better_result = coloring(A0, problem, better_algo)
184-
@test ncolors(result) >= ncolors(better_result)
185-
end
178+
more_orders = (algo.orders..., _ALL_ORDERS...)
179+
better_algo = GreedyColoringAlgorithm{decompression}(
180+
more_orders; algo.postprocessing
181+
)
182+
all_algos = [
183+
GreedyColoringAlgorithm{decompression}(order; algo.postprocessing) for
184+
order in more_orders
185+
]
186+
result = coloring(A0, problem, algo)
187+
better_result = coloring(A0, problem, better_algo)
188+
all_results = [coloring(A0, problem, _algo) for _algo in all_algos]
189+
@test ncolors(better_result) <= ncolors(result)
190+
@test ncolors(better_result) == minimum(ncolors, all_results)
186191
end
187192
end
188193

@@ -233,14 +238,19 @@ function test_bicoloring_decompression(
233238
end
234239

235240
@testset "More orders is better" begin
236-
if algo.orders _ALL_ORDERS
237-
better_algo = GreedyColoringAlgorithm{decompression}(
238-
_ALL_ORDERS; algo.postprocessing
239-
)
240-
result = coloring(A0, problem, algo)
241-
better_result = coloring(A0, problem, better_algo)
242-
@test ncolors(result) >= ncolors(better_result)
243-
end
241+
more_orders = (algo.orders..., _ALL_ORDERS...)
242+
better_algo = GreedyColoringAlgorithm{decompression}(
243+
more_orders; algo.postprocessing
244+
)
245+
all_algos = [
246+
GreedyColoringAlgorithm{decompression}(order; algo.postprocessing) for
247+
order in more_orders
248+
]
249+
result = coloring(A0, problem, algo)
250+
better_result = coloring(A0, problem, better_algo)
251+
all_results = [coloring(A0, problem, _algo) for _algo in all_algos]
252+
@test ncolors(better_result) <= ncolors(result)
253+
@test ncolors(better_result) == minimum(ncolors, all_results)
244254
end
245255
end
246256

0 commit comments

Comments
 (0)