Unit tests
hdrake opened this issue · 2 comments
hdrake commented
I should at least have some unit tests for the key functions.
hdrake commented
Added a first unit test as a doctest (docstring test) in PR #5, which should be automatically tested by Travis Continuous Integration (CI) every time the PR is updated.
hdrake commented
As of 102fdda, there is now a high-level set of tests which run the temperature-constrainted optimization for 1.5, 2.0, 2.5, 3.0, 3.5, and 4.0ºC above pre-industrial. In each case, it checks that 1) the optimization solves successfully and 2) the result has a maximum temperature approximately equal to the goal temperature.
function temperature_optimization_works(name::String, temp_goal::Float64)
config_path = "../configurations"
model = ClimateModel(ClimateMARGO.IO.load_params(name, config_path=config_path))
status = optimize_controls!(model, temp_goal=temp_goal)
return (
(raw_status(status) == "Solve_Succeeded") &
isapprox(
maximum(T(model, M=true, R=true, G=true, A=true)),
temp_goal,
rtol=1.e-5
)
)
end
function tests()
@testset "Subset of tests" begin
for temp_goal in 1.5:0.5:4.0
@test temperature_optimization_works("default", temp_goal)
end
end
end