Skip to content

Commit 51b6509

Browse files
committed
restructure tests
1 parent 62ca796 commit 51b6509

File tree

3 files changed

+63
-16
lines changed

3 files changed

+63
-16
lines changed

test/test_live/test_live.cpp renamed to test/animation/test_live/test_live.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "../SerialMock.h"
21
#include "BlenderServoAnimation.h"
2+
#include "../../SerialMock.h"
33
#include <unity.h>
44

55
using namespace BlenderServoAnimation;
@@ -30,14 +30,13 @@ void move(byte servoID, int position) {
3030
lastPositions[servoID].index++;
3131
}
3232

33-
const int positionsA[5] PROGMEM = {350, 340, 330, 340, 330};
34-
const int positionsB[5] PROGMEM = {250, 240, 230, 240, 230};
33+
const int positions[5] PROGMEM = {350, 340, 330, 340, 330};
3534

36-
void test_live(void) {
35+
void test_multiple_servos(void) {
3736
Animation animation;
3837
SerialMock mock;
3938
Servo servos[] = {
40-
Servo(0, positionsA, move),
39+
Servo(0, positions, move),
4140
Servo(1, move),
4241
};
4342
animation.addServos(servos, 2);
@@ -66,8 +65,29 @@ void test_live(void) {
6665
TEST_ASSERT_EQUAL(355, lastPositions[1].positions[1]);
6766
}
6867

68+
void test_skip(void) {
69+
Animation animation;
70+
SerialMock mock;
71+
Servo servo(0, move);
72+
animation.addServo(servo);
73+
animation.live(mock);
74+
TEST_ASSERT_EQUAL(Animation::MODE_LIVE, animation.getMode());
75+
76+
byte values[15] = {60, 0, 1, 94, 62, 60, 0, 1, 99, 0, 60, 0, 1, 104, 62};
77+
78+
for (int i = 0; i < 15; i++) {
79+
mock.write(values[i]);
80+
}
81+
82+
animation.run();
83+
84+
TEST_ASSERT_EQUAL(350, lastPositions[0].positions[0]);
85+
TEST_ASSERT_EQUAL(360, lastPositions[0].positions[1]);
86+
}
87+
6988
int main(int argc, char **argv) {
7089
UNITY_BEGIN();
71-
RUN_TEST(test_live);
90+
RUN_TEST(test_multiple_servos);
91+
RUN_TEST(test_skip);
7292
UNITY_END();
7393
}

test/test_mode_change/test_mode_change.cpp renamed to test/animation/test_mode_change/test_mode_change.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "../SerialMock.h"
21
#include "BlenderServoAnimation.h"
2+
#include "../../SerialMock.h"
33
#include <unity.h>
44

55
using namespace BlenderServoAnimation;
@@ -30,7 +30,33 @@ void onModeChange(byte prevMode, byte newMode) {
3030
modeIndex++;
3131
}
3232

33-
void test_mode_change(void) {
33+
void test_different_mode(void) {
34+
Animation animation(FPS, FRAMES);
35+
36+
animation.onModeChange(onModeChange);
37+
38+
animation.play();
39+
TEST_ASSERT_EQUAL(Animation::MODE_DEFAULT, lastModes[0].prevMode);
40+
TEST_ASSERT_EQUAL(Animation::MODE_PLAY, lastModes[0].newMode);
41+
animation.pause();
42+
TEST_ASSERT_EQUAL(Animation::MODE_PLAY, lastModes[1].prevMode);
43+
TEST_ASSERT_EQUAL(Animation::MODE_PAUSE, lastModes[1].newMode);
44+
}
45+
46+
void test_same_mode(void) {
47+
Animation animation(FPS, FRAMES);
48+
49+
animation.onModeChange(onModeChange);
50+
51+
animation.loop();
52+
TEST_ASSERT_EQUAL(Animation::MODE_DEFAULT, lastModes[0].prevMode);
53+
TEST_ASSERT_EQUAL(Animation::MODE_LOOP, lastModes[0].newMode);
54+
animation.loop();
55+
TEST_ASSERT_EQUAL(Animation::MODE_LOOP, lastModes[1].prevMode);
56+
TEST_ASSERT_EQUAL(Animation::MODE_LOOP, lastModes[1].newMode);
57+
}
58+
59+
void test_all_modes(void) {
3460
SerialMock mock;
3561
Animation animation(FPS, FRAMES);
3662

@@ -58,6 +84,8 @@ void test_mode_change(void) {
5884

5985
int main(int argc, char **argv) {
6086
UNITY_BEGIN();
61-
RUN_TEST(test_mode_change);
87+
RUN_TEST(test_different_mode);
88+
RUN_TEST(test_same_mode);
89+
RUN_TEST(test_all_modes);
6290
UNITY_END();
6391
}

test/test_animation/test_animation.cpp renamed to test/animation/test_playback/test_playback.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include "../SerialMock.h"
21
#include "BlenderServoAnimation.h"
32
#include <unity.h>
43

@@ -31,13 +30,13 @@ void move(byte servoID, int position) {
3130
lastPositions[servoID].index++;
3231
}
3332

34-
const int positionsA[5] PROGMEM = {350, 340, 330, 340, 330};
33+
const int positions[5] PROGMEM = {350, 340, 330, 340, 330};
3534
const int positionsB[5] PROGMEM = {250, 240, 230, 240, 230};
3635

3736
void test_play(void) {
3837
Animation animation(FPS, FRAMES);
3938
Servo servos[] = {
40-
Servo(1, positionsA, move),
39+
Servo(1, positions, move),
4140
Servo(2, positionsB, move),
4241
Servo(3, move),
4342
};
@@ -70,7 +69,7 @@ void test_play(void) {
7069

7170
void test_pause_play(void) {
7271
Animation animation(FPS, FRAMES);
73-
Servo servo(2, positionsA, move);
72+
Servo servo(2, positions, move);
7473
animation.addServo(servo);
7574
animation.play();
7675
TEST_ASSERT_EQUAL(Animation::MODE_PLAY, animation.getMode());
@@ -102,7 +101,7 @@ void test_pause_play(void) {
102101
void test_stop(void) {
103102
Animation animation(FPS, FRAMES);
104103
Servo servos[] = {
105-
Servo(0, positionsA, move),
104+
Servo(0, positions, move),
106105
Servo(1, positionsB, move),
107106
Servo(2, move),
108107
};
@@ -133,7 +132,7 @@ void test_stop(void) {
133132
void test_loop(void) {
134133
Animation animation(FPS, FRAMES);
135134
Servo servos[] = {
136-
Servo(1, positionsA, move),
135+
Servo(1, positions, move),
137136
Servo(2, positionsB, move),
138137
Servo(3, move),
139138
};
@@ -160,7 +159,7 @@ void test_loop(void) {
160159

161160
void test_pause_loop(void) {
162161
Animation animation(FPS, FRAMES);
163-
Servo servo(2, positionsA, move);
162+
Servo servo(2, positions, move);
164163
animation.addServo(servo);
165164
animation.loop();
166165
TEST_ASSERT_EQUAL(Animation::MODE_LOOP, animation.getMode());

0 commit comments

Comments
 (0)