Added edges.scad regression tests.

This commit is contained in:
Revar Desmera 2019-11-05 18:16:00 -08:00
parent 948e76d992
commit 029e3f612a
3 changed files with 107 additions and 3 deletions

View file

@ -38,7 +38,7 @@ function is_edge_array(v) = is_list(v) && is_vector(v[0]) && len(v)==3 && len(v[
// - A vector pointing towards a corner, indicating all edges that meet at that corner.
// - The string `"X"`, indicating all X axis aligned edges.
// - The string `"Y"`, indicating all Y axis aligned edges.
// - The string `"Z"`, indicating all Y axis aligned edges.
// - The string `"Z"`, indicating all Z axis aligned edges.
// - The string `"ALL"`, indicating all edges.
// - The string `"NONE"`, indicating no edges at all.
function edge_set(v) =
@ -99,7 +99,7 @@ function normalize_edges(v) = [for (ax=v) [for (edge=ax) edge>0? 1 : 0]];
// - A vector pointing towards a corner, indicating all edges touching that corner.
// - The string `"X"`, indicating all X axis aligned edges.
// - The string `"Y"`, indicating all Y axis aligned edges.
// - The string `"Z"`, indicating all Y axis aligned edges.
// - The string `"Z"`, indicating all Z axis aligned edges.
// - The string `"ALL"`, indicating all edges.
// - The string `"NONE"`, indicating no edges at all.
// Example: Just the front-top edge

104
tests/test_edges.scad Normal file
View file

@ -0,0 +1,104 @@
include <BOSL2/std.scad>
module test_is_edge_array() {
assert(is_edge_array([[0,0,0,0],[0,0,0,0],[0,0,0,0]]));
assert(is_edge_array([[1,1,1,1],[1,1,1,1],[1,1,1,1]]));
assert(!is_edge_array([[1,1,1],[1,1,1],[1,1,1]]));
assert(!is_edge_array([[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1]]));
assert(!is_edge_array([[1,1,1,1],[1,1,1,1]]));
assert(!is_edge_array([1,1,1,1]));
assert(!is_edge_array("foo"));
assert(!is_edge_array(42));
assert(!is_edge_array(true));
assert(is_edge_array(edges(["X","Y"])));
}
test_is_edge_array();
module test_edge_set() {
// Edge set pass through
assert(edge_set([[1,1,1,1],[0,1,0,1],[0,0,0,0]]) == [[1,1,1,1],[0,1,0,1],[0,0,0,0]]);
// Vectors towards corners
assert(edge_set([-1,-1,-1]) == [[1,0,0,0],[1,0,0,0],[1,0,0,0]]);
assert(edge_set([-1,-1, 1]) == [[0,0,1,0],[0,0,1,0],[1,0,0,0]]);
assert(edge_set([-1, 1,-1]) == [[0,1,0,0],[1,0,0,0],[0,0,1,0]]);
assert(edge_set([-1, 1, 1]) == [[0,0,0,1],[0,0,1,0],[0,0,1,0]]);
assert(edge_set([ 1,-1,-1]) == [[1,0,0,0],[0,1,0,0],[0,1,0,0]]);
assert(edge_set([ 1,-1, 1]) == [[0,0,1,0],[0,0,0,1],[0,1,0,0]]);
assert(edge_set([ 1, 1,-1]) == [[0,1,0,0],[0,1,0,0],[0,0,0,1]]);
assert(edge_set([ 1, 1, 1]) == [[0,0,0,1],[0,0,0,1],[0,0,0,1]]);
// Vectors towards edges
assert(edge_set([ 0,-1,-1]) == [[1,0,0,0],[0,0,0,0],[0,0,0,0]]);
assert(edge_set([ 0, 1,-1]) == [[0,1,0,0],[0,0,0,0],[0,0,0,0]]);
assert(edge_set([ 0,-1, 1]) == [[0,0,1,0],[0,0,0,0],[0,0,0,0]]);
assert(edge_set([ 0, 1, 1]) == [[0,0,0,1],[0,0,0,0],[0,0,0,0]]);
assert(edge_set([-1, 0,-1]) == [[0,0,0,0],[1,0,0,0],[0,0,0,0]]);
assert(edge_set([ 1, 0,-1]) == [[0,0,0,0],[0,1,0,0],[0,0,0,0]]);
assert(edge_set([-1, 0, 1]) == [[0,0,0,0],[0,0,1,0],[0,0,0,0]]);
assert(edge_set([ 1, 0, 1]) == [[0,0,0,0],[0,0,0,1],[0,0,0,0]]);
assert(edge_set([-1,-1, 0]) == [[0,0,0,0],[0,0,0,0],[1,0,0,0]]);
assert(edge_set([ 1,-1, 0]) == [[0,0,0,0],[0,0,0,0],[0,1,0,0]]);
assert(edge_set([-1, 1, 0]) == [[0,0,0,0],[0,0,0,0],[0,0,1,0]]);
assert(edge_set([ 1, 1, 0]) == [[0,0,0,0],[0,0,0,0],[0,0,0,1]]);
// Vectors towards faces
assert(edge_set([ 0, 0,-1]) == [[1,1,0,0],[1,1,0,0],[0,0,0,0]]);
assert(edge_set([ 0, 0, 1]) == [[0,0,1,1],[0,0,1,1],[0,0,0,0]]);
assert(edge_set([ 0,-1, 0]) == [[1,0,1,0],[0,0,0,0],[1,1,0,0]]);
assert(edge_set([ 0, 1, 0]) == [[0,1,0,1],[0,0,0,0],[0,0,1,1]]);
assert(edge_set([-1, 0, 0]) == [[0,0,0,0],[1,0,1,0],[1,0,1,0]]);
assert(edge_set([ 1, 0, 0]) == [[0,0,0,0],[0,1,0,1],[0,1,0,1]]);
// Named edge sets
assert(edge_set("X") == [[1,1,1,1],[0,0,0,0],[0,0,0,0]]);
assert(edge_set("Y") == [[0,0,0,0],[1,1,1,1],[0,0,0,0]]);
assert(edge_set("Z") == [[0,0,0,0],[0,0,0,0],[1,1,1,1]]);
assert(edge_set("NONE") == [[0,0,0,0],[0,0,0,0],[0,0,0,0]]);
assert(edge_set("ALL") == [[1,1,1,1],[1,1,1,1],[1,1,1,1]]);
}
test_edge_set();
module test_normalize_edges() {
assert(normalize_edges([[-2,-2,-2,-2],[-2,-2,-2,-2],[-2,-2,-2,-2]]) == [[0,0,0,0],[0,0,0,0],[0,0,0,0]]);
assert(normalize_edges([[-1,-1,-1,-1],[-1,-1,-1,-1],[-1,-1,-1,-1]]) == [[0,0,0,0],[0,0,0,0],[0,0,0,0]]);
assert(normalize_edges([[0,0,0,0],[0,0,0,0],[0,0,0,0]]) == [[0,0,0,0],[0,0,0,0],[0,0,0,0]]);
assert(normalize_edges([[1,1,1,1],[1,1,1,1],[1,1,1,1]]) == [[1,1,1,1],[1,1,1,1],[1,1,1,1]]);
assert(normalize_edges([[2,2,2,2],[2,2,2,2],[2,2,2,2]]) == [[1,1,1,1],[1,1,1,1],[1,1,1,1]]);
}
test_normalize_edges();
module test_edges() {
assert(edges("X")==[[1,1,1,1],[0,0,0,0],[0,0,0,0]]);
assert(edges("Y")==[[0,0,0,0],[1,1,1,1],[0,0,0,0]]);
assert(edges("Z")==[[0,0,0,0],[0,0,0,0],[1,1,1,1]]);
assert(edges(["X"])==[[1,1,1,1],[0,0,0,0],[0,0,0,0]]);
assert(edges(["Y"])==[[0,0,0,0],[1,1,1,1],[0,0,0,0]]);
assert(edges(["Z"])==[[0,0,0,0],[0,0,0,0],[1,1,1,1]]);
assert(edges(["X","Y"])==[[1,1,1,1],[1,1,1,1],[0,0,0,0]]);
assert(edges(["X","Z"])==[[1,1,1,1],[0,0,0,0],[1,1,1,1]]);
assert(edges(["Y","Z"])==[[0,0,0,0],[1,1,1,1],[1,1,1,1]]);
assert(edges("ALL",except="X")==[[0,0,0,0],[1,1,1,1],[1,1,1,1]]);
assert(edges("ALL",except="Y")==[[1,1,1,1],[0,0,0,0],[1,1,1,1]]);
assert(edges("ALL",except="Z")==[[1,1,1,1],[1,1,1,1],[0,0,0,0]]);
assert(edges(["Y","Z"],except=[FRONT+RIGHT,FRONT+LEFT])==[[0,0,0,0],[1,1,1,1],[0,0,1,1]]);
}
test_edges();
module test_corner_edge_count() {
edges = edges([TOP,FRONT+RIGHT]);
assert(corner_edge_count(edges,TOP+FRONT+RIGHT) == 3);
assert(corner_edge_count(edges,TOP+FRONT+LEFT) == 2);
assert(corner_edge_count(edges,BOTTOM+FRONT+RIGHT) == 1);
assert(corner_edge_count(edges,BOTTOM+FRONT+LEFT) == 0);
}
test_corner_edge_count();
// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap

View file

@ -8,7 +8,7 @@
//////////////////////////////////////////////////////////////////////
BOSL_VERSION = [2,0,5];
BOSL_VERSION = [2,0,6];
// Section: BOSL Library Version Functions