Skip to content

Commit 3947634

Browse files
committed
restructure show tests
1 parent 91691ad commit 3947634

File tree

6 files changed

+343
-256
lines changed

6 files changed

+343
-256
lines changed

test/show/test_loop/test_loop.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include "BlenderServoAnimation.h"
2+
#include <unity.h>
3+
4+
using namespace BlenderServoAnimation;
5+
using namespace fakeit;
6+
7+
#define FPS 60
8+
#define FRAMES 5
9+
#define FRAME_MICROS 16667
10+
11+
void setUp(void) {
12+
ArduinoFakeReset();
13+
}
14+
15+
void test_loop(void) {
16+
Animation animationA(0, FPS, FRAMES);
17+
Animation animationB(1, FPS, FRAMES);
18+
19+
Show show;
20+
show.addAnimation(animationA);
21+
show.addAnimation(animationB);
22+
23+
TEST_ASSERT_TRUE(show.hasAnimations());
24+
TEST_ASSERT_EQUAL(2, show.countAnimations());
25+
26+
TEST_ASSERT_EQUAL(Show::MODE_DEFAULT, show.getMode());
27+
28+
show.loop(0);
29+
30+
TEST_ASSERT_EQUAL(Show::MODE_LOOP, show.getMode());
31+
TEST_ASSERT_EQUAL(0, show.getCurrentAnimation()->getID());
32+
33+
for (long i = 0; i < FRAME_MICROS * (long)6; i++) {
34+
show.run(i);
35+
}
36+
37+
TEST_ASSERT_EQUAL(Show::MODE_LOOP, show.getMode());
38+
TEST_ASSERT_EQUAL(1, show.getCurrentAnimation()->getID());
39+
40+
for (long i = 0; i < FRAME_MICROS * (long)5; i++) {
41+
show.run(i);
42+
}
43+
44+
TEST_ASSERT_EQUAL(Show::MODE_LOOP, show.getMode());
45+
TEST_ASSERT_EQUAL(0, show.getCurrentAnimation()->getID());
46+
}
47+
48+
void test_without_animations(void) {
49+
Show show;
50+
show.loop(0);
51+
TEST_ASSERT_EQUAL(Show::MODE_DEFAULT, show.getMode());
52+
}
53+
54+
int main(int argc, char **argv) {
55+
UNITY_BEGIN();
56+
RUN_TEST(test_loop);
57+
RUN_TEST(test_without_animations);
58+
UNITY_END();
59+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#include "BlenderServoAnimation.h"
2+
#include <unity.h>
3+
4+
using namespace BlenderServoAnimation;
5+
using namespace fakeit;
6+
7+
#define FPS 60
8+
#define FRAMES 5
9+
#define FRAME_MICROS 16667
10+
11+
void setUp(void) {
12+
ArduinoFakeReset();
13+
}
14+
15+
void test_pause(byte mode) {
16+
Animation animationA(0, FPS, FRAMES);
17+
Animation animationB(1, FPS, FRAMES);
18+
19+
Show show;
20+
show.addAnimation(animationA);
21+
show.addAnimation(animationB);
22+
23+
TEST_ASSERT_EQUAL(Show::MODE_DEFAULT, show.getMode());
24+
25+
switch (mode) {
26+
case Show::MODE_PLAY:
27+
show.play(0);
28+
break;
29+
case Show::MODE_PLAY_SINGLE:
30+
show.playSingle(0, 0);
31+
break;
32+
case Show::MODE_PLAY_RANDOM:
33+
show.playRandom(0);
34+
break;
35+
case Show::MODE_LOOP:
36+
show.loop(0);
37+
break;
38+
}
39+
40+
TEST_ASSERT_EQUAL(mode, show.getMode());
41+
TEST_ASSERT_EQUAL(0, show.getCurrentAnimation()->getFrame());
42+
43+
for (long i = 0; i < FRAME_MICROS * (long)3; i++) {
44+
show.run(i);
45+
}
46+
47+
TEST_ASSERT_EQUAL(2, show.getCurrentAnimation()->getFrame());
48+
49+
show.pause();
50+
51+
for (long i = 0; i < FRAME_MICROS * (long)3; i++) {
52+
show.run(i);
53+
}
54+
55+
TEST_ASSERT_EQUAL(Show::MODE_PAUSE, show.getMode());
56+
TEST_ASSERT_EQUAL(2, show.getCurrentAnimation()->getFrame());
57+
58+
switch (mode) {
59+
case Show::MODE_PLAY:
60+
show.play(0);
61+
break;
62+
case Show::MODE_PLAY_SINGLE:
63+
show.playSingle(1, 0);
64+
break;
65+
case Show::MODE_PLAY_RANDOM:
66+
show.playRandom(0);
67+
break;
68+
case Show::MODE_LOOP:
69+
show.loop(0);
70+
break;
71+
}
72+
73+
show.run(FRAME_MICROS);
74+
75+
TEST_ASSERT_EQUAL(mode, show.getMode());
76+
TEST_ASSERT_EQUAL(3, show.getCurrentAnimation()->getFrame());
77+
}
78+
79+
void test_pause_play(void) {
80+
test_pause(Show::MODE_PLAY);
81+
}
82+
83+
void test_pause_loop(void) {
84+
test_pause(Show::MODE_LOOP);
85+
}
86+
87+
void test_pause_play_single(void) {
88+
test_pause(Show::MODE_PLAY_SINGLE);
89+
}
90+
91+
void test_pause_play_random(void) {
92+
When(OverloadedMethod(ArduinoFake(), random, long(long))).Return(1, 0);
93+
test_pause(Show::MODE_PLAY_RANDOM);
94+
}
95+
96+
int main(int argc, char **argv) {
97+
UNITY_BEGIN();
98+
RUN_TEST(test_pause_play);
99+
RUN_TEST(test_pause_loop);
100+
RUN_TEST(test_pause_play_single);
101+
RUN_TEST(test_pause_play_random);
102+
UNITY_END();
103+
}

test/show/test_play/test_play.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include "BlenderServoAnimation.h"
2+
#include <unity.h>
3+
4+
using namespace BlenderServoAnimation;
5+
using namespace fakeit;
6+
7+
#define FPS 60
8+
#define FRAMES 5
9+
#define FRAME_MICROS 16667
10+
11+
void setUp(void) {
12+
ArduinoFakeReset();
13+
}
14+
15+
void test_play(void) {
16+
Animation animationA(0, FPS, FRAMES);
17+
Animation animationB(1, FPS, FRAMES);
18+
19+
Show show;
20+
21+
TEST_ASSERT_FALSE(show.hasAnimations());
22+
TEST_ASSERT_EQUAL(0, show.countAnimations());
23+
TEST_ASSERT_FALSE(show.hasAnimation(0));
24+
TEST_ASSERT_FALSE(show.hasAnimation(1));
25+
TEST_ASSERT_EQUAL(nullptr, show.getCurrentAnimation());
26+
27+
show.addAnimation(animationB);
28+
show.addAnimation(animationA);
29+
30+
TEST_ASSERT_TRUE(show.hasAnimations());
31+
TEST_ASSERT_EQUAL(2, show.countAnimations());
32+
TEST_ASSERT_TRUE(show.hasAnimation(0));
33+
TEST_ASSERT_TRUE(show.hasAnimation(1));
34+
35+
TEST_ASSERT_EQUAL(Show::MODE_DEFAULT, show.getMode());
36+
37+
show.play(0);
38+
39+
TEST_ASSERT_EQUAL(Show::MODE_PLAY, show.getMode());
40+
TEST_ASSERT_NOT_EQUAL(nullptr, show.getCurrentAnimation());
41+
TEST_ASSERT_EQUAL(1, show.getCurrentAnimation()->getID());
42+
43+
for (long i = 0; i < FRAME_MICROS * (long)6; i++) {
44+
show.run(i);
45+
}
46+
47+
TEST_ASSERT_EQUAL(Show::MODE_PLAY, show.getMode());
48+
TEST_ASSERT_EQUAL(0, show.getCurrentAnimation()->getID());
49+
50+
for (long i = 0; i < FRAME_MICROS * (long)5; i++) {
51+
show.run(i);
52+
}
53+
54+
TEST_ASSERT_EQUAL(Show::MODE_DEFAULT, show.getMode());
55+
}
56+
57+
void test_without_animations(void) {
58+
Show show;
59+
show.play(0);
60+
TEST_ASSERT_EQUAL(Show::MODE_DEFAULT, show.getMode());
61+
}
62+
63+
int main(int argc, char **argv) {
64+
UNITY_BEGIN();
65+
RUN_TEST(test_play);
66+
RUN_TEST(test_without_animations);
67+
UNITY_END();
68+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include "BlenderServoAnimation.h"
2+
#include <unity.h>
3+
4+
using namespace BlenderServoAnimation;
5+
using namespace fakeit;
6+
7+
#define FPS 60
8+
#define FRAMES 5
9+
#define FRAME_MICROS 16667
10+
11+
void setUp(void) {
12+
ArduinoFakeReset();
13+
}
14+
15+
void test_play_random(void) {
16+
Animation animations[3] = {
17+
{0, FPS, FRAMES},
18+
{1, FPS, FRAMES},
19+
{2, FPS, FRAMES},
20+
};
21+
22+
Show show;
23+
show.addAnimations(animations, 3);
24+
25+
TEST_ASSERT_EQUAL(3, show.countAnimations());
26+
TEST_ASSERT_EQUAL(Show::MODE_DEFAULT, show.getMode());
27+
28+
When(OverloadedMethod(ArduinoFake(), random, long(long))).Return(1, 0, 2);
29+
30+
show.playRandom(0);
31+
32+
TEST_ASSERT_EQUAL(Show::MODE_PLAY_RANDOM, show.getMode());
33+
TEST_ASSERT_EQUAL(1, show.getCurrentAnimation()->getID());
34+
35+
for (long i = 0; i < FRAME_MICROS * (long)6; i++) {
36+
show.run(i);
37+
}
38+
39+
TEST_ASSERT_EQUAL(Show::MODE_PLAY_RANDOM, show.getMode());
40+
TEST_ASSERT_EQUAL(0, show.getCurrentAnimation()->getID());
41+
42+
for (long i = 0; i < FRAME_MICROS * (long)5; i++) {
43+
show.run(i);
44+
}
45+
46+
TEST_ASSERT_EQUAL(Show::MODE_PLAY_RANDOM, show.getMode());
47+
TEST_ASSERT_EQUAL(2, show.getCurrentAnimation()->getID());
48+
}
49+
50+
void test_without_animations(void) {
51+
Show show;
52+
show.playRandom(0);
53+
TEST_ASSERT_EQUAL(Show::MODE_DEFAULT, show.getMode());
54+
}
55+
56+
int main(int argc, char **argv) {
57+
UNITY_BEGIN();
58+
RUN_TEST(test_play_random);
59+
RUN_TEST(test_without_animations);
60+
UNITY_END();
61+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include "BlenderServoAnimation.h"
2+
#include <unity.h>
3+
4+
using namespace BlenderServoAnimation;
5+
using namespace fakeit;
6+
7+
#define FPS 60
8+
#define FRAMES 5
9+
#define FRAME_MICROS 16667
10+
11+
void setUp(void) {
12+
ArduinoFakeReset();
13+
}
14+
15+
void test_play_single(void) {
16+
Animation animations[4] = {
17+
{0, FPS, FRAMES},
18+
{1, FPS, FRAMES},
19+
{2, FPS, FRAMES},
20+
{3, FPS, FRAMES},
21+
};
22+
23+
Show show;
24+
show.addAnimations(animations, 4);
25+
26+
TEST_ASSERT_EQUAL(4, show.countAnimations());
27+
TEST_ASSERT_EQUAL(Show::MODE_DEFAULT, show.getMode());
28+
29+
show.playSingle(2, 0);
30+
31+
TEST_ASSERT_EQUAL(Show::MODE_PLAY_SINGLE, show.getMode());
32+
TEST_ASSERT_EQUAL(2, show.getCurrentAnimation()->getID());
33+
34+
for (long i = 0; i < FRAME_MICROS * (long)6; i++) {
35+
show.run(i);
36+
}
37+
38+
TEST_ASSERT_EQUAL(Show::MODE_DEFAULT, show.getMode());
39+
}
40+
41+
void test_without_animations(void) {
42+
Show show;
43+
show.playSingle(0, 0);
44+
TEST_ASSERT_EQUAL(Show::MODE_DEFAULT, show.getMode());
45+
}
46+
47+
int main(int argc, char **argv) {
48+
UNITY_BEGIN();
49+
RUN_TEST(test_play_single);
50+
RUN_TEST(test_without_animations);
51+
UNITY_END();
52+
}

0 commit comments

Comments
 (0)