This commit is contained in:
62
app/src/test/java/me/zobrist/tichucounter/TichuUnitTest.kt
Normal file
62
app/src/test/java/me/zobrist/tichucounter/TichuUnitTest.kt
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
package me.zobrist.tichucounter
|
||||||
|
|
||||||
|
import me.zobrist.tichucounter.domain.Round
|
||||||
|
import me.zobrist.tichucounter.domain.Tichu
|
||||||
|
import org.junit.Assert.*
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Example local unit test, which will execute on the development machine (host).
|
||||||
|
*
|
||||||
|
* See [testing documentation](http://d.android.com/tools/testing).
|
||||||
|
*/
|
||||||
|
class TichuUnitTest {
|
||||||
|
@Test
|
||||||
|
fun calculation_isCorrect() {
|
||||||
|
|
||||||
|
var inputScoreA = 125
|
||||||
|
var inputScoreB = -25
|
||||||
|
|
||||||
|
val tichu: Tichu = Tichu()
|
||||||
|
|
||||||
|
// Normal round range -25 to 125 as input
|
||||||
|
while (inputScoreB <= 125) {
|
||||||
|
assertGeneratedRound(tichu, inputScoreA, inputScoreB)
|
||||||
|
|
||||||
|
inputScoreA -= 5
|
||||||
|
inputScoreB += 5
|
||||||
|
}
|
||||||
|
|
||||||
|
// Double win
|
||||||
|
assertGeneratedRound(tichu, 200, 0)
|
||||||
|
|
||||||
|
// Double win with Tichu
|
||||||
|
assertGeneratedRound(tichu, 300, 0)
|
||||||
|
|
||||||
|
// Double win with Grand Tichu
|
||||||
|
assertGeneratedRound(tichu, 400, 0)
|
||||||
|
|
||||||
|
//Good rounds trough Tichu
|
||||||
|
assertValidRound(tichu, Round(0,0))
|
||||||
|
assertValidRound(tichu, Round(-100,0))
|
||||||
|
|
||||||
|
//Bad rounds
|
||||||
|
assertInvalidRound(tichu, Round(5, 12))
|
||||||
|
assertInvalidRound(tichu, Round(12, 5))
|
||||||
|
assertInvalidRound(tichu, Round(5, 55))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertGeneratedRound(tichu: Tichu, scoreA: Int, expectedScoreB: Int) {
|
||||||
|
val round = Round(scoreA, tichu.calculateOtherScore(scoreA))
|
||||||
|
assertEquals(expectedScoreB, round.scoreB)
|
||||||
|
assertTrue(tichu.isValidRound(round))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertInvalidRound(tichu: Tichu, round: Round) {
|
||||||
|
assertFalse(tichu.isValidRound(round))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun assertValidRound(tichu: Tichu, round: Round) {
|
||||||
|
assertTrue(tichu.isValidRound(round))
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user