From 50d7a725d492b3f74474809b8f64df41b60ff3a1 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Thu, 16 Jan 2020 15:15:05 +0100 Subject: [PATCH] solvtable:: unittest added --- devmods/solv-table.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/devmods/solv-table.cpp b/devmods/solv-table.cpp index 7663bfdd..c58fd3fd 100644 --- a/devmods/solv-table.cpp +++ b/devmods/solv-table.cpp @@ -508,6 +508,8 @@ void improve(sn::tabled_inverses& tab) { int dimX=64, dimY=64, dimZ=64; +EX hyperpoint recompress(hyperpoint h) { return decompress(compress(h)); } + int readArgs() { using namespace arg; @@ -547,6 +549,25 @@ int readArgs() { sn::get_tabled().load(); visualize_table(sn::get_tabled(), argcs()); } + else if(argis("-sn-unittest")) { + println(hlog, "nih = ", (bool)nih); + ld maxerr; + auto test_result = [&maxerr] (ld a, ld b) { maxerr = max(maxerr, (a-b)); }; + auto test_result_p = [&maxerr] (hyperpoint a, hyperpoint b) { maxerr = max(maxerr, hypot_d(3, a-b)); }; + auto test = [&maxerr] (string s, reaction_t tester) { + maxerr = 0; + tester(); + println(hlog, "unittest: ", s, " error = ", maxerr); + }; + test("x_to_ix", [&] { for(ld a=0; a<=20; a+=.1) test_result(a, sn::ix_to_x(sn::x_to_ix(a))); }); + test("z_to_iz", [&] { for(ld a=nih?-20:0; a<=20; a+=.1) test_result(a, sn::iz_to_z(sn::z_to_iz(a))); }); + test("azeq_to_table", [&] { for(ld a=-5; a<=5; a++) for(ld b=-5; b<=5; b++) for(ld c=-5; c<=5; c++) { hyperpoint h = point3(a,b,c); test_result_p(h, sn::table_to_azeq(sn::azeq_to_table(h))); }}); + test("azeq_to_table recompressed", [&] { + for(ld a=-5; a<=5; a++) for(ld b=-5; b<=5; b++) for(ld c=-5; c<=5; c++) { + hyperpoint h = point3(a,b,c); test_result_p(h, sn::table_to_azeq(recompress(sn::azeq_to_table(h)))); + } + }); + } else return 1; return 0;