diff options
author | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2012-03-18 08:08:38 +0400 |
---|---|---|
committer | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2012-03-18 08:08:38 +0400 |
commit | 54233d327052793807fc44583334dd3b396176e5 (patch) | |
tree | db01a4c85371b5d9669d2e82e366af42504b42fd /mert/OptimizerFactoryTest.cpp | |
parent | 38c662d4e036558ce07cc4c469d11631b8186be8 (diff) |
Create files for OptimizerFactory class; add the unit test.
Diffstat (limited to 'mert/OptimizerFactoryTest.cpp')
-rw-r--r-- | mert/OptimizerFactoryTest.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/mert/OptimizerFactoryTest.cpp b/mert/OptimizerFactoryTest.cpp new file mode 100644 index 000000000..30734ab67 --- /dev/null +++ b/mert/OptimizerFactoryTest.cpp @@ -0,0 +1,46 @@ +#include "OptimizerFactory.h" +#include "Optimizer.h" + +#define BOOST_TEST_MODULE MertOptimizerFactory +#include <boost/test/unit_test.hpp> +#include <boost/scoped_ptr.hpp> + +namespace { + +inline void CheckBuildOptimizer(unsigned dim, + const vector<unsigned>& to_optimize, + const vector<parameter_t>& start, + const string& type, + unsigned int num_random) { + boost::scoped_ptr<Optimizer> optimizer( + OptimizerFactory::BuildOptimizer(dim, to_optimize, start, type, num_random)); + BOOST_CHECK(optimizer.get() != NULL); +} + +} // namespace + +BOOST_AUTO_TEST_CASE(optimizer_type) { + BOOST_CHECK_EQUAL(OptimizerFactory::GetOptimizerType("powell"), + OptimizerFactory::POWELL); + BOOST_CHECK_EQUAL(OptimizerFactory::GetOptimizerType("random"), + OptimizerFactory::RANDOM); + BOOST_CHECK_EQUAL(OptimizerFactory::GetOptimizerType("random-direction"), + OptimizerFactory::RANDOM_DIRECTION); +} + +BOOST_AUTO_TEST_CASE(optimizer_build) { + const unsigned dim = 3; + std::vector<unsigned> to_optimize; + to_optimize.push_back(1); + to_optimize.push_back(2); + to_optimize.push_back(3); + std::vector<parameter_t> start; + start.push_back(0.3); + start.push_back(0.1); + start.push_back(0.2); + const unsigned int num_random = 1; + + CheckBuildOptimizer(dim, to_optimize, start, "powell", num_random); + CheckBuildOptimizer(dim, to_optimize, start, "random", num_random); + CheckBuildOptimizer(dim, to_optimize, start, "random-direction", num_random); +} |