Skip to content

Commit 7494e05

Browse files
🧪 test: Sketch debug API to avoid private props direct access.
1 parent 74dde89 commit 7494e05

File tree

14 files changed

+223
-52
lines changed

14 files changed

+223
-52
lines changed

src/5-api.js

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,93 @@
1-
import {Empty} from './3-tree/index.js';
1+
import assert from 'assert';
2+
import {Split} from './0-core/split/Split.js';
3+
import {One} from './1-digit/1-One.js';
4+
import {Two} from './1-digit/2-Two.js';
5+
import {Three} from './1-digit/3-Three.js';
6+
import {Four} from './1-digit/4-Four.js';
7+
import {Tree} from './3-tree/base/Tree.js';
8+
import {Empty} from './3-tree/implementations/0-Empty.js';
9+
import {Deep} from './3-tree/implementations/2-Deep.js';
210

311
export const empty = (M) => new Empty(M);
412
export {from} from './0-core/index.js';
13+
14+
export const leftTree = (treeSplit) => {
15+
assert(treeSplit instanceof Split);
16+
return treeSplit.left;
17+
};
18+
19+
export const rightTree = (treeSplit) => {
20+
assert(treeSplit instanceof Split);
21+
return treeSplit.right;
22+
};
23+
24+
export const middleElement = (treeSplit) => {
25+
assert(treeSplit instanceof Split);
26+
return treeSplit.middle;
27+
};
28+
29+
export const leftDigit = (tree) => {
30+
assert(tree instanceof Deep);
31+
return tree.left;
32+
};
33+
34+
export const rightDigit = (tree) => {
35+
assert(tree instanceof Deep);
36+
return tree.right;
37+
};
38+
39+
export const middleTree = (tree) => {
40+
assert(tree instanceof Deep);
41+
return tree.middle;
42+
};
43+
44+
export const embeddedMeasure = (tree) => {
45+
assert(tree instanceof Tree);
46+
return tree.force().M;
47+
};
48+
49+
export const nodes = (M, left, right) => {
50+
assert(
51+
left instanceof One ||
52+
left instanceof Two ||
53+
left instanceof Three ||
54+
left instanceof Four,
55+
);
56+
assert(
57+
right instanceof One ||
58+
right instanceof Two ||
59+
right instanceof Three ||
60+
right instanceof Four,
61+
);
62+
return left._nodes(M, right);
63+
};
64+
65+
export const nodesWithList = (M, left, list, right) => {
66+
assert(
67+
left instanceof One ||
68+
left instanceof Two ||
69+
left instanceof Three ||
70+
left instanceof Four,
71+
);
72+
assert(Number.isInteger(list.length) && list.length >= 1 && list.length <= 4);
73+
assert(
74+
right instanceof One ||
75+
right instanceof Two ||
76+
right instanceof Three ||
77+
right instanceof Four,
78+
);
79+
return left._nodes_with_list(M, list, right);
80+
};
81+
82+
export const digitSize = (digit) => {
83+
assert(
84+
digit instanceof One ||
85+
digit instanceof Two ||
86+
digit instanceof Three ||
87+
digit instanceof Four,
88+
);
89+
if (digit instanceof One) return 1;
90+
if (digit instanceof Two) return 2;
91+
if (digit instanceof Three) return 3;
92+
return 4;
93+
};

test/src/FingerTree.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ import {reversed} from '@iterable-iterator/reversed';
1010

1111
import {gt} from '@functional-abstraction/predicate';
1212

13-
import {empty, from} from '../../src/index.js';
13+
import {
14+
empty,
15+
from,
16+
leftTree,
17+
middleElement,
18+
rightTree,
19+
} from '../../src/index.js';
1420

1521
const {COUNTER} = Measures;
1622

@@ -171,7 +177,7 @@ test('FingerTree', (t) => {
171177
const split = F.splitTree(gt(4), COUNTER.zero());
172178

173179
t.deepEqual(
174-
[list(split.left), split.middle, list(split.right)],
180+
[list(leftTree(split)), middleElement(split), list(rightTree(split))],
175181
[list('abcd'), 'e', list('fgh')],
176182
'splitTree',
177183
);

test/src/github-issue-121.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import {Measures} from '@functional-abstraction/measure';
44

55
import {gt} from '@functional-abstraction/predicate';
66

7-
import {from} from '../../src/index.js';
7+
import {from, leftTree} from '../../src/index.js';
88

99
const {COUNTER} = Measures;
1010

1111
test('Cover Lazy#split', (t) => {
1212
const T = from(COUNTER, 'abcde');
1313
const split = T.splitTree(gt(2), COUNTER.zero());
14-
t.is([...split.left.takeUntil(gt(1))].join(''), 'a');
14+
t.is([...leftTree(split).takeUntil(gt(1))].join(''), 'a');
1515
});

test/src/github-issue-73.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {Measures} from '@functional-abstraction/measure';
44

55
import {list} from '@iterable-iterator/list';
66

7-
import {from} from '../../src/index.js';
7+
import {from, leftTree, rightTree} from '../../src/index.js';
88

99
const {COUNTER} = Measures;
1010

@@ -14,7 +14,7 @@ function set(tree, index, value) {
1414

1515
const split = tree.splitTree((m) => m > index, tree.M.zero());
1616

17-
return split.left.push(value).concat(split.right);
17+
return leftTree(split).push(value).concat(rightTree(split));
1818
}
1919

2020
test('github issue #73', (t) => {

test/src/regression/core/concatenate/nodes/03.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ import test from 'ava';
33
import {Measures} from '@functional-abstraction/measure';
44
import {nrepeat} from '@iterable-iterator/repeat';
55

6-
import {empty} from '../../../../../../src/index.js';
6+
import {
7+
empty,
8+
leftDigit,
9+
middleTree,
10+
rightDigit,
11+
nodes,
12+
digitSize,
13+
} from '../../../../../../src/index.js';
714

815
const {COUNTER} = Measures;
916

@@ -23,9 +30,9 @@ test('cover', (t) => {
2330
B = B.push(x); // (x, ([xxx], (), [xxx]), xx)
2431

2532
t.is(
26-
A.middle.right.measure(COUNTER) +
27-
A.right._nodes(COUNTER, B.left).length +
28-
B.middle.left.measure(COUNTER),
33+
digitSize(rightDigit(middleTree(A))) +
34+
nodes(COUNTER, rightDigit(A), leftDigit(B)).length +
35+
digitSize(leftDigit(middleTree(B))),
2936
3,
3037
);
3138

test/src/regression/core/concatenate/nodes/04.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ import test from 'ava';
33
import {Measures} from '@functional-abstraction/measure';
44
import {nrepeat} from '@iterable-iterator/repeat';
55

6-
import {empty} from '../../../../../../src/index.js';
6+
import {
7+
empty,
8+
leftDigit,
9+
middleTree,
10+
rightDigit,
11+
nodes,
12+
digitSize,
13+
} from '../../../../../../src/index.js';
714

815
const {COUNTER} = Measures;
916

@@ -23,9 +30,9 @@ test('cover', (t) => {
2330
B = B.push(x); // (x, ([xxx], (), [xxx]), xx)
2431

2532
t.is(
26-
B.middle.right.measure(COUNTER) +
27-
B.right._nodes(COUNTER, A.left).length +
28-
A.middle.left.measure(COUNTER),
33+
digitSize(rightDigit(middleTree(B))) +
34+
nodes(COUNTER, rightDigit(B), leftDigit(A)).length +
35+
digitSize(leftDigit(middleTree(A))),
2936
4,
3037
);
3138

test/src/regression/core/concatenate/nodes/05.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ import test from 'ava';
33
import {Measures} from '@functional-abstraction/measure';
44
import {nrepeat} from '@iterable-iterator/repeat';
55

6-
import {empty} from '../../../../../../src/index.js';
6+
import {
7+
empty,
8+
leftDigit,
9+
middleTree,
10+
rightDigit,
11+
nodes,
12+
digitSize,
13+
} from '../../../../../../src/index.js';
714

815
const {COUNTER} = Measures;
916

@@ -25,9 +32,9 @@ test('cover', (t) => {
2532
B = B.push(x); // (x, ([xxx], (), [xxx]), xxx)
2633

2734
t.is(
28-
B.middle.right.measure(COUNTER) +
29-
B.right._nodes(COUNTER, A.left).length +
30-
A.middle.left.measure(COUNTER),
35+
digitSize(rightDigit(middleTree(B))) +
36+
nodes(COUNTER, rightDigit(B), leftDigit(A)).length +
37+
digitSize(leftDigit(middleTree(A))),
3138
5,
3239
);
3340

test/src/regression/core/concatenate/nodes/06.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ import test from 'ava';
33
import {Measures} from '@functional-abstraction/measure';
44
import {nrepeat} from '@iterable-iterator/repeat';
55

6-
import {empty} from '../../../../../../src/index.js';
6+
import {
7+
empty,
8+
leftDigit,
9+
middleTree,
10+
rightDigit,
11+
nodes,
12+
digitSize,
13+
} from '../../../../../../src/index.js';
714

815
const {COUNTER} = Measures;
916

@@ -28,9 +35,9 @@ test('cover', (t) => {
2835
B = B.push(x).push(x); // (x, ([xxx], (), [xxx][xxx]), xxxx)
2936

3037
t.is(
31-
B.middle.right.measure(COUNTER) +
32-
B.right._nodes(COUNTER, A.left).length +
33-
A.middle.left.measure(COUNTER),
38+
digitSize(rightDigit(middleTree(B))) +
39+
nodes(COUNTER, rightDigit(B), leftDigit(A)).length +
40+
digitSize(leftDigit(middleTree(A))),
3441
6,
3542
);
3643

test/src/regression/core/concatenate/nodes/07.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ import test from 'ava';
33
import {Measures} from '@functional-abstraction/measure';
44
import {nrepeat} from '@iterable-iterator/repeat';
55

6-
import {empty} from '../../../../../../src/index.js';
6+
import {
7+
empty,
8+
leftDigit,
9+
middleTree,
10+
rightDigit,
11+
nodes,
12+
digitSize,
13+
} from '../../../../../../src/index.js';
714

815
const {COUNTER} = Measures;
916

@@ -29,9 +36,9 @@ test('cover', (t) => {
2936
B = B.push(x).push(x); // (x, ([xxx], (), [xxx][xxx]), xxxx)
3037

3138
t.is(
32-
B.middle.right.measure(COUNTER) +
33-
B.right._nodes(COUNTER, A.left).length +
34-
A.middle.left.measure(COUNTER),
39+
digitSize(rightDigit(middleTree(B))) +
40+
nodes(COUNTER, rightDigit(B), leftDigit(A)).length +
41+
digitSize(leftDigit(middleTree(A))),
3542
7,
3643
);
3744

test/src/regression/core/concatenate/nodes/08.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ import test from 'ava';
33
import {Measures} from '@functional-abstraction/measure';
44
import {nrepeat} from '@iterable-iterator/repeat';
55

6-
import {empty} from '../../../../../../src/index.js';
6+
import {
7+
empty,
8+
leftDigit,
9+
middleTree,
10+
rightDigit,
11+
nodes,
12+
digitSize,
13+
} from '../../../../../../src/index.js';
714

815
const {COUNTER} = Measures;
916

@@ -31,9 +38,9 @@ test('cover', (t) => {
3138
B = B.push(x); // (x, ([xxx], (), [xxx][xxx][xxx]), xx)
3239

3340
t.is(
34-
B.middle.right.measure(COUNTER) +
35-
B.right._nodes(COUNTER, A.left).length +
36-
A.middle.left.measure(COUNTER),
41+
digitSize(rightDigit(middleTree(B))) +
42+
nodes(COUNTER, rightDigit(B), leftDigit(A)).length +
43+
digitSize(leftDigit(middleTree(A))),
3744
8,
3845
);
3946

0 commit comments

Comments
 (0)