@gkucmierz/utils 1.28.3 → 1.28.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -4
- package/package.json +31 -2
- package/src/SetCnt.mjs +52 -6
- package/src/Trie.mjs +35 -2
- package/src/base64.mjs +24 -0
- package/src/bijective-numeration.mjs +24 -0
- package/src/binary-search.mjs +25 -5
- package/src/copy-case.mjs +5 -5
- package/src/egcd.mjs +8 -0
- package/src/factors.mjs +6 -8
- package/src/gcd.mjs +8 -8
- package/src/get-type.mjs +6 -2
- package/src/gpn.mjs +14 -0
- package/src/heap.mjs +26 -0
- package/src/herons-formula.mjs +17 -0
- package/src/lcm.mjs +13 -0
- package/src/list-node.mjs +19 -0
- package/src/matrix.mjs +6 -3
- package/src/memoize.mjs +5 -5
- package/src/mod.mjs +8 -14
- package/src/phi.mjs +13 -0
- package/src/pow-mod.mjs +12 -12
- package/src/range-array.mjs +12 -0
- package/src/square-root.mjs +6 -8
- package/src/tonelli-shanks.mjs +7 -2
- package/.github/workflows/deploy-docs.yml +0 -22
- package/.github/workflows/npm-publish.yml +0 -25
- package/.husky/pre-commit +0 -4
- package/jsdoc.json +0 -10
- package/package-lock.json +0 -1422
- package/scripts/generate_main.mjs +0 -43
- package/spec/SetCnt.spec.mjs +0 -58
- package/spec/Trie.spec.mjs +0 -69
- package/spec/base64.spec.mjs +0 -29
- package/spec/bijective-numeration.spec.mjs +0 -123
- package/spec/binary-search.spec.mjs +0 -91
- package/spec/copy-case.spec.mjs +0 -12
- package/spec/factors.spec.mjs +0 -35
- package/spec/gcd.spec.mjs +0 -27
- package/spec/get-type.spec.mjs +0 -75
- package/spec/gpn.spec.mjs +0 -35
- package/spec/heap.spec.mjs +0 -32
- package/spec/herons-formula.spec.mjs +0 -41
- package/spec/list-node.spec.mjs +0 -33
- package/spec/main.spec.mjs +0 -8
- package/spec/matrix.spec.mjs +0 -19
- package/spec/memoize.spec.mjs +0 -46
- package/spec/mod.spec.mjs +0 -39
- package/spec/phi.spec.mjs +0 -60
- package/spec/pow-mod.spec.mjs +0 -21
- package/spec/range-array.spec.mjs +0 -19
- package/spec/square-root.spec.mjs +0 -22
- package/spec/support/jasmine.json +0 -16
- package/spec/tonelli-shanks.spec.mjs +0 -15
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { fileURLToPath } from 'url';
|
|
5
|
-
|
|
6
|
-
const MAIN_FILE = './main.mjs';
|
|
7
|
-
|
|
8
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
-
const __dirname = path.dirname([path.dirname(__filename), '/../src/.'].join(''));
|
|
10
|
-
|
|
11
|
-
const files = fs.readdirSync(__dirname);
|
|
12
|
-
|
|
13
|
-
const utilsFiles = files
|
|
14
|
-
.filter(name => name.match(/\.mjs$/))
|
|
15
|
-
.filter(name => name !== 'main.mjs');
|
|
16
|
-
|
|
17
|
-
const allMethods = {};
|
|
18
|
-
const map = new Map();
|
|
19
|
-
|
|
20
|
-
for (const file of utilsFiles) {
|
|
21
|
-
const f = [__dirname, file].join('/');
|
|
22
|
-
const obj = await import(f);
|
|
23
|
-
map.set(file, Object.keys(obj));
|
|
24
|
-
Object.keys(obj).map(key => {
|
|
25
|
-
if (key in allMethods) throw Error('Duplicate method name');
|
|
26
|
-
allMethods[key] = obj[key];
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
fs.writeFileSync(MAIN_FILE, [
|
|
31
|
-
'',
|
|
32
|
-
...[...map].map(([file, methods]) => {
|
|
33
|
-
return `import {\n ${methods.join(', ')}\n} from './src/${file}'`;
|
|
34
|
-
}),
|
|
35
|
-
'',
|
|
36
|
-
...utilsFiles.map(file => `export * from './src/${file}';`),
|
|
37
|
-
'',
|
|
38
|
-
`export default [`,
|
|
39
|
-
` ${Object.keys(allMethods).join(', ')}`,
|
|
40
|
-
`];`,
|
|
41
|
-
'',
|
|
42
|
-
].join('\n'));
|
|
43
|
-
|
package/spec/SetCnt.spec.mjs
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
SetCnt,
|
|
4
|
-
} from '../src/SetCnt.mjs';
|
|
5
|
-
|
|
6
|
-
const set = new Set([1,2,3,5])
|
|
7
|
-
const map = new Map([[1,2],[3,5]])
|
|
8
|
-
// console.log([...sc.entries()]);
|
|
9
|
-
|
|
10
|
-
describe('SetCnt', () => {
|
|
11
|
-
it('has', () => {
|
|
12
|
-
const sc = new SetCnt([1,2,5,6,1,1]);
|
|
13
|
-
expect(sc.has(1)).toBe(true);
|
|
14
|
-
expect(sc.has(2)).toBe(true);
|
|
15
|
-
expect(sc.has(5)).toBe(true);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('add', () => {
|
|
19
|
-
const sc = new SetCnt([1,2,5,6,1,1]);
|
|
20
|
-
expect(sc.add(123)).toBe(sc);
|
|
21
|
-
expect(sc.has(123)).toBe(true);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('delete', () => {
|
|
25
|
-
const sc = new SetCnt();
|
|
26
|
-
expect(sc.add(123)).toBe(sc);
|
|
27
|
-
expect(sc.add(123)).toBe(sc);
|
|
28
|
-
|
|
29
|
-
expect(sc.delete(123)).toBe(true);
|
|
30
|
-
expect(sc.has(123)).toBe(true);
|
|
31
|
-
|
|
32
|
-
expect(sc.delete(123)).toBe(true);
|
|
33
|
-
expect(sc.has(123)).toBe(false);
|
|
34
|
-
|
|
35
|
-
expect(sc.delete(123)).toBe(false);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('deleteAll', () => {
|
|
39
|
-
const sc = new SetCnt();
|
|
40
|
-
expect(sc.add(123)).toBe(sc);
|
|
41
|
-
expect(sc.add(123)).toBe(sc);
|
|
42
|
-
|
|
43
|
-
expect(sc.deleteAll(123)).toBe(true);
|
|
44
|
-
expect(sc.has(123)).toBe(false);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('cnt', () => {
|
|
48
|
-
const sc = new SetCnt();
|
|
49
|
-
expect(sc.cnt(123)).toBe(0);
|
|
50
|
-
|
|
51
|
-
expect(sc.add(123)).toBe(sc);
|
|
52
|
-
expect(sc.add(123)).toBe(sc);
|
|
53
|
-
|
|
54
|
-
expect(sc.cnt(123)).toBe(2);
|
|
55
|
-
expect(sc.deleteAll(123)).toBe(true);
|
|
56
|
-
expect(sc.cnt(123)).toBe(0);
|
|
57
|
-
});
|
|
58
|
-
});
|
package/spec/Trie.spec.mjs
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
Trie,
|
|
4
|
-
} from '../src/Trie.mjs';
|
|
5
|
-
|
|
6
|
-
describe('Trie', () => {
|
|
7
|
-
it('check empty', () => {
|
|
8
|
-
const trie = Trie();
|
|
9
|
-
expect(trie.has('')).toBe(false);
|
|
10
|
-
expect(trie.has('abc')).toBe(false);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('init data', () => {
|
|
14
|
-
const trie = Trie(['abc', '']);
|
|
15
|
-
expect(trie.has('')).toBe(true);
|
|
16
|
-
expect(trie.has('abc')).toBe(true);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('add/readd data', () => {
|
|
20
|
-
const trie = Trie();
|
|
21
|
-
expect(trie.has('')).toBe(false);
|
|
22
|
-
expect(trie.add('')).toBe(true);
|
|
23
|
-
expect(trie.has('')).toBe(true);
|
|
24
|
-
expect(trie.add('')).toBe(false);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('list data', () => {
|
|
28
|
-
const trie = Trie(['abc', '', 'abcdef', 'xyz']);
|
|
29
|
-
const abc = ['abc', 'abcdef'];
|
|
30
|
-
expect(trie.get('a')).toEqual(abc);
|
|
31
|
-
expect(trie.get('ab')).toEqual(abc);
|
|
32
|
-
expect(trie.get('abc')).toEqual(abc);
|
|
33
|
-
expect(trie.get('aa')).toEqual([]);
|
|
34
|
-
expect(trie.get('')).toEqual(['', 'abc', 'abcdef', 'xyz']);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('remove node', () => {
|
|
38
|
-
const trie = Trie(['a', 'ab', 'abc']);
|
|
39
|
-
|
|
40
|
-
expect(trie.has('abc')).toEqual(true);
|
|
41
|
-
expect(trie.remove('abc')).toEqual(true);
|
|
42
|
-
expect(trie.remove('abc')).toEqual(false);
|
|
43
|
-
expect(trie.has('abc')).toEqual(false);
|
|
44
|
-
|
|
45
|
-
expect(trie.has('ab')).toEqual(true);
|
|
46
|
-
expect(trie.remove('ab')).toEqual(true);
|
|
47
|
-
expect(trie.remove('ab')).toEqual(false);
|
|
48
|
-
expect(trie.has('ab')).toEqual(false);
|
|
49
|
-
|
|
50
|
-
expect(trie.has('a')).toEqual(true);
|
|
51
|
-
expect(trie.remove('a')).toEqual(true);
|
|
52
|
-
expect(trie.remove('a')).toEqual(false);
|
|
53
|
-
expect(trie.has('a')).toEqual(false);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('keep child node after parent removal', () => {
|
|
57
|
-
const trie = Trie(['a', 'abc']);
|
|
58
|
-
|
|
59
|
-
expect(trie.has('a')).toEqual(true);
|
|
60
|
-
expect(trie.remove('a')).toEqual(true);
|
|
61
|
-
expect(trie.remove('a')).toEqual(false);
|
|
62
|
-
expect(trie.has('a')).toEqual(false);
|
|
63
|
-
|
|
64
|
-
expect(trie.has('abc')).toEqual(true);
|
|
65
|
-
expect(trie.remove('abc')).toEqual(true);
|
|
66
|
-
expect(trie.remove('abc')).toEqual(false);
|
|
67
|
-
expect(trie.has('abc')).toEqual(false);
|
|
68
|
-
})
|
|
69
|
-
});
|
package/spec/base64.spec.mjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
toBase64,
|
|
4
|
-
fromBase64,
|
|
5
|
-
toBase64Url,
|
|
6
|
-
fromBase64Url,
|
|
7
|
-
} from '../src/base64.mjs';
|
|
8
|
-
|
|
9
|
-
describe('base64', () => {
|
|
10
|
-
it('toBase64', () => {
|
|
11
|
-
expect(toBase64('🥚')).toBe('Ptha3Q==');
|
|
12
|
-
expect(toBase64('🐔')).toBe('PdgU3A==');
|
|
13
|
-
expect(toBase64('')).toBe('++8=');
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('fromBase64', () => {
|
|
17
|
-
expect(fromBase64('Ptha3Q==')).toBe('🥚');
|
|
18
|
-
expect(fromBase64('PdgU3A==')).toBe('🐔');
|
|
19
|
-
expect(fromBase64('++8=')).toBe('');
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('toBase64Url', () => {
|
|
23
|
-
expect(toBase64Url('')).toBe('--8=');
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('fromBase64', () => {
|
|
27
|
-
expect(fromBase64Url('--8=')).toBe('');
|
|
28
|
-
});
|
|
29
|
-
});
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
num2bijective,
|
|
4
|
-
bijective2num,
|
|
5
|
-
num2bijectiveBI,
|
|
6
|
-
bijective2numBI,
|
|
7
|
-
} from '../src/bijective-numeration.mjs';
|
|
8
|
-
|
|
9
|
-
describe('bijective-numeration', () => {
|
|
10
|
-
const alpha = 'abcdefghijklmnopqrstuvwxyz';
|
|
11
|
-
|
|
12
|
-
const map = [
|
|
13
|
-
[0, ''],
|
|
14
|
-
[1, '1'],
|
|
15
|
-
[2, '2'],
|
|
16
|
-
[3, '11'],
|
|
17
|
-
[4, '12'],
|
|
18
|
-
[5, '21'],
|
|
19
|
-
[6, '22'],
|
|
20
|
-
[7, '111'],
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
const mapAlpha = [
|
|
24
|
-
[0, ''],
|
|
25
|
-
[1, 'a'],
|
|
26
|
-
[26, 'z'],
|
|
27
|
-
[26 + 1, 'aa'],
|
|
28
|
-
[26 * 26 + 26, 'zz'],
|
|
29
|
-
[26 * 26 + 26 + 1, 'aaa'],
|
|
30
|
-
];
|
|
31
|
-
|
|
32
|
-
it('num2bijective', () => {
|
|
33
|
-
map.map(([num, bij]) => {
|
|
34
|
-
expect(num2bijective(num)).toEqual(bij);
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('num2bijective alpha', () => {
|
|
39
|
-
mapAlpha.map(([num, bij]) => {
|
|
40
|
-
expect(num2bijective(num, alpha)).toEqual(bij);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('bijective2num', () => {
|
|
45
|
-
map.map(([num, bij]) => {
|
|
46
|
-
expect(bijective2num(bij)).toEqual(num);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('bijective2num alpha', () => {
|
|
51
|
-
mapAlpha.map(([num, bij]) => {
|
|
52
|
-
expect(bijective2num(bij, alpha)).toEqual(num);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('random tests', () => {
|
|
57
|
-
for (let i = 0; i < 1e3; ++i) {
|
|
58
|
-
const n = Math.round(Math.random() * 1e6);
|
|
59
|
-
const bj = num2bijective(n, alpha);
|
|
60
|
-
expect(bijective2num(bj, alpha)).toEqual(n);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
describe('bijective-numeration BigInt', () => {
|
|
66
|
-
const alpha = 'abcdefghijklmnopqrstuvwxyz';
|
|
67
|
-
|
|
68
|
-
const map = [
|
|
69
|
-
[0n, ''],
|
|
70
|
-
[1n, '1'],
|
|
71
|
-
[2n, '2'],
|
|
72
|
-
[3n, '11'],
|
|
73
|
-
[4n, '12'],
|
|
74
|
-
[5n, '21'],
|
|
75
|
-
[6n, '22'],
|
|
76
|
-
[7n, '111'],
|
|
77
|
-
];
|
|
78
|
-
|
|
79
|
-
const mapAlpha = [
|
|
80
|
-
[0n, ''],
|
|
81
|
-
[1n, 'a'],
|
|
82
|
-
[26n, 'z'],
|
|
83
|
-
[26n + 1n, 'aa'],
|
|
84
|
-
[26n * 26n + 26n, 'zz'],
|
|
85
|
-
[26n * 26n + 26n + 1n, 'aaa'],
|
|
86
|
-
];
|
|
87
|
-
|
|
88
|
-
it('num2bijectiveBI', () => {
|
|
89
|
-
map.map(([num, bij]) => {
|
|
90
|
-
expect(num2bijectiveBI(num)).toEqual(bij);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('num2bijectiveBI alpha', () => {
|
|
95
|
-
mapAlpha.map(([num, bij]) => {
|
|
96
|
-
expect(num2bijectiveBI(num, alpha)).toEqual(bij);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('bijective2numBI', () => {
|
|
101
|
-
map.map(([num, bij]) => {
|
|
102
|
-
expect(bijective2numBI(bij)).toEqual(num);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('bijective2numBI alpha', () => {
|
|
107
|
-
mapAlpha.map(([num, bij]) => {
|
|
108
|
-
expect(bijective2numBI(bij, alpha)).toEqual(num);
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('random tests', () => {
|
|
113
|
-
for (let i = 0; i < 1e3; ++i) {
|
|
114
|
-
const b = BigInt(Math.round(Math.random() * 1000));
|
|
115
|
-
const n = BigInt(Math.round(Math.random() * 100));
|
|
116
|
-
const bi = b ** n;
|
|
117
|
-
|
|
118
|
-
const bj = num2bijectiveBI(bi, alpha);
|
|
119
|
-
expect(bijective2numBI(bj, alpha)).toEqual(bi);
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
});
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
binarySearchArr,
|
|
4
|
-
binarySearchLE,
|
|
5
|
-
binarySearchGE,
|
|
6
|
-
binarySearchRangeIncl,
|
|
7
|
-
} from '../src/binary-search.mjs';
|
|
8
|
-
|
|
9
|
-
describe('binarySearchArr', () => {
|
|
10
|
-
it('few cases', () => {
|
|
11
|
-
expect(binarySearchArr([1, 2, 3, 4], 1)).toBe(0);
|
|
12
|
-
expect(binarySearchArr([1, 2, 3, 4], 2)).toBe(1);
|
|
13
|
-
expect(binarySearchArr([1, 2, 3, 4], 3)).toBe(2);
|
|
14
|
-
expect(binarySearchArr([1, 2, 3, 4], 4)).toBe(3);
|
|
15
|
-
expect(binarySearchArr([1, 2, 3, 4], 0)).toBe(-1);
|
|
16
|
-
expect(binarySearchArr([1, 2, 3, 4], 5)).toBe(-1);
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
describe('binarySearchLE', () => {
|
|
21
|
-
it('mid group', () => {
|
|
22
|
-
const arr = [0,1,2,2,3];
|
|
23
|
-
expect(binarySearchLE(arr, -100)).toBe(-1);
|
|
24
|
-
expect(binarySearchLE(arr, 0)).toBe(0);
|
|
25
|
-
expect(binarySearchLE(arr, 1)).toBe(1);
|
|
26
|
-
expect(binarySearchLE(arr, 2)).toBe(3);
|
|
27
|
-
expect(binarySearchLE(arr, 3)).toBe(4);
|
|
28
|
-
expect(binarySearchLE(arr, 100)).toBe(4);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('begin group', () => {
|
|
32
|
-
const arr = [2,2,3];
|
|
33
|
-
expect(binarySearchLE(arr, -100)).toBe(-1);
|
|
34
|
-
expect(binarySearchLE(arr, 2)).toBe(1);
|
|
35
|
-
expect(binarySearchLE(arr, 3)).toBe(2);
|
|
36
|
-
expect(binarySearchLE(arr, 100)).toBe(2);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('end group', () => {
|
|
40
|
-
const arr = [1,2,2];
|
|
41
|
-
expect(binarySearchLE(arr, -100)).toBe(-1);
|
|
42
|
-
expect(binarySearchLE(arr, 1)).toBe(0);
|
|
43
|
-
expect(binarySearchLE(arr, 2)).toBe(2);
|
|
44
|
-
expect(binarySearchLE(arr, 100)).toBe(2);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
describe('binarySearchGE', () => {
|
|
49
|
-
it('mid group', () => {
|
|
50
|
-
const arr = [0,1,2,2,3];
|
|
51
|
-
expect(binarySearchGE(arr, -100)).toBe(0);
|
|
52
|
-
expect(binarySearchGE(arr, 0)).toBe(0);
|
|
53
|
-
expect(binarySearchGE(arr, 1)).toBe(1);
|
|
54
|
-
expect(binarySearchGE(arr, 2)).toBe(2);
|
|
55
|
-
expect(binarySearchGE(arr, 3)).toBe(4);
|
|
56
|
-
expect(binarySearchGE(arr, 100)).toBe(5);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('begin group', () => {
|
|
60
|
-
const arr = [2,2,3];
|
|
61
|
-
expect(binarySearchGE(arr, -100)).toBe(0);
|
|
62
|
-
expect(binarySearchGE(arr, 2)).toBe(0);
|
|
63
|
-
expect(binarySearchGE(arr, 3)).toBe(2);
|
|
64
|
-
expect(binarySearchGE(arr, 100)).toBe(3);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('end group', () => {
|
|
68
|
-
const arr = [1,2,2];
|
|
69
|
-
expect(binarySearchGE(arr, -100)).toBe(0);
|
|
70
|
-
expect(binarySearchGE(arr, 1)).toBe(0);
|
|
71
|
-
expect(binarySearchGE(arr, 2)).toBe(1);
|
|
72
|
-
expect(binarySearchGE(arr, 100)).toBe(3);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
describe('binarySearchRangeIncl', () => {
|
|
77
|
-
it('basic', () => {
|
|
78
|
-
const arr = [0,1,1,3];
|
|
79
|
-
const check = [-10, ...arr, 10];
|
|
80
|
-
const expected = [
|
|
81
|
-
[0, -1],
|
|
82
|
-
[0, 0], [1, 2], [1, 2], [3, 3],
|
|
83
|
-
[4, 3],
|
|
84
|
-
];
|
|
85
|
-
|
|
86
|
-
for (let i = 0; i < check.length; ++i) {
|
|
87
|
-
expect(binarySearchRangeIncl(arr, check[i])).toEqual(expected[i]);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
package/spec/copy-case.spec.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
copyCase,
|
|
4
|
-
} from '../src/copy-case.mjs';
|
|
5
|
-
|
|
6
|
-
describe('copy-case', () => {
|
|
7
|
-
it('few tests', () => {
|
|
8
|
-
expect(copyCase('styczeń', 'january')).toBe('styczeń');
|
|
9
|
-
expect(copyCase('styczeń', 'January')).toBe('Styczeń');
|
|
10
|
-
expect(copyCase('styczeń', 'JANUARY')).toBe('STYCZEŃ');
|
|
11
|
-
});
|
|
12
|
-
});
|
package/spec/factors.spec.mjs
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
factors,
|
|
4
|
-
factorsBI,
|
|
5
|
-
} from '../src/factors.mjs';
|
|
6
|
-
|
|
7
|
-
describe('factors', () => {
|
|
8
|
-
it('Number', () => {
|
|
9
|
-
expect(factors(0)).toEqual([]);
|
|
10
|
-
expect(factors(1)).toEqual([]);
|
|
11
|
-
expect(factors(2)).toEqual([2]);
|
|
12
|
-
expect(factors(3)).toEqual([3]);
|
|
13
|
-
expect(factors(4)).toEqual([2, 2]);
|
|
14
|
-
expect(factors(5)).toEqual([5]);
|
|
15
|
-
expect(factors(6)).toEqual([2, 3]);
|
|
16
|
-
expect(factors(7)).toEqual([7]);
|
|
17
|
-
expect(factors(8)).toEqual([2, 2, 2]);
|
|
18
|
-
expect(factors(9)).toEqual([3, 3]);
|
|
19
|
-
expect(factors(10)).toEqual([2, 5]);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('BigInt', () => {
|
|
23
|
-
expect(factorsBI(0n)).toEqual([]);
|
|
24
|
-
expect(factorsBI(1n)).toEqual([]);
|
|
25
|
-
expect(factorsBI(2n)).toEqual([2n]);
|
|
26
|
-
expect(factorsBI(3n)).toEqual([3n]);
|
|
27
|
-
expect(factorsBI(4n)).toEqual([2n, 2n]);
|
|
28
|
-
expect(factorsBI(5n)).toEqual([5n]);
|
|
29
|
-
expect(factorsBI(6n)).toEqual([2n, 3n]);
|
|
30
|
-
expect(factorsBI(7n)).toEqual([7n]);
|
|
31
|
-
expect(factorsBI(8n)).toEqual([2n, 2n, 2n]);
|
|
32
|
-
expect(factorsBI(9n)).toEqual([3n, 3n]);
|
|
33
|
-
expect(factorsBI(10n)).toEqual([2n, 5n]);
|
|
34
|
-
});
|
|
35
|
-
});
|
package/spec/gcd.spec.mjs
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
gcd,
|
|
4
|
-
gcdBI,
|
|
5
|
-
} from '../src/gcd.mjs';
|
|
6
|
-
|
|
7
|
-
describe('gcd', () => {
|
|
8
|
-
it('Number', () => {
|
|
9
|
-
expect(gcd(42, 56)).toEqual(14);
|
|
10
|
-
expect(gcd(461952, 116298)).toEqual(18);
|
|
11
|
-
expect(gcd(7966496, 314080416)).toEqual(32);
|
|
12
|
-
expect(gcd(24826148, 45296490)).toEqual(526);
|
|
13
|
-
expect(gcd(12, 0)).toEqual(12);
|
|
14
|
-
expect(gcd(0, 0)).toEqual(0);
|
|
15
|
-
expect(gcd(0, 9)).toEqual(9);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('BigInt', () => {
|
|
19
|
-
expect(gcdBI(42n, 56n)).toEqual(14n);
|
|
20
|
-
expect(gcdBI(461952n, 116298n)).toEqual(18n);
|
|
21
|
-
expect(gcdBI(7966496n, 314080416n)).toEqual(32n);
|
|
22
|
-
expect(gcdBI(24826148n, 45296490n)).toEqual(526n);
|
|
23
|
-
expect(gcdBI(12n, 0n)).toEqual(12n);
|
|
24
|
-
expect(gcdBI(0n, 0n)).toEqual(0n);
|
|
25
|
-
expect(gcdBI(0n, 9n)).toEqual(9n);
|
|
26
|
-
});
|
|
27
|
-
});
|
package/spec/get-type.spec.mjs
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { getType } from '../src/get-type.mjs';
|
|
3
|
-
|
|
4
|
-
describe('get-type', () => {
|
|
5
|
-
|
|
6
|
-
it('should undefined', () => {
|
|
7
|
-
expect(getType(undefined)).toEqual('undefined');
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('should null', () => {
|
|
11
|
-
expect(getType(null)).toEqual('null');
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('should boolean', () => {
|
|
15
|
-
expect(getType(true)).toEqual('boolean');
|
|
16
|
-
expect(getType(false)).toEqual('boolean');
|
|
17
|
-
expect(getType(new Boolean)).toEqual('boolean');
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should number', () => {
|
|
21
|
-
expect(getType(1)).toEqual('number');
|
|
22
|
-
expect(getType(1e3)).toEqual('number');
|
|
23
|
-
expect(getType(1_000)).toEqual('number');
|
|
24
|
-
expect(getType(NaN)).toEqual('number');
|
|
25
|
-
expect(getType(Infinity)).toEqual('number');
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should bigint', () => {
|
|
29
|
-
expect(getType(1n)).toEqual('bigint');
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('should string', () => {
|
|
33
|
-
expect(getType('hello')).toEqual('string');
|
|
34
|
-
expect(getType(new String)).toEqual('string');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should Symbol', () => {
|
|
38
|
-
expect(getType(Symbol())).toEqual('symbol');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('should function', () => {
|
|
42
|
-
expect(getType(() => 0)).toEqual('function');
|
|
43
|
-
expect(getType(function() { })).toEqual('function');
|
|
44
|
-
expect(getType(new Function)).toEqual('function');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('should generatorfunction', () => {
|
|
48
|
-
expect(getType(function*() { })).toEqual('generatorfunction');
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('should date', () => {
|
|
52
|
-
expect(getType(new Date)).toEqual('date');
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('should array', () => {
|
|
56
|
-
expect(getType([])).toEqual('array');
|
|
57
|
-
expect(getType(new Array)).toEqual('array');
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('should object', () => {
|
|
61
|
-
expect(getType({})).toEqual('object');
|
|
62
|
-
expect(getType(new Object)).toEqual('object');
|
|
63
|
-
expect(getType(new Proxy({}, {}))).toEqual('object');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('should map', () => {
|
|
67
|
-
expect(getType(new Map)).toEqual('map');
|
|
68
|
-
expect(getType(new WeakMap)).toEqual('weakmap');
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('should set', () => {
|
|
72
|
-
expect(getType(new Set)).toEqual('set');
|
|
73
|
-
expect(getType(new WeakSet)).toEqual('weakset');
|
|
74
|
-
});
|
|
75
|
-
});
|
package/spec/gpn.spec.mjs
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
gpn,
|
|
4
|
-
gpnBI,
|
|
5
|
-
} from '../src/gpn.mjs';
|
|
6
|
-
|
|
7
|
-
describe('gpn', () => {
|
|
8
|
-
it('first terms', () => {
|
|
9
|
-
expect(gpn(0)).toBe(0);
|
|
10
|
-
expect(gpn(1)).toBe(1);
|
|
11
|
-
expect(gpn(2)).toBe(2);
|
|
12
|
-
expect(gpn(3)).toBe(5);
|
|
13
|
-
expect(gpn(4)).toBe(7);
|
|
14
|
-
expect(gpn(5)).toBe(12);
|
|
15
|
-
expect(gpn(6)).toBe(15);
|
|
16
|
-
expect(gpn(7)).toBe(22);
|
|
17
|
-
expect(gpn(8)).toBe(26);
|
|
18
|
-
expect(gpn(9)).toBe(35);
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
describe('gpn BI', () => {
|
|
23
|
-
it('first terms', () => {
|
|
24
|
-
expect(gpnBI(0n)).toBe(0n);
|
|
25
|
-
expect(gpnBI(1n)).toBe(1n);
|
|
26
|
-
expect(gpnBI(2n)).toBe(2n);
|
|
27
|
-
expect(gpnBI(3n)).toBe(5n);
|
|
28
|
-
expect(gpnBI(4n)).toBe(7n);
|
|
29
|
-
expect(gpnBI(5n)).toBe(12n);
|
|
30
|
-
expect(gpnBI(6n)).toBe(15n);
|
|
31
|
-
expect(gpnBI(7n)).toBe(22n);
|
|
32
|
-
expect(gpnBI(8n)).toBe(26n);
|
|
33
|
-
expect(gpnBI(9n)).toBe(35n);
|
|
34
|
-
});
|
|
35
|
-
});
|
package/spec/heap.spec.mjs
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { Heap } from '../src/heap.mjs';
|
|
3
|
-
|
|
4
|
-
describe('Heap', () => {
|
|
5
|
-
it('size', () => {
|
|
6
|
-
const heap = Heap();
|
|
7
|
-
expect(heap.size()).toBe(0);
|
|
8
|
-
heap.add(1);
|
|
9
|
-
expect(heap.size()).toBe(1);
|
|
10
|
-
heap.add(1);
|
|
11
|
-
heap.add(1);
|
|
12
|
-
expect(heap.size()).toBe(3);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('take', () => {
|
|
16
|
-
const heap = Heap();
|
|
17
|
-
heap.add(2);
|
|
18
|
-
heap.add(1);
|
|
19
|
-
heap.add(3);
|
|
20
|
-
expect(heap.take()).toBe(1);
|
|
21
|
-
expect(heap.take()).toBe(2);
|
|
22
|
-
expect(heap.take()).toBe(3);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('valFn', () => {
|
|
26
|
-
const heap = Heap(obj => obj.value);
|
|
27
|
-
heap.add({ value: 42, other: 'second' });
|
|
28
|
-
heap.add({ value: 23, other: 'first' });
|
|
29
|
-
expect(heap.take().other).toBe('first');
|
|
30
|
-
expect(heap.take().other).toBe('second');
|
|
31
|
-
});
|
|
32
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
heronsFormula,
|
|
4
|
-
heronsFormulaBI,
|
|
5
|
-
} from '../src/herons-formula.mjs';
|
|
6
|
-
|
|
7
|
-
describe('herons-formula', () => {
|
|
8
|
-
it('Integer', () => {
|
|
9
|
-
expect(heronsFormula(5, 12, 13)).toEqual(30);
|
|
10
|
-
expect(heronsFormula(6, 8, 10)).toEqual(24);
|
|
11
|
-
expect(heronsFormula(7, 15, 20)).toEqual(42);
|
|
12
|
-
expect(heronsFormula(17, 17, 30)).toEqual(120);
|
|
13
|
-
expect(heronsFormula(13, 37, 30)).toEqual(180);
|
|
14
|
-
expect(heronsFormula(6, 25, 29)).toEqual(60);
|
|
15
|
-
expect(heronsFormula(73, 9, 80)).toEqual(216);
|
|
16
|
-
expect(heronsFormula(12, 35, 37)).toEqual(210);
|
|
17
|
-
expect(heronsFormula(120, 109, 13)).toEqual(396);
|
|
18
|
-
expect(heronsFormula(9, 10, 17)).toEqual(36);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('Float', () => {
|
|
22
|
-
expect(heronsFormula(2, 3, 4)).toEqual(2.9047375096555625);
|
|
23
|
-
expect(heronsFormula(7, 10, 12)).toEqual(34.977671449083054);
|
|
24
|
-
expect(heronsFormula(6, 11, 12)).toEqual(32.839572165300815);
|
|
25
|
-
expect(heronsFormula(25, 25, 45)).toEqual(245.1880655741629);
|
|
26
|
-
expect(heronsFormula(10, 11, 18)).toEqual(48.59976851796724);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('BigInt', () => {
|
|
30
|
-
expect(heronsFormulaBI(5n, 12n, 13n)).toEqual(30n);
|
|
31
|
-
expect(heronsFormulaBI(6n, 8n, 10n)).toEqual(24n);
|
|
32
|
-
expect(heronsFormulaBI(7n, 15n, 20n)).toEqual(42n);
|
|
33
|
-
expect(heronsFormulaBI(17n, 17n, 30n)).toEqual(120n);
|
|
34
|
-
expect(heronsFormulaBI(13n, 37n, 30n)).toEqual(180n);
|
|
35
|
-
expect(heronsFormulaBI(6n, 25n, 29n)).toEqual(60n);
|
|
36
|
-
expect(heronsFormulaBI(73n, 9n, 80n)).toEqual(216n);
|
|
37
|
-
expect(heronsFormulaBI(12n, 35n, 37n)).toEqual(210n);
|
|
38
|
-
expect(heronsFormulaBI(120n, 109n, 13n)).toEqual(396n);
|
|
39
|
-
expect(heronsFormulaBI(9n, 10n, 17n)).toEqual(36n);
|
|
40
|
-
});
|
|
41
|
-
});
|