This repository has been archived by the owner on Dec 26, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_fuzzyclock.c
92 lines (71 loc) · 2.45 KB
/
check_fuzzyclock.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
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <check.h>
#include "../src/fuzzyclock.h"
START_TEST(test_get_hour_string) {
fail_if(strcmp(get_hour_string(1), "one") != 0, NULL);
fail_if(strcmp(get_hour_string(2), "two") != 0, NULL);
fail_if(strcmp(get_hour_string(3), "three") != 0, NULL);
fail_if(strcmp(get_hour_string(4), "four") != 0, NULL);
fail_if(strcmp(get_hour_string(5), "five") != 0, NULL);
fail_if(strcmp(get_hour_string(6), "six") != 0, NULL);
fail_if(strcmp(get_hour_string(7), "seven") != 0, NULL);
fail_if(strcmp(get_hour_string(8), "eight") != 0, NULL);
fail_if(strcmp(get_hour_string(9), "nine") != 0, NULL);
fail_if(strcmp(get_hour_string(10), "ten") != 0, NULL);
fail_if(strcmp(get_hour_string(11), "eleven") != 0, NULL);
fail_if(strcmp(get_hour_string(12), "twelve") != 0, NULL);
}
END_TEST
START_TEST(test_oclock) {
char buff[MAX_MSG_SIZE];
char test[MAX_MSG_SIZE];
time_t now = time(NULL);
struct tm* clock = localtime(&now);
int i = 0;
// Verifying o' clock
clock->tm_min = 0;
for (i = 1; i < 12; i++) {
clock->tm_hour = i;
snprintf(test, MAX_MSG_SIZE, "%s o' clock", get_hour_string(i));
get_fuzzy_time(clock, buff);
fail_if(strcmp(test, buff) != 0, "T%0d:WANTED \"%s\", GOT \"%s\"", i, test, buff);
}
}
END_TEST
START_TEST(test_fivepast) {
char buff[MAX_MSG_SIZE];
char test[MAX_MSG_SIZE];
time_t now = time(NULL);
struct tm* clock = localtime(&now);
int i = 0;
// Verifying "five past"
clock->tm_hour = 1;
for (i = 3; i < 8; i++) {
clock->tm_min = i;
snprintf(test, MAX_MSG_SIZE, "five past one");
get_fuzzy_time(clock, buff);
fail_if(strcmp(test, buff) != 0, "T%0d:WANTED \"%s\", GOT \"%s\"", i, test, buff);
}
}
END_TEST
Suite* fuzzy_suite(void) {
Suite* suite = suite_create("fuzzyclock");
TCase* tc_core = tcase_create("Core");
tcase_add_test(tc_core, test_get_hour_string);
tcase_add_test(tc_core, test_oclock);
/* tcase_add_test(tc_core, test_fivepast); */
suite_add_tcase(suite, tc_core);
return suite;
}
int main(int argc, char const* argv[])
{
int num_failed = 0;
Suite* suite = fuzzy_suite();
SRunner* runner = srunner_create(suite);
srunner_run_all(runner, CK_NORMAL);
num_failed = srunner_ntests_failed(runner);
srunner_free(runner);
return (num_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}