Skip to content

Commit a6fcc0a

Browse files
☔ test(concatenate/nodes): Cover all cases to prevent regression.
This is progress on #120.
1 parent 855888c commit a6fcc0a

File tree

12 files changed

+413
-0
lines changed

12 files changed

+413
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"@iterable-iterator/list": "1.0.1",
7878
"@iterable-iterator/map": "1.0.1",
7979
"@iterable-iterator/range": "2.1.0",
80+
"@iterable-iterator/repeat": "1.0.1",
8081
"@iterable-iterator/reversed": "1.0.0",
8182
"@iterable-iterator/tee": "1.0.0",
8283
"@js-library/commitlint-config": "0.0.4",
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import test from 'ava';
2+
3+
import {Measures} from '@functional-abstraction/measure';
4+
import {nrepeat} from '@iterable-iterator/repeat';
5+
6+
import {empty} from '../../../../../../src/index.js';
7+
8+
const {COUNTER} = Measures;
9+
10+
test('cover', (t) => {
11+
const x = 'x';
12+
13+
// (xxxx, (), x)
14+
let A = empty(COUNTER).cons(x).cons(x).cons(x).cons(x).cons(x);
15+
A = A.cons(x); // (xx, ([xxx]), x)
16+
A = A.cons(x).cons(x); // (xxxx, ([xxx]), x)
17+
A = A.cons(x); // (xx, ([xxx], (), [xxx]), x)
18+
19+
// (x, (), xxxx)
20+
let B = empty(COUNTER).push(x).push(x).push(x).push(x).push(x);
21+
B = B.push(x); // (x, ([xxx]), xx)
22+
B = B.push(x).push(x); // (x, ([xxx]), xxxx)
23+
B = B.push(x); // (x, ([xxx], (), [xxx]), xx)
24+
25+
t.is(
26+
A.middle.right.measure(COUNTER) +
27+
A.right._nodes(COUNTER, B.left).length +
28+
B.middle.left.measure(COUNTER),
29+
3,
30+
);
31+
32+
const C = A.concat(B);
33+
34+
t.deepEqual([...C], [...nrepeat(x, 18)]);
35+
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import test from 'ava';
2+
3+
import {Measures} from '@functional-abstraction/measure';
4+
import {nrepeat} from '@iterable-iterator/repeat';
5+
6+
import {empty} from '../../../../../../src/index.js';
7+
8+
const {COUNTER} = Measures;
9+
10+
test('cover', (t) => {
11+
const x = 'x';
12+
13+
// (xxxx, (), x)
14+
let A = empty(COUNTER).cons(x).cons(x).cons(x).cons(x).cons(x);
15+
A = A.cons(x); // (xx, ([xxx]), x)
16+
A = A.cons(x).cons(x); // (xxxx, ([xxx]), x)
17+
A = A.cons(x); // (xx, ([xxx], (), [xxx]), x)
18+
19+
// (x, (), xxxx)
20+
let B = empty(COUNTER).push(x).push(x).push(x).push(x).push(x);
21+
B = B.push(x); // (x, ([xxx]), xx)
22+
B = B.push(x).push(x); // (x, ([xxx]), xxxx)
23+
B = B.push(x); // (x, ([xxx], (), [xxx]), xx)
24+
25+
t.is(
26+
B.middle.right.measure(COUNTER) +
27+
B.right._nodes(COUNTER, A.left).length +
28+
A.middle.left.measure(COUNTER),
29+
4,
30+
);
31+
32+
const C = B.concat(A);
33+
34+
t.deepEqual([...C], [...nrepeat(x, 18)]);
35+
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import test from 'ava';
2+
3+
import {Measures} from '@functional-abstraction/measure';
4+
import {nrepeat} from '@iterable-iterator/repeat';
5+
6+
import {empty} from '../../../../../../src/index.js';
7+
8+
const {COUNTER} = Measures;
9+
10+
test('cover', (t) => {
11+
const x = 'x';
12+
13+
// (xxxx, (), x)
14+
let A = empty(COUNTER).cons(x).cons(x).cons(x).cons(x).cons(x);
15+
A = A.cons(x); // (xx, ([xxx]), x)
16+
A = A.cons(x).cons(x); // (xxxx, ([xxx]), x)
17+
A = A.cons(x); // (xx, ([xxx], (), [xxx]), x)
18+
A = A.cons(x).cons(x); // (xxxx, ([xxx], (), [xxx]), x)
19+
20+
// (x, (), xxxx)
21+
let B = empty(COUNTER).push(x).push(x).push(x).push(x).push(x);
22+
B = B.push(x); // (x, ([xxx]), xx)
23+
B = B.push(x).push(x); // (x, ([xxx]), xxxx)
24+
B = B.push(x); // (x, ([xxx], (), [xxx]), xx)
25+
B = B.push(x); // (x, ([xxx], (), [xxx]), xxx)
26+
27+
t.is(
28+
B.middle.right.measure(COUNTER) +
29+
B.right._nodes(COUNTER, A.left).length +
30+
A.middle.left.measure(COUNTER),
31+
5,
32+
);
33+
34+
const C = B.concat(A);
35+
36+
t.deepEqual([...C], [...nrepeat(x, 21)]);
37+
});
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import test from 'ava';
2+
3+
import {Measures} from '@functional-abstraction/measure';
4+
import {nrepeat} from '@iterable-iterator/repeat';
5+
6+
import {empty} from '../../../../../../src/index.js';
7+
8+
const {COUNTER} = Measures;
9+
10+
test('cover', (t) => {
11+
const x = 'x';
12+
13+
// (xxxx, (), x)
14+
let A = empty(COUNTER).cons(x).cons(x).cons(x).cons(x).cons(x);
15+
A = A.cons(x); // (xx, ([xxx]), x)
16+
A = A.cons(x).cons(x); // (xxxx, ([xxx]), x)
17+
A = A.cons(x); // (xx, ([xxx], (), [xxx]), x)
18+
A = A.cons(x).cons(x); // (xxxx, ([xxx], (), [xxx]), x)
19+
A = A.cons(x); // (xx, ([xxx][xxx], (), [xxx]), x)
20+
21+
// (x, (), xxxx)
22+
let B = empty(COUNTER).push(x).push(x).push(x).push(x).push(x);
23+
B = B.push(x); // (x, ([xxx]), xx)
24+
B = B.push(x).push(x); // (x, ([xxx]), xxxx)
25+
B = B.push(x); // (x, ([xxx], (), [xxx]), xx)
26+
B = B.push(x).push(x); // (x, ([xxx], (), [xxx]), xxxx)
27+
B = B.push(x); // (x, ([xxx], (), [xxx][xxx]), xx)
28+
B = B.push(x).push(x); // (x, ([xxx], (), [xxx][xxx]), xxxx)
29+
30+
t.is(
31+
B.middle.right.measure(COUNTER) +
32+
B.right._nodes(COUNTER, A.left).length +
33+
A.middle.left.measure(COUNTER),
34+
6,
35+
);
36+
37+
const C = B.concat(A);
38+
39+
t.deepEqual([...C], [...nrepeat(x, 26)]);
40+
});
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import test from 'ava';
2+
3+
import {Measures} from '@functional-abstraction/measure';
4+
import {nrepeat} from '@iterable-iterator/repeat';
5+
6+
import {empty} from '../../../../../../src/index.js';
7+
8+
const {COUNTER} = Measures;
9+
10+
test('cover', (t) => {
11+
const x = 'x';
12+
13+
// (xxxx, (), x)
14+
let A = empty(COUNTER).cons(x).cons(x).cons(x).cons(x).cons(x);
15+
A = A.cons(x); // (xx, ([xxx]), x)
16+
A = A.cons(x).cons(x); // (xxxx, ([xxx]), x)
17+
A = A.cons(x); // (xx, ([xxx], (), [xxx]), x)
18+
A = A.cons(x).cons(x); // (xxxx, ([xxx], (), [xxx]), x)
19+
A = A.cons(x); // (xx, ([xxx][xxx], (), [xxx]), x)
20+
A = A.cons(x); // (xxx, ([xxx][xxx], (), [xxx]), x)
21+
22+
// (x, (), xxxx)
23+
let B = empty(COUNTER).push(x).push(x).push(x).push(x).push(x);
24+
B = B.push(x); // (x, ([xxx]), xx)
25+
B = B.push(x).push(x); // (x, ([xxx]), xxxx)
26+
B = B.push(x); // (x, ([xxx], (), [xxx]), xx)
27+
B = B.push(x).push(x); // (x, ([xxx], (), [xxx]), xxxx)
28+
B = B.push(x); // (x, ([xxx], (), [xxx][xxx]), xx)
29+
B = B.push(x).push(x); // (x, ([xxx], (), [xxx][xxx]), xxxx)
30+
31+
t.is(
32+
B.middle.right.measure(COUNTER) +
33+
B.right._nodes(COUNTER, A.left).length +
34+
A.middle.left.measure(COUNTER),
35+
7,
36+
);
37+
38+
const C = B.concat(A);
39+
40+
t.deepEqual([...C], [...nrepeat(x, 27)]);
41+
});
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import test from 'ava';
2+
3+
import {Measures} from '@functional-abstraction/measure';
4+
import {nrepeat} from '@iterable-iterator/repeat';
5+
6+
import {empty} from '../../../../../../src/index.js';
7+
8+
const {COUNTER} = Measures;
9+
10+
test('cover', (t) => {
11+
const x = 'x';
12+
13+
// (xxxx, (), x)
14+
let A = empty(COUNTER).cons(x).cons(x).cons(x).cons(x).cons(x);
15+
A = A.cons(x); // (xx, ([xxx]), x)
16+
A = A.cons(x).cons(x); // (xxxx, ([xxx]), x)
17+
A = A.cons(x); // (xx, ([xxx], (), [xxx]), x)
18+
A = A.cons(x).cons(x); // (xxxx, ([xxx], (), [xxx]), x)
19+
A = A.cons(x); // (xx, ([xxx][xxx], (), [xxx]), x)
20+
A = A.cons(x).cons(x); // (xxxx, ([xxx][xxx], (), [xxx]), x)
21+
A = A.cons(x); // (xx, ([xxx][xxx][xxx], (), [xxx]), x)
22+
23+
// (x, (), xxxx)
24+
let B = empty(COUNTER).push(x).push(x).push(x).push(x).push(x);
25+
B = B.push(x); // (x, ([xxx]), xx)
26+
B = B.push(x).push(x); // (x, ([xxx]), xxxx)
27+
B = B.push(x); // (x, ([xxx], (), [xxx]), xx)
28+
B = B.push(x).push(x); // (x, ([xxx], (), [xxx]), xxxx)
29+
B = B.push(x); // (x, ([xxx], (), [xxx][xxx]), xx)
30+
B = B.push(x).push(x); // (x, ([xxx], (), [xxx][xxx]), xxxx)
31+
B = B.push(x); // (x, ([xxx], (), [xxx][xxx][xxx]), xx)
32+
33+
t.is(
34+
B.middle.right.measure(COUNTER) +
35+
B.right._nodes(COUNTER, A.left).length +
36+
A.middle.left.measure(COUNTER),
37+
8,
38+
);
39+
40+
const C = B.concat(A);
41+
42+
t.deepEqual([...C], [...nrepeat(x, 30)]);
43+
});
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import test from 'ava';
2+
3+
import {Measures} from '@functional-abstraction/measure';
4+
import {nrepeat} from '@iterable-iterator/repeat';
5+
6+
import {empty} from '../../../../../../src/index.js';
7+
8+
const {COUNTER} = Measures;
9+
10+
test('cover', (t) => {
11+
const x = 'x';
12+
13+
// (xxxx, (), x)
14+
let A = empty(COUNTER).cons(x).cons(x).cons(x).cons(x).cons(x);
15+
A = A.cons(x); // (xx, ([xxx]), x)
16+
A = A.cons(x).cons(x); // (xxxx, ([xxx]), x)
17+
A = A.cons(x); // (xx, ([xxx], (), [xxx]), x)
18+
A = A.cons(x).cons(x); // (xxxx, ([xxx], (), [xxx]), x)
19+
A = A.cons(x); // (xx, ([xxx][xxx], (), [xxx]), x)
20+
A = A.cons(x).cons(x); // (xxxx, ([xxx][xxx], (), [xxx]), x)
21+
A = A.cons(x); // (xx, ([xxx][xxx][xxx], (), [xxx]), x)
22+
A = A.cons(x).cons(x); // (xxxx, ([xxx][xxx][xxx], (), [xxx]), x)
23+
24+
// (x, (), xxxx)
25+
let B = empty(COUNTER).push(x).push(x).push(x).push(x).push(x);
26+
B = B.push(x); // (x, ([xxx]), xx)
27+
B = B.push(x).push(x); // (x, ([xxx]), xxxx)
28+
B = B.push(x); // (x, ([xxx], (), [xxx]), xx)
29+
B = B.push(x).push(x); // (x, ([xxx], (), [xxx]), xxxx)
30+
B = B.push(x); // (x, ([xxx], (), [xxx][xxx]), xx)
31+
B = B.push(x).push(x); // (x, ([xxx], (), [xxx][xxx]), xxxx)
32+
B = B.push(x); // (x, ([xxx], (), [xxx][xxx][xxx]), xx)
33+
B = B.push(x).push(x); // (x, ([xxx], (), [xxx][xxx][xxx]), xxxx)
34+
35+
t.is(
36+
B.middle.right.measure(COUNTER) +
37+
B.right._nodes(COUNTER, A.left).length +
38+
A.middle.left.measure(COUNTER),
39+
9,
40+
);
41+
42+
const C = B.concat(A);
43+
44+
t.deepEqual([...C], [...nrepeat(x, 34)]);
45+
});
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import test from 'ava';
2+
3+
import {Measures} from '@functional-abstraction/measure';
4+
import {nrepeat} from '@iterable-iterator/repeat';
5+
6+
import {empty} from '../../../../../../src/index.js';
7+
8+
const {COUNTER} = Measures;
9+
10+
test('cover', (t) => {
11+
const x = 'x';
12+
13+
// (xxxx, (), x)
14+
let A = empty(COUNTER).cons(x).cons(x).cons(x).cons(x).cons(x);
15+
A = A.cons(x); // (xx, ([xxx]), x)
16+
A = A.cons(x).cons(x); // (xxxx, ([xxx]), x)
17+
A = A.cons(x); // (xx, ([xxx], (), [xxx]), x)
18+
A = A.cons(x).cons(x); // (xxxx, ([xxx], (), [xxx]), x)
19+
A = A.cons(x); // (xx, ([xxx][xxx], (), [xxx]), x)
20+
A = A.cons(x).cons(x); // (xxxx, ([xxx][xxx], (), [xxx]), x)
21+
A = A.cons(x); // (xx, ([xxx][xxx][xxx], (), [xxx]), x)
22+
A = A.cons(x).cons(x); // (xxxx, ([xxx][xxx][xxx], (), [xxx]), x)
23+
A = A.cons(x); // (xx, ([xxx][xxx][xxx][xxx], (), [xxx]), x)
24+
25+
// (x, (), xxxx)
26+
let B = empty(COUNTER).push(x).push(x).push(x).push(x).push(x);
27+
B = B.push(x); // (x, ([xxx]), xx)
28+
B = B.push(x).push(x); // (x, ([xxx]), xxxx)
29+
B = B.push(x); // (x, ([xxx], (), [xxx]), xx)
30+
B = B.push(x).push(x); // (x, ([xxx], (), [xxx]), xxxx)
31+
B = B.push(x); // (x, ([xxx], (), [xxx][xxx]), xx)
32+
B = B.push(x).push(x); // (x, ([xxx], (), [xxx][xxx]), xxxx)
33+
B = B.push(x); // (x, ([xxx], (), [xxx][xxx][xxx]), xx)
34+
B = B.push(x).push(x); // (x, ([xxx], (), [xxx][xxx][xxx]), xxxx)
35+
B = B.push(x); // (x, ([xxx], (), [xxx][xxx][xxx][xxx]), xx)
36+
37+
t.is(
38+
B.middle.right.measure(COUNTER) +
39+
B.right._nodes(COUNTER, A.left).length +
40+
A.middle.left.measure(COUNTER),
41+
10,
42+
);
43+
44+
const C = B.concat(A);
45+
46+
t.deepEqual([...C], [...nrepeat(x, 36)]);
47+
});
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import test from 'ava';
2+
3+
import {Measures} from '@functional-abstraction/measure';
4+
import {nrepeat} from '@iterable-iterator/repeat';
5+
6+
import {empty} from '../../../../../../src/index.js';
7+
8+
const {COUNTER} = Measures;
9+
10+
test('cover', (t) => {
11+
const x = 'x';
12+
13+
// (xxxx, (), x)
14+
let A = empty(COUNTER).cons(x).cons(x).cons(x).cons(x).cons(x);
15+
A = A.cons(x); // (xx, ([xxx]), x)
16+
A = A.cons(x).cons(x); // (xxxx, ([xxx]), x)
17+
A = A.cons(x); // (xx, ([xxx], (), [xxx]), x)
18+
A = A.cons(x).cons(x); // (xxxx, ([xxx], (), [xxx]), x)
19+
A = A.cons(x); // (xx, ([xxx][xxx], (), [xxx]), x)
20+
A = A.cons(x).cons(x); // (xxxx, ([xxx][xxx], (), [xxx]), x)
21+
A = A.cons(x); // (xx, ([xxx][xxx][xxx], (), [xxx]), x)
22+
A = A.cons(x).cons(x); // (xxxx, ([xxx][xxx][xxx], (), [xxx]), x)
23+
A = A.cons(x); // (xx, ([xxx][xxx][xxx][xxx], (), [xxx]), x)
24+
A = A.cons(x).cons(x); // (xxxx, ([xxx][xxx][xxx][xxx], (), [xxx]), x)
25+
26+
// (x, (), xxxx)
27+
let B = empty(COUNTER).push(x).push(x).push(x).push(x).push(x);
28+
B = B.push(x); // (x, ([xxx]), xx)
29+
B = B.push(x).push(x); // (x, ([xxx]), xxxx)
30+
B = B.push(x); // (x, ([xxx], (), [xxx]), xx)
31+
B = B.push(x).push(x); // (x, ([xxx], (), [xxx]), xxxx)
32+
B = B.push(x); // (x, ([xxx], (), [xxx][xxx]), xx)
33+
B = B.push(x).push(x); // (x, ([xxx], (), [xxx][xxx]), xxxx)
34+
B = B.push(x); // (x, ([xxx], (), [xxx][xxx][xxx]), xx)
35+
B = B.push(x).push(x); // (x, ([xxx], (), [xxx][xxx][xxx]), xxxx)
36+
B = B.push(x); // (x, ([xxx], (), [xxx][xxx][xxx][xxx]), xx)
37+
B = B.push(x).push(x); // (x, ([xxx], (), [xxx][xxx][xxx][xxx]), xxxx)
38+
39+
t.is(
40+
B.middle.right.measure(COUNTER) +
41+
B.right._nodes(COUNTER, A.left).length +
42+
A.middle.left.measure(COUNTER),
43+
11,
44+
);
45+
46+
const C = B.concat(A);
47+
48+
t.deepEqual([...C], [...nrepeat(x, 40)]);
49+
});

0 commit comments

Comments
 (0)