-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestPosition.h
More file actions
147 lines (130 loc) · 3.32 KB
/
testPosition.h
File metadata and controls
147 lines (130 loc) · 3.32 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
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
/***********************************************************************
* Header File:
* Test Position : Test the Position class
* Author:
* Br. Helfrich
* Summary:
* All the unit tests for Position
************************************************************************/
#pragma once
#include <iostream>
#include "position.h"
#include <cassert>
using namespace std;
/*******************************
* TEST Position
* A friend class for Position which contains the Position unit tests
********************************/
class TestPosition
{
public:
void run()
{
Position().setZoom(1000.0 /* 1km equals 1 pixel */);
defaultConstructor();
nonDefaultConstructor();
copyConstructor();
assignment();
setPixels();
setMeters();
addPixels();
addMeters();
}
private:
// utility funciton because floating point numbers are approximations
bool closeEnough(double value, double test, double tolerence) const
{
double difference = value - test;
return (difference >= -tolerence) && (difference <= tolerence);
}
void defaultConstructor() const
{ // setup
// exercise
Position pos;
// verify
assert(pos.x == 0.0);
assert(pos.y == 0.0);
} // teardown
void nonDefaultConstructor() const
{ // setup
// exercise
Position pos(3000.0, 9000.0);
// verify
assert(pos.x == 3000.0);
assert(pos.y == 9000.0);
} // teardown
void copyConstructor() const
{ // setup
Position pos1;
pos1.x = 4000.0;
pos1.y = 2000.0;
// exercise
Position pos2(pos1);
// verify
assert(pos1.x == 4000.0);
assert(pos1.y == 2000.0);
assert(pos2.x == 4000.0);
assert(pos2.y == 2000.0);
} // teardown
void assignment() const
{ // setup
Position pos1;
pos1.x = 4000.0;
pos1.y = 2000.0;
// exercise
Position pos2 = pos1;
// verify
assert(pos1.x == 4000.0);
assert(pos1.y == 2000.0);
assert(pos2.x == 4000.0);
assert(pos2.y == 2000.0);
} // teardown
void setMeters() const
{ // setup
Position pos;
pos.x = 0.0;
pos.y = 0.0;
// exercise
pos.setMetersX(5000.0);
pos.setMetersY(3000.0);
// verify
assert(pos.x == 5000.0);
assert(pos.y == 3000.0);
} // teardown
void setPixels() const
{ // setup
Position pos;
pos.x = 0.0;
pos.y = 0.0;
// exercise
pos.setPixelsX(6.0);
pos.setPixelsY(12.0);
// verify
assert(pos.x == 6000.0);
assert(pos.y == 12000.0);
} // teardown
void addMeters() const
{ // setup
Position pos;
pos.x = 800.0;
pos.y = 1600.0;
// exercise
pos.addMetersX(-400.0);
pos.addMetersY(800.0);
// verify
assert(pos.x == 400.0);
assert(pos.y == 2400.0);
} // teardown
void addPixels() const
{ // setup
Position pos;
pos.x = 2000.0;
pos.y = 4000.0;
// exercise
pos.addPixelsX(2);
pos.addPixelsY(3);
// verify
assert(pos.x == 4000.0);
assert(pos.y == 7000.0);
} // teardown
};