-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
83 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Tests in this folder are not necessary for individual implementations to implement | ||
since they test the algorithm, and not the implementations themselves |
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { expect, test } from 'vitest'; | ||
import Sqids, { defaultOptions } from '../../src/index.ts'; | ||
|
||
// @NOTE: "uniques, with blocked words" is auto-tested since a lot of these big ids | ||
// will match some words on the blocklist and will be re-generated anyway | ||
|
||
const upTo = 100_000_000; | ||
|
||
test('uniques', () => { | ||
const sqids = new Sqids(); | ||
|
||
const idSet = new Set<string>(); | ||
const numbersSet = new Set<string>(); | ||
|
||
for (let i = 0; i != upTo; i++) { | ||
const numbers = [i]; | ||
|
||
const id = sqids.encode(numbers); | ||
|
||
const decodedNumbers = sqids.decode(id); | ||
expect.soft(decodedNumbers).toEqual(numbers); | ||
|
||
idSet.add(id); | ||
numbersSet.add(decodedNumbers.join(',')); | ||
} | ||
|
||
expect.soft(idSet.size).toBe(upTo); | ||
expect.soft(numbersSet.size).toBe(upTo); | ||
}); | ||
|
||
test('uniques, with padding', () => { | ||
const sqids = new Sqids({ | ||
minLength: defaultOptions.alphabet.length | ||
}); | ||
|
||
const idSet = new Set<string>(); | ||
const numbersSet = new Set<string>(); | ||
|
||
for (let i = 0; i != upTo; i++) { | ||
const numbers = [i]; | ||
|
||
const id = sqids.encode(numbers); | ||
|
||
const decodedNumbers = sqids.decode(id); | ||
expect.soft(decodedNumbers).toEqual(numbers); | ||
|
||
idSet.add(id); | ||
numbersSet.add(decodedNumbers.join(',')); | ||
} | ||
|
||
expect.soft(idSet.size).toBe(upTo); | ||
expect.soft(numbersSet.size).toBe(upTo); | ||
}); | ||
|
||
test('uniques, with multiple numbers', () => { | ||
const sqids = new Sqids(); | ||
|
||
const idSet = new Set<string>(); | ||
const numbersSet = new Set<string>(); | ||
|
||
for (let i = 0; i != upTo; i++) { | ||
const numbers = [0, i, i + 1, 100, 999999999]; | ||
|
||
const id = sqids.encode(numbers); | ||
|
||
const decodedNumbers = sqids.decode(id); | ||
expect.soft(decodedNumbers).toEqual(numbers); | ||
|
||
idSet.add(id); | ||
numbersSet.add(decodedNumbers.join(',')); | ||
} | ||
|
||
expect.soft(idSet.size).toBe(upTo); | ||
expect.soft(numbersSet.size).toBe(upTo); | ||
}); |
This file was deleted.
Oops, something went wrong.