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

margaux/refactor typing and local buzzer games + tied scores managing #265

Merged
merged 43 commits into from
May 12, 2022

Conversation

zwierski
Copy link
Collaborator

@zwierski zwierski commented May 8, 2022

No description provided.

/* the array must be declared explicitly (and not with buzzersToRows.keys)
else the buzzers may not be ordered properly
*/
private val buzIds = arrayListOf(R.id.buzzer_0, R.id.buzzer_1, R.id.buzzer_2, R.id.buzzer_3)
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 2 locations. Consider refactoring.

@zwierski zwierski marked this pull request as ready for review May 11, 2022 20:11
assertTrue(testUpdater.getWinnerId() == idArray[0])
testUpdater.updateScoresArray(-1, true)
for (id in idArray) {
assertTrue(testUpdater.getMap()[id]==0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

for readability add space on both sides of "=="

val testWinner = testUpdater.computeWinner()
assertTrue(testWinner.size==2)
assertTrue(testWinner.contains(R.id.buzzer_0) && testWinner.contains(R.id.buzzer_2))
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

same in these tests, add spaces for readability

onView(withId(R.id.nb_players_selected)).check(matches(withEffectiveVisibility(Visibility.INVISIBLE)))
onView(withId(R.id.missingNameAlert)).check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

// click on "OK" button in alert => check alert disappears and next button reappears
Copy link
Collaborator

Choose a reason for hiding this comment

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

Like the comments here, good job 👍

@@ -175,7 +175,7 @@ class TypingGameActivityTest {

val intent =
Intent(ApplicationProvider.getApplicationContext(), TypingGameActivity::class.java)
// Do not put gameManager as an extra
// Do not put gameManager as an extra: it causes a RuntimeException
Copy link
Collaborator

Choose a reason for hiding this comment

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

good that you added an explanation

if (gameManager.playingMediaPlayer()) {
gameManager.stopMediaPlayer()
}
checkAnswer(ctx, null, gameManager)
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe add a comment what null means here

@@ -49,8 +49,8 @@ class GameEndingActivity : AppCompatActivity() {
if (intent.hasExtra("Winner Name")) {
val winner = intent.getStringExtra("Winner Name")
if (winner!=null) {
findViewById<TextView>(R.id.winnerText).text="And the winner is... $winner!"
} else {findViewById<TextView>(R.id.winnerText).text="Nobody won this game!"}
findViewById<TextView>(R.id.winnerText).text=winner
Copy link
Collaborator

Choose a reason for hiding this comment

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

just minor readability things here with "=="

*/
open class GameManager : Serializable {
private var score = 0
private var score = 0 // we can yeet this and use the size of the correct song list instead
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo "yeet"?

Copy link
Collaborator Author

@zwierski zwierski May 11, 2022

Choose a reason for hiding this comment

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

That was a typo haha, fixed it and added to the comment

Copy link
Collaborator

@laurislopata laurislopata left a comment

Choose a reason for hiding this comment

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

Really nice work, added some small comments that will help with readability, if you take a look at them I'll approve :)

Copy link
Collaborator

@laurislopata laurislopata left a comment

Choose a reason for hiding this comment

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

LGTM

@MaximeZmt MaximeZmt self-requested a review May 12, 2022 08:22
Copy link
Owner

@MaximeZmt MaximeZmt left a comment

Choose a reason for hiding this comment

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

Good Work 👍 Here are some comments :)

assertTrue(testUpdater.getWinnerId() == idArray[0])
testUpdater.updateScoresArray(-1, true)
for (id in idArray) {
assertTrue(testUpdater.getMap()[id] == 0)
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
assertTrue(testUpdater.getMap()[id] == 0)
assertEquals(0, testUpdater.getMap()[id])

It is maybe more precise to use assertEqual.
Indeed if there is an error, it will be able to say: Value received, Value Expected.
Whereas in your case it will just say, received false whereas expecting true

for (id in idArray) {
assertTrue(testUpdater.getMap()[id]==0)
testUpdater.updateScoresArray(id, false)
assertTrue(testUpdater.getMap()[id] == 0)
Copy link
Owner

Choose a reason for hiding this comment

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

same as above

val scoreArray = arrayOf(0, 0, 0, 0)
val testUpdater = BuzzerScoreUpdater(idArray, scoreArray)
val testWinner = testUpdater.computeWinner()
assertTrue(testWinner.size == 0)
Copy link
Owner

Choose a reason for hiding this comment

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

same

Comment on lines 69 to 70
assertTrue(testWinner.size == 1)
assertTrue(testWinner.get(0) == R.id.buzzer_2)
Copy link
Owner

Choose a reason for hiding this comment

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

same

Comment on lines 79 to 80
assertTrue(testWinner.size == 2)
assertTrue(testWinner.contains(R.id.buzzer_0) && testWinner.contains(R.id.buzzer_2))
Copy link
Owner

Choose a reason for hiding this comment

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

same

val scn: ActivityScenario<TypingGameActivity> = ActivityScenario.launch(intent)
val ctx = ApplicationProvider.getApplicationContext() as Context
createMockDataGetter()
createMockAuthenticator()
scn.onActivity { activity ->
activity.checkAnswer(ctx, songTest, gameManager)
}
assertEquals(true, gameManager.getScore() == 0)
assertEquals(true, gameManager.getCorrectSongs().size == 0)
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
assertEquals(true, gameManager.getCorrectSongs().size == 0)
assertEquals(0, gameManager.getCorrectSongs().size)

Maybe simpler and easier to read

button.text = pName
button.width = 100
button.height = 0
button.visibility=View.VISIBLE
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
button.visibility=View.VISIBLE
button.visibility = View.VISIBLE

setPressed(button.id)
if (findViewById<ProgressBar>(R.id.progressBarBuzzer).progress>0 && findViewById<Button>(R.id.nextSongBuzzer).visibility==View.GONE) {
answer.visibility = android.view.View.VISIBLE
findViewById<Button>(R.id.go_to_end).visibility=View.INVISIBLE
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
findViewById<Button>(R.id.go_to_end).visibility=View.INVISIBLE
findViewById<Button>(R.id.go_to_end).visibility = View.INVISIBLE

val view = map[pressedBuzzer]?.let { it1 -> findViewById<TextView>(it1) }
if (view != null && updater.getMap().keys.contains(pressedBuzzer)) {view.text=updater.getMap()[pressedBuzzer].toString()}
if (view != null && scoreUpdater.getMap().keys.contains(pressedBuzzer)) {view.text=scoreUpdater.getMap()[pressedBuzzer].toString()}
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
if (view != null && scoreUpdater.getMap().keys.contains(pressedBuzzer)) {view.text=scoreUpdater.getMap()[pressedBuzzer].toString()}
if (view != null && scoreUpdater.getMap().keys.contains(pressedBuzzer)) {
view.text = scoreUpdater.getMap()[pressedBuzzer].toString()
}

Copy link
Owner

Choose a reason for hiding this comment

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

will even improve coverage as tested code

Copy link
Owner

@MaximeZmt MaximeZmt left a comment

Choose a reason for hiding this comment

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

👍

@codeclimate
Copy link

codeclimate bot commented May 12, 2022

Code Climate has analyzed commit 5e27836 and detected 4 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 2
Duplication 2

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

This pull request will bring the total coverage in the repository to 80.1%.

View more on Code Climate.

@zwierski zwierski merged commit 49c3a7c into main May 12, 2022
@zwierski zwierski deleted the margaux/refactor-score-and-manager branch May 12, 2022 14:35
@zwierski zwierski self-assigned this May 12, 2022
@zwierski zwierski changed the title margaux/refactor typing and local buzzer games margaux/refactor typing and local buzzer games + tied scores managing May 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants