-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.c
95 lines (81 loc) · 2.67 KB
/
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
/*testes unitários*/
#include "main.h"
#include "sprites.h"
#include "lists.h"
#include <stdint.h>
#include <check.h>
START_TEST(test_push){
SPRITE s = DEFAULT_GHOST;
SPRITE *head = NULL;
push(&head, s);
ck_assert(head->representation == CH_GHOST);
SPRITE s2 = DEFAULT_FRUIT;
push(&head, s2);
//tem que inserir no comeco da lista
ck_assert(head->next->representation == CH_GHOST);
ck_assert(head->representation == CH_FRUIT);
}
END_TEST
START_TEST(test_list_size){
SPRITE s = DEFAULT_GHOST;
SPRITE *head = NULL;
ck_assert(list_size(head) == 0);
push(&head, s);
ck_assert(list_size(head) == 1);
}
END_TEST
START_TEST(test_count_alive){
SPRITE s = DEFAULT_GHOST;
SPRITE *head = NULL;
push(&head, s);
ck_assert(count_alive(head) == 1);
head->alive = 0;
ck_assert(count_alive(head) == 0);
}
END_TEST
START_TEST(test_collided){
SPRITE s1 = {.alive = 1, .representation = 'a', .position = {0, 0, 0, 0}};
SPRITE s2 = {.alive = 1, .representation = 'b', .position = {0, 0, 0, 0}};
ck_assert_int_eq(collided(&s1, &s2), 1);
SPRITE s3 = {.alive = 1, .representation = 'a', .position = {0, 0, 1, 0}};
SPRITE s4 = {.alive = 1, .representation = 'b', .position = {0, 0, 0, 0}};
ck_assert_int_eq(collided(&s3, &s4), 1);
SPRITE s5 = {.alive = 1, .representation = 'a', .position = {0, 1, 0, 0}};
SPRITE s6 = {.alive = 1, .representation = 'b', .position = {0, 0, 0, 1}};
ck_assert_int_eq(collided(&s5, &s6), 1);
SPRITE s7 = {.alive = 1, .representation = 'a', .position = {0, 0, 0, 1}};
SPRITE s8 = {.alive = 1, .representation = 'b', .position = {0, 1, 0, 0}};
ck_assert_int_eq(collided(&s7, &s8), 1);
SPRITE s9 = {.alive = 1, .representation = 'a', .position = {1, 0, 0, 0}};
SPRITE s10 = {.alive = 1, .representation = 'b', .position = {0, 0, 1, 0}};
ck_assert_int_eq(collided(&s9, &s10), 1);
SPRITE s11 = {.alive = 1, .representation = 'a', .position = {0, 2, 0, 1}};
SPRITE s12 = {.alive = 1, .representation = 'b', .position = {0, 1, 0, 0}};
ck_assert_int_eq(collided(&s11, &s12), 0);
}
END_TEST
Suite * mr_do_suite(void);
Suite * mr_do_suite(void){
Suite *s;
TCase *tc_unit;
s = suite_create("Mr_DO");
//testa casos unitarios
tc_unit = tcase_create("Units");
tcase_add_test(tc_unit, test_push);
tcase_add_test(tc_unit, test_list_size);
tcase_add_test(tc_unit, test_count_alive);
tcase_add_test(tc_unit, test_collided);
suite_add_tcase(s, tc_unit);
return s;
}
int main(void){
int number_failed;
Suite *s;
SRunner *sr;
s = mr_do_suite();
sr = srunner_create(s);
srunner_run_all(sr, CK_NORMAL);
number_failed = srunner_ntests_failed(sr);
srunner_free(sr);
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}