-
Notifications
You must be signed in to change notification settings - Fork 0
Conversation
} | ||
setAnswerButton(answer, findViewById(R.id.buttonCorrect), updater, buzToScoreMap) | ||
setAnswerButton(answer, findViewById(R.id.buttonWrong), updater, buzToScoreMap) | ||
} |
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.
Similar blocks of code found in 2 locations. Consider refactoring.
setAnswerButton(answer, findViewById(R.id.buttonCorrect), updater, buzToScoreMap) | ||
setAnswerButton(answer, findViewById(R.id.buttonWrong), updater, buzToScoreMap) | ||
} | ||
|
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.
Similar blocks of code found in 2 locations. Consider refactoring.
import ch.sdp.vibester.R | ||
|
||
|
||
class GamescreenActivity: AppCompatActivity() { | ||
|
||
private val MAX_N_PLAYERS = 4 | ||
private val NO_BUZZER_PRESSED = -1 | ||
private val rowsIdArray = arrayOf(R.id.row_0, R.id.row_1, R.id.row_2, R.id.row_3) |
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.
Similar blocks of code found in 2 locations. Consider refactoring.
private val MAX_N_PLAYERS = 4 | ||
private val NO_BUZZER_PRESSED = -1 | ||
private val rowsIdArray = arrayOf(R.id.row_0, R.id.row_1, R.id.row_2, R.id.row_3) | ||
private val buzIds = arrayOf(R.id.buzzer_0, R.id.buzzer_1, R.id.buzzer_2, R.id.buzzer_3) |
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.
Similar blocks of code found in 2 locations. Consider refactoring.
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.
Would not really make sense to refactor, this is just declaration and initialisation of 2 arrays with values from the xml.
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.
Agreed. Worst case, if these buzzers and rows are the only children of the layout, can iterate over them and use getChild to set their values. Leaving the comment here in case we need to do so in the future.
@@ -6,25 +6,43 @@ import org.junit.Test | |||
|
|||
public class BuzzerScoreUpdaterTest { | |||
|
|||
// FIXME: Uncomment this when the infinite loop issue in the class is fixed |
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 it fixed? If so, maybe it's time to remove 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.
Looks good!
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.
Super happy that now the scores are stored! Nice work!
There is a problem with the use of assert in the testing, please take a look. Thanks!
} | ||
for (value in scoreArray) { | ||
assert(testUpdater.getMap().values.contains(value)) | ||
} |
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 was searching and I believe it is not correct to use java's assert in the test. Because in this case the java's exception will appear, not junit's exception. I would change assert on junit's assertTrue or assertEquals.
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.
Also here ExpectedMap is not used, so it can be deleted
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 point, I'll change this!
val testUpdater = BuzzerScoreUpdater(idArray, scoreArray) | ||
testUpdater.updateScoresArray(-1) | ||
for (id in idArray) { | ||
assert(testUpdater.getMap()[id]==0) |
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.
assert(testUpdater.getMap()[id]==0) | |
assertTrue(testUpdater.getMap()[id]==0) | |
val testUpdater = BuzzerScoreUpdater(idArray, scoreArray) | ||
for (id in idArray) { | ||
testUpdater.updateScoresArray(id) | ||
assert(testUpdater.getMap()[id]==1) |
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.
assert(testUpdater.getMap()[id]==1) | |
assertTrue(testUpdater.getMap()[id]==1) | |
private fun initMap(ids: Array<Int>, scores: Array<Int>): LinkedHashMap<Int, Int> { | ||
var theMap = LinkedHashMap<Int, Int>() | ||
var i = 0 | ||
while (i < min(ids.size, scores.size)) { |
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.
Why do you take min here? Should not both arrays be the same size?
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.
When I tried to perform a same size check and then use one of the sizes in the while loop, the app kept crashing, even though I only have cases where the scores are initialized according to the number of players (so should always be the same size). I used the min function as a quick fix for this, and I'll try to implement a proper check when refactoring.
if (!buzzerToScoreMap.keys.contains(id)) { | ||
return | ||
} | ||
val updatedScore = buzzerToScoreMap.getOrDefault(id, 0) + 1 // 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.
If the buzzer is initiated, there is no need for default, right?
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 tried using the "get" function: however, it returns an Int? which is not castable to Int, even with a null 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.
also here you can update the score in buzzer directly, like that:
buzzerToScoreMap[id]?.plus(1)
* checks first if the given id | ||
*/ | ||
fun updateScoresArray(id: Int) { | ||
if (!buzzerToScoreMap.keys.contains(id)) { |
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 check is needed as well? The array will be initialized with exactly entered number of ids, so there could not be a missing id in general... or am I missing something?
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.
This check ensures that no update will be attempted if the parameter is equal to NO_BUZZER_PRESSED (which should not happen but I still added a check just in case). I'll update the doc to make this clearer.
Code Climate has analyzed commit 4109b04 and detected 2 issues on this pull request. Here's the issue category breakdown:
The test coverage on the diff in this pull request is 82.6% (80% is the threshold). This pull request will bring the total coverage in the repository to 90.6%. View more on Code Climate. |
This PR contains the new class BuzzerScoreUpdater, which keeps track of a local game's scores and updates them when a user correctly guesses a song.