Skip to content

Commit

Permalink
improve code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreMartinon committed May 17, 2024
1 parent ca7e23b commit 855d2e9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 11 deletions.
4 changes: 1 addition & 3 deletions src/CTDirect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@ const nlp_constraints = CTBase.nlp_constraints
const matrix2vec = CTBase.matrix2vec

# includes
#include("init.jl")
include("utils.jl")
include("problem.jl")
include("solution.jl")
include("solve.jl")

# export functions only for user
export solve
export available_methods
export is_solvable
export solve
#export OptimalControlInit
export directTranscription
export getNLP
export setDOCPInit
Expand Down
8 changes: 0 additions & 8 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ $(TYPEDSIGNATURES)
Retrieve state variables at given time step from the NLP variables
"""
function get_state_at_time_step(xu, docp, i::Int64)
"""
return
x(t_i)
"""
nx = docp.dim_NLP_state
n = docp.ocp.state_dimension
N = docp.dim_NLP_steps
Expand Down Expand Up @@ -65,10 +61,6 @@ $(TYPEDSIGNATURES)
Retrieve control variables at given time step from the NLP variables
"""
function get_control_at_time_step(xu, docp, i)
"""
return
u(t_i)
"""
nx = docp.dim_NLP_state
m = docp.ocp.control_dimension
N = docp.dim_NLP_steps
Expand Down
21 changes: 21 additions & 0 deletions test/suite/misc.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using CTDirect

println("Test: misc")

# simple integrator (control split as positive/negative parts)
ocp = Model()
state!(ocp, 1)
control!(ocp, 2)
time!(ocp, [0, 1])
constraint!(ocp, :initial, -1, :initial_constraint)
constraint!(ocp, :final, 0, :final_constraint)
constraint!(ocp, :control, 1:2, [0,0], [Inf, Inf], :positive_controls)
dynamics!(ocp, (x, u) -> -x - u[1] + u[2])
objective!(ocp, :lagrange, (x, u) -> (u[1]+u[2])^2)

@testset verbose = true showtiming = true ":control_dim_2" begin
@test (:adnlp,:ipopt) in available_methods()
@test is_solvable(ocp)
sol = solve(ocp, print_level=5)
@test sol.objective 0.313 rtol=1e-2
end
20 changes: 20 additions & 0 deletions test/test_misc.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using CTDirect

println("Test: misc")

# simple integrator (control split as positive/negative parts)
ocp = Model()
state!(ocp, 1)
control!(ocp, 2)
time!(ocp, [0, 1])
constraint!(ocp, :initial, -1, :initial_constraint)
constraint!(ocp, :final, 0, :final_constraint)
constraint!(ocp, :control, 1:2, [0,0], [Inf, Inf], :positive_controls)
dynamics!(ocp, (x, u) -> -x - u[1] + u[2])
objective!(ocp, :lagrange, (x, u) -> (u[1]+u[2])^2)

println(available_methods())
println(is_solvable(ocp))

sol = solve(ocp, print_level=5)
println("Expected Objective 0.313, found ", sol.objective)

0 comments on commit 855d2e9

Please sign in to comment.