-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.cpp
736 lines (655 loc) · 24.7 KB
/
test.cpp
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include <string>
using std::string;
using std::make_pair;
#include <random>
using std::mt19937;
using std::random_device;
using std::uniform_real_distribution;
using std::uniform_int_distribution;
#include <algorithm>
using std::swap;
#include "rectangle.h"
#include "polygon.h"
#include "spacer.h"
#include "circle.h"
//Complex Shapes
#include "layered.h"
#include "rotate.h"
#include "star.h" //Our custom shape
#include "scaled.h"
/* utils.h test functions
Functions to test utils.h functionality
Calling these functions should return the same thing
corresponding utils.h function.
*/
//error in doubles
const double ERROR = 0.0000001;
string testPsLine(int x, int y)
{
return to_string(x)+ " "+ to_string(y)+ " lineto\n" ;
}
string testPsMove (int x, int y)
{
return to_string(x) + " " + to_string(y) + " moveto\n";
}
string testPsArc(int x, int y, double r, int startAngle, int endAngle )
{
return to_string(x)+" "+ to_string(y)+" "+ to_string(r)+ " "+ to_string(startAngle) + " "+to_string(endAngle) + " arc\n";
}
string testPsHeader (int x, int y)
{
return "gsave\nnewpath\n" + to_string(x) + " " + to_string(y) + " " + "translate\n";
}
string testPsFooter ()
{
return "closepath\nstroke\ngrestore\n";
}
double testCalcX(int k, int n, double l)
{
return (l/2)*(sin(((2*k+1)*M_PI)/n)/(sin(M_PI/n)));
}
double testCalcY(int k, int n, double l)
{
return (-l/2)*(cos(((2*k+1)*M_PI)/n)/(sin(M_PI/n)));
}
double testGetwidth (int sides, double len)
{
if (sides % 2 !=0)
{
return (len * (sin( M_PI * (sides-1) / ( 2*sides )))/(sin(M_PI/sides)));
}
else
{
if (sides % 4 != 0)
{
return (len*(1/(sin(M_PI/sides))));
}
else
{
return (len*((cos(M_PI/sides))/(sin(M_PI/sides))));
}
}
}
double testGetHeight(int n,double l){
if(n%2 == 0){
return (l * (cos(M_PI/n)) / (sin(M_PI/n)));
} else {
return (l * (1+cos(M_PI/n)) / (2*sin(M_PI/n)));
}
}
double testGetRadius(int n,double l){
return l/(2*sin(M_PI/n));
}
double testGetConvexX(int k, int n, double r){
return r * cos(2 * M_PI * k / n);
}
double testGetConvexY(int k, int n, double r){
return r * sin(2 * M_PI * k / n);
}
double testGetConcaveX(int k, int n, double r){
return r * cos( (2 * M_PI * k + M_PI) / n);
}
double testGetConcaveY(int k, int n, double r){
return r * sin( (2 * M_PI * k + M_PI) / n);
}
string testPolyDraw (int x, int y, int sides, double length)
{
stringstream ss;
ss << testPsHeader(x,y);
double vertX = testCalcX(0,sides,length);
double vertY = testCalcY(0,sides,length);
ss << testPsMove(vertX,vertY);
for(int i = 1; i < sides; i++){
vertX = testCalcX(i,sides,length);
vertY = testCalcY(i,sides,length);
ss << testPsLine(vertX,vertY);
}
ss << testPsFooter();
return ss.str();
}
string testCircleDraw(int x, int y, double radius)
{
stringstream ss;
ss << testPsHeader(x,y);
ss << testPsArc(0,0, radius,0,360);
ss << testPsFooter();
return ss.str();
}
TEST_CASE ("Testing utils drawing helpers","[Utils]")
{
const int NUM = 5;
random_device rndDev;
mt19937 randomNum(rndDev());
uniform_int_distribution<> posx(0,842);
uniform_int_distribution<>posy (0,595);
uniform_int_distribution<> startAngle(0,360);
uniform_int_distribution<>endAngle (0,360);
uniform_real_distribution<>radii(0,595);
std::vector<int> xCollection;
std::vector<int> yCollection;
std::vector<int> startAngleCollection;
std::vector<int> endAngleCollection;
std::vector<double> radiiColection;
string expectedPS, returnedPS;
for (int i=0; i<NUM; i++ )
{
xCollection.push_back(posx(rndDev));
yCollection.push_back(posy(rndDev));
startAngleCollection.push_back(startAngle(rndDev));
endAngleCollection.push_back(endAngle(rndDev));
radiiColection.push_back(radii(rndDev));
}
for (int i = 0; i<NUM; i++)
{
expectedPS = testPsLine(xCollection[i],yCollection[i]);
returnedPS = psLine(xCollection[i],yCollection[i]);
REQUIRE(returnedPS == expectedPS);
expectedPS=returnedPS=string();
expectedPS = testPsArc(xCollection[i], yCollection[i], radiiColection[i] , startAngleCollection[i],endAngleCollection[i]);
returnedPS = psArc(xCollection[i], yCollection[i], radiiColection[i], startAngleCollection[i],endAngleCollection[i]);
REQUIRE(returnedPS == expectedPS);
//Testing psMove
expectedPS=returnedPS=string();
expectedPS = testPsMove(xCollection[i],yCollection[i]);
returnedPS = psMove(xCollection[i],yCollection[i]);
REQUIRE(expectedPS == returnedPS);
//Testing psHeader
expectedPS=returnedPS=string();
expectedPS = testPsHeader(xCollection[i],yCollection[i]);
returnedPS = psHeader(xCollection[i],yCollection[i]);
REQUIRE(expectedPS == returnedPS);
}
//Testing psFooter
expectedPS=returnedPS=string();
expectedPS = testPsFooter();
returnedPS = psFooter();
REQUIRE(expectedPS == returnedPS);
}
TEST_CASE ("Testing Centers","[Utils]")
{
const int NUM = 5;
random_device rndDev;
mt19937 randomNum(rndDev());
uniform_real_distribution<> randomLen(0,842);
std::vector<double> lenCollection;
for (int i=0; i<NUM; i++ )
{
lenCollection.push_back(randomLen(rndDev));
}
//Testing Triangles
for (auto v:lenCollection)
{
REQUIRE(testCalcX(1,3,v) == calcX (1,3,v));
REQUIRE(testCalcX(2,3,v) == calcX (2,3,v));
REQUIRE(testCalcY(1,3,v) == calcY (1,3,v));
REQUIRE(testCalcY(2,3,v) == calcY (2,3,v));
}
//Testing Squares
for (auto v:lenCollection)
{
REQUIRE(testCalcX(1,4,v) == calcX (1,4,v));
REQUIRE(testCalcX(2,4,v) == calcX (2,4,v));
REQUIRE(testCalcX(3,4,v) == calcX (3,4,v));
REQUIRE(testCalcY(1,4,v) == calcY (1,4,v));
REQUIRE(testCalcY(2,4,v) == calcY (2,4,v));
REQUIRE(testCalcY(3,4,v) == calcY (3,4,v));
}
//Testing Pentagon
for (auto v:lenCollection)
{
REQUIRE(testCalcX(1,5,v) == calcX (1,5,v));
REQUIRE(testCalcX(2,5,v) == calcX (2,5,v));
REQUIRE(testCalcX(3,5,v) == calcX (3,5,v));
REQUIRE(testCalcX(4,5,v) == calcX (4,5,v));
REQUIRE(testCalcY(1,5,v) == calcY (1,5,v));
REQUIRE(testCalcY(2,5,v) == calcY (2,5,v));
REQUIRE(testCalcY(3,5,v) == calcY (3,5,v));
REQUIRE(testCalcY(4,5,v) == calcY (4,5,v));
}
}
TEST_CASE ("Testing width and height calculations","[Utils]")
{
const int NUM = 5;
random_device rndDev;
mt19937 randomNum(rndDev());
uniform_real_distribution<double> len(0,842);
uniform_int_distribution<>sides (0,1000);
double expectWidth, expectHeight;
double returnedWidth, returnedHeight;
std::vector<double> lenCollection;
std::vector<int> sidesCollection;
for (int i=0;i<NUM;i++)
{
lenCollection.push_back(len(rndDev));
sidesCollection.push_back(sides(rndDev));
}
for(int i=0;i<NUM;i++)
{
SECTION ("Testing Width")
{
expectWidth = testGetwidth(sidesCollection[i],lenCollection[i]);
returnedWidth = getWidth(sidesCollection[i],lenCollection[i]);
REQUIRE( abs(expectWidth - returnedWidth) <= ERROR);
expectWidth = testGetwidth(sidesCollection[i],lenCollection[i]);
returnedWidth = getWidth(sidesCollection[i],lenCollection[i]);
REQUIRE( abs(expectWidth - returnedWidth) <= ERROR);
expectWidth = testGetwidth(sidesCollection[i],lenCollection[i]);
returnedWidth = getWidth(sidesCollection[i],lenCollection[i]);
REQUIRE( abs(expectWidth - returnedWidth) <= ERROR);
expectWidth = testGetwidth(sidesCollection[i],lenCollection[i]);
returnedWidth = getWidth(sidesCollection[i],lenCollection[i]);
REQUIRE( abs(expectWidth - returnedWidth) <= ERROR);
expectWidth = testGetwidth(sidesCollection[i],lenCollection[i]);
returnedWidth = getWidth(sidesCollection[i],lenCollection[i]);
REQUIRE( abs(expectWidth - returnedWidth) <= ERROR);
expectWidth = testGetwidth(sidesCollection[i],lenCollection[i]);
returnedWidth = getWidth(sidesCollection[i],lenCollection[i]);
REQUIRE( abs(expectWidth - returnedWidth) <= ERROR);
expectWidth = testGetwidth(sidesCollection[i],lenCollection[i]);
returnedWidth = getWidth(sidesCollection[i],lenCollection[i]);
REQUIRE( abs(expectWidth - returnedWidth) <= ERROR);
expectWidth = testGetwidth(sidesCollection[i],lenCollection[i]);
returnedWidth = getWidth(sidesCollection[i],lenCollection[i]);
REQUIRE( abs(expectWidth - returnedWidth) <= ERROR);
}
SECTION("Testing height")
{
expectHeight = testGetHeight(sidesCollection[i],lenCollection[i]);
returnedHeight = getHeight(sidesCollection[i],lenCollection[i]);
REQUIRE( abs(expectHeight - returnedHeight) <= ERROR);
expectHeight = testGetHeight(sidesCollection[i],lenCollection[i]);
returnedHeight = getHeight(sidesCollection[i],lenCollection[i]);
REQUIRE( abs(expectHeight - returnedHeight) <= ERROR);
expectHeight = testGetHeight(sidesCollection[i],lenCollection[i]);
returnedHeight = getHeight(sidesCollection[i],lenCollection[i]);
REQUIRE( abs(expectHeight - returnedHeight) <= ERROR);
expectHeight = testGetHeight(sidesCollection[i],lenCollection[i]);
returnedHeight = getHeight(sidesCollection[i],lenCollection[i]);
REQUIRE( abs(expectHeight - returnedHeight) <= ERROR);
expectHeight = testGetHeight(sidesCollection[i],lenCollection[i]);
returnedHeight = getHeight(sidesCollection[i],lenCollection[i]);
REQUIRE( abs(expectHeight - returnedHeight) <= ERROR);
expectHeight = testGetHeight(sidesCollection[i],lenCollection[i]);
returnedHeight = getHeight(sidesCollection[i],lenCollection[i]);
REQUIRE( abs(expectHeight - returnedHeight) <= ERROR);
expectHeight = testGetHeight(sidesCollection[i],lenCollection[i]);
returnedHeight = getHeight(sidesCollection[i],lenCollection[i]);
REQUIRE( abs(expectHeight - returnedHeight) <= ERROR);
expectHeight = testGetHeight(sidesCollection[i],lenCollection[i]);
returnedHeight = getHeight(sidesCollection[i],lenCollection[i]);
REQUIRE( abs(expectHeight - returnedHeight) <= ERROR);
}
}
}
TEST_CASE ("Simple Shape Default Construction","[Construction]")
{
Rectangle defaultRect;
string postScript, expectPS;
postScript = defaultRect.draw(72,72);
expectPS = testPolyDraw(72,72,4,0);
REQUIRE(expectPS == postScript);
Square defaultSquare;
postScript = defaultSquare.draw(72,72);
expectPS = testPolyDraw(72,72,4,0);
REQUIRE(expectPS == postScript);
Triangle defaultTri;
postScript = defaultTri.draw(72,72);
expectPS = testPolyDraw(72,72,3,0);
REQUIRE(expectPS == postScript);
Polygon defaultPoly;
postScript = defaultPoly.draw(72,72);
expectPS = testPolyDraw(72,72,0,0);
REQUIRE(expectPS == postScript);
Spacer defaultSpacer;
postScript = defaultSpacer.draw(72,72);
expectPS = "";
REQUIRE(expectPS == postScript);
Circle defaultCircle;
postScript = defaultCircle.draw(72,72);
expectPS = testCircleDraw(72,72,0);
REQUIRE(expectPS == postScript);
}
TEST_CASE( "Drawing and Constructing Simple Shapes ", "Construction, Drawing")
{
SECTION ("Polygons")
{
const int NUM = 5;
random_device rndDev;
mt19937 randomNum(rndDev());
uniform_real_distribution<> len(0,842);
uniform_int_distribution<>x (0,842);
uniform_int_distribution<>y (0,595);
std::vector<double> lenCollection;
std::vector<int> xCollection;
std::vector<int> yCollection;
std::vector<int> sidesCollection = {2,3,4,5,6,7,8,9,10,100,1000};
string expectedPS, returnedPS;
for(int i=0; i<NUM; i++)
{
lenCollection.push_back(len(rndDev));
xCollection.push_back(x(rndDev));
yCollection.push_back(y(rndDev));
}
for (int i = 0; i < NUM; ++i)
{
Polygon poly1(xCollection[i],yCollection[i],sidesCollection[0],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],sidesCollection[0],lenCollection[i]);
returnedPS = poly1.draw();
REQUIRE(expectedPS == returnedPS);
Polygon poly2(xCollection[i],yCollection[i],sidesCollection[1],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],sidesCollection[1],lenCollection[i]);
returnedPS = poly2.draw();
REQUIRE(expectedPS == returnedPS);
Polygon poly3(xCollection[i],yCollection[i],sidesCollection[2],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],sidesCollection[2],lenCollection[i]);
returnedPS = poly3.draw();
REQUIRE(expectedPS == returnedPS);
Polygon poly4(xCollection[i],yCollection[i],sidesCollection[3],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],sidesCollection[3],lenCollection[i]);
returnedPS = poly4.draw();
REQUIRE(expectedPS == returnedPS);
Polygon poly5(xCollection[i],yCollection[i],sidesCollection[4],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],sidesCollection[4],lenCollection[i]);
returnedPS = poly5.draw();
REQUIRE(expectedPS == returnedPS);
Polygon poly6(xCollection[i],yCollection[i],sidesCollection[5],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],sidesCollection[5],lenCollection[i]);
returnedPS = poly6.draw();
REQUIRE(expectedPS == returnedPS);
Polygon poly7(xCollection[i],yCollection[i],sidesCollection[6],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],sidesCollection[6],lenCollection[i]);
returnedPS = poly7.draw();
REQUIRE(expectedPS == returnedPS);
Polygon poly8(xCollection[i],yCollection[i],sidesCollection[7],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],sidesCollection[7],lenCollection[i]);
returnedPS = poly8.draw();
REQUIRE(expectedPS == returnedPS);
Polygon poly9(xCollection[i],yCollection[i],sidesCollection[8],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],sidesCollection[8],lenCollection[i]);
returnedPS = poly9.draw();
REQUIRE(expectedPS == returnedPS);
Polygon poly10(xCollection[i],yCollection[i],sidesCollection[9],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],sidesCollection[9],lenCollection[i]);
returnedPS = poly10.draw();
REQUIRE(expectedPS == returnedPS);
Polygon poly11(xCollection[i],yCollection[i],sidesCollection[10],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],sidesCollection[10],lenCollection[i]);
returnedPS = poly11.draw();
REQUIRE(expectedPS == returnedPS);
}
}
SECTION ("Squares")
{
const int NUM = 5;
random_device rndDev;
mt19937 randomNum(rndDev());
uniform_real_distribution<> len(0,842);
uniform_int_distribution<>x (0,842);
uniform_int_distribution<>y (0,595);
std::vector<double> lenCollection;
std::vector<int> xCollection;
std::vector<int> yCollection;
string expectedPS, returnedPS;
for(int i=0; i<NUM; i++)
{
lenCollection.push_back(len(rndDev));
xCollection.push_back(x(rndDev));
yCollection.push_back(y(rndDev));
}
for (int i = 0; i < NUM; ++i)
{
Square square1(xCollection[i],yCollection[i],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],4,lenCollection[i]);
returnedPS = square1.draw();
REQUIRE(expectedPS == returnedPS);
Square square2(xCollection[i],yCollection[i],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],4,lenCollection[i]);
returnedPS = square2.draw();
REQUIRE(expectedPS == returnedPS);
Square square3(xCollection[i],yCollection[i],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],4,lenCollection[i]);
returnedPS = square3.draw();
REQUIRE(expectedPS == returnedPS);
Square square4(xCollection[i],yCollection[i],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],4,lenCollection[i]);
returnedPS = square4.draw();
REQUIRE(expectedPS == returnedPS);
Square square5(xCollection[i],yCollection[i],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],4,lenCollection[i]);
returnedPS = square5.draw();
REQUIRE(expectedPS == returnedPS);
Square square6(xCollection[i],yCollection[i],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],4,lenCollection[i]);
returnedPS = square6.draw();
REQUIRE(expectedPS == returnedPS);
Square square(xCollection[i],yCollection[i],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],4,lenCollection[i]);
returnedPS = square.draw();
REQUIRE(expectedPS == returnedPS);
Square square8(xCollection[i],yCollection[i],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],4,lenCollection[i]);
returnedPS = square8.draw();
REQUIRE(expectedPS == returnedPS);
Square square9(xCollection[i],yCollection[i],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],4,lenCollection[i]);
returnedPS = square9.draw();
REQUIRE(expectedPS == returnedPS);
Square square10(xCollection[i],yCollection[i],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],4,lenCollection[i]);
returnedPS = square10.draw();
REQUIRE(expectedPS == returnedPS);
Square square11(xCollection[i],yCollection[i],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],4,lenCollection[i]);
returnedPS = square11.draw();
REQUIRE(expectedPS == returnedPS);
}
}
SECTION ("Triangles")
{
const int NUM = 5;
random_device rndDev;
mt19937 randomNum(rndDev());
uniform_real_distribution<> len(0,842);
uniform_int_distribution<>x (0,842);
uniform_int_distribution<>y (0,595);
std::vector<double> lenCollection;
std::vector<int> xCollection;
std::vector<int> yCollection;
string expectedPS, returnedPS;
for(int i=0; i<NUM; i++)
{
lenCollection.push_back(len(rndDev));
xCollection.push_back(x(rndDev));
yCollection.push_back(y(rndDev));
}
for (int i = 0; i < NUM; ++i)
{
Triangle triangle1(xCollection[i],yCollection[i],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],3,lenCollection[i]);
returnedPS = triangle1.draw();
REQUIRE(expectedPS == returnedPS);
Triangle triangle2(xCollection[i],yCollection[i],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],3,lenCollection[i]);
returnedPS = triangle2.draw();
REQUIRE(expectedPS == returnedPS);
Triangle triangle3(xCollection[i],yCollection[i],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],3,lenCollection[i]);
returnedPS = triangle3.draw();
REQUIRE(expectedPS == returnedPS);
Triangle triangle4(xCollection[i],yCollection[i],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],3,lenCollection[i]);
returnedPS = triangle4.draw();
REQUIRE(expectedPS == returnedPS);
Triangle triangle5(xCollection[i],yCollection[i],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],3,lenCollection[i]);
returnedPS = triangle5.draw();
REQUIRE(expectedPS == returnedPS);
Triangle triangle6(xCollection[i],yCollection[i],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],3,lenCollection[i]);
returnedPS = triangle6.draw();
REQUIRE(expectedPS == returnedPS);
Triangle triangle7(xCollection[i],yCollection[i],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],3,lenCollection[i]);
returnedPS = triangle7.draw();
REQUIRE(expectedPS == returnedPS);
Triangle triangle8(xCollection[i],yCollection[i],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],3,lenCollection[i]);
returnedPS = triangle8.draw();
REQUIRE(expectedPS == returnedPS);
Triangle triangle9(xCollection[i],yCollection[i],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],3,lenCollection[i]);
returnedPS = triangle9.draw();
REQUIRE(expectedPS == returnedPS);
Triangle triangle0(xCollection[i],yCollection[i],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],3,lenCollection[i]);
returnedPS = triangle0.draw();
REQUIRE(expectedPS == returnedPS);
Triangle triangle11(xCollection[i],yCollection[i],lenCollection[i]);
expectedPS = testPolyDraw(xCollection[i],yCollection[i],3,lenCollection[i]);
returnedPS = triangle11.draw();
REQUIRE(expectedPS == returnedPS);
}
}
SECTION ("Circles")
{
const int NUM = 5;
random_device rndDev;
mt19937 randomNum(rndDev());
uniform_real_distribution<> radius(0,842);
uniform_int_distribution<>x (0,842);
uniform_int_distribution<>y (0,595);
std::vector<double> radiiCollection;
std::vector<int> xCollection;
std::vector<int> yCollection;
string expectedPS, returnedPS;
for(int i=0; i<NUM; i++)
{
radiiCollection.push_back(radius(rndDev));
xCollection.push_back(x(rndDev));
yCollection.push_back(y(rndDev));
}
for (int i = 0; i < NUM; ++i)
{
Circle circle1(xCollection[i],yCollection[i],radiiCollection[i]);
expectedPS = testCircleDraw(xCollection[i],yCollection[i],radiiCollection[i]);
returnedPS = circle1.draw();
REQUIRE(expectedPS == returnedPS);
Circle circle2(xCollection[i],yCollection[i],radiiCollection[i]);
expectedPS = testCircleDraw(xCollection[i],yCollection[i],radiiCollection[i]);
returnedPS = circle2.draw();
REQUIRE(expectedPS == returnedPS);
Circle circle3(xCollection[i],yCollection[i],radiiCollection[i]);
expectedPS = testCircleDraw(xCollection[i],yCollection[i],radiiCollection[i]);
returnedPS = circle3.draw();
REQUIRE(expectedPS == returnedPS);
Circle circle4(xCollection[i],yCollection[i],radiiCollection[i]);
expectedPS = testCircleDraw(xCollection[i],yCollection[i],radiiCollection[i]);
returnedPS = circle4.draw();
REQUIRE(expectedPS == returnedPS);
Circle circle5(xCollection[i],yCollection[i],radiiCollection[i]);
expectedPS = testCircleDraw(xCollection[i],yCollection[i],radiiCollection[i]);
returnedPS = circle5.draw();
REQUIRE(expectedPS == returnedPS);
Circle circle6(xCollection[i],yCollection[i],radiiCollection[i]);
expectedPS = testCircleDraw(xCollection[i],yCollection[i],radiiCollection[i]);
returnedPS = circle6.draw();
REQUIRE(expectedPS == returnedPS);
Circle circle7(xCollection[i],yCollection[i],radiiCollection[i]);
expectedPS = testCircleDraw(xCollection[i],yCollection[i],radiiCollection[i]);
returnedPS = circle7.draw();
REQUIRE(expectedPS == returnedPS);
Circle circle8(xCollection[i],yCollection[i],radiiCollection[i]);
expectedPS = testCircleDraw(xCollection[i],yCollection[i],radiiCollection[i]);
returnedPS = circle8.draw();
REQUIRE(expectedPS == returnedPS);
Circle circle9(xCollection[i],yCollection[i],radiiCollection[i]);
expectedPS = testCircleDraw(xCollection[i],yCollection[i],radiiCollection[i]);
returnedPS = circle9.draw();
REQUIRE(expectedPS == returnedPS);
Circle circle0(xCollection[i],yCollection[i],radiiCollection[i]);
expectedPS = testCircleDraw(xCollection[i],yCollection[i],radiiCollection[i]);
returnedPS = circle0.draw();
REQUIRE(expectedPS == returnedPS);
Circle circle11(xCollection[i],yCollection[i],radiiCollection[i]);
expectedPS = testCircleDraw(xCollection[i],yCollection[i],radiiCollection[i]);
returnedPS = circle11.draw();
REQUIRE(expectedPS == returnedPS);
}
}
}
TEST_CASE("Polygon Draw","[Polygon] [draw function]")
{
//numOfSides, sidelength
Polygon poly1(0,0,1,1);
Polygon poly2(0,0,1,1);
Polygon poly3(0,0,3,1); //Triangle
Polygon poly4(0,0,4,10); //Square
Polygon poly5(0,0,10,10);
Polygon poly6(0,0,9,23);
Polygon poly7(0,0,10,230.345);
REQUIRE(poly1.draw(72,72) == testPolyDraw(72,72,1,1));
REQUIRE(poly2.draw(72,144) == testPolyDraw(72,144,1,1));
REQUIRE(poly3.draw(72,72) == testPolyDraw(72,72,3,1));
REQUIRE(poly4.draw(72,72) == testPolyDraw(72,72,4,10));
REQUIRE(poly5.draw(72,72) == testPolyDraw(72,72,10,10));
REQUIRE(poly6.draw(72,72) == testPolyDraw(72,72,9,23));
REQUIRE(poly7.draw(72,72) == testPolyDraw(72,72,10,230.345));
}
TEST_CASE("Shape operator <<","[Shape] [operator <<]")
{
const int NUM = 5;
random_device rndDev;
mt19937 randomNum(rndDev());
uniform_real_distribution<> randomLen(0,842);
std::vector<double> lenCollection;
stringstream returnedPS;
for (int i=0; i<NUM; i++ )
{
lenCollection.push_back(randomLen(rndDev));
}
for(auto len : lenCollection)
{
returnedPS.str("");
Polygon poly1(2,len);
returnedPS << poly1;
REQUIRE(returnedPS.str() == testPolyDraw (0,0,2,len));
returnedPS.str("");
Triangle tri1(len);
returnedPS << tri1;
REQUIRE(returnedPS.str() == testPolyDraw (0,0,3,len));
Square square1(len);
returnedPS.str("");
returnedPS << square1;
REQUIRE(returnedPS.str() == testPolyDraw (0,0,4,len));
}
}
TEST_CASE("Shape operator ()","[Shape] [operator ()]")
{
const int NUM = 5;
random_device rndDev;
mt19937 randomNum(rndDev());
uniform_real_distribution<> randomLen(0,842);
std::vector<double> lenCollection;
stringstream returnedPS;
for (int i=0; i<NUM; i++ )
{
lenCollection.push_back(randomLen(rndDev));
}
for(auto len : lenCollection)
{
returnedPS.str("");
Polygon poly1(2,len);
returnedPS << poly1(0,0);
REQUIRE(returnedPS.str() == testPolyDraw (0,0,2,len));
returnedPS.str("");
Triangle tri1(len);
returnedPS << tri1(10,10);
REQUIRE(returnedPS.str() == testPolyDraw (10,10,3,len));
Square square1(len);
returnedPS.str("");
returnedPS << square1(20,20);
REQUIRE(returnedPS.str() == testPolyDraw (20,20,4,len));
}
}