Refactor: Implement SmartCube renderer, improve UI styling, and fix gaps

This commit is contained in:
2026-02-22 04:35:59 +00:00
parent 57abfd6b80
commit b5ddc21662
4168 changed files with 763782 additions and 1008 deletions

58
node_modules/@gkucmierz/utils/spec/SetCnt.spec.mjs generated vendored Normal file
View File

@@ -0,0 +1,58 @@
import {
SetCnt,
} from '../src/SetCnt.mjs';
const set = new Set([1,2,3,5])
const map = new Map([[1,2],[3,5]])
// console.log([...sc.entries()]);
describe('SetCnt', () => {
it('has', () => {
const sc = new SetCnt([1,2,5,6,1,1]);
expect(sc.has(1)).toBe(true);
expect(sc.has(2)).toBe(true);
expect(sc.has(5)).toBe(true);
});
it('add', () => {
const sc = new SetCnt([1,2,5,6,1,1]);
expect(sc.add(123)).toBe(sc);
expect(sc.has(123)).toBe(true);
});
it('delete', () => {
const sc = new SetCnt();
expect(sc.add(123)).toBe(sc);
expect(sc.add(123)).toBe(sc);
expect(sc.delete(123)).toBe(true);
expect(sc.has(123)).toBe(true);
expect(sc.delete(123)).toBe(true);
expect(sc.has(123)).toBe(false);
expect(sc.delete(123)).toBe(false);
});
it('deleteAll', () => {
const sc = new SetCnt();
expect(sc.add(123)).toBe(sc);
expect(sc.add(123)).toBe(sc);
expect(sc.deleteAll(123)).toBe(true);
expect(sc.has(123)).toBe(false);
});
it('cnt', () => {
const sc = new SetCnt();
expect(sc.cnt(123)).toBe(0);
expect(sc.add(123)).toBe(sc);
expect(sc.add(123)).toBe(sc);
expect(sc.cnt(123)).toBe(2);
expect(sc.deleteAll(123)).toBe(true);
expect(sc.cnt(123)).toBe(0);
});
});

69
node_modules/@gkucmierz/utils/spec/Trie.spec.mjs generated vendored Normal file
View File

@@ -0,0 +1,69 @@
import {
Trie,
} from '../src/Trie.mjs';
describe('Trie', () => {
it('check empty', () => {
const trie = Trie();
expect(trie.has('')).toBe(false);
expect(trie.has('abc')).toBe(false);
});
it('init data', () => {
const trie = Trie(['abc', '']);
expect(trie.has('')).toBe(true);
expect(trie.has('abc')).toBe(true);
});
it('add/readd data', () => {
const trie = Trie();
expect(trie.has('')).toBe(false);
expect(trie.add('')).toBe(true);
expect(trie.has('')).toBe(true);
expect(trie.add('')).toBe(false);
});
it('list data', () => {
const trie = Trie(['abc', '', 'abcdef', 'xyz']);
const abc = ['abc', 'abcdef'];
expect(trie.get('a')).toEqual(abc);
expect(trie.get('ab')).toEqual(abc);
expect(trie.get('abc')).toEqual(abc);
expect(trie.get('aa')).toEqual([]);
expect(trie.get('')).toEqual(['', 'abc', 'abcdef', 'xyz']);
});
it('remove node', () => {
const trie = Trie(['a', 'ab', 'abc']);
expect(trie.has('abc')).toEqual(true);
expect(trie.remove('abc')).toEqual(true);
expect(trie.remove('abc')).toEqual(false);
expect(trie.has('abc')).toEqual(false);
expect(trie.has('ab')).toEqual(true);
expect(trie.remove('ab')).toEqual(true);
expect(trie.remove('ab')).toEqual(false);
expect(trie.has('ab')).toEqual(false);
expect(trie.has('a')).toEqual(true);
expect(trie.remove('a')).toEqual(true);
expect(trie.remove('a')).toEqual(false);
expect(trie.has('a')).toEqual(false);
});
it('keep child node after parent removal', () => {
const trie = Trie(['a', 'abc']);
expect(trie.has('a')).toEqual(true);
expect(trie.remove('a')).toEqual(true);
expect(trie.remove('a')).toEqual(false);
expect(trie.has('a')).toEqual(false);
expect(trie.has('abc')).toEqual(true);
expect(trie.remove('abc')).toEqual(true);
expect(trie.remove('abc')).toEqual(false);
expect(trie.has('abc')).toEqual(false);
})
});

29
node_modules/@gkucmierz/utils/spec/base64.spec.mjs generated vendored Normal file
View File

@@ -0,0 +1,29 @@
import {
toBase64,
fromBase64,
toBase64Url,
fromBase64Url,
} from '../src/base64.mjs';
describe('base64', () => {
it('toBase64', () => {
expect(toBase64('🥚')).toBe('Ptha3Q==');
expect(toBase64('🐔')).toBe('PdgU3A==');
expect(toBase64('')).toBe('++8=');
});
it('fromBase64', () => {
expect(fromBase64('Ptha3Q==')).toBe('🥚');
expect(fromBase64('PdgU3A==')).toBe('🐔');
expect(fromBase64('++8=')).toBe('');
});
it('toBase64Url', () => {
expect(toBase64Url('')).toBe('--8=');
});
it('fromBase64', () => {
expect(fromBase64Url('--8=')).toBe('');
});
});

View File

@@ -0,0 +1,123 @@
import {
num2bijective,
bijective2num,
num2bijectiveBI,
bijective2numBI,
} from '../src/bijective-numeration.mjs';
describe('bijective-numeration', () => {
const alpha = 'abcdefghijklmnopqrstuvwxyz';
const map = [
[0, ''],
[1, '1'],
[2, '2'],
[3, '11'],
[4, '12'],
[5, '21'],
[6, '22'],
[7, '111'],
];
const mapAlpha = [
[0, ''],
[1, 'a'],
[26, 'z'],
[26 + 1, 'aa'],
[26 * 26 + 26, 'zz'],
[26 * 26 + 26 + 1, 'aaa'],
];
it('num2bijective', () => {
map.map(([num, bij]) => {
expect(num2bijective(num)).toEqual(bij);
});
});
it('num2bijective alpha', () => {
mapAlpha.map(([num, bij]) => {
expect(num2bijective(num, alpha)).toEqual(bij);
});
});
it('bijective2num', () => {
map.map(([num, bij]) => {
expect(bijective2num(bij)).toEqual(num);
});
});
it('bijective2num alpha', () => {
mapAlpha.map(([num, bij]) => {
expect(bijective2num(bij, alpha)).toEqual(num);
});
});
it('random tests', () => {
for (let i = 0; i < 1e3; ++i) {
const n = Math.round(Math.random() * 1e6);
const bj = num2bijective(n, alpha);
expect(bijective2num(bj, alpha)).toEqual(n);
}
});
});
describe('bijective-numeration BigInt', () => {
const alpha = 'abcdefghijklmnopqrstuvwxyz';
const map = [
[0n, ''],
[1n, '1'],
[2n, '2'],
[3n, '11'],
[4n, '12'],
[5n, '21'],
[6n, '22'],
[7n, '111'],
];
const mapAlpha = [
[0n, ''],
[1n, 'a'],
[26n, 'z'],
[26n + 1n, 'aa'],
[26n * 26n + 26n, 'zz'],
[26n * 26n + 26n + 1n, 'aaa'],
];
it('num2bijectiveBI', () => {
map.map(([num, bij]) => {
expect(num2bijectiveBI(num)).toEqual(bij);
});
});
it('num2bijectiveBI alpha', () => {
mapAlpha.map(([num, bij]) => {
expect(num2bijectiveBI(num, alpha)).toEqual(bij);
});
});
it('bijective2numBI', () => {
map.map(([num, bij]) => {
expect(bijective2numBI(bij)).toEqual(num);
});
});
it('bijective2numBI alpha', () => {
mapAlpha.map(([num, bij]) => {
expect(bijective2numBI(bij, alpha)).toEqual(num);
});
});
it('random tests', () => {
for (let i = 0; i < 1e3; ++i) {
const b = BigInt(Math.round(Math.random() * 1000));
const n = BigInt(Math.round(Math.random() * 100));
const bi = b ** n;
const bj = num2bijectiveBI(bi, alpha);
expect(bijective2numBI(bj, alpha)).toEqual(bi);
}
});
});

View File

@@ -0,0 +1,91 @@
import {
binarySearchArr,
binarySearchLE,
binarySearchGE,
binarySearchRangeIncl,
} from '../src/binary-search.mjs';
describe('binarySearchArr', () => {
it('few cases', () => {
expect(binarySearchArr([1, 2, 3, 4], 1)).toBe(0);
expect(binarySearchArr([1, 2, 3, 4], 2)).toBe(1);
expect(binarySearchArr([1, 2, 3, 4], 3)).toBe(2);
expect(binarySearchArr([1, 2, 3, 4], 4)).toBe(3);
expect(binarySearchArr([1, 2, 3, 4], 0)).toBe(-1);
expect(binarySearchArr([1, 2, 3, 4], 5)).toBe(-1);
});
});
describe('binarySearchLE', () => {
it('mid group', () => {
const arr = [0,1,2,2,3];
expect(binarySearchLE(arr, -100)).toBe(-1);
expect(binarySearchLE(arr, 0)).toBe(0);
expect(binarySearchLE(arr, 1)).toBe(1);
expect(binarySearchLE(arr, 2)).toBe(3);
expect(binarySearchLE(arr, 3)).toBe(4);
expect(binarySearchLE(arr, 100)).toBe(4);
});
it('begin group', () => {
const arr = [2,2,3];
expect(binarySearchLE(arr, -100)).toBe(-1);
expect(binarySearchLE(arr, 2)).toBe(1);
expect(binarySearchLE(arr, 3)).toBe(2);
expect(binarySearchLE(arr, 100)).toBe(2);
});
it('end group', () => {
const arr = [1,2,2];
expect(binarySearchLE(arr, -100)).toBe(-1);
expect(binarySearchLE(arr, 1)).toBe(0);
expect(binarySearchLE(arr, 2)).toBe(2);
expect(binarySearchLE(arr, 100)).toBe(2);
});
});
describe('binarySearchGE', () => {
it('mid group', () => {
const arr = [0,1,2,2,3];
expect(binarySearchGE(arr, -100)).toBe(0);
expect(binarySearchGE(arr, 0)).toBe(0);
expect(binarySearchGE(arr, 1)).toBe(1);
expect(binarySearchGE(arr, 2)).toBe(2);
expect(binarySearchGE(arr, 3)).toBe(4);
expect(binarySearchGE(arr, 100)).toBe(5);
});
it('begin group', () => {
const arr = [2,2,3];
expect(binarySearchGE(arr, -100)).toBe(0);
expect(binarySearchGE(arr, 2)).toBe(0);
expect(binarySearchGE(arr, 3)).toBe(2);
expect(binarySearchGE(arr, 100)).toBe(3);
});
it('end group', () => {
const arr = [1,2,2];
expect(binarySearchGE(arr, -100)).toBe(0);
expect(binarySearchGE(arr, 1)).toBe(0);
expect(binarySearchGE(arr, 2)).toBe(1);
expect(binarySearchGE(arr, 100)).toBe(3);
});
});
describe('binarySearchRangeIncl', () => {
it('basic', () => {
const arr = [0,1,1,3];
const check = [-10, ...arr, 10];
const expected = [
[0, -1],
[0, 0], [1, 2], [1, 2], [3, 3],
[4, 3],
];
for (let i = 0; i < check.length; ++i) {
expect(binarySearchRangeIncl(arr, check[i])).toEqual(expected[i]);
}
});
});

12
node_modules/@gkucmierz/utils/spec/copy-case.spec.mjs generated vendored Normal file
View File

@@ -0,0 +1,12 @@
import {
copyCase,
} from '../src/copy-case.mjs';
describe('copy-case', () => {
it('few tests', () => {
expect(copyCase('styczeń', 'january')).toBe('styczeń');
expect(copyCase('styczeń', 'January')).toBe('Styczeń');
expect(copyCase('styczeń', 'JANUARY')).toBe('STYCZEŃ');
});
});

35
node_modules/@gkucmierz/utils/spec/factors.spec.mjs generated vendored Normal file
View File

@@ -0,0 +1,35 @@
import {
factors,
factorsBI,
} from '../src/factors.mjs';
describe('factors', () => {
it('Number', () => {
expect(factors(0)).toEqual([]);
expect(factors(1)).toEqual([]);
expect(factors(2)).toEqual([2]);
expect(factors(3)).toEqual([3]);
expect(factors(4)).toEqual([2, 2]);
expect(factors(5)).toEqual([5]);
expect(factors(6)).toEqual([2, 3]);
expect(factors(7)).toEqual([7]);
expect(factors(8)).toEqual([2, 2, 2]);
expect(factors(9)).toEqual([3, 3]);
expect(factors(10)).toEqual([2, 5]);
});
it('BigInt', () => {
expect(factorsBI(0n)).toEqual([]);
expect(factorsBI(1n)).toEqual([]);
expect(factorsBI(2n)).toEqual([2n]);
expect(factorsBI(3n)).toEqual([3n]);
expect(factorsBI(4n)).toEqual([2n, 2n]);
expect(factorsBI(5n)).toEqual([5n]);
expect(factorsBI(6n)).toEqual([2n, 3n]);
expect(factorsBI(7n)).toEqual([7n]);
expect(factorsBI(8n)).toEqual([2n, 2n, 2n]);
expect(factorsBI(9n)).toEqual([3n, 3n]);
expect(factorsBI(10n)).toEqual([2n, 5n]);
});
});

27
node_modules/@gkucmierz/utils/spec/gcd.spec.mjs generated vendored Normal file
View File

@@ -0,0 +1,27 @@
import {
gcd,
gcdBI,
} from '../src/gcd.mjs';
describe('gcd', () => {
it('Number', () => {
expect(gcd(42, 56)).toEqual(14);
expect(gcd(461952, 116298)).toEqual(18);
expect(gcd(7966496, 314080416)).toEqual(32);
expect(gcd(24826148, 45296490)).toEqual(526);
expect(gcd(12, 0)).toEqual(12);
expect(gcd(0, 0)).toEqual(0);
expect(gcd(0, 9)).toEqual(9);
});
it('BigInt', () => {
expect(gcdBI(42n, 56n)).toEqual(14n);
expect(gcdBI(461952n, 116298n)).toEqual(18n);
expect(gcdBI(7966496n, 314080416n)).toEqual(32n);
expect(gcdBI(24826148n, 45296490n)).toEqual(526n);
expect(gcdBI(12n, 0n)).toEqual(12n);
expect(gcdBI(0n, 0n)).toEqual(0n);
expect(gcdBI(0n, 9n)).toEqual(9n);
});
});

75
node_modules/@gkucmierz/utils/spec/get-type.spec.mjs generated vendored Normal file
View File

@@ -0,0 +1,75 @@
import { getType } from '../src/get-type.mjs';
describe('get-type', () => {
it('should undefined', () => {
expect(getType(undefined)).toEqual('undefined');
});
it('should null', () => {
expect(getType(null)).toEqual('null');
});
it('should boolean', () => {
expect(getType(true)).toEqual('boolean');
expect(getType(false)).toEqual('boolean');
expect(getType(new Boolean)).toEqual('boolean');
});
it('should number', () => {
expect(getType(1)).toEqual('number');
expect(getType(1e3)).toEqual('number');
expect(getType(1_000)).toEqual('number');
expect(getType(NaN)).toEqual('number');
expect(getType(Infinity)).toEqual('number');
});
it('should bigint', () => {
expect(getType(1n)).toEqual('bigint');
});
it('should string', () => {
expect(getType('hello')).toEqual('string');
expect(getType(new String)).toEqual('string');
});
it('should Symbol', () => {
expect(getType(Symbol())).toEqual('symbol');
});
it('should function', () => {
expect(getType(() => 0)).toEqual('function');
expect(getType(function() { })).toEqual('function');
expect(getType(new Function)).toEqual('function');
});
it('should generatorfunction', () => {
expect(getType(function*() { })).toEqual('generatorfunction');
});
it('should date', () => {
expect(getType(new Date)).toEqual('date');
});
it('should array', () => {
expect(getType([])).toEqual('array');
expect(getType(new Array)).toEqual('array');
});
it('should object', () => {
expect(getType({})).toEqual('object');
expect(getType(new Object)).toEqual('object');
expect(getType(new Proxy({}, {}))).toEqual('object');
});
it('should map', () => {
expect(getType(new Map)).toEqual('map');
expect(getType(new WeakMap)).toEqual('weakmap');
});
it('should set', () => {
expect(getType(new Set)).toEqual('set');
expect(getType(new WeakSet)).toEqual('weakset');
});
});

35
node_modules/@gkucmierz/utils/spec/gpn.spec.mjs generated vendored Normal file
View File

@@ -0,0 +1,35 @@
import {
gpn,
gpnBI,
} from '../src/gpn.mjs';
describe('gpn', () => {
it('first terms', () => {
expect(gpn(0)).toBe(0);
expect(gpn(1)).toBe(1);
expect(gpn(2)).toBe(2);
expect(gpn(3)).toBe(5);
expect(gpn(4)).toBe(7);
expect(gpn(5)).toBe(12);
expect(gpn(6)).toBe(15);
expect(gpn(7)).toBe(22);
expect(gpn(8)).toBe(26);
expect(gpn(9)).toBe(35);
});
});
describe('gpn BI', () => {
it('first terms', () => {
expect(gpnBI(0n)).toBe(0n);
expect(gpnBI(1n)).toBe(1n);
expect(gpnBI(2n)).toBe(2n);
expect(gpnBI(3n)).toBe(5n);
expect(gpnBI(4n)).toBe(7n);
expect(gpnBI(5n)).toBe(12n);
expect(gpnBI(6n)).toBe(15n);
expect(gpnBI(7n)).toBe(22n);
expect(gpnBI(8n)).toBe(26n);
expect(gpnBI(9n)).toBe(35n);
});
});

32
node_modules/@gkucmierz/utils/spec/heap.spec.mjs generated vendored Normal file
View File

@@ -0,0 +1,32 @@
import { Heap } from '../src/heap.mjs';
describe('Heap', () => {
it('size', () => {
const heap = Heap();
expect(heap.size()).toBe(0);
heap.add(1);
expect(heap.size()).toBe(1);
heap.add(1);
heap.add(1);
expect(heap.size()).toBe(3);
});
it('take', () => {
const heap = Heap();
heap.add(2);
heap.add(1);
heap.add(3);
expect(heap.take()).toBe(1);
expect(heap.take()).toBe(2);
expect(heap.take()).toBe(3);
});
it('valFn', () => {
const heap = Heap(obj => obj.value);
heap.add({ value: 42, other: 'second' });
heap.add({ value: 23, other: 'first' });
expect(heap.take().other).toBe('first');
expect(heap.take().other).toBe('second');
});
});

View File

@@ -0,0 +1,41 @@
import {
heronsFormula,
heronsFormulaBI,
} from '../src/herons-formula.mjs';
describe('herons-formula', () => {
it('Integer', () => {
expect(heronsFormula(5, 12, 13)).toEqual(30);
expect(heronsFormula(6, 8, 10)).toEqual(24);
expect(heronsFormula(7, 15, 20)).toEqual(42);
expect(heronsFormula(17, 17, 30)).toEqual(120);
expect(heronsFormula(13, 37, 30)).toEqual(180);
expect(heronsFormula(6, 25, 29)).toEqual(60);
expect(heronsFormula(73, 9, 80)).toEqual(216);
expect(heronsFormula(12, 35, 37)).toEqual(210);
expect(heronsFormula(120, 109, 13)).toEqual(396);
expect(heronsFormula(9, 10, 17)).toEqual(36);
});
it('Float', () => {
expect(heronsFormula(2, 3, 4)).toEqual(2.9047375096555625);
expect(heronsFormula(7, 10, 12)).toEqual(34.977671449083054);
expect(heronsFormula(6, 11, 12)).toEqual(32.839572165300815);
expect(heronsFormula(25, 25, 45)).toEqual(245.1880655741629);
expect(heronsFormula(10, 11, 18)).toEqual(48.59976851796724);
});
it('BigInt', () => {
expect(heronsFormulaBI(5n, 12n, 13n)).toEqual(30n);
expect(heronsFormulaBI(6n, 8n, 10n)).toEqual(24n);
expect(heronsFormulaBI(7n, 15n, 20n)).toEqual(42n);
expect(heronsFormulaBI(17n, 17n, 30n)).toEqual(120n);
expect(heronsFormulaBI(13n, 37n, 30n)).toEqual(180n);
expect(heronsFormulaBI(6n, 25n, 29n)).toEqual(60n);
expect(heronsFormulaBI(73n, 9n, 80n)).toEqual(216n);
expect(heronsFormulaBI(12n, 35n, 37n)).toEqual(210n);
expect(heronsFormulaBI(120n, 109n, 13n)).toEqual(396n);
expect(heronsFormulaBI(9n, 10n, 17n)).toEqual(36n);
});
});

33
node_modules/@gkucmierz/utils/spec/list-node.spec.mjs generated vendored Normal file
View File

@@ -0,0 +1,33 @@
import { ListNode } from '../src/list-node.mjs';
describe('ListNode', () => {
it('constructor', () => {
expect(new ListNode().val).toEqual(0);
expect(new ListNode().next).toEqual(null);
expect(new ListNode(123).val).toEqual(123);
expect(new ListNode(123).next).toEqual(null);
expect(new ListNode(123, 'next').next).toEqual('next');
});
it('toArr', () => {
expect(new ListNode().toArr()).toEqual([0]);
expect(new ListNode(123).toArr()).toEqual([123]);
expect(new ListNode(1, new ListNode(2)).toArr()).toEqual([1, 2]);
});
it('fromArr', () => {
expect(ListNode.fromArr([1, 2])).toEqual(new ListNode(1, new ListNode(2)));
});
it('both', () => {
const arr = [1, 2, 3, 4, 5];
expect(ListNode.fromArr(arr).toArr()).toEqual(arr);
});
it('cyclic reference', () => {
const node = ListNode.fromArr([1, 2]);
node.next.next = node;
expect(() => node.toArr()).toThrow(new Error('Cyclic reference detected'));
});
});

8
node_modules/@gkucmierz/utils/spec/main.spec.mjs generated vendored Normal file
View File

@@ -0,0 +1,8 @@
import * as all from '../main.mjs';
describe('main', () => {
it('default', () => {
expect(all.default).toBeDefined();
});
});

19
node_modules/@gkucmierz/utils/spec/matrix.spec.mjs generated vendored Normal file
View File

@@ -0,0 +1,19 @@
import {
matrixAsArray,
} from '../src/matrix.mjs';
describe('matrix', () => {
it('matrixAsArray', () => {
const m = [
[1, 2],
[3, 4],
];
const arr = matrixAsArray(m);
expect(arr.length).toBe(4);
expect(arr[0]).toBe(1);
expect(arr[1]).toBe(2);
expect(arr[2]).toBe(3);
expect(arr[3]).toBe(4);
});
});

46
node_modules/@gkucmierz/utils/spec/memoize.spec.mjs generated vendored Normal file
View File

@@ -0,0 +1,46 @@
import {
memoize,
} from '../src/memoize.mjs';
describe('memoize', () => {
it('called once', () => {
let cnt = 0;
const add = memoize((a, b) => {
++cnt;
return a + b;
});
expect(add(1, 2)).toBe(3);
expect(cnt).toBe(1);
expect(add(1, 2)).toBe(3);
expect(cnt).toBe(1);
expect(add(2, 1)).toBe(3);
expect(cnt).toBe(2);
});
it('variable args length', () => {
const fn = memoize((...args) => args.length);
expect(fn()).toBe(0);
expect(fn(1)).toBe(1);
expect(fn(1, 2)).toBe(2);
expect(fn(1, 2, 3)).toBe(3);
});
it('different empty object arrays', () => {
let cnt = 0;
const fn = memoize(() => ++cnt);
const emptyArr = [];
fn(emptyArr);
expect(cnt).toBe(1);
fn(emptyArr);
expect(cnt).toBe(1);
fn([]);
expect(cnt).toBe(2);
fn([]);
expect(cnt).toBe(3);
});
});

39
node_modules/@gkucmierz/utils/spec/mod.spec.mjs generated vendored Normal file
View File

@@ -0,0 +1,39 @@
import {
mod,
modBI,
} from '../src/mod.mjs';
describe('mod', () => {
it('mod', () => {
expect(mod(4, 100)).toEqual(4);
expect(mod(104, 100)).toEqual(4);
expect(mod(4 - 100, 100)).toEqual(4);
expect(mod(4 + 96, 100)).toEqual(0);
expect(mod(-4 - 96, 100)).toEqual(0);
});
it('mod sign', () => {
expect(mod(4, 100)).toEqual(4);
expect(mod(-4, 100)).toEqual(96);
expect(mod(4, -100)).toEqual(-96);
expect(mod(-4, -100)).toEqual(-4);
});
});
describe('mod BI', () => {
it('mod', () => {
expect(modBI(4n, 100n)).toEqual(4n);
expect(modBI(104n, 100n)).toEqual(4n);
expect(modBI(4n - 100n, 100n)).toEqual(4n);
expect(modBI(4n + 96n, 100n)).toEqual(0n);
expect(modBI(-4n - 96n, 100n)).toEqual(0n);
});
it('mod sign', () => {
expect(modBI(4n, 100n)).toEqual(4n);
expect(modBI(-4n, 100n)).toEqual(96n);
expect(modBI(4n, -100n)).toEqual(-96n);
expect(modBI(-4n, -100n)).toEqual(-4n);
});
});

60
node_modules/@gkucmierz/utils/spec/phi.spec.mjs generated vendored Normal file
View File

@@ -0,0 +1,60 @@
import {
phi,
phiBI,
} from '../src/phi.mjs';
describe('phi', () => {
it('Number x1', () => {
expect(phi(1)).toBe(1);
expect(phi(11)).toBe(10);
expect(phi(21)).toBe(12);
expect(phi(31)).toBe(30);
expect(phi(41)).toBe(40);
expect(phi(51)).toBe(32);
expect(phi(61)).toBe(60);
expect(phi(71)).toBe(70);
expect(phi(81)).toBe(54);
expect(phi(91)).toBe(72);
});
it('Number x5', () => {
expect(phi(5)).toBe(4);
expect(phi(15)).toBe(8);
expect(phi(25)).toBe(20);
expect(phi(35)).toBe(24);
expect(phi(45)).toBe(24);
expect(phi(55)).toBe(40);
expect(phi(65)).toBe(48);
expect(phi(75)).toBe(40);
expect(phi(85)).toBe(64);
expect(phi(95)).toBe(72);
});
it('BigInt x1', () => {
expect(phiBI(1n)).toBe(1n);
expect(phiBI(11n)).toBe(10n);
expect(phiBI(21n)).toBe(12n);
expect(phiBI(31n)).toBe(30n);
expect(phiBI(41n)).toBe(40n);
expect(phiBI(51n)).toBe(32n);
expect(phiBI(61n)).toBe(60n);
expect(phiBI(71n)).toBe(70n);
expect(phiBI(81n)).toBe(54n);
expect(phiBI(91n)).toBe(72n);
});
it('BigInt x5', () => {
expect(phiBI(5n)).toBe(4n);
expect(phiBI(15n)).toBe(8n);
expect(phiBI(25n)).toBe(20n);
expect(phiBI(35n)).toBe(24n);
expect(phiBI(45n)).toBe(24n);
expect(phiBI(55n)).toBe(40n);
expect(phiBI(65n)).toBe(48n);
expect(phiBI(75n)).toBe(40n);
expect(phiBI(85n)).toBe(64n);
expect(phiBI(95n)).toBe(72n);
});
});

21
node_modules/@gkucmierz/utils/spec/pow-mod.spec.mjs generated vendored Normal file
View File

@@ -0,0 +1,21 @@
import {
powMod,
powModBI,
} from '../src/pow-mod.mjs';
describe('pow-mod', () => {
it('powMod', () => {
expect(powMod(2, 1)).toEqual(2);
expect(powMod(2, 1, 10)).toEqual(2);
expect(powMod(2, 1, 2)).toEqual(0);
expect(powMod(2, 0, 2)).toEqual(1);
});
it('powModBI', () => {
expect(powModBI(2n, 1n)).toEqual(2n);
expect(powModBI(2n, 1n, 10n)).toEqual(2n);
expect(powModBI(2n, 1n, 2n)).toEqual(0n);
expect(powModBI(2n, 0n, 2n)).toEqual(1n);
});
});

View File

@@ -0,0 +1,19 @@
import {
range2array,
array2range,
} from '../src/range-array.mjs';
describe('range-array', () => {
it('array2range', () => {
expect(array2range([])).toEqual([]);
expect(array2range([1,3,4,5,7,9,10])).toEqual([[1,1],[3,5],[7,7],[9,10]]);
expect(array2range([10,12,13,14,15,16,17,20,22,23,27])).toEqual([[10,10],[12,17],[20,20],[22,23],[27,27]]);
});
it('range2array', () => {
expect(range2array([])).toEqual([]);
expect(range2array([[1],[3,5],[7],[9,10]])).toEqual([1,3,4,5,7,9,10]);
expect(range2array([[10],[12,17],[20],[22,23],[27]])).toEqual([10,12,13,14,15,16,17,20,22,23,27]);
});
});

View File

@@ -0,0 +1,22 @@
import {
squareRoot,
squareRootBI,
} from '../src/square-root.mjs';
describe('square-root', () => {
it('squareRootBI small', () => {
expect(squareRootBI(0n)).toEqual(0n);
expect(squareRootBI(1n)).toEqual(1n);
expect(squareRootBI(2n)).toEqual(1n);
expect(squareRootBI(3n)).toEqual(1n);
expect(squareRootBI(4n)).toEqual(2n);
});
it('squareRootBI 0-1e3', () => {
for (let i = 0; i < 1e3; ++i) {
const sqf = BigInt(Math.floor(i ** 0.5));
expect(squareRootBI(BigInt(i))).toEqual(sqf);
}
});
});

View File

@@ -0,0 +1,16 @@
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.?(m)js"
],
"helpers": [
"helpers/**/*.?(m)js"
],
"env": {
"stopSpecOnExpectationFailure": false,
"random": true
},
"client": {
"captureConsole": false
}
}

View File

@@ -0,0 +1,15 @@
import {
tonelliShanksBI,
} from '../src/tonelli-shanks.mjs';
describe('tonelli-shanks', () => {
it('tonelliShanksBI', () => {
const a = 8479994658316772151941616510097127087554541274812435112009425778595495359700244470400642403747058566807127814165396640215844192327900454116257979487432016769329970767046735091249898678088061634796559556704959846424131820416048436501387617211770124292793308079214153179977624440438616958575058361193975686620046439877308339989295604537867493683872778843921771307305602776398786978353866231661453376056771972069776398999013769588936194859344941268223184197231368887060609212875507518936172060702209557124430477137421847130682601666968691651447236917018634902407704797328509461854842432015009878011354022108661461024768n;
const p = 30531851861994333252675935111487950694414332763909083514133769861350960895076504687261369815735742549428789138300843082086550059082835141454526618160634109969195486322015775943030060449557090064811940139431735209185996454739163555910726493597222646855506445602953689527405362207926990442391705014604777038685880527537489845359101552442292804398472642356609304810680731556542002301547846635101455995732584071355903010856718680732337369128498655255277003643669031694516851390505923416710601212618443109844041514942401969629158975457079026906304328749039997262960301209158175920051890620947063936347307238412281568760161n;
const r = tonelliShanksBI(a, p);
expect((r * r) % p).toEqual(a);
});
});