Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bjack205 committed Mar 27, 2022
1 parent 1c4b3e8 commit 5731b66
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions test/trajectories.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ using RobotDynamics: state, control, states, controls

@testset "Trajectories" begin
n,m,N = 5,3,11
nx = fill(n,N)
nu = fill(m,N)
t,dt = 0.0,0.1
x = @SVector rand(n)
u = @SVector rand(m)
Expand All @@ -21,7 +23,7 @@ Z = RD.SampledTrajectory(n,m,dt=dt,N=N)
@test Z[1].t 0
@test Z[N].t (N-1)*dt
@test RobotDynamics.is_terminal(Z[end]) == true
@test RobotDynamics.dims(Z) == (Any,Any,N)
@test RobotDynamics.dims(Z) == (nx,nu,N)
@test RobotDynamics.num_vars(Z) == N*(n+m)-m

Z = RD.SampledTrajectory{n,m}(n,m, dt=dt, N=N, equal=true)
Expand All @@ -37,7 +39,7 @@ Z = RD.SampledTrajectory{n,m}(n,m, dt=dt, N=N, equal=true)
@test Z[N].t (N-1)*dt
@test RobotDynamics.is_terminal(Z[end]) == false
@test RobotDynamics.num_vars(Z) == N*(n+m)
@test RD.dims(Z) == (n,m,N)
@test RD.dims(Z) == (nx,nu,N)

#--- Try different time inputs
tf = (N - 1) * dt
Expand Down Expand Up @@ -179,19 +181,21 @@ RobotDynamics.shift_fill!(Z)
# @test !(conval.vals ≈ [zeros(n) for k = 1:N-1])

# Test rollout
nx = fill(n,N)
nu = fill(m,N)
RD.rollout!(RD.StaticReturn(), dmodel, Z, X[1])
Zmut = RD.SampledTrajectory([RD.KnotPoint{n,m}(MVector{n+m}(z.z), z.t, z.dt) for z in Z])
RD.rollout!(RD.InPlace(), dmodel, Zmut, X[1])
@test Z Zmut

# Block constructors
Z = RD.SampledTrajectory{n,m}(randn(n,N), randn(m,N-1), tf=2.0)
@test RD.dims(Z) == (n,m,N)
@test RD.dims(Z) == (nx,nu,N)
@test Z[end].t == 2.0
@test all(z->z.dt 0.2, Z[1:end-1])

Z = RD.SampledTrajectory([randn(n) for k = 1:N], [randn(m) for k = 1:N], dt=0.1)
@test RD.dims(Z) == (Any,Any,N)
@test RD.dims(Z) == (nx,nu,N)
@test Z[end].t == 1.0
@test RD.gettimes(Z) range(0,tf,step=dt)

Expand Down Expand Up @@ -221,7 +225,7 @@ U = [randn(m) for m in nu]
dt = 0.1
Z = SampledTrajectory(X, U, dt=dt)
@test Z isa SampledTrajectory{Any,Any}
@test RD.dims(Z) == (Any,Any,11)
@test RD.dims(Z) == (nx,nu,11)
@test RD.dims(Z[1]) == (4,2)
@test RD.dims(Z[end]) == (2,1)

Expand Down

2 comments on commit 5731b66

@bjack205
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/57445

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.4 -m "<description of version>" 5731b66c5c478559f9a51c3db0535a05de912623
git push origin v0.4.4

Please sign in to comment.