本文整理汇总了C++中CuAssertDblEquals函数的典型用法代码示例。如果您正苦于以下问题:C++ CuAssertDblEquals函数的具体用法?C++ CuAssertDblEquals怎么用?C++ CuAssertDblEquals使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CuAssertDblEquals函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Test_maxmin_pw
void Test_maxmin_pw(CuTest * tc){
printf("Testing functions: absmax, max and min of pw \n");
// function
struct Fwrap * fw = fwrap_create(1,"general-vec");
fwrap_set_fvec(fw,maxminpoly,NULL);
// approximation
double lb = -1.0, ub = 2.0;
struct PwPolyOpts * opts = pw_poly_opts_alloc(LEGENDRE,lb,ub);
opoly_t pl = piecewise_poly_approx1_adapt(opts,fw);
double loc;
double max = piecewise_poly_max(pl, &loc);
double min = piecewise_poly_min(pl, &loc);
double absmax = piecewise_poly_absmax(pl, &loc,NULL);
CuAssertDblEquals(tc, 1.0, max, 1e-10);
CuAssertDblEquals(tc, -1.0, min, 1e-10);
CuAssertDblEquals(tc, 1.0, absmax, 1e-10);
piecewise_poly_free(pl);
fwrap_destroy(fw);
pw_poly_opts_free(opts);
}
示例2: Test_serialize_double
void Test_serialize_double(CuTest * tc){
printf("doubleserialization tests and experiments \n");
printf("size of double in bytes= %zu\n",sizeof(double));
printf("DBL_MAX = %G \n",DBL_MAX);
printf("DBL_MIN = %G \n",DBL_MIN);
printf("DBL_EPSILON = %G\n",DBL_EPSILON);
double a = 20423.231;
double value;
unsigned char buffer[sizeof(double)];
serialize_double(buffer,a);
deserialize_double(buffer,&value);
CuAssertDblEquals(tc,value,a,0.0);
a = DBL_MAX;
serialize_double(buffer,a);
deserialize_double(buffer,&value);
CuAssertDblEquals(tc,value,a,0.0);
a = 0.0;
serialize_double(buffer,a);
deserialize_double(buffer,&value);
CuAssertDblEquals(tc,value,a,0.0);
}
示例3: Test_lin_elem_exp_orth_basis
void Test_lin_elem_exp_orth_basis(CuTest * tc)
{
printf("Testing function: lin_elem_exp_orth_basis\n");
double lb = -2.0;
double ub = 0.2;
size_t N = 100;
double * x = linspace(lb,ub,N);
struct LinElemExpAopts * opts = lin_elem_exp_aopts_alloc(N,x);
/* double * coeff = calloc_double(N); */
le_t f[100];
for (size_t ii = 0; ii < N; ii++){
f[ii] = NULL;// lin_elem_exp_init(N,x,coeff);
}
lin_elem_exp_orth_basis(N,f,opts);
for (size_t ii = 0; ii < N; ii++){
for (size_t jj = 0; jj < N; jj++){
double val = lin_elem_exp_inner(f[ii],f[jj]);
if (ii == jj){
CuAssertDblEquals(tc,1.0,val,1e-15);
}
else{
CuAssertDblEquals(tc,0.0,val,1e-15);
}
}
}
for (size_t ii = 0; ii < N; ii++){
LINELEM_FREE(f[ii]);
}
free(x); x = NULL;
/* free(coeff); coeff = NULL; */
lin_elem_exp_aopts_free(opts);
}
示例4: testVectorMalloc
void testVectorMalloc(CuTest* tc) {
vector v = vectorMalloc();
//CuAssertTrue(tc, NULL != v);
CuAssertDblEquals(tc, 0.0, v.x, DELTA);
CuAssertDblEquals(tc, 0.0, v.y, DELTA);
CuAssertDblEquals(tc, 0.0, v.z, DELTA);
}
示例5: Testwishart
void Testwishart(CuTest* tc) {
/*set a non-trivial location matrix*/
gsl_matrix* V = gsl_matrix_alloc(DIM, DIM);
gsl_matrix_set_identity(V);
gsl_matrix_scale(V, V0);
for(size_t i=0; i<DIM; i++) for(size_t j=i+1; j < DIM; j++) {
gsl_matrix_set(V, i, j, 1.0);
gsl_matrix_set(V, j, i, 1.0);
}
p = mcmclib_wishart_lpdf_alloc(V, P);
x = gsl_vector_alloc(DIM * DIM);
gsl_matrix_view X_v = gsl_matrix_view_vector(x, DIM, DIM);
gsl_matrix* X = &(X_v.matrix);
gsl_matrix_set_all(X, 0.2);
for(size_t i=0; i<DIM; i++)
gsl_matrix_set(X, i, i, 1.0);
CuAssertDblEquals(tc, -7.152627, lpdf(1.0), TOL);
CuAssertDblEquals(tc, -29.549142, lpdf(0.5), TOL);
CuAssertDblEquals(tc, 13.380252, lpdf(2.0), TOL);
mcmclib_wishart_lpdf_free(p);
gsl_vector_free(x);
gsl_matrix_free(V);
}
示例6: test_sp_proj_module
void test_sp_proj_module(CuTest* tc)
{
int size = 2;
Image * a = sp_image_alloc(size,size,1);
for(int i = 0;i<sp_image_size(a);i++){
a->image->data[i] = sp_cinit(p_drand48(),p_drand48());
}
Image * exp = sp_image_alloc(size,size,1);
for(int i = 0;i<sp_image_size(a);i++){
exp->image->data[i] = sp_cinit(p_drand48(),0);
}
for(int i = 0;i<sp_image_size(a);i++){
exp->mask->data[i] = 1;
}
Image * proj = sp_proj_module(a,exp,SpOutOfPlace);
for(int i = 0;i<sp_image_size(a);i++){
/* Check that the magnitude is the same as the experimental */
CuAssertDblEquals(tc,sp_cabs(proj->image->data[i]),sp_cabs(exp->image->data[i]),fabs(2*REAL_EPSILON*sp_cabs(exp->image->data[i])));
/* Check that the phase is the same as the input */
CuAssertDblEquals(tc,sp_carg(proj->image->data[i]),sp_carg(a->image->data[i]),fabs(2*REAL_EPSILON*sp_carg(a->image->data[i])));
}
PRINT_DONE;
}
示例7: Testiwishart
void Testiwishart(CuTest* tc) {
/*set a non-trivial location matrix*/
gsl_matrix* V = gsl_matrix_alloc(DIM, DIM);
gsl_matrix_set_identity(V);
gsl_matrix_add_constant(V, 1.0);
p = mcmclib_iwishart_lpdf_alloc(V, P);
x = gsl_vector_alloc(DIM * DIM);
gsl_matrix_view X_v = gsl_matrix_view_vector(x, DIM, DIM);
gsl_matrix* X = &(X_v.matrix);
gsl_matrix_set_identity(X);
gsl_matrix_add_constant(X, 1.0);
/*check for side-effects*/
double tmp = lpdf(1.0);
CuAssertTrue(tc, tmp == lpdf(1.0));
CuAssertDblEquals(tc, -18.188424, lpdf(1.0), TOL);
CuAssertDblEquals(tc, 49.59203, lpdf(0.5), TOL);
CuAssertDblEquals(tc, -88.468878, lpdf(2.0), TOL);
mcmclib_iwishart_lpdf_free(p);
gsl_vector_free(x);
gsl_matrix_free(V);
}
示例8: Test_pw_approx_nonnormal
void Test_pw_approx_nonnormal(CuTest * tc){
printf("Testing function: piecewise_poly_approx on (a,b)\n");
// function
struct Fwrap * fw = fwrap_create(1,"general-vec");
fwrap_set_fvec(fw,Sin3xTx2,NULL);
// approximation
double lb=-3.0, ub=2.0;
struct PwPolyOpts * opts = pw_poly_opts_alloc(LEGENDRE,lb,ub);
size_t N = 15;
double * pts = linspace(lb,ub,N);
pw_poly_opts_set_pts(opts,N,pts);
opoly_t pw = piecewise_poly_approx1(opts,fw);
double lb1 = piecewise_poly_lb(pw->branches[0]);
double ub1 = piecewise_poly_ub(pw->branches[0]);
CuAssertDblEquals(tc,pts[0],lb1,1e-14);
CuAssertDblEquals(tc,pts[1],ub1,1e-14);
// compute error
double abs_err;
double func_norm;
compute_error_vec(lb,ub,1000,pw,Sin3xTx2,NULL,&abs_err,&func_norm);
double err = abs_err / func_norm;
CuAssertDblEquals(tc, 0.0, err, 1e-13);
fwrap_destroy(fw);
POLY_FREE(pw);
pw_poly_opts_free(opts);
free(pts);
}
示例9: test_sorting
void test_sorting(CuTest* tc) {
double flux[] = { 50, 100, 50, 100, 20, 20, 40, 40 };
double bg[] = { 0, 10, 10, 0, 10, 0, 5, 0 };
int trueorder[] = { 4, 5, 7, 6, 2, 0, 1, 3 };
int i, N;
starxy_t* s;
char* infn = "/tmp/test-resort-xylist";
char* outfn = "/tmp/test-resort-xylist-out";
xylist_t* xy;
xylist_t* xy2;
starxy_t* s2;
xy = xylist_open_for_writing(infn);
CuAssertPtrNotNull(tc, xy);
xylist_set_include_flux(xy, TRUE);
xylist_set_include_background(xy, TRUE);
if (xylist_write_primary_header(xy) ||
xylist_write_header(xy)) {
CuFail(tc, "write header");
}
N = sizeof(flux) / sizeof(double);
s = starxy_new(N, TRUE, TRUE);
for (i=0; i<N; i++) {
starxy_setx(s, i, random()%1000);
starxy_sety(s, i, random()%1000);
}
starxy_set_flux_array(s, flux);
starxy_set_bg_array(s, bg);
if (xylist_write_field(xy, s) ||
xylist_fix_header(xy) ||
xylist_fix_primary_header(xy) ||
xylist_close(xy)) {
CuFail(tc, "close xy");
}
CuAssertIntEquals(tc, 0,
resort_xylist(infn, outfn, NULL, NULL, TRUE));
xy2 = xylist_open(outfn);
s2 = xylist_read_field(xy2, NULL);
CuAssertPtrNotNull(tc, s2);
CuAssertPtrNotNull(tc, s2->x);
CuAssertPtrNotNull(tc, s2->y);
CuAssertPtrNotNull(tc, s2->flux);
CuAssertPtrNotNull(tc, s2->background);
for (i=0; i<N; i++) {
CuAssertDblEquals(tc, s->x[trueorder[i]], s2->x[i], 1e-6);
CuAssertDblEquals(tc, s->y[trueorder[i]], s2->y[i], 1e-6);
CuAssertDblEquals(tc, s->flux[trueorder[i]], s2->flux[i], 1e-6);
CuAssertDblEquals(tc, s->background[trueorder[i]], s2->background[i], 1e-6);
}
}
示例10: testMag
void testMag(CuTest* tc) {
vector v;
assign(&v, 0.0, 3.0, 4.0);
CuAssertDblEquals(tc, 5.0, mag(v), DELTA);
assign(&v, 1.0, 1.0, 1.0);
CuAssertDblEquals(tc, sqrt(3.0), mag(v), DELTA);
//vectorFree(v);
}
示例11: testAssign
void testAssign(CuTest* tc) {
vector v;
assign(&v, 1.0, 2.0, 3.0);
CuAssertDblEquals(tc, 1.0, v.x, DELTA);
CuAssertDblEquals(tc, 2.0, v.y, DELTA);
CuAssertDblEquals(tc, 3.0, v.z, DELTA);
//vectorFree(v);
}
示例12: Test_unc6
void Test_unc6(CuTest * tc)
{
printf("////////////////////////////////////////////\n");
printf("\t Unconstrained Test: 6\n");
size_t f1 = 5;
struct UncTestProblem p = tprobs[f1];
size_t dim = unc_test_problem_get_dim(&p);
struct c3Opt * opt = c3opt_alloc(BFGS,dim);
c3opt_add_objective(opt,unc_test_problem_eval,&p);
c3opt_set_verbose(opt,0);
/* c3opt_set_gtol(opt,1e-20); */
/* c3opt_set_absxtol(opt,1e-20); */
/* c3opt_set_relftol(opt,1e-14); */
c3opt_set_maxiter(opt,400);
c3opt_ls_set_maxiter(opt,1000);
double * start = unc_test_problem_get_start(&p);
/* printf("start\n"); */
/* dprint(2,start); */
double gerr = c3opt_check_deriv(opt,start,1e-8);
CuAssertDblEquals(tc,0.0,gerr,1e-5);
/* printf("gerr = %G\n",gerr); */
double val;
int res = c3opt_minimize(opt,start,&val);
CuAssertIntEquals(tc,1,res>=0);
double * soll = unc_test_problem_get_sol(&p);
//minimum
double err = fabs(soll[dim]-val);
if (fabs(soll[dim]) > 1){
err /= fabs(soll[dim]);
}
CuAssertDblEquals(tc,0.0,err,1e-4);
//minimizer
for (size_t ii = 0; ii < dim; ii++){
CuAssertDblEquals(tc,soll[ii],start[ii],1e-2);
}
printf("\t\t *True* Minimum: : %3.6E\n", soll[dim]);
printf("\t\t Minimum Found: : %3.6E\n\n",val);
printf("\t\t Number of Function Evaluations: %zu\n",c3opt_get_nevals(opt));
printf("\t\t Number of Gradient Evaluations: %zu\n",c3opt_get_ngvals(opt));
printf("\t\t Number of iterations: %zu\n",c3opt_get_niters(opt));
printf("////////////////////////////////////////////\n");
c3opt_free(opt); opt = NULL;
}
示例13: test_param_flt
static void test_param_flt(CuTest * tc)
{
struct param *par = 0;
test_cleanup();
CuAssertDblEquals(tc, 13, get_param_flt(par, "foo", 13), 0.01);
set_param(&par, "foo", "23.0");
set_param(&par, "bar", "42.0");
CuAssertDblEquals(tc, 23.0, get_param_flt(par, "foo", 0.0), 0.01);
CuAssertDblEquals(tc, 42.0, get_param_flt(par, "bar", 0.0), 0.01);
}
示例14: testNormalize
void testNormalize(CuTest* tc) {
vector v;
assign(&v, 1.0, 1.0, 1.0);
normalize(&v);
CuAssertDblEquals(tc, 1.0, mag(v), DELTA);
assign(&v, 123.0, -321.0, 1.23);
normalize(&v);
CuAssertDblEquals(tc, 1.0, mag(v), DELTA);
//vectorFree(v);
}
示例15: testCopy
void testCopy(CuTest* tc) {
vector v1;
vector v2;
assign(&v1, 23.23, -99.32, 12334.23);
copy(&v2, v1);
CuAssertDblEquals(tc, v1.x, v2.x, DELTA);
CuAssertDblEquals(tc, v1.y, v2.y, DELTA);
CuAssertDblEquals(tc, v1.z, v2.z, DELTA);
//vectorFree(v1);
//vectorFree(v2);
}