Skip to content

Commit

Permalink
Fix Windows line endings
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarrough committed Dec 26, 2020
1 parent 43db8d3 commit e72cdb8
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 111 deletions.
152 changes: 76 additions & 76 deletions tests/dungeon.js
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
import test from 'ava'
import actions from '../public/game/actions'
import Dungeon, {CampfireRoom, MonsterRoom, Monster} from '../public/game/dungeon'
import {getCurrRoom, isCurrentRoomCompleted, isDungeonCompleted} from '../public/game/utils'

const a = actions

test('can create rooms with many monsters', (t) => {
const room = new MonsterRoom(new Monster(), new Monster())
t.is(room.monsters.length, 2)
})

test('can create a dungeon', (t) => {
const d = Dungeon({
rooms: [MonsterRoom(Monster()), CampfireRoom(), MonsterRoom(Monster())],
})
t.is(d.rooms.length, 3)
t.is(d.rooms[0].type, 'monster')
t.is(d.rooms[0].monsters.length, 1)
t.is(d.rooms[1].type, 'campfire')
t.is(d.rooms[2].type, 'monster')
})

test('can set a dungeon', (t) => {
const dungeon = Dungeon({rooms: [MonsterRoom(Monster())]})
let state = a.createNewGame()
state = a.setDungeon(state, dungeon)
t.deepEqual(state.dungeon, dungeon, 'setting dungeon works')
})

test('we know when a monster room is won', (t) => {
const room = new MonsterRoom(new Monster())
const state = {dungeon: {rooms: [room]}}
t.false(isCurrentRoomCompleted(state))
room.monsters[0].currentHealth = 0
t.true(isCurrentRoomCompleted(state))
})

test('we know when the entire dungeon has been cleared', (t) => {
const dungeon = Dungeon({
rooms: [MonsterRoom(Monster()), MonsterRoom(Monster())],
})
const state = {dungeon}
t.false(isDungeonCompleted(state))
state.dungeon.rooms[0].monsters[0].currentHealth = 0
t.false(isDungeonCompleted(state))
state.dungeon.rooms[1].monsters[0].currentHealth = 0
t.true(isDungeonCompleted(state))
})

test('we know when a monster room with many monsters is won', (t) => {
const room = new MonsterRoom(new Monster(), new Monster())
const state = {dungeon: {rooms: [room]}}
t.false(isCurrentRoomCompleted(state))
room.monsters[0].currentHealth = 0
t.false(isCurrentRoomCompleted(state))
room.monsters[1].currentHealth = 0
t.true(isCurrentRoomCompleted(state))
})

test.todo('we know when a campfire has been used')

test('we can navigate a dungeon', (t) => {
// Prepare a game with a dungeon.
let state = a.createNewGame()
const dungeon = Dungeon({
rooms: [CampfireRoom(), CampfireRoom(), CampfireRoom()],
})
state = a.setDungeon(state, dungeon)
// Go through the next rooms.
state = a.goToNextRoom(state)
t.is(getCurrRoom(state).id, dungeon.rooms[1].id)
state = a.goToNextRoom(state)
t.is(getCurrRoom(state).id, dungeon.rooms[2].id)
t.throws(() => a.goToNextRoom(state), null, 'can not go further than last room')
})
import test from 'ava'
import actions from '../public/game/actions'
import Dungeon, {CampfireRoom, MonsterRoom, Monster} from '../public/game/dungeon'
import {getCurrRoom, isCurrentRoomCompleted, isDungeonCompleted} from '../public/game/utils'

const a = actions

test('can create rooms with many monsters', (t) => {
const room = new MonsterRoom(new Monster(), new Monster())
t.is(room.monsters.length, 2)
})

test('can create a dungeon', (t) => {
const d = Dungeon({
rooms: [MonsterRoom(Monster()), CampfireRoom(), MonsterRoom(Monster())],
})
t.is(d.rooms.length, 3)
t.is(d.rooms[0].type, 'monster')
t.is(d.rooms[0].monsters.length, 1)
t.is(d.rooms[1].type, 'campfire')
t.is(d.rooms[2].type, 'monster')
})

test('can set a dungeon', (t) => {
const dungeon = Dungeon({rooms: [MonsterRoom(Monster())]})
let state = a.createNewGame()
state = a.setDungeon(state, dungeon)
t.deepEqual(state.dungeon, dungeon, 'setting dungeon works')
})

test('we know when a monster room is won', (t) => {
const room = new MonsterRoom(new Monster())
const state = {dungeon: {rooms: [room]}}
t.false(isCurrentRoomCompleted(state))
room.monsters[0].currentHealth = 0
t.true(isCurrentRoomCompleted(state))
})

test('we know when the entire dungeon has been cleared', (t) => {
const dungeon = Dungeon({
rooms: [MonsterRoom(Monster()), MonsterRoom(Monster())],
})
const state = {dungeon}
t.false(isDungeonCompleted(state))
state.dungeon.rooms[0].monsters[0].currentHealth = 0
t.false(isDungeonCompleted(state))
state.dungeon.rooms[1].monsters[0].currentHealth = 0
t.true(isDungeonCompleted(state))
})

test('we know when a monster room with many monsters is won', (t) => {
const room = new MonsterRoom(new Monster(), new Monster())
const state = {dungeon: {rooms: [room]}}
t.false(isCurrentRoomCompleted(state))
room.monsters[0].currentHealth = 0
t.false(isCurrentRoomCompleted(state))
room.monsters[1].currentHealth = 0
t.true(isCurrentRoomCompleted(state))
})

test.todo('we know when a campfire has been used')

test('we can navigate a dungeon', (t) => {
// Prepare a game with a dungeon.
let state = a.createNewGame()
const dungeon = Dungeon({
rooms: [CampfireRoom(), CampfireRoom(), CampfireRoom()],
})
state = a.setDungeon(state, dungeon)
// Go through the next rooms.
state = a.goToNextRoom(state)
t.is(getCurrRoom(state).id, dungeon.rooms[1].id)
state = a.goToNextRoom(state)
t.is(getCurrRoom(state).id, dungeon.rooms[2].id)
t.throws(() => a.goToNextRoom(state), null, 'can not go further than last room')
})
70 changes: 35 additions & 35 deletions tests/game.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import test from 'ava'
import createNewGame from '../public/game/index.js'
import {createCard} from '../public/game/cards'

// We don't want to test too much here,
// since tests/actions.js has most of it.

test('it all', (t) => {
const game = createNewGame()
t.is(game.state.player.currentHealth, 72)
// can add a card
const strike = createCard('Strike')
game.enqueue({type: 'addCardToHand', card: strike})
t.is(game.future.list.length, 1)
t.is(game.past.list.length, 0)
game.dequeue()
t.is(game.future.list.length, 0)
t.is(game.past.list.length, 1)
t.is(game.state.hand.length, 6)
t.is(game.state.hand[game.state.hand.length - 1].id, strike.id)
// we can undo
game.undo()
t.is(game.state.hand.length, 5)
// and draw cards again
game.enqueue({type: 'drawCards'})
game.dequeue()
t.is(game.state.hand.length, 10)
})

test('game also contains actions', (t) => {
const game = createNewGame()
game.state.hand = []
game.state = game.actions.drawCards(game.state)
t.is(game.state.hand.length, 5)
})
import test from 'ava'
import createNewGame from '../public/game/index.js'
import {createCard} from '../public/game/cards'

// We don't want to test too much here,
// since tests/actions.js has most of it.

test('it all', (t) => {
const game = createNewGame()
t.is(game.state.player.currentHealth, 72)
// can add a card
const strike = createCard('Strike')
game.enqueue({type: 'addCardToHand', card: strike})
t.is(game.future.list.length, 1)
t.is(game.past.list.length, 0)
game.dequeue()
t.is(game.future.list.length, 0)
t.is(game.past.list.length, 1)
t.is(game.state.hand.length, 6)
t.is(game.state.hand[game.state.hand.length - 1].id, strike.id)
// we can undo
game.undo()
t.is(game.state.hand.length, 5)
// and draw cards again
game.enqueue({type: 'drawCards'})
game.dequeue()
t.is(game.state.hand.length, 10)
})

test('game also contains actions', (t) => {
const game = createNewGame()
game.state.hand = []
game.state = game.actions.drawCards(game.state)
t.is(game.state.hand.length, 5)
})

0 comments on commit e72cdb8

Please sign in to comment.