Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ocots committed Jun 13, 2024
1 parent e81980b commit f6e69d4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 55 deletions.
49 changes: 0 additions & 49 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,55 +11,6 @@ const constraint_type = CTBase.constraint_type

#
include("utils.jl")
function __constraint!(
ocp::OptimalControlModel{<: TimeDependence, V},
type::Symbol,
rg::Index,
lb::Union{ctVector,Nothing},
ub::Union{ctVector,Nothing},
label::Symbol=CTBase.__constraint_label()) where {V <: VariableDependence}

constraint!(ocp, type, rg=rg.val, f=nothing, lb=lb, ub=ub, label=label)
nothing # to force to return nothing

end

function __constraint!(
ocp::OptimalControlModel{<: TimeDependence, V},
type::Symbol,
rg::OrdinalRange{<:Integer},
lb::Union{ctVector,Nothing},
ub::Union{ctVector,Nothing},
label::Symbol=CTBase.__constraint_label()) where {V <: VariableDependence}

constraint!(ocp, type, rg=rg, f=nothing, lb=lb, ub=ub, label=label)
nothing # to force to return nothing

end

function __constraint!(
ocp::OptimalControlModel,
type::Symbol,
lb::Union{ctVector,Nothing},
ub::Union{ctVector,Nothing},
label::Symbol=CTBase.__constraint_label())

constraint!(ocp, type, rg=nothing, f=nothing, lb=lb, ub=ub, label=label)
nothing # to force to return nothing

end

function __constraint!(
ocp::OptimalControlModel{T, V},
type::Symbol,
f::Function,
lb::Union{ctVector,Nothing},
ub::Union{ctVector,Nothing},
label::Symbol=CTBase.__constraint_label()) where {T, V}

constraint!(ocp, type, rg=nothing, f=f, lb=lb, ub=ub, label=label)
nothing # to force to return nothing
end

#
@testset verbose = true showtiming = true "Base" begin
Expand Down
6 changes: 0 additions & 6 deletions test/test_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,6 @@ end
@test constraint(ocp, :c0)(x, ∅) == x
@test constraint(ocp, :cf)(∅, x) == x

ocp = Model(); __time!(ocp, 0, 1); state!(ocp, 2); control!(ocp, 1)
x = [12, 13]
x0 = [0, 1]
xf = [1, 2]
@test_throws IncorrectArgument __constraint!(ocp, :initial, Index(2), x0, :c0)
@test_throws IncorrectArgument __constraint!(ocp, :final, Index(2), xf, :cf)
constraint!(ocp, :initial, rg=1, lb=x0, ub=x0, label=:c00)
constraint!(ocp, :final, rg=1, lb=xf, ub=xf, label=:cff)
@test constraint(ocp, :c00)(x, ∅) == x
Expand Down
54 changes: 54 additions & 0 deletions test/utils.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# time!

function __time!(ocp::OptimalControlModel{<: TimeDependence, NonFixed}, t0::Time, indf::Index, name::String=CTBase.__time_name())
time!(ocp; t0=t0, indf=indf.val, name=name)
end
Expand Down Expand Up @@ -28,4 +30,56 @@ end

function __time!(ocp::OptimalControlModel, t0::Time, tf::Time, name::Symbol)
time!(ocp; t0=t0, tf=tf, name=name)
end

# constraint!

function __constraint!(
ocp::OptimalControlModel{<: TimeDependence, V},
type::Symbol,
rg::Index,
lb::Union{ctVector,Nothing},
ub::Union{ctVector,Nothing},
label::Symbol=CTBase.__constraint_label()) where {V <: VariableDependence}

constraint!(ocp, type, rg=rg.val, f=nothing, lb=lb, ub=ub, label=label)
nothing # to force to return nothing

end

function __constraint!(
ocp::OptimalControlModel{<: TimeDependence, V},
type::Symbol,
rg::OrdinalRange{<:Integer},
lb::Union{ctVector,Nothing},
ub::Union{ctVector,Nothing},
label::Symbol=CTBase.__constraint_label()) where {V <: VariableDependence}

constraint!(ocp, type, rg=rg, f=nothing, lb=lb, ub=ub, label=label)
nothing # to force to return nothing

end

function __constraint!(
ocp::OptimalControlModel,
type::Symbol,
lb::Union{ctVector,Nothing},
ub::Union{ctVector,Nothing},
label::Symbol=CTBase.__constraint_label())

constraint!(ocp, type, rg=nothing, f=nothing, lb=lb, ub=ub, label=label)
nothing # to force to return nothing

end

function __constraint!(
ocp::OptimalControlModel{T, V},
type::Symbol,
f::Function,
lb::Union{ctVector,Nothing},
ub::Union{ctVector,Nothing},
label::Symbol=CTBase.__constraint_label()) where {T, V}

constraint!(ocp, type, rg=nothing, f=f, lb=lb, ub=ub, label=label)
nothing # to force to return nothing
end

0 comments on commit f6e69d4

Please sign in to comment.