forked from 61c-teach/fa22-proj1-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_tests.c
182 lines (155 loc) · 3.75 KB
/
custom_tests.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "asserts.h"
// Necessary due to static functions in state.c
#include "state.c"
/* Look at asserts.c for some helpful assert functions */
int greater_than_forty_two(int x) { return x > 42; }
bool is_vowel(char c) {
char* vowels = "aeiouAEIOU";
for (int i = 0; i < strlen(vowels); i++) {
if (c == vowels[i]) {
return true;
}
}
return false;
}
/*
Example 1: Returns true if all test cases pass. False otherwise.
The function greater_than_forty_two(int x) will return true if x > 42. False otherwise.
Note: This test is NOT comprehensive
*/
bool test_greater_than_forty_two() {
int testcase_1 = 42;
bool output_1 = greater_than_forty_two(testcase_1);
if (!assert_false("output_1", output_1)) {
return false;
}
int testcase_2 = -42;
bool output_2 = greater_than_forty_two(testcase_2);
if (!assert_false("output_2", output_2)) {
return false;
}
int testcase_3 = 4242;
bool output_3 = greater_than_forty_two(testcase_3);
if (!assert_true("output_3", output_3)) {
return false;
}
return true;
}
/*
Example 2: Returns true if all test cases pass. False otherwise.
The function is_vowel(char c) will return true if c is a vowel (i.e. c is a,e,i,o,u)
and returns false otherwise
Note: This test is NOT comprehensive
*/
bool test_is_vowel() {
char testcase_1 = 'a';
bool output_1 = is_vowel(testcase_1);
if (!assert_true("output_1", output_1)) {
return false;
}
char testcase_2 = 'e';
bool output_2 = is_vowel(testcase_2);
if (!assert_true("output_2", output_2)) {
return false;
}
char testcase_3 = 'i';
bool output_3 = is_vowel(testcase_3);
if (!assert_true("output_3", output_3)) {
return false;
}
char testcase_4 = 'o';
bool output_4 = is_vowel(testcase_4);
if (!assert_true("output_4", output_4)) {
return false;
}
char testcase_5 = 'u';
bool output_5 = is_vowel(testcase_5);
if (!assert_true("output_5", output_5)) {
return false;
}
char testcase_6 = 'k';
bool output_6 = is_vowel(testcase_6);
if (!assert_false("output_6", output_6)) {
return false;
}
return true;
}
/* Task 4.1 */
bool test_is_tail() {
// TODO: Implement this function.
return true;
}
bool test_is_head() {
// TODO: Implement this function.
return true;
}
bool test_is_snake() {
// TODO: Implement this function.
return true;
}
bool test_body_to_tail() {
// TODO: Implement this function.
return true;
}
bool test_head_to_body() {
// TODO: Implement this function.
return true;
}
bool test_get_next_x() {
// TODO: Implement this function.
return true;
}
bool test_get_next_y() {
// TODO: Implement this function.
return true;
}
bool test_customs() {
if (!test_greater_than_forty_two()) {
printf("%s\n", "test_greater_than_forty_two failed.");
return false;
}
if (!test_is_vowel()) {
printf("%s\n", "test_is_vowel failed.");
return false;
}
if (!test_is_tail()) {
printf("%s\n", "test_is_tail failed");
return false;
}
if (!test_is_head()) {
printf("%s\n", "test_is_head failed");
return false;
}
if (!test_is_snake()) {
printf("%s\n", "test_is_snake failed");
return false;
}
if (!test_body_to_tail()) {
printf("%s\n", "test_body_to_tail failed");
return false;
}
if (!test_head_to_body()) {
printf("%s\n", "test_head_to_body failed");
return false;
}
if (!test_get_next_x()) {
printf("%s\n", "test_get_next_x failed");
return false;
}
if (!test_get_next_y()) {
printf("%s\n", "test_get_next_y failed");
return false;
}
return true;
}
int main(int argc, char* argv[]) {
init_colors();
if (!test_and_print("custom", test_customs)) {
return 0;
}
return 0;
}