Skip to content
This repository was archived by the owner on Aug 22, 2025. It is now read-only.

Commit 85d7b8a

Browse files
committed
added tests
1 parent be50d36 commit 85d7b8a

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

test/runtests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ using Test
44

55
@testset "Exact coloring via contraction" begin include("test_contraction.jl") end
66
@testset "Greedy distance-1 coloring" begin include("test_greedy_d1.jl") end
7+
@testset "Greedy star coloring" begin include("test_greedy_star.jl") end
78
@testset "Matrix to graph conversion" begin include("test_matrix2graph.jl") end
89
@testset "AD using color vector" begin include("test_ad.jl") end
910
@testset "Integration test" begin include("test_integration.jl") end
1011
@testset "Special matrices" begin include("test_specialmatrices.jl") end
1112
@testset "Jac Vecs and Hes Vecs" begin include("test_jaches_products.jl") end
12-
@testset "Jacobian sparsity computation" begin include("program_sparsity/testall.jl") end
13+
@testset "Jacobian sparsity computation" begin include("program_sparsity/testall.jl") end

test/test_greedy_star.jl

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using SparseDiffTools
2+
using LightGraphs
3+
using Random
4+
5+
Random.seed!(123)
6+
7+
#= Test data =#
8+
test_graphs = Array{VSafeGraph, 1}(undef, 0)
9+
10+
for _ in 1:5
11+
nv = rand(5:20)
12+
ne = rand(1:100)
13+
graph = SimpleGraph(nv)
14+
for e in 1:ne
15+
v1 = rand(1:nv)
16+
v2 = rand(1:nv)
17+
while v1 == v2
18+
v2 = rand(1:nv)
19+
end
20+
add_edge!(graph, v1, v2)
21+
end
22+
push!(test_graphs, copy(graph))
23+
end
24+
25+
#=
26+
Coloring needs to satisfy two conditions:
27+
28+
1. every pair of adjacent vertices receives distinct colors
29+
(a distance-1 coloring)
30+
31+
2. For any vertex v, any color that leads to a two-colored path
32+
involving v and three other vertices is impermissible for v.
33+
In other words, every path on four vertices uses at least three
34+
colors.
35+
=#
36+
37+
for i in 1:5
38+
g = test_graphs[i]
39+
40+
out_colors1 = SparseDiffTools.greedy_star1_coloring(g)
41+
out_colors2 = SparseDiffTools.greedy_star2_coloring(g)
42+
43+
#test condition 1
44+
for v = vertices(g)
45+
color = out_colors1[v]
46+
for j in inneighbors(g, v)
47+
@test out_color[j] != color
48+
end
49+
end
50+
51+
#test condition 2
52+
for j = vertices(g)
53+
walk = saw(g, j, 4)
54+
walk_colors = zeros(Int64, 0)
55+
if length(saw) >= 4
56+
for t in walk
57+
push!(walk_colors, out_colors1[t])
58+
end
59+
@test unique(walk_colors) >= 3
60+
end
61+
end
62+
63+
end

0 commit comments

Comments
 (0)