00001 #include "Util.h" 00002 00003 #define BOOST_TEST_MODULE UtilTest 00004 #include <boost/test/unit_test.hpp> 00005 00006 using namespace MosesTuning; 00007 00008 BOOST_AUTO_TEST_CASE(util_get_next_pound_test) 00009 { 00010 { 00011 std::string str("9 9 7 "); 00012 std::string substr; 00013 std::vector<std::string> res; 00014 00015 while (!str.empty()) { 00016 getNextPound(str, substr); 00017 res.push_back(substr); 00018 } 00019 BOOST_REQUIRE(res.size() == 3); 00020 BOOST_CHECK_EQUAL("9", res[0]); 00021 BOOST_CHECK_EQUAL("9", res[1]); 00022 BOOST_CHECK_EQUAL("7", res[2]); 00023 } 00024 00025 { 00026 std::string str("ref.0,ref.1,ref.2"); 00027 std::string substr; 00028 std::vector<std::string> res; 00029 const std::string delim(","); 00030 00031 while (!str.empty()) { 00032 getNextPound(str, substr, delim); 00033 res.push_back(substr); 00034 } 00035 BOOST_REQUIRE(res.size() == 3); 00036 BOOST_CHECK_EQUAL("ref.0", res[0]); 00037 BOOST_CHECK_EQUAL("ref.1", res[1]); 00038 BOOST_CHECK_EQUAL("ref.2", res[2]); 00039 } 00040 } 00041 00042 BOOST_AUTO_TEST_CASE(util_tokenize_test) 00043 { 00044 { 00045 std::vector<std::string> res; 00046 Tokenize("9 9 7", ' ', &res); 00047 BOOST_REQUIRE(res.size() == 3); 00048 BOOST_CHECK_EQUAL("9", res[0]); 00049 BOOST_CHECK_EQUAL("9", res[1]); 00050 BOOST_CHECK_EQUAL("7", res[2]); 00051 } 00052 00053 { 00054 std::vector<std::string> res; 00055 Tokenize("9 8 7 ", ' ', &res); 00056 BOOST_REQUIRE(res.size() == 3); 00057 BOOST_CHECK_EQUAL("9", res[0]); 00058 BOOST_CHECK_EQUAL("8", res[1]); 00059 BOOST_CHECK_EQUAL("7", res[2]); 00060 } 00061 00062 { 00063 std::vector<std::string> res; 00064 Tokenize("ref.0,ref.1,", ',', &res); 00065 BOOST_REQUIRE(res.size() == 2); 00066 BOOST_CHECK_EQUAL("ref.0", res[0]); 00067 BOOST_CHECK_EQUAL("ref.1", res[1]); 00068 } 00069 } 00070 00071 BOOST_AUTO_TEST_CASE(util_ends_with_test) 00072 { 00073 BOOST_CHECK(EndsWith("abc:", ":")); 00074 BOOST_CHECK(EndsWith("a b c:", ":")); 00075 BOOST_CHECK(!EndsWith("a", ":")); 00076 BOOST_CHECK(!EndsWith("a:b", ":")); 00077 00078 BOOST_CHECK(EndsWith("ab ", " ")); 00079 BOOST_CHECK(!EndsWith("ab", " ")); 00080 BOOST_CHECK(!EndsWith("a b", " ")); 00081 }