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

Commit 4a2d0ce

Browse files
committed
added tests for both functions
1 parent 85d7b8a commit 4a2d0ce

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

src/SparseDiffTools.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import Core: SSAValue
1313

1414
export contract_color,
1515
greedy_d1,
16+
greedy_star1_coloring,
17+
greedy_star2_coloring,
1618
matrix2graph,
1719
matrix_colors,
1820
forwarddiff_color_jacobian!,
@@ -33,6 +35,8 @@ export contract_color,
3335
include("coloring/high_level.jl")
3436
include("coloring/contraction_coloring.jl")
3537
include("coloring/greedy_d1_coloring.jl")
38+
include("coloring/greedy_star1_coloring.jl")
39+
include("coloring/greedy_star2_coloring.jl")
3640
include("coloring/matrix2graph.jl")
3741
include("differentiation/compute_jacobian_ad.jl")
3842
include("differentiation/jaches_products.jl")

src/coloring/greedy_star2_coloring.jl

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
TODO: add text explaining the difference between star1 and
2525
star2
2626
"""
27-
function greedy_star2_coloring(G::LightGraphs.AbstractGraph)
27+
function greedy_star2_coloring(g::LightGraphs.AbstractGraph)
2828
v = nv(g)
2929
color = zeros(Int64, v)
3030

@@ -55,11 +55,3 @@ function greedy_star2_coloring(G::LightGraphs.AbstractGraph)
5555

5656
color
5757
end
58-
59-
function find_min_color(forbiddenColors::AbstractVector, vertex_i::Integer)
60-
c = 1
61-
while (forbiddenColors[c] == vertex_i)
62-
c+=1
63-
end
64-
c
65-
end

test/test_greedy_star.jl

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using Random
55
Random.seed!(123)
66

77
#= Test data =#
8-
test_graphs = Array{VSafeGraph, 1}(undef, 0)
8+
test_graphs = Array{SimpleGraph, 1}(undef, 0)
99

1010
for _ in 1:5
1111
nv = rand(5:20)
@@ -44,19 +44,39 @@ for i in 1:5
4444
for v = vertices(g)
4545
color = out_colors1[v]
4646
for j in inneighbors(g, v)
47-
@test out_color[j] != color
47+
@test out_colors1[j] != color
4848
end
4949
end
5050

5151
#test condition 2
5252
for j = vertices(g)
5353
walk = saw(g, j, 4)
5454
walk_colors = zeros(Int64, 0)
55-
if length(saw) >= 4
55+
if length(walk) >= 4
5656
for t in walk
5757
push!(walk_colors, out_colors1[t])
5858
end
59-
@test unique(walk_colors) >= 3
59+
@test length(unique(walk_colors)) >= 3
60+
end
61+
end
62+
63+
#test condition 1
64+
for v = vertices(g)
65+
color = out_colors2[v]
66+
for j in inneighbors(g, v)
67+
@test out_colors2[j] != color
68+
end
69+
end
70+
71+
#test condition 2
72+
for j = vertices(g)
73+
walk = saw(g, j, 4)
74+
walk_colors = zeros(Int64, 0)
75+
if length(walk) >= 4
76+
for t in walk
77+
push!(walk_colors, out_colors2[t])
78+
end
79+
@test length(unique(walk_colors)) >= 3
6080
end
6181
end
6282

0 commit comments

Comments
 (0)