summaryrefslogtreecommitdiff
path: root/extractor
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
commitfa9a4f72cb1fc8de823a11db4e510fccbe1c3532 (patch)
tree4aaf11038e8c91e5903d06c6f6e81239476c6f91 /extractor
parentde708edda64bf210f99a85deba9fe35af41856b0 (diff)
Added 3 missing unit tests.
Diffstat (limited to 'extractor')
-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