omdl  v0.6.1
OpenSCAD Mechanical Design Library
Script
include <console.scad>;
include <datatypes/datatypes-base.scad>;
include <datatypes/datatypes_table.scad>;
include <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 list", empty_lst],
["t03", "A range", [0:0.5:9]],
["t04", "A string", "A string"],
["t05", "Test list 01", ["orange","apple","grape","banana"]],
["t06", "Test list 02", ["b","a","n","a","n","a","s"]],
["t07", "Test list 03", [undef]],
["t08", "Test list 04", [[1,2],[2,3]]],
["t09", "Test list 05", ["ab",[1,2],[2,3],[4,5]]],
["t10", "Test list 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 = get_table_ridl( 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
["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
],
["find_12",
empty_lst, // t01
empty_lst, // t02
empty_lst, // t03
empty_lst, // t04
empty_lst, // t05
empty_lst, // t06
empty_lst, // t07
[0], // t08
[1], // t09
empty_lst, // t10
empty_lst // 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
],
["first",
undef, // t01
undef, // t02
0, // 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
0.5, // t03
" ", // t04
"apple", // t05
"a", // t06
undef, // t07
[2,3], // t08
[1,2], // t09
[4,5,6], // t10
1 // t11
],
["third",
undef, // t01
undef, // t02
9, // t03
"s", // t04
"grape", // t05
"n", // t06
undef, // t07
undef, // t08
[2,3], // t09
[7,8,9], // t10
2 // 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_lst, // 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_lst, // 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
],
["reverse",
undef, // t01
empty_lst, // 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
],
["rselect_02",
undef, // t01
empty_lst, // 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
],
["nssequence_31",
empty_lst, // t01
empty_lst, // t02
empty_lst, // t03
[
["A"," ","s"],[" ","s","t"],["s","t","r"],
["t","r","i"],["r","i","n"],["i","n","g"]
], // t04
[
["orange","apple","grape"],
["apple","grape","banana"]
], // t05
[
["b","a","n"],["a","n","a"],["n","a","n"],
["a","n","a"],["n","a","s"]
], // t06
empty_lst, // t07
empty_lst, // t08
[["ab",[1,2],[2,3]],[[1,2],[2,3],[4,5]]], // t09
[
[[1,2,3],[4,5,6],[7,8,9]],
[[4,5,6],[7,8,9],["a","b","c"]]
], // t10
[
[0,1,2],[1,2,3],[2,3,4],[3,4,5],[4,5,6],[5,6,7],
[6,7,8],[7,8,9],[8,9,10],[9,10,11],[10,11,12],
[11,12,13],[12,13,14],[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_lst, // 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
],
["strip",
undef, // t01
empty_lst, // 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
],
["unique",
undef, // t01
empty_lst, // 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 ) = get_table_v(test_r, test_c, vid, "tv");
module run_test( fname, fresult, vid )
{
value_text = get_table_v(test_r, test_c, vid, "td");
pass_value = get_table_v(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!!!
for (vid=test_ids) run_test( "edefined_or_DE3", edefined_or(get_value(vid),3,"default"), vid );
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 );
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( "third", third(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( "reverse", reverse(get_value(vid)), vid );
for (vid=test_ids) run_test( "rselect_02", rselect(get_value(vid),i=[0:2]), vid );
for (vid=test_ids) run_test( "nssequence_31", nssequence(get_value(vid),n=3,s=1), 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( "strip", strip(get_value(vid)), vid );
for (vid=test_ids) run_test( "unique", unique(get_value(vid)), vid );
// end-of-tests