Skip to content

Commit 4a98aa7

Browse files
🧪 test: Split tests, cover new API.
1 parent d168387 commit 4a98aa7

File tree

7 files changed

+49
-27
lines changed

7 files changed

+49
-27
lines changed

test/fixtures.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import {increasing as _inc, decreasing as _dec} from '@aureooms/js-compare';
22

33
export const increasing = (a, b) => _inc(a, b);
4+
increasing.step = 1;
45
export const decreasing = (a, b) => _dec(a, b);
6+
decreasing.step = -1;

test/src/RedBlackTree/get.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import test from 'ava';
22

3-
import {increasing, decreasing} from '@aureooms/js-compare';
3+
import {increasing, decreasing} from '../../fixtures.js';
44

55
import {range} from '@aureooms/js-itertools';
66

77
import {RedBlackTree} from '../../../src/index.js';
88

9-
test('RedBlackTree::get', (t) => {
10-
for (const compare of [increasing, decreasing]) {
11-
const tree = new RedBlackTree(compare);
9+
for (const compare of [increasing, decreasing]) {
10+
test(`RedBlackTree::get [${compare.name}]`, (t) => {
11+
const tree = RedBlackTree.empty(compare);
1212

1313
t.is(tree.get(0), null);
1414

@@ -28,5 +28,5 @@ test('RedBlackTree::get', (t) => {
2828

2929
t.is(tree.get(-1), null);
3030
t.is(tree.get(n), null);
31-
}
32-
});
31+
});
32+
}

test/src/RedBlackTree/has.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import test from 'ava';
22

3-
import {increasing, decreasing} from '@aureooms/js-compare';
3+
import {increasing, decreasing} from '../../fixtures.js';
44

55
import {range} from '@aureooms/js-itertools';
66

77
import {RedBlackTree} from '../../../src/index.js';
88

9-
test('RedBlackTree::has', (t) => {
10-
for (const compare of [increasing, decreasing]) {
9+
for (const compare of [increasing, decreasing]) {
10+
test(`RedBlackTree::has [${compare.name}]`, (t) => {
1111
const tree = new RedBlackTree(compare);
1212

1313
t.falsy(tree.has(0));
@@ -28,5 +28,5 @@ test('RedBlackTree::has', (t) => {
2828

2929
t.falsy(tree.has(-1));
3030
t.falsy(tree.has(n));
31-
}
32-
});
31+
});
32+
}

test/src/RedBlackTree/isEmpty.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,30 @@ import {range} from '@aureooms/js-itertools';
44

55
import {increasing, decreasing} from '../../fixtures.js';
66

7-
import {RedBlackTree} from '../../../src/index.js';
7+
import {empty, from, RedBlackTree} from '../../../src/index.js';
8+
9+
for (const compare of [increasing, decreasing]) {
10+
test(`empty(${compare.name})`, (t) => {
11+
t.true(empty(compare).isEmpty());
12+
});
13+
14+
test(`from(${compare.name}, [])`, (t) => {
15+
t.true(from(compare, []).isEmpty());
16+
});
17+
18+
test(`from(${compare.name}, range(100))`, (t) => {
19+
t.false(from(compare, range(100)).isEmpty());
20+
});
21+
22+
test(`RedBlackTree.empty(${compare.name}) + add + remove`, (t) => {
23+
const tree = RedBlackTree.empty(compare);
24+
t.true(tree.isEmpty());
25+
tree.add('x');
26+
t.false(tree.isEmpty());
27+
tree.remove('x');
28+
t.true(tree.isEmpty());
29+
});
30+
}
831

932
const macro = (t, compare, items, expected) => {
1033
const tree = RedBlackTree.from(compare, items);

test/src/RedBlackTree/iter.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import test from 'ava';
22

3-
import {increasing, decreasing} from '@aureooms/js-compare';
3+
import {increasing, decreasing} from '../../fixtures.js';
44

55
import {list, range} from '@aureooms/js-itertools';
66

77
import {RedBlackTree} from '../../../src/index.js';
88

9-
test('RedBlackTree::Symbol.iterator', (t) => {
10-
for (const compare of [increasing, decreasing]) {
9+
for (const compare of [increasing, decreasing]) {
10+
test(`RedBlackTree::Symbol.iterator [${compare.name}]`, (t) => {
1111
const tree = new RedBlackTree(compare);
1212

1313
const a1 = list(tree);
@@ -30,5 +30,5 @@ test('RedBlackTree::Symbol.iterator', (t) => {
3030

3131
t.deepEqual(a2.length, n, `tree contains ${n} elements`);
3232
t.deepEqual(a2, reference, 'tree is sorted');
33-
}
34-
});
33+
});
34+
}

test/src/RedBlackTree/range.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
import test from 'ava';
22

3-
import {increasing, decreasing} from '@aureooms/js-compare';
3+
import {increasing, decreasing} from '../../fixtures.js';
44

55
import {list, range} from '@aureooms/js-itertools';
66

77
import {shuffle} from '@aureooms/js-random';
88

99
import {RedBlackTree} from '../../../src/index.js';
1010

11-
test('RedBlackTree::range', (t) => {
12-
for (const [s, compare] of [
13-
[1, increasing],
14-
[-1, decreasing],
15-
]) {
11+
for (const compare of [increasing, decreasing]) {
12+
test(`RedBlackTree::range [${compare.name}]`, (t) => {
1613
const n = 10000;
1714
const reference = range(n);
1815
shuffle(reference, 0, n);
1916

2017
const tree = RedBlackTree.from(compare, reference);
2118

2219
const x = (a, b) =>
23-
t.deepEqual(list(tree.range(a, b)), list(range(a, b, s)));
20+
t.deepEqual(list(tree.range(a, b)), list(range(a, b, compare.step)));
2421

2522
x(0, n);
2623
x(10, 20);
@@ -29,5 +26,5 @@ test('RedBlackTree::range', (t) => {
2926
x(13, 7);
3027
x(n - 1, -1);
3128
x(10, 10);
32-
}
33-
});
29+
});
30+
}

test/src/RedBlackTree/remove.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import test from 'ava';
22

3-
import {increasing} from '@aureooms/js-compare';
3+
import {increasing} from '../../fixtures.js';
44

55
import {list, range, sorted, head, iter, exhaust} from '@aureooms/js-itertools';
66

0 commit comments

Comments
 (0)