include <console.scad>;
include <datatypes/datatypes-base.scad>;
include <datatypes/datatypes_table.scad>;
include <validation.scad>;
show_passing = true;
show_skipped = true;
echo( str("OpenSCAD Version ", version()) );
test_c =
[
["id", "identifier"],
["td", "description"],
["tv", "test value"]
];
test_r =
[
["t01", "The undefined value", undef],
["t02", "An odd integer", 1],
["t03", "The boolean true", true],
["t04", "The boolean false", false],
["t05", "A character string", "a"],
["t06", "A string", "This is a longer string"],
["t09", "A shorthand range", [0:9]],
["t10", "A range", [0:0.5:9]],
["t11", "Test list 01", [undef]],
["t12", "Test list 02", [1]],
["t13", "Test list 03", [1, 2, 3]],
["t14", "Test list 04", [[1], [2], [3], [4], [5]]],
["t15", "Test list 05", [[1,2], [2,3]]],
["t16", "Test list 06", [[1,2], [2,3], [4,5], "ab"]],
["t17", "Test list 07", [[1,2,3], [4,5,6], [7,8,9], ["a", "b", "c"]]],
["t18", "Test list 08", [1, 2, 3, undef]],
["t19", "Test list 09", [undef, undef, undef, undef]],
["t20", "Test list 10", [[undef], [undef], [undef]]],
["t21", "Test list 11", [true, true, true, true, false]],
["t22", "Test list 12", [true, false, false, false, false]],
["t23", "Test list 13", [true, true, true, true]]
];
good_c =
pmerge([concat(
"id", test_ids), concat(
"identifier", test_ids)]);
t = true;
f = false;
u = undef;
s = -1;
good_r =
[
["all_equal_T", f, f, t, f, f, f, t, t, f, f, f, f, f, f, f, f, f, f, f, f, f, f, t],
["all_equal_F", f, f, f, t, f, f, t, t, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f],
["all_equal_U", t, f, f, f, f, f, t, t, f, f, t, f, f, f, f, f, f, f, t, f, f, f, f],
["any_equal_T", f, f, t, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, t, t, t],
["any_equal_F", f, f, f, t, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f, t, t, f],
["any_equal_U", t, f, f, f, f, f, f, f, f, f, t, f, f, f, f, f, f, t, t, f, f, f, f],
["all_defined", f, t, t, t, t, t, t, t, t, t, f, t, t, t, t, t, t, f, f, t, t, t, t],
["any_undefined", t, f, f, f, f, f, f, f, f, f, t, f, f, f, f, f, f, t, t, f, f, f, f],
["all_scalars", u, t, t, t, f, f, s, s, s, s, t, t, t, f, f, f, f, t, t, f, t, t, t],
["all_lists", u, f, f, f, f, f, t, t, f, f, f, f, f, t, t, f, t, f, f, t, f, f, f],
["all_strings", u, f, f, f, t, t, t, s, f, f, f, f, f, f, f, f, f, f, f, f, f, f, f],
["all_numbers", u, t, f, f, f, f, s, s, f, f, f, t, t, f, f, f, f, f, f, f, f, f, f],
["all_len_1", u, f, f, f, t, t, s, s, f, f, f, f, f, t, f, f, f, f, f, t, f, f, f],
["all_len_2", u, f, f, f, f, f, s, s, f, f, f, f, f, f, t, t, f, f, f, f, f, f, f],
["all_len_3", u, f, f, f, f, f, s, s, f, f, f, f, f, f, f, f, t, f, f, f, f, f, f]
];
function get_value( vid ) =
get_table_v(test_r, test_c, vid,
"tv");
module run_test( fname, fresult, 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 != s )
{
if ( !test_pass )
log_warn( str(vid,
"(", value_text,
") ", test_text) );
else if ( show_passing )
}
else if ( show_skipped )
log_info( str(vid,
" *skip*: '", fname,
"(", value_text,
")'") );
}
for (vid=test_ids) run_test(
"all_equal_T",
all_equal(get_value(vid),t), vid );
for (vid=test_ids) run_test(
"all_equal_F",
all_equal(get_value(vid),f), vid );
for (vid=test_ids) run_test(
"all_equal_U",
all_equal(get_value(vid),u), vid );
for (vid=test_ids) run_test(
"any_equal_T",
any_equal(get_value(vid),t), vid );
for (vid=test_ids) run_test(
"any_equal_F",
any_equal(get_value(vid),f), vid );
for (vid=test_ids) run_test(
"any_equal_U",
any_equal(get_value(vid),u), vid );
for (vid=test_ids) run_test(
"all_defined",
all_defined(get_value(vid)), vid );
for (vid=test_ids) run_test(
"any_undefined",
any_undefined(get_value(vid)), vid );
for (vid=test_ids) run_test(
"all_scalars",
all_scalars(get_value(vid)), vid );
for (vid=test_ids) run_test(
"all_lists",
all_lists(get_value(vid)), vid );
for (vid=test_ids) run_test(
"all_strings",
all_strings(get_value(vid)), vid );
for (vid=test_ids) run_test(
"all_numbers",
all_numbers(get_value(vid)), vid );
for (vid=test_ids) run_test(
"all_len_1",
all_len(get_value(vid),1), vid );
for (vid=test_ids) run_test(
"all_len_2",
all_len(get_value(vid),2), vid );
for (vid=test_ids) run_test(
"all_len_3",
all_len(get_value(vid),3), vid );