diff options
author | Chris Dyer <cdyer@allegro.clab.cs.cmu.edu> | 2013-04-23 19:35:18 -0400 |
---|---|---|
committer | Chris Dyer <cdyer@allegro.clab.cs.cmu.edu> | 2013-04-23 19:35:18 -0400 |
commit | c164dc0ed8a32e4095ba1b36495e0f743b8cc1ea (patch) | |
tree | 78b81e4c63adfa67adb7b8f80c3e6be87b4a2b2a /extractor/phrase_test.cc | |
parent | 0e46089cafa4e8e2f060e370d7afaceeda6b90a9 (diff) | |
parent | d467e14b28085809c31431be0478eb3d9322fe96 (diff) |
merge paul's extractor code
Diffstat (limited to 'extractor/phrase_test.cc')
-rw-r--r-- | extractor/phrase_test.cc | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/extractor/phrase_test.cc b/extractor/phrase_test.cc new file mode 100644 index 00000000..3ba9368a --- /dev/null +++ b/extractor/phrase_test.cc @@ -0,0 +1,83 @@ +#include <gtest/gtest.h> + +#include <memory> +#include <vector> + +#include "mocks/mock_vocabulary.h" +#include "phrase.h" +#include "phrase_builder.h" + +using namespace std; +using namespace ::testing; + +namespace extractor { +namespace { + +class PhraseTest : public Test { + protected: + virtual void SetUp() { + shared_ptr<MockVocabulary> vocabulary = make_shared<MockVocabulary>(); + 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); + + symbols1 = vector<int>{1, 2, 3}; + phrase1 = phrase_builder->Build(symbols1); + symbols2 = vector<int>{1, 2, -1, 3, -2, 4}; + phrase2 = phrase_builder->Build(symbols2); + } + + vector<int> symbols1, symbols2; + Phrase phrase1, phrase2; +}; + +TEST_F(PhraseTest, TestArity) { + EXPECT_EQ(0, phrase1.Arity()); + EXPECT_EQ(2, phrase2.Arity()); +} + +TEST_F(PhraseTest, GetChunkLen) { + EXPECT_EQ(3, phrase1.GetChunkLen(0)); + + EXPECT_EQ(2, phrase2.GetChunkLen(0)); + EXPECT_EQ(1, phrase2.GetChunkLen(1)); + EXPECT_EQ(1, phrase2.GetChunkLen(2)); +} + +TEST_F(PhraseTest, TestGet) { + EXPECT_EQ(symbols1, phrase1.Get()); + EXPECT_EQ(symbols2, phrase2.Get()); +} + +TEST_F(PhraseTest, TestGetSymbol) { + for (size_t i = 0; i < symbols1.size(); ++i) { + EXPECT_EQ(symbols1[i], phrase1.GetSymbol(i)); + } + for (size_t i = 0; i < symbols2.size(); ++i) { + EXPECT_EQ(symbols2[i], phrase2.GetSymbol(i)); + } +} + +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 |