Update the app with some features skeleton.

Change the navigation system
Add a basic file system management to save the charactersheet.
Add a common source code directory & commonTest module.
Add test to the business class.
This commit is contained in:
Thomas Andres Gomez 2024-11-04 23:33:11 +01:00
parent d74a5fcd7c
commit 65aa53890f
34 changed files with 1412 additions and 541 deletions

View file

@ -0,0 +1,44 @@
package com.pixelized.desktop.lwa.business
import org.junit.Test
class RollUseCaseTest {
companion object {
private const val ROLL_COUNT = 1000000000
}
@Test
fun testRoll1D100() {
val result = build1D100ResultSet()
println("Testing if with $ROLL_COUNT rolls we have at least 1 result of each value.")
assert(result.all { it > 0 }) {
"Maybe a false negative, we expected that all values should have a result.\nroll amount: $ROLL_COUNT - result:$result"
}
}
@Test
fun testRoll1D100_() {
val result = build1D100ResultSet()
val delta = 0.001f
val median = (ROLL_COUNT / 100).let {
(it * (1f - delta)).toInt()..(it * (1f + delta)).toInt()
}
println("Testing if with $ROLL_COUNT rolls we have at least all results in $median.")
assert(result.all { it in median }) {
"Maybe a false negative, we expected that all values should be in $median a result.\nroll amount: $ROLL_COUNT - result:$result"
}
}
private fun build1D100ResultSet(count: Int = ROLL_COUNT): List<Int> {
val result = MutableList(100) { 0 }
repeat(count) {
val roll = RollUseCase.rollD100()
result[roll - 1] += 1
}
return result
}
}

View file

@ -0,0 +1,29 @@
package com.pixelized.desktop.lwa.business
import com.pixelized.desktop.lwa.business.SkillNormalizerUseCase.normalize
import org.junit.Test
class SkillNormalizerUseCaseText {
@Test
fun testNormalization() {
val samples = listOf(
0 to 0,
1 to 0,
2 to 0,
3 to 0,
4 to 0,
5 to 5,
6 to 5,
7 to 5,
8 to 5,
9 to 5,
10 to 10,
)
samples.forEach { (value, expected) ->
assert(normalize(value) == expected) {
"$value should be normalized to $expected"
}
}
}
}

View file

@ -0,0 +1,180 @@
package com.pixelized.desktop.lwa.business
import org.junit.Test
class SkillStepUseCaseTest {
companion object {
val EXPECTED = hashMapOf(
0 to listOf(-1..-1, 1..1, 2..5, 6..95, 96..100),
5 to listOf(-1..-1, 1..1, 2..5, 6..95, 96..100),
10 to listOf(1..1, 2..2, 3..10, 11..95, 96..100),
15 to listOf(1..1, 2..3, 4..15, 16..96, 97..100),
20 to listOf(1..1, 2..4, 5..20, 21..96, 97..100),
25 to listOf(1..1, 2..5, 6..25, 26..96, 97..100),
30 to listOf(1..2, 3..6, 7..30, 31..96, 97..100),
35 to listOf(1..2, 3..7, 8..35, 36..97, 98..100),
40 to listOf(1..2, 3..8, 9..40, 41..97, 98..100),
45 to listOf(1..2, 3..9, 10..45, 46..97, 98..100),
50 to listOf(1..3, 4..10, 11..50, 51..97, 98..100),
55 to listOf(1..3, 4..11, 12..55, 56..98, 99..100),
60 to listOf(1..3, 4..12, 13..60, 61..98, 99..100),
65 to listOf(1..3, 4..13, 14..65, 66..98, 99..100),
70 to listOf(1..4, 5..14, 15..70, 71..98, 99..100),
75 to listOf(1..4, 5..15, 16..75, 76..99, 100..100),
80 to listOf(1..4, 5..16, 17..80, 81..99, 100..100),
85 to listOf(1..4, 5..17, 18..85, 86..99, 100..100),
90 to listOf(1..5, 6..18, 19..90, 91..99, 100..100),
95 to listOf(1..5, 6..19, 20..95, 96..99, 100..100),
100 to listOf(1..5, 6..20, 21..99, -1..-1, 100..100),
)
}
@Test
fun testStepForSkillAt_0() {
testStepForSkillStep(skill = 0)
}
@Test
fun testStepForSkillAt_5() {
testStepForSkillStep(skill = 5)
}
@Test
fun testStepForSkillAt10() {
testStepForSkillStep(skill = 10)
}
@Test
fun testStepForSkillAt15() {
testStepForSkillStep(skill = 15)
}
@Test
fun testStepForSkillAt20() {
testStepForSkillStep(skill = 20)
}
@Test
fun testStepForSkillAt25() {
testStepForSkillStep(skill = 25)
}
@Test
fun testStepForSkillAt30() {
testStepForSkillStep(skill = 30)
}
@Test
fun testStepForSkillAt35() {
testStepForSkillStep(skill = 35)
}
@Test
fun testStepForSkillAt40() {
testStepForSkillStep(skill = 40)
}
@Test
fun testStepForSkillAt45() {
testStepForSkillStep(skill = 45)
}
@Test
fun testStepForSkillAt50() {
testStepForSkillStep(skill = 50)
}
@Test
fun testStepForSkillAt55() {
testStepForSkillStep(skill = 55)
}
@Test
fun testStepForSkillAt60() {
testStepForSkillStep(skill = 60)
}
@Test
fun testStepForSkillAt65() {
testStepForSkillStep(skill = 65)
}
@Test
fun testStepForSkillAt70() {
testStepForSkillStep(skill = 70)
}
@Test
fun testStepForSkillAt75() {
testStepForSkillStep(skill = 75)
}
@Test
fun testStepForSkillAt80() {
testStepForSkillStep(skill = 80)
}
@Test
fun testStepForSkillAt85() {
testStepForSkillStep(skill = 85)
}
@Test
fun testStepForSkillAt90() {
testStepForSkillStep(skill = 90)
}
@Test
fun testStepForSkillAt95() {
testStepForSkillStep(skill = 95)
}
@Test
fun testStepForSkillAt100() {
testStepForSkillStep(skill = 100)
}
@Test
fun testStepForSkillAbove100() {
val levels = List(50) { 100 + it * 5 }
levels.forEach { skillLevel ->
testStepForSkillStep(
skill = skillLevel,
expectedCriticalSuccessRange = 1..(skillLevel * 5 / 100),
expectedSpecialSuccessRange = (skillLevel * 5 / 100 + 1)..(skillLevel * 20 / 100),
expectedSuccessRange = (skillLevel * 20 / 100 + 1)..99,
expectedFailureRange = -1..-1,
expectedCriticalFailureRange = 100..100,
)
}
}
private fun testStepForSkillStep(
skill: Int,
expectedCriticalSuccessRange: IntRange = EXPECTED[skill]!![0],
expectedSpecialSuccessRange: IntRange = EXPECTED[skill]!![1],
expectedSuccessRange: IntRange = EXPECTED[skill]!![2],
expectedFailureRange: IntRange = EXPECTED[skill]!![3],
expectedCriticalFailureRange: IntRange = EXPECTED[skill]!![4],
) {
val step = SkillStepUseCase.computeSkillStep(skill = skill)
assert(step.criticalSuccessRange == expectedCriticalSuccessRange) {
"Skill level $skill - Critical success range should be $expectedCriticalSuccessRange bu was ${step.criticalSuccessRange}"
}
assert(step.specialSuccessRange == expectedSpecialSuccessRange) {
"Skill level $skill - Special success range should be $expectedSpecialSuccessRange bu was ${step.specialSuccessRange}"
}
assert(step.successRange == expectedSuccessRange) {
"Skill level $skill - Success range should be $expectedSuccessRange bu was ${step.successRange}"
}
assert(step.failureRange == expectedFailureRange) {
"Skill level $skill - failure range should be $expectedFailureRange bu was ${step.failureRange}"
}
assert(step.criticalFailureRange == expectedCriticalFailureRange) {
"Skill level $skill - Critical failure range should be $expectedCriticalFailureRange bu was ${step.criticalFailureRange}"
}
}
}