-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_runner.html
More file actions
278 lines (231 loc) · 10.1 KB
/
Copy pathtest_runner.html
File metadata and controls
278 lines (231 loc) · 10.1 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test Runner</title>
</head>
<style>
pre {
background-color: lightgrey;
}
body {
font-family: sans-serif;
margin: 3rem;
}
</style>
<body>
<script>
window.onerror = function(errorMsg, url, lineNumber){
// any action you want goes here
// errorMsg is the error message itself.
// url should be the file presenting the error, though i have
// found that it only presents to me the address of the site.
// lineNumber is the line number the error occoured on.
// here is an example of what you could do with it:
const error = document.getElementById("error")
error.innerHTML = "Error in " + url + " at " + lineNumber + ":\n" + errorMsg
}
</script>
<h1>🏃 Test Runner 🏃 </h1>
<h2>🔧 Testing Tuple functions</h2>
<ul id="test_list"></ul>
<h2>🌈 Testing Color functions</h2>
<ul id="colors_list"></ul>
<h2>📈 Testing Canvas functions</h2>
<ul id="canvas_list"></ul>
<h2>🧮 Testing Matrix functions</h2>
<ul id="matrix_list"></ul>
<h2>🌠 Testing Ray functions</h2>
<ul id="ray_list"></ul>
<h2>🌓 Testing Shading functions</h2>
<ul id="shading_list"></ul>
<h2>⛺ Testing Scene functions</h2>
<ul id="scene_list"></ul>
<h2>🛫 Testing Shape functions</h2>
<ul id="shape_list"></ul>
<h2>🏁 Testing Pattern functions</h2>
<ul id="pattern_list"></ul>
<h2>💖 Testing Reflection and Refraction functions</h2>
<ul id="reflect_list"></ul>
<h2>🧊 Testing Cubes functions</h2>
<ul id="cubes_list"></ul>
<h2>🎩 Testing Cylinders functions</h2>
<ul id="cylinders_list"></ul>
<pre><code id="error"></code></pre>
<p id="perf"></p>
<script src="./js/patterns.js"></script>
<script src="./js/shapes.js"></script>
<script src="./js/functions.js"></script>
<script src="./js/tests.js"></script>
<script>
// *** RUN TESTS, DISPLAY RESULTS
const start = performance.now()
function runTest(domId, callback) {
// Get list and create a new list item
const ul = document.getElementById(domId)
const li = document.createElement("li")
// Create placeholder inside list item
const li_text = document.createElement("span")
li_text.innerHTML = "Running " + callback.name + "(): "
// Append list item to list
ul.appendChild(li);
// Append span to list item
li.appendChild(li_text)
// Measure time for each test
const start = performance.now()
// Run test
var result = callback()
const elapsed = performance.now() - start
const li_result = document.createElement("span")
li.appendChild(li_result)
var text = (result) ? "Test Passed! 🌞":"Test Failed! 💥"
var color = (result) ? "green":"red"
li_result.style.color = color
li_result.innerHTML = text //+ ` (in ${elapsed.toFixed(2)} ms.)`
li_time = document.createElement("span")
li.appendChild(li_time)
var time_color = elapsed > 1 ? "red" : "green"
li_time.style.color = time_color
li_time.innerHTML = ` (in ${elapsed.toFixed(2)} ms.)`
}
runTest("test_list", test_tuple_function)
runTest("test_list", test_vector_function)
runTest("test_list", test_point_function)
runTest("test_list", test_equal_function)
runTest("test_list", test_equal_tuples_function)
runTest("test_list", test_add_tuples_function)
runTest("test_list", test_subtract_tuples_function)
runTest("test_list", test_negate_tuple_function)
runTest("test_list", test_multiply_vector_function)
runTest("test_list", test_divide_vector_function)
runTest("test_list", test_magnitude_function)
runTest("test_list", test_normalize_function)
runTest("test_list", test_dot_function)
runTest("test_list", test_cross_function)
runTest("colors_list", test_color_function)
runTest("colors_list", test_add_colors_function)
runTest("colors_list", test_subtract_colors_function)
runTest("colors_list", test_multiply_color_function)
runTest("colors_list", test_multiply_colors_function)
runTest("colors_list", test_scale_color_function)
runTest("canvas_list", test_canvas_function)
runTest("canvas_list", test_html_canvas_function)
runTest("canvas_list", test_html_get_pixel_color_function)
runTest("canvas_list", test_write_pixel_function)
runTest("canvas_list", test_constructing_ppm_header)
runTest("canvas_list", test_ppm_pixel_data)
runTest("canvas_list", test_canvas_to_ppm_function)
runTest("matrix_list", test_create_matrix_function)
runTest("matrix_list", test_matrix_equal_function)
runTest("matrix_list", test_multiply_matrices_function)
runTest("matrix_list", test_multiply_matrix_by_tuple_function)
runTest("matrix_list", test_idmatrix_function)
runTest("matrix_list", test_multiply_by_identity_matrix_function)
runTest("matrix_list", test_transpose_matrix_function)
runTest("matrix_list", test_transpose_identity_matrix)
runTest("matrix_list", test_calculate_determinant_of_2x2_matrix)
runTest("matrix_list", test_submatrix_function)
runTest("matrix_list", test_minor_function)
runTest("matrix_list", test_cofactor_function)
runTest("matrix_list", test_calculate_determinant_of_3x3_matrix)
runTest("matrix_list", test_is_matrix_invertible)
runTest("matrix_list", test_inverse_matrix_function)
runTest("matrix_list", test_inverse_matrix_function_2)
runTest("matrix_list", test_multiply_by_inverse)
runTest("matrix_list", test_translation_function)
runTest("matrix_list", test_scaling_function)
runTest("matrix_list", test_rotation_x_function)
runTest("matrix_list", test_rotation_y_function)
runTest("matrix_list", test_rotation_z_function)
runTest("matrix_list", test_shearing_function)
runTest("matrix_list", test_angle_function)
runTest("matrix_list", test_chained_transformations)
runTest("matrix_list", test_apply_individual_transformations)
runTest("ray_list", test_creating_ray_function)
runTest("ray_list", test_position_function)
runTest("ray_list", test_sphere_function)
runTest("ray_list", test_intersect_sets_the_object_on_the_intersection)
runTest("ray_list", test_ray_intersects_sphere_at_two_points)
runTest("ray_list", test_ray_intersects_sphere_at_tangent)
runTest("ray_list", test_ray_misses_a_sphere)
runTest("ray_list", test_ray_originates_inside_a_sphere)
runTest("ray_list", test_sphere_is_behind_a_ray)
runTest("ray_list", test_intersection_function)
runTest("ray_list", test_intersections_function)
runTest("ray_list", test_hit_function)
runTest("ray_list", test_transform_function)
runTest("ray_list", test_transform_sphere)
runTest("shading_list", test_normal_at_function)
runTest("shading_list", test_normal_on_transformed_sphere)
runTest("shading_list", test_reflect_function)
runTest("shading_list", test_point_light_function)
runTest("shading_list", test_material_function)
runTest("shading_list", test_sphere_has_material)
runTest("shading_list", test_lighting_function)
runTest("scene_list", test_world_function)
runTest("scene_list", test_create_default_world_function)
runTest("scene_list", test_intersect_world_function)
runTest("scene_list", test_prepare_computations_function)
runTest("scene_list", test_hit_inside_object)
runTest("scene_list", test_shade_hit_function)
runTest("scene_list", test_color_at_function)
runTest("scene_list", test_view_transform_function)
runTest("scene_list", test_camera_function)
runTest("scene_list", test_ray_for_pixel_function)
runTest("scene_list", test_render_function)
runTest("scene_list", test_is_shadowed_function)
runTest("shape_list", test_test_shape_function)
runTest("shape_list", test_shape_inherited_intersect_function)
runTest("shape_list", test_shape_inherited_normal_at_function)
runTest("shape_list", test_plane_function)
runTest("pattern_list", test_stripe_pattern_function)
runTest("pattern_list", test_stripe_at_function)
runTest("pattern_list", test_lighting_has_stripe_pattern)
runTest("pattern_list", test_stripe_at_object_function)
runTest("pattern_list", test_pattern_has_inherited_from_abstract_class)
runTest("pattern_list", test_gradient_pattern_function)
runTest("pattern_list", test_ring_pattern_function)
runTest("pattern_list", test_chequered_pattern_function)
runTest("reflect_list", test_material_reflective_attribute)
runTest("reflect_list", test_prepare_computations_reflectv)
runTest("reflect_list", test_reflected_color_function)
runTest("reflect_list", test_avoid_infinite_recursion_reflection)
runTest("reflect_list", test_limit_recursion_of_reflection)
runTest("reflect_list", test_material_has_transparency_and_refraction)
runTest("reflect_list", test_glass_sphere_function)
runTest("reflect_list", test_finding_n1_and_n2_refractive_indices)
runTest("reflect_list", test_computing_under_point)
runTest("reflect_list", test_refracted_color_of_opaque_object)
runTest("reflect_list", test_refracted_color_at_max_recursions)
runTest("reflect_list", test_refracted_color_under_total_internal_reflection)
runTest("reflect_list", test_refracted_color_with_a_refracted_ray)
runTest("reflect_list", test_shade_hit_handles_refraction)
runTest("reflect_list", test_shlick_function)
runTest("reflect_list", test_shade_hit_with_reflective_transparent_material)
runTest("reflect_list", test_object_can_omit_casting_shadow)
runTest("cubes_list", test_ray_intersects_cube)
runTest("cubes_list", test_ray_misses_cube)
runTest("cubes_list", test_normal_on_cube)
runTest("cylinders_list", test_ray_misses_cylinder)
runTest("cylinders_list", test_ray_hits_cylinder)
runTest("cylinders_list", test_normal_on_cylinder)
runTest("cylinders_list", test_default_minmax_on_cylinder)
runTest("cylinders_list", test_truncated_cylinders)
runTest("cylinders_list", test_default_open_cylinder)
runTest("cylinders_list", test_intersect_cylinder_end_caps)
runTest("cylinders_list", test_normal_on_cylinder_end_caps)
const end = performance.now()
const elapsed = end - start
const cumulated_id = "test_running_time"
const numberOfRuns_id = "runs"
const cumulated = localStorage.getItem(cumulated_id)
const runs = localStorage.getItem(numberOfRuns_id)
localStorage.setItem("runs", Number(runs) + 1)
localStorage.setItem(cumulated_id, Number(cumulated) + elapsed)
log("perf", "Tests running time: " + Math.round(elapsed) + " ms.")
log("perf", "Average running time: " + (cumulated / runs).toFixed(4) + " ms.")
Object.keys(_calls).length > 0 ? log("perf", "Telemetry profiler: " + JSON.stringify(_calls,0,3)) : null
window.scrollTo(0,document.body.scrollHeight);
</script>
</body>
</html>