|
1 | 1 | using RecursiveArrayTools, Test |
2 | 2 |
|
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) |
5 | 6 |
|
6 | 7 | for (i, elem) in enumerate(testva) |
7 | 8 | @test elem == testva[i] |
8 | 9 | end |
9 | 10 |
|
| 11 | +for (i, elem) in enumerate(testda) |
| 12 | + @test elem == testda[i] |
| 13 | +end |
| 14 | + |
10 | 15 | push!(testva, [10, 11, 12]) |
11 | 16 | @test testva[:, end] == [10, 11, 12] |
| 17 | +push!(testda, [10, 11, 12]) |
| 18 | +@test testda[:, end] == [10, 11, 12] |
| 19 | + |
12 | 20 | testva2 = copy(testva) |
13 | 21 | push!(testva2, [13, 14, 15]) |
| 22 | +testda2 = copy(testva) |
| 23 | +push!(testda2, [13, 14, 15]) |
| 24 | + |
14 | 25 | # make sure we copy when we pass containers |
15 | 26 | @test size(testva) == (3, 4) |
16 | 27 | @test testva2[:, end] == [13, 14, 15] |
| 28 | +@test size(testda) == (3, 4) |
| 29 | +@test testda2[:, end] == [13, 14, 15] |
17 | 30 |
|
18 | 31 | append!(testva, testva) |
19 | 32 | @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] |
20 | 35 |
|
21 | 36 | # Test that adding a array of different dimension makes the array ragged |
22 | 37 | push!(testva, [-1, -2, -3, -4]) |
| 38 | +push!(testda, [-1, -2, -3, -4]) |
23 | 39 | #testva #TODO: this screws up printing, try to make a fallback |
24 | 40 | @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 | + |
26 | 43 | @test_throws BoundsError testva[4:5, 5:6] |
| 44 | +@test_throws BoundsError testda[4:5, 5:6] |
| 45 | + |
27 | 46 | @test testva[9] == [-1, -2, -3, -4] |
28 | 47 | @test testva[end] == [-1, -2, -3, -4] |
| 48 | +@test testda[9] == [-1, -2, -3, -4] |
| 49 | +@test testda[end] == [-1, -2, -3, -4] |
29 | 50 |
|
30 | 51 | # Currently we enforce the general shape, they can just be different lengths, ie we |
31 | 52 | # can't do |
32 | 53 | # Decide if this is desired, or remove this restriction |
33 | 54 | @test_throws MethodError push!(testva, [-1 -2 -3 -4]) |
34 | 55 | @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]) |
35 | 58 |
|
36 | | -# convert array from VectorOfArray |
| 59 | +# convert array from VectorOfArray/DiffEqArray |
| 60 | +t = 1:8 |
37 | 61 | recs = [rand(10, 7) for i = 1:8] |
38 | 62 | testva = VectorOfArray(recs) |
| 63 | +testda = DiffEqArray(recs,t) |
39 | 64 | testa = cat(recs...,dims=3) |
| 65 | + |
40 | 66 | @test convert(Array,testva) == testa |
| 67 | +@test convert(Array,testda) == testa |
41 | 68 |
|
| 69 | +t = 1:3 |
42 | 70 | recs = [[1 2; 3 4], [3 5; 6 7], [8 9; 10 11]] |
43 | 71 | testva = VectorOfArray(recs) |
| 72 | +testda = DiffEqArray(recs,t) |
| 73 | + |
44 | 74 | @test size(convert(Array,testva)) == (2,2,3) |
| 75 | +@test size(convert(Array,testda)) == (2,2,3) |
45 | 76 |
|
46 | | -# create similar VectorOfArray |
| 77 | +# create similar VectorOfArray/DiffEqArray |
| 78 | +t = 1:4 |
47 | 79 | recs = [rand(6) for i = 1:4] |
48 | 80 | testva = VectorOfArray(recs) |
| 81 | + |
49 | 82 | testva2 = similar(testva) |
50 | 83 | @test typeof(testva2) == typeof(testva) |
51 | 84 | @test size(testva2) == size(testva) |
@@ -77,3 +110,6 @@ emptyda = DiffEqArray(Array{Vector{Float64}}([]), Vector{Float64}()) |
77 | 110 |
|
78 | 111 | A = VectorOfArray(map(i->rand(2,4),1:7)) |
79 | 112 | @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