6
6
#include "utils/tUtils.h"
7
7
#include "sipnet/events.c"
8
8
9
- int checkEvent (EventNode * event , int loc , int year , int day , enum EventType type ) {
10
- int success =
11
- event -> loc == loc &&
12
- event -> year == year &&
13
- event -> day == day &&
14
- event -> type == type ;
9
+ int checkEvent (EventNode * event , int loc , int year , int day ,
10
+ enum EventType type ) {
11
+ if (!event ) {
12
+ return 1 ;
13
+ }
14
+ int success = event -> loc == loc && event -> year == year && event -> day == day &&
15
+ event -> type == type ;
15
16
if (!success ) {
16
17
printf ("Error checking event\n" );
17
18
printEvent (event );
@@ -20,111 +21,95 @@ int checkEvent(EventNode* event, int loc, int year, int day, enum EventType type
20
21
return 0 ;
21
22
}
22
23
23
- int checkHarvestParams (
24
- HarvestParams * params , double fracRemAbove ,
25
- double fracRemBelow ,
26
- double fracTransAbove ,
27
- double fracTransBelow
28
- ) {
29
- return !(
30
- compareDoubles (params -> fractionRemovedAbove , fracRemAbove ) &&
31
- compareDoubles (params -> fractionRemovedBelow , fracRemBelow ) &&
32
- compareDoubles (params -> fractionTransferredAbove , fracTransAbove ) &&
33
- compareDoubles (params -> fractionTransferredBelow , fracTransBelow )
34
- );
24
+ int checkHarvestParams (HarvestParams * params , double fracRemAbove ,
25
+ double fracRemBelow , double fracTransAbove ,
26
+ double fracTransBelow ) {
27
+ return !(compareDoubles (params -> fractionRemovedAbove , fracRemAbove ) &&
28
+ compareDoubles (params -> fractionRemovedBelow , fracRemBelow ) &&
29
+ compareDoubles (params -> fractionTransferredAbove , fracTransAbove ) &&
30
+ compareDoubles (params -> fractionTransferredBelow , fracTransBelow ));
35
31
}
36
32
37
- int checkIrrigationParams (
38
- IrrigationParams * params ,
39
- double amountAdded ,
40
- int method
41
- ) {
42
- return !(
43
- compareDoubles (params -> amountAdded , amountAdded ) &&
44
- params -> method == method
45
- );
33
+ int checkIrrigationParams (IrrigationParams * params , double amountAdded ,
34
+ int method ) {
35
+ return !(compareDoubles (params -> amountAdded , amountAdded ) &&
36
+ params -> method == method );
46
37
}
47
38
48
- int checkFertilizationParams (
49
- FertilizationParams * params ,
50
- double orgN ,
51
- double orgC ,
52
- double minN
53
- ) {
54
- return !(
55
- compareDoubles (params -> orgN , orgN ) &&
56
- compareDoubles (params -> orgC , orgC ) &&
57
- compareDoubles (params -> minN , minN )
58
- );
39
+ int checkFertilizationParams (FertilizationParams * params , double orgN ,
40
+ double orgC , double minN ) {
41
+ return !(compareDoubles (params -> orgN , orgN ) &&
42
+ compareDoubles (params -> orgC , orgC ) &&
43
+ compareDoubles (params -> minN , minN ));
59
44
}
60
45
61
- int checkPlantingParams (
62
- PlantingParams * params , int emergenceLag , double addedC , double addedN
63
- ) {
64
- return !(
65
- params -> emergenceLag == emergenceLag &&
66
- compareDoubles (params -> addedC , addedC ) &&
67
- compareDoubles (params -> addedN , addedN )
68
- );
46
+ int checkPlantingParams (PlantingParams * params , int emergenceLag , double addedC ,
47
+ double addedN ) {
48
+ return !(params -> emergenceLag == emergenceLag &&
49
+ compareDoubles (params -> addedC , addedC ) &&
50
+ compareDoubles (params -> addedN , addedN ));
69
51
}
70
52
71
- int checkTillageParams (
72
- TillageParams * params ,
73
- double fracLitterTransferred ,
74
- double somDecompModifier ,
75
- double litterDecompModifier
76
- ) {
77
- return !(
78
- compareDoubles (params -> fractionLitterTransferred , fracLitterTransferred ) &&
79
- compareDoubles (params -> somDecompModifier , somDecompModifier ) &&
80
- compareDoubles (params -> litterDecompModifier , litterDecompModifier )
81
- );
53
+ int checkTillageParams (TillageParams * params , double fracLitterTransferred ,
54
+ double somDecompModifier , double litterDecompModifier ) {
55
+ return !(compareDoubles (params -> fractionLitterTransferred ,
56
+ fracLitterTransferred ) &&
57
+ compareDoubles (params -> somDecompModifier , somDecompModifier ) &&
58
+ compareDoubles (params -> litterDecompModifier , litterDecompModifier ));
82
59
}
83
60
84
- int init () {
85
- // char * filename = "infra_events_simple.in";
86
- // if (access(filename, F_OK) == -1) {
87
- // return 1;
88
- // }
89
- //
90
- // return copyFile(filename, "events.in");
91
- return 0 ;
61
+ int init (void ) { return 0 ; }
62
+
63
+ int runTestEmpty (void ) {
64
+ int numLocs = 2 ;
65
+ int status = 0 ;
66
+ // Should return empty for no file
67
+ EventNode * * output = readEventData ("infra_events_no_file.in" , numLocs );
68
+ status |= !((output [0 ] == NULL ) && (output [1 ] == NULL ));
69
+ output = readEventData ("infra_events_empty_file.in" , numLocs );
70
+ status |= !((output [0 ] == NULL ) && (output [1 ] == NULL ));
71
+
72
+ return status ;
92
73
}
93
74
94
- int runTestSimple () {
75
+ int runTestSimple (void ) {
95
76
// Simple test with one loc, one event per type
96
77
int numLocs = 1 ;
97
- EventNode * * output = readEventData ("infra_events_simple.in" , numLocs );
78
+ EventNode * * output = readEventData ("infra_events_simple.in" , numLocs );
98
79
99
- if (!output ) {
80
+ if (!output || ! output [ 0 ] ) {
100
81
return 1 ;
101
82
}
102
83
103
84
// check output is correct
104
85
int status = 0 ;
105
86
EventNode * event = output [0 ];
106
87
status |= checkEvent (event , 0 , 2022 , 40 , IRRIGATION );
107
- status |= checkIrrigationParams ((IrrigationParams * )event -> eventParams , 5 , 0 );
88
+ status |= checkIrrigationParams ((IrrigationParams * )event -> eventParams , 5 , 0 );
108
89
event = event -> nextEvent ;
109
90
status |= checkEvent (event , 0 , 2022 , 40 , FERTILIZATION );
110
- status |= checkFertilizationParams ((FertilizationParams * )event -> eventParams , 15 , 5 ,10 );
91
+ status |= checkFertilizationParams ((FertilizationParams * )event -> eventParams ,
92
+ 15 , 5 , 10 );
111
93
event = event -> nextEvent ;
112
94
status |= checkEvent (event , 0 , 2022 , 45 , TILLAGE );
113
- status |= checkTillageParams ((TillageParams * )event -> eventParams , 0.1 , 0.2 , 0.3 );
95
+ status |=
96
+ checkTillageParams ((TillageParams * )event -> eventParams , 0.1 , 0.2 , 0.3 );
114
97
event = event -> nextEvent ;
115
98
status |= checkEvent (event , 0 , 2022 , 46 , PLANTING );
116
- status |= checkPlantingParams ((PlantingParams * )event -> eventParams , 10 , 10 , 1 );
99
+ status |=
100
+ checkPlantingParams ((PlantingParams * )event -> eventParams , 10 , 10 , 1 );
117
101
event = event -> nextEvent ;
118
102
status |= checkEvent (event , 0 , 2022 , 250 , HARVEST );
119
- status |= checkHarvestParams ((HarvestParams * )event -> eventParams , 0.4 , 0.1 , 0.2 , 0.3 );
103
+ status |= checkHarvestParams ((HarvestParams * )event -> eventParams , 0.4 , 0.1 ,
104
+ 0.2 , 0.3 );
120
105
121
106
return status ;
122
107
}
123
108
124
- int runTestMulti () {
109
+ int runTestMulti (void ) {
125
110
// More complex test; multiple locations
126
111
int numLocs = 1 ;
127
- EventNode * * output = readEventData ("infra_events_multi.in" , numLocs );
112
+ EventNode * * output = readEventData ("infra_events_multi.in" , numLocs );
128
113
129
114
if (!output ) {
130
115
return 1 ;
@@ -135,61 +120,78 @@ int runTestMulti() {
135
120
int loc = 0 ;
136
121
EventNode * event = output [loc ];
137
122
status |= checkEvent (event , loc , 2024 , 60 , TILLAGE );
138
- status |= checkTillageParams ((TillageParams * )event -> eventParams , 0.1 , 0.2 , 0.3 );
123
+ status |=
124
+ checkTillageParams ((TillageParams * )event -> eventParams , 0.1 , 0.2 , 0.3 );
139
125
event = event -> nextEvent ;
140
126
status |= checkEvent (event , loc , 2024 , 65 , PLANTING );
141
- status |= checkPlantingParams ((PlantingParams * )event -> eventParams , 15 , 20 , 5 );
127
+ status |=
128
+ checkPlantingParams ((PlantingParams * )event -> eventParams , 15 , 20 , 5 );
142
129
event = event -> nextEvent ;
143
130
status |= checkEvent (event , loc , 2024 , 70 , IRRIGATION );
144
- status |= checkIrrigationParams ((IrrigationParams * )event -> eventParams , 5 , 1 );
131
+ status |= checkIrrigationParams ((IrrigationParams * )event -> eventParams , 5 , 1 );
145
132
event = event -> nextEvent ;
146
133
status |= checkEvent (event , loc , 2024 , 75 , FERTILIZATION );
147
- status |= checkFertilizationParams ((FertilizationParams * )event -> eventParams , 15 , 10 ,5 );
134
+ status |= checkFertilizationParams ((FertilizationParams * )event -> eventParams ,
135
+ 15 , 10 , 5 );
148
136
event = event -> nextEvent ;
149
137
status |= checkEvent (event , loc , 2024 , 250 , HARVEST );
150
- status |= checkHarvestParams ((HarvestParams * )event -> eventParams , 0.1 , 0.2 , 0.3 , 0.4 );
138
+ status |= checkHarvestParams ((HarvestParams * )event -> eventParams , 0.1 , 0.2 ,
139
+ 0.3 , 0.4 );
151
140
152
141
loc ++ ;
153
142
event = output [loc ];
154
143
status |= checkEvent (event , loc , 2024 , 59 , TILLAGE );
155
- status |= checkTillageParams ((TillageParams * )event -> eventParams , 0.2 , 0.3 , 0.1 );
144
+ status |=
145
+ checkTillageParams ((TillageParams * )event -> eventParams , 0.2 , 0.3 , 0.1 );
156
146
event = event -> nextEvent ;
157
147
status |= checkEvent (event , loc , 2024 , 64 , PLANTING );
158
- status |= checkPlantingParams ((PlantingParams * )event -> eventParams , 15 , 20 , 5 );
148
+ status |=
149
+ checkPlantingParams ((PlantingParams * )event -> eventParams , 15 , 20 , 5 );
159
150
event = event -> nextEvent ;
160
151
status |= checkEvent (event , loc , 2024 , 69 , IRRIGATION );
161
- status |= checkIrrigationParams ((IrrigationParams * )event -> eventParams , 5 , 0 );
152
+ status |= checkIrrigationParams ((IrrigationParams * )event -> eventParams , 5 , 0 );
162
153
event = event -> nextEvent ;
163
154
status |= checkEvent (event , loc , 2024 , 74 , FERTILIZATION );
164
- status |= checkFertilizationParams ((FertilizationParams * )event -> eventParams , 5 , 15 ,10 );
155
+ status |= checkFertilizationParams ((FertilizationParams * )event -> eventParams ,
156
+ 5 , 15 , 10 );
165
157
event = event -> nextEvent ;
166
158
status |= checkEvent (event , loc , 2024 , 249 , HARVEST );
167
- status |= checkHarvestParams ((HarvestParams * )event -> eventParams , 0.2 , 0.3 , 0.4 , 0.1 );
159
+ status |= checkHarvestParams ((HarvestParams * )event -> eventParams , 0.2 , 0.3 ,
160
+ 0.4 , 0.1 );
168
161
169
162
loc ++ ;
170
163
event = output [loc ];
171
164
status |= checkEvent (event , loc , 2024 , 58 , TILLAGE );
172
- status |= checkTillageParams ((TillageParams * )event -> eventParams , 0.3 , 0.1 , 0.2 );
165
+ status |=
166
+ checkTillageParams ((TillageParams * )event -> eventParams , 0.3 , 0.1 , 0.2 );
173
167
event = event -> nextEvent ;
174
168
status |= checkEvent (event , loc , 2024 , 63 , PLANTING );
175
- status |= checkPlantingParams ((PlantingParams * )event -> eventParams , 15 , 20 , 5 );
169
+ status |=
170
+ checkPlantingParams ((PlantingParams * )event -> eventParams , 15 , 20 , 5 );
176
171
event = event -> nextEvent ;
177
172
status |= checkEvent (event , loc , 2024 , 68 , IRRIGATION );
178
- status |= checkIrrigationParams ((IrrigationParams * )event -> eventParams , 6 , 1 );
173
+ status |= checkIrrigationParams ((IrrigationParams * )event -> eventParams , 6 , 1 );
179
174
event = event -> nextEvent ;
180
175
status |= checkEvent (event , loc , 2024 , 73 , FERTILIZATION );
181
- status |= checkFertilizationParams ((FertilizationParams * )event -> eventParams , 5 , 10 ,15 );
176
+ status |= checkFertilizationParams ((FertilizationParams * )event -> eventParams ,
177
+ 5 , 10 , 15 );
182
178
event = event -> nextEvent ;
183
179
status |= checkEvent (event , loc , 2024 , 248 , HARVEST );
184
- status |= checkHarvestParams ((HarvestParams * )event -> eventParams , 0.3 , 0.4 , 0.1 , 0.2 );
180
+ status |= checkHarvestParams ((HarvestParams * )event -> eventParams , 0.3 , 0.4 ,
181
+ 0.1 , 0.2 );
185
182
186
183
return status ;
187
184
}
188
185
189
- int run () {
186
+ int run (void ) {
190
187
191
188
int status ;
192
189
190
+ status = runTestEmpty ();
191
+ if (status ) {
192
+ return 1 ;
193
+ }
194
+
193
195
status = runTestSimple ();
194
196
if (status ) {
195
197
return 1 ;
@@ -203,20 +205,20 @@ int run() {
203
205
return 0 ;
204
206
}
205
207
206
- void cleanup () {
208
+ void cleanup (void ) {
207
209
// Perform any cleanup as needed
208
210
// None needed here, we can leave the copied file
209
211
}
210
212
211
- int main () {
213
+ int main (void ) {
212
214
int status ;
213
- status = init ();
214
- if (status ) {
215
- printf ("Test initialization failed with status %d\n" , status );
216
- exit (status );
217
- } else {
218
- printf ("Test initialized\n" );
219
- }
215
+ // status = init();
216
+ // if (status) {
217
+ // printf("Test initialization failed with status %d\n", status);
218
+ // exit(status);
219
+ // } else {
220
+ printf ("Test initialized\n" );
221
+ // }
220
222
221
223
printf ("Starting run()\n" );
222
224
status = run ();
@@ -228,4 +230,4 @@ int main() {
228
230
printf ("testEventInfra PASSED\n" );
229
231
230
232
cleanup ();
231
- }
233
+ }
0 commit comments