-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestingMain.cpp
More file actions
351 lines (290 loc) · 14.5 KB
/
Copy pathTestingMain.cpp
File metadata and controls
351 lines (290 loc) · 14.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#include <iostream>
#include "CompositeFarm.h"
#include "CropField.h"
#include "FarmUnit.h"
#include "FloodedSoil.h"
#include "Fertilizer.h"
#include "ExtraBarn.h"
#include "DeliveryTruck.h"
#include "FertilizerTruck.h"
#include "TruckFactory.h"
#include "FarmTraversal.h"
#include "DepthFirstTraversal.h"
#include "BreadthFirstTraversal.h"
void testComponent1();
void testComponent2();
void testComponent3();
void testComponent4();
void testComponent5();
int main()
{
testComponent1();
testComponent2();
testComponent3();
testComponent4();
testComponent5();
return 0;
}
void testComponent1()
{
CropField *cornField = new CropField("Corn", 100, "CF001", "Field 1", 10.0, 20);
std::cout << "+++++++++++++++++++CORNFIELD DATA+++++++++++++++++++++" << std::endl;
cornField->displayDetails();
cornField->updateSensorData("Pest Control(sPs/ml)", 880);
std::cout << "Increased the pest control sensor to : " << cornField->getSensorData("Pest Control(sPs/ml)") << std::endl;
CropField *wheatField = new CropField("Wheat", 150, "CF002", "Field 2", 15.0, 30);
std::cout << "+++++++++++++++++++WheatField DATA+++++++++++++++++++++" << std::endl;
wheatField->displayDetails();
wheatField->updateSensorData("Moisture Level(%)", 70);
std::cout << "Inceased the moisture to: " << wheatField->getSensorData("Moisture Level(%)") << std::endl;
CompositeFarm *myFarm = new CompositeFarm("Farm001", "Main Farm Location", 50.0);
std::cout << "+++++++++++++++++++FARM DATA+++++++++++++++++++++" << std::endl;
myFarm->addUnit(cornField);
myFarm->addUnit(wheatField);
std::cout << "Total Capacity of the Farm: " << myFarm->getTotalCapacity() << std::endl;
std::cout << "Crop Types in the Farm: " << myFarm->getCropType() << std::endl;
std::cout << "Unit IDs in the Farms: " << myFarm->getUnitID() << std::endl;
std::cout << "Locations in the Farms: " << myFarm->getLocation() << std::endl;
std::cout << "Energy Consumption of the Farm(kWh): " << myFarm->getEnergyConsumption() << std::endl;
cornField->updateSensorData("Moisture", 25.5);
std::cout << "Corn Field Moisture: " << cornField->getSensorData("Moisture") << std::endl;
wheatField->updateSensorData("Temperature", 28.0);
std::cout << "Wheat Field Temperature: " << wheatField->getSensorData("Temperature") << std::endl;
delete myFarm;
}
void testComponent2()
{
CropField *wheatField = new CropField("Wheat", 100, "CF001", "North Field", 500.0, 60);
CropField *cornField = new CropField("Corn", 150, "CF002", "Field 2", 300.0, 45);
CompositeFarm *myFarm = new CompositeFarm("Farm001", "Main Farm Location", 50.0);
myFarm->addUnit(wheatField);
myFarm->addUnit(cornField);
std::cout << "++++++++++++++++++++++++++STATES+++++++++++++++++++++++++++++++" << std::endl;
std::cout << "Intial state of Wheat: " << wheatField->getSoilStateName() << std::endl;
std::cout << "Intial state of Corn: " << cornField->getSoilStateName() << std::endl;
DrySoil dy;
FruitfulSoil fs;
FloodedSoil fs2;
double rainfall = 18.0;
double rainfall2 = 14.0;
double rainfall3 = 30.0;
double rainfall4 = 9.0;
// dry to fruitful
std::cout << "\n=== Changing from dry to fruitful ===" << std::endl;
int yield = dy.harvestCrops(wheatField);
wheatField->setTotalCapacity(yield);
std::cout << "State: " << dy.getName() << std::endl;
std::cout << "Yield: " << yield << " units of crops harvested." << std::endl;
std::cout << "Total Capacity: " << wheatField->getTotalCapacity() << std::endl;
wheatField->rain(wheatField, rainfall);
std::cout << "After rain, soil state: " << wheatField->getSoilStateName() << std::endl;
std::cout << "\n=== Frutiful to flooed ===" << std::endl;
int yield2 = fs.harvestCrops(cornField);
cornField->setTotalCapacity(yield2);
std::cout << "State: " << fs.getName() << std::endl;
std::cout << "Yield: " << yield2 << " units of crops harvested." << std::endl;
std::cout << "Total Capacity: " << cornField->getTotalCapacity() << std::endl;
std::cout << "State name of cornfield: " << cornField->getSoilStateName() << std::endl;
cornField->rain(cornField, rainfall3);
std::cout << "After rain, soil state: " << cornField->getSoilStateName() << std::endl;
std::cout << std::endl;
wheatField->setSoilState(new FloodedSoil());
cornField->setSoilState(new DrySoil());
std::cout << "\n=== Set state manually ===" << std::endl;
std::cout << wheatField->getSoilStateName() << std::endl;
std::cout << cornField->getSoilStateName() << std::endl;
std::cout << "\n=== Changing from flooded to dry ===" << std::endl;
int yield3 = fs2.harvestCrops(wheatField);
wheatField->setTotalCapacity(yield3);
std::cout << "Yield: " << yield3 << " times units of crops harvested." << std::endl;
std::cout << "Total Capacity: " << wheatField->getTotalCapacity() << std::endl;
wheatField->rain(wheatField, rainfall4);
std::cout << "After more rain, soil state: " << wheatField->getSoilStateName() << std::endl;
int yield4 = dy.harvestCrops(wheatField);
wheatField->setTotalCapacity(yield4);
std::cout << "Yield: " << yield4 << " units of crops harvested." << std::endl;
std::cout << "Total Capacity: " << wheatField->getTotalCapacity() << std::endl;
std::cout << "\n=== Staying in dry state ===" << std::endl;
int yield5 = dy.harvestCrops(cornField);
cornField->setTotalCapacity(yield5);
std::cout << "Yield: " << yield5 << " times units of crops harvested." << std::endl;
std::cout << "Total Capacity: " << cornField->getTotalCapacity() << std::endl;
cornField->rain(cornField, rainfall2);
std::cout << "After more rain, soil state: " << cornField->getSoilStateName() << std::endl;
int yield6 = dy.harvestCrops(cornField);
cornField->setTotalCapacity(yield6);
std::cout << "Yield: " << yield6 << " units of crops harvested." << std::endl;
std::cout << "Total Capacity: " << cornField->getTotalCapacity() << std::endl;
delete myFarm;
}
void testComponent3()
{
CropField *tomatoes = new CropField("Tomatoes", 1000, "Field1", "North", 200, 50);
CropField *potatoes = new CropField("Potato", 900, "CFT8", "Section6", 150, 50);
CompositeFarm *farm1 = new CompositeFarm("OpenLand", "SpringField", 400);
std::cout << "++++++++++++++++++++FERTLIZER++++++++++++++++++++++ " << std::endl;
Fertilizer *ftl = new Fertilizer(tomatoes);
ftl->display();
Fertilizer *ftl2 = new Fertilizer(potatoes);
ftl2->display();
std::cout << "\n";
ftl->updateSensorData("Temperature", 28.0);
std::cout << "Sensor updated is Temperature to " << ftl->getSensorData("Temperature") << " for " << ftl->getCropType() << std::endl;
ftl2->updateSensorData("Temperature", 25.0);
std::cout << "Sensor updated is Temperature to " << ftl2->getSensorData("Temperature") << " for " << ftl2->getCropType() << std::endl;
std::cout << "\n=== INCREASE PRODUCTION===" << std::endl;
ftl->increaseProduction();
ftl2->increaseProduction();
int yield = ftl->harvest();
int t = ftl2->harvest();
std::cout << "Increased Yield of Tomatoes: " << yield << std::endl;
std::cout << "Increased Yield of Potatoes: " << t << std::endl;
std::cout << "++++++++++++++++++++EXTRA BARN+++++++++++++++++++++ " << std::endl;
ExtraBarn *barn = new ExtraBarn(tomatoes, 50);
ExtraBarn *barn2 = new ExtraBarn(potatoes, 70);
std::cout << "\n===Adding to Barn===" << std::endl;
barn->add();
barn2->add();
int cap = barn->getLeftoverCapacity();
int cap2 = barn->getLeftoverCapacity();
std::cout << "Total increased capacity of Tomatoes after an extra barn: " << cap << std::endl;
barn->print();
std::cout << "Total increased capacity of Potatoes after an extra barn: " << cap2 << std::endl;
barn2->print();
std::cout << "++++++++++++++++++++FARM DATA++++++++++++++++++++++ " << std::endl;
farm1->addUnit(tomatoes);
farm1->addUnit(potatoes);
farm1->displayD();
delete farm1;
delete barn;
delete barn2;
delete ftl;
delete ftl2;
}
void testComponent4()
{
std::cout << "++++++++++++++++++++++++++++++++CROPS++++++++++++++++++++++++++++++++++++++ " << std::endl;
CropField *wheatField = new CropField("Wheat", 1500, "CF01", "North Field", 50.5, 500);
CropField *potatoField = new CropField("Potato", 2500, "GYG8", "South Corner", 690, 800);
CropField *sugarcaneField = new CropField("SugarCane", 3000, "DG8J", "Central Farm", 100, 1200);
CropField *sunflowerField = new CropField("Sunflower", 2000, "FDF9", "Down East", 80, 600);
std::cout << "Details of crops: " << std::endl;
wheatField->displayDetails();
potatoField->displayDetails();
sugarcaneField->displayDetails();
sunflowerField->displayDetails();
std::cout << "++++++++++++++++++++++++++++++++FARM++++++++++++++++++++++++++++++++++++++++ " << std::endl;
CompositeFarm *farm = new CompositeFarm("SIMBAFARM", "North West", 1500);
farm->addUnit(wheatField);
farm->addUnit(potatoField);
farm->addUnit(sugarcaneField);
farm->addUnit(sunflowerField);
farm->displayD();
std::cout << "++++++++++++++++++++++++++++TRUCKS FOR FIELDS++++++++++++++++++++++++++++++++ " << std::endl;
std::cout << "=== Buying Trucks ===" << std::endl;
Truck *truck = wheatField->buyTruck("DeliveryTruck", 100, 1, 200);
DeliveryTruck *dtk = dynamic_cast<DeliveryTruck *>(truck);
Truck *truck2 = potatoField->buyTruck("FertilizerTruck", 468, 55, 200);
FertilizerTruck *ftk = dynamic_cast<FertilizerTruck *>(truck2);
Truck *truck3 = sugarcaneField->buyTruck("FertilizerTruck", 468, 20, 200);
FertilizerTruck *ftk2 = dynamic_cast<FertilizerTruck *>(truck3);
Truck *truck4 = sunflowerField->buyTruck("DeliveryTruck", 580, 31, 880);
DeliveryTruck *dtk2 = dynamic_cast<DeliveryTruck *>(truck4);
std::cout << "\n=== Notifying Trucks ===" << std::endl;
wheatField->notifyTrucks();
std::cout << "Count of delivery truck for wheatfield: " << dtk->getCallCounter() << std::endl;
potatoField->notifyTrucks();
std::cout << "Count of fertilizer truck for potatofield: " << ftk->getCallCounter() << std::endl;
sugarcaneField->notifyTrucks();
std::cout << "Count of fertilizer truck for potatofield: " << ftk2->getCallCounter() << std::endl;
// sunflowerField->notifyTrucks();
std::cout << "Count of delivery truck for sunflowerfield: " << dtk2->getCallCounter() << std::endl;
std::cout << "Details of crops: " << std::endl;
wheatField->displayDetails();
potatoField->displayDetails();
sugarcaneField->displayDetails();
sunflowerField->displayDetails();
std::cout << "\n=== Notifying a specific Truck ===" << std::endl;
sugarcaneField->notifyTruck(ftk2);
std::cout << "Details of crop: " << std::endl;
sugarcaneField->displayDetails();
std::cout << "\n=== Simulate Crop Storage Capacity and When soil is dry===" << std::endl;
wheatField->currStorageCap();
wheatField->currSoilState();
std::cout << "Details of wheatField: " << std::endl;
wheatField->displayDetails();
potatoField->currStorageCap();
potatoField->currSoilState();
std::cout << "Details of potatoField: " << std::endl;
potatoField->displayDetails();
sugarcaneField->currStorageCap();
sugarcaneField->currSoilState();
std::cout << "Details of sugarcaneField: " << std::endl;
sugarcaneField->displayDetails();
std::cout << "\n===Attempting to sell an unused truck===" << std::endl;
sunflowerField->sellTruck();
std::cout << "\n===Attempting to sell a used truck===" << std::endl;
wheatField->sellTruck();
sugarcaneField->sellTruck();
potatoField->sellTruck();
std::cout << "++++++++++++++++++++++++++++TRUCKS FOR Farm++++++++++++++++++++++++++++++++ " << std::endl;
std::cout << "\n===Total trucks in each field:===" << std::endl;
std::cout << "Total trucks in wheatField: " << wheatField->getCount() << std::endl;
std::cout << "Total trucks in potatoField: " << potatoField->getCount() << std::endl;
std::cout << "Total trucks in sugarcaneField: " << sugarcaneField->getCount() << std::endl;
std::cout << "Total trucks in sunflowerField: " << sunflowerField->getCount() << std::endl;
std::cout << "\n===Total trucks in the farm:===" << std::endl;
farm->addTruck(dtk);
farm->addTruck(ftk);
farm->addTruck(ftk2);
farm->addTruck(dtk2);
std::cout << "\n===Removing some trucks from the farm:===" << std::endl;
farm->removeTruck(dtk);
farm->removeTruck(ftk2);
std::cout << "Total Trucks in Farm: " << farm->getTruckCount() << std::endl;
farm->updateSensorData("Temperature", 50.60);
std::cout << "Updating the temperature sensors of the farm to : " << farm->getSensorData("Temperature") << std::endl;
delete truck3;
delete truck2;
delete truck;
}
void testComponent5()
{
std::cout << "++++++++++++++++++++Adding CROPFields++++++++++++++++++++++ " << std::endl;
CropField *cornField = new CropField("Corn", 100, "CF001", "North Field", 50.0, 20);
CropField *wheatField = new CropField("Wheat", 150, "CF002", "South Field", 40.0, 25);
CropField *soybeanField = new CropField("Soybean", 200, "CF003", "South-West Field", 60.0, 85);
CropField *riceField = new CropField("Rice", 300, "CF004", "East Field", 30.0, 95);
CropField *maizefield = new CropField("Maize", 100, "CF005", "West-side", 78.6, 100);
std::cout << "++++++++++++++++++++++++++Adding Farm++++++++++++++++++++++++++++ " << std::endl;
CompositeFarm *mainFarm = new CompositeFarm("Farm001", "Main Farm Location", 50.0);
mainFarm->addUnit(cornField);
mainFarm->addUnit(wheatField);
mainFarm->addUnit(soybeanField);
mainFarm->addUnit(riceField);
mainFarm->addUnit(maizefield);
std::cout << "++++++++++++++++++++++++++++BFT++++++++++++++++++++++++++++++ " << std::endl;
std::cout << "Breadth-First Traversal:" << std::endl;
BreadthFirstTraversal bfs(mainFarm);
while (!bfs.isDone())
{
FarmUnit *current = bfs.next();
if (current != NULL)
{
std::cout << "Visiting: " << current->getName() << std::endl;
}
}
std::cout << std::endl;
std::cout << "++++++++++++++++++++++++++++DFT+++++++++++++++++++++++++++++++ " << std::endl;
std::cout << "Depth-First Traversal:" << std::endl;
DepthFirstTraversal dfs(mainFarm);
while (!dfs.isDone())
{
FarmUnit *current = dfs.next();
if (current != NULL)
{
std::cout << "Visiting: " << current->getName() << std::endl;
}
}
delete mainFarm;
}