Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dankogai committed Jul 24, 2020
1 parent 5e3bac1 commit 528ff77
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
13 changes: 8 additions & 5 deletions combinatorics.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ class _CBase {
toArray() {
return [...this];
}
get isBig() {
return Number.MAX_SAFE_INTEGER < this.length;
}
get isSafe() {
return typeof BigInt !== 'undefined' || !this.isBig;
}
}
/**
* Permutation
Expand All @@ -124,11 +130,7 @@ export class Permutation extends _CBase {
super();
this.seed = [...seed];
this.size = 0 < size && size <= this.seed.length ? size : this.seed.length;
const length = permutation(seed.length, this.size);
if (_BI === Number && Number.MAX_SAFE_INTEGER < length) {
throw RangeError(`${length} exceeds Number.MAX_SAFE_INTEGER`);
};
this.length = length;
this.length = permutation(seed.length, this.size);
Object.freeze(this);
}
nth(n) {
Expand Down Expand Up @@ -180,6 +182,7 @@ export class Combination extends _CBase {
export class BaseN extends _CBase {
constructor(seed, size){
super();
if (!size) size = 1;
this.seed = [...seed];
this.size = size;
let base = this.seed.length;
Expand Down
1 change: 0 additions & 1 deletion test/00-chai.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/03-combination.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('class Combination', () => {
it(`new Combination([0,1...99],50).length === ${sbn}n`, () => {
$$(c.length).to.equal(BigInt(sbn));
});
it(`new Combination([0,1...99],50).nth(${sbn}n-1n)`, () => {
it(`.nth(${sbn}n-1n)`, () => {
$$(c.nth(BigInt(sbn)-BigInt(1))).to.deep.equal([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
Expand Down
2 changes: 1 addition & 1 deletion test/03-permutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('class Permutation', () => {
it(`new Permutation('${seed}').length === ${sbn}n`, () => {
$$(c.length).to.equal(BigInt(sbn));
});
it(`new Permutation('${seed}').nth(${sbn}n-1n)`, () => {
it(`.nth(${sbn}n-1n)`, () => {
$$(c.nth(BigInt(sbn)-BigInt(1))).to.deep.equal([...seed].reverse())
});
} else {
Expand Down
15 changes: 14 additions & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,28 @@
</head>
<body>
<div id="mocha"></div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/platform.min.js"></script>
<script>
isLegacySafari = ((p) => {
const name = p.name;
const ver = Number(p.version.split('.')[0]);
console.log(name, ver, p.description);
return (name === 'Safari' && ver <= 13);
})(platform);
</script>
<script src="https://unpkg.com/[email protected]/chai.js"></script>
<script src="https://unpkg.com/[email protected]/mocha.js"></script>
<script>mocha.setup('bdd')</script>
<script type="module" src="./01-import.js"></script>
<script type="module" src="./02-arithmetics.js"></script>
<script type="module" src="./03-permutation.js"></script>
<script type="module" src="./03-combination.js"></script>
<script type="module" src="./03-basen.js"></script>
<script type="module" src="./03-powerset.js"></script>
<script type="module" src="./03-permcomb.js"></script>
<script type="module">
mocha.checkLeaks();
mocha.run();
</script>
</body>
</html>

0 comments on commit 528ff77

Please sign in to comment.