From 0ab91ad8ca1d5c5326c12d6a25117232c9cdee6b Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Thu, 25 May 2017 14:05:19 +0800 Subject: [PATCH] refactored --- test/test_rounded_square.scad | 8 +++++-- test/test_shape_arc.scad | 11 ++++++---- test/test_shape_cyclicpolygon.scad | 34 ++++++++++++++++++++++++++++++ test/test_shape_ellipse.scad | 12 +++++++---- test/test_shape_pie.scad | 12 +++++++---- test/test_shape_square.scad | 12 +++++++---- test/test_shape_trapezium.scad | 19 ++++++++++------- 7 files changed, 82 insertions(+), 26 deletions(-) create mode 100644 test/test_shape_cyclicpolygon.scad diff --git a/test/test_rounded_square.scad b/test/test_rounded_square.scad index 6dba90e1..ef804a63 100644 --- a/test/test_rounded_square.scad +++ b/test/test_rounded_square.scad @@ -1,8 +1,8 @@ include ; -echo("==== test_rounded_square ===="); - module test_rounded_square_size_corner() { + echo("==== test_rounded_square_size_corner ===="); + include ; module test_rounded_square(position, points) { @@ -17,6 +17,8 @@ module test_rounded_square_size_corner() { } module test_rounded_square_size_corner_center() { + echo("==== test_rounded_square_size_corner_center ===="); + include ; module test_rounded_square(position, points) { @@ -35,6 +37,8 @@ module test_rounded_square_size_corner_center() { } module test_rounded_square_size_corner_center_fn() { + echo("==== test_rounded_square_size_corner_center_fn ===="); + include ; module test_rounded_square(position, points) { diff --git a/test/test_shape_arc.scad b/test/test_shape_arc.scad index eb781c67..5875c3be 100644 --- a/test/test_shape_arc.scad +++ b/test/test_shape_arc.scad @@ -1,11 +1,14 @@ include ; include ; -echo("==== test_shape_arc ===="); +module test_shape_arc() { + echo("==== test_shape_arc ===="); -expected = [[0, -12.4315], [1.30661, -12.4315], [3.86271, -11.8882], [6.25, -10.8253], [8.36413, -9.28931], [10.1127, -7.34732], [11.4193, -5.08421], [12.2268, -2.5989], [12.5, 0], [12.2268, 2.5989], [11.4193, 5.08421], [10.1127, 7.34732], [8.36413, 9.28931], [6.25, 10.8253], [3.86271, 11.8882], [1.30661, 12.4315], [0, 12.4315], [0, 7.45891], [0.783963, 7.45891], [2.31763, 7.13292], [3.75, 6.49519], [5.01848, 5.57359], [6.06763, 4.40839], [6.85159, 3.05052], [7.33611, 1.55934], [7.5, 0], [7.33611, -1.55934], [6.85159, -3.05052], [6.06763, -4.40839], [5.01848, -5.57359], [3.75, -6.49519], [2.31763, -7.13292], [0.783963, -7.45891], [0, -7.45891]]; + expected = [[0, -12.4315], [1.30661, -12.4315], [3.86271, -11.8882], [6.25, -10.8253], [8.36413, -9.28931], [10.1127, -7.34732], [11.4193, -5.08421], [12.2268, -2.5989], [12.5, 0], [12.2268, 2.5989], [11.4193, 5.08421], [10.1127, 7.34732], [8.36413, 9.28931], [6.25, 10.8253], [3.86271, 11.8882], [1.30661, 12.4315], [0, 12.4315], [0, 7.45891], [0.783963, 7.45891], [2.31763, 7.13292], [3.75, 6.49519], [5.01848, 5.57359], [6.06763, 4.40839], [6.85159, 3.05052], [7.33611, 1.55934], [7.5, 0], [7.33611, -1.55934], [6.85159, -3.05052], [6.06763, -4.40839], [5.01848, -5.57359], [3.75, -6.49519], [2.31763, -7.13292], [0.783963, -7.45891], [0, -7.45891]]; -actual = shape_arc(radius = 10, angle = [-90, 90], width = 5); + actual = shape_arc(radius = 10, angle = [-90, 90], width = 5); -assertEqualPoints(expected, actual); + assertEqualPoints(expected, actual); +} +test_shape_arc(); \ No newline at end of file diff --git a/test/test_shape_cyclicpolygon.scad b/test/test_shape_cyclicpolygon.scad new file mode 100644 index 00000000..651d2992 --- /dev/null +++ b/test/test_shape_cyclicpolygon.scad @@ -0,0 +1,34 @@ +include ; +include ; + +module test_shape_cyclicpolygon() { + echo("==== test_shape_cyclicpolygon ===="); + + expected_all = [ + [[5.5, -2.59808], [6.12132, -2.12132], [6.59808, -1.5], [6.89778, -0.776457], [7, 0], [6.89778, 0.776457], [6.59808, 1.5], [6.12132, 2.12132], [5.5, 2.59808], [-0.5, 6.06218], [-1.22354, 6.36188], [-2, 6.4641], [-2.77646, 6.36188], [-3.5, 6.06218], [-4.12132, 5.58542], [-4.59808, 4.9641], [-4.89778, 4.24056], [-5, 3.4641], [-5, -3.4641], [-4.89778, -4.24056], [-4.59808, -4.9641], [-4.12132, -5.58542], [-3.5, -6.06218], [-2.77646, -6.36188], [-2, -6.4641], [-1.22354, -6.36188], [-0.5, -6.06218]], + + [[7.87868, -2.12132], [8.35544, -1.5], [8.65514, -0.776457], [8.75736, 0], [8.65514, 0.776457], [8.35544, 1.5], [7.87868, 2.12132], [2.12132, 7.87868], [1.5, 8.35544], [0.776457, 8.65514], [0, 8.75736], [-0.776457, 8.65514], [-1.5, 8.35544], [-2.12132, 7.87868], [-7.87868, 2.12132], [-8.35544, 1.5], [-8.65514, 0.776457], [-8.75736, 0], [-8.65514, -0.776457], [-8.35544, -1.5], [-7.87868, -2.12132], [-2.12132, -7.87868], [-1.5, -8.35544], [-0.776457, -8.65514], [0, -8.75736], [0.776457, -8.65514], [1.5, -8.35544], [2.12132, -7.87868]], + + [[8.71885, -1.76336], [9.09254, -1.0751], [9.27536, -0.313585], [9.25486, 0.469303], [9.03243, 1.22021], [8.71885, 1.76336], [4.37132, 7.74721], [3.83223, 8.31529], [3.16448, 8.72449], [2.41358, 8.94692], [1.63069, 8.96742], [1.01722, 8.83702], [-6.01722, 6.55139], [-6.72409, 6.21424], [-7.3196, 5.70562], [-7.76319, 5.0602], [-8.02461, 4.32196], [-8.09017, 3.69822], [-8.09017, -3.69822], [-7.98795, -4.47468], [-7.68825, -5.19822], [-7.21149, -5.81955], [-6.59017, -6.2963], [-6.01722, -6.55139], [1.01722, -8.83702], [1.78726, -8.97974], [2.56801, -8.9183], [3.30624, -8.65687], [3.95166, -8.21329], [4.37132, -7.74721]], + + [[9.13397, -1.5], [9.43368, -0.776457], [9.5359, 0], [9.43368, 0.776457], [9.13397, 1.5], [5.86603, 7.16025], [5.38927, 7.78157], [4.76795, 8.25833], [4.04441, 8.55803], [3.26795, 8.66025], [-3.26795, 8.66025], [-4.04441, 8.55803], [-4.76795, 8.25833], [-5.38927, 7.78157], [-5.86603, 7.16025], [-9.13397, 1.5], [-9.43368, 0.776457], [-9.5359, 0], [-9.43368, -0.776457], [-9.13397, -1.5], [-5.86603, -7.16025], [-5.38927, -7.78157], [-4.76795, -8.25833], [-4.04441, -8.55803], [-3.26795, -8.66025], [3.26795, -8.66025], [4.04441, -8.55803], [4.76795, -8.25833], [5.38927, -7.78157], [5.86603, -7.16025]] + ]; + + circle_r = 10; + corner_r = 3; + + $fn = 24; + + for(i = [0:3]) { + actual = shape_cyclicpolygon( + sides = 3 + i, + circle_r = circle_r, + corner_r = corner_r + ); + + assertEqualPoints(expected_all[i], actual); + } +} + +test_shape_cyclicpolygon(); + diff --git a/test/test_shape_ellipse.scad b/test/test_shape_ellipse.scad index f248ace3..9878aa9f 100644 --- a/test/test_shape_ellipse.scad +++ b/test/test_shape_ellipse.scad @@ -1,10 +1,14 @@ include ; include ; -echo("==== test_shape_ellipse ===="); +module test_shape_ellipse() { + echo("==== test_shape_ellipse ===="); -expected = [[40, 0], [39.1259, 4.15823], [36.5418, 8.13473], [32.3607, 11.7557], [26.7652, 14.8629], [20, 17.3205], [12.3607, 19.0211], [4.18114, 19.8904], [-4.18114, 19.8904], [-12.3607, 19.0211], [-20, 17.3205], [-26.7652, 14.8629], [-32.3607, 11.7557], [-36.5418, 8.13473], [-39.1259, 4.15823], [-40, 0], [-39.1259, -4.15823], [-36.5418, -8.13473], [-32.3607, -11.7557], [-26.7652, -14.8629], [-20, -17.3205], [-12.3607, -19.0211], [-4.18114, -19.8904], [4.18114, -19.8904], [12.3607, -19.0211], [20, -17.3205], [26.7652, -14.8629], [32.3607, -11.7557], [36.5418, -8.13473], [39.1259, -4.15823]]; + expected = [[40, 0], [39.1259, 4.15823], [36.5418, 8.13473], [32.3607, 11.7557], [26.7652, 14.8629], [20, 17.3205], [12.3607, 19.0211], [4.18114, 19.8904], [-4.18114, 19.8904], [-12.3607, 19.0211], [-20, 17.3205], [-26.7652, 14.8629], [-32.3607, 11.7557], [-36.5418, 8.13473], [-39.1259, 4.15823], [-40, 0], [-39.1259, -4.15823], [-36.5418, -8.13473], [-32.3607, -11.7557], [-26.7652, -14.8629], [-20, -17.3205], [-12.3607, -19.0211], [-4.18114, -19.8904], [4.18114, -19.8904], [12.3607, -19.0211], [20, -17.3205], [26.7652, -14.8629], [32.3607, -11.7557], [36.5418, -8.13473], [39.1259, -4.15823]]; -actual = shape_ellipse([40, 20]); + actual = shape_ellipse([40, 20]); -assertEqualPoints(expected, actual); \ No newline at end of file + assertEqualPoints(expected, actual); +} + +test_shape_ellipse(); \ No newline at end of file diff --git a/test/test_shape_pie.scad b/test/test_shape_pie.scad index eae1f8ed..5bb9a3d7 100644 --- a/test/test_shape_pie.scad +++ b/test/test_shape_pie.scad @@ -1,10 +1,14 @@ include ; include ; -echo("==== test_shape_pie ===="); +module test_shape_pie() { + echo("==== test_shape_pie ===="); -expected = [[0, 0], [7.07107, 7.07107], [5, 8.66025], [2.58819, 9.65926], [0, 10], [-2.58819, 9.65926], [-5, 8.66025], [-7.07107, 7.07107], [-8.66025, 5], [-9.65926, 2.58819], [-10, 0], [-9.65926, -2.58819], [-8.66025, -5], [-7.07107, -7.07107], [-5, -8.66025], [-2.58819, -9.65926], [0, -10], [2.58819, -9.65926], [5, -8.66025], [7.07107, -7.07107]]; + expected = [[0, 0], [7.07107, 7.07107], [5, 8.66025], [2.58819, 9.65926], [0, 10], [-2.58819, 9.65926], [-5, 8.66025], [-7.07107, 7.07107], [-8.66025, 5], [-9.65926, 2.58819], [-10, 0], [-9.65926, -2.58819], [-8.66025, -5], [-7.07107, -7.07107], [-5, -8.66025], [-2.58819, -9.65926], [0, -10], [2.58819, -9.65926], [5, -8.66025], [7.07107, -7.07107]]; -actual = shape_pie(10, [45, 315], $fn = 24); + actual = shape_pie(10, [45, 315], $fn = 24); -assertEqualPoints(expected, actual); \ No newline at end of file + assertEqualPoints(expected, actual); +} + +test_shape_pie(); \ No newline at end of file diff --git a/test/test_shape_square.scad b/test/test_shape_square.scad index 5f54ddfc..448b1261 100644 --- a/test/test_shape_square.scad +++ b/test/test_shape_square.scad @@ -1,10 +1,14 @@ include ; include ; -echo("==== test_shape_square ===="); +module test_shape_square() { + echo("==== test_shape_square ===="); -expected = [[20, -25], [21.9471, -24.6053], [23.5868, -23.4835], [24.6602, -21.8118], [25, -20], [25, 20], [24.6053, 21.9471], [23.4835, 23.5868], [21.8118, 24.6602], [20, 25], [-20, 25], [-21.8118, 24.6602], [-23.4835, 23.5868], [-24.6053, 21.9471], [-25, 20], [-25, -20], [-24.6602, -21.8118], [-23.5868, -23.4835], [-21.9471, -24.6053], [-20, -25]]; + expected = [[20, -25], [21.9471, -24.6053], [23.5868, -23.4835], [24.6602, -21.8118], [25, -20], [25, 20], [24.6053, 21.9471], [23.4835, 23.5868], [21.8118, 24.6602], [20, 25], [-20, 25], [-21.8118, 24.6602], [-23.4835, 23.5868], [-24.6053, 21.9471], [-25, 20], [-25, -20], [-24.6602, -21.8118], [-23.5868, -23.4835], [-21.9471, -24.6053], [-20, -25]]; -actual = shape_square(size = 50, corner_r = 5); + actual = shape_square(size = 50, corner_r = 5); -assertEqualPoints(expected, actual); \ No newline at end of file + assertEqualPoints(expected, actual); +} + +test_shape_square(); \ No newline at end of file diff --git a/test/test_shape_trapezium.scad b/test/test_shape_trapezium.scad index 25d3f792..ad655bb7 100644 --- a/test/test_shape_trapezium.scad +++ b/test/test_shape_trapezium.scad @@ -1,15 +1,18 @@ include ; include ; -echo("==== test_shape_trapezium ===="); +module test_shape_trapezium() { + echo("==== test_shape_trapezium ===="); -expected = [[16.7639, -10], [18.4469, -9.0806], [18.5825, -7.1677], [18.5528, -7.10557], [10.5528, 8.89443], [8.97782, 9.98853], [8.76393, 10], [-8.76393, 10], [-8.97782, 9.98853], [-10.5528, 8.89443], [-18.5528, -7.10557], [-18.5825, -7.1677], [-18.4469, -9.0806], [-16.7639, -10]]; + expected = [[16.7639, -10], [18.4469, -9.0806], [18.5825, -7.1677], [18.5528, -7.10557], [10.5528, 8.89443], [8.97782, 9.98853], [8.76393, 10], [-8.76393, 10], [-8.97782, 9.98853], [-10.5528, 8.89443], [-18.5528, -7.10557], [-18.5825, -7.1677], [-18.4469, -9.0806], [-16.7639, -10]]; -actual = shape_trapezium( - [40, 20], - h = 20, - corner_r = 2 -); + actual = shape_trapezium( + [40, 20], + h = 20, + corner_r = 2 + ); -assertEqualPoints(expected, actual); + assertEqualPoints(expected, actual); +} +test_shape_trapezium();