Skip to content

Commit

Permalink
Add missing tests for scalar corner cases (#174)
Browse files Browse the repository at this point in the history
* add tests and adjust type in test

* add minor change

* Update @system.jl

* Update @system.jl

* fix test

* test eltype of system macro's result

Co-authored-by: Christian Schilling <[email protected]>
  • Loading branch information
ueliwechsler and schillic authored Feb 18, 2020
1 parent d9e9331 commit 54c3013
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions test/@system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ end
@test @system(w' = A*w + B*u_1) == LinearControlContinuousSystem(A, B)
# similarily for x_ = A_*x_ + B_*u_ + c_
@test @system(w' = A*w + B*u_1 + c, wX, u_1U) == ConstrainedAffineControlContinuousSystem(A, B, c, X, U)

# scalar cases
@test @system(x' = x + u) == LinearControlContinuousSystem(hcat(1.), hcat(1.))
@test @system(x' = x + 0.1u) == LinearControlContinuousSystem(hcat(1.), hcat(0.1))
@test @system(x' = x + 0.1*u) == LinearControlContinuousSystem(hcat(1.), hcat(0.1))
sys = @system(x' = 0.3x + 0.1u + 0.2, xX, uU)
@test sys == ConstrainedAffineControlContinuousSystem(hcat(0.3), hcat(0.1), vcat(0.2), X, U)
end

@testset "@system for linear algebraic continous systems" begin
Expand Down Expand Up @@ -248,12 +255,14 @@ end
# =======================
@testset "@system with for an initial-value problem" begin
# continuous ivp in floating-point
s = IVP(LinearContinuousSystem(I(-1.0, 1)), Interval(-1, 1))
@test @system(x' = -1.0x, x(0) Interval(-1, 1)) == s

# similar for integers
s = IVP(LinearDiscreteSystem(I(-1, 1)), [1])
@test @system(x⁺ = -x, x(0) [1]) == s
ivp = @system(x' = -1.0x, x(0) Interval(-1, 1))
@test ivp == IVP(LinearContinuousSystem(I(-1.0, 1)), Interval(-1, 1)) &&
eltype(ivp.s.A) == Float64

# discrete ivp in floating-point
ivp = @system(x⁺ = -x, x(0) [1])
@test ivp == IVP(LinearDiscreteSystem(I(-1.0, 1)), [1]) &&
eltype(ivp.s.A) == Float64

# initial state assignment doesn't match state variable
@test_throws ArgumentError @system(x' = -x, t(0) Interval(-1.0, 1.0))
Expand Down

0 comments on commit 54c3013

Please sign in to comment.