Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Basics: Viewmodel and State in Compose #23

Closed
myhency opened this issue Nov 16, 2022 · 5 comments
Closed

Android Basics: Viewmodel and State in Compose #23

myhency opened this issue Nov 16, 2022 · 5 comments
Assignees

Comments

@myhency
Copy link

myhency commented Nov 16, 2022

@Test
fun gameViewModel_Initialization_FirstWordLoaded() {
    val gameUiState = viewModel.uiState.value
    val unScrambledWord = getUnscrambledWord(gameUiState.currentScrambledWord)

    // Assert that current word is scrambled.
    assertNotEquals(unScrambledWord, gameUiState.currentScrambledWord)
    // Assert that current word count is set to 1.
    assertTrue(gameUiState.currentWordCount == 1)
    // Assert that initially the score is 0.
    assertTrue(gameUiState.score == 0)
    // Assert that the wrong word guessed is false.
    assertFalse(gameUiState.isGuessedWordWrong)
    // Assert that game is not over.
    assertFalse(gameUiState.isGameOver)
}

At the first time the app initialized, currentWordCount should be 0 not 1. Am I wrong?

@tugceaktepe
Copy link

Yes, you're right. I spotted it, too. Because init block in GameViewModel calls resetGame(). In this function, a new instance of GameUiState with shuffled word is created for _uiState. So, currentWordCount takes default value, 0. I'm sure this mistake will be fixed, soon.

@AAB999
Copy link

AAB999 commented Jan 21, 2023

No, it is not fixed yet.... i just encountered the same issue while testing, and found the solution also by myself and thinking, maybe this fault is on purpose to test our understanding of the function because it is so easy to see?... :-)

@android-dev-lxl
Copy link
Collaborator

@tugceaktepe
@AAB999
@myhency

Could you please check now.
This should have been fixed!

@android-dev-lxl android-dev-lxl pinned this issue Feb 13, 2023
@android-dev-lxl android-dev-lxl self-assigned this Feb 13, 2023
@enikebraimoh
Copy link

enikebraimoh commented Mar 30, 2023

@android-dev-lxl this has not been fixed on the Codelab it still states
val currentWordCount: Int = 0, val score: Int = 1,
when the object is created, currentWordCount should be 1 and score should be 0

@osuleymanova
Copy link
Contributor

Hello @enikebraimoh,

Thank you for reaching out to us. The typo is fixed:

Screenshot 2023-05-31 at 4 14 51 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants