From 5530575ae0ad939e17f08d6bd49978acea388ab7 Mon Sep 17 00:00:00 2001 From: Paul Baltescu Date: Mon, 28 Jan 2013 11:56:31 +0000 Subject: Initial working commit. --- extractor/phrase_test.cc | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 extractor/phrase_test.cc (limited to 'extractor/phrase_test.cc') diff --git a/extractor/phrase_test.cc b/extractor/phrase_test.cc new file mode 100644 index 00000000..2b553b6f --- /dev/null +++ b/extractor/phrase_test.cc @@ -0,0 +1,61 @@ +#include + +#include +#include + +#include "mocks/mock_vocabulary.h" +#include "phrase.h" +#include "phrase_builder.h" + +using namespace std; +using namespace ::testing; + +namespace { + +class PhraseTest : public Test { + protected: + virtual void SetUp() { + shared_ptr vocabulary = make_shared(); + EXPECT_CALL(*vocabulary, GetTerminalValue(_)) + .WillRepeatedly(Return("word")); + shared_ptr phrase_builder = + make_shared(vocabulary); + + symbols1 = vector{1, 2, 3}; + phrase1 = phrase_builder->Build(symbols1); + symbols2 = vector{1, 2, -1, 3, -2, 4}; + phrase2 = phrase_builder->Build(symbols2); + } + + vector 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)); + } +} + +} // namespace -- cgit v1.2.3