I’ve been trying to get my code coverage to 100% in my package ThreeBodyProblem.jl[GitHub - jared711/ThreeBodyProblem.jl: An astrodynamics package for working in the three body problem]
The last thing left that isn’t covered is a plot recipe. I have a test that uses this recipe, so the code inside the recipe is marked as covered, but the line where the @recipe macro is used still shows up as uncovered. See the photo below.
Below is the code for the recipe
using LinearAlgebra
using RecipesBase
"""
trajectory_2D(rv)
Outputs the x and y coordinates of the trajectory 'rv', which is a vector of vectors.
"""
function trajectory_2D(rv::Vector{Vector{Float64}})
N = length(rv)
x = [rv[i][1] for i = 1:N]
y = [rv[i][2] for i = 1:N]
return x,y
end
"""
trajectory_2D(rv)
Outputs the x, y, and z coordinates of the trajectory 'rv', which is a vector of vectors.
"""
function trajectory_3D(rv::Vector{Vector{Float64}})
N = length(rv)
x = [rv[i][1] for i = 1:N]
y = [rv[i][2] for i = 1:N]
z = [rv[i][3] for i = 1:N]
return x,y,z
end
"""
trajectory_2D(rv)
Outputs the ẋ and ẏ components of the velocity of the trajectory 'rv', which is a vector of vectors.
"""
function velocity_2D(rv)
N = length(rv)
ẋ = [rv[i][3] for i = 1:N]
ẏ = [rv[i][4] for i = 1:N]
return ẋ,ẏ
end
function velocity_3D(rv)
N = length(rv)
ẋ = [rv[i][4] for i = 1:N]
ẏ = [rv[i][5] for i = 1:N]
ż = [rv[i][6] for i = 1:N]
return ẋ,ẏ,ż
end
"""
Recipe for plotting trajectories
"""
@recipe function f(rv::Vector{Vector{T}} where T<:Real; label="trajectory", color=:black, planar=false, vel = false)
@series begin
label := label
seriescolor := color
if vel
if length(rv[1]) == 4 || planar
x,y = velocity_2D(rv)
elseif length(rv[1]) == 6
x,y,z = velocity_3D(rv)
else
error("Velocity must be 2D or 3D")
end
else
if length(rv[1]) == 2 || length(rv[1]) == 4 || planar
x,y = trajectory_2D(rv)
elseif length(rv[1]) == 3 || length(rv[1]) == 6
x,y,z = trajectory_3D(rv)
else
error("Trajectory must be 2D or 3D")
end
end
end
end
Here is the code for the test
using ThreeBodyProblem
using RecipesBase
using Test
using Plots
sys = earth_moon()
Lpts = computeLpts(sys)
t = LinRange(0,2π,10)
traj = [rot2inert([Lpts[1];zeros(3)],t[i],sys) for i ∈ eachindex(t)]
traj4D= [traj[i][[1,2,4,5]] for i ∈ eachindex(t)]
p = plot(traj);
@test !isempty(p)
p = plot(traj4D);
@test !isempty(p)
p = plot(traj, vel=true);
@test !isempty(p)
p = plot(traj4D);
@test !isempty(p)
@test !isempty(RecipesBase.apply_recipe(Dict{Symbol, Any}(), traj))
@test !isempty(RecipesBase.apply_recipe(Dict{Symbol, Any}(), traj4D))
@test !isempty(RecipesBase.apply_recipe(Dict{Symbol, Any}(:vel=>true), traj))
@test !isempty(RecipesBase.apply_recipe(Dict{Symbol, Any}(:vel=>true), traj4D))
If anyone could help me get that last line covered, I would greatly appreciate it. This is my first question on the Julia Discourse page, so please let me know if I’ve left anything out.