-
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.
Radical Overhaul of exports and internal mechanics (#643)
- Loading branch information
Showing
74 changed files
with
1,515 additions
and
1,578 deletions.
There are no files selected for viewing
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,20 @@ | ||
import dts from 'bun-plugin-dts' | ||
|
||
await Bun.build({ | ||
const results = await Bun.build({ | ||
entrypoints: ['./src/index.ts'], | ||
outdir: './dist', | ||
target: 'node', | ||
splitting: true, | ||
sourcemap: 'inline', | ||
plugins: [dts()] | ||
}) | ||
|
||
if (results.success == false) { | ||
console.error('Build failed') | ||
for (const message of results.logs) { | ||
console.error(message) | ||
} | ||
} else { | ||
console.log('Compiled ' + results.outputs.length + ' javascript files...') | ||
} | ||
|
||
export {} |
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,23 @@ | ||
import { RollConfig } from '~src/types' | ||
import { coreRandom } from '~src/utils/coreRandom' | ||
|
||
export class D { | ||
constructor(public sides: number) { | ||
this.sides = sides | ||
} | ||
|
||
toRollConfig(): RollConfig { | ||
return { | ||
sides: this.sides, | ||
quantity: 1 | ||
} | ||
} | ||
|
||
roll(): number { | ||
return coreRandom(this.sides) | ||
} | ||
|
||
rollMany(quantity: number): number[] { | ||
return Array.from({ length: quantity }, () => this.roll()) | ||
} | ||
} |
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,39 @@ | ||
import { describe, expect, test } from 'bun:test' | ||
import { D } from '../D' | ||
|
||
describe('D', () => { | ||
test('.sides returns the number given as sides', () => { | ||
const sides = 6 | ||
const die = new D(sides) | ||
|
||
expect(die.sides).toEqual(sides) | ||
}) | ||
|
||
test('.roll() returns a number included in the constructor', () => { | ||
const sides = 6 | ||
const die = new D(sides) | ||
|
||
expect([1, 2, 3, 4, 5, 6]).toContain(die.roll()) | ||
}) | ||
|
||
test('.rollMany() returns an array of numbers ', () => { | ||
const sides = 6 | ||
const die = new D(sides) | ||
const quantity = 10 | ||
const rolls = die.rollMany(quantity) | ||
|
||
expect(rolls.length).toEqual(quantity) | ||
rolls.forEach((roll) => expect([1, 2, 3, 4, 5, 6]).toContain(roll)) | ||
}) | ||
|
||
test('toConfig() returns a RollConfig object', () => { | ||
const sides = 6 | ||
const die = new D(sides) | ||
const config = die.toRollConfig() | ||
|
||
expect(config).toEqual({ | ||
sides, | ||
quantity: 1 | ||
}) | ||
}) | ||
}) |
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,32 @@ | ||
import { D10, D100, D12, D20, D4, D6, D8 } from '../dice' | ||
import { describe, expect, test } from 'bun:test' | ||
|
||
describe('exported dice', () => { | ||
test('D4 should be a D with 4 sides', () => { | ||
expect(D4.sides).toEqual(4) | ||
}) | ||
|
||
test('D6 should be a D with 6 sides', () => { | ||
expect(D6.sides).toEqual(6) | ||
}) | ||
|
||
test('D8 should be a D with 8 sides', () => { | ||
expect(D8.sides).toEqual(8) | ||
}) | ||
|
||
test('D10 should be a D with 10 sides', () => { | ||
expect(D10.sides).toEqual(10) | ||
}) | ||
|
||
test('D12 should be a D with 12 sides', () => { | ||
expect(D12.sides).toEqual(12) | ||
}) | ||
|
||
test('D20 should be a D with 20 sides', () => { | ||
expect(D20.sides).toEqual(20) | ||
}) | ||
|
||
test('D100 should be a D with 100 sides', () => { | ||
expect(D100.sides).toEqual(100) | ||
}) | ||
}) |
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 @@ | ||
export { D } from './D' | ||
export * from './dice' |
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,34 @@ | ||
import { describe, expect, test } from 'bun:test' | ||
import { rollCustomFaces } from '../rollCustomFaces' | ||
|
||
import { CustomFacesD } from '../customFacesD' | ||
|
||
const loops = 9999 | ||
|
||
describe('roll', () => { | ||
describe('Stress Test', () => { | ||
describe('custom dice and numerical dice mixed', () => { | ||
const dummyArray = Array.from( | ||
{ length: loops }, | ||
() => | ||
rollCustomFaces( | ||
20, | ||
{ sides: 20 }, | ||
new CustomFacesD(['H', 'T']), | ||
'2d20' | ||
).result | ||
) | ||
|
||
test('returns an array of strings', () => { | ||
dummyArray.forEach((individualRolls) => { | ||
expect(individualRolls).toHaveLength(5) | ||
individualRolls.flat().forEach((individualRoll) => { | ||
expect(individualRoll).toSatisfy( | ||
(value) => typeof value === 'string' | ||
) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
32 changes: 32 additions & 0 deletions
32
src/faces/__tests__/utils/customNotificationToCustomRollConfig.test.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,32 @@ | ||
import { describe, expect, it } from 'bun:test' | ||
import { customFacesNotationToCustomFacesRollConfig } from '../../utils/customFacesNotationToCustomFacesRollConfig' | ||
|
||
describe('customNotificationToCustomFacesRollConfig', () => { | ||
describe('given standard dice notation', () => { | ||
const argument = '2d6' | ||
|
||
it('returns a valid custom roll config', () => { | ||
const result = customFacesNotationToCustomFacesRollConfig(argument) | ||
|
||
expect(result).toEqual({ | ||
faces: ['1', '2', '3', '4', '5', '6'], | ||
quantity: 2, | ||
sides: 6 | ||
}) | ||
}) | ||
}) | ||
|
||
describe('given custom dice notation', () => { | ||
const argument = '2d{++ --}' | ||
|
||
it('returns a valid custom roll config', () => { | ||
const result = customFacesNotationToCustomFacesRollConfig(argument) | ||
|
||
expect(result).toEqual({ | ||
faces: ['+', '+', ' ', ' ', '-', '-'], | ||
quantity: 2, | ||
sides: 6 | ||
}) | ||
}) | ||
}) | ||
}) |
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,41 @@ | ||
import { describe, expect, it } from 'bun:test' | ||
import { CustomFacesDiceNotation } from '../types' | ||
import { validateCustomFacesNotation } from '../validateCustomFacesNotation' | ||
|
||
describe('validateCustomFacesNotation', () => { | ||
describe('when given a valid custom dice notation', () => { | ||
const notation: CustomFacesDiceNotation = '2d{HT}' | ||
|
||
it('returns a valid result', () => { | ||
const result = validateCustomFacesNotation(notation) | ||
|
||
expect(result).toEqual({ | ||
valid: true, | ||
argument: notation, | ||
notation: '2d{HT}', | ||
config: { | ||
sides: 2, | ||
quantity: 2, | ||
faces: ['H', 'T'] | ||
}, | ||
description: ['Roll 2 2-sided dice', 'with faces: H, T'] | ||
}) | ||
}) | ||
}) | ||
|
||
describe('when the notation is completely invalid', () => { | ||
const notation = 'invalid-notation' | ||
|
||
it('returns an error result', () => { | ||
const result = validateCustomFacesNotation(notation) | ||
|
||
expect(result).toEqual({ | ||
valid: false, | ||
argument: notation, | ||
notation: undefined, | ||
config: undefined, | ||
description: undefined | ||
}) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.