Skip to content

Commit 7e1ac61

Browse files
✨ feat: Cover in-range search misses.
1 parent 8066aee commit 7e1ac61

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/fixtures.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export const arrayValue = (ctor, v) => {
7878
switch (ctor) {
7979
case BigInt64Array:
8080
case BigUint64Array:
81-
return BigInt(v);
81+
return BigInt(Math.floor(v));
8282
default:
8383
return v;
8484
}

src/macro.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,36 @@ const macro = (
3333
t.is(pos(r), length, `where === ${length}`);
3434

3535
// CHECK BODY
36-
for (let i = length - 1; i >= 0; --i) {
36+
for (let i = 0; i < length; ++i) {
3737
r = search(delta, a, 0, length, a[i]);
3838
t.true(found(r), `found a[${i}]`);
3939
t.deepEqual(a[pos(r)], a[i], `val === ${a[i]}`);
4040
}
4141

42+
// CHECK INNER MISS
43+
for (let i = 1; i < length; ++i) {
44+
const values = new Set([
45+
arrayValue(array, Number(a[i - 1]) + (delta(-1, 0) < 0 ? 1 : -1)),
46+
arrayValue(array, (Number(a[i - 1]) + Number(a[i])) / 2),
47+
arrayValue(array, Number(a[i]) + (delta(-1, 0) < 0 ? -1 : 1)),
48+
]);
49+
for (const v of values) {
50+
if (delta(v, a[i - 1]) <= 0) continue;
51+
if (delta(v, a[i]) >= 0) continue;
52+
const r = search(delta, a, 0, length, v);
53+
t.false(found(r), `not found ${v}`);
54+
t.deepEqual(pos(r), i, `pos === ${i}`);
55+
}
56+
}
57+
4258
// CHECK < OUTER BOUND
4359
v = delta(-1, 0) > 0 ? _max : _min;
4460
r = search(delta, a, 0, length, v);
45-
t.false(found(r), 'not found -1');
61+
t.false(found(r), `not found ${v}`);
4662
t.is(pos(r), 0, 'where === 0');
4763
} else {
4864
const r = search(delta, a, 0, length, _min);
49-
t.false(found(r), 'not found -1');
65+
t.false(found(r), `not found ${_min}`);
5066
t.is(pos(r), 0, 'where === 0');
5167
}
5268

0 commit comments

Comments
 (0)