include <console.scad>;
include <datatypes/datatypes_table.scad>;
include <math/math_bitwise.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 =
[
["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 =
pmerge([concat(
"id", test_ids), concat(
"identifier", test_ids)]);
skip = -1;
good_r =
[
["bitwise_is_equal_0", 2,
false,
false,
true,
false,
false,
true,
true,
true,
true,
true,
true,
true
],
["bitwise_is_equal_1", 2,
false,
false,
false,
true,
true,
false,
false,
false,
false,
false,
false,
false
],
["bitwise_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]
],
["bitwise_i2v_v2i", 1,
undef,
undef,
254,
254,
255,
0,
126,
25,
1024,
4253,
835,
856
],
["bitwise_i2s", 1,
undef,
undef,
"11111110",
"11111110",
"11111111",
"0",
"1111110",
"11001",
"10000000000",
"1000010011101",
"1101000011",
"1101011000"
],
["bitwise_i2s_s2i", 1,
undef,
undef,
254,
254,
255,
0,
126,
25,
1024,
4253,
835,
856
],
["bitwise_imi_32", 1,
undef,
undef,
7,
7,
7,
0,
7,
6,
0,
7,
0,
6
],
["bitwise_and", 2,
undef,
undef,
0,
0,
0,
0,
62,
8,
0,
25,
769,
592
],
["bitwise_or", 2,
undef,
undef,
254,
255,
255,
255,
127,
27,
1536,
4543,
835,
889
],
["bitwise_xor", 2,
undef,
undef,
254,
255,
255,
255,
65,
19,
1536,
4518,
66,
297
],
["bitwise_not", 1,
undef,
undef,
1,
1,
0,
1,
1,
6,
1023,
3938,
188,
167
],
["bitwise_lsh", 1,
undef,
undef,
508,
508,
510,
0,
252,
50,
2048,
8506,
1670,
1712
],
["bitwise_rsh", 1,
undef,
undef,
127,
127,
127,
0,
63,
12,
512,
2126,
417,
428
]
];
function get_value( vid ) =
get_table_v(test_r, test_c, vid,
"tv");
function gv( vid, e ) = get_value( vid )[e];
module run( fname, vid )
{
children();
else if ( show_skipped )
log_info( str(
"*skip*: ", vid,
" '", fname,
"(", value_text,
")'") );
}
module test( fname, fresult, vid )
{
fname_argc =
get_table_v(good_r, good_c, fname,
"fac");
test_pass =
validate(cv=fresult, t=
"equals", ev=pass_value, pf=
true);
farg_text =
lstr(
eappend(
", ",
rselect(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_warn( str(vid,
"(", value_text,
") ", test_text) );
else if ( show_passing )
}
else if ( show_skipped )
log_info( str(vid,
" *skip*: '", fname,
"(", value_text,
")'") );
}
run_ids = delete( test_ids, mv=["fac", "crp"] );
for (vid=run_ids) run(
"bitwise_is_equal_0",vid) test( "bitwise_is_equal_0",
bitwise_is_equal(gv(vid,0),gv(vid,1),0), vid );
for (vid=run_ids) run("bitwise_is_equal_1",vid) test( "bitwise_is_equal_1",
bitwise_is_equal(gv(vid,0),gv(vid,1),1), vid );
for (vid=run_ids) run("bitwise_i2v",vid) test( "bitwise_i2v", bitwise_i2v(gv(vid,0)), vid );
for (vid=run_ids) run("bitwise_i2v_v2i",vid) test( "bitwise_i2v_v2i",
bitwise_v2i(bitwise_i2v(gv(vid,0))), vid );
for (vid=run_ids) run("bitwise_i2s",vid) test( "bitwise_i2s", bitwise_i2s(gv(vid,0)), vid );
for (vid=run_ids) run("bitwise_i2s_s2i",vid) test( "bitwise_i2s_s2i",
bitwise_s2i(bitwise_i2s(gv(vid,0))), vid );
for (vid=run_ids) run("bitwise_imi_32",vid) test( "bitwise_imi_32",
bitwise_imi(gv(vid,0),3,2), vid );
for (vid=run_ids) run("bitwise_and",vid) test( "bitwise_and", bitwise_and(gv(vid,0),gv(vid,1)), vid );
for (vid=run_ids) run("bitwise_or",vid) test( "bitwise_or", bitwise_or(gv(vid,0),gv(vid,1)), vid );
for (vid=run_ids) run("bitwise_xor",vid) test( "bitwise_xor", bitwise_xor(gv(vid,0),gv(vid,1)), vid );
for (vid=run_ids) run("bitwise_not",vid) test( "bitwise_not", bitwise_not(gv(vid,0)), vid );
for (vid=run_ids) run("bitwise_lsh",vid) test( "bitwise_lsh", bitwise_lsh(gv(vid,0)), vid );
for (vid=run_ids) run("bitwise_rsh",vid) test( "bitwise_rsh", bitwise_rsh(gv(vid,0)), vid );