qs1dsearch/autotest: moving functionality to testbench
#include <math.h>
#include <getopt.h>
-float qs1dsearch_autotest_utility_min(float _v, void * _context)
+float qs1dsearch_utility_min(float _v, void * _context)
{
float v_opt = *(float*)(_context);
float v = _v - v_opt;
@@ -37,15 +37,16 @@ float qs1dsearch_autotest_utility_min(float _v, void * _context)
}
//
-void autotest_qs1dsearch_min()
+void testbench_qs1dsearch(liquid_utility_1d _utility,
+ float _v_opt,
+ float _v_init,
+ int _direction)
{
// create qs1dsearch object
- float v_opt = 0.0f;
- qs1dsearch q = qs1dsearch_create(qs1dsearch_autotest_utility_min,
- &v_opt, LIQUID_OPTIM_MINIMIZE);
+ qs1dsearch q = qs1dsearch_create(_utility, &_v_opt, _direction);
//qs1dsearch_init_bounds(q, -20, 10);
- qs1dsearch_init(q, -50);
+ qs1dsearch_init(q, _v_init);
// run search
unsigned int i;
@@ -56,18 +57,20 @@ void autotest_qs1dsearch_min()
}
// check result
- CONTEND_DELTA( qs1dsearch_get_opt_v(q), v_opt, 1e-3f );
- CONTEND_LESS_THAN( qs1dsearch_get_opt_u(q), 1e-3f );
+ CONTEND_DELTA( qs1dsearch_get_opt_v(q), _v_opt, 1e-3f );
+ CONTEND_DELTA( qs1dsearch_get_opt_u(q), 0.0f, 1e-3f );
if (liquid_autotest_verbose) {
printf("%3u : u(%12.8f) = %12.4e, v_opt=%12.4e (error=%12.4e)\n",
i,
qs1dsearch_get_opt_v(q),
qs1dsearch_get_opt_u(q),
- v_opt,
- v_opt - qs1dsearch_get_opt_v(q));
+ _v_opt,
+ _v_opt - qs1dsearch_get_opt_v(q));
}
qs1dsearch_destroy(q);
}
+void autotest_qs1dsearch_01() { testbench_qs1dsearch(qs1dsearch_utility_min, 0, -20, LIQUID_OPTIM_MINIMIZE); }
+
