diff options
author | Minteck <contact@minteck.org> | 2021-12-21 16:52:28 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2021-12-21 16:52:28 +0100 |
commit | 46e43f4bde4a35785b4997b81e86cd19f046b69b (patch) | |
tree | c53c2f826f777f9d6b2d249dab556feb72a6c3a6 /src/node_modules/chance/test/test.regional.js | |
download | langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.gz langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.bz2 langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.zip |
Commit
Diffstat (limited to 'src/node_modules/chance/test/test.regional.js')
-rw-r--r-- | src/node_modules/chance/test/test.regional.js | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/src/node_modules/chance/test/test.regional.js b/src/node_modules/chance/test/test.regional.js new file mode 100644 index 0000000..2fd7aee --- /dev/null +++ b/src/node_modules/chance/test/test.regional.js @@ -0,0 +1,116 @@ +import test from 'ava' +import Chance from '../chance.js' +import _ from 'lodash' + +const chance = new Chance() + +// chance.cf() +test('cf() returns a valid random cf', t => { + _.times(1000, () => { + let cf = chance.cf() + t.true(_.isString(cf)) + t.is(cf.length, 16) + t.true(/[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]/.test(cf)) + }) +}) + +test('cf() returns a consistent cf', t => { + let testCases = [{ + item: { + first: 'Aldo', + last: 'Fabrizi', + gender: 'Male', + birthday: new Date(1905,10,1), + city: 'h501' + }, + cf: 'FBRLDA05S01H501A' + }, { + item: { + first: 'Sophia', + last: 'Loren', + gender: 'Female', + birthday: new Date(1934,8,20), + city: 'h501' + }, + cf: 'LRNSPH34P60H501G' + }, { + item: { + first: 'Claudia', + last: 'Cardinale', + gender: 'Female', + birthday: new Date(1938,3,15), + city: 'z352' + }, + cf: 'CRDCLD38D55Z352Q' + }, { + item: { + first: 'Sergio', + last: 'Leone', + gender: 'Male', + birthday: new Date(1929,0,3), + city: 'h501' + }, + cf: 'LNESRG29A03H501W' + }, { + item: { + first: 'Claudio', + last: 'Marchisio', + gender: 'Male', + birthday: new Date(1986,0,19), + city: 'l219' + }, + cf: 'MRCCLD86A19L219F' + }, { + item: { + first: 'Eu', + last: 'Ho', + gender: 'Male', + birthday: new Date(2012,3,12), + city: 'z210' + }, + cf: 'HOXEUX12D12Z210Q' + }]; + + testCases.map((test) => { + t.is(chance.cf(test.item), test.cf) + }) +}) + +// chance.pl_nip() +test('pl_nip() returns a valid NIP number', t => { + _.times(1000, () => { + let nip = chance.pl_nip() + t.true(_.isString(nip)) + t.is(nip.length, 10) + }) +}) + +// chance.pl_pesel() +test('pl_pesel() returns a valid PESEL number', t => { + _.times(1000, () => { + let pesel = chance.pl_pesel() + t.true(_.isString(pesel)) + t.is(pesel.length, 11) + }) +}) + +// chance.pl_regon() +test('pl_regon() returns a valid REGON number', t => { + _.times(1000, () => { + let regon = chance.pl_regon() + t.true(_.isString(regon)) + t.is(regon.length, 9) + }) +}) + +// chance.vat() +test('vat() returns a valid italian vat number', t => { + _.times(1000, () => { + let vat = chance.vat({ country: 'it' }) + t.true(_.isString(vat)) + t.is(vat.length, 11) + let first = vat.charAt(0) + t.true(first === '0' || first === '1') + t.true(chance.luhn_check(vat)) + }) +}) |