00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "DomainFeature.h"
00021 #include "ScoreFeature.h"
00022 #include "tables-core.h"
00023
00024 #define BOOST_TEST_MODULE MosesTrainingScoreFeature
00025 #include <boost/test/test_tools.hpp>
00026 #include <boost/test/unit_test.hpp>
00027 #include <boost/assign/list_of.hpp>
00028
00029 #include <unordered_set>
00030 #include <unordered_map>
00031
00032 using namespace MosesTraining;
00033 using namespace std;
00034
00035
00036 namespace MosesTraining
00037 {
00038 bool hierarchicalFlag = false;
00039 Vocabulary vcbT;
00040 Vocabulary vcbS;
00041 }
00042
00043
00044 const char *DomainFileLocation()
00045 {
00046 if (boost::unit_test::framework::master_test_suite().argc < 2) {
00047 return "test.domain";
00048 }
00049 return boost::unit_test::framework::master_test_suite().argv[1];
00050 }
00051
00052
00053 BOOST_AUTO_TEST_CASE(manager_configure_domain_except)
00054 {
00055
00056 ScoreFeatureManager manager;
00057 BOOST_CHECK_THROW(
00058 manager.configure(boost::assign::list_of("--DomainRatio")("/dev/null")("--DomainIndicator")("/dev/null")),
00059 ScoreFeatureArgumentException);
00060 BOOST_CHECK_THROW(
00061 manager.configure(boost::assign::list_of("--SparseDomainSubset")("/dev/null")("--SparseDomainRatio")("/dev/null")),
00062 ScoreFeatureArgumentException);
00063 BOOST_CHECK_THROW(
00064 manager.configure(boost::assign::list_of("--SparseDomainBlah")("/dev/null")),
00065 ScoreFeatureArgumentException);
00066 BOOST_CHECK_THROW(
00067 manager.configure(boost::assign::list_of("--DomainSubset")),
00068 ScoreFeatureArgumentException);
00069 }
00070
00071 template <class Expected>
00072 static void checkDomainConfigured(
00073 const vector<string>& args)
00074 {
00075 ScoreFeatureManager manager;
00076 manager.configure(args);
00077 const std::vector<ScoreFeaturePtr>& features = manager.getFeatures();
00078
00079
00080 BOOST_REQUIRE_EQUAL(features.size(), 1);
00081 Expected* feature = dynamic_cast<Expected*>(features[0].get());
00082 BOOST_REQUIRE(feature);
00083 BOOST_CHECK(manager.includeSentenceId());
00084 }
00085
00086 template<typename T>
00087 T adder(T v)
00088 {
00089 return v;
00090 }
00091
00092 template<typename T, typename... Args>
00093 T adder(T first, Args... args)
00094 {
00095 return first + adder(args...);
00096 }
00097
00098
00099 BOOST_AUTO_TEST_CASE(manager_config_domain)
00100 {
00101 checkDomainConfigured<RatioDomainFeature>
00102 (boost::assign::list_of("--DomainRatio")("/dev/null"));
00103 checkDomainConfigured<IndicatorDomainFeature>
00104 (boost::assign::list_of("--DomainIndicator")("/dev/null"));
00105 checkDomainConfigured<SubsetDomainFeature>
00106 (boost::assign::list_of("--DomainSubset")("/dev/null"));
00107 checkDomainConfigured<SparseRatioDomainFeature>
00108 (boost::assign::list_of("--SparseDomainRatio")("/dev/null"));
00109 checkDomainConfigured<SparseIndicatorDomainFeature>
00110 (boost::assign::list_of("--SparseDomainIndicator")("/dev/null"));
00111 checkDomainConfigured<SparseSubsetDomainFeature>
00112 (boost::assign::list_of("--SparseDomainSubset")("/dev/null"));
00113
00114
00115 unordered_set<int> s;
00116 s.insert(4);
00117 s.insert(7);
00118 s.insert(4);
00119 s.insert(1);
00120
00121 for (auto i: s) {
00122 cerr << i << " ";
00123 }
00124
00125 unordered_map<std::string, int> m;
00126 m["a"] = 4;
00127 m["ba"] = 6;
00128 m["aabc"] = 7;
00129
00130 for (auto i: m) {
00131 cerr << i.first << "=" << i.second << " ";
00132 }
00133
00134 long sum = adder(1, 2, 3, 8, 7);
00135
00136 std::string s1 = "x", s2 = "aa", s3 = "bb", s4 = "yy";
00137 std::string ssum = adder(s1, s2, s3, s4);
00138
00139 }
00140