Skip to content

Commit

Permalink
Improve formatting of test results
Browse files Browse the repository at this point in the history
  • Loading branch information
ufechner7 committed Oct 18, 2024
1 parent e7f58c1 commit 4505720
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 42 deletions.
5 changes: 3 additions & 2 deletions test/bench3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if ! @isdefined res3
end

msg=""
@testset verbose = true "KPS3 benchmarking.... " begin
@testset verbose = true "KPS3 benchmarking.... " begin

function set_defaults()
KiteModels.clear!(kps)
Expand Down Expand Up @@ -85,7 +85,8 @@ t = @benchmark residual!(res, yd, y, p, t) setup = (res1 = zeros(SVector{SEGMENT
global msg = "Mean time residual! one point model: $(round(mean(t.times), digits=1)) ns"

end
println(msg)
printstyled("Benchmark results for KPS3:\n"; bold = true)
println(msg, "\n")

# julia> include("test/bench.jl")
# Test Summary: |
Expand Down
4 changes: 3 additions & 1 deletion test/bench4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if ! @isdefined kps4
end

msg = String[]
@testset verbose = true "KPS4 benchmarking...." begin
@testset verbose = true "KPS4 benchmarking... " begin

function set_defaults()
KiteModels.clear!(kps4)
Expand Down Expand Up @@ -131,7 +131,9 @@ push!(msg, ("Mean time residual!: $(round(mean(t.times), digits=1)) ns
# Julia 1.10 on Laptop on battery: 1047ns
# Julia 1.11 on Laptop on battery: 1035ns
end
printstyled("Benchmark results for KPS4:\n"; bold = true)
for i in eachindex(msg)
println(msg[i])
end
println()

15 changes: 9 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ using Test

cd("..")
KiteUtils.set_data_path("")
include("test_kps3.jl")
include("test_kps4.jl")
include("test_kps4_3l.jl")
include("bench3.jl")
include("bench4.jl")
include("test_helpers.jl")
@testset verbose = true "Testing KiteModels..." begin
include("test_orientation.jl")
include("test_kps3.jl")
include("test_kps4.jl")
include("test_kps4_3l.jl")
include("bench3.jl")
include("bench4.jl")
include("test_helpers.jl")
end
21 changes: 11 additions & 10 deletions test/test_helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using Test
using KiteModels
using Pkg

@testset "Testing KiteModels...." begin
@testset "Testing helper functions..." begin
path=pwd()
tmpdir=mktempdir()
mkpath(tmpdir)
Expand All @@ -24,7 +24,7 @@ using Pkg
tmpdir=mktempdir()
mkpath(tmpdir)
cd(tmpdir)
KiteModels.install_examples()
KiteModels.install_examples(false)
@test isfile(joinpath(tmpdir, "examples", "bench.jl"))
@test isfile(joinpath(tmpdir, "examples", "compare_kps3_kps4.jl"))
@test isfile(joinpath(tmpdir, "examples", "menu.jl"))
Expand All @@ -37,15 +37,16 @@ using Pkg
rm(tmpdir, recursive=true)
end
cd(path)

@test ! ("TestEnv" keys(Pkg.project().dependencies))
@test ! ("Revise" keys(Pkg.project().dependencies))
@test ! ("Plots" keys(Pkg.project().dependencies))
# ensure that BenchmarkTools is not in the main environment
oldprpath = Pkg.project().path
if ! Pkg.project().ispackage
Pkg.activate(".")
end
hasbm = ("BenchmarkTools" keys(Pkg.project().dependencies))
Pkg.activate(oldprpath)
@test ! hasbm
# # ensure that BenchmarkTools is not in the main environment
# oldprpath = Pkg.project().path
# if ! Pkg.project().ispackage
# Pkg.activate(".")
# end
# hasbm = ("BenchmarkTools" ∈ keys(Pkg.project().dependencies))
# Pkg.activate(oldprpath)
# @test ! hasbm
end
25 changes: 16 additions & 9 deletions test/test_kps4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -467,14 +467,14 @@ end
KiteModels.set_depower_steering!(kps4, kps4.set.depower_offset/100.0, 0.0)
height = sin(deg2rad(kps4.set.elevation)) * kps4.set.l_tether
kps4.v_wind .= kps4.v_wind_gnd * calc_wind_factor(kps4.am, height)
res1, res2 = find_steady_state!(kps4; stiffness_factor=0.035, prn=true)
res1, res2 = find_steady_state!(kps4; stiffness_factor=0.035, prn=false)
# TODO check why -9.81 appears in the residual
@test sum(res2) -9.81*(se().segments+ KiteModels.KITE_PARTICLES) # velocity and acceleration must be near zero
pre_tension = KiteModels.calc_pre_tension(kps4)
@test pre_tension > 1.0001
@test pre_tension < 1.01
@test unstretched_length(kps4) 392.0 # initial, unstreched tether lenght
println("length: ", tether_length(kps4))
# println("length: ", tether_length(kps4))
@test isapprox(tether_length(kps4), 408.74, rtol=1e-2) # real, streched tether length was: 406.4
# @test winch_force(kps) ≈ 276.25776695110034 # initial force at the winch [N]
# lift, drag = lift_drag(kps)
Expand All @@ -491,7 +491,7 @@ end
kps4.set.alpha_zero = 0.0
res = zeros(MVector{6*(kps4.set.segments+4), SimFloat})
y0, yd0 = KiteModels.init(kps4)
forces = spring_forces(kps4)
forces = spring_forces(kps4; prn=false)
ref_forces = [3.928735076156923e-12, 3.928735076156923e-12, 3.928735076156923e-12, 0.0, -3.928735076156923e-12, 1.1786205228470769e-11, 2.160277004750972, 2.1602770047433926, 2.1602770047441373, 2.1602770047074573, 2.1602770047483513, 2.1602770047483513, 2.1602770047074573, 2.1602770047433926, 2.160277004685822]
for i in 1:se().segments + KiteModels.KITE_PARTICLES + 1
@test isapprox(forces[i], ref_forces[i], atol=1e-6, rtol=1e-4)
Expand All @@ -512,19 +512,26 @@ end
kps4.set.depower = 23.6
kps4.set.solver = "IDA"
integrator = KiteModels.init_sim!(kps4; stiffness_factor=0.5, delta=0.0, prn=false)
println("\nStarting simulation...")
# println("\nStarting simulation...")
simulate(integrator, 100)
av_steps = simulate(integrator, STEPS-100)
if Sys.isapple()
result = isapprox(av_steps, 300, rtol=0.6)
if !result
println("isapple $av_steps")
end
println("isapple $av_steps")
@test isapprox(av_steps, 300, rtol=0.6)
@test result
else
println("not apple $av_steps")
@test isapprox(av_steps, 300, rtol=0.6)
result = isapprox(av_steps, 300, rtol=0.6)
if !result
println("not apple $av_steps")
end
@test result
end

lift, drag = KiteModels.lift_drag(kps4)
println(lift, " ", drag) # 703.7699568972286 161.44746368100536
# println(lift, " ", drag) # 703.7699568972286 161.44746368100536
@test isapprox(lift, 703.8, rtol=0.05)
sys_state = SysState(kps4)
update_sys_state!(sys_state, kps4)
Expand All @@ -536,7 +543,7 @@ end
integrator = KiteModels.init_sim!(kps4_; stiffness_factor=0.035, prn=false)
kps4_.set.version = 2
kps4_.stiffness_factor = 3
@test maximum(spring_forces(kps4_)) > 20000
@test maximum(spring_forces(kps4_; prn=false)) > 20000
end

# TODO Add test for winch_force
Expand Down
28 changes: 15 additions & 13 deletions test/test_kps4_3l.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ using Test, BenchmarkTools, StaticArrays, LinearAlgebra, KiteUtils
using KiteModels, KitePodModels

old_path = get_data_path()
@show old_path
# @show old_path
set_data_path(joinpath(dirname(dirname(pathof(KiteModels))), "data"))
kcu_3l::KCU = KCU(se("system_3l.yaml"))
kcu_3l.set.winch_model = "AsyncMachine"
k3l::KPS4_3L = KPS4_3L(kcu_3l)

pos, vel = nothing, nothing

@testset verbose = true "s tests...." begin
@testset verbose = true "KPS4_3l tests..." begin

tol::Float32 = 1e-5
prn::Bool = false
Expand Down Expand Up @@ -59,7 +59,7 @@ global initial_pos
# initial init
k3l.set.mass = 0.9
k3l.set.l_tether = 50.0
KiteModels.init_sim!(k3l; prn=true, torque_control=false)
KiteModels.init_sim!(k3l; prn=false, torque_control=false)
initial_pos = deepcopy(k3l.pos)
prn && println("initial_pos")
for i in 1:3
Expand All @@ -83,7 +83,7 @@ global initial_pos
# init after changing settings
k3l.set.mass = 1.0
k3l.set.l_tether = 51.0
KiteModels.init_sim!(k3l; prn=true, torque_control=false)
KiteModels.init_sim!(k3l; prn=false, torque_control=false)
pos2 = deepcopy(k3l.pos)
@test isapprox(k3l.tether_lengths[3], 51.0, atol=0.1)
for i in 4:k3l.num_A
Expand All @@ -93,15 +93,15 @@ global initial_pos
# init after changing settings back
k3l.set.mass = 0.9
k3l.set.l_tether = 50.0
KiteModels.init_sim!(k3l; prn=true, torque_control=false)
KiteModels.init_sim!(k3l; prn=false, torque_control=false)
pos3 = deepcopy(k3l.pos)
for i in eachindex(initial_pos)
@test isapprox(pos3[i], initial_pos[i], atol=tol, rtol=tol)
end

# init after changing only initial conditions
k3l.set.elevation = 84.0
KiteModels.init_sim!(k3l; prn=true, torque_control=false)
KiteModels.init_sim!(k3l; prn=false, torque_control=false)
pos4 = deepcopy(k3l.pos)
@test isapprox(rad2deg(calc_elevation(k3l)), 84.0, atol=2.0)
for i in 4:k3l.num_A
Expand All @@ -110,7 +110,7 @@ global initial_pos

# init after just stepping
KiteModels.next_step!(k3l)
KiteModels.init_sim!(k3l; prn=true, torque_control=false)
KiteModels.init_sim!(k3l; prn=false, torque_control=false)
pos5 = deepcopy(k3l.pos)
for i in eachindex(initial_pos)
@test isapprox(pos5[i], pos4[i], atol=tol, rtol=tol)
Expand All @@ -122,7 +122,7 @@ end

@testset "test_step " begin
set_defaults()
KiteModels.init_sim!(k3l; prn=true, torque_control=false)
KiteModels.init_sim!(k3l; prn=false, torque_control=false)

KiteModels.next_step!(k3l)
# pos2 = [
Expand Down Expand Up @@ -170,16 +170,18 @@ end

@testset "test_simulate " begin
STEPS = 10
KiteModels.init_sim!(k3l; prn=true, torque_control=false)
KiteModels.init_sim!(k3l; prn=false, torque_control=false)
# println("\nStarting simulation...")
av_steps, av_L_C = simulate(STEPS)
prn && println(av_steps)
if Sys.isapple()
println("isapple $av_steps")
prn || @test av_steps < 100
result = av_steps < 100
!result && println("isapple, KPS4_3L, steps: $av_steps")
prn || @test result
else
println("not apple $av_steps")
prn || @test av_steps < 100
result = av_steps < 100
!result && println("not apple, KPS4_3L, steps: $av_steps")
prn || @test result
end

if prn
Expand Down
2 changes: 1 addition & 1 deletion test/test_orientation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function obtain_results(s)
return rad2deg(roll), rad2deg(pitch), rad2deg(yaw), rad2deg(azimuth_north), rad2deg(elevation), rad2deg(heading)
end

@testset verbose=true "test_orientation" begin
@testset verbose=true "Test roll, pitch, yaw, azimuth, elevation and heading..." begin

# Kite at an elevation of 45 degrees and with 0 roll pitch yaw and azimuth. Heading is then 180 degrees"
@testset "elevation 45" begin
Expand Down

0 comments on commit 4505720

Please sign in to comment.