-
Notifications
You must be signed in to change notification settings - Fork 2
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
6654330
commit ab267e6
Showing
6 changed files
with
167 additions
and
13 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
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,14 +1,17 @@ | ||
import Player from '@/services/enum/Player' | ||
import { Round, Turn } from '@/store/state' | ||
|
||
export default function (params?: MockRoundParams) : Round { | ||
const round : Round = { | ||
round: params?.round ?? 1, | ||
startPlayer: params?.startPlayer ?? Player.PLAYER, | ||
turns: params?.turns ?? [] | ||
} | ||
return round | ||
} | ||
|
||
export interface MockRoundParams { | ||
round? : number | ||
round? : number, | ||
startPlayer?: Player, | ||
turns? : Turn[] | ||
} |
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,18 +1,25 @@ | ||
import DifficultyLevel from '@/services/enum/DifficultyLevel' | ||
import { Round, State } from '@/store/state' | ||
import ScoringCategory from '@/services/enum/ScoringCategory' | ||
import { CardDeckPersistence, Round, State } from '@/store/state' | ||
|
||
export default function (params?: MockStateParams) : State { | ||
return { | ||
language: 'en', | ||
baseFontSize: 1, | ||
setup: { | ||
difficultyLevel: params?.difficultyLevel ?? DifficultyLevel.BEGINNER | ||
difficultyLevel: params?.difficultyLevel ?? DifficultyLevel.BEGINNER, | ||
eraScoringTiles: params?.eraScoringTiles ?? [], | ||
finalScoringTiles: params?.finalScoringTiles ?? [], | ||
initialCardDeck: params?.initialCardDeck | ||
}, | ||
rounds: params?.rounds ?? [] | ||
} | ||
} | ||
|
||
export interface MockStateParams { | ||
difficultyLevel?: DifficultyLevel | ||
difficultyLevel?: DifficultyLevel, | ||
eraScoringTiles?: ScoringCategory[], | ||
finalScoringTiles?: ScoringCategory[], | ||
initialCardDeck?: CardDeckPersistence, | ||
rounds?: Round[] | ||
} |
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,13 +1,34 @@ | ||
import { Turn } from '@/store/state' | ||
import CardDeck from '@/services/CardDeck' | ||
import Player from '@/services/enum/Player' | ||
import { CardDeckPersistence, Turn } from '@/store/state' | ||
|
||
export default function (params?: MockTurnParams) : Turn { | ||
return { | ||
const turn : Turn = { | ||
round: params?.round ?? 1, | ||
turn: params?.turn ?? 1 | ||
turn: params?.turn ?? 1, | ||
player: params?.player ?? Player.PLAYER | ||
} | ||
if (params?.cardDeck || params?.evolutionCount || params?.prosperityCount || params?.actionRoll || params?.territoryRoll || params?.beaconRoll) { | ||
turn.botPersistence = { | ||
cardDeck: params?.cardDeck ?? CardDeck.new().toPersistence(), | ||
evolutionCount: params?.evolutionCount ?? 0, | ||
prosperityCount: params?.prosperityCount ?? 0, | ||
actionRoll: params?.actionRoll ?? 0, | ||
territoryRoll: params?.territoryRoll ?? 0, | ||
beaconRoll: params?.beaconRoll ?? 0 | ||
} | ||
} | ||
return turn | ||
} | ||
|
||
export interface MockTurnParams { | ||
round? : number | ||
turn? : number | ||
player? : Player | ||
cardDeck?: CardDeckPersistence | ||
evolutionCount?: number | ||
prosperityCount?: number | ||
actionRoll?: number | ||
territoryRoll?: number | ||
beaconRoll?: number | ||
} |
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,114 @@ | ||
import NavigationState from '@/util/NavigationState' | ||
import { expect } from 'chai' | ||
import mockRouteLocation from '../helper/mockRouteLocation' | ||
import mockState from '../helper/mockState' | ||
import Player from '@/services/enum/Player' | ||
import mockRound from '../helper/mockRound' | ||
import mockTurn from '../helper/mockTurn' | ||
|
||
const stateBotData = mockState({initialCardDeck:{pile:[1,2,3,4],discard:[]}, rounds:[ | ||
mockRound({round:1, turns:[ | ||
mockTurn({round:1,turn:1,player:Player.PLAYER}), | ||
mockTurn({round:1,turn:2,player:Player.BOT,cardDeck:{pile:[2,3,4],discard:[1]}}), | ||
mockTurn({round:1,turn:3,player:Player.PLAYER}), | ||
mockTurn({round:1,turn:4,player:Player.BOT,cardDeck:{pile:[3,4],discard:[2,1]}, | ||
evolutionCount:2, prosperityCount:1, | ||
actionRoll:3, territoryRoll:4, beaconRoll:5}) | ||
]}) | ||
]}) | ||
|
||
describe('util/NavigationState', () => { | ||
it('roundStart', () => { | ||
const route = mockRouteLocation({name:'RoundStart', params:{round:'1'}}) | ||
const state = mockState() | ||
const navigationState = new NavigationState(route, state) | ||
|
||
expect(navigationState.player).to.eq(Player.PLAYER) | ||
expect(navigationState.round).to.eq(1) | ||
expect(navigationState.turn).to.eq(0) | ||
}) | ||
|
||
it('turnPlayer', () => { | ||
const route = mockRouteLocation({name:'TurnPlayer', params:{round:'1',turn:'3'}}) | ||
const state = mockState() | ||
const navigationState = new NavigationState(route, state) | ||
|
||
expect(navigationState.player).to.eq(Player.PLAYER) | ||
expect(navigationState.round).to.eq(1) | ||
expect(navigationState.turn).to.eq(3) | ||
}) | ||
|
||
it('roundEnd', () => { | ||
const route = mockRouteLocation({name:'RoundEnd', params:{round:'1'}}) | ||
const state = mockState() | ||
const navigationState = new NavigationState(route, state) | ||
|
||
expect(navigationState.player).to.eq(Player.PLAYER) | ||
expect(navigationState.round).to.eq(1) | ||
expect(navigationState.turn).to.eq(999) | ||
}) | ||
|
||
it('startPlayer', () => { | ||
const route = mockRouteLocation({name:'TurnBot', params:{round:'1',turn:'3'}}) | ||
const state = mockState({rounds:[ | ||
mockRound({round:1,startPlayer:Player.BOT}) | ||
]}) | ||
const navigationState = new NavigationState(route, state) | ||
|
||
expect(navigationState.player).to.eq(Player.BOT) | ||
expect(navigationState.round).to.eq(1) | ||
expect(navigationState.turn).to.eq(3) | ||
}) | ||
|
||
it('turnBot-currentTurn', () => { | ||
const route = mockRouteLocation({name:'TurnBot', params:{round:'1',turn:'4'}}) | ||
const navigationState = new NavigationState(route, stateBotData) | ||
|
||
expect(navigationState.player).to.eq(Player.BOT) | ||
expect(navigationState.cardDeck.toPersistence()).to.eql({pile:[3,4],discard:[2,1]}) | ||
expect(navigationState.evolutionCount).to.eq(2) | ||
expect(navigationState.prosperityCount).to.eq(1) | ||
expect(navigationState.actionRoll).to.eq(3) | ||
expect(navigationState.territoryRoll).to.eq(4) | ||
expect(navigationState.beaconRoll).to.eq(5) | ||
}) | ||
|
||
it('turnBot-lastTurn', () => { | ||
const route = mockRouteLocation({name:'TurnBot', params:{round:'1',turn:'6'}}) | ||
const navigationState = new NavigationState(route, stateBotData) | ||
|
||
expect(navigationState.player).to.eq(Player.BOT) | ||
expect(navigationState.cardDeck.toPersistence()).to.eql({pile:[4],discard:[3,2,1]}) | ||
expect(navigationState.evolutionCount).to.eq(2) | ||
expect(navigationState.prosperityCount).to.eq(1) | ||
expect(navigationState.actionRoll).to.greaterThanOrEqual(1) | ||
expect(navigationState.territoryRoll).to.greaterThanOrEqual(1) | ||
expect(navigationState.beaconRoll).to.greaterThanOrEqual(1) | ||
}) | ||
|
||
it('turnBot-lastRoundLastTurn', () => { | ||
const route = mockRouteLocation({name:'TurnBot', params:{round:'2',turn:'1'}}) | ||
const navigationState = new NavigationState(route, stateBotData) | ||
|
||
expect(navigationState.player).to.eq(Player.BOT) | ||
expect(navigationState.cardDeck.toPersistence()).to.eql({pile:[4],discard:[3,2,1]}) | ||
expect(navigationState.evolutionCount).to.eq(2) | ||
expect(navigationState.prosperityCount).to.eq(1) | ||
expect(navigationState.actionRoll).to.greaterThanOrEqual(1) | ||
expect(navigationState.territoryRoll).to.greaterThanOrEqual(1) | ||
expect(navigationState.beaconRoll).to.greaterThanOrEqual(1) | ||
}) | ||
|
||
it('turnBot-initialCardDeck', () => { | ||
const route = mockRouteLocation({name:'TurnPlayer', params:{round:'1',turn:'1'}}) | ||
const navigationState = new NavigationState(route, stateBotData) | ||
|
||
expect(navigationState.player).to.eq(Player.PLAYER) | ||
expect(navigationState.cardDeck.toPersistence()).to.eql({pile:[1,2,3,4],discard:[]}) | ||
expect(navigationState.evolutionCount).to.eq(0) | ||
expect(navigationState.prosperityCount).to.eq(0) | ||
expect(navigationState.actionRoll).to.eq(0) | ||
expect(navigationState.territoryRoll).to.eq(0) | ||
expect(navigationState.beaconRoll).to.eq(0) | ||
}) | ||
}) |