-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit_test.py
88 lines (55 loc) · 1.98 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
# unit test suite for RoadModel.py
# run 'py.test unit_test.py'
# missing test functions: functions creating files and arrays
from RoadModel import *
def test_createProjectBbox():
# Input
standsfn = 'stands.shp'
offsetBbox = 200
# Expected Output
bbox = (274057.7229842426, 278445.30065590295, 1064147.15267288, 1067090.7083014385)
assert(createProjectBbox(standsfn,offsetBbox)) == bbox
def test_createGrid():
# Input
gridfn = 'grid.shp'
bbox = (274057.7229842426, 278445.30065590295, 1064147.15267288, 1067090.7083014385)
gridHeight = gridWidth = 100
# Expected Output
outbbox = (274057.7229842426, 278457.7229842426, 1064090.7083014385, 1067090.7083014385)
assert(createGrid(gridfn,bbox,gridHeight,gridWidth)) == outbbox
def test_selectCell():
# Input
gridfn = 'grid.shp'
bufferfn = 'buffer.shp'
# Expected Output
selectedCell = 623
assert(selectCell(gridfn,bufferfn)) == selectedCell
def test_getBbox():
# Input
shpfn = 'stands.shp'
# Expected Output
bbox = (274257.7229842426, 278245.30065590295, 1064347.15267288, 1066890.7083014385)
assert(getBbox(shpfn)) == bbox
def test_coord2pixelOffset():
# Input
rasterfn = 'slope.tif'
x = 274057.722984
y = 1064090.7083
# Expected Output
xOffset = 82
yOffset = 498
pixelWidth = 9.082676986761792
pixelHeight = -9.082676986761792
assert(coord2pixelOffset(rasterfn,x,y)) == (xOffset, yOffset, pixelWidth, pixelHeight)
def test_bbox2pixelOffset():
# Input
rasterfn = 'slope.tif'
bbox = (274057.7229842426, 278457.7229842426, 1064090.7083014385, 1067090.7083014385)
# Expected Output
xoff = 82
yoff = 168
xsize = 484
ysize = 330
pixelWidth = 9.082676986761792
pixelHeight = -9.082676986761792
assert(bbox2pixelOffset(rasterfn,bbox)) == (xoff,yoff,xsize,ysize,pixelWidth,pixelHeight)