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.
Monster-test.h
00001 #ifndef MONSTER_TEST_H 00002 #define MONSTER_TEST_H 00003 00004 /** 00005 * \brief Check that Monster object goes to correct position when moved 00006 * 00007 * \returns true if all the tests passed 00008 */ 00009 bool Monster_test_movement() 00010 { 00011 // Initialise Monster object with a speed of 2 00012 Monster monster; 00013 monster.init(2); 00014 00015 // test 1 00016 // Set the x position to 42 00017 monster.set_pos(42); 00018 00019 // Read the position 00020 int read_pos_1 = monster.get_pos(); 00021 printf("%d \n", read_pos_1); 00022 00023 // Update the position 00024 monster.update(); 00025 00026 // Read the position 00027 int read_pos_2 = monster.get_pos(); 00028 printf("%d \n", read_pos_2); 00029 00030 // test2 00031 // Set the x position to -2 00032 monster.set_pos(-2); 00033 00034 // Read the position 00035 int read_pos_3 = monster.get_pos(); 00036 printf("%d \n", read_pos_3); 00037 00038 // Update the position 00039 monster.update(); 00040 00041 // Read the position 00042 int read_pos_4 = monster.get_pos(); 00043 printf("%d \n", read_pos_4); 00044 00045 // Now check that both the positions are as expected 00046 bool success_flag = true; 00047 00048 // Fail the test if the initial position is wrong 00049 if (read_pos_1 != 42 || read_pos_2 != 40) { 00050 success_flag = false; 00051 } 00052 00053 if (read_pos_3 != -2 || read_pos_4 != 84) { 00054 success_flag = false; 00055 } 00056 00057 return success_flag; 00058 } 00059 #endif
Generated on Sat Jul 16 2022 10:18:04 by
1.7.2