Skip to content

Commit

Permalink
Add import fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SleeplessByte committed Jul 29, 2024
1 parent e425038 commit 62f6808
Show file tree
Hide file tree
Showing 22 changed files with 1,477 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ COPY . .

# Build the test runner
RUN set -ex; \
corepack enable; \
# install all the development modules (used for building)
yarn install; \
yarn build; \
Expand All @@ -28,6 +29,5 @@ RUN set -ex; \
# install only the node_modules we need for production
yarn workspaces focus --production;


USER appuser
ENTRYPOINT [ "/opt/test-runner/bin/run.sh" ]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"prepublish": "yarn test:bare && yarn lint",
"lint": "yarn eslint src -c eslint.config.mjs && yarn eslint test -c eslint.config.mjs",
"test": "yarn build && yarn test:bare",
"test:bare": "yarn node test/smoke.test.mjs && yarn node test/skip.test.mjs"
"test:bare": "yarn node test/smoke.test.mjs && yarn node test/skip.test.mjs && yarn node test/import.test.mjs"
},
"dependencies": {
"@exercism/babel-preset-typescript": "^0.5.0",
Expand Down
17 changes: 7 additions & 10 deletions test/asserts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import { run, root } from './paths.mjs'

const SILENT = true

export function assertPass(slug, fixture, outputDir = '') {
export function assertPass(slug, fixture, outputDir = null) {
outputDir = outputDir || mkdtempSync(join(tmpdir(), 'foo-'))
outputDir = fixture
const resultPath = join(outputDir, 'results.json')

if (fixture[fixture.length - 1] !== sep) {
Expand All @@ -24,7 +23,7 @@ export function assertPass(slug, fixture, outputDir = '') {
shelljs.rm(resultPath)
}

const command = ['bash', run, slug, fixture].join(' ')
const command = ['bash', run, slug, fixture, outputDir].join(' ')

// shelljs.echo(`-> ${command}`)
const { stderr, code } = shelljs.exec(command, {
Expand All @@ -47,7 +46,7 @@ export function assertPass(slug, fixture, outputDir = '') {

if (!existsSync(resultPath)) {
shelljs.echo(
`assert pass on ${slug} for ${fixture} failed. result.json does not exist.`
`assert pass on ${slug} for ${resultPath} failed. results.json does not exist.`
)
shelljs.exit(-1)
}
Expand All @@ -64,9 +63,8 @@ export function assertPass(slug, fixture, outputDir = '') {
shelljs.echo('assert pass')
}

export function rejectPass(slug, fixture, outputDir = '') {
export function rejectPass(slug, fixture, outputDir = null) {
outputDir = outputDir || mkdtempSync(join(tmpdir(), 'foo-'))
outputDir = fixture
const resultPath = join(outputDir, 'results.json')

if (fixture[fixture.length - 1] !== sep) {
Expand All @@ -82,7 +80,7 @@ export function rejectPass(slug, fixture, outputDir = '') {
shelljs.rm(resultPath)
}

const command = ['bash', run, slug, fixture].join(' ')
const command = ['bash', run, slug, fixture, outputDir].join(' ')

// shelljs.echo(`-> ${command}`)
const { stderr, code } = shelljs.exec(command, {
Expand Down Expand Up @@ -128,9 +126,8 @@ export function rejectPass(slug, fixture, outputDir = '') {
shelljs.echo('reject pass')
}

export function assertError(slug, fixture, outputDir = '') {
export function assertError(slug, fixture, outputDir = null) {
outputDir = outputDir || mkdtempSync(join(tmpdir(), 'foo-'))
outputDir = fixture
const resultPath = join(outputDir, 'results.json')

if (fixture[fixture.length - 1] !== sep) {
Expand All @@ -146,7 +143,7 @@ export function assertError(slug, fixture, outputDir = '') {
shelljs.rm(resultPath)
}

const command = ['bash', run, slug, fixture].join(' ')
const command = ['bash', run, slug, fixture, outputDir].join(' ')

// shelljs.echo(`-> ${command}`)
const { stderr, code } = shelljs.exec(command, {
Expand Down
32 changes: 32 additions & 0 deletions test/fixtures/dnd-character/peerreynders/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Instructions

For a game of [Dungeons & Dragons][dnd], each player starts by generating a character they can play with.
This character has, among other things, six abilities; strength, dexterity, constitution, intelligence, wisdom and charisma.
These six abilities have scores that are determined randomly.
You do this by rolling four 6-sided dice and recording the sum of the largest three dice.
You do this six times, once for each ability.

Your character's initial hitpoints are 10 + your character's constitution modifier.
You find your character's constitution modifier by subtracting 10 from your character's constitution, divide by 2 and round down.

Write a random character generator that follows the above rules.

For example, the six throws of four dice may look like:

- 5, 3, 1, 6: You discard the 1 and sum 5 + 3 + 6 = 14, which you assign to strength.
- 3, 2, 5, 3: You discard the 2 and sum 3 + 5 + 3 = 11, which you assign to dexterity.
- 1, 1, 1, 1: You discard the 1 and sum 1 + 1 + 1 = 3, which you assign to constitution.
- 2, 1, 6, 6: You discard the 1 and sum 2 + 6 + 6 = 14, which you assign to intelligence.
- 3, 5, 3, 4: You discard the 3 and sum 5 + 3 + 4 = 12, which you assign to wisdom.
- 6, 6, 6, 6: You discard the 6 and sum 6 + 6 + 6 = 18, which you assign to charisma.

Because constitution is 3, the constitution modifier is -4 and the hitpoints are 6.

~~~~exercism/note
Most programming languages feature (pseudo-)random generators, but few programming languages are designed to roll dice.
One such language is [Troll][troll].
[troll]: https://di.ku.dk/Ansatte/?pure=da%2Fpublications%2Ftroll-a-language-for-specifying-dicerolls(84a45ff0-068b-11df-825d-000ea68e967b)%2Fexport.html
~~~~

[dnd]: https://en.wikipedia.org/wiki/Dungeons_%26_Dragons
10 changes: 10 additions & 0 deletions test/fixtures/dnd-character/peerreynders/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Introduction

After weeks of anticipation, you and your friends get together for your very first game of [Dungeons & Dragons][dnd] (D&D).
Since this is the first session of the game, each player has to generate a character to play with.
The character's abilities are determined by rolling 6-sided dice, but where _are_ the dice?
With a shock, you realize that your friends are waiting for _you_ to produce the dice; after all it was your idea to play D&D!
Panicking, you realize you forgot to bring the dice, which would mean no D&D game.
As you have some basic coding skills, you quickly come up with a solution: you'll write a program to simulate dice rolls.

[dnd]: https://en.wikipedia.org/wiki/Dungeons_%26_Dragons
20 changes: 20 additions & 0 deletions test/fixtures/dnd-character/peerreynders/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"authors": [
"JoshiRaez",
"SleeplessByte"
],
"files": {
"solution": [
"dnd-character.ts"
],
"test": [
"dnd-character.test.ts"
],
"example": [
".meta/proof.ci.ts"
]
},
"blurb": "Randomly generate Dungeons & Dragons characters.",
"source": "Simon Shine, Erik Schierboom",
"source_url": "https://github.com/exercism/problem-specifications/issues/616#issuecomment-437358945"
}
40 changes: 40 additions & 0 deletions test/fixtures/dnd-character/peerreynders/.meta/proof.ci.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export class DnDCharacter {
public readonly hitpoints: number

public readonly strength: number
public readonly dexterity: number
public readonly constitution: number
public readonly intelligence: number
public readonly wisdom: number
public readonly charisma: number

constructor() {
this.strength = DnDCharacter.generateAbilityScore()
this.dexterity = DnDCharacter.generateAbilityScore()
this.constitution = DnDCharacter.generateAbilityScore()
this.intelligence = DnDCharacter.generateAbilityScore()
this.wisdom = DnDCharacter.generateAbilityScore()
this.charisma = DnDCharacter.generateAbilityScore()

this.hitpoints = 10 + DnDCharacter.getModifierFor(this.constitution)
}

public static generateAbilityScore(): number {
return this.rollDice(4)
.sort()
.slice(1, 4)
.reduce((acu, act) => acu + act, 0)
}

public static getModifierFor(abilityValue: number): number {
return Math.floor((abilityValue - 10) / 2)
}

private static rollDice(quantity: number): number[] {
return new Array<number>(quantity).fill(0).map(() => this.rollDie())
}

private static rollDie(): number {
return Math.floor(Math.random() * 6) + 1
}
}
76 changes: 76 additions & 0 deletions test/fixtures/dnd-character/peerreynders/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[1e9ae1dc-35bd-43ba-aa08-e4b94c20fa37]
description = "Ability modifier for score 3 is -4"
include = true

[cc9bb24e-56b8-4e9e-989d-a0d1a29ebb9c]
description = "Ability modifier for score 4 is -3"
include = true

[5b519fcd-6946-41ee-91fe-34b4f9808326]
description = "Ability modifier for score 5 is -3"
include = true

[dc2913bd-6d7a-402e-b1e2-6d568b1cbe21]
description = "Ability modifier for score 6 is -2"
include = true

[099440f5-0d66-4b1a-8a10-8f3a03cc499f]
description = "Ability modifier for score 7 is -2"
include = true

[cfda6e5c-3489-42f0-b22b-4acb47084df0]
description = "Ability modifier for score 8 is -1"
include = true

[c70f0507-fa7e-4228-8463-858bfbba1754]
description = "Ability modifier for score 9 is -1"
include = true

[6f4e6c88-1cd9-46a0-92b8-db4a99b372f7]
description = "Ability modifier for score 10 is 0"
include = true

[e00d9e5c-63c8-413f-879d-cd9be9697097]
description = "Ability modifier for score 11 is 0"
include = true

[eea06f3c-8de0-45e7-9d9d-b8cab4179715]
description = "Ability modifier for score 12 is 1"
include = true

[9c51f6be-db72-4af7-92ac-b293a02c0dcd]
description = "Ability modifier for score 13 is 1"
include = true

[94053a5d-53b6-4efc-b669-a8b5098f7762]
description = "Ability modifier for score 14 is 2"
include = true

[8c33e7ca-3f9f-4820-8ab3-65f2c9e2f0e2]
description = "Ability modifier for score 15 is 2"
include = true

[c3ec871e-1791-44d0-b3cc-77e5fb4cd33d]
description = "Ability modifier for score 16 is 3"
include = true

[3d053cee-2888-4616-b9fd-602a3b1efff4]
description = "Ability modifier for score 17 is 3"
include = true

[bafd997a-e852-4e56-9f65-14b60261faee]
description = "Ability modifier for score 18 is 4"
include = true

[4f28f19c-2e47-4453-a46a-c0d365259c14]
description = "Random ability is within range"
include = true

[385d7e72-864f-4e88-8279-81a7d75b04ad]
description = "Random character is valid"
include = true

[2ca77b9b-c099-46c3-a02c-0d0f68ffa0fe]
description = "Each ability is only calculated once"
include = true

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"arcanis.vscode-zipfs",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"cSpell.words": ["exercism"],
"search.exclude": {
"**/.yarn": true,
"**/.pnp.*": true
}
}
Loading

0 comments on commit 62f6808

Please sign in to comment.