-
Notifications
You must be signed in to change notification settings - Fork 2
/
unit_test.py
289 lines (234 loc) · 9.14 KB
/
unit_test.py
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
# unit test suite for forestcost
# run 'py.test unit_test.py'
from forestcost import landing
from forestcost import routing
from forestcost import main_model
from forestcost import skidding
from forestcost import harvesting
from forestcost import hauling
import ogr
driver = ogr.GetDriverByName('ESRI Shapefile')
def test_landing():
# test landing: landing_coords
# Input
property_shp = driver.Open('testdata//test_stand.shp', 0)
property_lyr = property_shp.GetLayer()
# Expected Output
landing_coords = (-124.04858, 43.12776)
assert(landing.landing(property_lyr)) == landing_coords
def test_routing():
# test routing: haulDist, haulTime, coord_mill
# Input
landing_coords = (-124.04858, 43.12776)
mill_shp = 'testdata//mills.shp'
# Expected Output
haulDist = 8.674960531
haulTime = 32.92
coord_mill = (-124.161246, 43.106512)
assert(routing.routing(landing_coords, mill_shp=mill_shp)) == (haulDist, haulTime, coord_mill)
def test_skidding():
# test skidding: SkidDist, HauldistExtension, coord_landing_stand"
# Input
stand_wkt = u'POLYGON ((-13809080.891332019 5330620.9753014417,-13808943.708174769 5331066.8205624959,-13808393.373740762 5330897.4868904939,-13808530.556898013 5330451.6416294342,-13809080.891332019 5330620.9753014417))'
landing_coords = (-124.04858, 43.12776)
Slope = 21.74728843
# Expected Output
SkidDist = 999.69
HaulDistExtension = 1420.39
coord_landing_stand = (-124.04706351844823, 43.125146208049415)
assert(skidding.skidding(stand_wkt, landing_coords, Slope)) == (SkidDist, HaulDistExtension, coord_landing_stand)
def test_harvesting_GroundBasedMechWT():
# test harvesting: harvestCost, HarvestSystem
# Input
PartialCut = 0
Slope = 30
SkidDist = 1200
Elevation = 100
RemovalsCT = 200.0
TreeVolCT = 5.0
RemovalsSLT = 100.0
TreeVolSLT = 70.0
RemovalsLLT = 20.0
TreeVolLLT = 200.0
HdwdFractionCT = 0.15
HdwdFractionSLT = 0.0
HdwdFractionLLT = 0.0
# Expected Output
harvestCost = 0.4423
HarvestSystem = 'GroundBasedMechWT'
assert(harvesting.harvestcost(
PartialCut, Slope, SkidDist, Elevation,
RemovalsCT, TreeVolCT, RemovalsSLT, TreeVolSLT, RemovalsLLT, TreeVolLLT,
HdwdFractionCT, HdwdFractionSLT, HdwdFractionLLT))== (harvestCost, HarvestSystem)
def test_harvesting_GroundBasedMechWT():
# test harvesting: harvestCost, HarvestSystem
# Input
PartialCut = 1
Slope = 30
SkidDist = 100
Elevation = 100
RemovalsCT = 200.0
TreeVolCT = 5.0
RemovalsSLT = 100.0
TreeVolSLT = 70.0
RemovalsLLT = 20.0
TreeVolLLT = 200.0
HdwdFractionCT = 0.15
HdwdFractionSLT = 0.0
HdwdFractionLLT = 0.0
# Expected Output
harvestCost = 0.3038
HarvestSystem = 'GroundBasedMechWT'
assert(harvesting.harvestcost(
PartialCut, Slope, SkidDist, Elevation,
RemovalsCT, TreeVolCT, RemovalsSLT, TreeVolSLT, RemovalsLLT, TreeVolLLT,
HdwdFractionCT, HdwdFractionSLT, HdwdFractionLLT))== (harvestCost, HarvestSystem)
def test_harvesting_GroundBasedManualWT():
# test harvesting: harvestCost, HarvestSystem
# Input
PartialCut = 0
Slope = 30
SkidDist = 1200
Elevation = 100
RemovalsCT = 200.0
TreeVolCT = 5.0
RemovalsSLT = 100.0
TreeVolSLT = 70.0
RemovalsLLT = 20.0
TreeVolLLT = 300.0
HdwdFractionCT = 0.15
HdwdFractionSLT = 0.0
HdwdFractionLLT = 0.0
# Expected Output
harvestCost = 0.5358
HarvestSystem = 'GroundBasedManualWT'
assert(harvesting.harvestcost(
PartialCut, Slope, SkidDist, Elevation,
RemovalsCT, TreeVolCT, RemovalsSLT, TreeVolSLT, RemovalsLLT, TreeVolLLT,
HdwdFractionCT, HdwdFractionSLT, HdwdFractionLLT))== (harvestCost, HarvestSystem)
def test_harvesting_CableManualWT():
# test harvesting: harvestCost, HarvestSystem
# Input
PartialCut = 0
Slope = 60
SkidDist = 1200
Elevation = 100
RemovalsCT = 200.0
TreeVolCT = 5.0
RemovalsSLT = 100.0
TreeVolSLT = 70.0
RemovalsLLT = 20.0
TreeVolLLT = 200.0
HdwdFractionCT = 0.15
HdwdFractionSLT = 0.0
HdwdFractionLLT = 0.0
# Expected Output
harvestCost = 0.7595
HarvestSystem = 'CableManualWT'
assert(harvesting.harvestcost(
PartialCut, Slope, SkidDist, Elevation,
RemovalsCT, TreeVolCT, RemovalsSLT, TreeVolSLT, RemovalsLLT, TreeVolLLT,
HdwdFractionCT, HdwdFractionSLT, HdwdFractionLLT))== (harvestCost, HarvestSystem)
def test_harvesting_CableManualWT_PartialCut():
# test harvesting: harvestCost, HarvestSystem
# Input
PartialCut = 1
Slope = 60
SkidDist = 1200
Elevation = 100
RemovalsCT = 200.0
TreeVolCT = 5.0
RemovalsSLT = 100.0
TreeVolSLT = 70.0
RemovalsLLT = 20.0
TreeVolLLT = 200.0
HdwdFractionCT = 0.15
HdwdFractionSLT = 0.0
HdwdFractionLLT = 0.0
# Expected Output
harvestCost = 0.5467
HarvestSystem = 'CableManualWT'
assert(harvesting.harvestcost(
PartialCut, Slope, SkidDist, Elevation,
RemovalsCT, TreeVolCT, RemovalsSLT, TreeVolSLT, RemovalsLLT, TreeVolLLT,
HdwdFractionCT, HdwdFractionSLT, HdwdFractionLLT))== (harvestCost, HarvestSystem)
def test_harvesting_HelicopterManualWT():
# test harvesting: harvestCost, HarvestSystem
# Input
PartialCut = 0
Slope = 60
SkidDist = 2000
Elevation = 100
RemovalsCT = 200.0
TreeVolCT = 5.0
RemovalsSLT = 100.0
TreeVolSLT = 70.0
RemovalsLLT = 20.0
TreeVolLLT = 100.0
HdwdFractionCT = 0.15
HdwdFractionSLT = 0.0
HdwdFractionLLT = 0.0
# Expected Output
harvestCost = 1.2036
HarvestSystem = 'HelicopterManualWT'
assert(harvesting.harvestcost(
PartialCut, Slope, SkidDist, Elevation,
RemovalsCT, TreeVolCT, RemovalsSLT, TreeVolSLT, RemovalsLLT, TreeVolLLT,
HdwdFractionCT, HdwdFractionSLT, HdwdFractionLLT))== (harvestCost, HarvestSystem)
def test_hauling():
# test hauling: haulCost
# Input
haulDist = 8.94
haulTimeRT = 65.8402988889
# Expected Output
haulCost = 0.604
assert(hauling.haulcost(haulDist, haulTimeRT)) == haulCost
def test_cost_func():
# test cost_func: cost
# Input
# stand info
area = 66.3709
elevation = 141.034205761
slope = 21.74728843
stand_wkt = u'POLYGON ((-13809080.891332019 5330620.9753014417,-13808943.708174769 5331066.8205624959,-13808393.373740762 5330897.4868904939,-13808530.556898013 5330451.6416294342,-13809080.891332019 5330620.9753014417))'
# harvest info
RemovalsCT = 200.0
TreeVolCT = 5.0
RemovalsSLT = 100.0
TreeVolSLT = 70.0
RemovalsLLT = 20.0
TreeVolLLT = 200.0
HdwdFractionCT = 0.15
HdwdFractionSLT = 0.0
HdwdFractionLLT = 0.0
PartialCut = 0
# routing info
landing_coords = (-124.04858, 43.12776)
haulDist = 8.674960531
haulTime = 32.92
coord_mill = (-124.161246, 43.106512)
# Expected Output
cost = {'slope': 21.75, 'skid_distance': 999.69, 'mill_coordinates': (-124.161246, 43.106512), 'elevation': 141.03, 'total_harvest_cost': 314598.0, 'haul_distance_ow': 8.94, 'total_cost': 350309.0, 'haul_cost_min': 0.604, 'total_area': 66.37, 'harvest_cost_ft3': 0.395, 'haul_distance_extension': 0.269, 'total_haul_trips': 898.0, 'haul_time_ow': 32.92, 'total_haul_cost': 35711.0, 'harvest_system': 'GroundBasedMechWT', 'landing_coordinates': (-124.04706351844823, 43.125146208049415), 'total_volume': 796450.8}
assert(main_model.cost_func(
# stand info
area,
elevation,
slope,
stand_wkt,
# harvest info
RemovalsCT,
TreeVolCT,
RemovalsSLT,
TreeVolSLT,
RemovalsLLT,
TreeVolLLT,
HdwdFractionCT,
HdwdFractionSLT,
HdwdFractionLLT,
PartialCut,
# routing info
landing_coords,
haulDist,
haulTime,
coord_mill
)) == cost