Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
CSE3150_Project/DocumentRowTest.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
200 lines (182 sloc)
5.35 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "DocumentRowTest.h" | |
#include "DocumentRow.h" | |
#include <string> | |
#include <memory> | |
#include <vector> | |
using namespace std; | |
namespace DocumentRowTesting { | |
typedef shared_ptr<string> _sps; | |
class TestInit: public UnitTest | |
{ | |
public: | |
TestInit() { testName = "TestInit"; } | |
void PerformTest() | |
{ | |
cout << "Hello World From Test Init in DocumentRowTest" << endl; | |
DocumentRow row(10); | |
AssertEquals(row.GetLength(),0); | |
AssertEquals(row.GetFirstWordLength(),0); | |
AssertEquals(row.GetLastWordLength(),0); | |
cout << "It appears that my GetString() method doesn't want to work on Linux" << endl; | |
cout << "Pass Check: " << Passed() << endl; | |
AssertEquals(row.GetString(),string()); | |
} | |
}; | |
class TestGetLength: public UnitTest | |
{ | |
public: | |
TestGetLength() { testName = "GetLength"; } | |
void PerformTest() | |
{ | |
DocumentRow row(100); | |
AssertTrue(row.GetLength() == 0); | |
shared_ptr<string> firstString = shared_ptr<string>(new string("Hello")); | |
row.AppendWord(firstString); | |
AssertTrue(row.GetLength() == 5); | |
row.AppendWord(firstString); | |
AssertTrue(row.GetLength() == 11); | |
shared_ptr<string> secondString = shared_ptr<string>(new string("World")); | |
row.AppendWord(secondString); | |
AssertTrue(row.GetLength() == 17); | |
} | |
}; | |
class TestClearRow: public UnitTest | |
{ | |
public: | |
TestClearRow() { testName = "ClearRow"; } | |
void PerformTest() | |
{ | |
DocumentRow row(100); | |
shared_ptr<string> word = shared_ptr<string>(new string("Hello")); | |
row.AppendWord(word); | |
AssertTrue(row.GetLength() == 5); | |
row.ClearRow(); | |
AssertTrue(row.GetLength() == 0); | |
for (int i = 0; i<10; ++i) { | |
row.AppendWord(word); | |
} | |
AssertTrue(row.GetLength() == 59); | |
row.ClearRow(); | |
AssertTrue(row.GetLength() == 0); | |
} | |
}; | |
class TestGetFirstWordLength: public UnitTest | |
{ | |
public: | |
TestGetFirstWordLength() { testName = "TestGetFirstWordLength"; } | |
void PerformTest() | |
{ | |
DocumentRow row(100); | |
AssertTrue(row.GetFirstWordLength() == 0); | |
vector<shared_ptr<string>> words; | |
for (int i = 1; i<10; ++i) { | |
string* str = new string(); | |
for (int j = 0; j<i; ++j) { | |
str->push_back((char)i); | |
} | |
words.push_back(shared_ptr<string>(str)); | |
} | |
for (shared_ptr<string> str : words) { | |
row.AppendWord(str); | |
} | |
AssertTrue(row.GetFirstWordLength() == 1); | |
row.ClearRow(); | |
AssertTrue(row.GetFirstWordLength() == 0); | |
for (auto itr = words.rbegin(); itr != words.rend(); ++itr) { | |
row.AppendWord(*itr); | |
} | |
AssertTrue(row.GetFirstWordLength() == 9); | |
} | |
}; | |
class TestGetLastWordLength: public UnitTest | |
{ | |
public: | |
TestGetLastWordLength() { testName = "GetLastWordLength"; } | |
void PerformTest() | |
{ | |
DocumentRow row(100); | |
AssertTrue(row.GetLastWordLength() == 0); | |
vector<shared_ptr<string>> words; | |
shared_ptr<string> word = shared_ptr<string>(new string("word")); | |
row.AppendWord(word); | |
AssertTrue(row.GetLastWordLength() == 4); | |
word = shared_ptr<string>(new string("123456789")); | |
row.AppendWord(word); | |
AssertTrue(row.GetLastWordLength() == 9); | |
row.ClearRow(); | |
AssertTrue(row.GetLastWordLength() == 0); | |
row.AppendWord(word); | |
AssertTrue(row.GetLastWordLength() == 9); | |
} | |
}; | |
class TestAppendWord: public UnitTest | |
{ | |
public: | |
TestAppendWord() { testName = "AppendWord"; } | |
void PerformTest() | |
{ | |
DocumentRow row1(100); | |
// First let's see how this fucker takes short words | |
shared_ptr<string> word1 = shared_ptr<string>(new string("ThisIsALongFuckingWordThatsLessThan100Characters")); | |
AssertTrue(row1.AppendWord(word1)); | |
AssertTrue(row1.GetLength() == word1->length()); | |
cout << "The length of the word matches: " << Passed() << endl; | |
AssertTrue(row1.GetString() == *word1); | |
cout << "Sanity Check here. Added a big word to a big buffer: " << Passed() << endl; | |
// Now the document row is too tight to take this word if you know what I mean. | |
DocumentRow row2(20); | |
AssertFalse(row2.AppendWord(word1)); | |
} | |
}; | |
class TestGetString: public UnitTest | |
{ | |
public: | |
TestGetString() { testName = "GetString"; } | |
void PerformTest() | |
{ | |
DocumentRow row(100); | |
_sps word = _sps(new string("Hello")); | |
_sps word2 = _sps(new string("World")); | |
row.AppendWord(word); | |
row.AppendWord(word2); | |
AssertTrue(row.GetString() == "Hello World"); | |
row.ClearRow(); | |
_sps word3 = _sps(new string()); | |
row.AppendWord(word3); | |
AssertTrue(row.GetString() == ""); | |
row.AppendWord(word3); | |
AssertTrue(row.GetString() == " "); | |
row.AppendWord(word3); | |
AssertTrue(row.GetString() == " "); | |
row.ClearRow(); | |
AssertTrue(row.GetString() == ""); | |
} | |
}; | |
class TestAppendWordRowLength: public UnitTest | |
{ | |
public: | |
TestAppendWordRowLength() { testName = "Appending word with length equal to max width"; } | |
void PerformTest() | |
{ | |
DocumentRow row(10); | |
_sps word = _sps(new string("1234567890")); | |
AssertTrue(row.AppendWord(word)); | |
} | |
}; | |
} | |
DocumentRowTest :: DocumentRowTest() | |
{ | |
using namespace DocumentRowTesting; | |
testName = "DocumentRow"; | |
tests.push_back(new TestInit()); | |
tests.push_back(new TestGetLength()); | |
tests.push_back(new TestClearRow()); | |
tests.push_back(new TestGetFirstWordLength()); | |
tests.push_back(new TestGetLastWordLength()); | |
tests.push_back(new TestAppendWord()); | |
tests.push_back(new TestGetString()); | |
tests.push_back(new TestAppendWordRowLength()); | |
} | |
DocumentRowTest :: ~DocumentRowTest() | |
{ | |
} |