-
Notifications
You must be signed in to change notification settings - Fork 6
/
check_median.c
65 lines (51 loc) · 1.09 KB
/
check_median.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
#include <check.h>
#include <stdlib.h>
#include "median.h"
START_TEST(test_insertion_sort)
{
int a[] = {3, 2, 1};
insertion_sort(a, 3);
for(int i = 0; i < 2; i++) {
ck_assert(a[i] <= a[i+1]);
}
}
END_TEST
START_TEST(test_partition)
{
int a[] = {12, 9, 3, 4, 11, 10, 7};
partition(a, 7, 7);
for(int i = 0; i < 2; i++) {
ck_assert(a[i] < 7);
}
ck_assert(a[2] == 7);
for(int i = 3; i < 7; i++) {
ck_assert(a[i] > 7);
}
}
END_TEST
START_TEST(test_select)
{
int a[] = {12, 9, 3, 4, 11, 10, 7};
int median = select(a, 3, 7);
ck_assert_int_eq(median, 9);
}
END_TEST
Suite *median_suite()
{
Suite *s = suite_create("Median");
TCase *tc_core = tcase_create("Core");
tcase_add_test(tc_core, test_insertion_sort);
tcase_add_test(tc_core, test_partition);
tcase_add_test(tc_core, test_select);
suite_add_tcase(s, tc_core);
return s;
}
int main()
{
Suite *s = median_suite();
SRunner *sr = srunner_create(s);
srunner_run_all(sr, CK_NORMAL);
int n_failed = srunner_ntests_failed(sr);
srunner_free(sr);
return (n_failed == 0)? EXIT_SUCCESS : EXIT_FAILURE;
}