Skip to content

Commit 94c845e

Browse files
committed
Add interface tests for DiffEqArray
1 parent 9a83043 commit 94c845e

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

test/interface_tests.jl

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,84 @@
11
using RecursiveArrayTools, Test
22

3-
recs = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
4-
testva = VectorOfArray(recs)
3+
t = 1:3
4+
testva = VectorOfArray([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
5+
testda = DiffEqArray([[1, 2, 3], [4, 5, 6], [7, 8, 9]],t)
56

67
for (i, elem) in enumerate(testva)
78
@test elem == testva[i]
89
end
910

11+
for (i, elem) in enumerate(testda)
12+
@test elem == testda[i]
13+
end
14+
1015
push!(testva, [10, 11, 12])
1116
@test testva[:, end] == [10, 11, 12]
17+
push!(testda, [10, 11, 12])
18+
@test testda[:, end] == [10, 11, 12]
19+
1220
testva2 = copy(testva)
1321
push!(testva2, [13, 14, 15])
22+
testda2 = copy(testva)
23+
push!(testda2, [13, 14, 15])
24+
1425
# make sure we copy when we pass containers
1526
@test size(testva) == (3, 4)
1627
@test testva2[:, end] == [13, 14, 15]
28+
@test size(testda) == (3, 4)
29+
@test testda2[:, end] == [13, 14, 15]
1730

1831
append!(testva, testva)
1932
@test testva[1:2, 5:6] == [1 4; 2 5]
33+
append!(testda, testda)
34+
@test testda[1:2, 5:6] == [1 4; 2 5]
2035

2136
# Test that adding a array of different dimension makes the array ragged
2237
push!(testva, [-1, -2, -3, -4])
38+
push!(testda, [-1, -2, -3, -4])
2339
#testva #TODO: this screws up printing, try to make a fallback
2440
@test testva[1:2, 5:6] == [1 4; 2 5] # we just let the indexing happen if it works
25-
testva[4, 9] # == testva.data[9][4]
41+
@test testda[1:2, 5:6] == [1 4; 2 5]
42+
2643
@test_throws BoundsError testva[4:5, 5:6]
44+
@test_throws BoundsError testda[4:5, 5:6]
45+
2746
@test testva[9] == [-1, -2, -3, -4]
2847
@test testva[end] == [-1, -2, -3, -4]
48+
@test testda[9] == [-1, -2, -3, -4]
49+
@test testda[end] == [-1, -2, -3, -4]
2950

3051
# Currently we enforce the general shape, they can just be different lengths, ie we
3152
# can't do
3253
# Decide if this is desired, or remove this restriction
3354
@test_throws MethodError push!(testva, [-1 -2 -3 -4])
3455
@test_throws MethodError push!(testva, [-1 -2; -3 -4])
56+
@test_throws MethodError push!(testda, [-1 -2 -3 -4])
57+
@test_throws MethodError push!(testda, [-1 -2; -3 -4])
3558

36-
# convert array from VectorOfArray
59+
# convert array from VectorOfArray/DiffEqArray
60+
t = 1:8
3761
recs = [rand(10, 7) for i = 1:8]
3862
testva = VectorOfArray(recs)
63+
testda = DiffEqArray(recs,t)
3964
testa = cat(recs...,dims=3)
65+
4066
@test convert(Array,testva) == testa
67+
@test convert(Array,testda) == testa
4168

69+
t = 1:3
4270
recs = [[1 2; 3 4], [3 5; 6 7], [8 9; 10 11]]
4371
testva = VectorOfArray(recs)
72+
testda = DiffEqArray(recs,t)
73+
4474
@test size(convert(Array,testva)) == (2,2,3)
75+
@test size(convert(Array,testda)) == (2,2,3)
4576

46-
# create similar VectorOfArray
77+
# create similar VectorOfArray/DiffEqArray
78+
t = 1:4
4779
recs = [rand(6) for i = 1:4]
4880
testva = VectorOfArray(recs)
81+
4982
testva2 = similar(testva)
5083
@test typeof(testva2) == typeof(testva)
5184
@test size(testva2) == size(testva)
@@ -77,3 +110,6 @@ emptyda = DiffEqArray(Array{Vector{Float64}}([]), Vector{Float64}())
77110

78111
A = VectorOfArray(map(i->rand(2,4),1:7))
79112
@test map(x->maximum(x),A) isa Vector
113+
114+
DA = DiffEqArray(map(i->rand(2,4),1:7), 1:7)
115+
@test map(x->maximum(x),DA) isa Vector

0 commit comments

Comments
 (0)