void testCase4() { string words_[] = {"oneword"}; vector<string> words(words_, words_ + (sizeof(words_) / sizeof(words_[0]))); string expected__[] = {"o"}; vector<string> expected_(expected__, expected__ + (sizeof(expected__) / sizeof(expected__[0]))); assertEquals(4, expected_, solution.getAbbreviations(words)); }
void testCase2() { string words_[] = {"top", "coder", "contest"}; vector<string> words(words_, words_ + (sizeof(words_) / sizeof(words_[0]))); string expected__[] = {"t", "cod", "con"}; vector<string> expected_(expected__, expected__ + (sizeof(expected__) / sizeof(expected__[0]))); assertEquals(2, expected_, solution.getAbbreviations(words)); }
void testCase3() { string words_[] = {"bababaaaaa", "baaabaababa", "bbabaaabbaaabbabaabaabbbbbaabb", "aaababababbbbababbbaabaaaaaaaabbabbbaaab", "baaaaabaababbbaabbbabbababbbabbbbbbbbab"}; vector<string> words(words_, words_ + (sizeof(words_) / sizeof(words_[0]))); string expected__[] = {"bab", "baaab", "bb", "a", "baaaa"}; vector<string> expected_(expected__, expected__ + (sizeof(expected__) / sizeof(expected__[0]))); assertEquals(3, expected_, solution.getAbbreviations(words)); }
void testCase0() { string words_[] = {"abc", "def", "ghi"}; vector<string> words(words_, words_ + (sizeof(words_) / sizeof(words_[0]))); string expected__[] = {"a", "d", "g"}; vector<string> expected_(expected__, expected__ + (sizeof(expected__) / sizeof(expected__[0]))); assertEquals(0, expected_, solution.getAbbreviations(words)); }
double test3() { string t0[] = { "bababaaaaa", "baaabaababa", "bbabaaabbaaabbabaabaabbbbbaabb", "aaababababbbbababbbaabaaaaaaaabbabbbaaab", "baaaaabaababbbaabbbabbababbbabbbbbbbbab" }; vector <string> p0(t0, t0+sizeof(t0)/sizeof(string)); WordAbbreviation * obj = new WordAbbreviation(); clock_t start = clock(); vector <string> my_answer = obj->getAbbreviations(p0); clock_t end = clock(); delete obj; cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl; string t1[] = {"bab", "baaab", "bb", "a", "baaaa" }; vector <string> p1(t1, t1+sizeof(t1)/sizeof(string)); cout <<"Desired answer: " <<endl; cout <<"\t{ "; if (p1.size() > 0) { cout <<"\""<<p1[0]<<"\""; for (int i=1; i<p1.size(); i++) cout <<", \"" <<p1[i]<<"\""; cout <<" }" <<endl; } else cout <<"}" <<endl; cout <<endl <<"Your answer: " <<endl; cout <<"\t{ "; if (my_answer.size() > 0) { cout <<"\""<<my_answer[0]<<"\""; for (int i=1; i<my_answer.size(); i++) cout <<", \"" <<my_answer[i]<<"\""; cout <<" }" <<endl; } else cout <<"}" <<endl; if (my_answer != p1) { cout <<"DOESN'T MATCH!!!!" <<endl <<endl; return -1; } else { cout <<"Match :-)" <<endl <<endl; return (double)(end-start)/CLOCKS_PER_SEC; } }