//--------------------------------------------------------------------------- // @function: // CCostTest::EresUnittest_Arithmetic // // @doc: // Test arithmetic operations // //--------------------------------------------------------------------------- GPOS_RESULT CCostTest::EresUnittest_Arithmetic() { CAutoMemoryPool amp; IMemoryPool *mp = amp.Pmp(); CCost cost1(2.5); CCost cost2(3.0); CCost cost3(5.49); CCost cost4(5.51); CCost cost5(7.49); CCost cost6(7.51); CCost costAdd(cost1 + cost2); CCost costMultiply(cost1 * cost2); GPOS_ASSERT(costAdd > cost3); GPOS_ASSERT(costAdd < cost4); GPOS_ASSERT(costMultiply > cost5); GPOS_ASSERT(costMultiply < cost6); CAutoTrace at(mp); IOstream &os(at.Os()); os << "Arithmetic operations: " << std::endl << cost1 << " + " << cost2 << " = " << costAdd << std::endl << cost1 << " * " << cost2 << " = " << costMultiply << std::endl; return GPOS_OK; }
static ERL_NIF_TERM cost3_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { double x,y,z,ret; if (!enif_get_double(env, argv[0], &x)) { return enif_make_badarg(env); } if (!enif_get_double(env, argv[1], &y)) { return enif_make_badarg(env); } if (!enif_get_double(env, argv[2], &z)) { return enif_make_badarg(env); } ret = cost3(x,y,z); return enif_make_double(env, ret); }