|
1 | 1 | import test from 'ava'; |
2 | 2 | import cryptoRandomString from '.'; |
3 | 3 |
|
4 | | -// Probailistic, result is always less than or equal to actual set size, chance it is less is below 1e-256 for sizes up to 32656 |
| 4 | +// Probabilistic, result is always less than or equal to actual set size, chance it is less is below 1e-256 for sizes up to 32656 |
5 | 5 | const generatedCharacterSetSize = (options, targetSize) => { |
6 | 6 | const set = new Set(); |
7 | 7 | const length = targetSize * 640; |
@@ -46,6 +46,14 @@ test('url-safe', t => { |
46 | 46 | t.is(generatedCharacterSetSize({type: 'url-safe'}, 66), 66); |
47 | 47 | }); |
48 | 48 |
|
| 49 | +test('numeric', t => { |
| 50 | + t.is(cryptoRandomString({length: 0, type: 'numeric'}).length, 0); |
| 51 | + t.is(cryptoRandomString({length: 10, type: 'numeric'}).length, 10); |
| 52 | + t.is(cryptoRandomString({length: 100, type: 'numeric'}).length, 100); |
| 53 | + t.regex(cryptoRandomString({length: 100, type: 'numeric'}), /^[\d]*$/); // Sanity check, probabilistic |
| 54 | + t.is(generatedCharacterSetSize({type: 'numeric'}, 10), 10); |
| 55 | +}); |
| 56 | + |
49 | 57 | test('characters', t => { |
50 | 58 | t.is(cryptoRandomString({length: 0, characters: '1234'}).length, 0); |
51 | 59 | t.is(cryptoRandomString({length: 10, characters: '1234'}).length, 10); |
|
0 commit comments