qs1dsearch/autotest: adding test to check maximum
@@ -36,6 +36,11 @@ float qs1dsearch_utility_min(float _v, void * _context)
return tanhf(v)*tanhf(v);
}
+float qs1dsearch_utility_max(float _v, void * _context)
+{
+ return 1.0f - qs1dsearch_utility_min(_v, _context);
+}
+
//
void testbench_qs1dsearch(liquid_utility_1d _utility,
float _v_opt,
@@ -58,19 +63,19 @@ void testbench_qs1dsearch(liquid_utility_1d _utility,
// check result
CONTEND_DELTA( qs1dsearch_get_opt_v(q), _v_opt, 1e-3f );
- CONTEND_DELTA( qs1dsearch_get_opt_u(q), 0.0f, 1e-3f );
+ CONTEND_DELTA( qs1dsearch_get_opt_u(q), _utility(_v_opt, &_v_opt), 1e-3f );
+ // print results
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));
+ i, qs1dsearch_get_opt_v(q), qs1dsearch_get_opt_u(q),
+ _v_opt, _v_opt - qs1dsearch_get_opt_v(q));
}
+ // clean it upt
qs1dsearch_destroy(q);
}
void autotest_qs1dsearch_01() { testbench_qs1dsearch(qs1dsearch_utility_min, 0, -20, LIQUID_OPTIM_MINIMIZE); }
+void autotest_qs1dsearch_02() { testbench_qs1dsearch(qs1dsearch_utility_max, 0, -20, LIQUID_OPTIM_MAXIMIZE); }
