From df0f2938251d4856289b5eb2e43644f4d8b7a52e Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Tue, 11 Jun 2019 13:49:31 +0800 Subject: [PATCH] use built-in assert --- src/unittest.scad | 9 --------- test/test_function_grapher.scad | 2 +- test/test_line2d.scad | 6 +++--- test/test_line3d.scad | 4 ++-- test/test_polysections.scad | 4 ++-- test/test_rounded_cube.scad | 6 +++--- 6 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/unittest.scad b/src/unittest.scad index 68239504..f58bc1d4 100644 --- a/src/unittest.scad +++ b/src/unittest.scad @@ -96,15 +96,6 @@ module assertEqual(expected, actual, float_digits = 4) { } } -module assertTrue(truth) { - if(!truth) { - fail( - "Truth", - "expected: true, but: false" - ); - } -} - module round_echo_pts(points, float_digits = 4) { echo(round_pts(points, float_digits)); } diff --git a/test/test_function_grapher.scad b/test/test_function_grapher.scad index b78ab755..17e4ec98 100644 --- a/test/test_function_grapher.scad +++ b/test/test_function_grapher.scad @@ -33,7 +33,7 @@ module test_function_grapher_default() { expected_faces = [[0, 5, 1], [1, 6, 2], [2, 7, 3], [4, 9, 5], [5, 10, 6], [6, 11, 7], [8, 13, 9], [9, 14, 10], [10, 15, 11], [0, 4, 5], [1, 5, 6], [2, 6, 7], [4, 8, 9], [5, 9, 10], [6, 10, 11], [8, 12, 13], [9, 13, 14], [10, 14, 15], [17, 21, 16], [18, 22, 17], [19, 23, 18], [21, 25, 20], [22, 26, 21], [23, 27, 22], [25, 29, 24], [26, 30, 25], [27, 31, 26], [21, 20, 16], [22, 21, 17], [23, 22, 18], [25, 24, 20], [26, 25, 21], [27, 26, 22], [29, 28, 24], [30, 29, 25], [31, 30, 26], [0, 1, 17, 16], [1, 2, 18, 17], [2, 3, 19, 18], [3, 7, 23, 19], [7, 11, 27, 23], [11, 15, 31, 27], [13, 12, 28, 29], [14, 13, 29, 30], [15, 14, 30, 31], [4, 0, 16, 20], [8, 4, 20, 24], [12, 8, 24, 28]]; for(i = [0:len(expected_faces) - 1]) { - assertTrue(expected_faces[i] == faces[i]); + assert(expected_faces[i] == faces[i]); } } diff --git a/test/test_line2d.scad b/test/test_line2d.scad index 0cda2d9b..c70cdf17 100644 --- a/test/test_line2d.scad +++ b/test/test_line2d.scad @@ -12,7 +12,7 @@ module test_line2d() { include ; module test_line2d_cap(point, style) { - assertTrue( + assert( (point == p1 && style == "CAP_SQUARE") || (point == p2 && style == "CAP_SQUARE") ); @@ -34,7 +34,7 @@ module test_line2d() { include ; module test_line2d_cap(point, style) { - assertTrue( + assert( (point == p1 && style == "CAP_ROUND") || (point == p2 && style == "CAP_ROUND") ); @@ -57,7 +57,7 @@ module test_line2d() { include ; module test_line2d_cap(point, style) { - assertTrue( + assert( (point == p1 && style == "CAP_BUTT") || (point == p2 && style == "CAP_BUTT") ); diff --git a/test/test_line3d.scad b/test/test_line3d.scad index fc0ab185..91f296e3 100644 --- a/test/test_line3d.scad +++ b/test/test_line3d.scad @@ -20,7 +20,7 @@ module test_line3d() { } module test_line3d_cap(p, r, frags, cap_leng, angles) { - assertTrue(p == p1 || p == p2); + assert(p == p1 || p == p2); assertEqual(thickness / 2, r); assertEqual(fn, frags); assertEqual(0.3536, cap_leng); @@ -77,7 +77,7 @@ module test_line3d() { } module test_line3d_cap(p, r, frags, cap_leng, angles) { - assertTrue(p == p1 || p == p2); + assert(p == p1 || p == p2); assertEqual(thickness / 2, r); assertEqual(fn, frags); assertEqual(0.5043, cap_leng); diff --git a/test/test_polysections.scad b/test/test_polysections.scad index bc3793d6..6f7b7a01 100644 --- a/test/test_polysections.scad +++ b/test/test_polysections.scad @@ -35,7 +35,7 @@ module test_polysections_solid_sections() { assertEqualPoints(expected_pts, points); for(i = [0:len(expected_faces) - 1]) { - assertTrue(expected_faces[i] == faces[i]); + assert(expected_faces[i] == faces[i]); } } @@ -78,7 +78,7 @@ module test_polysections_hollow_sections() { assertEqualPoints(expected_pts, points); for(i = [0:len(expected_faces) - 1]) { - assertTrue(expected_faces[i] == faces[i]); + assert(expected_faces[i] == faces[i]); } } diff --git a/test/test_rounded_cube.scad b/test/test_rounded_cube.scad index 4ae311df..9500da78 100644 --- a/test/test_rounded_cube.scad +++ b/test/test_rounded_cube.scad @@ -11,7 +11,7 @@ module test_rounded_cube_size_corner() { module test_rounded_edge_corner_center(corner_frags, corners, center_pts) { half_size = size / 2; - assertTrue(corner_frags % 4 == 0); + assert(corner_frags % 4 == 0); expected_corners = [[5.0961, 5.0961, 5.0961], [-5.0961, 5.0961, 5.0961], [5.0961, -5.0961, 5.0961], [-5.0961, -5.0961, 5.0961], [5.0961, 5.0961, -5.0961], [-5.0961, 5.0961, -5.0961], [5.0961, -5.0961, -5.0961], [-5.0961, -5.0961, -5.0961]]; @@ -36,7 +36,7 @@ module test_rounded_cube_size_center() { module test_rounded_edge_corner_center(corner_frags, corners, center_pts) { - assertTrue(corner_frags % 4 == 0); + assert(corner_frags % 4 == 0); expected_corners = [[20.0961, 7.5961, 2.5961], [-20.0961, 7.5961, 2.5961], [20.0961, -7.5961, 2.5961], [-20.0961, -7.5961, 2.5961], [20.0961, 7.5961, -2.5961], [-20.0961, 7.5961, -2.5961], [20.0961, -7.5961, -2.5961], [-20.0961, -7.5961, -2.5961]]; @@ -63,7 +63,7 @@ module test_rounded_cube_size_center_fn() { module test_rounded_edge_corner_center(corner_frags, corners, center_pts) { - assertTrue(corner_frags == $fn); + assert(corner_frags == $fn); expected_corners = [[20.3806, 7.8806, 2.8806], [-20.3806, 7.8806, 2.8806], [20.3806, -7.8806, 2.8806], [-20.3806, -7.8806, 2.8806], [20.3806, 7.8806, -2.8806], [-20.3806, 7.8806, -2.8806], [20.3806, -7.8806, -2.8806], [-20.3806, -7.8806, -2.8806]];