Skip to content

Commit cbf61c6

Browse files
test: more comprehensive tests
1 parent 92fc778 commit cbf61c6

File tree

3 files changed

+58
-8
lines changed

3 files changed

+58
-8
lines changed

test/basic_indexing.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,33 @@ recs = [rand(8) for i in 1:10]
3636
testa = cat(recs..., dims = 2)
3737
testva = VectorOfArray(recs)
3838

39+
# Array functions
40+
@test size(testva) == (8, 10)
41+
@test axes(testva) == Base.OneTo.((8, 10))
42+
@test ndims(testva) == 2
43+
@test eltype(testva) == eltype(eltype(recs))
44+
testvasim = similar(testva)
45+
@test size(testvasim) == size(testva)
46+
@test eltype(testvasim) == eltype(testva)
47+
testvasim = similar(testva, Float32)
48+
@test size(testvasim) == size(testva)
49+
@test eltype(testvasim) == Float32
50+
testvb = deepcopy(testva)
51+
@test testva == testvb == recs
52+
53+
# Math operations
54+
@test testva + testvb == testva + recs == 2testva == 2 .* recs
55+
@test testva - testvb == testva - recs == 0 .* recs
56+
@test testva / 2 == recs ./ 2
57+
@test 2 .\ testva == 2 .\ recs
58+
3959
# ## Linear indexing
4060
@test_deprecated testva[1]
4161
@test_deprecated testva[1:2]
62+
@test_deprecated testva[begin]
63+
@test_deprecated testva[end]
64+
@test testva[begin] == testva[:, begin] == first(testva)
65+
@test testva[end] == testva[:, end] == last(testva)
4266
@test testa[:, 1] == recs[1]
4367
@test testva.u == recs
4468
@test testva[: ,2:end] == VectorOfArray([recs[i] for i in 2:length(recs)])

test/downstream/symbol_indexing.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ sol_new = DiffEqArray(sol.u[1:10],
2121
@test sol_new[RHS] (1 .- sol_new[x]) ./ 3.0
2222
@test sol_new[t] sol_new.t
2323
@test sol_new[t, 1:5] sol_new.t[1:5]
24+
@test sol.ps[τ] == sol_new.ps[τ] == 3.0
25+
@test_deprecated sol[τ]
26+
@test_deprecated sol_new[τ]
2427

2528
# Tables interface
2629
test_tables_interface(sol_new, [:timestamp, Symbol("x(t)")], hcat(sol_new[t], sol_new[x]))
Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,49 @@
1-
using RecursiveArrayTools, Test, LabelledArrays
1+
using RecursiveArrayTools, Test, LabelledArrays, SymbolicIndexingInterface
22

33
t = 0.0:0.1:1.0
44
f(x) = 2x
55
f2(x) = 3x
66

77
dx = DiffEqArray([[f(x), f2(x)] for x in t],
8-
t;
8+
t,
9+
[1.0, 2.0];
910
variables = [:a, :b],
11+
parameters = [:p, :q],
1012
independent_variables = [:t])
1113
@test dx[:t] == t
1214
@test dx[:a] == [f(x) for x in t]
13-
@test dx[:b] == [f2(x) for x in t]
14-
15-
dx = DiffEqArray([[f(x), f2(x)] for x in t],
16-
t;
17-
variables = [:a, :b],
18-
independent_variables = [:t])
15+
@test dx[:a, 2] f(t[2])
16+
@test dx[:b, 3] f2(t[3])
17+
@test dx[:a, 2:4] [f(x) for x in t[2:4]]
18+
@test dx[:b, 4:6] [f2(x) for x in t[4:6]]
19+
@test dx[:b] [f2(x) for x in t]
20+
@test dx[[:a, :b]] [[f(x), f2(x)] for x in t]
21+
@test dx[(:a, :b)] == [(f(x), f2(x)) for x in t]
22+
@test dx[[:a, :b], 3] [f(t[3]), f2(t[3])]
23+
@test dx[[:a, :b], 4:5] vcat(f.(t[4:5])', f2.(t[4:5])')
24+
@test dx.ps[[:p, :q]] == [1.0, 2.0]
25+
@test dx.ps[:p] == 1.0
26+
@test dx.ps[:q] == 2.0
1927
@test dx[:t] == t
28+
29+
@test symbolic_container(dx) isa SymbolCache
30+
@test parameter_values(dx) == [1.0, 2.0]
31+
@test is_variable.((dx,), [:a, :b, :p, :q, :t]) == [true, true, false, false, false]
32+
@test variable_index.((dx,), [:a, :b, :p, :q, :t]) == [1, 2, nothing, nothing, nothing]
33+
@test is_parameter.((dx,), [:a, :b, :p, :q, :t]) == [false, false, true, true, false]
34+
@test parameter_index.((dx,), [:a, :b, :p, :q, :t]) == [nothing, nothing, 1, 2, nothing]
35+
@test is_independent_variable.((dx,), [:a, :b, :p, :q, :t]) == [false, false, false, false, true]
36+
@test variable_symbols(dx) == [:a, :b]
37+
@test parameter_symbols(dx) == [:p, :q]
38+
@test independent_variable_symbols(dx) == [:t]
39+
@test is_time_dependent(dx)
40+
@test constant_structure(dx)
41+
2042
dx = DiffEqArray([[f(x), f2(x)] for x in t], t; variables = [:a, :b])
2143
@test_throws Exception dx[nothing] # make sure it isn't storing [nothing] as indepsym
2244

2345
ABC = @SLVector (:a, :b, :c);
2446
A = ABC(1, 2, 3);
2547
B = RecursiveArrayTools.DiffEqArray([A, A], [0.0, 2.0]);
2648
@test getindex(B, :a) == [1, 1]
49+

0 commit comments

Comments
 (0)