summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Baltescu <pauldb89@gmail.com>2013-03-06 17:35:49 +0000
committerPaul Baltescu <pauldb89@gmail.com>2013-03-06 17:35:49 +0000
commit3219aaf89f0c08c5ac18da6338a3df87b1e5dd3f (patch)
treec1aae95dda98600758f69eea21d24086e1ccf6c3
parent4a331030632d9a818f1853a5afed20b9f14e354a (diff)
Added 3 missing unit tests.
-rw-r--r--extractor/phrase.cc2
-rw-r--r--extractor/phrase.h5
-rw-r--r--extractor/phrase_test.cc24
3 files changed, 24 insertions, 7 deletions
diff --git a/extractor/phrase.cc b/extractor/phrase.cc
index 244fab07..e619bfe5 100644
--- a/extractor/phrase.cc
+++ b/extractor/phrase.cc
@@ -34,7 +34,7 @@ vector<string> Phrase::GetWords() const {
return words;
}
-int Phrase::operator<(const Phrase& other) const {
+bool Phrase::operator<(const Phrase& other) const {
return symbols < other.symbols;
}
diff --git a/extractor/phrase.h b/extractor/phrase.h
index 8c98a025..6521c438 100644
--- a/extractor/phrase.h
+++ b/extractor/phrase.h
@@ -23,14 +23,11 @@ class Phrase {
int GetSymbol(int position) const;
- //TODO(pauldb): Unit test this method.
int GetNumSymbols() const;
- //TODO(pauldb): Add unit tests.
vector<string> GetWords() const;
- //TODO(pauldb): Add unit tests.
- int operator<(const Phrase& other) const;
+ bool operator<(const Phrase& other) const;
friend ostream& operator<<(ostream& os, const Phrase& phrase);
diff --git a/extractor/phrase_test.cc b/extractor/phrase_test.cc
index c8176178..3ba9368a 100644
--- a/extractor/phrase_test.cc
+++ b/extractor/phrase_test.cc
@@ -17,8 +17,11 @@ class PhraseTest : public Test {
protected:
virtual void SetUp() {
shared_ptr<MockVocabulary> vocabulary = make_shared<MockVocabulary>();
- EXPECT_CALL(*vocabulary, GetTerminalValue(_))
- .WillRepeatedly(Return("word"));
+ vector<string> words = {"w1", "w2", "w3", "w4"};
+ for (size_t i = 0; i < words.size(); ++i) {
+ EXPECT_CALL(*vocabulary, GetTerminalValue(i + 1))
+ .WillRepeatedly(Return(words[i]));
+ }
shared_ptr<PhraseBuilder> phrase_builder =
make_shared<PhraseBuilder>(vocabulary);
@@ -59,5 +62,22 @@ TEST_F(PhraseTest, TestGetSymbol) {
}
}
+TEST_F(PhraseTest, TestGetNumSymbols) {
+ EXPECT_EQ(3, phrase1.GetNumSymbols());
+ EXPECT_EQ(6, phrase2.GetNumSymbols());
+}
+
+TEST_F(PhraseTest, TestGetWords) {
+ vector<string> expected_words = {"w1", "w2", "w3"};
+ EXPECT_EQ(expected_words, phrase1.GetWords());
+ expected_words = {"w1", "w2", "w3", "w4"};
+ EXPECT_EQ(expected_words, phrase2.GetWords());
+}
+
+TEST_F(PhraseTest, TestComparator) {
+ EXPECT_FALSE(phrase1 < phrase2);
+ EXPECT_TRUE(phrase2 < phrase1);
+}
+
} // namespace
} // namespace extractor