Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
test.h
00001 #ifndef TESTS_H 00002 #define TESTS_H 00003 00004 // Included Headers ------------------------------------------------------------ 00005 #include "Spaceship_test.h" 00006 #include "Map_test.h" 00007 #include "Alien_test.h" 00008 #include "Weapons_test.h" 00009 #include "Explosion_test.h" 00010 #include "People_test.h" 00011 #include "Menu_test.h" 00012 #include "HUD_test.h" 00013 #include "SavedGames_test.h" 00014 #include "Settings_test.h" 00015 #include "HighScore_test.h" 00016 #include "PlayEngine_test.h" 00017 00018 /** Test 00019 * @brief Runs all tests for game 00020 * @author Benjamin Evans, University of Leeds 00021 * @date April 2020 00022 */ 00023 // Spaceship tests ------------------------------------------------------------- 00024 00025 void run_spaceship_movement_tests() { 00026 printf ("\nTesting spaceship_movement_test() \n"); 00027 int passed_counter = 0; 00028 00029 // Runs test with all possible movement directions 00030 if (spaceship_movement_test(CENTRE, 36, 22)) passed_counter++; 00031 if (spaceship_movement_test(N, 36, 21)) passed_counter++; 00032 if (spaceship_movement_test(NE, 35, 21)) passed_counter++; 00033 if (spaceship_movement_test(E, 35, 22)) passed_counter++; 00034 if (spaceship_movement_test(SE, 35, 23)) passed_counter++; 00035 if (spaceship_movement_test(S, 36, 23)) passed_counter++; 00036 if (spaceship_movement_test(SW, 37, 23)) passed_counter++; 00037 if (spaceship_movement_test(W, 37, 22)) passed_counter++; 00038 if (spaceship_movement_test(NW, 37, 21)) passed_counter++; 00039 00040 // Prints results 00041 printf ("\nspaceship_movement_test passed %d tests out of 9\n\n\n", 00042 passed_counter); 00043 } 00044 00045 void run_spaceship_draw_tests() { 00046 printf ("\nTesting spaceship_draw_tests() \n\n"); 00047 int passed_counter = 0; 00048 00049 // Runs test with max movement directions 00050 if (spaceship_draw_test(NE, 1, 15, 9)) passed_counter++; 00051 if (spaceship_draw_test(SE, 1, 15, 44)) passed_counter++; 00052 if (spaceship_draw_test(SW, 1, 64, 44)) passed_counter++; 00053 if (spaceship_draw_test(NW, 1, 64, 9)) passed_counter++; 00054 00055 // Prints results 00056 printf ("\nspaceship_draw_test passed %d tests out of 4\n\n\n",passed_counter); 00057 } 00058 00059 00060 00061 // Map tests ------------------------------------------------------------------- 00062 00063 void run_map_draw_tests() { 00064 printf ("\nTesting map_draw_tests() \n\n"); 00065 int passed_counter = 0; 00066 00067 // Runs multiple map tests 00068 if (map_move_test(CENTRE, -84)) passed_counter++; 00069 if (map_move_test(N, -84)) passed_counter++; 00070 if (map_move_test(NE,-86)) passed_counter++; 00071 if (map_move_test(E, -86)) passed_counter++; 00072 if (map_move_test(SE, -86)) passed_counter++; 00073 if (map_move_test(S, -84)) passed_counter++; 00074 if (map_move_test(SW, -82)) passed_counter++; 00075 if (map_move_test(W, -82)) passed_counter++; 00076 if (map_move_test(NW, -82)) passed_counter++; 00077 00078 // Prints results 00079 printf ("\nmap_draw_test passed %d tests out of 9\n\n\n",passed_counter); 00080 } 00081 00082 00083 00084 // Alien tests ----------------------------------------------------------------- 00085 00086 void run_alien_draw_tests() { 00087 printf ("\nTesting alien_draw_test() \n\n"); 00088 int passed_counter = 0; 00089 00090 // Runs test with all possible movement directions 00091 if (alien_draw_test(1,CENTRE, 1, 1)) passed_counter++; 00092 if (alien_draw_test(1,N, 43, 20)) passed_counter++; 00093 if (alien_draw_test(0,NE, -23, 6)) passed_counter++; 00094 if (alien_draw_test(0,E, 23, -34)) passed_counter++; 00095 if (alien_draw_test(0,SE, -23, -43)) passed_counter++; 00096 if (alien_draw_test(0,S, 100, 26)) passed_counter++; 00097 if (alien_draw_test(0,SE, 40, 100)) passed_counter++; 00098 if (alien_draw_test(1,E, 70, 5)) passed_counter++; 00099 if (alien_draw_test(1,NE, 6, 44)) passed_counter++; 00100 00101 // Prints results 00102 printf ("\nalien_draw_test passed %d tests out of 9\n\n\n",passed_counter); 00103 } 00104 00105 void run_check_collision_test() { 00106 printf ("\nTesting alien_collision_test() \n\n"); 00107 int passed_counter = 0; 00108 00109 // Runs test with all different possible inputs 00110 if (check_collision_test(1, 1, 10,22)) passed_counter++; 00111 if (check_collision_test(0, 1, 28,40)) passed_counter++; 00112 if (check_collision_test(1, 0, 11,22)) passed_counter++; 00113 if (check_collision_test(0, 0, 20,22)) passed_counter++; 00114 00115 // Prints results 00116 printf ("\nalien_draw_test passed %d tests out of 4\n\n\n",passed_counter); 00117 } 00118 00119 00120 // Weapons tests --------------------------------------------------------------- 00121 00122 void run_weapons_draw_tests() { 00123 printf ("\nTesting spaceship_draw_tests() \n\n"); 00124 int passed_counter = 0; 00125 00126 // Runs test with max movement directions 00127 if (weapons_draw_test(1, 1, 1, 49, 24)) passed_counter++; 00128 if (weapons_draw_test(1, 1, 2, 52, 24)) passed_counter++; 00129 if (weapons_draw_test(0, 1, 2, 49, 24)) passed_counter++; 00130 if (weapons_draw_test(1, 0, 1, 36, 24)) passed_counter++; 00131 if (weapons_draw_test(1, 0, 2, 33, 24)) passed_counter++; 00132 if (weapons_draw_test(0, 0, 2, 33, 24)) passed_counter++; 00133 00134 // Prints results 00135 printf ("\nspaceship_draw_test passed %d tests out of 6\n\n\n",passed_counter); 00136 } 00137 00138 00139 00140 // Explosion tests ------------------------------------------------------------- 00141 00142 void run_explosion_draw_tests() { 00143 printf ("\nTesting explosion_draw_tests() \n\n"); 00144 int passed_counter = 0; 00145 00146 // Runs test with max movement directions 00147 if (explosion_draw_test(1, 15, 3)) passed_counter++; 00148 if (explosion_draw_test(1, 15, 44)) passed_counter++; 00149 if (explosion_draw_test(1, 64, 44)) passed_counter++; 00150 if (explosion_draw_test(1, 64, 2)) passed_counter++; 00151 00152 // Prints results 00153 printf ("\nspaceship_draw_test passed %d tests out of 4\n\n\n",passed_counter); 00154 } 00155 00156 00157 00158 // People tests ---------------------------------------------------------------- 00159 00160 void run_people_draw_tests() { 00161 printf ("\nTesting people_draw_tests() \n\n"); 00162 int passed_counter = 0; 00163 00164 // Runs test with max movement directions 00165 if (people_draw_test(CENTRE, 1,44)) passed_counter++; 00166 if (people_draw_test(N, 0,100)) passed_counter++; 00167 if (people_draw_test(NE, 0, -100)) passed_counter++; 00168 if (people_draw_test(E, 1,0)) passed_counter++; 00169 if (people_draw_test(SE, 1,82)) passed_counter++; 00170 if (people_draw_test(S, 1,43)) passed_counter++; 00171 if (people_draw_test(SW, 0,-64)) passed_counter++; 00172 if (people_draw_test(W, 0,-6)) passed_counter++; 00173 if (people_draw_test(NW, 0,84)) passed_counter++; 00174 00175 // Prints results 00176 printf ("\npeople_draw_test passed %d tests out of 9\n\n\n",passed_counter); 00177 } 00178 00179 void run_check_alien_collision_test() { 00180 printf ("\nTesting check_alien_collision_test() \n\n"); 00181 int passed_counter = 0; 00182 00183 // Runs test with all different possible inputs 00184 if (check_alien_collision_test(1,1)) passed_counter++; 00185 if (check_alien_collision_test(1,80)) passed_counter++; 00186 if (check_alien_collision_test(1,-42)) passed_counter++; 00187 if (check_alien_collision_test(1,100)) passed_counter++; 00188 00189 // Prints results 00190 printf ("\ncheck_alien_collision_test passed %d tests out of 4\n\n\n", 00191 passed_counter); 00192 } 00193 00194 00195 00196 // Menu tests ------------------------------------------------------------------ 00197 00198 void run_menu_select_part_test() { 00199 printf ("\nTesting menu_select_part_test() \n\n"); 00200 int passed_counter = 0; 00201 00202 // Runs test with all different possible inputs 00203 if (menu_select_part_test(play,1)) passed_counter++; 00204 if (menu_select_part_test(main_menu,0)) passed_counter++; 00205 00206 // Prints results 00207 printf ("\nmenu_select_part_test passed %d tests out of 2\n\n\n", 00208 passed_counter); 00209 } 00210 00211 void run_menu_scroll_test() { 00212 printf ("\nTesting menu_scroll_test() \n\n"); 00213 int passed_counter = 0; 00214 00215 // Runs test with all different possible inputs 00216 if (menu_scroll_test(CENTRE, play)) passed_counter++; 00217 if (menu_scroll_test(N, settings)) passed_counter++; 00218 if (menu_scroll_test(NE, settings)) passed_counter++; 00219 if (menu_scroll_test(E, play)) passed_counter++; 00220 if (menu_scroll_test(SE, high_score)) passed_counter++; 00221 if (menu_scroll_test(S, high_score)) passed_counter++; 00222 if (menu_scroll_test(SW, high_score)) passed_counter++; 00223 if (menu_scroll_test(W, play)) passed_counter++; 00224 if (menu_scroll_test(NW, settings)) passed_counter++; 00225 00226 // Prints results 00227 printf ("\nmenu_scroll_test passed %d tests out of 9\n\n\n", 00228 passed_counter); 00229 } 00230 00231 void run_menu_draw_part_test() { 00232 printf ("\nmenu_draw_part_test() \n\n"); 00233 int passed_counter = 0; 00234 00235 // Runs test with all different possible inputs 00236 if (menu_draw_part_test(1, 42, 27)) passed_counter++; 00237 if (menu_draw_part_test(1, 41, 43)) passed_counter++; 00238 if (menu_draw_part_test(0, 9, 1)) passed_counter++; 00239 if (menu_draw_part_test(0, 0, 0)) passed_counter++; 00240 00241 // Prints results 00242 printf ("\nmenu_draw_part_test %d tests out of 4\n\n\n", 00243 passed_counter); 00244 } 00245 00246 00247 00248 00249 // HUD tests ------------------------------------------------------------------- 00250 00251 void run_HUD_draw_test() { 00252 printf ("\nTesting HUD_draw_test() \n\n"); 00253 int passed_counter = 0; 00254 00255 // Runs test with all different possible inputs 00256 if (HUD_draw_test(3, 0, 4, 1, 3, 3)) passed_counter++; 00257 if (HUD_draw_test(3, 0, 4, 1, 12, 3)) passed_counter++; 00258 if (HUD_draw_test(1, 0, 4, 0, 12, 3)) passed_counter++; 00259 if (HUD_draw_test(3, 0, 4, 1, 62, 3)) passed_counter++; 00260 if (HUD_draw_test(3, 0, 3, 0, 62, 3)) passed_counter++; 00261 if (HUD_draw_test(3, 0, 3, 1, 30, 3)) passed_counter++; 00262 if (HUD_draw_test(3, 1111, 3, 00, 30, 3)) passed_counter++; 00263 00264 // Prints results 00265 printf ("\nHUD_draw_test passed %d tests out of 7\n\n\n", 00266 passed_counter); 00267 } 00268 00269 00270 00271 00272 // Saved Games tests ----------------------------------------------------------- 00273 00274 void run_saved_games_scroll_test() { 00275 printf ("\nsaved_games_scroll_test() \n\n"); 00276 int passed_counter = 0; 00277 00278 // Runs test with all different possible inputs 00279 if (saved_games_scroll_test(CENTRE, 1)) passed_counter++; 00280 if (saved_games_scroll_test(N, 2)) passed_counter++; 00281 if (saved_games_scroll_test(NE, 2)) passed_counter++; 00282 if (saved_games_scroll_test(E, 1)) passed_counter++; 00283 if (saved_games_scroll_test(SE, 3)) passed_counter++; 00284 if (saved_games_scroll_test(S, 3)) passed_counter++; 00285 if (saved_games_scroll_test(SW, 3)) passed_counter++; 00286 if (saved_games_scroll_test(W, 1)) passed_counter++; 00287 if (saved_games_scroll_test(NW, 2)) passed_counter++; 00288 00289 // Prints results 00290 printf ("\nsaved_games_scroll_test passed %d tests out of 9\n\n\n", 00291 passed_counter); 00292 } 00293 00294 void run_display_saved_games_test() { 00295 printf ("\nTesting display_saved_games_test() \n\n"); 00296 int passed_counter = 0; 00297 00298 // Runs test with all different possible inputs 00299 if (display_saved_games_test(1, 41, 18 )) passed_counter++; 00300 if (display_saved_games_test(1, 41, 34)) passed_counter++; 00301 if (display_saved_games_test(1, 9, 1)) passed_counter++; 00302 if (display_saved_games_test(0, 0, 0)) passed_counter++; 00303 00304 // Prints results 00305 printf ("\ndisplay_saved_games_test %d tests out of 4\n\n\n", 00306 passed_counter); 00307 } 00308 00309 void run_save_game_screen_test() { 00310 printf ("\nTesting save_game_screen_test() \n\n"); 00311 int passed_counter = 0; 00312 00313 // Runs test with all different possible inputs 00314 if (save_game_screen_test(1, 41, 18 )) passed_counter++; 00315 if (save_game_screen_test(1, 41, 34)) passed_counter++; 00316 if (save_game_screen_test(1, 3, 1)) passed_counter++; 00317 if (save_game_screen_test(0, 0, 0)) passed_counter++; 00318 00319 // Prints results 00320 printf ("\nsave_game_screen_test %d tests out of 4\n\n\n", 00321 passed_counter); 00322 } 00323 00324 00325 00326 // Settings tests -------------------------------------------------------------- 00327 00328 void run_settings_select_part_test() { 00329 printf ("\nTesting settings_select_part_test() \n\n"); 00330 int passed_counter = 0; 00331 00332 // Runs test with all different possible inputs 00333 if (settings_select_part_test(acc,1)) passed_counter++; 00334 if (settings_select_part_test(joy,0)) passed_counter++; 00335 00336 // Prints results 00337 printf ("\nsettings_select_part_test passed %d tests out of 2\n\n\n", 00338 passed_counter); 00339 } 00340 00341 void run_settings_scroll_test() { 00342 printf ("\nsettings_scroll_test() \n\n"); 00343 int passed_counter = 0; 00344 00345 // Runs test with all different possible inputs 00346 if (settings_scroll_test(CENTRE, controls)) passed_counter++; 00347 if (settings_scroll_test(N, sound_fx)) passed_counter++; 00348 if (settings_scroll_test(NE, sound_fx)) passed_counter++; 00349 if (settings_scroll_test(E, controls)) passed_counter++; 00350 if (settings_scroll_test(SE, contrast)) passed_counter++; 00351 if (settings_scroll_test(S, contrast)) passed_counter++; 00352 if (settings_scroll_test(SW, contrast)) passed_counter++; 00353 if (settings_scroll_test(W, controls)) passed_counter++; 00354 if (settings_scroll_test(NW, sound_fx)) passed_counter++; 00355 00356 // Prints results 00357 printf ("\nsettings_scroll_test passed %d tests out of 9\n\n\n", 00358 passed_counter); 00359 } 00360 00361 void run_display_settings_screen_test() { 00362 printf ("\ndisplay_settings_screen_test() \n\n"); 00363 int passed_counter = 0; 00364 00365 // Runs test with all different possible inputs 00366 if (display_settings_screen_test(1, 41, 18 )) passed_counter++; 00367 if (display_settings_screen_test(1, 41, 34)) passed_counter++; 00368 if (display_settings_screen_test(0, 9, 1)) passed_counter++; 00369 if (display_settings_screen_test(0, 0, 0)) passed_counter++; 00370 00371 // Prints results 00372 printf ("\ndisplay_settings_screen_test %d tests out of 4\n\n\n", 00373 passed_counter); 00374 } 00375 00376 00377 00378 00379 // High Score tests ------------------------------------------------------------ 00380 00381 void run_no_high_scores_test() { 00382 printf ("\nno_high_scores_test_test() \n\n"); 00383 int passed_counter = 0; 00384 00385 // Runs test with all different possible inputs 00386 if (no_high_scores_test(1, 0, 27)) passed_counter++; 00387 if (no_high_scores_test(1, 3, 35)) passed_counter++; 00388 if (no_high_scores_test(0, 9, 1)) passed_counter++; 00389 if (no_high_scores_test(0, 0, 0)) passed_counter++; 00390 00391 // Prints results 00392 printf ("\nno_high_scores_test %d tests out of 4\n\n\n", 00393 passed_counter); 00394 } 00395 00396 00397 00398 00399 // Play Engine tests ----------------------------------------------------------- 00400 00401 void run_read_accelerometer_direction_test() { 00402 printf ("\nread_accelerometer_direction_test() \n\n"); 00403 int passed_counter = 0; 00404 00405 // Runs test with all different possible inputs 00406 if (read_accelerometer_direction_test(CENTRE,5,-40 )) passed_counter++; 00407 if (read_accelerometer_direction_test(N, 5,-10)) passed_counter++; 00408 if (read_accelerometer_direction_test(NE, 20, -10)) passed_counter++; 00409 if (read_accelerometer_direction_test(E, 20,-40)) passed_counter++; 00410 if (read_accelerometer_direction_test(SE, 20,-60)) passed_counter++; 00411 if (read_accelerometer_direction_test(S, 5,-60)) passed_counter++; 00412 if (read_accelerometer_direction_test(SW, -20,-60)) passed_counter++; 00413 if (read_accelerometer_direction_test(W, -40, -40)) passed_counter++; 00414 if (read_accelerometer_direction_test(NW, -15, -10)) passed_counter++; 00415 00416 // Prints results 00417 printf ("\nread_accelerometer_direction_test passed %d tests out of 9\n\n\n" 00418 ,passed_counter); 00419 } 00420 00421 void run_spawn_aliens_test() { 00422 printf ("\nspawn_aliens_test() \n\n"); 00423 int passed_counter = 0; 00424 00425 // Runs test with all different possible inputs 00426 if (spawn_aliens_test(1)) passed_counter++; 00427 if (spawn_aliens_test(3)) passed_counter++; 00428 if (spawn_aliens_test(5)) passed_counter++; 00429 if (spawn_aliens_test(10)) passed_counter++; 00430 if (spawn_aliens_test(20)) passed_counter++; 00431 00432 // Prints results 00433 printf ("\nspawn_aliens_test passed %d tests out of 5\n\n\n" 00434 ,passed_counter); 00435 } 00436 00437 void run_create_alien_test() { 00438 printf ("\ncreate_aliens_test() \n\n"); 00439 int passed_counter = 0; 00440 00441 // Runs test with all different possible inputs 00442 if (create_alien_test(2)) passed_counter++; 00443 if (create_alien_test(4)) passed_counter++; 00444 if (create_alien_test(6)) passed_counter++; 00445 if (create_alien_test(15)) passed_counter++; 00446 if (create_alien_test(30)) passed_counter++; 00447 00448 // Prints results 00449 printf ("\ncreate_aliens_test() %d tests out of 5\n\n\n" 00450 ,passed_counter); 00451 } 00452 00453 void run_create_explosion_test() { 00454 printf ("\ncreate_explosion_test() \n\n"); 00455 int passed_counter = 0; 00456 00457 // Runs test with all different possible inputs 00458 if (create_explosion_test(3)) passed_counter++; 00459 if (create_explosion_test(6)) passed_counter++; 00460 if (create_explosion_test(9)) passed_counter++; 00461 if (create_explosion_test(1)) passed_counter++; 00462 if (create_explosion_test(22)) passed_counter++; 00463 00464 // Prints results 00465 printf ("\ncreate_explosion_test() %d tests out of 5\n\n\n" 00466 ,passed_counter); 00467 } 00468 00469 void run_spawn_people_test() { 00470 printf ("\nspawn_people_test() \n\n"); 00471 int passed_counter = 0; 00472 00473 // Runs test with all different possible inputs 00474 if (spawn_people_test(1)) passed_counter++; 00475 if (spawn_people_test(2)) passed_counter++; 00476 if (spawn_people_test(3)) passed_counter++; 00477 if (spawn_people_test(4)) passed_counter++; 00478 if (spawn_people_test(5)) passed_counter++; 00479 00480 // Prints results 00481 printf ("\nspawn_people_test passed %d tests out of 5\n\n\n" 00482 ,passed_counter); 00483 } 00484 00485 void run_people_alien_test() { 00486 printf ("\ncreate_people_test() \n\n"); 00487 int passed_counter = 0; 00488 00489 // Runs test with all different possible inputs 00490 if (create_people_test(1)) passed_counter++; 00491 if (create_people_test(2)) passed_counter++; 00492 if (create_people_test(3)) passed_counter++; 00493 if (create_people_test(4)) passed_counter++; 00494 if (create_people_test(5)) passed_counter++; 00495 00496 // Prints results 00497 printf ("\ncreate_people_test() %d tests out of 5\n\n\n" 00498 ,passed_counter); 00499 } 00500 00501 void run_reset_map_timer_test() { 00502 printf ("\nreset_map_timer_test() \n\n"); 00503 int passed_counter = 0; 00504 00505 // Runs test with all different possible inputs 00506 if (reset_map_timer_test(CENTRE, true)) passed_counter++; 00507 if (reset_map_timer_test(N, false)) passed_counter++; 00508 00509 // Prints results 00510 printf ("\nreset_map_timer_test() %d tests out of 2\n\n\n" 00511 ,passed_counter); 00512 } 00513 00514 void run_reset_map_test() { 00515 printf ("\nreset_map_test() \n\n"); 00516 int passed_counter = 0; 00517 00518 // Runs test with all different possible inputs 00519 if (reset_map_test()) passed_counter++; 00520 00521 // Prints results 00522 printf ("\nreset_map_test() %d tests out of 1\n\n\n" 00523 ,passed_counter); 00524 } 00525 #endif
Generated on Fri Aug 5 2022 06:55:07 by
1.7.2