-
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.
feat(grandom): add shuffle and weighted packages to grandom
- Loading branch information
Showing
8 changed files
with
110 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 @@ | ||
import shuffle from '@grandom/shuffle' | ||
export default shuffle |
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 @@ | ||
import weighted from '@grandom/weighted' | ||
export default weighted |
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,22 @@ | ||
import BasicGrandom from '../../../src/Grandom/BasicGrandom' | ||
|
||
describe('Grandom', () => { | ||
test('default usage', () => { | ||
const grandom = new BasicGrandom() | ||
|
||
expect(grandom.bigint).toBeFunction() | ||
expect(typeof grandom.bigint()).toBe('bigint') | ||
|
||
expect(grandom.boolean).toBeFunction() | ||
expect(typeof grandom.boolean()).toBe('boolean') | ||
|
||
expect(grandom.number).toBeFunction() | ||
expect(typeof grandom.number()).toBe('number') | ||
|
||
expect(grandom.pick).toBeFunction() | ||
expect(typeof grandom.pick('123')).toBe('string') | ||
|
||
expect(grandom.string).toBeFunction() | ||
expect(typeof grandom.string()).toBe('string') | ||
}) | ||
}) |
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,12 +1,47 @@ | ||
import { LENGTH, BooleanStats } from '@testyard/stats' | ||
import grandom from '../src' | ||
|
||
describe('grandom', () => { | ||
test('basics', () => { | ||
expect(grandom.bigint).toBeFunction() | ||
expect(grandom.boolean).toBeFunction() | ||
expect(grandom.number).toBeFunction() | ||
expect(grandom.string).toBeFunction() | ||
expect(grandom.shuffle).toBeFunction() | ||
expect(grandom.pick).toBeFunction() | ||
describe('default Grandom instance', () => { | ||
describe('.boolean()', () => { | ||
test('basic usage', () => { | ||
expect(grandom.boolean()).toBeBoolean() | ||
}) | ||
|
||
describe('biased usage', () => { | ||
test('~50% true / ~50% false', () => { | ||
const { add, result } = new BooleanStats() | ||
|
||
for (let i = 0; i < LENGTH; i++) { | ||
add(grandom.boolean()) | ||
} | ||
|
||
expect(result.true.percent).toBeWithin(0.49, 0.52) | ||
expect(result.false.percent).toBeWithin(0.49, 0.52) | ||
}) | ||
|
||
test('always true', () => { | ||
const { add, result } = new BooleanStats() | ||
|
||
for (let i = 0; i < LENGTH; i++) { | ||
add(grandom.boolean(1)) | ||
} | ||
|
||
expect(result.true.percent).toBe(1) | ||
expect(result.false.percent).toBe(0) | ||
}) | ||
|
||
test('always false', () => { | ||
const { add, result } = new BooleanStats() | ||
|
||
for (let i = 0; i < LENGTH; i++) { | ||
add(grandom.boolean(0)) | ||
} | ||
|
||
expect(result.true.percent).toBe(0) | ||
expect(result.false.percent).toBe(1) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |