-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.mel
197 lines (159 loc) · 5.41 KB
/
tests.mel
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
// test suite for asset spacer
// author: dimelo waterson (@boner-cmd)
global proc testAssetSpacer() {
// to run, tests must exactly match procedure names!
string $testList[] = {
"soloX",
"squareX",
"rectangleX",
"oddX",
"oddXDiff",
"soloZ",
"squareZ",
"rectangleZ",
"oddZ",
"oddZDiff"
};
int $totalTests = size($testList);
if ( $totalTests == 0 ) {
warning "Asset Spacer test list is empty.\n";
error "Edit the MEL to add tests by procedure name.\n";
}
int $testPasses = runTests($testList);
print("aspacer results: " + $testPasses + " of " + $totalTests + " passed.\n");
}
proc int runTests(string[] $testSelection) {
int $passes
for ( $test in $testSelection ) {
if ( `exists $name` == 0 ) {
string $errmsg = "Test procedure " + $name + " does not exist.\n";
error $errmsg;
} else {
// possibly problematic syntax
$passes += eval $test;
}
}
return $passes;
}
// if MEL doesn't support comparing arrays element-for-element, do it ourselves
// limited to comparing axis query results (arrays of three floats)
proc int samePosition(float[] $firstPosition, float[] $secondPosition){
int $i;
for ($i = 0; $i < 3; $i++)) {
if ( $firstPosition[$i] != $secondPosition[$i] ) {
return 0;
}
}
return 1;
}
// tests return 0 on fail, 1 on pass
// tests should be run in an empty viewport
proc string[] makeTestPolys(int $numPolys, string $polyType){
// "polyPrimitive" is the command to create a soccer ball
// but all listed polygon types are primitives, including the platonic solids
string $polyPrimitives[11] = {
"sphere",
"cube",
"cylinder",
"cone",
"plane",
"torus",
"prism",
"pyramid",
"pipe",
"helix",
"primitive"
};
string $platonicSolids[4] = {
"dodecahedron",
"icosahedron",
"octahedron",
"tetrahedron"
};
tolower $polyType;
int $polyOnPrimitiveList = stringArrayContains($polyType, $polyPrimitives);
int $polyIsPlatonicSolid = stringArrayContains($polyType, $platonicSolids);
if ( $polyOnPrimitiveList || $polyIsPlatonicSolid ) {
capitalizeString($polyType);
string $polyName = "test" + $polyType;
string $polyCmd = "poly";
string $polyNameList[$numPolys];
if ( $polyIsPlatonicSolid ) {
$polyCmd += "PlatonicSolid -solidType ";
int $pSolidType;
switch ( startString($polyType, 1) ) {
case "D":
$pSolidType = 0;
break;
case "I":
$pSolidType = 1;
break;
case "O":
$pSolidType = 2;
break;
case "T":
$pSolidType = 3;
break;
}
$polyCmd += $pSolidType + " -name ";
} else {
$polyCmd += $polyType + " -name ";
}
int $i;
for ($n = 1; $n <= $numPolys; $n++){
$i = $n-1;
string $nextPoly = $polyName + $n;
if ( catch (eval ($polyCmd + $nextPoly)) ){
warning "Cannot create " + $nextPoly ".\n";
error $nextPoly + " already exists.\n";
}
$polyNameList[$i] = $nextPoly;
}
return $polyNameList;
} else {
warning "Valid polygon primitive types include: sphere, cube, cylinder, cone, \
plane, torus, prism, pyramid, pipe, helix, primitive (for soccer ball), \
dodecahedron, icosahedron, octahedron, and tetrahedron.\n";
error "Invalid poly primitive specified for creation.\n";
}
}
// get the position of an object using the appropriate procedure based on its name
// TODO is it worth doing this, rather than just grabbing the translate attribute?
// TODO are there times that querying the axis gives different results than translate attributes?
proc float[] getPosition(string $polygon){
}
proc int soloX(){
int $numPolys = 1;
string $polyNamesList[$numPolys] = makeTestPolys($numPolys, "cube");
// TODO created polygons must be added to a group, since Asset Spacer works by group
// select $somegroup;
aSpacerCmd({1, 1, 1, 0, 0});
float $pos[3]; // resolve TODO related to proc getPosition to complete this statement
// TODO actually find the correct position
float $correctPos[3] = {0.5, 0.5, 0};
if ( samePosition($pos, $correctPos) ){
warning "Solo X test passed.\n";
return 1;
} else {
warning "Solo X test failed. Cube " + $cubename + " in wrong position.\n";
return 0;
}
}
proc int squareX() {
}
proc int rectangleX() {
}
proc int oddX() {
}
proc int oddXDiff() {
}
proc int soloZ() {
}
proc int squareZ() {
}
proc int rectangleZ() {
}
proc int oddZ() {
}
proc int oddZDiff() {
}