-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoah_test.cpp
More file actions
107 lines (86 loc) · 2.71 KB
/
Copy pathnoah_test.cpp
File metadata and controls
107 lines (86 loc) · 2.71 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 <memory>
using std::shared_ptr;
using std::make_shared;
#include <iostream>
using std::cout;
using std::endl;
#include <string>
using std::string;
#include <sstream>
using std::stringstream;
using std::fstream;
using std::ifstream;
using std::ofstream;
#include <cstdio>
using std::remove;
#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/ScaledShape.h"
#include "classes/RotatedShape.h"
#include "classes/Triangle.h"
#include "classes/Square.h"
#include "classes/Spacer.h"
#include "classes/Star.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
Triangle triangle1(72);
Square square1(72);
Spacer spacer1(72,72);
Star star1(72);
RotatedShape rotatedpolygon1(make_shared<Polygon>(polygon1), Ninety);
ScaledShape scaledpolygon1(make_shared<Polygon>(polygon1), 2, 2);
RotatedShape rotatedscaledpolygon1(make_shared<ScaledShape>(scaledpolygon1), Ninety);
ScaledShape scaledrotatedscaledpolygon1(make_shared<RotatedShape>(rotatedscaledpolygon1), 0.1, 0.1);
//Circle circle1(72); // radius is 72
//Rectangle rectangle1(72, 144); // width 72, height 144
string fileName = "experiment.ps";
if(ifstream(fileName)) // if the file exists
{
remove("experiment.ps"); // delete it
}
writePostScriptToFile(&polygon1, fileName);
writePostScriptToFile(&triangle1, fileName);
writePostScriptToFile(&square1, fileName);
writePostScriptToFile(&spacer1, fileName);
writePostScriptToFile(&star1, fileName);
writePostScriptToFile(&rotatedpolygon1, fileName);
writePostScriptToFile(&scaledpolygon1, fileName);
writePostScriptToFile(&rotatedscaledpolygon1, fileName);
writePostScriptToFile(&scaledrotatedscaledpolygon1, 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);
}