Skip to content

Commit c3db442

Browse files
committed
Add test of symbol chars
1 parent 4303232 commit c3db442

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

src/lib/puid.spec.ts

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,43 @@ test('Base32HexUpper chars (32 chars, 5 bits)', (t) => {
255255
t.is(base32HexUpperId(), '2B72')
256256
})
257257

258-
test('puid from Chars.AlphaUpper and Chars.SafeAscii', (t) => {
258+
test('puid from Chars.AlphaUpper', (t) => {
259259
const { generator: alphaUpperId } = puid({ bits: 48, chars: Chars.AlphaUpper })
260-
t.is(alphaUpperId.info.charsName, 'alphaUpper')
261-
t.is(alphaUpperId().length, 11)
262260

261+
const { bits, bitsPerChar, chars, charsName, ere, length } = alphaUpperId.info
262+
t.is(bits, 51.7)
263+
t.is(bitsPerChar, 4.7)
264+
t.is(chars, Chars.AlphaUpper)
265+
t.is(charsName, 'alphaUpper')
266+
t.is(ere, 0.59)
267+
t.is(length, 11)
268+
t.is(alphaUpperId().length, length)
269+
})
270+
271+
test('puid from Chars.SafeAscii', (t) => {
263272
const { generator: safeAsciiId } = puid({ bits: 52, chars: Chars.SafeAscii })
264-
t.is(safeAsciiId.info.charsName, 'safeAscii')
265-
t.is(safeAsciiId().length, 9)
273+
274+
const { bits, bitsPerChar, chars, charsName, ere, length } = safeAsciiId.info
275+
t.is(bits, 58.43)
276+
t.is(bitsPerChar, 6.49)
277+
t.is(chars, Chars.SafeAscii)
278+
t.is(charsName, 'safeAscii')
279+
t.is(ere, 0.81)
280+
t.is(length, 9)
281+
t.is(safeAsciiId().length, length)
282+
})
283+
284+
test('puid from Chars.Symbol', (t) => {
285+
const { generator: symbolId } = puid({ bits: 59, chars: Chars.Symbol })
286+
287+
const { bits, bitsPerChar, chars, charsName, ere, length } = symbolId.info
288+
t.is(bits, 62.5)
289+
t.is(bitsPerChar, 4.81)
290+
t.is(chars, Chars.Symbol)
291+
t.is(charsName, 'symbol')
292+
t.is(ere, 0.6)
293+
t.is(length, 13)
294+
t.is(symbolId().length, length)
266295
})
267296

268297
test('256 characters', (t) => {

0 commit comments

Comments
 (0)