-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
be86d6a
commit fde6992
Showing
5 changed files
with
61 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
import randomEnumDifferentValue from "./randomEnumDifferentValue" | ||
|
||
/** | ||
* Gets multiple random enum values from all available enums. | ||
* @param anEnum Enum type | ||
* @param count Number of random values to return | ||
* @returns Random enum values | ||
*/ | ||
export default function randomEnumMultiDifferentValue<T extends Record<string, unknown>>(anEnum: T, count: number): T[keyof T][] { | ||
return [] | ||
const result : T[keyof T][] = [] | ||
for (let i = 0; i < count; i++) { | ||
result.push(randomEnumDifferentValue(anEnum, ...result)) | ||
} | ||
return result | ||
} |
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
38 changes: 38 additions & 0 deletions
38
tests/unit/util/random/randomEnumMultiDifferentValue.spec.ts
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,38 @@ | ||
import { expect } from 'chai' | ||
import randomEnumMultiDifferentValue from '@/util/random/randomEnumMultiDifferentValue' | ||
|
||
describe('util/random/randomEnumMultiDifferentValue', () => { | ||
it('int enum', () => { | ||
const values = randomEnumMultiDifferentValue(IntEnum, 2) | ||
|
||
expect(values.length).to.eq(2) | ||
values.forEach((value,index) => { | ||
expect([1,2,3,4].includes(value)).to.true | ||
expect(values.toSpliced(index, 1).includes(value)).to.false | ||
}) | ||
}) | ||
|
||
it('string enum', () => { | ||
const values = randomEnumMultiDifferentValue(StringEnum, 3) | ||
|
||
expect(values.length).to.eq(3) | ||
values.forEach((value,index) => { | ||
expect(['one','two','three','four'].includes(value)).to.true | ||
expect(values.toSpliced(index, 1).includes(value)).to.false | ||
}) | ||
}) | ||
}) | ||
|
||
enum IntEnum { | ||
ONE = 1, | ||
TWO = 2, | ||
THREE = 3, | ||
FOUR = 4 | ||
} | ||
|
||
enum StringEnum { | ||
ONE = 'one', | ||
TWO = 'two', | ||
THREE = 'three', | ||
FOUR = 'four' | ||
} |
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
14 changes: 14 additions & 0 deletions
14
tests/unit/util/random/rollDiceMultiDifferentValue.spec.ts
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,14 @@ | ||
import { expect } from 'chai' | ||
import rollDiceMultiDifferentValue from '@/util/random/rollDiceMultiDifferentValue' | ||
|
||
describe('util/random/rollDiceMultiDifferentValue', () => { | ||
it('D6', () => { | ||
const values = rollDiceMultiDifferentValue(6, 3) | ||
|
||
expect(values.length).to.eq(3) | ||
values.forEach((value,index) => { | ||
expect([1,2,3,4,5,6].includes(value)).to.true | ||
expect(values.toSpliced(index, 1).includes(value)).to.false | ||
}) | ||
}) | ||
}) |