|
1 | 1 | @testset "Univariate History" begin |
| 2 | + # Constructors |
2 | 3 | h_empty1 = History(0.0, 1.0) |
3 | 4 | h_empty2 = History(0.0, 1.0, 2) |
4 | 5 |
|
5 | | - @test h_empty1 isa History{Float64} |
6 | | - @test h_empty2 isa History{Float64} |
| 6 | + @test h_empty1 isa History{Float64,Any} |
| 7 | + @test h_empty2 isa History{Float64,Any} |
7 | 8 | @test ndims(h_empty1) == 1 |
8 | 9 | @test ndims(h_empty2) == 2 |
9 | 10 | @test isempty(h_empty1) |
10 | 11 | @test isempty(h_empty2) |
11 | 12 |
|
12 | 13 | h = History([0.2, 0.8, 1.1], 0.0, 2.0, ["a", "b", "c"]); |
13 | 14 |
|
| 15 | + @test h isa History{Float64,String} |
| 16 | + |
| 17 | + # Access |
14 | 18 | @test duration(h) == 2.0 |
15 | 19 | @test nb_events(h) == 3 |
16 | 20 | @test nb_events(h, 1.0, 2.0) == 1 |
|
21 | 25 | @test event_times(h) == [0.2, 0.8, 1.1] |
22 | 26 | @test event_times(h, 0.2, 0.8) == [0.2] |
23 | 27 | @test event_times(h, 0.8, 0.2) == [] |
| 28 | + @test event_times(h, nothing) == h.times |
24 | 29 | @test event_marks(h) == ["a", "b", "c"] |
25 | 30 | @test event_marks(h, 0.2, 0.8) == ["a"] |
26 | 31 | @test event_marks(h, 0.8, 0.2) == [] |
27 | 32 | @test ndims(h) == 1 |
28 | 33 | @test event_dims(h) == fill(nothing, 3) |
29 | 34 |
|
| 35 | + # Interface |
30 | 36 | push!(h, 1.7, "d") |
31 | 37 |
|
32 | 38 | @test has_events(h, 1.5, 2.0) |
33 | 39 |
|
34 | 40 | h2 = History(; times=[2.3], marks=["e"], tmin=2.0, tmax=2.5) |
35 | | - h3 = History(; times=[[1], [2, 2.5]], tmin=0, tmax=3) |
36 | 41 |
|
37 | | - @test (event_marks(h3) == fill(nothing, 3)) && (event_dims(h3) == [1, 2, 2]) |
38 | 42 | @test string(h2) == "History{Float64,String} with 1 events on interval [2.0, 2.5)" |
39 | 43 |
|
40 | 44 | h_cat = cat(h, h2) |
|
75 | 79 | @test event_marks(h_multi) == ["a", "c", "b", "d"] |
76 | 80 | @test event_dims(h_multi) == [1, 2, 1, 2] |
77 | 81 |
|
| 82 | + h_multi1 = History(h_multi, 1) |
| 83 | + h_multi2 = History(h_multi, 2) |
| 84 | + |
| 85 | + @test event_times(h_multi1) == times1 |
| 86 | + @test event_times(h_multi2) == times2 |
| 87 | + @test event_marks(h_multi1) == marks1 |
| 88 | + @test event_marks(h_multi2) == marks2 |
| 89 | + |
78 | 90 | @test_throws DomainError History(rand(3), 0, 1, rand(3), [1, 2, 3], 2) |
79 | 91 | @test event_dims(History([[0.5]], 0, 1)) == [nothing] |
80 | 92 |
|
| 93 | + @test_throws DomainError History([1.0, 1.0, 2.0, 3.0, 4.0], 0.0, 5.0, fill(nothing, 5), [1, 1, 1, 2, 1], 2) |
| 94 | + @test_throws DomainError History([1.0, 1.0, 1.0, 2.0, 3.0], 0.0, 5.0, fill(nothing, 5), [1, 2, 1, 2, 1], 2) |
| 95 | + |
81 | 96 | # Test dimension-specific methods |
82 | 97 | @test event_times(h_multi, 1) == [0.1, 0.5] |
83 | 98 | @test event_times(h_multi, 2) == [0.2, 0.8] |
|
0 commit comments