Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ComputerSolitaire/Game/Klondike/GameSessionKlondike.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ extension SolitaireViewModel {
state.waste.removeAll()
setWasteDrawCount(0)
incrementMovesCount()
if stockDrawCount == DrawMode.one.rawValue {
if scoringDrawCount == DrawMode.one.rawValue {
applyScore(.recycleWasteInDrawOne)
}
SoundManager.shared.play(.wasteRecycleToStock)
Expand Down
2 changes: 1 addition & 1 deletion ComputerSolitaire/Game/Shared/GameSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class SolitaireViewModel {
private(set) var finalElapsedSeconds: Int?
private var pauseStartedAt: Date?
private(set) var stockDrawCount: Int = 3
private var scoringDrawCount: Int = DrawMode.three.rawValue
private(set) var scoringDrawCount: Int = DrawMode.three.rawValue
private var hasStartedTrackedGame = false
private var isCurrentGameFinalized = false
private var hintRequestsInCurrentGame: Int = 0
Expand Down
41 changes: 40 additions & 1 deletion ComputerSolitaireTests/Shared/SolitaireViewModelCoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,44 @@ final class SolitaireViewModelCoreTests: XCTestCase {
XCTAssertTrue(viewModel.state.stock.allSatisfy { !$0.isFaceUp })
}

func testRecyclePenaltyAppliesWhenDealtDrawOneEvenAfterSwitchingToDrawThree() {
var state = GameStateFixtures.validPersistenceState()
state.waste = state.stock.map { card in
var faceUp = card
faceUp.isFaceUp = true
return faceUp
}
state.stock = []
state.wasteDrawCount = min(1, state.waste.count)
let viewModel = makeViewModel(
restoring: payload(state: state, stockDrawCount: DrawMode.one.rawValue, score: 150)
)

viewModel.updateDrawMode(.three)
viewModel.handleStockTap()

XCTAssertEqual(viewModel.score, 150 + Scoring.delta(for: .recycleWasteInDrawOne))
}

func testRecycleHasNoPenaltyWhenDealtDrawThreeEvenAfterSwitchingToDrawOne() {
var state = GameStateFixtures.validPersistenceState()
state.waste = state.stock.map { card in
var faceUp = card
faceUp.isFaceUp = true
return faceUp
}
state.stock = []
state.wasteDrawCount = min(3, state.waste.count)
let viewModel = makeViewModel(
restoring: payload(state: state, stockDrawCount: DrawMode.three.rawValue, score: 150)
)

viewModel.updateDrawMode(.one)
viewModel.handleStockTap()

XCTAssertEqual(viewModel.score, 150)
}

func testStartDragCanDropAndHandleDropMoveWasteToFoundation() {
let aceSpades = TestCards.make(.spades, .ace, isFaceUp: true)
let state = makeValidState(
Expand Down Expand Up @@ -168,14 +206,15 @@ final class SolitaireViewModelCoreTests: XCTestCase {
state: GameState,
savedAt: Date = DateFixtures.reference,
stockDrawCount: Int,
score: Int = 0,
gameStartedAt: Date = DateFixtures.reference,
pauseStartedAt: Date? = nil
) -> SavedGamePayload {
SavedGamePayload(
savedAt: savedAt,
state: state,
movesCount: 0,
score: 0,
score: score,
gameStartedAt: gameStartedAt,
pauseStartedAt: pauseStartedAt,
hasAppliedTimeBonus: false,
Expand Down
Loading