-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwill_test.cpp
More file actions
107 lines (84 loc) · 2.9 KB
/
Copy pathwill_test.cpp
File metadata and controls
107 lines (84 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// CS 372 Project 2
// CPS: C++ to PostScript
// Noah Betzen, William Showalter, Saira Walia
// test.cpp
// main.cpp is the release suite
// test.cpp is the test/debug suite
#define CATCH_CONFIG_MAIN
#include "Catch/single_include/catch.hpp"
#include <iostream>
using std::cout;
using std::endl;
#include <string>
using std::string;
#include <sstream>
using std::stringstream;
using std::ifstream;
using std::ofstream;
#include <cstdio>
using std::remove;
#include <memory>
using std::make_shared;
using std::make_unique;
using std::shared_ptr;
#include "classes/Shape.h"
#include "classes/CompoundShape.h"
#include "classes/Polygon.h"
#include "classes/Rectangle.h"
#include "classes/Circle.h"
#include "classes/ShapeDecorator.h"
#include "classes/Layered.h"
#include "classes/Horizontal.h"
#include "classes/Vertical.h"
void writePostScriptToFile(Shape *shape, string fileName)
{
stringstream shapePostScript(shape->getPostScript());
ofstream outputFile(fileName, std::ios_base::app);
string temp;
while (std::getline(shapePostScript,temp))
{
outputFile << temp << "\n";
}
outputFile << "showpage\n\n";
outputFile.close();
}
TEST_CASE("Implement C++ to PostScript.", "CPS")
{
Shape::flipDrawBoundingBox(); // turns on drawing of bounding boxes
Polygon polygon1(9, 72); // 9 sides, each side is 72 in length
Polygon polygon2(13, 72); // 9 sides, each side is 72 in length
Circle circle1(72); // radius is 72
Rectangle rectangle1(72, 144); // width 72, height 144
shared_ptr<Shape> layered1 = make_shared<Layered>(std::initializer_list<shared_ptr<Shape>>
({make_shared<Circle>(72), make_shared<Polygon>(9,72)}));
shared_ptr<Shape> vertical1 = make_shared<Vertical>(std::initializer_list<shared_ptr<Shape>>
({make_shared<Circle>(72/2), make_shared<Polygon>(9,72/2),
make_shared<Rectangle>(72/2,144/2), make_shared<Polygon>(5,72/2)}));
shared_ptr<Shape> horizontal1 = make_shared<Horizontal>(std::initializer_list<shared_ptr<Shape>>
({make_shared<Circle>(72/2), make_shared<Polygon>(9,72/2),
make_shared<Rectangle>(72/2,144/2), make_shared<Polygon>(5,72/2)}));
shared_ptr<Shape> horizontalVerticalStack =
make_shared<Horizontal>(std::initializer_list<shared_ptr<Shape>>
({horizontal1,vertical1}));
string fileName = "experiment.ps";
if(ifstream(fileName)) // if the file exists
{
remove("experiment.ps"); // delete it
}
// writePostScriptToFile(layered1.get(), fileName);
writePostScriptToFile(horizontal1.get(), fileName);
writePostScriptToFile(vertical1.get(), fileName);
writePostScriptToFile(horizontalVerticalStack.get(), fileName);
// writePostScriptToFile(&polygon1, fileName);
// writePostScriptToFile(&polygon2, fileName);
// writePostScriptToFile(&circle1, fileName);
// writePostScriptToFile(&rectangle1, fileName);
/*Shape *polygon;
for(int i=0; i<100; ++i)
{
polygon = new Polygon(i, 72);
writePostScriptToFile(polygon, fileName);
delete polygon;
}*/
REQUIRE(0==0);
}