You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey developers, On facing an issue in the code this might be the solution,
var currentGameUiState = viewModel.uiState.value
val correctPlayerWord = getUnscrambledWord(currentGameUiState.currentScrambledWord)
The currentGameUiState.currentScrambledWord is generated by the gameViewModel for example : "omeehmda"
getUnscrambledWord method is from test/.../data file where it maps the wordLength from allWords set and give you the value. Here the currentGameUiState.currentScrambledWord length is 8 and the getUnscrambledWord maps it and gives you an 8 Length word which is for example: birthday from test/../data file
The gameViewModel code is right, So the currentGameUiState.isGuessedWordWrong is true which is given by the gameViewModel.
currentGameUiState = viewModel.uiState.value
// Assert that checkUserGuess() method updates isGuessedWordWrong is updated correctly.
assertFalse(currentGameUiState.isGuessedWordWrong)
// Assert that score is updated correctly.
assertEquals(SCORE_AFTER_FIRST_CORRECT_ANSWER, currentGameUiState.score)
Here what is the point of using assertFalse where the currentGameUiState.isGuessedWordWrong is true and ends
up with assertionError and assertEquals also fails because correctPlayerWord is not true and the score wouldn't be increased.
To fix the code
assertTrue(currentGameUiState.isGuessedWordWrong)
// Assert that score is updated correctly
assertEquals(Wrong_Answer, currentGameUiState.Score)
companion object {
private const val SCORE_AFTER_FIRST_CORRECT_ANSWER = SCORE_INCREASE
private const val Worng_Answr= Wrong_Answer
}
}
The text was updated successfully, but these errors were encountered:
Test Strategy for Success path
https://developer.android.com/codelabs/basic-android-kotlin-compose-test-viewmodel?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-4-pathway-1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-test-viewmodel#3
Hey developers, On facing an issue in the code this might be the solution,
var currentGameUiState = viewModel.uiState.value
val correctPlayerWord = getUnscrambledWord(currentGameUiState.currentScrambledWord)
The currentGameUiState.currentScrambledWord is generated by the gameViewModel for example : "omeehmda"
getUnscrambledWord method is from test/.../data file where it maps the wordLength from allWords set and give you the value. Here the currentGameUiState.currentScrambledWord length is 8 and the getUnscrambledWord maps it and gives you an 8 Length word which is for example: birthday from test/../data file
The gameViewModel code is right, So the currentGameUiState.isGuessedWordWrong is true which is given by the gameViewModel.
currentGameUiState = viewModel.uiState.value
// Assert that checkUserGuess() method updates isGuessedWordWrong is updated correctly.
assertFalse(currentGameUiState.isGuessedWordWrong)
// Assert that score is updated correctly.
assertEquals(SCORE_AFTER_FIRST_CORRECT_ANSWER, currentGameUiState.score)
Here what is the point of using assertFalse where the currentGameUiState.isGuessedWordWrong is true and ends
up with assertionError and assertEquals also fails because correctPlayerWord is not true and the score wouldn't be increased.
To fix the code
assertTrue(currentGameUiState.isGuessedWordWrong)
// Assert that score is updated correctly
assertEquals(Wrong_Answer, currentGameUiState.Score)
companion object {
private const val SCORE_AFTER_FIRST_CORRECT_ANSWER = SCORE_INCREASE
private const val Worng_Answr= Wrong_Answer
}
}
The text was updated successfully, but these errors were encountered: