From 3219aaf89f0c08c5ac18da6338a3df87b1e5dd3f Mon Sep 17 00:00:00 2001 From: Paul Baltescu Date: Wed, 6 Mar 2013 17:35:49 +0000 Subject: Added 3 missing unit tests. --- extractor/phrase.cc | 2 +- extractor/phrase.h | 5 +---- extractor/phrase_test.cc | 24 ++++++++++++++++++++++-- 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 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 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 vocabulary = make_shared(); - EXPECT_CALL(*vocabulary, GetTerminalValue(_)) - .WillRepeatedly(Return("word")); + vector 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 phrase_builder = make_shared(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 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 -- cgit v1.2.3