Skip to content

Commit 2fcf359

Browse files
add vector and matrix methods tests (#5)
1 parent c2dbfdb commit 2fcf359

File tree

2 files changed

+78
-4
lines changed

2 files changed

+78
-4
lines changed

test/matrix_and_vector_methods.jl

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
types = [Bool, Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, Float32, Float64]
2+
3+
@testset "Matrix methods" begin
4+
I = J = collect(1:5)
5+
for t in types
6+
X = rand(t, 5)
7+
A = GrB_Matrix(I, J, X)
8+
@test size(A) == (5, 5)
9+
@test size(A, 1) == 5
10+
P, Q, R = findnz(A)
11+
@test P == I
12+
@test Q == J
13+
@test R == X
14+
@test nnz(A) == 5
15+
B = copy(A)
16+
@test size(B) == (5, 5)
17+
P, Q, R = findnz(B)
18+
@test P == I
19+
@test Q == J
20+
@test R == X
21+
@test nnz(B) == 5
22+
i = rand(1:5)
23+
@test A[i, i] == X[i]
24+
k = rand(t)
25+
A[i, i] = k
26+
@test A[i, i] == k
27+
empty!(A)
28+
@test nnz(A) == 0
29+
GrB_free(A)
30+
GrB_free(B)
31+
end
32+
end
33+
34+
@testset "Vector Methods" begin
35+
I = [1, 4, 5]
36+
for t in types
37+
X = rand(t, 3)
38+
V = GrB_Vector(I, X)
39+
@test size(V) == (5, )
40+
@test size(V, 1) == 5
41+
P, Q = findnz(V)
42+
@test P == I
43+
@test Q == X
44+
@test nnz(V) == 3
45+
W = copy(V)
46+
@test size(W) == (5, )
47+
P, Q = findnz(W)
48+
@test P == I
49+
@test Q == X
50+
@test nnz(W) == 3
51+
i = rand(1:3)
52+
@test V[I[i]] == X[i]
53+
k = rand(t)
54+
V[i] = k
55+
@test V[i] == k
56+
empty!(V)
57+
@test nnz(V) == 0
58+
GrB_free(W)
59+
GrB_free(V)
60+
end
61+
end

test/runtests.jl

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1-
using SuiteSparseGraphBLAS
2-
using Test
3-
4-
@test GrB_init(GrB_NONBLOCKING) == GrB_SUCCESS
1+
using SuiteSparseGraphBLAS
2+
using Test
3+
4+
@test GrB_init(GrB_NONBLOCKING) == GrB_SUCCESS
5+
6+
const testdir = dirname(@__FILE__)
7+
8+
tests = [
9+
"matrix_and_vector_methods",
10+
]
11+
12+
@testset "SuiteSparseGraphBLAS" begin
13+
for t in tests
14+
tp = joinpath(testdir, "$(t).jl")
15+
include(tp)
16+
end
17+
end

0 commit comments

Comments
 (0)