1
- #include "test-framework/unity.h"
2
1
#include "secret_handshake.h"
2
+ #include "test-framework/unity.h"
3
3
#include <stdlib.h>
4
4
5
- #define ARRAY_SIZE (arr ) (sizeof(arr) / sizeof(arr[0]))
5
+ #define ARRAY_SIZE 4
6
+
7
+ #undef TEST_IGNORE
8
+ #define TEST_IGNORE ()
6
9
7
10
void setUp (void )
8
11
{
@@ -14,72 +17,72 @@ void tearDown(void)
14
17
15
18
static void test_commands_wink_for_1 (void )
16
19
{
17
- const char * expected [] = { "wink" };
20
+ const char * expected [] = { "wink" , NULL , NULL , NULL };
18
21
const char * * actual = commands (1 );
19
- TEST_ASSERT_EQUAL_STRING_ARRAY (expected , actual , ARRAY_SIZE ( expected ) );
22
+ TEST_ASSERT_EQUAL_STRING_ARRAY (expected , actual , ARRAY_SIZE );
20
23
free (actual );
21
24
}
22
25
23
26
static void test_commands_double_blink_for_10 (void )
24
27
{
25
28
TEST_IGNORE (); // delete this line to run test
26
- const char * expected [] = { "double blink" };
29
+ const char * expected [] = { "double blink" , NULL , NULL , NULL };
27
30
const char * * actual = commands (2 );
28
- TEST_ASSERT_EQUAL_STRING_ARRAY (expected , actual , ARRAY_SIZE ( expected ) );
31
+ TEST_ASSERT_EQUAL_STRING_ARRAY (expected , actual , ARRAY_SIZE );
29
32
free (actual );
30
33
}
31
34
32
35
static void test_commands_close_your_eyes_for_100 (void )
33
36
{
34
37
TEST_IGNORE ();
35
- const char * expected [] = { "close your eyes" };
38
+ const char * expected [] = { "close your eyes" , NULL , NULL , NULL };
36
39
const char * * actual = commands (4 );
37
- TEST_ASSERT_EQUAL_STRING_ARRAY (expected , actual , ARRAY_SIZE ( expected ) );
40
+ TEST_ASSERT_EQUAL_STRING_ARRAY (expected , actual , ARRAY_SIZE );
38
41
free (actual );
39
42
}
40
43
41
44
static void test_commands_jump_for_1000 (void )
42
45
{
43
46
TEST_IGNORE ();
44
- const char * expected [] = { "jump" };
47
+ const char * expected [] = { "jump" , NULL , NULL , NULL };
45
48
const char * * actual = commands (8 );
46
- TEST_ASSERT_EQUAL_STRING_ARRAY (expected , actual , ARRAY_SIZE ( expected ) );
49
+ TEST_ASSERT_EQUAL_STRING_ARRAY (expected , actual , ARRAY_SIZE );
47
50
free (actual );
48
51
}
49
52
50
53
static void test_commands_combine_two_actions (void )
51
54
{
52
55
TEST_IGNORE ();
53
- const char * expected [] = { "wink" , "double blink" };
56
+ const char * expected [] = { "wink" , "double blink" , NULL , NULL };
54
57
const char * * actual = commands (3 );
55
- TEST_ASSERT_EQUAL_STRING_ARRAY (expected , actual , ARRAY_SIZE ( expected ) );
58
+ TEST_ASSERT_EQUAL_STRING_ARRAY (expected , actual , ARRAY_SIZE );
56
59
free (actual );
57
60
}
58
61
59
62
static void test_commands_reverse_two_actions (void )
60
63
{
61
64
TEST_IGNORE ();
62
- const char * expected [] = { "double blink" , "wink" };
65
+ const char * expected [] = { "double blink" , "wink" , NULL , NULL };
63
66
const char * * actual = commands (19 );
64
- TEST_ASSERT_EQUAL_STRING_ARRAY (expected , actual , ARRAY_SIZE ( expected ) );
67
+ TEST_ASSERT_EQUAL_STRING_ARRAY (expected , actual , ARRAY_SIZE );
65
68
free (actual );
66
69
}
67
70
68
71
static void test_commands_reversing_one_action_gives_the_same_action (void )
69
72
{
70
73
TEST_IGNORE ();
71
- const char * expected [] = { "jump" };
74
+ const char * expected [] = { "jump" , NULL , NULL , NULL };
72
75
const char * * actual = commands (24 );
73
- TEST_ASSERT_EQUAL_STRING_ARRAY (expected , actual , ARRAY_SIZE ( expected ) );
76
+ TEST_ASSERT_EQUAL_STRING_ARRAY (expected , actual , ARRAY_SIZE );
74
77
free (actual );
75
78
}
76
79
77
80
static void test_commands_reversing_no_actions_still_gives_no_actions (void )
78
81
{
79
82
TEST_IGNORE ();
80
- const char * expected [] = { NULL };
83
+ const char * expected [] = { NULL , NULL , NULL , NULL };
81
84
const char * * actual = commands (16 );
82
- TEST_ASSERT_EQUAL_STRING_ARRAY (expected , actual , ARRAY_SIZE ( expected ) );
85
+ TEST_ASSERT_EQUAL_STRING_ARRAY (expected , actual , ARRAY_SIZE );
83
86
free (actual );
84
87
}
85
88
@@ -89,7 +92,7 @@ static void test_commands_all_possible_actions(void)
89
92
const char * expected [] = { "wink" , "double blink" , "close your eyes" ,
90
93
"jump" };
91
94
const char * * actual = commands (15 );
92
- TEST_ASSERT_EQUAL_STRING_ARRAY (expected , actual , ARRAY_SIZE ( expected ) );
95
+ TEST_ASSERT_EQUAL_STRING_ARRAY (expected , actual , ARRAY_SIZE );
93
96
free (actual );
94
97
}
95
98
@@ -99,16 +102,16 @@ static void test_commands_reverse_all_possible_actions(void)
99
102
const char * expected [] = { "jump" , "close your eyes" , "double blink" ,
100
103
"wink" };
101
104
const char * * actual = commands (31 );
102
- TEST_ASSERT_EQUAL_STRING_ARRAY (expected , actual , ARRAY_SIZE ( expected ) );
105
+ TEST_ASSERT_EQUAL_STRING_ARRAY (expected , actual , ARRAY_SIZE );
103
106
free (actual );
104
107
}
105
108
106
109
static void test_commands_do_nothing_for_zero (void )
107
110
{
108
111
TEST_IGNORE ();
109
- const char * expected [] = { NULL };
112
+ const char * expected [] = { NULL , NULL , NULL , NULL };
110
113
const char * * actual = commands (0 );
111
- TEST_ASSERT_EQUAL_STRING_ARRAY (expected , actual , ARRAY_SIZE ( expected ) );
114
+ TEST_ASSERT_EQUAL_STRING_ARRAY (expected , actual , ARRAY_SIZE );
112
115
free (actual );
113
116
}
114
117
0 commit comments