Skip to content

Commit

Permalink
Add more tests for FunctionType MethodForms
Browse files Browse the repository at this point in the history
  • Loading branch information
shikharbhardwaj committed Oct 23, 2017
1 parent f38aebe commit 4eb730d
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion src/mlpack/tests/functiontype_method_forms_test.cpp
Expand Up @@ -27,16 +27,22 @@ class A
{
public:
size_t NumFunctions() const;
size_t NumFeatures() const;
double Evaluate(const arma::mat&, const size_t) const;
void Gradient(const arma::mat&, const size_t, arma::mat&) const;
void Gradient(const arma::mat&, const size_t, arma::sp_mat&) const;
void PartialGradient(const arma::mat&, const size_t, arma::sp_mat&) const;
};

class B
{
public:
size_t NumFunctions();
size_t NumFeatures();
double Evaluate(const arma::mat&, const size_t);
void Gradient(const arma::mat&, const size_t, arma::mat&);
void Gradient(const arma::mat&, const size_t, arma::sp_mat&);
void PartialGradient(const arma::mat&, const size_t, arma::sp_mat&);
};

class C
Expand All @@ -63,7 +69,6 @@ class D
/**
* Test the correctness of the static check for DecomposableFunctionType API.
*/

BOOST_AUTO_TEST_CASE(DecomposableFunctionTypeCheckTest)
{
static_assert(CheckNumFunctions<A>::value,
Expand Down Expand Up @@ -94,6 +99,9 @@ BOOST_AUTO_TEST_CASE(DecomposableFunctionTypeCheckTest)
"CheckDecomposableGradient static check failed.");
}

/**
* Test the correctness of the static check for LagrangianFunctionType API.
*/
BOOST_AUTO_TEST_CASE(LagrangianFunctionTypeCheckTest)
{
static_assert(!CheckEvaluate<A>::value, "CheckEvaluate static check failed.");
Expand Down Expand Up @@ -134,4 +142,43 @@ BOOST_AUTO_TEST_CASE(LagrangianFunctionTypeCheckTest)
"CheckGradientConstraint static check failed.");
}

/**
* Test the correctness of the static check for SparseFunctionType API.
*/
BOOST_AUTO_TEST_CASE(SparseFunctionTypeCheckTest)
{
static_assert(CheckSparseGradient<A>::value,
"CheckSparseGradient static check failed.");
static_assert(CheckSparseGradient<B>::value,
"CheckSparseGradient static check failed.");
static_assert(!CheckSparseGradient<C>::value,
"CheckSparseGradient static check failed.");
static_assert(!CheckSparseGradient<D>::value,
"CheckSparseGradient static check failed.");
}

/**
* Test the correctness of the static check for SparseFunctionType API.
*/
BOOST_AUTO_TEST_CASE(ResolvableFunctionTypeCheckTest)
{
static_assert(CheckNumFeatures<A>::value,
"CheckNumFeatures static check failed.");
static_assert(CheckNumFeatures<B>::value,
"CheckNumFeatures static check failed.");
static_assert(!CheckNumFeatures<C>::value,
"CheckNumFeatures static check failed.");
static_assert(!CheckNumFeatures<D>::value,
"CheckNumFeatures static check failed.");

static_assert(CheckPartialGradient<A>::value,
"CheckPartialGradient static check failed.");
static_assert(CheckPartialGradient<B>::value,
"CheckPartialGradient static check failed.");
static_assert(!CheckPartialGradient<C>::value,
"CheckPartialGradient static check failed.");
static_assert(!CheckPartialGradient<D>::value,
"CheckPartialGradient static check failed.");
}

BOOST_AUTO_TEST_SUITE_END();

0 comments on commit 4eb730d

Please sign in to comment.