Skip to content

Commit

Permalink
test: add downstream tests for SymbolicIndexingInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Dec 11, 2023
1 parent aa50d32 commit 2ded1ac
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ if GROUP == "All" || GROUP == "Core"
@safetestset "LogExpFunctions Test" begin include("logexpfunctions.jl") end
end

if GROUP == "All" || GROUP == "Core" || GROUP == "SymbolicIndexingInterface"
@safetestset "SymbolicIndexingInterface Trait Test" begin
include("symbolic_indexing_interface_trait.jl")
end
@safetestset "SymbolicIndexingInterface Parameter Indexing Test" begin
include("symbolic_indexing_interface_parameter_indexing.jl")
end
end

if GROUP == "Downstream"
activate_downstream_env()
#@time @safetestset "ParameterizedFunctions MATLABDiffEq Regression Test" begin include("downstream/ParameterizedFunctions_MATLAB.jl") end
Expand Down
23 changes: 23 additions & 0 deletions test/symbolic_indexing_interface_parameter_indexing.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using SymbolicIndexingInterface
using Symbolics

struct FakeIntegrator{P}
p::P
end

SymbolicIndexingInterface.symbolic_container(fp::FakeIntegrator) = fp.sys
SymbolicIndexingInterface.parameter_values(fp::FakeIntegrator) = fp.p

@variables a[1:2] b
sys = SymbolCache([:x, :y, :z], [a[1], a[2], b], [:t])
p = [1.0, 2.0, 3.0]
fi = FakeIntegrator(copy(p))
for (i, sym) in [(1, a[1]), (2, a[2]), (3, b), ([1,2], a), ([1, 3], [a[1], b]), ((2, 3), (a[2], b))]
get = getp(sys, sym)
set! = setp(sys, sym)
true_value = i isa Tuple ? getindex.((p,), i) : p[i]
@test get(fi) == true_value
set!(fi, 0.5 .* i)
@test get(fi) == 0.5 .* i
set!(fi, true_value)
end
12 changes: 12 additions & 0 deletions test/symbolic_indexing_interface_trait.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Symbolics
using SymbolicUtils
using SymbolicIndexingInterface

@test all(symbolic_type.([SymbolicUtils.BasicSymbolic, Symbolics.Num]) .==
(ScalarSymbolic(),))
@test symbolic_type(Symbolics.Arr) == ArraySymbolic()
@variables x
@test symbolic_type(x) == ScalarSymbolic()
@variables y[1:3]
@test symbolic_type(y) == ArraySymbolic()
@test all(symbolic_type.(collect(y)) .== (ScalarSymbolic(),))

0 comments on commit 2ded1ac

Please sign in to comment.