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.
PlayEngine_test.h
00001 #ifndef PLAYENGINE_TEST_H 00002 #define PLAYENGINE_TEST_H 00003 00004 /** PlayEngine Test 00005 * @brief Checks that the engine functions of the playable part of game work 00006 * @author Benjamin Evans, University of Leeds 00007 * @date May 2020 00008 * @return true if test are passed 00009 */ 00010 00011 bool read_accelerometer_direction_test(Direction expected_d, float roll, 00012 float pitch) { 00013 // Objects required for test 00014 PlayEngine engine;; 00015 00016 printf("read_accelerometer_direction = %d : ", expected_d); 00017 00018 engine.read_accelerometer_direction(roll, pitch); 00019 00020 // Checks if pixel is drawn and therefor testing it hasn’t gone of screen 00021 if (expected_d == engine.d_) { 00022 printf ( "Passed!\n"); 00023 return true; 00024 } else { 00025 printf ( "Failed! value = %d (expecting %d)\n", expected_d, 00026 engine.d_); 00027 return false; 00028 } 00029 } 00030 00031 bool spawn_aliens_test(int expected_alien_num) { 00032 // Objects required for test 00033 PlayEngine engine; 00034 engine.alien_number_ = expected_alien_num; 00035 00036 printf("spawn_aliens : "); 00037 00038 //spawn number of expected aliens 00039 for (int i = 1; i <= expected_alien_num; i++) { 00040 engine.spawn_aliens(); 00041 } 00042 00043 // Checks if pixel is drawn and therefor testing it hasn’t gone of screen 00044 if (engine.alien_vector.size() == expected_alien_num) { 00045 printf ( "Passed!\n"); 00046 return true; 00047 } else { 00048 printf ( "Failed! value = %d (expecting %d)\n", 00049 engine.alien_vector.size(), expected_alien_num); 00050 return false; 00051 } 00052 } 00053 00054 bool create_alien_test(int expected_alien_num) { 00055 // Objects required for test 00056 PlayEngine engine; 00057 engine.alien_number_ = expected_alien_num; 00058 00059 printf("create_aliens : "); 00060 00061 //spawn number of expected aliens 00062 for (int i = 1; i <= expected_alien_num; i++) { 00063 engine.create_alien(); 00064 } 00065 00066 // Checks if pixel is drawn and therefor testing it hasn’t gone of screen 00067 if (engine.alien_vector.size() == expected_alien_num) { 00068 printf ( "Passed!\n"); 00069 return true; 00070 } else { 00071 printf ( "Failed! value = %d (expecting %d)\n", 00072 engine.alien_vector.size(), expected_alien_num); 00073 return false; 00074 } 00075 } 00076 00077 bool create_explosion_test(int expected_explosion_num) { 00078 // Objects required for test 00079 PlayEngine engine; 00080 GameEngine GameEngine; 00081 Vector2D pos = {5,4}; 00082 00083 printf("Create_explosion : "); 00084 00085 //spawn number of expected aliens 00086 for (int i = 1; i <= expected_explosion_num; i++) { 00087 engine.create_explosion(pos); 00088 } 00089 00090 // Checks if pixel is drawn and therefor testing it hasn’t gone of screen 00091 if (engine.explosion_vector.size() == expected_explosion_num) { 00092 printf ( "Passed!\n"); 00093 return true; 00094 } else { 00095 printf ( "Failed! value = %d (expecting %d)\n", 00096 engine.explosion_vector.size(), expected_explosion_num); 00097 return false; 00098 } 00099 } 00100 00101 bool spawn_people_test(int expected_people_num) { 00102 // Objects required for test 00103 PlayEngine engine; 00104 00105 printf("spawn_people : "); 00106 00107 //spawn number of expected aliens 00108 for (int i = 1; i <= expected_people_num; i++) { 00109 engine.spawn_people(); 00110 } 00111 00112 // Checks if pixel is drawn and therefor testing it hasn’t gone of screen 00113 if (engine.people_vector.size() == expected_people_num) { 00114 printf ( "Passed!\n"); 00115 return true; 00116 } else { 00117 printf ( "Failed! value = %d (expecting %d)\n", 00118 engine.people_vector.size(), expected_people_num); 00119 return false; 00120 } 00121 } 00122 00123 bool create_people_test(int expected_people_num) { 00124 // Objects required for test 00125 PlayEngine engine; 00126 00127 printf("create_people : "); 00128 00129 //spawn number of expected aliens 00130 for (int i = 1; i <= expected_people_num; i++) { 00131 engine.create_people(); 00132 } 00133 00134 // Checks if pixel is drawn and therefor testing it hasn’t gone of screen 00135 if (engine.people_vector.size() == expected_people_num) { 00136 printf ( "Passed!\n"); 00137 return true; 00138 } else { 00139 printf ( "Failed! value = %d (expecting %d)\n", 00140 engine.people_vector.size(), expected_people_num); 00141 return false; 00142 } 00143 } 00144 00145 bool reset_map_timer_test(Direction expected_d, bool spaceship_destroyed) { 00146 // Objects required for test 00147 PlayEngine engine; 00148 00149 printf("reset_map_timer %d: ",spaceship_destroyed); 00150 00151 // Pre defines variables 00152 engine.spaceship_destroyed_ = spaceship_destroyed; 00153 engine.d_ = N; 00154 00155 engine.reset_map_timer(); 00156 00157 // Checks if pixel is drawn and therefor testing it hasn’t gone of screen 00158 if (engine.d_ == expected_d) { 00159 printf ( "Passed!\n"); 00160 return true; 00161 } else { 00162 printf ( "Failed! value = %d (expecting %d)\n",engine.d_, expected_d); 00163 return false; 00164 } 00165 } 00166 00167 bool reset_map_test() { 00168 // Objects required for test 00169 PlayEngine engine; 00170 00171 00172 printf("reset_map_ : "); 00173 00174 // Create object for map functions 00175 engine.spawn_people(); 00176 engine.spawn_aliens(); 00177 00178 engine.reset_map(); 00179 00180 // Checks if pixel is drawn and therefor testing it hasn’t gone of screen 00181 if (engine.people_vector.size()== 0 && engine.alien_vector.size() == 0) { 00182 printf ( "Passed!\n"); 00183 return true; 00184 } else { 00185 printf ( "Failed! value = %d,%d, (expecting 0,0)\n", 00186 engine.people_vector.size(), engine.alien_vector.size()); 00187 return false; 00188 } 00189 } 00190 #endif
Generated on Fri Aug 5 2022 06:55:07 by
1.7.2