|
| 1 | +module TestOCPState |
| 2 | + |
| 3 | +using Test |
| 4 | +using CTBase |
| 5 | +using CTModels |
| 6 | +using Main.TestOptions: VERBOSE, SHOWTIMING |
| 7 | + |
1 | 8 | 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₂"] |
2 | 40 |
|
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 |
62 | 68 | end |
| 69 | + |
| 70 | +end # module |
| 71 | + |
| 72 | +test_state() = TestOCPState.test_state() |
0 commit comments