-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_sort.c
113 lines (107 loc) · 2.99 KB
/
test_sort.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
#include <stdlib.h>
#include <math.h>
#include <check.h>
#include "fradix16-64.h"
START_TEST(positives)
{
float c0[] = {3.0, 2.0, 4.0, 1.0};
float *cols[] = {c0};
int indicies[] = {0, 1, 2, 3};
direction dirs[] = {DOWN};
fradixSort16_64_init();
fradixSortL16_64((uint32_t**)cols, dirs, sizeof(cols) / sizeof(cols[0]),
sizeof(c0) / sizeof(c0[0]), indicies);
ck_assert_float_eq(c0[indicies[0]], 4.0);
ck_assert_float_eq(c0[indicies[1]], 3.0);
ck_assert_float_eq(c0[indicies[2]], 2.0);
ck_assert_float_eq(c0[indicies[3]], 1.0);
}
END_TEST
START_TEST(negatives)
{
float c0[] = {-3.0, -2.0, -4.0, -1.0};
float *cols[] = {c0};
int indicies[] = {0, 1, 2, 3};
direction dirs[] = {DOWN};
fradixSort16_64_init();
fradixSortL16_64((uint32_t**)cols, dirs, sizeof(cols) / sizeof(cols[0]),
sizeof(c0) / sizeof(c0[0]), indicies);
ck_assert_float_eq(c0[indicies[0]], -1.0);
ck_assert_float_eq(c0[indicies[1]], -2.0);
ck_assert_float_eq(c0[indicies[2]], -3.0);
ck_assert_float_eq(c0[indicies[3]], -4.0);
}
END_TEST
START_TEST(pos_neg)
{
float c0[] = {3.0, -2.0, 4.0, -1.0};
float *cols[] = {c0};
int indicies[] = {0, 1, 2, 3};
direction dirs[] = {DOWN};
fradixSort16_64_init();
fradixSortL16_64((uint32_t**)cols, dirs, sizeof(cols) / sizeof(cols[0]),
sizeof(c0) / sizeof(c0[0]), indicies);
ck_assert_float_eq(c0[indicies[0]], 4.0);
ck_assert_float_eq(c0[indicies[1]], 3.0);
ck_assert_float_eq(c0[indicies[2]], -1.0);
ck_assert_float_eq(c0[indicies[3]], -2.0);
}
END_TEST
START_TEST(pos_neg_nan)
{
float c0[] = {3.0, -2.0, NAN, 4.0, -1.0};
float *cols[] = {c0};
int indicies[] = {0, 1, 2, 3, 4};
direction dirs[] = {DOWN};
fradixSort16_64_init();
fradixSortL16_64((uint32_t**)cols, dirs, sizeof(cols) / sizeof(cols[0]),
sizeof(c0) / sizeof(c0[0]), indicies);
ck_assert_float_eq(c0[indicies[0]], 4.0);
ck_assert_float_eq(c0[indicies[1]], 3.0);
ck_assert_float_eq(c0[indicies[2]], -1.0);
ck_assert_float_eq(c0[indicies[3]], -2.0);
ck_assert_float_nan(c0[indicies[4]]);
}
END_TEST
START_TEST(pos_neg_nan_large)
{
int n = 20 * 5;
float *c0 = malloc(sizeof(float) * n);
for (int i = 0; i < n; i += 5) {
c0[i] = 3.0;
c0[i + 1] = -2.0;
c0[i + 2] = NAN;
c0[i + 3] = 4.0;
c0[i + 4] = -1.0;
}
float *cols[] = {c0};
int *indicies = malloc(sizeof(int) * n);
for (int i = 0; i < n; ++i) {
indicies[i] = i;
}
direction dirs[] = {DOWN};
fradixSort16_64_init();
fradixSortL16_64((uint32_t**)cols, dirs, 1, n, indicies);
for (int i = 0; i < 20; ++i) {
ck_assert_float_eq(c0[indicies[i]], 4.0);
}
for (int i = 20; i < 40; ++i) {
ck_assert_float_eq(c0[indicies[i]], 3.0);
}
for (int i = 40; i < 60; ++i) {
ck_assert_float_eq(c0[indicies[i]], -1.0);
}
for (int i = 60; i < 80; ++i) {
ck_assert_float_eq(c0[indicies[i]], -2.0);
}
for (int i = 80; i < 100; ++i) {
ck_assert_float_nan(c0[indicies[i]]);
}
}
void add_sort(TCase *tc) {
tcase_add_test(tc, positives);
tcase_add_test(tc, negatives);
tcase_add_test(tc, pos_neg);
tcase_add_test(tc, pos_neg_nan);
tcase_add_test(tc, pos_neg_nan_large);
}