-
Notifications
You must be signed in to change notification settings - Fork 1
/
grid_test.c
68 lines (57 loc) · 2.01 KB
/
grid_test.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
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <check.h>
#include "dotris.h"
START_TEST(test_char_to_dots) {
DotChar a;
char *input = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char *expected = "⣏⡇⣹⡀⣩⡃⣹⡇⠓⡇⣛⡅⣯⡅⡩⠃⣿⡇⣛⡇⡯⡇⣟⡅⣏⡁⣏⡆⣿⡁⡟⠃⣯⡅⡗⡇⢸ ⣍⡇⡷⡁⣇⡀⡗⡇⡗⡇⣏⡇⡯⠇⣏⣇⡯⡃⣫⡅⢹⠁⣇⡇⢧⠇⣷⡇⡱⡁⢱⠁⣩⡃";
int exp_len = strlen(expected);
char output[exp_len + 1]; // +1 null byte
int i, offset = 0;
for (i = 0; i < (int)strlen(input); i++) {
a = char_to_dotchar(input[i]);
snprintf(output + offset, exp_len, "%s%s", a.c1, a.c2);
offset += strlen(a.c1) + strlen(a.c2);
}
ck_assert_str_eq(expected, output);
ck_assert_int_eq(exp_len, strlen(output));
}
END_TEST
START_TEST(test_tetriminos_to_dots) {
char *expected = " ⡇⠠⢤⡤⠄⠰⠆⢀⡤⠠⡤⢤⡀";
int exp_len = strlen(expected), offset = 0;
char output[exp_len + 1 + 200];
for (int t_type = I; t_type <= Z; t_type++) {
Tetrimino t = tetrimino_create(t_type);
DotChar dots = dotmap_to_dotchar(*t.states[0]);
sprintf(output + offset, "%s%s", dots.c1, dots.c2);
offset += strlen(dots.c1) + strlen(dots.c2);
}
ck_assert_str_eq(expected, output);
ck_assert_int_eq(exp_len, strlen(output));
}
END_TEST
Suite *grid_suite(void) {
Suite *s;
TCase *tc_core;
s = suite_create("Grid");
tc_core = tcase_create("Dots");
tcase_add_test(tc_core, test_char_to_dots);
tcase_add_test(tc_core, test_tetriminos_to_dots);
suite_add_tcase(s, tc_core);
return s;
}
int main(void) {
int number_failed;
Suite *s;
SRunner *sr;
s = grid_suite();
sr = srunner_create(s);
srunner_set_fork_status(sr, CK_NOFORK);
srunner_run_all(sr, CK_NORMAL);
number_failed = srunner_ntests_failed(sr);
srunner_free(sr);
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}