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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
#include "../../kit/lower_bound.h"
#include "../../kit/array_ref.h"
#define TEST_FILE lower_bound
#include "../../kit_test/test.h"
static int kit_less_int(int left, int right) {
return left < right;
}
static int kit_less_int_ref(int const *left, int const *right) {
return *left < *right;
}
TEST("lower bound empty") {
AR(ref, int) = { .size = 0, .values = NULL };
ptrdiff_t index;
LOWER_BOUND(index, ref, 42, kit_less_int);
REQUIRE(index == 0);
}
TEST("lower bound single left") {
int const v[1] = { 42 };
AR(ref, int) = { .size = 1, .values = v };
ptrdiff_t index;
LOWER_BOUND(index, ref, 42, kit_less_int);
REQUIRE(index == 0);
}
TEST("lower bound single right") {
int const v[1] = { 42 };
AR(ref, int) = { .size = 1, .values = v };
ptrdiff_t index;
LOWER_BOUND(index, ref, 43, kit_less_int);
REQUIRE(index == 1);
}
TEST("lower bound first of four") {
int const v[4] = { 1, 2, 3, 4 };
AR(ref, int) = { .size = 4, .values = v };
ptrdiff_t index;
LOWER_BOUND(index, ref, 1, kit_less_int);
REQUIRE(index == 0);
}
TEST("lower bound second of four") {
int const v[4] = { 1, 2, 3, 4 };
AR(ref, int) = { .size = 4, .values = v };
ptrdiff_t index;
LOWER_BOUND(index, ref, 2, kit_less_int);
REQUIRE(index == 1);
}
TEST("lower bound third of four") {
int const v[4] = { 1, 2, 3, 4 };
AR(ref, int) = { .size = 4, .values = v };
ptrdiff_t index;
LOWER_BOUND(index, ref, 3, kit_less_int);
REQUIRE(index == 2);
}
TEST("lower bound forth of four") {
int const v[4] = { 1, 2, 3, 4 };
AR(ref, int) = { .size = 4, .values = v };
ptrdiff_t index;
LOWER_BOUND(index, ref, 4, kit_less_int);
REQUIRE(index == 3);
}
TEST("lower bound fifth of four") {
int const v[4] = { 1, 2, 3, 4 };
AR(ref, int) = { .size = 4, .values = v };
ptrdiff_t index;
LOWER_BOUND(index, ref, 5, kit_less_int);
REQUIRE(index == 4);
}
TEST("lower bound first of five") {
int const v[5] = { 1, 2, 3, 4, 5 };
AR(ref, int) = { .size = 5, .values = v };
ptrdiff_t index;
LOWER_BOUND(index, ref, 1, kit_less_int);
REQUIRE(index == 0);
}
TEST("lower bound second of five") {
int const v[5] = { 1, 2, 3, 4, 5 };
AR(ref, int) = { .size = 5, .values = v };
ptrdiff_t index;
LOWER_BOUND(index, ref, 2, kit_less_int);
REQUIRE(index == 1);
}
TEST("lower bound third of five") {
int const v[5] = { 1, 2, 3, 4, 5 };
AR(ref, int) = { .size = 5, .values = v };
ptrdiff_t index;
LOWER_BOUND(index, ref, 3, kit_less_int);
REQUIRE(index == 2);
}
TEST("lower bound forth of five") {
int const v[5] = { 1, 2, 3, 4, 5 };
AR(ref, int) = { .size = 5, .values = v };
ptrdiff_t index;
LOWER_BOUND(index, ref, 4, kit_less_int);
REQUIRE(index == 3);
}
TEST("lower bound fifth of five") {
int const v[5] = { 1, 2, 3, 4, 5 };
AR(ref, int) = { .size = 5, .values = v };
ptrdiff_t index;
LOWER_BOUND(index, ref, 5, kit_less_int);
REQUIRE(index == 4);
}
TEST("lower bound sixth of five") {
int const v[5] = { 1, 2, 3, 4, 5 };
AR(ref, int) = { .size = 5, .values = v };
ptrdiff_t index;
LOWER_BOUND(index, ref, 6, kit_less_int);
REQUIRE(index == 5);
}
TEST("lower bound ref first of four") {
int const v[4] = { 1, 2, 3, 4 };
int const value = 1;
AR(ref, int) = { .size = 4, .values = v };
ptrdiff_t index;
LOWER_BOUND_REF(index, ref, &value, kit_less_int_ref);
REQUIRE(index == 0);
}
TEST("lower bound ref second of four") {
int const v[4] = { 1, 2, 3, 4 };
int const value = 2;
AR(ref, int) = { .size = 4, .values = v };
ptrdiff_t index;
LOWER_BOUND_REF(index, ref, &value, kit_less_int_ref);
REQUIRE(index == 1);
}
TEST("lower bound ref fifth of five") {
int const v[5] = { 1, 2, 3, 4, 5 };
int const value = 5;
AR(ref, int) = { .size = 5, .values = v };
ptrdiff_t index;
LOWER_BOUND_REF(index, ref, &value, kit_less_int_ref);
REQUIRE(index == 4);
}
TEST("lower bound ref sixth of five") {
int const v[5] = { 1, 2, 3, 4, 5 };
int const value = 6;
AR(ref, int) = { .size = 5, .values = v };
ptrdiff_t index;
LOWER_BOUND_REF(index, ref, &value, kit_less_int_ref);
REQUIRE(index == 5);
}
|