-
Notifications
You must be signed in to change notification settings - Fork 0
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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]!!) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>) { |
There was a problem hiding this comment.
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()} | ||
} |
There was a problem hiding this comment.
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)) | ||
} | ||
|
||
*/ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 😅
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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. |
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.