Skip to content

Commit 33e4461

Browse files
committed
refactor: Complete modularization of ocp test files
- test_control.jl: Wrap in TestOCPControl module - test_defaults.jl: Wrap in TestOCPDefaults module - test_definition.jl: Wrap in TestOCPDefinition module - test_dual_model.jl: Wrap in TestOCPDualModel module - test_ocp_components.jl: Wrap in TestOCPComponents module - test_ocp_model_types.jl: Wrap in TestOCPModelTypes module - test_print.jl: Wrap in TestOCPPrint module - test_state.jl: Wrap in TestOCPState module - test_time_dependence.jl: Wrap in TestOCPTimeDependence module - test_variable.jl: Wrap in TestOCPVariable module All 58 test files in CTModels.jl are now modularized (100%). All files follow the standard test module pattern with VERBOSE/SHOWTIMING support.
1 parent 35fb57e commit 33e4461

10 files changed

Lines changed: 272 additions & 169 deletions

test/suite/ocp/test_control.jl

Lines changed: 68 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,71 @@
1+
module TestOCPControl
2+
3+
using Test
4+
using CTBase
5+
using CTModels
6+
using Main.TestOptions: VERBOSE, SHOWTIMING
7+
18
function test_control()
9+
Test.@testset "OCP Control" verbose = VERBOSE showtiming = SHOWTIMING begin
10+
# ControlModel
11+
12+
# some checks
13+
ocp = CTModels.PreModel()
14+
@test isnothing(ocp.control)
15+
@test !CTModels.__is_control_set(ocp)
16+
CTModels.control!(ocp, 1)
17+
@test CTModels.__is_control_set(ocp)
18+
19+
# control!
20+
ocp = CTModels.PreModel()
21+
@test_throws CTBase.IncorrectArgument CTModels.control!(ocp, 0)
22+
23+
ocp = CTModels.PreModel()
24+
CTModels.control!(ocp, 1)
25+
@test CTModels.dimension(ocp.control) == 1
26+
@test CTModels.name(ocp.control) == "u"
27+
@test CTModels.components(ocp.control) == ["u"]
28+
29+
ocp = CTModels.PreModel()
30+
CTModels.control!(ocp, 1, "v")
31+
@test CTModels.dimension(ocp.control) == 1
32+
@test CTModels.name(ocp.control) == "v"
33+
34+
ocp = CTModels.PreModel()
35+
CTModels.control!(ocp, 2)
36+
@test CTModels.dimension(ocp.control) == 2
37+
@test CTModels.name(ocp.control) == "u"
38+
@test CTModels.components(ocp.control) == ["u₁", "u₂"]
239

3-
#
4-
5-
# ControlModel
6-
7-
# some checks
8-
ocp = CTModels.PreModel()
9-
@test isnothing(ocp.control)
10-
@test !CTModels.__is_control_set(ocp)
11-
CTModels.control!(ocp, 1)
12-
@test CTModels.__is_control_set(ocp)
13-
14-
# control!
15-
ocp = CTModels.PreModel()
16-
@test_throws CTBase.IncorrectArgument CTModels.control!(ocp, 0)
17-
18-
ocp = CTModels.PreModel()
19-
CTModels.control!(ocp, 1)
20-
@test CTModels.dimension(ocp.control) == 1
21-
@test CTModels.name(ocp.control) == "u"
22-
@test CTModels.components(ocp.control) == ["u"]
23-
24-
ocp = CTModels.PreModel()
25-
CTModels.control!(ocp, 1, "v")
26-
@test CTModels.dimension(ocp.control) == 1
27-
@test CTModels.name(ocp.control) == "v"
28-
29-
ocp = CTModels.PreModel()
30-
CTModels.control!(ocp, 2)
31-
@test CTModels.dimension(ocp.control) == 2
32-
@test CTModels.name(ocp.control) == "u"
33-
@test CTModels.components(ocp.control) == ["u₁", "u₂"]
34-
35-
ocp = CTModels.PreModel()
36-
CTModels.control!(ocp, 2, :v)
37-
@test CTModels.dimension(ocp.control) == 2
38-
@test CTModels.name(ocp.control) == "v"
39-
@test CTModels.components(ocp.control) == ["v₁", "v₂"]
40-
41-
ocp = CTModels.PreModel()
42-
CTModels.control!(ocp, 2, "v", ["a", "b"])
43-
@test CTModels.dimension(ocp.control) == 2
44-
@test CTModels.name(ocp.control) == "v"
45-
@test CTModels.components(ocp.control) == ["a", "b"]
46-
47-
ocp = CTModels.PreModel()
48-
CTModels.control!(ocp, 2, "v", [:a, :b])
49-
@test CTModels.dimension(ocp.control) == 2
50-
@test CTModels.name(ocp.control) == "v"
51-
@test CTModels.components(ocp.control) == ["a", "b"]
52-
53-
# set twice
54-
ocp = CTModels.PreModel()
55-
CTModels.control!(ocp, 1)
56-
@test_throws CTBase.UnauthorizedCall CTModels.control!(ocp, 1)
57-
58-
# wrong number of components
59-
ocp = CTModels.PreModel()
60-
@test_throws CTBase.IncorrectArgument CTModels.control!(ocp, 2, "v", ["a"])
40+
ocp = CTModels.PreModel()
41+
CTModels.control!(ocp, 2, :v)
42+
@test CTModels.dimension(ocp.control) == 2
43+
@test CTModels.name(ocp.control) == "v"
44+
@test CTModels.components(ocp.control) == ["v₁", "v₂"]
45+
46+
ocp = CTModels.PreModel()
47+
CTModels.control!(ocp, 2, "v", ["a", "b"])
48+
@test CTModels.dimension(ocp.control) == 2
49+
@test CTModels.name(ocp.control) == "v"
50+
@test CTModels.components(ocp.control) == ["a", "b"]
51+
52+
ocp = CTModels.PreModel()
53+
CTModels.control!(ocp, 2, "v", [:a, :b])
54+
@test CTModels.dimension(ocp.control) == 2
55+
@test CTModels.name(ocp.control) == "v"
56+
@test CTModels.components(ocp.control) == ["a", "b"]
57+
58+
# set twice
59+
ocp = CTModels.PreModel()
60+
CTModels.control!(ocp, 1)
61+
@test_throws CTBase.UnauthorizedCall CTModels.control!(ocp, 1)
62+
63+
# wrong number of components
64+
ocp = CTModels.PreModel()
65+
@test_throws CTBase.IncorrectArgument CTModels.control!(ocp, 2, "v", ["a"])
66+
end
6167
end
68+
69+
end # module
70+
71+
test_control() = TestOCPControl.test_control()

test/suite/ocp/test_defaults.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
module TestOCPDefaults
2+
3+
using Test
4+
using CTBase
5+
using CTModels
6+
using Main.TestOptions: VERBOSE, SHOWTIMING
7+
18
function test_defaults()
29
# TODO: add tests for src/core/default.jl (default options, etc.).
310

@@ -53,3 +60,7 @@ function test_defaults()
5360
Test.@test CTModels.__filename_export_import() == "solution"
5461
end
5562
end
63+
64+
end # module
65+
66+
test_defaults() = TestOCPDefaults.test_defaults()

test/suite/ocp/test_definition.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
module TestOCPDefinition
2+
3+
using Test
4+
using CTModels
5+
using Main.TestOptions: VERBOSE, SHOWTIMING
6+
17
function test_definition()
28
# TODO: add tests for src/ocp/definition.jl.
39

@@ -50,3 +56,7 @@ function test_definition()
5056
Test.@test CTModels.definition(model) === expr
5157
end
5258
end
59+
60+
end # module
61+
62+
test_definition() = TestOCPDefinition.test_definition()

test/suite/ocp/test_dual_model.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
module TestOCPDualModel
2+
3+
using Test
4+
using CTModels
5+
using Main.TestOptions: VERBOSE, SHOWTIMING
6+
17
function test_dual_model()
28
# TODO: add tests for src/ocp/dual_model.jl.
39

@@ -27,3 +33,7 @@ function test_dual_model()
2733
Test.@test CTModels.variable_constraints_ub_dual(dual) === vc_ub
2834
end
2935
end
36+
37+
end # module
38+
39+
test_dual_model() = TestOCPDualModel.test_dual_model()

test/suite/ocp/test_ocp_components.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
module TestOCPComponents
2+
3+
using Test
4+
using CTBase
5+
using CTModels
6+
using Main.TestOptions: VERBOSE, SHOWTIMING
7+
18
function test_ocp_components()
29
# TODO: add tests for src/core/types/ocp_components.jl.
310

@@ -62,3 +69,7 @@ function test_ocp_components()
6269
Test.@test constraints.variable_box == ()
6370
end
6471
end
72+
73+
end # module
74+
75+
test_ocp_components() = TestOCPComponents.test_ocp_components()

test/suite/ocp/test_ocp_model_types.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
module TestOCPModelTypes
2+
3+
using Test
4+
using CTModels
5+
using Main.TestOptions: VERBOSE, SHOWTIMING
6+
17
function test_ocp_model_types()
28
# TODO: add tests for src/core/types/ocp_model.jl.
39

@@ -140,3 +146,7 @@ function test_ocp_model_types()
140146
Test.@test can_build(ocp)
141147
end
142148
end
149+
150+
end # module
151+
152+
test_ocp_model_types() = TestOCPModelTypes.test_ocp_model_types()

test/suite/ocp/test_print.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
module TestOCPPrint
2+
3+
using Test
4+
using CTModels
5+
using Main.TestOptions: VERBOSE, SHOWTIMING
6+
17
function test_print()
28
# TODO: add tests for src/ocp/print.jl.
39

@@ -78,3 +84,7 @@ function test_print()
7884
Test.@test occursin("optimal control problem is of the form:", s)
7985
end
8086
end
87+
88+
end # module
89+
90+
test_print() = TestOCPPrint.test_print()

test/suite/ocp/test_state.jl

Lines changed: 69 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,72 @@
1+
module TestOCPState
2+
3+
using Test
4+
using CTBase
5+
using CTModels
6+
using Main.TestOptions: VERBOSE, SHOWTIMING
7+
18
function test_state()
9+
Test.@testset "OCP State" verbose = VERBOSE showtiming = SHOWTIMING begin
10+
# StateModel
11+
12+
# some checks
13+
ocp = CTModels.PreModel()
14+
@test isnothing(ocp.state)
15+
@test !CTModels.__is_state_set(ocp)
16+
CTModels.state!(ocp, 1)
17+
@test CTModels.__is_state_set(ocp)
18+
19+
# state!
20+
ocp = CTModels.PreModel()
21+
@test_throws CTBase.IncorrectArgument CTModels.state!(ocp, 0)
22+
23+
ocp = CTModels.PreModel()
24+
CTModels.state!(ocp, 1)
25+
@test CTModels.dimension(ocp.state) == 1
26+
@test CTModels.name(ocp.state) == "x"
27+
@test CTModels.components(ocp.state) == ["x"]
28+
29+
ocp = CTModels.PreModel()
30+
CTModels.state!(ocp, 1, "y")
31+
@test CTModels.dimension(ocp.state) == 1
32+
@test CTModels.name(ocp.state) == "y"
33+
@test CTModels.components(ocp.state) == ["y"]
34+
35+
ocp = CTModels.PreModel()
36+
CTModels.state!(ocp, 2)
37+
@test CTModels.dimension(ocp.state) == 2
38+
@test CTModels.name(ocp.state) == "x"
39+
@test CTModels.components(ocp.state) == ["x₁", "x₂"]
240

3-
#
4-
5-
# StateModel
6-
7-
# some checks
8-
ocp = CTModels.PreModel()
9-
@test isnothing(ocp.state)
10-
@test !CTModels.__is_state_set(ocp)
11-
CTModels.state!(ocp, 1)
12-
@test CTModels.__is_state_set(ocp)
13-
14-
# state!
15-
ocp = CTModels.PreModel()
16-
@test_throws CTBase.IncorrectArgument CTModels.state!(ocp, 0)
17-
18-
ocp = CTModels.PreModel()
19-
CTModels.state!(ocp, 1)
20-
@test CTModels.dimension(ocp.state) == 1
21-
@test CTModels.name(ocp.state) == "x"
22-
@test CTModels.components(ocp.state) == ["x"]
23-
24-
ocp = CTModels.PreModel()
25-
CTModels.state!(ocp, 1, "y")
26-
@test CTModels.dimension(ocp.state) == 1
27-
@test CTModels.name(ocp.state) == "y"
28-
@test CTModels.components(ocp.state) == ["y"]
29-
30-
ocp = CTModels.PreModel()
31-
CTModels.state!(ocp, 2)
32-
@test CTModels.dimension(ocp.state) == 2
33-
@test CTModels.name(ocp.state) == "x"
34-
@test CTModels.components(ocp.state) == ["x₁", "x₂"]
35-
36-
ocp = CTModels.PreModel()
37-
CTModels.state!(ocp, 2, :y)
38-
@test CTModels.dimension(ocp.state) == 2
39-
@test CTModels.name(ocp.state) == "y"
40-
@test CTModels.components(ocp.state) == ["y₁", "y₂"]
41-
42-
ocp = CTModels.PreModel()
43-
CTModels.state!(ocp, 2, "y", ["u", "v"])
44-
@test CTModels.dimension(ocp.state) == 2
45-
@test CTModels.name(ocp.state) == "y"
46-
@test CTModels.components(ocp.state) == ["u", "v"]
47-
48-
ocp = CTModels.PreModel()
49-
CTModels.state!(ocp, 2, "y", [:u, :v])
50-
@test CTModels.dimension(ocp.state) == 2
51-
@test CTModels.name(ocp.state) == "y"
52-
@test CTModels.components(ocp.state) == ["u", "v"]
53-
54-
# set twice
55-
ocp = CTModels.PreModel()
56-
CTModels.state!(ocp, 1)
57-
@test_throws CTBase.UnauthorizedCall CTModels.state!(ocp, 1)
58-
59-
# wrong number of components
60-
ocp = CTModels.PreModel()
61-
@test_throws CTBase.IncorrectArgument CTModels.state!(ocp, 2, "y", ["u"])
41+
ocp = CTModels.PreModel()
42+
CTModels.state!(ocp, 2, :y)
43+
@test CTModels.dimension(ocp.state) == 2
44+
@test CTModels.name(ocp.state) == "y"
45+
@test CTModels.components(ocp.state) == ["y₁", "y₂"]
46+
47+
ocp = CTModels.PreModel()
48+
CTModels.state!(ocp, 2, "y", ["u", "v"])
49+
@test CTModels.dimension(ocp.state) == 2
50+
@test CTModels.name(ocp.state) == "y"
51+
@test CTModels.components(ocp.state) == ["u", "v"]
52+
53+
ocp = CTModels.PreModel()
54+
CTModels.state!(ocp, 2, "y", [:u, :v])
55+
@test CTModels.dimension(ocp.state) == 2
56+
@test CTModels.name(ocp.state) == "y"
57+
@test CTModels.components(ocp.state) == ["u", "v"]
58+
59+
# set twice
60+
ocp = CTModels.PreModel()
61+
CTModels.state!(ocp, 1)
62+
@test_throws CTBase.UnauthorizedCall CTModels.state!(ocp, 1)
63+
64+
# wrong number of components
65+
ocp = CTModels.PreModel()
66+
@test_throws CTBase.IncorrectArgument CTModels.state!(ocp, 2, "y", ["u"])
67+
end
6268
end
69+
70+
end # module
71+
72+
test_state() = TestOCPState.test_state()

test/suite/ocp/test_time_dependence.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
module TestOCPTimeDependence
2+
3+
using Test
4+
using CTBase
5+
using CTModels
6+
using Main.TestOptions: VERBOSE, SHOWTIMING
7+
18
function test_time_dependence()
29
# TODO: add tests for src/ocp/time_dependence.jl.
310

@@ -54,3 +61,7 @@ function test_time_dependence()
5461
Test.@test CTModels.is_autonomous(pre_nonautonomous) === false
5562
end
5663
end
64+
65+
end # module
66+
67+
test_time_dependence() = TestOCPTimeDependence.test_time_dependence()

0 commit comments

Comments
 (0)