include <omdl-base.scad>;
include <common/validation.scad>;
echo( str("openscad version ", version()) );
test_c =
[
["id", "identifier"],
["td", "description"],
["tv", "test value"]
];
test_r =
[
["fac", "Function argument count", undef],
["t01", "All undefined", [undef,undef]],
["t03", "test value 1", [254, 0]],
["t04", "test value 2", [254, 1]],
["t05", "test value 3", [255, 0]],
["t06", "test value 4", [0, 255]],
["t07", "test value 5", [126, 63]],
["t08", "test value 6", [25, 10]],
["t09", "test value 7", [1024, 512]],
["t10", "test value 8", [4253, 315]],
["t11", "test value 9", [835, 769]],
["t12", "test value 10", [856, 625]]
];
good_c =
merge_p([concat(
"id", test_ids), concat(
"identifier", test_ids)]);
skip = -1;
good_r =
[
["binary_bit_is_0", 2,
undef,
undef,
true,
false,
false,
true,
true,
true,
true,
true,
true,
true
],
["binary_bit_is_1", 2,
undef,
undef,
false,
true,
true,
false,
false,
false,
false,
false,
false,
false
],
["binary_i2v", 1,
undef,
undef,
[1,1,1,1,1,1,1,0],
[1,1,1,1,1,1,1,0],
[1,1,1,1,1,1,1,1],
[0],
[1,1,1,1,1,1,0],
[1,1,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0],
[1,0,0,0,0,1,0,0,1,1,1,0,1],
[1,1,0,1,0,0,0,0,1,1],
[1,1,0,1,0,1,1,0,0,0]
],
["binary_i2v_v2i", 1,
0,
0,
254,
254,
255,
0,
126,
25,
1024,
4253,
835,
856
],
["binary_i2s", 1,
undef,
undef,
"11111110",
"11111110",
"11111111",
"0",
"1111110",
"11001",
"10000000000",
"1000010011101",
"1101000011",
"1101011000"
],
["binary_i2s_s2i", 1,
0,
0,
254,
254,
255,
0,
126,
25,
1024,
4253,
835,
856
],
["binary_iw2i_32", 1,
undef,
undef,
7,
7,
7,
0,
7,
6,
0,
7,
0,
6
],
["binary_and", 2,
undef,
undef,
0,
0,
0,
0,
62,
8,
0,
25,
769,
592
],
["binary_or", 2,
undef,
undef,
254,
255,
255,
255,
127,
27,
1536,
4543,
835,
889
],
["binary_xor", 2,
undef,
undef,
254,
255,
255,
255,
65,
19,
1536,
4518,
66,
297
],
["binary_not", 1,
undef,
undef,
1,
1,
0,
1,
1,
6,
1023,
3938,
188,
167
],
["binary_ishl", 1,
undef,
undef,
508,
508,
510,
0,
252,
50,
2048,
8506,
1670,
1712
],
["binary_ishr", 1,
undef,
undef,
127,
127,
127,
0,
63,
12,
512,
2126,
417,
428
]
];
function gv( vid, e ) = get_value( vid )[e];
module log_test( m ) {
log_type (
"test", m ); }
module log_skip( f ) { log_test ( str("ignore: '", f, "'") ); }
module run( fname, vid )
{
children();
else
log_test( str(vid, " -skip-: '", fname, "(", value_text, ")'") );
}
module test( fname, fresult, vid )
{
test_pass =
validate(cv=fresult, t=
"equals", ev=pass_value, pf=
true);
farg_text =
strl(
append_e(
", ",
select_r(get_value(vid), [0:fname_argc-1]), r=
false, j=
false, l=
false));
test_text =
validate(str(fname,
"(", farg_text,
")=", pass_value), fresult,
"equals", pass_value);
if ( pass_value != skip )
{
if ( !test_pass )
log_test( str(vid, " ", test_text, " (", value_text, ")") );
else
log_test( str(vid, " ", test_text) );
}
else
log_test( str(vid, " -skip-: '", fname, "(", value_text, ")'") );
}
run_ids = delete( test_ids, mv=["fac", "crp"] );
for (vid=run_ids) run(
"binary_bit_is_0",vid) test(
"binary_bit_is_0",
binary_bit_is(gv(vid,0),gv(vid,1),0), vid );
for (vid=run_ids) run(
"binary_bit_is_1",vid) test(
"binary_bit_is_1",
binary_bit_is(gv(vid,0),gv(vid,1),1), vid );
for (vid=run_ids) run(
"binary_i2v",vid) test(
"binary_i2v",
binary_i2v(gv(vid,0)), vid );
for (vid=run_ids) run(
"binary_i2v_v2i",vid) test(
"binary_i2v_v2i",
binary_v2i(
binary_i2v(gv(vid,0))), vid );
for (vid=run_ids) run(
"binary_i2s",vid) test(
"binary_i2s",
binary_i2s(gv(vid,0)), vid );
for (vid=run_ids) run(
"binary_i2s_s2i",vid) test(
"binary_i2s_s2i",
binary_s2i(
binary_i2s(gv(vid,0))), vid );
for (vid=run_ids) run(
"binary_iw2i_32",vid) test(
"binary_iw2i_32",
binary_iw2i(gv(vid,0),2,3), vid );
for (vid=run_ids) run(
"binary_and",vid) test(
"binary_and",
binary_and(gv(vid,0),gv(vid,1)), vid );
for (vid=run_ids) run(
"binary_or",vid) test(
"binary_or",
binary_or(gv(vid,0),gv(vid,1)), vid );
for (vid=run_ids) run(
"binary_xor",vid) test(
"binary_xor",
binary_xor(gv(vid,0),gv(vid,1)), vid );
for (vid=run_ids) run(
"binary_not",vid) test(
"binary_not",
binary_not(gv(vid,0)), vid );
for (vid=run_ids) run(
"binary_ishl",vid) test(
"binary_ishl",
binary_ishl(gv(vid,0)), vid );
for (vid=run_ids) run(
"binary_ishr",vid) test(
"binary_ishr",
binary_ishr(gv(vid,0)), vid );
module log_type(t, m)
Output diagnostic message to console.
empty_lst
<list> A list with no values (the empty list).
function validate(d, cv, t, ev, p=4, pf=false)
Compare a computed test value with an known good result.
function binary_and(v1, v2, bv=1)
Base-2 binary AND operation for integers.
function binary_iw2i(v, s, w)
Decode the binary bits of a bit window to an integer value.
function binary_xor(v1, v2, bv=1)
Base-2 binary XOR operation for integers.
function binary_i2s(v, w=1)
Encode an integer value as a binary string of bits.
function binary_bit_is(v, b, t=1)
Test if a binary bit position of an integer value equals a test bit.
function binary_ishl(v, s=1, bm=1, bv=1)
Base-2 binary left-shift operation for an integer.
function binary_i2v(v, w=1, bv=1)
Encode an integer value as a binary list of bits.
function binary_v2i(v)
Decode a binary list of bits to an integer value.
function binary_ishr(v, s=1)
Base-2 binary right-shift operation for an integer.
function binary_not(v, w=1, bv=1)
Base-2 binary NOT operation for an integer.
function binary_or(v1, v2, bv=1)
Base-2 binary OR operation for integers.
function binary_s2i(v)
Decode a binary string of bits to an integer value.
function select_r(v, i)
Select a range of elements from an iterable value.
function append_e(nv, v, r=true, j=true, l=true)
Append a value to each element of an iterable value.
function strl(v)
Convert a list of values to a concatenated string.
function merge_p(v, j=true)
Parallel-merge the iterable elements of a list.
module table_check(r, c, verbose=false)
Perform basic format checks on a table and output errors to console.
function table_get_row_ids(r)
Form a list of all table row identifiers.
function table_get_value(r, c, ri, ci)
Get the table cell value for a specified row and column identifier.