Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
atomgomba committed Jun 1, 2024
1 parent 9feed32 commit 2e35337
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.ekezet.othello.core.data.models.Position
import com.ekezet.othello.core.game.GameEnd
import com.ekezet.othello.core.game.state.CurrentGameState
import com.ekezet.othello.core.game.store.GameHistoryStore
import com.ekezet.othello.core.ui.render.HistoryImagesRenderer
import com.ekezet.othello.feature.gameboard.actions.OnGameEnded
import com.ekezet.othello.feature.gameboard.actions.OnMoveMade
import com.ekezet.othello.feature.gameboard.actions.OnTurnPassed
Expand All @@ -20,6 +21,9 @@ class GameBoardEffectTest : EffectTest() {
@MockK
private lateinit var mockGameHistoryStore: GameHistoryStore

@MockK
private lateinit var mockHistoryImagesRenderer: HistoryImagesRenderer

private lateinit var dependency: GameBoardDependency

@Before
Expand All @@ -28,6 +32,7 @@ class GameBoardEffectTest : EffectTest() {

dependency = GameBoardDependency(
gameHistoryStore = mockGameHistoryStore,
historyImagesRenderer = mockHistoryImagesRenderer,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import com.ekezet.othello.core.data.models.Disk
import com.ekezet.othello.core.data.models.Position
import com.ekezet.othello.core.data.models.flip
import com.ekezet.othello.core.data.models.isLight
import com.ekezet.othello.core.game.GameEnd
import com.ekezet.othello.core.game.GameEnd.EndedTie
import com.ekezet.othello.core.game.GameEnd.EndedWin
import com.ekezet.othello.core.game.NextTurn
import com.ekezet.othello.core.game.PassTurn
import com.ekezet.othello.core.game.Tie
Expand All @@ -16,9 +19,7 @@ import com.ekezet.othello.core.game.strategy.HumanPlayer
import com.ekezet.othello.core.game.strategy.Strategy
import com.ekezet.othello.core.game.throwable.InvalidNewMoveException
import com.ekezet.othello.feature.gameboard.GameBoardModel
import com.ekezet.othello.core.game.GameEnd
import com.ekezet.othello.core.game.GameEnd.EndedTie
import com.ekezet.othello.core.game.GameEnd.EndedWin
import com.ekezet.othello.feature.gameboard.PublishPastMoves
import com.ekezet.othello.feature.gameboard.WaitBeforeGameEnd
import com.ekezet.othello.feature.gameboard.WaitBeforeNextTurn
import com.ekezet.othello.feature.gameboard.WaitBeforePassTurn
Expand All @@ -35,6 +36,7 @@ import kotlin.test.assertFailsWith
@RunWith(JUnitParamsRunner::class)
class GameBoardActionTest {
private val mockLightStrategy: Strategy = mockk()

private val testModel = GameBoardModel(
lightStrategy = mockLightStrategy,
)
Expand Down Expand Up @@ -196,7 +198,9 @@ class GameBoardActionTest {
assertModel(expectedModel)

if (disk!!.isDark && expectedModel.darkStrategy == HumanPlayer) {
assertEffects(setOf(WaitBeforeNextTurn(nextMovePosition)))
assertEffects(setOf(WaitBeforeNextTurn(nextMovePosition), PublishPastMoves(nextState)))
} else {
assertEffects(setOf(PublishPastMoves(nextState)))
}
}

Expand Down Expand Up @@ -244,6 +248,7 @@ class GameBoardActionTest {
} else if (disk.isLight && expectedModel.lightStrategy != HumanPlayer) {
add(WaitBeforePassTurn(null, nextState))
}
add(PublishPastMoves(nextState))
}

initModel after ContinueGame matches {
Expand Down Expand Up @@ -293,6 +298,7 @@ class GameBoardActionTest {
val expectedModel = initModel.resetNextTurn(nextState)
val expectedEffects = buildSet {
add(WaitBeforeGameEnd(EndedWin(disk!!)))
add(PublishPastMoves(newState = nextState, gameEnd = EndedWin(disk)))
}

initModel after ContinueGame matches {
Expand Down Expand Up @@ -326,7 +332,8 @@ class GameBoardActionTest {

val expectedModel = initModel.resetNextTurn(nextState)
val expectedEffects = buildSet {
add(WaitBeforeGameEnd(EndedTie))
add(WaitBeforeGameEnd(result = EndedTie))
add(PublishPastMoves(newState = nextState, gameEnd = EndedTie))
}

initModel after ContinueGame matches {
Expand Down

0 comments on commit 2e35337

Please sign in to comment.