-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
313 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#include "BlenderServoAnimation.h" | ||
#include "../../SerialMock.h" | ||
#include <unity.h> | ||
|
||
using namespace BlenderServoAnimation; | ||
|
||
#define FPS 60 | ||
#define FRAMES 5 | ||
|
||
struct positionLog { | ||
int index; | ||
int positions[20]; | ||
}; | ||
|
||
positionLog lastPositions[16]; | ||
|
||
void setUp(void) { | ||
for (int id = 0; id < 16; id++) { | ||
lastPositions[id].index = 0; | ||
|
||
for (int i = 0; i < 20; i++) { | ||
lastPositions[id].positions[i] = 0; | ||
} | ||
} | ||
} | ||
|
||
void move(byte servoID, int position) { | ||
int index = lastPositions[servoID].index; | ||
lastPositions[servoID].positions[index] = position; | ||
lastPositions[servoID].index++; | ||
} | ||
|
||
const int positions[5] PROGMEM = {350, 340, 330, 340, 330}; | ||
|
||
void test_multiple_servos(void) { | ||
Animation animation; | ||
SerialMock mock; | ||
Servo servos[] = { | ||
Servo(0, positions, move), | ||
Servo(1, move), | ||
}; | ||
animation.addServos(servos, 2); | ||
animation.live(mock); | ||
TEST_ASSERT_EQUAL(Animation::MODE_LIVE, animation.getMode()); | ||
|
||
byte values[20] = {60, 0, 1, 94, 62, 60, 1, 1, 94, 62, | ||
60, 0, 1, 99, 62, 60, 1, 1, 99, 62}; | ||
|
||
for (int i = 0; i < 10; i++) { | ||
mock.write(values[i]); | ||
} | ||
|
||
animation.run(); | ||
|
||
TEST_ASSERT_EQUAL(0, lastPositions[0].positions[0]); | ||
TEST_ASSERT_EQUAL(350, lastPositions[1].positions[0]); | ||
|
||
for (int i = 10; i < 20; i++) { | ||
mock.write(values[i]); | ||
} | ||
|
||
animation.run(); | ||
|
||
TEST_ASSERT_EQUAL(355, lastPositions[0].positions[0]); | ||
TEST_ASSERT_EQUAL(355, lastPositions[1].positions[1]); | ||
} | ||
|
||
void test_skip(void) { | ||
Animation animation; | ||
SerialMock mock; | ||
Servo servo(0, move); | ||
animation.addServo(servo); | ||
animation.live(mock); | ||
TEST_ASSERT_EQUAL(Animation::MODE_LIVE, animation.getMode()); | ||
|
||
byte values[15] = {60, 0, 1, 94, 62, 60, 0, 1, 99, 0, 60, 0, 1, 104, 62}; | ||
|
||
for (int i = 0; i < 15; i++) { | ||
mock.write(values[i]); | ||
} | ||
|
||
animation.run(); | ||
|
||
TEST_ASSERT_EQUAL(350, lastPositions[0].positions[0]); | ||
TEST_ASSERT_EQUAL(360, lastPositions[0].positions[1]); | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
UNITY_BEGIN(); | ||
RUN_TEST(test_multiple_servos); | ||
RUN_TEST(test_skip); | ||
UNITY_END(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#include "BlenderServoAnimation.h" | ||
#include "../../SerialMock.h" | ||
#include <unity.h> | ||
|
||
using namespace BlenderServoAnimation; | ||
|
||
#define FPS 60 | ||
#define FRAMES 5 | ||
|
||
struct modeLog { | ||
byte prevMode; | ||
byte newMode; | ||
}; | ||
|
||
byte modeIndex = 0; | ||
modeLog lastModes[10]; | ||
|
||
void setUp(void) { | ||
for (int i = 0; i < 10; i++) { | ||
lastModes[i].prevMode = 0; | ||
lastModes[i].newMode = 0; | ||
} | ||
|
||
modeIndex = 0; | ||
} | ||
|
||
void onModeChange(byte prevMode, byte newMode) { | ||
lastModes[modeIndex].prevMode = prevMode; | ||
lastModes[modeIndex].newMode = newMode; | ||
modeIndex++; | ||
} | ||
|
||
void test_different_mode(void) { | ||
Animation animation(FPS, FRAMES); | ||
|
||
animation.onModeChange(onModeChange); | ||
|
||
animation.play(); | ||
TEST_ASSERT_EQUAL(Animation::MODE_DEFAULT, lastModes[0].prevMode); | ||
TEST_ASSERT_EQUAL(Animation::MODE_PLAY, lastModes[0].newMode); | ||
animation.pause(); | ||
TEST_ASSERT_EQUAL(Animation::MODE_PLAY, lastModes[1].prevMode); | ||
TEST_ASSERT_EQUAL(Animation::MODE_PAUSE, lastModes[1].newMode); | ||
} | ||
|
||
void test_same_mode(void) { | ||
Animation animation(FPS, FRAMES); | ||
|
||
animation.onModeChange(onModeChange); | ||
|
||
animation.loop(); | ||
TEST_ASSERT_EQUAL(Animation::MODE_DEFAULT, lastModes[0].prevMode); | ||
TEST_ASSERT_EQUAL(Animation::MODE_LOOP, lastModes[0].newMode); | ||
animation.loop(); | ||
TEST_ASSERT_EQUAL(Animation::MODE_LOOP, lastModes[1].prevMode); | ||
TEST_ASSERT_EQUAL(Animation::MODE_LOOP, lastModes[1].newMode); | ||
} | ||
|
||
void test_all_modes(void) { | ||
SerialMock mock; | ||
Animation animation(FPS, FRAMES); | ||
|
||
animation.onModeChange(onModeChange); | ||
|
||
animation.play(); | ||
TEST_ASSERT_EQUAL(Animation::MODE_DEFAULT, lastModes[0].prevMode); | ||
TEST_ASSERT_EQUAL(Animation::MODE_PLAY, lastModes[0].newMode); | ||
animation.pause(); | ||
TEST_ASSERT_EQUAL(Animation::MODE_PLAY, lastModes[1].prevMode); | ||
TEST_ASSERT_EQUAL(Animation::MODE_PAUSE, lastModes[1].newMode); | ||
animation.loop(); | ||
TEST_ASSERT_EQUAL(Animation::MODE_PAUSE, lastModes[2].prevMode); | ||
TEST_ASSERT_EQUAL(Animation::MODE_LOOP, lastModes[2].newMode); | ||
animation.stop(); | ||
TEST_ASSERT_EQUAL(Animation::MODE_LOOP, lastModes[3].prevMode); | ||
TEST_ASSERT_EQUAL(Animation::MODE_STOP, lastModes[3].newMode); | ||
animation.run(); | ||
TEST_ASSERT_EQUAL(Animation::MODE_STOP, lastModes[4].prevMode); | ||
TEST_ASSERT_EQUAL(Animation::MODE_DEFAULT, lastModes[4].newMode); | ||
animation.live(mock); | ||
TEST_ASSERT_EQUAL(Animation::MODE_DEFAULT, lastModes[5].prevMode); | ||
TEST_ASSERT_EQUAL(Animation::MODE_LIVE, lastModes[5].newMode); | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
UNITY_BEGIN(); | ||
RUN_TEST(test_different_mode); | ||
RUN_TEST(test_same_mode); | ||
RUN_TEST(test_all_modes); | ||
UNITY_END(); | ||
} |
Oops, something went wrong.