1 /*=========================================================================
2
3 Module: verdict_test.cpp
4
5 Copyright (c) 2006 Sandia Corporation.
6 All rights reserved.
7 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notice for more information.
12
13 =========================================================================*/
14 /*
15 *
16 * verdict_test.cpp provides routines for testing the quality metrics code
17 *
18 * This file is part of VERDICT
19 *
20 */
21 #define VERDICT_EXPORTS
22
23 #include "verdict.h"
24 #include "v_vector.h"
25 #include <math.h>
26 #include <iostream>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30
31 using namespace std;
32
33
34 #define MAX_NODES_PER_ELEMENT 27
35 #define MAX_TESTS_PER_ELEMENT 20
36
37
38 #ifdef VERDICT_USE_FLOAT
39 #define VERDICT_SIGNIFICANT_FIG 7 // 7 significant figures for floats
40 #else
41 #define VERDICT_SIGNIFICANT_FIG 15 // 15 significant figures for doubles
42 #endif
43
44
45 struct test_case
46 {
47 const char* testname;
48 VerdictFunction function[MAX_TESTS_PER_ELEMENT];
49 int num_nodes;
50 // note: the 1st dim. of coords must bigger than the maximum num_nodes
51 // for any one element being tested
52 double coords[MAX_NODES_PER_ELEMENT][3];
53 double answer[MAX_TESTS_PER_ELEMENT];
54 };
55
56
main()57 int main( )
58 {
59 // all test cases go here
60 test_case testcases[] = {
61 /*
62 {
63 "edge calc 1",
64 {v_edge_length, 0},
65 2,
66 { { 0,0,0 }, {1,1,1} },
67 { 1.732050807568877, 0 }
68 },
69
70 {
71 "edge calc 2",
72 {v_edge_length, 0 },
73 2,
74 { { 0,0,0 }, { 1,0,0 } },
75 { 1.0, 0 }
76 },
77
78 {
79 "edge calc 3",
80 {v_edge_length, 0 },
81 2,
82 { { 0,0,0 }, { 0,0,0 } },
83 { 0, 0 }
84 },
85
86 {
87 "simple wedge" ,
88 {v_wedge_volume, 0},
89 6,
90 { { 0,0,0}, {-1,1,0}, {-1,0,0}, {0,0,1}, {-1,1,1}, {-1,0,1} },
91 { 0.5, 0 }
92 },
93
94 {
95 "singularity wedge",
96 {v_wedge_volume, 0},
97 6,
98 { {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0} },
99 { 0 }
100 },
101
102 {
103 "simple tri",
104 { v_tri_area, v_tri_minimum_angle, v_tri_maximum_angle, v_tri_condition,
105 v_tri_shape, v_tri_shape_and_size, v_tri_distortion, 0},
106 3,
107 {
108 {0,0,0},
109 {5,0,0},
110 {2.5, 4.330127, 0},
111 },
112
113 { 0,0,0,0,0,0,0}
114 },
115 {
116 "singular tri",
117 {v_tri_area, v_tri_aspect_ratio, v_tri_condition,
118 v_tri_distortion, v_tri_minimum_angle, v_tri_maximum_angle,
119 v_tri_relative_size_squared, v_tri_shape, v_tri_shape_and_size,
120 0},
121 3,
122 {
123 {0,0,0},
124 {0.5,0.8660254037,0},
125 {1,0,0} },
126 { 123, 1234, 1234, 1234, 1234, 1234, 1234, 1234, 1234,0}
127 },
128 {
129 "simple quad",
130 { v_quad_skew, 0},
131 4,
132 {
133 {0,0,0},
134 {1,0,0},
135 {1,7,0},
136 {0,7,0 }
137 },
138 { 1.3333333333333333333, 0 }
139 },
140
141 {
142 "simple quad",
143 { v_quad_aspect_ratio, v_quad_skew, v_quad_taper, v_quad_warpage, v_quad_area,
144 v_quad_stretch, v_quad_minimum_angle, v_quad_maximum_angle,
145 v_quad_condition, v_quad_jacobian, v_quad_shear,
146 v_quad_shape, v_quad_shape_and_size, v_quad_shear_and_size,
147 v_quad_distortion, 0},
148 4,
149 {
150 {2,0,0}, //1
151 {1,1,2}, //2
152 {0,1,0 }, //3
153 {0,0,0}, //0
154
155
156
157 },
158 { 1.34, .30, .20, .20, .23, 0,0, 0, 0, 0 , 0, 0, 0, 0, 0, 0}
159 },
160 {
161 "tet test",
162 { v_tet_volume, v_tet_condition, v_tet_jacobian,
163 v_tet_shape, v_tet_shape_and_size, v_tet_distortion, 0 },
164 4,
165 {
166 {-5, -5, -5 },
167 {-5, 5, -5 },
168 {-5, -5, 5 },
169 {5, -5, -5 },
170
171 },
172
173 {0,0,0,0,0,0,0}
174 },
175 {
176 "hex test",
177 { v_hex_skew, v_hex_taper, v_hex_volume, v_hex_stretch, v_hex_diagonal,
178 v_hex_dimension, v_hex_condition, v_hex_jacobian, v_hex_shear,
179 v_hex_shape, v_hex_shear_and_size, v_hex_shape_and_size,
180 v_hex_distortion, 0 },
181 8,
182
183 {
184 { -.2, -.7, -.3 }, //1
185 { -.7, .4, -.6 }, //2
186 { -.5, .5, .3 }, //3
187 { -.3, -.5, .5 }, //0
188
189 { .5, -.8, -.2 }, //5
190 { .4, .4, -.6 }, //6
191 { .2, .5, .2 }, //7
192 { .5, -.3, .8 } //4
193 },
194
195
196 {0.34,0.34,0.34,0.34,0.34,0.34,0.34,0.34,0.34,0.34,0.34,0.34,0}
197 },
198
199 */
200 // keep this one last
201 { 0, {0} , 0, {{0}} , {0} } };
202
203
204
205
206
207 int i;
208 int j = 0;
209 double answer_from_lib;
210 double tolerance;
211 // double norm_answer_from_lib;
212
213 #define MAX_STR_LEN 30
214
215 char exponent[MAX_STR_LEN];
216 char *base_ptr;
217 int base;
218 bool passed = true; // have all the tests performed so far passed?
219
220 cout.setf( ios::scientific, ios::floatfield );
221 cout.precision(VERDICT_SIGNIFICANT_FIG + 3 );
222
223 cout << endl;
224
225
226 // loop through each test
227 for ( i = 0; testcases[i].testname != 0; i++ )
228 {
229
230 for ( j = 0; testcases[i].function[j] != 0; j++ )
231 {
232 answer_from_lib =
233 (testcases[i].function[j])
234 (testcases[i].num_nodes, testcases[i].coords);
235
236 sprintf(exponent, "%e", testcases[i].answer[j]);
237 base_ptr = strstr( exponent, "e" );
238
239 base_ptr = &base_ptr[1];
240
241 base = atoi(base_ptr);
242
243 tolerance = pow (10.0, - VERDICT_SIGNIFICANT_FIG ) * pow ( 10.0, base );
244
245 if ( fabs( answer_from_lib - testcases[i].answer[j] ) > tolerance )
246 {
247 cout << endl;
248 cout << "Test case \"" << testcases[i].testname
249 << "\" #" << j+1 << " FAILED" << endl;
250
251 cout << "answer calculated was "
252 << answer_from_lib << endl
253 << "answer expected was "
254 << testcases[i].answer[j]
255 << endl << endl;
256 passed = false;
257 }
258 else
259 {
260 cout << "Test case \"" << testcases[i].testname
261 << "\" #" << j+1 << " passed" << endl;
262 // << "answer calculated was "
263 // << answer_from_lib << endl
264 // << "answer expected was "
265 // << testcases[i].answer[j] << endl;
266 // // cout << endl;
267 }
268 }
269 }
270
271 cout << endl;
272
273 return passed ? 0 : 1;
274 }
275