Skip to content

Commit bd690a8

Browse files
committed
Add some spectral radius tests
1 parent 2d70b0d commit bd690a8

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ end
252252
@testset "Fit Candidates" begin
253253
test_fit_candidates()
254254
end
255+
256+
@testset "Approximate Spectral Radius" begin
257+
test_approximate_spectral_radius()
258+
end
255259
end
256260

257261
end

test/sa_tests.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,36 @@ function generate_fit_candidates_cases()
183183
end
184184

185185
cases
186+
end
187+
188+
# Test approximate spectral radius
189+
function test_approximate_spectral_radius()
190+
191+
cases = []
192+
srand(0)
193+
194+
push!(cases, [2. 0.
195+
0. 1.])
196+
197+
push!(cases, [-2. 0.
198+
0 1])
199+
200+
push!(cases, [100. 0. 0.
201+
0. 101. 0.
202+
0. 0. 99.])
203+
204+
for i in 2:5
205+
push!(cases, rand(i,i))
206+
end
207+
208+
for A in cases
209+
E,V = eig(A)
210+
E = abs.(E)
211+
largest_eig = find(E .== maximum(E))[1]
212+
expected_eig = E[largest_eig]
213+
214+
@test isapprox(approximate_spectral_radius(A), expected_eig)
215+
216+
end
217+
186218
end

0 commit comments

Comments
 (0)