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

Commit

Permalink
Merge pull request #265 from MaximeZmt/margaux/refactor-score-and-man…
Browse files Browse the repository at this point in the history
…ager

margaux/refactor typing and local buzzer games
  • Loading branch information
zwierski authored May 12, 2022
2 parents 0a14ea4 + 5e27836 commit 49c3a7c
Show file tree
Hide file tree
Showing 23 changed files with 652 additions and 359 deletions.
47 changes: 39 additions & 8 deletions app/src/androidTest/java/ch/sdp/vibester/BuzzerScoreUpdaterTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ch.sdp.vibester

import junit.framework.Assert.assertEquals
import junit.framework.Assert.assertTrue
import org.junit.Test

Expand All @@ -24,29 +25,59 @@ public class BuzzerScoreUpdaterTest {
val scoreArray = arrayOf(0, 0, 0, 0)
val testUpdater = BuzzerScoreUpdater(idArray, scoreArray)
for (id in idArray) {
testUpdater.updateScoresArray(id, 1)
testUpdater.updateScoresArray(id, true)
assertTrue(testUpdater.getMap()[id] == 1)
}
}

@Test
fun getWinnerIdTest() {
fun arrayUpdateWithWrongIdReturns() {
val idArray = arrayListOf(R.id.buzzer_0, R.id.buzzer_1, R.id.buzzer_2, R.id.buzzer_3)
val scoreArray = arrayOf(0, 0, 0, 0)
val testUpdater = BuzzerScoreUpdater(idArray, scoreArray)
assertTrue(testUpdater.getWinnerId() == -1)
testUpdater.updateScoresArray(idArray[0], 1)
assertTrue(testUpdater.getWinnerId() == idArray[0])
testUpdater.updateScoresArray(-1, true)
for (id in idArray) {
assertEquals(0, testUpdater.getMap()[id])
}
}

@Test
fun arrayUpdateWithWrongIdReturns() {
fun penaltyOnScoreZeroMakesTheScoreRemainZero() {
val idArray = arrayListOf(R.id.buzzer_0, R.id.buzzer_1, R.id.buzzer_2, R.id.buzzer_3)
val scoreArray = arrayOf(0, 0, 0, 0)
val testUpdater = BuzzerScoreUpdater(idArray, scoreArray)
testUpdater.updateScoresArray(-1, 1)
for (id in idArray) {
assertTrue(testUpdater.getMap()[id]==0)
testUpdater.updateScoresArray(id, false)
assertEquals(0, testUpdater.getMap()[id])
}
}

@Test
fun noWinnerTest() {
val idArray = arrayListOf(R.id.buzzer_0, R.id.buzzer_1, R.id.buzzer_2, R.id.buzzer_3)
val scoreArray = arrayOf(0, 0, 0, 0)
val testUpdater = BuzzerScoreUpdater(idArray, scoreArray)
val testWinner = testUpdater.computeWinner()
assertEquals(0, testWinner.size)
}

@Test
fun oneWinnerTest() {
val idArray = arrayListOf(R.id.buzzer_0, R.id.buzzer_1, R.id.buzzer_2, R.id.buzzer_3)
val scoreArray = arrayOf(1, 0, 2, 0)
val testUpdater = BuzzerScoreUpdater(idArray, scoreArray)
val testWinner = testUpdater.computeWinner()
assertEquals(1, testWinner.size)
assertEquals(R.id.buzzer_2, testWinner.get(0))
}

@Test
fun moreThanOneWinnerTest() {
val idArray = arrayListOf(R.id.buzzer_0, R.id.buzzer_1, R.id.buzzer_2, R.id.buzzer_3)
val scoreArray = arrayOf(2, 1, 2, 0)
val testUpdater = BuzzerScoreUpdater(idArray, scoreArray)
val testWinner = testUpdater.computeWinner()
assertEquals(2, testWinner.size)
assertTrue(testWinner.contains(R.id.buzzer_0) && testWinner.contains(R.id.buzzer_2))
}
}
Loading

0 comments on commit 49c3a7c

Please sign in to comment.