Skip to content

Commit 3911c90

Browse files
committed
Add tests
1 parent 81b8b30 commit 3911c90

File tree

9 files changed

+64
-8
lines changed

9 files changed

+64
-8
lines changed

Project.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
88
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
99

1010
[compat]
11-
julia = "1"
11+
LightGraphs = "1.3"
12+
StaticArrays = "1.0"
13+
julia = "1.5, 1.6"
1214

1315
[extras]
16+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1417
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
18+
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
1519

1620
[targets]
17-
test = ["Test"]
21+
test = ["LinearAlgebra", "Test", "SafeTestsets"]

src/GraphBasedSystems.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ export System,
88
full_matrix,
99
full_vector,
1010

11-
ldu_factorization!,
12-
ldu_backsubstitution!,
1311
ldu_solve!
1412

1513

@@ -19,6 +17,9 @@ include("entry.jl")
1917
include("system.jl")
2018
include("graph_functions.jl")
2119

20+
# include("lu.jl")
21+
# include("llt.jl")
22+
# include("ldlt.jl")
2223
include("ldu.jl")
2324

2425
end

src/entry.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ end
1111

1212
function randomize!(entry::Entry)
1313
value = entry.value
14-
entry.value = rand(eltype(value), size(value))
14+
entry.value = randn(eltype(value), size(value))
1515
end

src/ldlt.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# LDLᵀ factorization for block-symmetric systems

src/ldu.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# LDU factorization for unsymmetric systems
2+
13
function ldu_factorization_l!(offdiagonal, diagonal)
24
offdiagonal.value = offdiagonal.value/diagonal.value
35
return

src/llt.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# LLᵀ (Choleski) factorization for symmetric systems

src/lu.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# LU factorization for unsymmetric systems

test/ldu_test.jl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using GraphBasedSystems
2+
using LinearAlgebra
3+
GBS = GraphBasedSystems
4+
5+
Z = zeros(Int64,10,10)
6+
A = [
7+
0 1 0 1 1 0 1 0 1 0
8+
1 0 1 0 0 0 0 0 0 0
9+
0 1 0 0 0 0 0 0 0 0
10+
1 0 0 0 1 0 0 0 0 0
11+
1 0 0 1 0 1 0 0 0 0
12+
0 0 0 0 1 0 0 0 0 0
13+
1 0 0 0 0 0 0 1 0 0
14+
0 0 0 0 0 0 1 0 1 1
15+
1 0 0 0 0 0 0 1 0 0
16+
0 0 0 0 0 0 0 1 0 0
17+
]
18+
19+
A = [
20+
A Z Z Z
21+
Z A Z Z
22+
Z Z A Z
23+
Z Z Z A
24+
]
25+
26+
A[3,11] = A[11,3] = 1
27+
A[6,21] = A[21,6] = 1
28+
A[10,31] = A[31,10] = 1
29+
30+
31+
system = System{Float64}(A, [rand(1:3) for i=1:size(A)[1]])
32+
33+
for i=1:10
34+
for entry in collect(values(system.matrix_entries))
35+
GBS.randomize!(entry)
36+
end
37+
for entry in collect(values(system.vector_entries))
38+
GBS.randomize!(entry)
39+
end
40+
41+
B = full_matrix(system)
42+
b = full_vector(system)
43+
ldu_solve!(system)
44+
@test maximum(abs.(full_vector(system)-B\b)) < 1e-5
45+
end
46+

test/runtests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using GraphBasedSystems
21
using Test
2+
using SafeTestsets
33

4-
@testset "GraphBasedSystems.jl" begin
5-
# Write your tests here.
4+
@safetestset "LDU Tests" begin
5+
include("ldu_test.jl")
66
end

0 commit comments

Comments
 (0)