|
8 | 8 | @test timestamp(timeArray) == timestamp(copyTimeArray)
|
9 | 9 | @test values(timeArray) == values(copyTimeArray)
|
10 | 10 | end
|
11 |
| - |
| 11 | + |
12 | 12 | # Test case for deepcopying TimeArray
|
13 | 13 | @testset "Test DeepCopy TimeArray" begin
|
14 | 14 | timeArray = loadDataset(NROU)
|
|
28 | 28 | granularity = Dates.Day(1)
|
29 | 29 | weekDaysOnly = false
|
30 | 30 | datetimes_length = 0
|
31 |
| - result = buildDatetimes(start_datetime, granularity, weekDaysOnly, datetimes_length) |
| 31 | + result = |
| 32 | + buildDatetimes(start_datetime, granularity, weekDaysOnly, datetimes_length) |
32 | 33 | @test result == DateTime[]
|
33 | 34 | end
|
34 | 35 |
|
|
38 | 39 | granularity = Dates.Year(1)
|
39 | 40 | weekDaysOnly = false
|
40 | 41 | datetimes_length = 10
|
41 |
| - result = buildDatetimes(start_datetime, granularity, weekDaysOnly, datetimes_length) |
42 |
| - expected_result = [DateTime("2021-01-01T00:00:00"), DateTime("2022-01-01T00:00:00"), |
43 |
| - DateTime("2023-01-01T00:00:00"), DateTime("2024-01-01T00:00:00"), DateTime("2025-01-01T00:00:00"), |
44 |
| - DateTime("2026-01-01T00:00:00"), DateTime("2027-01-01T00:00:00"), DateTime("2028-01-01T00:00:00"), |
45 |
| - DateTime("2029-01-01T00:00:00"),DateTime("2030-01-01T00:00:00")] |
| 42 | + result = |
| 43 | + buildDatetimes(start_datetime, granularity, weekDaysOnly, datetimes_length) |
| 44 | + expected_result = [ |
| 45 | + DateTime("2021-01-01T00:00:00"), |
| 46 | + DateTime("2022-01-01T00:00:00"), |
| 47 | + DateTime("2023-01-01T00:00:00"), |
| 48 | + DateTime("2024-01-01T00:00:00"), |
| 49 | + DateTime("2025-01-01T00:00:00"), |
| 50 | + DateTime("2026-01-01T00:00:00"), |
| 51 | + DateTime("2027-01-01T00:00:00"), |
| 52 | + DateTime("2028-01-01T00:00:00"), |
| 53 | + DateTime("2029-01-01T00:00:00"), |
| 54 | + DateTime("2030-01-01T00:00:00"), |
| 55 | + ] |
46 | 56 | @test result == expected_result
|
47 | 57 | end
|
48 |
| - |
| 58 | + |
49 | 59 | # Test case for building timestamps daily with weekdays only
|
50 | 60 | @testset "Test daily weekdays only" begin
|
51 | 61 | start_datetime = DateTime("2024-03-27T00:00:00")
|
52 | 62 | granularity = Dates.Day(1)
|
53 | 63 | weekDaysOnly = true
|
54 | 64 | datetimes_length = 10
|
55 |
| - result = buildDatetimes(start_datetime, granularity, weekDaysOnly, datetimes_length) |
56 |
| - expected_result = [DateTime("2024-03-28T00:00:00"), DateTime("2024-03-29T00:00:00"), |
57 |
| - DateTime("2024-04-01T00:00:00"), DateTime("2024-04-02T00:00:00"), DateTime("2024-04-03T00:00:00"), |
58 |
| - DateTime("2024-04-04T00:00:00"), DateTime("2024-04-05T00:00:00"), DateTime("2024-04-08T00:00:00"), |
59 |
| - DateTime("2024-04-09T00:00:00"), DateTime("2024-04-10T00:00:00")] |
| 65 | + result = |
| 66 | + buildDatetimes(start_datetime, granularity, weekDaysOnly, datetimes_length) |
| 67 | + expected_result = [ |
| 68 | + DateTime("2024-03-28T00:00:00"), |
| 69 | + DateTime("2024-03-29T00:00:00"), |
| 70 | + DateTime("2024-04-01T00:00:00"), |
| 71 | + DateTime("2024-04-02T00:00:00"), |
| 72 | + DateTime("2024-04-03T00:00:00"), |
| 73 | + DateTime("2024-04-04T00:00:00"), |
| 74 | + DateTime("2024-04-05T00:00:00"), |
| 75 | + DateTime("2024-04-08T00:00:00"), |
| 76 | + DateTime("2024-04-09T00:00:00"), |
| 77 | + DateTime("2024-04-10T00:00:00"), |
| 78 | + ] |
60 | 79 | @test result == expected_result
|
61 | 80 | end
|
62 | 81 | end
|
63 | 82 |
|
64 | 83 | # Define the timestamps for testing
|
65 |
| - timestampsAnnually = [DateTime("2020-01-01T00:00:00") + Dates.Year(i) for i in 0:9] |
66 |
| - timestampsMonthly = [DateTime("2024-01-01T00:00:00") + Dates.Month(i) for i in 0:9] |
67 |
| - timestampsQuarterly = [DateTime("2024-01-01T00:00:00") + Dates.Month(3*i) for i in 0:9] |
68 |
| - timestamps15Days = [DateTime("2024-03-24T00:00:00") + Dates.Day(15*i) for i in 0:9] |
69 |
| - timestampsWeekly = [DateTime("2024-01-01T00:00:00") + Dates.Week(i) for i in 0:9] |
70 |
| - timestampsDaily = [DateTime("2024-03-24T00:00:00") + Dates.Day(i) for i in 0:9] |
71 |
| - timestampsHourly = [DateTime("2024-03-24T00:00:00") + Dates.Hour(i) for i in 0:9] |
72 |
| - timestampsLessHourly = [DateTime("2024-03-24T00:00:00") + Dates.Minute(15*i) for i in 0:9] |
| 84 | + timestampsAnnually = [DateTime("2020-01-01T00:00:00") + Dates.Year(i) for i = 0:9] |
| 85 | + timestampsMonthly = [DateTime("2024-01-01T00:00:00") + Dates.Month(i) for i = 0:9] |
| 86 | + timestampsQuarterly = [DateTime("2024-01-01T00:00:00") + Dates.Month(3 * i) for i = 0:9] |
| 87 | + timestamps15Days = [DateTime("2024-03-24T00:00:00") + Dates.Day(15 * i) for i = 0:9] |
| 88 | + timestampsWeekly = [DateTime("2024-01-01T00:00:00") + Dates.Week(i) for i = 0:9] |
| 89 | + timestampsDaily = [DateTime("2024-03-24T00:00:00") + Dates.Day(i) for i = 0:9] |
| 90 | + timestampsHourly = [DateTime("2024-03-24T00:00:00") + Dates.Hour(i) for i = 0:9] |
| 91 | + timestampsLessHourly = |
| 92 | + [DateTime("2024-03-24T00:00:00") + Dates.Minute(15 * i) for i = 0:9] |
73 | 93 | timestampsInconsistent = [DateTime("2024-03-24T00:00:00")]
|
74 |
| - for i in 1:8 |
| 94 | + for i = 1:8 |
75 | 95 | times = timestampsInconsistent[i] + Dates.Hour(rand(1:3))
|
76 | 96 | push!(timestampsInconsistent, times)
|
77 | 97 | end
|
78 | 98 |
|
79 |
| - timestampsWeekdays =[DateTime("2024-03-25T00:00:00") + Dates.Day(i) for i in 0:4] |
80 |
| - timestampsWeekdays = vcat(timestampsWeekdays, [DateTime("2024-04-01T00:00:00") + Dates.Day(i) for i in 0:4]) |
| 99 | + timestampsWeekdays = [DateTime("2024-03-25T00:00:00") + Dates.Day(i) for i = 0:4] |
| 100 | + timestampsWeekdays = vcat( |
| 101 | + timestampsWeekdays, |
| 102 | + [DateTime("2024-04-01T00:00:00") + Dates.Day(i) for i = 0:4], |
| 103 | + ) |
81 | 104 |
|
82 |
| - timestampsNotWeekdays = [DateTime("2024-03-28T00:00:00") + Dates.Day(i) for i in 0:10] |
| 105 | + timestampsNotWeekdays = [DateTime("2024-03-28T00:00:00") + Dates.Day(i) for i = 0:10] |
83 | 106 |
|
84 | 107 |
|
85 | 108 | # Write test cases
|
|
88 | 111 | result = identifyGranularity(timestampsAnnually)
|
89 | 112 | @test result == (granularity = :Year, frequency = 1, weekdays = false)
|
90 | 113 | end
|
91 |
| - |
| 114 | + |
92 | 115 | @testset "Test monthly" begin
|
93 | 116 | result = identifyGranularity(timestampsMonthly)
|
94 | 117 | @test result == (granularity = :Month, frequency = 1, weekdays = false)
|
95 | 118 | end
|
96 |
| - |
| 119 | + |
97 | 120 | @testset "Test quarterly" begin
|
98 | 121 | result = identifyGranularity(timestampsQuarterly)
|
99 | 122 | @test result == (granularity = :Month, frequency = 3, weekdays = false)
|
100 | 123 | end
|
101 |
| - |
| 124 | + |
102 | 125 | @testset "Test 15 days" begin
|
103 | 126 | result = identifyGranularity(timestamps15Days)
|
104 | 127 | @test result == (granularity = :Day, frequency = 15, weekdays = false)
|
105 | 128 | end
|
106 |
| - |
| 129 | + |
107 | 130 | @testset "Test weekly" begin
|
108 | 131 | result = identifyGranularity(timestampsWeekly)
|
109 | 132 | @test result == (granularity = :Week, frequency = 1, weekdays = false)
|
110 | 133 | end
|
111 |
| - |
| 134 | + |
112 | 135 | @testset "Test daily" begin
|
113 | 136 | result = identifyGranularity(timestampsDaily)
|
114 | 137 | @test result == (granularity = :Day, frequency = 1, weekdays = false)
|
115 | 138 | end
|
116 |
| - |
| 139 | + |
117 | 140 | @testset "Test hourly" begin
|
118 | 141 | result = identifyGranularity(timestampsHourly)
|
119 | 142 | @test result == (granularity = :Hour, frequency = 1, weekdays = false)
|
120 | 143 | end
|
121 |
| - |
| 144 | + |
122 | 145 | @testset "Test less than hourly" begin
|
123 | 146 | result = identifyGranularity(timestampsLessHourly)
|
124 | 147 | @test result == (granularity = :Minute, frequency = 15, weekdays = false)
|
125 | 148 | end
|
126 |
| - |
| 149 | + |
127 | 150 | @testset "Test inconsistent" begin
|
128 | 151 | @test_throws InconsistentDatePattern identifyGranularity(timestampsInconsistent)
|
129 | 152 | end
|
130 |
| - |
| 153 | + |
131 | 154 | @testset "Test weekdays" begin
|
132 | 155 | result = identifyGranularity(timestampsWeekdays)
|
133 | 156 | @test result == (granularity = :Day, frequency = 1, weekdays = true)
|
|
139 | 162 |
|
140 | 163 | @testset "merge" begin
|
141 | 164 |
|
142 |
| - @testset "Test Merge empty" begin |
| 165 | + @testset "Test Merge empty" begin |
143 | 166 | @test Sarimax.merge(Vector{TimeArray}()) == TimeArray(DateTime[], [])
|
144 | 167 | end
|
145 | 168 |
|
|
164 | 187 | timeArray1 = loadDataset(NROU)
|
165 | 188 | timeArray2 = loadDataset(GDPC1)
|
166 | 189 | timeArray2 = from(timeArray2, timestamp(timeArray2)[2])
|
167 |
| - timeArray3 = TimeArray(timestamp(timeArray2)[1:end-1], values(timeArray2)[1:end-1], ["teste"]) |
| 190 | + timeArray3 = TimeArray( |
| 191 | + timestamp(timeArray2)[1:end-1], |
| 192 | + values(timeArray2)[1:end-1], |
| 193 | + ["teste"], |
| 194 | + ) |
168 | 195 |
|
169 | 196 | timeArrays::Vector{TimeArray} = [timeArray1, timeArray2, timeArray3]
|
170 | 197 | finalTimeArray = Sarimax.merge(timeArrays)
|
|
0 commit comments