Self-test implementations.
120 {
121
122 uint16_t int_length = 0;
123 uint16_t int_width = 0;
124 uint16_t int_base = 0;
125 uint16_t int_height = 0;
126 uint16_t int_hypotenuse = 0;
127 uint16_t int_sides = 0;
128 uint16_t int_expected = 0;
129 uint16_t int_perimeter = 0;
130
131 float float_length = NAN;
132 float float_expected = NAN;
133 float float_perimeter = NAN;
134
135 double double_length = NAN;
136 double double_width = NAN;
137 double double_radius = NAN;
138 double double_height = NAN;
139 double double_expected = NAN;
140 double double_perimeter = NAN;
141
142
143 int_length = 5;
144 int_expected = 20;
146
147 std::cout << "perimeter OF A SQUARE (int)" << std::endl;
148 std::cout << "Input Length: " << int_length << std::endl;
149 std::cout << "Expected Output: " << int_expected << std::endl;
150 std::cout << "Output: " << int_perimeter << std::endl;
151 assert(int_perimeter == int_expected);
152 std::cout << "TEST PASSED" << std::endl << std::endl;
153
154
155 float_length = 2.5;
156 float_expected = 10;
158
159 std::cout << "perimeter OF A SQUARE (float)" << std::endl;
160 std::cout << "Input Length: " << float_length << std::endl;
161 std::cout << "Expected Output: " << float_expected << std::endl;
162 std::cout << "Output: " << float_perimeter << std::endl;
163 assert(float_perimeter == float_expected);
164 std::cout << "TEST PASSED" << std::endl << std::endl;
165
166
167 int_length = 4;
168 int_width = 7;
169 int_expected = 22;
171
172 std::cout << "perimeter OF A RECTANGLE (int)" << std::endl;
173 std::cout << "Input Length: " << int_length << std::endl;
174 std::cout << "Input Width: " << int_width << std::endl;
175 std::cout << "Expected Output: " << int_expected << std::endl;
176 std::cout << "Output: " << int_perimeter << std::endl;
177 assert(int_perimeter == int_expected);
178 std::cout << "TEST PASSED" << std::endl << std::endl;
179
180
181 double_length = 2.5;
182 double_width = 5.7;
183 double_expected = 16.4;
185
186 std::cout << "perimeter OF A RECTANGLE (double)" << std::endl;
187 std::cout << "Input Length: " << double_length << std::endl;
188 std::cout << "Input Width: " << double_width << std::endl;
189 std::cout << "Expected Output: " << double_expected << std::endl;
190 std::cout << "Output: " << double_perimeter << std::endl;
191 assert(double_perimeter == double_expected);
192 std::cout << "TEST PASSED" << std::endl << std::endl;
193
194
195 int_base = 10;
196 int_height = 3;
197 int_hypotenuse = 5;
198 int_expected = 18;
199 int_perimeter =
201
202 std::cout << "perimeter OF A TRIANGLE" << std::endl;
203 std::cout << "Input Base: " << int_base << std::endl;
204 std::cout << "Input Height: " << int_height << std::endl;
205 std::cout << "Expected Output: " << int_expected << std::endl;
206 std::cout << "Output: " << int_perimeter << std::endl;
207 assert(int_perimeter == int_expected);
208 std::cout << "TEST PASSED" << std::endl << std::endl;
209
210
211 double_radius = 6;
212 double_expected =
213 37.69911184307752;
214
216
217 std::cout << "perimeter OF A CIRCLE" << std::endl;
218 std::cout << "Input Radius: " << double_radius << std::endl;
219 std::cout << "Expected Output: " << double_expected << std::endl;
220 std::cout << "Output: " << double_perimeter << std::endl;
221 assert(double_perimeter == double_expected);
222 std::cout << "TEST PASSED" << std::endl << std::endl;
223
224
225 int_base = 6;
226 int_height = 7;
227 int_expected = 26;
229
230 std::cout << "perimeter OF A PARALLELOGRAM" << std::endl;
231 std::cout << "Input Base: " << int_base << std::endl;
232 std::cout << "Input Height: " << int_height << std::endl;
233 std::cout << "Expected Output: " << int_expected << std::endl;
234 std::cout << "Output: " << int_perimeter << std::endl;
235 assert(int_perimeter == int_expected);
236 std::cout << "TEST PASSED" << std::endl << std::endl;
237
238
239 double_length = 5.5;
240 double_expected = 66.0;
242
243 std::cout << "SURFACE perimeter OF A CUBE" << std::endl;
244 std::cout << "Input Length: " << double_length << std::endl;
245 std::cout << "Expected Output: " << double_expected << std::endl;
246 std::cout << "Output: " << double_perimeter << std::endl;
247 assert(double_perimeter == double_expected);
248 std::cout << "TEST PASSED" << std::endl << std::endl;
249
250
251 int_sides = 7;
252 int_length = 10;
253 int_expected = 70;
255
256 std::cout << "SURFACE perimeter OF A N-POLYGON" << std::endl;
257 std::cout << "Input Sides: " << int_sides << std::endl;
258 std::cout << "Input Length: " << int_length << std::endl;
259 std::cout << "Expected Output: " << int_expected << std::endl;
260 std::cout << "Output: " << int_perimeter << std::endl;
261 assert(int_perimeter == int_expected);
262 std::cout << "TEST PASSED" << std::endl << std::endl;
263
264
265 double_radius = 4.0;
266 double_height = 7.0;
267 double_expected = 22.0;
268 double_perimeter =
270
271 std::cout << "SURFACE perimeter OF A CYLINDER" << std::endl;
272 std::cout << "Input Radius: " << double_radius << std::endl;
273 std::cout << "Input Height: " << double_height << std::endl;
274 std::cout << "Expected Output: " << double_expected << std::endl;
275 std::cout << "Output: " << double_perimeter << std::endl;
276 assert(double_perimeter == double_expected);
277 std::cout << "TEST PASSED" << std::endl << std::endl;
278}
T parallelogram_perimeter(T base, T height)
perimeter of a parallelogram 2(b + h)
T cylinder_surface_perimeter(T radius, T height)
surface perimeter of a cylinder (2 * radius + 2 * height)
T triangle_perimeter(T base, T height, T hypotenuse)
perimeter of a triangle (a + b + c)
T rect_perimeter(T length, T width)
perimeter of a rectangle ( 2(l + w) )
T cube_surface_perimeter(T length)
surface perimeter of a cube ( 12
T square_perimeter(T length)
perimeter of a square (4 * l)
T n_polygon_surface_perimeter(T sides, T length)
surface perimeter of a n-polygon ( n * l)
T circle_perimeter(T radius)
perimeter of a circle (2 * pi * r)