Self-test implementations.
112 {
113
114 uint32_t int_length = 0;
115 uint32_t int_width = 0;
116 uint32_t int_base = 0;
117 uint32_t int_height = 0;
118 uint32_t int_depth = 0;
119
120 double double_radius = NAN;
121 double double_height = NAN;
122
123
124 uint32_t int_expected = 0;
125 uint32_t int_volume = 0;
126
127 double double_expected = NAN;
128 double double_volume = NAN;
129
130
131 int_length = 5;
132 int_expected = 125;
134
135 std::cout << "VOLUME OF A CUBE" << std::endl;
136 std::cout << "Input Length: " << int_length << std::endl;
137 std::cout << "Expected Output: " << int_expected << std::endl;
138 std::cout << "Output: " << int_volume << std::endl;
139 assert(int_volume == int_expected);
140 std::cout << "TEST PASSED" << std::endl << std::endl;
141
142
143 int_length = 4;
144 int_width = 3;
145 int_height = 5;
146 int_expected = 60;
148
149 std::cout << "VOLUME OF A RECTANGULAR PRISM" << std::endl;
150 std::cout << "Input Length: " << int_length << std::endl;
151 std::cout << "Input Width: " << int_width << std::endl;
152 std::cout << "Input Height: " << int_height << std::endl;
153 std::cout << "Expected Output: " << int_expected << std::endl;
154 std::cout << "Output: " << int_volume << std::endl;
155 assert(int_volume == int_expected);
156 std::cout << "TEST PASSED" << std::endl << std::endl;
157
158
159 double_radius = 5;
160 double_height = 7;
161 double_expected = 183.16666666666666;
163
164 std::cout << "VOLUME OF A CONE" << std::endl;
165 std::cout << "Input Radius: " << double_radius << std::endl;
166 std::cout << "Input Height: " << double_height << std::endl;
167 std::cout << "Expected Output: " << double_expected << std::endl;
168 std::cout << "Output: " << double_volume << std::endl;
169 assert(double_volume == double_expected);
170 std::cout << "TEST PASSED" << std::endl << std::endl;
171
172
173 int_base = 3;
174 int_height = 4;
175 int_depth = 5;
176 int_expected = 30;
178
179 std::cout << "VOLUME OF A TRIANGULAR PRISM" << std::endl;
180 std::cout << "Input Base: " << int_base << std::endl;
181 std::cout << "Input Height: " << int_height << std::endl;
182 std::cout << "Input Depth: " << int_depth << std::endl;
183 std::cout << "Expected Output: " << int_expected << std::endl;
184 std::cout << "Output: " << int_volume << std::endl;
185 assert(int_volume == int_expected);
186 std::cout << "TEST PASSED" << std::endl << std::endl;
187
188
189 int_length = 10;
190 int_width = 3;
191 int_height = 5;
192 int_expected = 50;
194
195 std::cout << "VOLUME OF A PYRAMID" << std::endl;
196 std::cout << "Input Length: " << int_length << std::endl;
197 std::cout << "Input Width: " << int_width << std::endl;
198 std::cout << "Input Height: " << int_height << std::endl;
199 std::cout << "Expected Output: " << int_expected << std::endl;
200 std::cout << "Output: " << int_volume << std::endl;
201 assert(int_volume == int_expected);
202 std::cout << "TEST PASSED" << std::endl << std::endl;
203
204
205 double_radius = 3;
206 double_expected = 113.04;
208
209 std::cout << "VOLUME OF A SPHERE" << std::endl;
210 std::cout << "Input Radius: " << double_radius << std::endl;
211 std::cout << "Expected Output: " << double_expected << std::endl;
212 std::cout << "Output: " << double_volume << std::endl;
213 assert(double_volume == double_expected);
214 std::cout << "TEST PASSED" << std::endl << std::endl;
215
216
217 double_radius = 5;
218 double_height = 2;
219 double_expected = 157;
221
222 std::cout << "VOLUME OF A CYLINDER" << std::endl;
223 std::cout << "Input Radius: " << double_radius << std::endl;
224 std::cout << "Input Height: " << double_height << std::endl;
225 std::cout << "Expected Output: " << double_expected << std::endl;
226 std::cout << "Output: " << double_volume << std::endl;
227 assert(double_volume == double_expected);
228 std::cout << "TEST PASSED" << std::endl << std::endl;
229}
T triangle_prism_volume(T base, T height, T depth)
The volume of a triangular prism.
T sphere_volume(T radius, double PI=3.14)
The volume of a sphere
T rect_prism_volume(T length, T width, T height)
The volume of a rectangular prism.
T cone_volume(T radius, T height, double PI=3.14)
The volume of a cone
T pyramid_volume(T length, T width, T height)
The volume of a pyramid
T cylinder_volume(T radius, T height, double PI=3.14)
The volume of a cylinder
T cube_volume(T length)
The volume of a cube