mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 16:29:40 +00:00
test reorganization
This commit is contained in:
parent
5d0b42b667
commit
32d9a96bc4
5 changed files with 123 additions and 67 deletions
51
tests/test_drawing.scad
Normal file
51
tests/test_drawing.scad
Normal file
|
@ -0,0 +1,51 @@
|
|||
include <../std.scad>
|
||||
|
||||
module test_turtle() {
|
||||
assert_approx(
|
||||
turtle([
|
||||
"move", 10,
|
||||
"ymove", 5,
|
||||
"xmove", 5,
|
||||
"xymove", [10,15],
|
||||
"left", 135,
|
||||
"untilx", 0,
|
||||
"turn", 90,
|
||||
"untily", 0,
|
||||
"right", 135,
|
||||
"arcsteps", 5,
|
||||
"arcright", 15, 30,
|
||||
"arcleft", 15, 30,
|
||||
"arcsteps", 0,
|
||||
"arcrightto", 15, 90,
|
||||
"arcleftto", 15, 180,
|
||||
"jump", [10,10],
|
||||
"xjump", 15,
|
||||
"yjump", 15,
|
||||
"angle", 30,
|
||||
"length", 15,
|
||||
"right",
|
||||
"move",
|
||||
"scale", 2,
|
||||
"left",
|
||||
"move",
|
||||
"addlength", 5,
|
||||
"repeat", 3, ["move"],
|
||||
], $fn=24),
|
||||
[[0,0],[10,0],[10,5],[15,5],[25,20],[-3.5527136788e-15,45],[-45,0],[-44.8716729206,1.9578928833],[-44.4888873943,3.88228567654],[-43.8581929877,5.74025148548],[-42.9903810568,7.5],[-42.1225691259,9.25974851452],[-41.4918747192,11.1177143235],[-41.1090891929,13.0421071167],[-40.9807621135,15],[-41.0157305757,16.0236362005],[-41.120472923,17.0424997364],[-41.2945007983,18.0518401958],[-41.5370028033,19.0469515674],[-41.8468482818,20.0231941826],[-42.222592591,20.9760163477],[-42.6624838375,21.900975566],[-43.1644710453,22.7937592505],[-43.7262137184,23.6502048317],[-44.345092753,24.4663191649],[-45.0182226494,25.2382971483],[-45.7424649653,25.9625394642],[-46.5144429486,26.6356693606],[-47.3305572818,27.2545483952],[-48.187002863,27.8162910682],[-49.0797865476,28.318278276],[-50.0047457658,28.7581695226],[-50.957567931,29.1339138318],[-51.9338105462,29.4437593102],[-52.9289219177,29.6862613152],[-53.9382623771,29.8602891905],[-54.9571259131,29.9650315379],[-55.9807621135,30],[10,10],[15,10],[15,15],[2.00961894323,22.5],[-27.9903810568,22.5],[-62.9903810568,22.5],[-97.9903810568,22.5],[-132.990381057,22.5]]
|
||||
);
|
||||
}
|
||||
test_turtle();
|
||||
|
||||
|
||||
module test_arc() {
|
||||
assert_approx(arc(N=8, d=100, angle=135, cp=[10,10]), [[60,10],[57.1941665154,26.5139530978],[49.0915741234,41.1744900929],[36.6016038258,52.3362099614],[21.1260466978,58.7463956091],[4.40177619483,59.6856104947],[-11.6941869559,55.0484433951],[-25.3553390593,45.3553390593]]);
|
||||
assert_approx(arc(N=8, d=100, angle=135, cp=[10,10],endpoint=false), [[60,10],[57.8470167866,24.5142338627],[51.5734806151,37.778511651],[41.7196642082,48.6505226681],[29.1341716183,56.1939766256],[14.9008570165,59.7592363336],[0.245483899194,59.0392640202],[-13.5698368413,54.0960632174]]);
|
||||
assert_approx(arc(N=8, d=100, angle=[45,225], cp=[10,10]), [[45.3553390593,45.3553390593],[26.5139530978,57.1941665154],[4.40177619483,59.6856104947],[-16.6016038258,52.3362099614],[-32.3362099614,36.6016038258],[-39.6856104947,15.5982238052],[-37.1941665154,-6.51395309776],[-25.3553390593,-25.3553390593]]);
|
||||
assert_approx(arc(N=8, d=100, start=45, angle=135, cp=[10,10]), [[45.3553390593,45.3553390593],[31.6941869559,55.0484433951],[15.5982238052,59.6856104947],[-1.12604669782,58.7463956091],[-16.6016038258,52.3362099614],[-29.0915741234,41.1744900929],[-37.1941665154,26.5139530978],[-40,10]]);
|
||||
assert_approx(arc(N=8, d=100, start=45, angle=-90, cp=[10,10]), [[45.3553390593,45.3553390593],[52.3362099614,36.6016038258],[57.1941665154,26.5139530978],[59.6856104947,15.5982238052],[59.6856104947,4.40177619483],[57.1941665154,-6.51395309776],[52.3362099614,-16.6016038258],[45.3553390593,-25.3553390593]]);
|
||||
assert_approx(arc(N=8, width=100, thickness=30), [[50,-3.5527136788e-15],[39.5300788555,13.9348601124],[25.3202618476,24.0284558904],[8.71492362453,29.3258437015],[-8.71492362453,29.3258437015],[-25.3202618476,24.0284558904],[-39.5300788555,13.9348601124],[-50,-1.42108547152e-14]]);
|
||||
assert_approx(arc(N=8, cp=[10,10], points=[[45,45],[-25,45]]), [[45,45],[36.3342442379,51.9107096148],[26.3479795075,56.7198412457],[15.5419588213,59.1862449514],[4.45804117867,59.1862449514],[-6.34797950747,56.7198412457],[-16.3342442379,51.9107096148],[-25,45]]);
|
||||
assert_approx(arc(N=24, cp=[10,10], points=[[45,45],[-25,45]], long=true), [[45,45],[51.3889035257,37.146982612],[56.0464336973,28.1583574081],[58.7777575294,18.4101349813],[59.4686187624,8.31010126292],[58.0901174104,-1.71924090789],[54.6999187001,-11.2583458482],[49.4398408296,-19.9081753929],[42.5299224539,-27.3068913894],[34.2592180667,-33.1449920477],[24.9737063235,-37.1782589647],[15.0618171232,-39.2379732261],[4.93818287676,-39.2379732261],[-4.97370632349,-37.1782589647],[-14.2592180667,-33.1449920477],[-22.5299224539,-27.3068913894],[-29.4398408296,-19.9081753929],[-34.6999187001,-11.2583458482],[-38.0901174104,-1.71924090789],[-39.4686187624,8.31010126292],[-38.7777575294,18.4101349813],[-36.0464336973,28.1583574081],[-31.3889035257,37.146982612],[-25,45]]);
|
||||
assert_approx(arc($fn=24, cp=[10,10], points=[[45,45],[-25,45]], long=true), [[45,45],[53.2421021636,34.0856928585],[58.1827254512,21.3324740498],[59.4446596304,7.71403542491],[56.9315576496,-5.72987274525],[50.8352916125,-17.9728253654],[41.6213035891,-28.0800887515],[29.9930697126,-35.2799863457],[16.8383906815,-39.0228152281],[3.16160931847,-39.0228152281],[-9.9930697126,-35.2799863457],[-21.6213035891,-28.0800887515],[-30.8352916125,-17.9728253654],[-36.9315576496,-5.72987274525],[-39.4446596304,7.71403542491],[-38.1827254512,21.3324740498],[-33.2421021636,34.0856928585],[-25,45]]);
|
||||
}
|
||||
test_arc();
|
|
@ -12,7 +12,7 @@ test_point_line_distance();
|
|||
test_segment_distance();
|
||||
test_line_normal();
|
||||
test_line_intersection();
|
||||
//test_line_ray_intersection(); // should add this typ eof case
|
||||
//test_line_ray_intersection(); // should add this type of case
|
||||
//test_ray_intersection(); // should add this type of case
|
||||
//test_ray_segment_intersection(); // should add this type of case
|
||||
test_line_closest_point();
|
||||
|
@ -56,13 +56,6 @@ test_reverse_polygon();
|
|||
test_polygon_normal();
|
||||
|
||||
//tests to migrate to other files
|
||||
test_is_path();
|
||||
test_is_closed_path();
|
||||
test_close_path();
|
||||
test_cleanup_path();
|
||||
test_simplify_path();
|
||||
test_simplify_path_indexed();
|
||||
test_is_region();
|
||||
test_convex_distance();
|
||||
test_convex_collision();
|
||||
|
||||
|
@ -751,40 +744,6 @@ module test_is_above_plane() {
|
|||
*test_is_above_plane();
|
||||
|
||||
|
||||
module test_is_path() {
|
||||
assert(is_path([[1,2,3],[4,5,6]]));
|
||||
assert(is_path([[1,2,3],[4,5,6],[7,8,9]]));
|
||||
assert(!is_path(123));
|
||||
assert(!is_path("foo"));
|
||||
assert(!is_path(true));
|
||||
assert(!is_path([]));
|
||||
assert(!is_path([[]]));
|
||||
assert(!is_path([["foo","bar","baz"]]));
|
||||
assert(!is_path([[1,2,3]]));
|
||||
assert(!is_path([["foo","bar","baz"],["qux","quux","quuux"]]));
|
||||
}
|
||||
*test_is_path();
|
||||
|
||||
|
||||
module test_is_closed_path() {
|
||||
assert(!is_closed_path([[1,2,3],[4,5,6],[1,8,9]]));
|
||||
assert(is_closed_path([[1,2,3],[4,5,6],[1,8,9],[1,2,3]]));
|
||||
}
|
||||
*test_is_closed_path();
|
||||
|
||||
|
||||
module test_close_path() {
|
||||
assert(close_path([[1,2,3],[4,5,6],[1,8,9]]) == [[1,2,3],[4,5,6],[1,8,9],[1,2,3]]);
|
||||
assert(close_path([[1,2,3],[4,5,6],[1,8,9],[1,2,3]]) == [[1,2,3],[4,5,6],[1,8,9],[1,2,3]]);
|
||||
}
|
||||
*test_close_path();
|
||||
|
||||
|
||||
module test_cleanup_path() {
|
||||
assert(cleanup_path([[1,2,3],[4,5,6],[1,8,9]]) == [[1,2,3],[4,5,6],[1,8,9]]);
|
||||
assert(cleanup_path([[1,2,3],[4,5,6],[1,8,9],[1,2,3]]) == [[1,2,3],[4,5,6],[1,8,9]]);
|
||||
}
|
||||
*test_cleanup_path();
|
||||
|
||||
|
||||
module test_polygon_area() {
|
||||
|
@ -869,19 +828,6 @@ module test_centroid() {
|
|||
*test_centroid();
|
||||
|
||||
|
||||
module test_simplify_path() {
|
||||
path = [[-20,-20], [-10,-20], [0,-10], [10,0], [20,10], [20,20], [15,30]];
|
||||
assert(simplify_path(path) == [[-20,-20], [-10,-20], [20,10], [20,20], [15,30]]);
|
||||
}
|
||||
*test_simplify_path();
|
||||
|
||||
|
||||
module test_simplify_path_indexed() {
|
||||
pts = [[10,0], [0,-10], [20,20], [20,10], [-20,-20], [15,30], [-10,-20]];
|
||||
path = [4,6,1,0,3,2,5];
|
||||
assert(simplify_path_indexed(pts, path) == [4,6,3,2,5]);
|
||||
}
|
||||
*test_simplify_path_indexed();
|
||||
|
||||
|
||||
module test_point_in_polygon() {
|
||||
|
@ -946,17 +892,6 @@ module test_reverse_polygon() {
|
|||
*test_reverse_polygon();
|
||||
|
||||
|
||||
module test_is_region() {
|
||||
assert(is_region([circle(d=10),square(10)]));
|
||||
assert(is_region([circle(d=10),square(10),circle(d=50)]));
|
||||
assert(is_region([square(10)]));
|
||||
assert(!is_region([]));
|
||||
assert(!is_region(23));
|
||||
assert(!is_region(true));
|
||||
assert(!is_region("foo"));
|
||||
}
|
||||
*test_is_region();
|
||||
|
||||
module test_convex_distance() {
|
||||
// 2D
|
||||
c1 = circle(10,$fn=24);
|
||||
|
|
51
tests/test_paths.scad
Normal file
51
tests/test_paths.scad
Normal file
|
@ -0,0 +1,51 @@
|
|||
include<../std.scad>
|
||||
|
||||
module test_is_path() {
|
||||
assert(is_path([[1,2,3],[4,5,6]]));
|
||||
assert(is_path([[1,2,3],[4,5,6],[7,8,9]]));
|
||||
assert(!is_path(123));
|
||||
assert(!is_path("foo"));
|
||||
assert(!is_path(true));
|
||||
assert(!is_path([]));
|
||||
assert(!is_path([[]]));
|
||||
assert(!is_path([["foo","bar","baz"]]));
|
||||
assert(!is_path([[1,2,3]]));
|
||||
assert(!is_path([["foo","bar","baz"],["qux","quux","quuux"]]));
|
||||
}
|
||||
test_is_path();
|
||||
|
||||
|
||||
module test_is_closed_path() {
|
||||
assert(!is_closed_path([[1,2,3],[4,5,6],[1,8,9]]));
|
||||
assert(is_closed_path([[1,2,3],[4,5,6],[1,8,9],[1,2,3]]));
|
||||
}
|
||||
test_is_closed_path();
|
||||
|
||||
|
||||
module test_close_path() {
|
||||
assert(close_path([[1,2,3],[4,5,6],[1,8,9]]) == [[1,2,3],[4,5,6],[1,8,9],[1,2,3]]);
|
||||
assert(close_path([[1,2,3],[4,5,6],[1,8,9],[1,2,3]]) == [[1,2,3],[4,5,6],[1,8,9],[1,2,3]]);
|
||||
}
|
||||
test_close_path();
|
||||
|
||||
|
||||
module test_cleanup_path() {
|
||||
assert(cleanup_path([[1,2,3],[4,5,6],[1,8,9]]) == [[1,2,3],[4,5,6],[1,8,9]]);
|
||||
assert(cleanup_path([[1,2,3],[4,5,6],[1,8,9],[1,2,3]]) == [[1,2,3],[4,5,6],[1,8,9]]);
|
||||
}
|
||||
test_cleanup_path();
|
||||
|
||||
|
||||
module test_simplify_path() {
|
||||
path = [[-20,-20], [-10,-20], [0,-10], [10,0], [20,10], [20,20], [15,30]];
|
||||
assert(simplify_path(path) == [[-20,-20], [-10,-20], [20,10], [20,20], [15,30]]);
|
||||
}
|
||||
test_simplify_path();
|
||||
|
||||
|
||||
module test_simplify_path_indexed() {
|
||||
pts = [[10,0], [0,-10], [20,20], [20,10], [-20,-20], [15,30], [-10,-20]];
|
||||
path = [4,6,1,0,3,2,5];
|
||||
assert(simplify_path_indexed(pts, path) == [4,6,3,2,5]);
|
||||
}
|
||||
test_simplify_path_indexed();
|
12
tests/test_regions.scad
Normal file
12
tests/test_regions.scad
Normal file
|
@ -0,0 +1,12 @@
|
|||
include<../std.scad>
|
||||
|
||||
module test_is_region() {
|
||||
assert(is_region([circle(d=10),square(10)]));
|
||||
assert(is_region([circle(d=10),square(10),circle(d=50)]));
|
||||
assert(is_region([square(10)]));
|
||||
assert(!is_region([]));
|
||||
assert(!is_region(23));
|
||||
assert(!is_region(true));
|
||||
assert(!is_region("foo"));
|
||||
}
|
||||
test_is_region();
|
|
@ -81,11 +81,18 @@ test_vnf_centroid();
|
|||
|
||||
module test_vnf_volume() {
|
||||
assert_approx(vnf_volume(cube(100, center=false)), 1000000);
|
||||
assert(approx(vnf_volume(sphere(d=100, anchor=BOT, $fn=144)), 4/3*PI*pow(50,3), eps=1e3));
|
||||
assert(approx(vnf_volume(sphere(d=100, anchor=BOT, $fn=144)) / (4/3*PI*pow(50,3)),1, eps=.001));
|
||||
}
|
||||
test_vnf_volume();
|
||||
|
||||
|
||||
|
||||
module test_vnf_area(){
|
||||
assert(approx(vnf_area(sphere(d=100, $fn=144)) / (4*PI*50*50),1, eps=1e-3));
|
||||
}
|
||||
test_vnf_area();
|
||||
|
||||
|
||||
module test_vnf_merge() {
|
||||
vnf1 = vnf_add_face(pts=[[-1,-1,-1],[1,-1,-1],[0,1,-1]]);
|
||||
vnf2 = vnf_add_face(pts=[[1,1,1],[-1,1,1],[0,1,-1]]);
|
||||
|
|
Loading…
Reference in a new issue