Skip to content

Commit fd9d270

Browse files
author
LuizFCDuarte
committed
🎨 Format test code according to spacing guidelines
1 parent afdfe08 commit fd9d270

File tree

9 files changed

+294
-188
lines changed

9 files changed

+294
-188
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ julia = "1.0 - 1.11"
5454

5555
[extras]
5656
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
57-
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
58-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
5957
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
6058
RCall = "6f49c342-dc21-5d91-9882-a32aef131414"
59+
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
60+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
6161

6262
[targets]
6363
test = ["Test", "JSON", "Revise"]

test/datasets.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@
1010
@testset "loadDataset(Datasets)" begin
1111
@testset "AIR_PASSENGERS" begin
1212
airPassengersData = loadDataset(AIR_PASSENGERS)
13-
@test size(airPassengersData,1) == 204
13+
@test size(airPassengersData, 1) == 204
1414
@test values(airPassengersData)[1] == 3.526591
1515
@test values(airPassengersData)[end] == 19.43174
1616
end
1717

1818
@testset "GDPC1" begin
1919
GDPC1Data = loadDataset(GDPC1)
20-
@test size(GDPC1Data,1) == 344
20+
@test size(GDPC1Data, 1) == 344
2121
@test values(GDPC1Data)[1] == 2260.807
2222
@test values(GDPC1Data)[end] == 27944.500
2323
end
2424

2525
@testset "NROU" begin
2626
NROUData = loadDataset(NROU)
27-
@test size(NROUData,1) == 344
27+
@test size(NROUData, 1) == 344
2828
@test values(NROUData)[1] == 5.2550525665283200
2929
@test values(NROUData)[end] == 4.2031234672198900
3030
end
@@ -34,23 +34,23 @@
3434
@testset "Air Passengers" begin
3535
airPassengersDf = CSV.File("../datasets/airpassengers.csv") |> DataFrame
3636
airPassengersData = loadDataset(airPassengersDf)
37-
@test size(airPassengersData,1) == 204
37+
@test size(airPassengersData, 1) == 204
3838
@test values(airPassengersData)[1] == 3.526591
3939
@test values(airPassengersData)[end] == 19.43174
4040
end
4141

4242
@testset "GDPC1" begin
4343
GDPC1Df = CSV.File("../datasets/GDPC1.csv") |> DataFrame
4444
GDPC1Data = loadDataset(GDPC1Df)
45-
@test size(GDPC1Data,1) == 344
45+
@test size(GDPC1Data, 1) == 344
4646
@test values(GDPC1Data)[1] == 2260.807
4747
@test values(GDPC1Data)[end] == 27944.500
4848
end
4949

5050
@testset "NROU" begin
5151
NROUDf = CSV.File("../datasets/NROU.csv") |> DataFrame
5252
NROUData = loadDataset(NROUDf)
53-
@test size(NROUData,1) == 344
53+
@test size(NROUData, 1) == 344
5454
@test values(NROUData)[1] == 5.2550525665283200
5555
@test values(NROUData)[end] == 4.2031234672198900
5656
end
@@ -61,24 +61,24 @@
6161
@testset "splitTrainTest(Datasets)" begin
6262
@testset "AIR_PASSENGERS" begin
6363
airPassengers = loadDataset(AIR_PASSENGERS)
64-
train, test = splitTrainTest(airPassengers; trainPercentage=0.8)
65-
@test size(train,1) == 163
66-
@test size(test,1) == 41
64+
train, test = splitTrainTest(airPassengers; trainPercentage = 0.8)
65+
@test size(train, 1) == 163
66+
@test size(test, 1) == 41
6767
end
6868

6969
@testset "GDPC1" begin
7070
GDPC1Data = loadDataset(GDPC1)
71-
train, test = splitTrainTest(GDPC1Data; trainPercentage=0.8)
72-
@test size(train,1) == 275
73-
@test size(test,1) == 69
71+
train, test = splitTrainTest(GDPC1Data; trainPercentage = 0.8)
72+
@test size(train, 1) == 275
73+
@test size(test, 1) == 69
7474
end
7575

7676
@testset "NROU" begin
7777
NROUData = loadDataset(NROU)
78-
train, test = splitTrainTest(NROUData; trainPercentage=0.8)
79-
@test size(train,1) == 275
80-
@test size(test,1) == 69
78+
train, test = splitTrainTest(NROUData; trainPercentage = 0.8)
79+
@test size(train, 1) == 275
80+
@test size(test, 1) == 69
8181
end
8282
end
8383
end
84-
end
84+
end

test/datetime_utils.jl

Lines changed: 63 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
@test timestamp(timeArray) == timestamp(copyTimeArray)
99
@test values(timeArray) == values(copyTimeArray)
1010
end
11-
11+
1212
# Test case for deepcopying TimeArray
1313
@testset "Test DeepCopy TimeArray" begin
1414
timeArray = loadDataset(NROU)
@@ -28,7 +28,8 @@
2828
granularity = Dates.Day(1)
2929
weekDaysOnly = false
3030
datetimes_length = 0
31-
result = buildDatetimes(start_datetime, granularity, weekDaysOnly, datetimes_length)
31+
result =
32+
buildDatetimes(start_datetime, granularity, weekDaysOnly, datetimes_length)
3233
@test result == DateTime[]
3334
end
3435

@@ -38,48 +39,70 @@
3839
granularity = Dates.Year(1)
3940
weekDaysOnly = false
4041
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+
]
4656
@test result == expected_result
4757
end
48-
58+
4959
# Test case for building timestamps daily with weekdays only
5060
@testset "Test daily weekdays only" begin
5161
start_datetime = DateTime("2024-03-27T00:00:00")
5262
granularity = Dates.Day(1)
5363
weekDaysOnly = true
5464
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+
]
6079
@test result == expected_result
6180
end
6281
end
6382

6483
# 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]
7393
timestampsInconsistent = [DateTime("2024-03-24T00:00:00")]
74-
for i in 1:8
94+
for i = 1:8
7595
times = timestampsInconsistent[i] + Dates.Hour(rand(1:3))
7696
push!(timestampsInconsistent, times)
7797
end
7898

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+
)
81104

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]
83106

84107

85108
# Write test cases
@@ -88,46 +111,46 @@
88111
result = identifyGranularity(timestampsAnnually)
89112
@test result == (granularity = :Year, frequency = 1, weekdays = false)
90113
end
91-
114+
92115
@testset "Test monthly" begin
93116
result = identifyGranularity(timestampsMonthly)
94117
@test result == (granularity = :Month, frequency = 1, weekdays = false)
95118
end
96-
119+
97120
@testset "Test quarterly" begin
98121
result = identifyGranularity(timestampsQuarterly)
99122
@test result == (granularity = :Month, frequency = 3, weekdays = false)
100123
end
101-
124+
102125
@testset "Test 15 days" begin
103126
result = identifyGranularity(timestamps15Days)
104127
@test result == (granularity = :Day, frequency = 15, weekdays = false)
105128
end
106-
129+
107130
@testset "Test weekly" begin
108131
result = identifyGranularity(timestampsWeekly)
109132
@test result == (granularity = :Week, frequency = 1, weekdays = false)
110133
end
111-
134+
112135
@testset "Test daily" begin
113136
result = identifyGranularity(timestampsDaily)
114137
@test result == (granularity = :Day, frequency = 1, weekdays = false)
115138
end
116-
139+
117140
@testset "Test hourly" begin
118141
result = identifyGranularity(timestampsHourly)
119142
@test result == (granularity = :Hour, frequency = 1, weekdays = false)
120143
end
121-
144+
122145
@testset "Test less than hourly" begin
123146
result = identifyGranularity(timestampsLessHourly)
124147
@test result == (granularity = :Minute, frequency = 15, weekdays = false)
125148
end
126-
149+
127150
@testset "Test inconsistent" begin
128151
@test_throws InconsistentDatePattern identifyGranularity(timestampsInconsistent)
129152
end
130-
153+
131154
@testset "Test weekdays" begin
132155
result = identifyGranularity(timestampsWeekdays)
133156
@test result == (granularity = :Day, frequency = 1, weekdays = true)
@@ -139,7 +162,7 @@
139162

140163
@testset "merge" begin
141164

142-
@testset "Test Merge empty" begin
165+
@testset "Test Merge empty" begin
143166
@test Sarimax.merge(Vector{TimeArray}()) == TimeArray(DateTime[], [])
144167
end
145168

@@ -164,7 +187,11 @@
164187
timeArray1 = loadDataset(NROU)
165188
timeArray2 = loadDataset(GDPC1)
166189
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+
)
168195

169196
timeArrays::Vector{TimeArray} = [timeArray1, timeArray2, timeArray3]
170197
finalTimeArray = Sarimax.merge(timeArrays)

test/exceptions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ using Test
5858
end
5959
end
6060

61-
end
61+
end

test/fit.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
@testset "Fit" begin
2-
mutable struct ARIMA_TEST <: Sarimax.SarimaxModel
3-
end
2+
mutable struct ARIMA_TEST <: Sarimax.SarimaxModel end
43
@testset "hasFitMethods" begin
54
@test hasFitMethods(SARIMAModel)
65
@test !hasFitMethods(ARIMA_TEST)
@@ -39,26 +38,26 @@
3938
end
4039

4140
@testset "informationCriteriaModel" begin
42-
@test_throws MissingMethodImplementation begin
41+
@test_throws MissingMethodImplementation begin
4342
aic(ARIMA_TEST())
4443
end
4544

46-
@test_throws MissingMethodImplementation begin
45+
@test_throws MissingMethodImplementation begin
4746
aicc(ARIMA_TEST())
4847
end
4948

50-
@test_throws MissingMethodImplementation begin
49+
@test_throws MissingMethodImplementation begin
5150
bic(ARIMA_TEST())
5251
end
5352

5453
airPassengers = loadDataset(AIR_PASSENGERS)
5554
airPassengersLog = log.(airPassengers)
56-
testModel = SARIMA(airPassengersLog, 3, 0, 1; seasonality=12, P=1, D=1, Q=1)
55+
testModel = SARIMA(airPassengersLog, 3, 0, 1; seasonality = 12, P = 1, D = 1, Q = 1)
5756
fit!(testModel)
5857
@test aic(testModel) -1063.1519532534248
5958
@test aicc(testModel) -1062.3650680075232
6059
@test bic(testModel) -1037.0919902772025
6160
end
6261

6362

64-
end
63+
end

0 commit comments

Comments
 (0)