-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use node >= v22.x and use new available functionalities
- Loading branch information
1 parent
13a1293
commit 903fed7
Showing
8 changed files
with
89 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,60 @@ | ||
import Encoder from '../src/encoder.mjs'; | ||
import {ArgumentError} from '../src/errors.mjs'; | ||
import assert from 'assert'; | ||
import Base32 from '../utils/base32.mjs'; | ||
|
||
describe('[Encoder] class tests', function () { | ||
describe('encoder', function () { | ||
describe('encode method', function () { | ||
it('no cards', function () { | ||
assert.equal(Encoder.decode('CEAAAAA').length, 0); | ||
}); | ||
|
||
it('no cards skip version', function () { | ||
assert.equal(Encoder.decode('EUAAAAA', true).length, 0); | ||
}); | ||
|
||
it('check version', function () { | ||
assert.throws(() => Encoder.decode('CZAAAAA', false), ArgumentError); | ||
}); | ||
|
||
it('check format', function () { | ||
assert.throws(() => Encoder.decode('EUAAAAA', false), SyntaxError); | ||
}); | ||
|
||
it('empty value', function () { | ||
assert.throws(() => Encoder.decode('')); | ||
}); | ||
|
||
it('invalid deck', function () { | ||
assert.throws(() => Encoder.encode([null])); | ||
assert.throws(() => Encoder.encode([{count: 0}])); | ||
}); | ||
describe('decode method', function () { | ||
it('no cards', function () { | ||
assert.equal(Encoder.decode('CEAAAAA').length, 0); | ||
}); | ||
|
||
it('no cards skip version', function () { | ||
assert.equal(Encoder.decode('EUAAAAA', true).length, 0); | ||
}); | ||
|
||
it('check version', function () { | ||
assert.throws(() => Encoder.decode('CZAAAAA', false), ArgumentError); | ||
}); | ||
|
||
it('check format', function () { | ||
assert.throws(() => Encoder.decode('EUAAAAA', false), SyntaxError); | ||
}); | ||
|
||
it('empty value', function () { | ||
assert.throws(() => Encoder.decode('')); | ||
}); | ||
}); | ||
|
||
describe('encode method', function () { | ||
it('invalid deck', function () { | ||
assert.throws(() => Encoder.encode([null])); | ||
assert.throws(() => Encoder.encode([{count: 0}])); | ||
}); | ||
}); | ||
|
||
describe('decode algorithm', function () { | ||
|
||
const newGrouping = cards => Object.groupBy(cards, ({count}) => (count > 3 ? 'x' : count)); | ||
const newMapping = (grouped, count) => Map.groupBy(grouped[count] ?? [], ({set, factionId}) => set * 100 + factionId); | ||
|
||
const code = 'CEBAIAIABEQDINIFAEBAUEATEAYAEAIBAIYQGAIAAIDSUAQCAEBCWLIDAEAAMHJN'; | ||
let cards, info; | ||
|
||
beforeEach(function () { | ||
cards = Encoder.decode(code); | ||
info = Base32.decode(code); | ||
}); | ||
|
||
it('must match old groups', function () { | ||
const groups = newGrouping(cards); | ||
|
||
newMapping(groups, 3); | ||
}); | ||
|
||
it('must match lengths', function () { | ||
assert.equal(cards.length, 18); | ||
assert.equal(info.length, 40); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters