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.
Brick/Brick-test.h@0:92b180c8d407, 2021-01-05 (annotated)
- Committer:
- jamesheavey
- Date:
- Tue Jan 05 01:14:11 2021 +0000
- Revision:
- 0:92b180c8d407
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jamesheavey | 0:92b180c8d407 | 1 | #ifndef BRICK_TEST_H |
jamesheavey | 0:92b180c8d407 | 2 | #define BRICK_TEST_H |
jamesheavey | 0:92b180c8d407 | 3 | |
jamesheavey | 0:92b180c8d407 | 4 | /** |
jamesheavey | 0:92b180c8d407 | 5 | * \brief Check that Brick object goes to correct position when moved |
jamesheavey | 0:92b180c8d407 | 6 | * |
jamesheavey | 0:92b180c8d407 | 7 | * \returns true if all the tests passed |
jamesheavey | 0:92b180c8d407 | 8 | */ |
jamesheavey | 0:92b180c8d407 | 9 | bool Brick_test_movement() |
jamesheavey | 0:92b180c8d407 | 10 | { |
jamesheavey | 0:92b180c8d407 | 11 | // Initialise Brick object at (2,2) with 2 lives |
jamesheavey | 0:92b180c8d407 | 12 | Brick _brick; |
jamesheavey | 0:92b180c8d407 | 13 | _brick.init(2, 2, 2); |
jamesheavey | 0:92b180c8d407 | 14 | int read_pos1x = _brick.get_x(); |
jamesheavey | 0:92b180c8d407 | 15 | int read_pos1y = _brick.get_y(); |
jamesheavey | 0:92b180c8d407 | 16 | |
jamesheavey | 0:92b180c8d407 | 17 | // Read the position |
jamesheavey | 0:92b180c8d407 | 18 | printf("%f, %f\n", read_pos1x, read_pos1y); |
jamesheavey | 0:92b180c8d407 | 19 | |
jamesheavey | 0:92b180c8d407 | 20 | // Set the x position to 10, 0 |
jamesheavey | 0:92b180c8d407 | 21 | _brick.set_posx(10); |
jamesheavey | 0:92b180c8d407 | 22 | |
jamesheavey | 0:92b180c8d407 | 23 | // Update the position |
jamesheavey | 0:92b180c8d407 | 24 | _brick.update(); |
jamesheavey | 0:92b180c8d407 | 25 | |
jamesheavey | 0:92b180c8d407 | 26 | int read_pos2x = _brick.get_x(); |
jamesheavey | 0:92b180c8d407 | 27 | int read_pos2y = _brick.get_y(); |
jamesheavey | 0:92b180c8d407 | 28 | |
jamesheavey | 0:92b180c8d407 | 29 | // Read the position |
jamesheavey | 0:92b180c8d407 | 30 | printf("%f, %f\n", read_pos2x, read_pos2y); |
jamesheavey | 0:92b180c8d407 | 31 | |
jamesheavey | 0:92b180c8d407 | 32 | // Now check that both the positions are as expected |
jamesheavey | 0:92b180c8d407 | 33 | bool success_flag = true; |
jamesheavey | 0:92b180c8d407 | 34 | |
jamesheavey | 0:92b180c8d407 | 35 | // Fail the test if the initial position is wrong |
jamesheavey | 0:92b180c8d407 | 36 | if (read_pos1x != 0 || read_pos1y != 0) { |
jamesheavey | 0:92b180c8d407 | 37 | success_flag = false; |
jamesheavey | 0:92b180c8d407 | 38 | } |
jamesheavey | 0:92b180c8d407 | 39 | if (read_pos2x != 10 || read_pos2y != 0) { |
jamesheavey | 0:92b180c8d407 | 40 | success_flag = false; |
jamesheavey | 0:92b180c8d407 | 41 | } |
jamesheavey | 0:92b180c8d407 | 42 | |
jamesheavey | 0:92b180c8d407 | 43 | return success_flag; |
jamesheavey | 0:92b180c8d407 | 44 | } |
jamesheavey | 0:92b180c8d407 | 45 | #endif |