FINAL VERSION

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Brick-test.h Source File

Brick-test.h

00001 #ifndef BRICK_TEST_H
00002 #define BRICK_TEST_H
00003 
00004 /**
00005  * \brief Check that Brick object goes to correct position when moved
00006  *
00007  * \returns true if all the tests passed
00008  */
00009 bool Brick_test_movement()
00010 {
00011     // Initialise Brick object at (2,2) with 2 lives
00012     Brick _brick;
00013     _brick.init(2, 2, 2);
00014     int read_pos1x = _brick.get_x();
00015     int read_pos1y = _brick.get_y();
00016 
00017     // Read the position
00018     printf("%f, %f\n", read_pos1x, read_pos1y);
00019 
00020     // Set the x position to 10, 0
00021     _brick.set_posx(10);
00022 
00023     // Update the position
00024     _brick.update();
00025 
00026     int read_pos2x = _brick.get_x();
00027     int read_pos2y = _brick.get_y();
00028 
00029     // Read the position
00030     printf("%f, %f\n", read_pos2x, read_pos2y);
00031 
00032     // Now check that both the positions are as expected
00033     bool success_flag = true;
00034 
00035     // Fail the test if the initial position is wrong
00036     if (read_pos1x != 0 || read_pos1y != 0) {
00037         success_flag = false;
00038     }
00039     if (read_pos2x != 10 || read_pos2y != 0) {
00040         success_flag = false;
00041     }
00042 
00043     return success_flag;
00044 }
00045 #endif