ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18zc2

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Bullet_test.h Source File

Bullet_test.h

00001 #ifndef BULLET_TEST_H
00002 #define BUllET_TEST_H
00003 
00004 /**
00005  * \brief Check that Ball object goes to correct position when moved
00006  * 
00007  * \returns true if all the tests passed
00008  */
00009 bool Bullet_test_movement()
00010 {
00011     // Initialise Bullet object with a size of 2, and speed of 1
00012     Bullet bullet;
00013     bullet.init(2, 1);
00014 
00015     // Set the position to 5, 5
00016     Vector2D initial_pos = {5, 5};
00017     bullet.set_pos(initial_pos);
00018 
00019     // Read the position
00020     Vector2D read_pos_1 = bullet.get_pos();
00021     printf("%f, %f\n", read_pos_1.x, read_pos_1.y);
00022 
00023     // Set the velocity to -2, 3
00024     Vector2D velocity = {-2, 3};
00025     bullet.set_velocity(velocity);
00026 
00027     // Update the position
00028     bullet.update();
00029 
00030     // Read the position
00031     Vector2D read_pos_2 = bullet.get_pos();
00032     printf("%f, %f\n", read_pos_2.x, read_pos_2.y);
00033     
00034     // Now check that both the positions are as expected
00035     bool success_flag = true;
00036     
00037     // Fail the test if the initial position is wrong
00038     if (read_pos_1.x != 5 || read_pos_1.y != 5) {
00039         success_flag = false;
00040     }
00041     
00042     // Fail the test if the final position is wrong
00043     if (read_pos_2.x != 3 || read_pos_2.y != 8) {
00044         success_flag = false;
00045     }
00046 
00047     return success_flag;
00048 }
00049 #endif