/
test_functions.c
163 lines (119 loc) · 3.46 KB
/
test_functions.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
#include <stdio.h>
#include "minunit.h"
#include "matrix.h"
#include "functions.h"
#define KNRM "\x1B[0m"
#define KRED "\x1B[31m"
#define KGRN "\x1B[32m"
#define KYEL "\x1B[33m"
#define KBLU "\x1B[34m"
#define KMAG "\x1B[35m"
#define KCYN "\x1B[36m"
#define KWHT "\x1B[37m"
#define RESET "\033[0m"
int tests_run = 0;
static char * test_create_initial_board_from_file() {
Matrix* board;
Matrix* expected_matrix;
char* filename;
filename = "test_island/test_island.txt";
expected_matrix = matrix_create(2, 2);
/*
1 2
3 4
*/
matrix_set(expected_matrix, 0, 0, 1);
matrix_set(expected_matrix, 0, 1, 2);
matrix_set(expected_matrix, 1, 0, 3);
matrix_set(expected_matrix, 1, 1, 4);
board = create_initial_board_from_file(filename);
/*
print_board("board: ", board);
print_board("expected: ", expected_matrix);
*/
mu_assert("error, expected_matrix != board_from_file", matrix_equal(board, expected_matrix));
return 0;
}
static char * test_create_initial_board_from_file_with_empty_lines() {
Matrix* board;
Matrix* expected_matrix;
char* filename;
filename = "test_island/test_island_empty_lines.txt";
expected_matrix = matrix_create(2, 2);
/*
1 2
3 4
*/
matrix_set(expected_matrix, 0, 0, 1);
matrix_set(expected_matrix, 0, 1, 2);
matrix_set(expected_matrix, 1, 0, 3);
matrix_set(expected_matrix, 1, 1, 4);
board = create_initial_board_from_file(filename);
/*
print_board("board: ", board);
print_board("expected: ", expected_matrix);
*/
mu_assert("error, expected_matrix != board_from_file", matrix_equal(board, expected_matrix));
return 0;
}
/* TODO: Rename to missing column */
static char * test_initial_board_missing_matrix_value() {
Matrix* board;
char* filename;
filename = "test_island/test_island_missing_matrix_value.txt";
board = create_initial_board_from_file(filename);
print_board("board: ", board);
return 0;
}
static char * test_initial_board_missing_number_of_columns() {
Matrix* board;
char* filename;
filename = "test_island/test_island_missing_number_of_columns.txt";
board = create_initial_board_from_file(filename);
return 0;
}
static char * test_initial_board_missing_row() {
Matrix* board;
char* filename;
filename = "test_island/test_island_missing_row.txt";
board = create_initial_board_from_file(filename);
return 0;
}
static char * test_unit() {
mu_assert("error, test_unit 1 != 1", 1 == 1);
return 0;
}
/* How to captured exit? */
static char * all_tests() {
mu_run_test(test_unit);
mu_run_test(test_create_initial_board_from_file);
mu_run_test(test_create_initial_board_from_file_with_empty_lines);
/*
mu_run_test(test_initial_board_missing_matrix_value);
*/
/*
mu_run_test(test_initial_board_missing_number_of_columns);
*/
/*
mu_run_test(test_initial_board_missing_row);
*/
return 0;
}
int main(int argc, char **argv) {
char *result = all_tests();
if (result != 0) {
printf("-_-_-_-_-_-_-_,------, o \n");
printf("_-_-_-_-_-_-_-| /\\_/\\ \n");
printf("-_-_-_-_-_-_-~|__( X .X) + + \n");
printf("_-_-_-_-_-_-_- \"\" \"\" \n");
printf(KRED "✗ %s \n" RESET, result);
} else {
printf("-_-_-_-_-_-_-_,------, o \n");
printf("_-_-_-_-_-_-_-| /\\_/\\ \n");
printf("-_-_-_-_-_-_-~|__( ^ .^) + + \n");
printf("_-_-_-_-_-_-_- \"\" \"\" \n");
printf(KGRN " ✓ ALL TESTS PASSED \n" RESET);
}
printf("Tests run: %d\n", tests_run);
return result != 0;
}