Skip to content

Commit

Permalink
Add problem tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bjack205 committed Apr 9, 2022
1 parent 9931cc5 commit c280cbb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
12 changes: 0 additions & 12 deletions src/problem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,6 @@ num_constraints(prob::Problem) = get_constraints(prob).p
@inline get_initial_state(prob::Problem) = prob.x0


"""
change_integration(prob::Problem, Q<:QuadratureRule)
Change dynamics integration for the problem. Returns a new problem.
"""
change_integration(prob::Problem, ::Type{Q}) where Q<:QuadratureRule =
Problem{Q}(prob)

function Problem{Q}(p::Problem) where Q
Problem{Q}(p.model, p.obj, p.constraints, p.x0, p.xf, p.Z, p.N, p.t0, p.tf)
end

"""
rollout!(::Problem)
Expand Down
21 changes: 20 additions & 1 deletion test/problems_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,23 @@ prob = Problem(dmodels, obj, x0, tf, xf=xf, constraints=copy(conSet))
@test prob.model === dmodels

dmodels2 = [copy(dmodel) for k = 1:N]
@test_throws AssertionError Problem(dmodels2, obj, x0, tf, xf=xf, constraints=copy(conSet))
@test_throws AssertionError Problem(dmodels2, obj, x0, tf, xf=xf, constraints=copy(conSet))

## Check dims
nx,nu,N = RD.dims(prob)
@test nx == fill(n,N)
@test nu == fill(m,N)

@test RD.state_dim(prob,1) == n
@test RD.control_dim(prob,1) == m

## Misc
@test TO.is_constrained(prob) == false
@test isnan(cost(prob))
rollout!(prob)
@test !isnan(cost(prob))
@test TO.get_model(prob) isa Vector{<:RD.DiscreteDynamics}

@test TO.set_initial_time!(prob, 1.0) == 1.0 + tf
@test prob.Z[1].t == 1.0
@test prob.Z[end].t == 1.0 + tf

0 comments on commit c280cbb

Please sign in to comment.