Skip to content

Commit 638e93a

Browse files
committed
Added some tests for conversions and promotion
1 parent 152d06e commit 638e93a

File tree

7 files changed

+31
-2
lines changed

7 files changed

+31
-2
lines changed

docs/src/man/creating_systems.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ ControlSystems._string_mat_with_headers(a::SizedArray) = ControlSystems._string_
9191
Notice the different matrix types used
9292
```jldoctest HSS
9393
julia> sys = ss([-5 0; 0 -5],[2; 2],[3 3],[0])
94-
StateSpace{Continuous,Int64,Array{Int64,2}}
94+
StateSpace{Continuous,Int64}
9595
A =
9696
-5 0
9797
0 -5

src/types/DelayLtiSystem.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ function /(anything, sys::DelayLtiSystem)
109109
/(anything, sys.P.P) # If all delays are zero, invert the inner system
110110
end
111111

112+
113+
# Test equality (of realizations)
114+
function ==(sys1::DelayLtiSystem, sys2::DelayLtiSystem)
115+
all(getfield(sys1, f) == getfield(sys2, f) for f in fieldnames(DelayLtiSystem))
116+
end
117+
118+
112119
ninputs(sys::DelayLtiSystem) = size(sys.P.P, 2) - length(sys.Tau)
113120
noutputs(sys::DelayLtiSystem) = size(sys.P.P, 1) - length(sys.Tau)
114121
nstates(sys::DelayLtiSystem) = nstates(sys.P.P)

src/types/PartionedStateSpace.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,8 @@ end
220220
function Base.convert(::Type{<:PartionedStateSpace}, sys::T) where T<: StateSpace
221221
PartionedStateSpace(sys,sys.nu,sys.ny)
222222
end
223+
224+
# Test equality (of realizations)
225+
function ==(sys1::PartionedStateSpace, sys2::PartionedStateSpace)
226+
all(getfield(sys1, f) == getfield(sys2, f) for f in fieldnames(PartionedStateSpace))
227+
end

test/test_connections.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ s = tf("s")
9191
@test [D_111; Dtf_212] == [D_111; ss(Dtf_212)]
9292
@test append(D_111, Dtf_211) == append(D_111, ss(Dtf_211))
9393

94+
# Combination of DelayLtiSystem with TransferFunction and StateSpace
95+
@test [delay(1.0) tf(1, [1,2])] == [delay(1.0) ss(-2.0,1,1,0)]
96+
@test [delay(1.0) zpk([], [-2], 1)] == [delay(1.0) ss(-2.0,1,1,0)]
9497

9598
# hcat and vcat for StateSpace and Matrix
9699
A = [-1.1 -1.2; -1.3 -1.4]

test/test_delayed_systems.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using DelayDiffEq
22

33
@testset "test_delay_system" begin
4+
5+
# For simplicity, equality of DelayLtiSystems are tested over a finite set of frequencies
46
ω = 0.0:8
57

68

@@ -50,6 +52,10 @@ P2_fr = (im*ω .+ 1) ./ (im*ω .+ 2)
5052
@test freqresp(delay(1) * P2, ω)[:] P2_fr .* exp.(-im*ω) rtol=1e-15
5153

5254

55+
# Equality
56+
@test P1 == deepcopy(P1)
57+
@test P1 != deepcopy(P2)
58+
5359
# evalfr
5460
s_vec = [0, 1im, 1, 1 + 1im]
5561
@test [evalfr(delay(2), s)[1] for s in s_vec] [exp(-2*s) for s in s_vec] rtol=1e-16

test/test_partitioned_statespace.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ sys1.D12 == matrix(6.0)
2121
sys1.D21 == matrix(8.0)
2222
sys1.D22 == matrix(9.0)
2323

24-
2524
##
2625
sys2 = ControlSystems.PartionedStateSpace(ss(fill(1.0, 2, 2), fill(2.0, 2, 5), fill(3.0, 7, 2), fill(4.0, 7, 5)), 2, 3)
2726

@@ -36,6 +35,10 @@ sys2 = ControlSystems.PartionedStateSpace(ss(fill(1.0, 2, 2), fill(2.0, 2, 5), f
3635
@test sys2.D22 == fill(4.0, 4, 3)
3736

3837

38+
39+
@test sys1 == deepcopy(sys1)
40+
@test sys1 != deepcopy(sys2)
41+
3942
# TODO: Add some tests for interconnections, implicitly tested through delay system implementations though
4043
@test (sys1 + sys1).P[1, 1] == (sys1.P[1,1] + sys1.P[1,1])
4144

test/test_promotion.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ TG2 = typeof(G2)
3535
@test promote_type(typeof(tf(1)), typeof(tf(1))) == typeof(tf(1))
3636
@test promote_type(typeof(ss(1)), typeof(ss(1))) == typeof(ss(1))
3737

38+
39+
@test promote(ss(1), 1.0) == (ss(1.), ss(1.))
40+
@test promote(ss(1), 1) == (ss(1.), ss(1.))
3841
@test promote(ss(1), ss(1.)) == (ss(1.), ss(1.))
3942
@test promote(ss(1), tf(1.)) == (ss(1.), ss(1.))
4043
@test promote(ss(1), zpk(1.)) == (ss(1.), ss(1.))
@@ -43,5 +46,7 @@ TG2 = typeof(G2)
4346
@test promote(zpk(1), tf(1)) == (zpk(1.), zpk(1.))
4447
@test promote(ss(1), ss([1 .*im])) == (ss([1+0*im]),ss([1 .*im]))
4548
@test promote(ss(1), tf([1 .*im])) == (ss([1+0*im]),ss([1 .*im]))
49+
@test promote(tf(1), 1) == (tf(1.), tf(1.))
50+
4651

4752
end

0 commit comments

Comments
 (0)