omdl  v0.5
OpenSCAD Mechanical Design Library
Validation Script
include <primitives.scad>;
use <table.scad>;
use <console.scad>;
use <validation.scad>;
show_passing = true; // show passing tests
show_skipped = true; // show skipped tests
echo( str("OpenSCAD Version ", version()) );
// test-values columns
test_c =
[
["id", "identifier"],
["td", "description"],
["tv", "test value"]
];
// test-values rows
test_r =
[
["t01", "The undefined value", undef],
["t02", "The empty vector", empty_v],
["t03", "A range", [0:0.5:9]],
["t04", "A string", "A string"],
["t05", "Test vector 01", ["orange","apple","grape","banana"]],
["t06", "Test vector 02", ["b","a","n","a","n","a","s"]],
["t07", "Test vector 03", [undef]],
["t08", "Test vector 04", [[1,2],[2,3]]],
["t09", "Test vector 05", ["ab",[1,2],[2,3],[4,5]]],
["t10", "Test vector 06", [[1,2,3],[4,5,6],[7,8,9],["a","b","c"]]],
["t11", "Vector of integers 0 to 15", [for (i=[0:15]) i]]
];
test_ids = table_get_row_ids( test_r );
// expected columns: ("id" + one column for each test)
good_c = pmerge([concat("id", test_ids), concat("identifier", test_ids)]);
// expected rows: ("golden" test results), use 's' to skip test
skip = -1; // skip test
good_r =
[ // function
["consts",
empty_v, // t01
empty_v, // t02
empty_v, // t03
empty_v, // t04
empty_v, // t05
empty_v, // t06
empty_v, // t07
empty_v, // t08
empty_v, // t09
empty_v, // t10
empty_v // t11
],
["vstr",
undef, // t01
empty_str, // t02
"[0 : 0.5 : 9]", // t03
"A string", // t04
"orangeapplegrapebanana", // t05
"bananas", // t06
"undef", // t07
"[1, 2][2, 3]", // t08
"ab[1, 2][2, 3][4, 5]", // t09
"[1, 2, 3][4, 5, 6][7, 8, 9][\"a\", \"b\", \"c\"]", // t10
"0123456789101112131415" // t11
],
["sum",
undef, // t01
0, // t02
85.5, // t03
undef, // t04
undef, // t05
undef, // t06
undef, // t07
[3,5], // t08
undef, // t09
[undef,undef,undef], // t10
120 // t11
],
["find_12",
empty_v, // t01
empty_v, // t02
empty_v, // t03
empty_v, // t04
empty_v, // t05
empty_v, // t06
empty_v, // t07
[0], // t08
[1], // t09
empty_v, // t10
empty_v // t11
],
["count_S1",
0, // t01
0, // t02
0, // t03
0, // t04
0, // t05
0, // t06
0, // t07
1, // t08
1, // t09
1, // t10
1 // t11
],
["exists_S1",
false, // t01
false, // t02
false, // t03
false, // t04
false, // t05
false, // t06
false, // t07
true, // t08
true, // t09
true, // t10
true // t11
],
["defined_or_D",
"default", // t01
empty_v, // t02
[0:0.5:9], // t03
"A string", // 04
["orange","apple","grape","banana"], // t05
["b","a","n","a","n","a","s"], // t06
[undef], // t07
[[1,2],[2,3]], // t08
["ab",[1,2],[2,3],[4,5]], // t09
[[1,2,3],[4,5,6],[7,8,9],["a","b","c"]], // t10
[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] // t11
],
["edefined_or_DE3",
"default", // t01
"default", // t02
"default", // t03
"t", // t04
"banana", // t05
"a", // t06
"default", // t07
"default", // t08
[4,5], // t09
["a","b","c"], // t10
3 // t11
],
["first",
undef, // t01
undef, // t02
undef, // t03
"A", // t04
"orange", // t05
"b", // t06
undef, // t07
[1,2], // t08
"ab", // t09
[1,2,3], // t10
0 // t11
],
["second",
undef, // t01
undef, // t02
undef, // t03
" ", // t04
"apple", // t05
"a", // t06
undef, // t07
[2,3], // t08
[1,2], // t09
[4,5,6], // t10
1 // t11
],
["last",
undef, // t01
undef, // t02
undef, // t03
"g", // t04
"banana", // t05
"s", // t06
undef, // t07
[2,3], // t08
[4,5], // t09
["a","b","c"], // t10
15 // t11
],
["nfirst_1",
undef, // t01
undef, // t02
undef, // t03
["A"], // t04
["orange"], // t05
["b"], // t06
[undef], // t07
[[1,2]], // t08
["ab"], // t09
[[1,2,3]], // t10
[0] // t11
],
["nlast_1",
undef, // t01
undef, // t02
undef, // t03
["g"], // t04
["banana"], // t05
["s"], // t06
[undef], // t07
[[2,3]], // t08
[[4,5]], // t09
[["a","b","c"]], // t10
[15] // t11
],
["nhead_1",
undef, // t01
undef, // t02
undef, // t03
["A"," ","s","t","r","i","n"], // t04
["orange","apple","grape"], // t05
["b","a","n","a","n","a"], // t06
empty_v, // t07
[[1,2]], // t08
["ab",[1,2],[2,3]], // t09
[[1,2,3],[4,5,6],[7,8,9]], // t10
[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14] // t11
],
["ntail_1",
undef, // t01
undef, // t02
undef, // t03
[" ","s","t","r","i","n","g"], // t04
["apple","grape","banana"], // t05
["a","n","a","n","a","s"], // t06
empty_v, // t07
[[2,3]], // t08
[[1,2],[2,3],[4,5]], // t09
[[4,5,6],[7,8,9],["a","b","c"]], // t10
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] // t11
],
["rselect_02",
undef, // t01
empty_v, // t02
undef, // t03
["A"," ","s"], // t04
["orange","apple","grape"], // t05
["b","a","n"], // t06
undef, // t07
undef, // t08
["ab",[1,2],[2,3]], // t09
[[1,2,3],[4,5,6],[7,8,9]], // t10
[0,1,2] // t11
],
["eselect_F",
undef, // t01
empty_v, // t02
undef, // t03
["A"," ","s","t","r","i","n","g"], // t04
["o","a","g","b"], // t05
["b","a","n","a","n","a","s"], // t06
[undef], // t07
[1,2], // t08
["a",1,2,4], // t09
[1,4,7,"a"], // t10
skip // t11
],
["eselect_L",
undef, // t01
empty_v, // t02
undef, // t03
["A"," ","s","t","r","i","n","g"], // t04
["e","e","e","a"], // t05
["b","a","n","a","n","a","s"], // t06
[undef], // t07
[2,3], // t08
["b",2,3,5], // t09
[3,6,9,"c"], // t10
skip // t11
],
["eselect_1",
undef, // t01
empty_v, // t02
undef, // t03
skip, // t04
["r","p","r","a"], // t05
skip, // t06
[undef], // t07
[2,3], // t08
["b",2,3,5], // t09
[2,5,8,"b"], // t10
skip // t11
],
["smerge",
undef, // t01
empty_v, // t02
[[0:0.5:9]], // t03
["A string"], // t04
["orange","apple","grape","banana"], // t05
["b","a","n","a","n","a","s"], // t06
[undef], // t07
[1,2,2,3], // t08
["ab",1,2,2,3,4,5], // t09
[1,2,3,4,5,6,7,8,9,"a","b","c"], // t10
[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] // t11
],
["pmerge",
undef, // t01
empty_v, // t02
undef, // t03
["A string"], // t04
[
["o","a","g","b"],["r","p","r","a"],
["a","p","a","n"],["n","l","p","a"],
["g","e","e","n"]
], // t05
[["b","a","n","a","n","a","s"]], // t06
undef, // t07
[[1,2],[2,3]], // t08
[["a",1,2,4],["b",2,3,5]], // t09
[[1,4,7,"a"],[2,5,8,"b"],[3,6,9,"c"]], // t10
undef // t11
],
["reverse",
undef, // t01
empty_v, // t02
undef, // t03
["g","n","i","r","t","s"," ","A"], // t04
["banana","grape","apple","orange"], // t05
["s","a","n","a","n","a","b"], // t06
[undef], // t07
[[2,3],[1,2]], // t08
[[4,5],[2,3],[1,2],"ab"], // t09
[["a","b","c"],[7,8,9],[4,5,6],[1,2,3]], // t10
[15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0] // t11
],
["qsort",
undef, // t01
empty_v, // t02
undef, // t03
undef, // t04
["apple","banana","grape","orange"], // t05
["a","a","a","b","n","n","s"], // t06
undef, // t07
undef, // t08
undef, // t09
undef, // t10
[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] // t11
],
["qsort2_HR",
undef, // t01
empty_v, // t02
undef, // t03
undef, // t04
["orange","grape","banana","apple"], // t05
["s","n","n","b","a","a","a"], // t06
[undef], // t07
[[3,2],[2,1]], // t08
[[5,4],[3,2],[2,1],"ab"], // t09
[["c","b","a"],[9,8,7],[6,5,4],[3,2,1]], // t10
[15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0] // t11
],
["strip",
undef, // t01
empty_v, // t02
undef, // t03
["A"," ","s","t","r","i","n","g"], // t04
["orange","apple","grape","banana"], // t05
["b","a","n","a","n","a","s"], // t06
[undef], // t07
[[1,2],[2,3]], // t08
["ab",[1,2],[2,3],[4,5]], // t09
[[1,2,3],[4,5,6],[7,8,9],["a","b","c"]], // t10
[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] // t11
],
["eappend_T0",
undef, // t01
[[0]], // t02
undef, // t03
[
["A",0],[" ",0],["s",0],["t",0],
["r",0],["i",0],["n",0],["g",0]
], // t04
[
["orange",0],["apple",0],
["grape",0],["banana",0]
], // t05
[
["b",0],["a",0],["n",0],["a",0],
["n",0],["a",0],["s",0]
], // t06
[[undef,0]], // t07
[[1,2,0],[2,3,0]], // t08
[["ab",0],[1,2,0],[2,3,0],[4,5,0]], // t09
[[1,2,3,0],[4,5,6,0],[7,8,9,0],["a","b","c",0]], // t10
[
[0,0],[1,0],[2,0],[3,0],[4,0],[5,0],
[6,0],[7,0],[8,0],[9,0],[10,0],[11,0],
[12,0],[13,0],[14,0],[15,0]
] // t11
],
["insert_T0",
undef, // t01
undef, // t02
undef, // t03
undef, // t04
["orange",0,"apple","grape","banana"], // t05
["b","a","n","a","n","a",0,"s"], // t06
undef, // t07
[[1,2],0,[2,3]], // t08
["ab",[1,2],0,[2,3],[4,5]], // t09
undef, // t10
[0,1,2,3,4,0,5,6,7,8,9,10,11,12,13,14,15] // t11
],
["delete_T0",
undef, // t01
empty_v, // t02
undef, // t03
["A"," ","s","t","r","i","n","g"], // t04
["orange","grape","banana"], // t05
["b","a","n","a","n","a"], // t06
[undef], // t07
[[1,2]], // t08
["ab",[1,2],[4,5]], // t09
[[1,2,3],[4,5,6],[7,8,9],["a","b","c"]], // t10
[0,1,2,3,4,6,7,8,9,10,11,12,13,14,15] // t11
],
["unique",
undef, // t01
empty_v, // t02
undef, // t03
["A"," ","s","t","r","i","n","g"], // t04
["orange","apple","grape","banana"], // t05
["b","a","n","s"], // t06
[undef], // t07
[[1,2],[2,3]], // t08
["ab",[1,2],[2,3],[4,5]], // t09
[[1,2,3],[4,5,6],[7,8,9],["a","b","c"]], // t10
[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] // t11
]
];
// sanity-test tables
table_check( test_r, test_c, false );
table_check( good_r, good_c, false );
// validate helper function and module
function get_value( vid ) = table_get(test_r, test_c, vid, "tv");
module run_test( fname, fresult, vid )
{
value_text = table_get(test_r, test_c, vid, "td");
pass_value = table_get(good_r, good_c, fname, vid);
test_pass = validate( cv=fresult, t="equals", ev=pass_value, pf=true );
test_text = validate( str(fname, "(", get_value(vid), ")=", pass_value), fresult, "equals", pass_value );
if ( pass_value != skip )
{
if ( !test_pass )
log_warn( str(vid, "(", value_text, ") ", test_text) );
else if ( show_passing )
log_info( str(vid, " ", test_text) );
}
else if ( show_skipped )
log_info( str(vid, " *skip*: '", fname, "(", value_text, ")'") );
}
// Indirect function calls would be very useful here!!!
// create / convert
for (vid=test_ids) run_test( "consts", consts(get_value(vid)), vid );
for (vid=test_ids) run_test( "vstr", vstr(get_value(vid)), vid );
for (vid=test_ids) run_test( "sum", sum(get_value(vid)), vid );
// query
for (vid=test_ids) run_test( "find_12", find([1,2],get_value(vid)), vid );
for (vid=test_ids) run_test( "count_S1", count(1,get_value(vid),true), vid );
for (vid=test_ids) run_test( "exists_S1", exists(1,get_value(vid),true), vid );
// select
for (vid=test_ids) run_test( "defined_or_D", defined_or(get_value(vid),"default"), vid );
for (vid=test_ids) run_test( "edefined_or_DE3", edefined_or(get_value(vid),3,"default"), vid );
for (vid=test_ids) run_test( "first", first(get_value(vid)), vid );
for (vid=test_ids) run_test( "second", second(get_value(vid)), vid );
for (vid=test_ids) run_test( "last", last(get_value(vid)), vid );
for (vid=test_ids) run_test( "nfirst_1", nfirst(get_value(vid),n=1), vid );
for (vid=test_ids) run_test( "nlast_1", nlast(get_value(vid),n=1), vid );
for (vid=test_ids) run_test( "nhead_1", nhead(get_value(vid),n=1), vid );
for (vid=test_ids) run_test( "ntail_1", ntail(get_value(vid),n=1), vid );
for (vid=test_ids) run_test( "rselect_02", rselect(get_value(vid),i=[0:2]), vid );
for (vid=test_ids) run_test( "eselect_F", eselect(get_value(vid),f=true), vid );
for (vid=test_ids) run_test( "eselect_L", eselect(get_value(vid),l=true), vid );
for (vid=test_ids) run_test( "eselect_1", eselect(get_value(vid),i=1), vid );
// not tested: ciselect()
// not tested: cmvselect()
// reorder
for (vid=test_ids) run_test( "smerge", smerge(get_value(vid)), vid );
for (vid=test_ids) run_test( "pmerge", pmerge(get_value(vid)), vid );
for (vid=test_ids) run_test( "reverse", reverse(get_value(vid)), vid );
for (vid=test_ids) run_test( "qsort", qsort(get_value(vid)), vid );
for (vid=test_ids) run_test( "qsort2_HR", qsort2(get_value(vid), d=5, r=true), vid );
// grow / reduce
for (vid=test_ids) run_test( "strip", strip(get_value(vid)), vid );
for (vid=test_ids) run_test( "eappend_T0", eappend(0,get_value(vid)), vid );
for (vid=test_ids) run_test( "insert_T0", insert(0,get_value(vid),mv=["x","r","apple","s",[2,3],5]), vid );
for (vid=test_ids) run_test( "delete_T0", delete(get_value(vid),mv=["x","r","apple","s",[2,3],5]), vid );
for (vid=test_ids) run_test( "unique", unique(get_value(vid)), vid );
// end-of-tests