-
Notifications
You must be signed in to change notification settings - Fork 2
/
pegboard_tests.scad
199 lines (165 loc) · 5.74 KB
/
pegboard_tests.scad
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
use <pegboard.scad>
module test_case(test_number, test_name, xoff, yoff)
{
echo(str("--> test ", test_number, ": ", test_name));
translate([xoff, yoff, 0])
let($test = test_number, $test_name = test_name)
children();
echo(str("<-- test ", test_number, ": ", test_name));
}
module assert_expect(varname, actual, expected)
{
assert(expected == actual, str(varname, ": expected ", expected, ", got ", actual));
}
// Hint: use F12 "thrown together" view for tests
module pegboard_test()
{
// Coarse draft for tests; we don't need quality and we're going
// to have a LOT of holes.
$fn = 10;
// Make sure we have proper is_undef support
assert(is_undef($undefined));
//=== BASIC FORMS ===
test_case(1, "default margin, hexpattern", 0, 0)
{
pegboard([20, 20, 3], 1, 2, hexpattern=true)
{
assert_expect("$test", $test, 1); // Can see $test
assert($strip_ncols != undef); // Can see $strip_ncols
assert_expect("$strip_ncols", $strip_ncols, 10);
assert_expect("$strip_nrows", $strip_nrows, 11);
}
};
test_case(1, "scalar margin, hexpattern", 25, 0)
{
pegboard([20, 20, 3], 1, 2, hexpattern=true, margins=4) {
assert_expect("$strip_ncols", $strip_ncols, 6);
assert_expect("$strip_nrows", $strip_nrows, 7);
}
}
test_case(1, "vector margin, hexpattern", 50, 0) {
pegboard([20, 20, 3], 1, 2, true, [2, 4]) {
assert_expect("$strip_ncols", $strip_ncols, 8);
assert_expect("$strip_nrows", $strip_nrows, 7);
}
}
test_case(2, "default margin, grid", 0, 25) {
pegboard([20, 20, 3], 1, 2, false) {
assert_expect("$strip_ncols", $strip_ncols, 10);
assert_expect("$strip_nrows", $strip_nrows, 10);
}
}
test_case(3, "scalar margin, grid", 25, 25) {
pegboard([20, 20, 3], 1, 2, false, 4) {
assert_expect("$strip_ncols", $strip_ncols, 6);
assert_expect("$strip_nrows", $strip_nrows, 6);
}
}
test_case(4, "vector margin, grid", 50, 25) {
pegboard([20, 20, 3], 1, 2, false, [2, 4])
{
assert_expect("$strip_ncols", $strip_ncols, 8);
assert_expect("$strip_nrows", $strip_nrows, 6);
}
}
// === SMALL FORMS ===
// Should produce 1 row, 1 col, as diameter is 1, margin total is 1,
// height is 2
test_case(5, "small 1x1", 0, 50) {
pegboard([2, 2, 3], 1, 2, false, 0.5) {
assert_expect("$strip_ncols", $strip_ncols, 1);
assert_expect("$strip_nrows", $strip_nrows, 1);
}
}
// With 1 hole, hexpattern doesn't matter so same result
test_case(6, "small 1x1", 10, 50) {
pegboard([2, 2, 3], 1, 2, true, 0.5) {
assert_expect("$strip_ncols", $strip_ncols, 1);
assert_expect("$strip_nrows", $strip_nrows, 1);
}
}
// This should have 4 holes
test_case(7, "small 2x2", 20, 50) {
pegboard([4, 4, 3], 1, 2, false, 0.5) {
assert_expect("$strip_ncols", $strip_ncols, 2);
assert_expect("$strip_nrows", $strip_nrows, 2);
};
}
// This should produce 3 holes. The bottom row isn't
// affected by hexpattern.
test_case(8, "small 3 holes triangle arrangement", 30, 50) {
pegboard([4, 4, 3], 1, 2, true, 0.5) {
assert_expect("$strip_ncols", $strip_ncols, 2);
assert_expect("$strip_nrows", $strip_nrows, 2);
};
}
// === Shallow holes ====
// Holes in this one only go half way through
test_case(9, "shallow", 40, 50) {
pegboard([2, 2, 3], 1, 2, false, 0.5, 1.5);
}
// Centered vs uncentered. Uncentered should have holes
// cutting through edges. Also tests negative margins.
test_case(10, "centered", 0, 60) {
pegboard([8,8,5], 2, 4, false, 0, center=true);
}
test_case(11, "uncentered", 10, 60) {
pegboard([8,8,5], 2, 4, false, 0, center=false);
}
// Negative margins: Holes will cut through edges
// to form semicircular cutouts + one hole in center.
test_case(12, "negative margin, holes intersect edges", 20, 60) {
pegboard([8,8,5], 2, 4, false, -2);
}
// === TIGHT PACKING ===
// No hexpattern. Holes should touch, bridge ~= 0
test_case(13, "pitch=diam, grid, holes touch each other", 30, 60) {
pegboard([7, 7, 3], 2, 2, false, 0.5) {
assert_expect("$strip_ncols", $strip_ncols, 3);
assert_expect("$strip_nrows", $strip_nrows, 3);
}
}
// With hexpattern the holes should touch too, but not
// overlap.
test_case(14, "pitch=diam, hex, holes touch each other", 40, 60) {
pegboard([7, 7, 3], 2, 2, true, 0.5) {
assert_expect("$strip_ncols", $strip_ncols, 3);
assert_expect("$strip_nrows", $strip_nrows, 3);
}
}
// Hole bigger than object will force 1 hole
// which will cut out edges
test_case(15, "hole bigger than object, 1 hole cuts out edges", 50, 60) {
pegboard([7, 7, 3], 8, 1, true, 0.5) {
assert_expect("$strip_ncols", $strip_ncols, 1);
assert_expect("$strip_nrows", $strip_nrows, 1);
}
}
// Holes bigger than pitch will overlap holes.
test_case(16, "hole bigger than pitch, holes overlap each other", 60, 60) {
pegboard([20, 7, 3], 6, 5, true, 0.5);
}
// === LONG THIN FORMS ===
test_case(17, "2x30 hex/stagger", 0, 70) {
pegboard([60, 4, 3], 1, 2, true, 0.5) {
assert_expect("$strip_ncols", $strip_ncols, 30);
assert_expect("$strip_nrows", $strip_nrows, 2);
}
}
test_case(18, "2x30 grid", 0, 75) {
pegboard([60, 4, 3], 1, 2, false, 0.5) {
assert_expect("$strip_ncols", $strip_ncols, 30);
assert_expect("$strip_nrows", $strip_nrows, 2);
}
}
// === NEGATIVES ===
// Pegs shouldn't be longer than needed when making
// negative forms.
test_case(19, "negative form pegs", 0, 80) {
peg_grid([60, 4, 3], 1, 2, true, 0.5) {
assert_expect("$strip_ncols", $strip_ncols, 30);
assert_expect("$strip_nrows", $strip_nrows, 2);
}
}
}
pegboard_test();