00001 #include "FeatureData.h"
00002
00003 #define BOOST_TEST_MODULE FeatureData
00004 #include <boost/test/unit_test.hpp>
00005
00006 #include <sstream>
00007
00008 using namespace MosesTuning;
00009
00010 namespace
00011 {
00012
00013 void CheckFeatureMap(const FeatureData* feature_data,
00014 const char* str, int num_feature, int* cnt)
00015 {
00016 for (int i = 0; i < num_feature; ++i) {
00017 std::stringstream ss;
00018 ss << str << "_" << i;
00019 const std::string& s = ss.str();
00020 BOOST_CHECK_EQUAL(feature_data->getFeatureIndex(s), (std::size_t)(*cnt));
00021 BOOST_CHECK_EQUAL(feature_data->getFeatureName(*cnt).c_str(), s);
00022 ++(*cnt);
00023 }
00024 }
00025
00026 }
00027
00028 BOOST_AUTO_TEST_CASE(set_feature_map)
00029 {
00030 std::string str("d_0 d_1 d_2 d_3 d_4 d_5 d_6 lm_0 lm_1 tm_0 tm_1 tm_2 tm_3 tm_4 w_0 ");
00031 FeatureData feature_data;
00032
00033 feature_data.setFeatureMap(str);
00034
00035 BOOST_REQUIRE(feature_data.Features() == str);
00036 BOOST_REQUIRE(feature_data.NumberOfFeatures() == 15);
00037
00038 int cnt = 0;
00039 CheckFeatureMap(&feature_data, "d", 7, &cnt);
00040 CheckFeatureMap(&feature_data, "lm", 2, &cnt);
00041 CheckFeatureMap(&feature_data, "tm", 5, &cnt);
00042
00043 BOOST_CHECK_EQUAL(feature_data.getFeatureIndex("w_0"), (std::size_t)cnt);
00044 BOOST_CHECK_EQUAL(feature_data.getFeatureName(cnt).c_str(), "w_0");
00045 }