Self-test implementations.
130 {
131
132 uint16_t int_length = 0;
133 uint16_t int_width = 0;
134 uint16_t int_base = 0;
135 uint16_t int_height = 0;
136 uint16_t int_expected = 0;
137 uint16_t int_area = 0;
138
139 float float_length = NAN;
140 float float_expected = NAN;
141 float float_area = NAN;
142
143 double double_length = NAN;
144 double double_width = NAN;
145 double double_radius = NAN;
146 double double_height = NAN;
147 double double_expected = NAN;
148 double double_area = NAN;
149
150
151 int_length = 5;
152 int_expected = 25;
154
155 std::cout << "AREA OF A SQUARE (int)" << std::endl;
156 std::cout << "Input Length: " << int_length << std::endl;
157 std::cout << "Expected Output: " << int_expected << std::endl;
158 std::cout << "Output: " << int_area << std::endl;
159 assert(int_area == int_expected);
160 std::cout << "TEST PASSED" << std::endl << std::endl;
161
162
163 float_length = 2.5;
164 float_expected = 6.25;
166
167 std::cout << "AREA OF A SQUARE (float)" << std::endl;
168 std::cout << "Input Length: " << float_length << std::endl;
169 std::cout << "Expected Output: " << float_expected << std::endl;
170 std::cout << "Output: " << float_area << std::endl;
171 assert(float_area == float_expected);
172 std::cout << "TEST PASSED" << std::endl << std::endl;
173
174
175 int_length = 4;
176 int_width = 7;
177 int_expected = 28;
179
180 std::cout << "AREA OF A RECTANGLE (int)" << std::endl;
181 std::cout << "Input Length: " << int_length << std::endl;
182 std::cout << "Input Width: " << int_width << std::endl;
183 std::cout << "Expected Output: " << int_expected << std::endl;
184 std::cout << "Output: " << int_area << std::endl;
185 assert(int_area == int_expected);
186 std::cout << "TEST PASSED" << std::endl << std::endl;
187
188
189 double_length = 2.5;
190 double_width = 5.7;
191 double_expected = 14.25;
193
194 std::cout << "AREA OF A RECTANGLE (double)" << std::endl;
195 std::cout << "Input Length: " << double_length << std::endl;
196 std::cout << "Input Width: " << double_width << std::endl;
197 std::cout << "Expected Output: " << double_expected << std::endl;
198 std::cout << "Output: " << double_area << std::endl;
199 assert(double_area == double_expected);
200 std::cout << "TEST PASSED" << std::endl << std::endl;
201
202
203 int_base = 10;
204 int_height = 3;
205 int_expected = 15;
207
208 std::cout << "AREA OF A TRIANGLE" << std::endl;
209 std::cout << "Input Base: " << int_base << std::endl;
210 std::cout << "Input Height: " << int_height << std::endl;
211 std::cout << "Expected Output: " << int_expected << std::endl;
212 std::cout << "Output: " << int_area << std::endl;
213 assert(int_area == int_expected);
214 std::cout << "TEST PASSED" << std::endl << std::endl;
215
216
217 double_radius = 6;
218 double_expected =
219 113.09733552923255;
220
222
223 std::cout << "AREA OF A CIRCLE" << std::endl;
224 std::cout << "Input Radius: " << double_radius << std::endl;
225 std::cout << "Expected Output: " << double_expected << std::endl;
226 std::cout << "Output: " << double_area << std::endl;
227 assert(double_area == double_expected);
228 std::cout << "TEST PASSED" << std::endl << std::endl;
229
230
231 int_base = 6;
232 int_height = 7;
233 int_expected = 42;
235
236 std::cout << "AREA OF A PARALLELOGRAM" << std::endl;
237 std::cout << "Input Base: " << int_base << std::endl;
238 std::cout << "Input Height: " << int_height << std::endl;
239 std::cout << "Expected Output: " << int_expected << std::endl;
240 std::cout << "Output: " << int_area << std::endl;
241 assert(int_area == int_expected);
242 std::cout << "TEST PASSED" << std::endl << std::endl;
243
244
245 double_length = 5.5;
246 double_expected = 181.5;
248
249 std::cout << "SURFACE AREA OF A CUBE" << std::endl;
250 std::cout << "Input Length: " << double_length << std::endl;
251 std::cout << "Expected Output: " << double_expected << std::endl;
252 std::cout << "Output: " << double_area << std::endl;
253 assert(double_area == double_expected);
254 std::cout << "TEST PASSED" << std::endl << std::endl;
255
256
257 double_radius = 10.0;
258 double_expected = 1256.6370614359172;
259
261
262 std::cout << "SURFACE AREA OF A SPHERE" << std::endl;
263 std::cout << "Input Radius: " << double_radius << std::endl;
264 std::cout << "Expected Output: " << double_expected << std::endl;
265 std::cout << "Output: " << double_area << std::endl;
266 assert(double_area == double_expected);
267 std::cout << "TEST PASSED" << std::endl << std::endl;
268
269
270 double_radius = 4.0;
271 double_height = 7.0;
272 double_expected = 276.46015351590177;
274
275 std::cout << "SURFACE AREA OF A CYLINDER" << std::endl;
276 std::cout << "Input Radius: " << double_radius << std::endl;
277 std::cout << "Input Height: " << double_height << std::endl;
278 std::cout << "Expected Output: " << double_expected << std::endl;
279 std::cout << "Output: " << double_area << std::endl;
280 assert(double_area == double_expected);
281 std::cout << "TEST PASSED" << std::endl << std::endl;
282
283
284 double_radius = 10.0;
285 double_expected = 942.4777960769379;
287
288 std::cout << "SURFACE AREA OF A HEMI-SPHERE" << std::endl;
289 std::cout << "Input Radius: " << double_radius << std::endl;
290 std::cout << "Expected Output: " << double_expected << std::endl;
291 std::cout << "Output: " << double_area << std::endl;
292 assert(double_area == double_expected);
293 std::cout << "TEST PASSED" << std::endl << std::endl;
294}
T hemi_sphere_surface_area(T radius)
surface area of a hemi-sphere ( 3 * pi * r^2)
T circle_area(T radius)
area of a circle (pi
T parallelogram_area(T base, T height)
area of a parallelogram (b * h)
T square_area(T length)
area of a square (l * l)
T rect_area(T length, T width)
area of a rectangle (l * w)
T triangle_area(T base, T height)
area of a triangle (b * h / 2)
T sphere_surface_area(T radius)
surface area of a sphere ( 4 * pi * r^2)
T cube_surface_area(T length)
surface area of a cube ( 6 * (l
T cylinder_surface_area(T radius, T height)
surface area of a cylinder (2 * pi * r * h + 2 * pi * r^2)