Skip to content
Permalink
master
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
#include "DocumentPageTest.h"
#include "DocumentPage.h"
#include <iostream>
#include <memory>
using namespace std;
namespace DocumentPageTesting {
typedef shared_ptr<string> _sps;
typedef shared_ptr<DocumentParagraph> _spdp;
class TestInit: public UnitTest
{
public:
TestInit() { testName = "Test initialization"; }
void PerformTest()
{
DocumentPage page(10,10);
AssertEquals(page.GetNumLines(),0);
AssertEquals(page.GetPageNum(),0);
}
};
class TestAppendParagraph: public UnitTest
{
public:
TestAppendParagraph() { testName = "Append Paragraph"; }
void PerformTest()
{
_sps word = _sps(new string("Hello"));
_sps spsd = _sps(new string("sdfhsdf"));
vector<_sps> paragraph = { word, spsd };
DocumentPage page(10,10);
AssertEquals(page.GetNumLines(),0);
AssertEquals(page.AppendParagraph(paragraph,1),2);
AssertEquals(page.GetNumLines(),2);
_sps longWord = _sps(new string("1234567890"));
paragraph.clear();
for (int i = 0; i<10; ++i) {
paragraph.push_back(longWord);
}
AssertEquals(page.AppendParagraph(paragraph,2),8);
AssertEquals(page.GetNumLines(),10);
DocumentPage page2(10,10);
AssertEquals(page2.AppendParagraph(paragraph,1),10);
}
};
class TestGetString: public UnitTest
{
public:
TestGetString() { testName = "Test Getting the string of a paragraph"; }
void PerformTest()
{
DocumentPage page(10,10);
for (int i = 0; i<10; ++i) {
_sps word = _sps(new string(to_string(i)));
vector<_sps> para = { word };
AssertEquals(page.AppendParagraph(para,i),1);
}
cout << "Added ten lines to the page. Pass Check: " << Passed() << endl;
AssertEquals(page.GetNumLines(),10);
cout << "Expected 10 lines from GetNumLines(). Pass Check: " << Passed() << endl;
for (int i = 0; i<10; ++i) {
string str = page.GetLine(i);
cout << "Checking for line: " << i << " Got: " << str << endl;
AssertEquals(page.GetLine(i),to_string(i));
}
vector<_sps> cantAdd = { _sps(new string("10")) };
AssertEquals(page.AppendParagraph(cantAdd,10),0);
}
};
class TestEmptyWordsParagraph: public UnitTest
{
public:
TestEmptyWordsParagraph() { testName = "Paragraph of Empty Words"; }
void PerformTest()
{
DocumentPage page(10,10);
cout << "We want 100 spaces in this paragraph" << endl;
cout << "This will also serve partially as a GetString test" << endl;
_sps word = _sps(new string());
vector<_sps> spaces;
for (int i = 0; i<100; ++i) {
spaces.push_back(word);
}
AssertEquals(page.AppendParagraph(spaces,0),100);
string expected = " ";
for (int i = 0; i<9; ++i) {
cout << "Length of line is :" << page.GetLine(i).length() << endl;
AssertEquals(page.GetLine(i),expected);
}
cout << "Something I just noticed is that 10 of the spaces I expected are trimmed away by the new lines" << endl;
}
};
class TestSanity: public UnitTest
{
public:
TestSanity() { testName = "Just testing out something"; }
void PerformTest()
{
_sps word;
AssertEquals(word,_sps(__null));
}
};
class TestContinueParagraph: public UnitTest
{
public:
TestContinueParagraph() { testName = "Test Continue Paragraph"; }
void PerformTest()
{
DocumentPage page(10,10);
_sps word = _sps(new string("1234567890"));
vector<_sps> splitString;
for (int i = 0; i<20; ++i) {
splitString.push_back(word);
}
AssertEquals(page.AppendParagraph(splitString,0),10);
DocumentPage page2(page);
AssertEquals(page2.GetNumLines(),0);
cout << "Num Lines on new page: " << page2.GetNumLines() << endl;
try {
page2.ContinueParagraph();
} catch (string e) {
cout << "Caught: " << e << endl;
}
splitString.erase(splitString.begin(),splitString.begin()+10);
AssertEquals(page2.AppendParagraph(splitString,0),10);
AssertEquals(page.GetParagraph(0)->GetActualLineCount(),page2.GetParagraph(0)->GetActualLineCount());
}
};
class TestGetParagraphContainingLine: public UnitTest
{
public:
TestGetParagraphContainingLine() { testName = "GetParagraphContainingLine"; }
void PerformTest()
{
DocumentPage page(10,10);
_sps word = _sps(new string("1234"));
vector<_sps> words = {word,word};
vector<_sps> words2 = {word,word,word};
vector<_sps> words3 = {};
page.AppendParagraph(words,0);
page.AppendParagraph(words2,1);
page.AppendParagraph(words3,2);
cout << "Number of Lines in Page: " << page.GetNumLines() << endl;
cout << "Number of Paragraphs in Page: " << page.GetNumParagraphs() << endl;
int lineNum = 3;
_spdp para3 = page.GetParagraphContainingLine(lineNum);
AssertTrue(para3 != __null);
cout << "Pointer to para3 != null: " << Passed() << endl;
AssertEquals(page.GetParagraph(2),para3);
}
};
class TestGetLine: public UnitTest
{
public:
TestGetLine() { testName = "GetLine"; }
void PerformTest()
{
DocumentPage page(10,10);
_sps word1 = _sps(new string("This"));
_sps word2 = _sps(new string());
vector<_sps> words = {word1,word2};
page.AppendParagraph(words,0);
string line = page.GetLine(0);
AssertEquals(line, string("This "));
}
};
}
DocumentPageTest :: DocumentPageTest()
{
using namespace DocumentPageTesting;
testName = "DocumentPage";
tests.push_back(new TestInit());
tests.push_back(new TestAppendParagraph());
tests.push_back(new TestGetString());
tests.push_back(new TestEmptyWordsParagraph());
tests.push_back(new TestSanity());
tests.push_back(new TestContinueParagraph());
tests.push_back(new TestGetParagraphContainingLine());
tests.push_back(new TestGetLine());
}
DocumentPageTest :: ~DocumentPageTest()
{
}