Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Margaux/name check #152

Merged
merged 16 commits into from
Apr 7, 2022
Merged

Margaux/name check #152

merged 16 commits into from
Apr 7, 2022

Conversation

zwierski
Copy link
Collaborator

@zwierski zwierski commented Apr 6, 2022

This PR adds to the BuzzerSetupScreen a check that a name has been entered for every player: if one or more text fields are left empty, an alert appears upon clicking on proceed.

missing_player_alert

@zwierski zwierski marked this pull request as ready for review April 7, 2022 16:47
Copy link
Collaborator

@kamilababayeva kamilababayeva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I have tried the changes on the app, works like a charm. I have added few comments. I believe we should be able to test some pieces of the code.

@@ -24,15 +27,31 @@ class BuzzerScoreUpdater(ids: ArrayList<Int>, scores: Array<Int>) {
return buzzerToScoreMap
}

fun getWinnerId(): Int {
return winnerId
Copy link
Collaborator

@kamilababayeva kamilababayeva Apr 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codeclimate shows this line is not tested. This return should not be hard to test, right? Just calling the function and comparing the result to the actual value?

if (!buzzerToScoreMap.keys.contains(id)) {
return
}
val updatedScore = buzzerToScoreMap.getOrDefault(id, 0) + 1 // should never get to default,
val updatedScore = max(buzzerToScoreMap.getOrDefault(id, 0) + point, 0) // should never get to default
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you put max considering that the score can be negative or what was the reason?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I added a functionality that gives the player a -1 penalty if they buzz and guess wrong (instead of keeping their score unchanged). If they guess wrong when their score is 0, the score should not become negative.

* @param potentialWinnerScore: that player's new score
*/
private fun updateWinner(potentialWinnerId: Int, potentialWinnerScore: Int) {
if (winnerId<0 || potentialWinnerScore> buzzerToScoreMap[winnerId]!!) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (winnerId<0 || potentialWinnerScore> buzzerToScoreMap[winnerId]!!) {
if (winnerId < 0 || potentialWinnerScore > buzzerToScoreMap[winnerId]!!) {

Sorry hahah, this was hard to read, did not want to be mean

@@ -144,13 +145,15 @@ class BuzzerScreenActivity : AppCompatActivity() {
private fun setAnswerButton(answer: LinearLayout, button: Button, updater: BuzzerScoreUpdater, map: Map<Int, Int>) {
button.setOnClickListener {
answer.visibility = android.view.View.INVISIBLE
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
answer.visibility = android.view.View.INVISIBLE
answer.visibility = View.INVISIBLE

@@ -144,13 +145,15 @@ class BuzzerScreenActivity : AppCompatActivity() {
private fun setAnswerButton(answer: LinearLayout, button: Button, updater: BuzzerScoreUpdater, map: Map<Int, Int>) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map is buzzersToRows in this function. BuzzersToRows is global in BuzzerScreenActivity class, so it is accessible in this function without passing it as a parameter. Do you think it is better if we remove map from here as a parameter and will access buzzerToRows inside the function?

winnerId = updater.getWinnerId()
} else {updater.updateScoresArray(pressedBuzzer, -1)}
val view = map[pressedBuzzer]?.let { it1 -> findViewById<TextView>(it1) }
if (view != null && updater.getMap().keys.contains(pressedBuzzer)) {view.text=updater.getMap()[pressedBuzzer].toString()}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this piece of code hard to test? You assign listener in onCreate, so if you do button.preform.click(), this code should be testable, no?

onView(withId(R.id.nb_players_selected)).perform(click())
intended(hasComponent(BuzzerScreenActivity::class.java.name))
intended(hasExtra("Number of players", 4))
}

*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happened with this test? Other three works and this one no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this one always fails for some reason while the other three always pass.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried these tests myself, it worked in my android!

Copy link
Collaborator

@jiabaow jiabaow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!
I left some comments but they are mostly related to formatting issues

@@ -86,7 +91,11 @@ class BuzzerSetupActivity : AppCompatActivity(), AdapterView.OnItemSelectedListe
arrayOf(R.id.namePlayer1, R.id.namePlayer2, R.id.namePlayer3, R.id.namePlayer4)
var i = 0
for (playerView in players) {
pNameArray[i] = findViewById<EditText>(editTextIdArray[i]).text.toString()
val name = findViewById<EditText>(editTextIdArray[i]).text.toString()
if (name.isNotEmpty()) { pNameArray[i] = name } else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a particular reason why the if-else is formatted like this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was to remain under 25 lines of code for the function for the CodeClimate check 😅

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah okkkk, in this case, create a separate function then make a call to it would be a solution too

if (intent.hasExtra("Winner Name")) {
val winner = intent.getStringExtra("Winner Name")
/*
if (winner!=null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest either removing the commented code or adding a fixme explanation


/*
fun hideWinnerPanel(view: View) {
findViewById<TextView>(R.id.winnerPanel).visibility=View.INVISIBLE
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

*/
private fun enterNames(n: Int) {
var i = 0
while (i < n) { onView(withId(editTextIdArray[i])).perform(typeText(mockArray[i]), closeSoftKeyboard())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe move the onView... to a new line for better readability

Copy link
Collaborator

@jiabaow jiabaow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@codeclimate
Copy link

codeclimate bot commented Apr 7, 2022

Code Climate has analyzed commit 70bb71d and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 75.0% (80% is the threshold).

This pull request will bring the total coverage in the repository to 91.2% (0.0% change).

View more on Code Climate.

@zwierski zwierski merged commit 47f480e into main Apr 7, 2022
@zwierski zwierski deleted the margaux/local-game-refactor branch April 7, 2022 21:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor local multiplayer game (default names, sanitization checks, connect winner name to ending screen).
3 participants