Exemple #1
0
//---------------------------------------------------------------------------
//	@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;
}
Exemple #2
0
static ERL_NIF_TERM cost5_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    double x1,x2,x3,x4,x5,ret;
    if (!enif_get_double(env, argv[0], &x1)) {
		return enif_make_badarg(env);
    }
    if (!enif_get_double(env, argv[1], &x2)) {
		return enif_make_badarg(env);
    }
    if (!enif_get_double(env, argv[2], &x3)) {
		return enif_make_badarg(env);
    }
    if (!enif_get_double(env, argv[2], &x4)) {
		return enif_make_badarg(env);
    }
    if (!enif_get_double(env, argv[2], &x5)) {
		return enif_make_badarg(env);
    }
    ret = cost5(x1,x2,x3,x4,x5);
    return enif_make_double(env, ret);
}