Add support for Hp grow bonus and Leaning bonus.
This commit is contained in:
parent
3419afbe59
commit
ca20078ffa
18 changed files with 526 additions and 402 deletions
|
|
@ -6,43 +6,45 @@ class DamageBonusUseCaseTest {
|
|||
|
||||
@Test
|
||||
fun testBonusDamage() {
|
||||
val userCase = CharacterSheetUseCase()
|
||||
|
||||
(0 until 12).forEach {
|
||||
val result = DamageBonusUseCase.bonusDamage(stat = it)
|
||||
val result = userCase.defaultDamageBonus(sum = it)
|
||||
val expected = "-1d6"
|
||||
assert(result == expected) {
|
||||
"Expected:'$expected' bonus damage for stat:'$it' but was:'$result'"
|
||||
}
|
||||
}
|
||||
(12 until 18).forEach {
|
||||
val result = DamageBonusUseCase.bonusDamage(stat = it)
|
||||
val result = userCase.defaultDamageBonus(sum = it)
|
||||
val expected = "-1d4"
|
||||
assert(result == expected) {
|
||||
"Expected:'$expected' bonus damage for stat:'$it' but was:'$result'"
|
||||
}
|
||||
}
|
||||
(18 until 23).forEach {
|
||||
val result = DamageBonusUseCase.bonusDamage(stat = it)
|
||||
val result = userCase.defaultDamageBonus(sum = it)
|
||||
val expected = "+0"
|
||||
assert(result == expected) {
|
||||
"Expected:'$expected' bonus damage for stat:'$it' but was:'$result'"
|
||||
}
|
||||
}
|
||||
(23 until 30).forEach {
|
||||
val result = DamageBonusUseCase.bonusDamage(stat = it)
|
||||
val result = userCase.defaultDamageBonus(sum = it)
|
||||
val expected = "+1d4"
|
||||
assert(result == expected) {
|
||||
"Expected:'$expected' bonus damage for stat:'$it' but was:'$result'"
|
||||
}
|
||||
}
|
||||
(30 until 40).forEach {
|
||||
val result = DamageBonusUseCase.bonusDamage(stat = it)
|
||||
val result = userCase.defaultDamageBonus(sum = it)
|
||||
val expected = "+1d6"
|
||||
assert(result == expected) {
|
||||
"Expected:'$expected' bonus damage for stat:'$it' but was:'$result'"
|
||||
}
|
||||
}
|
||||
(40 until 100).forEach {
|
||||
val result = DamageBonusUseCase.bonusDamage(stat = it)
|
||||
val result = userCase.defaultDamageBonus(sum = it)
|
||||
val expected = "+2d6"
|
||||
assert(result == expected) {
|
||||
"Expected:'$expected' bonus damage for stat:'$it' but was:'$result'"
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import org.junit.Test
|
|||
class RollUseCaseTest {
|
||||
|
||||
companion object {
|
||||
private const val ROLL_COUNT = 1000000000
|
||||
private const val ROLL_COUNT = 100000000 // 100*10^6
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -20,16 +20,18 @@ class RollUseCaseTest {
|
|||
|
||||
@Test
|
||||
fun testRoll1D100_() {
|
||||
val result = build1D100ResultSet()
|
||||
val results = build1D100ResultSet()
|
||||
|
||||
val delta = 0.001f
|
||||
val delta = 0.005f
|
||||
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"
|
||||
results.map { it in median }.forEachIndexed { index, result ->
|
||||
assert(result) {
|
||||
"Maybe a false negative, we expected that all values should be in $median a result.\nroll amount: $ROLL_COUNT - index:$index result:${results[index]}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -37,7 +39,7 @@ class RollUseCaseTest {
|
|||
val useCase = RollUseCase()
|
||||
val result = MutableList(100) { 0 }
|
||||
repeat(count) {
|
||||
val roll = useCase.rollD100()
|
||||
val roll = useCase.roll(faces = 100)
|
||||
result[roll - 1] += 1
|
||||
}
|
||||
return result
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ class SkillNormalizerUseCaseText {
|
|||
|
||||
@Test
|
||||
fun testNormalization() {
|
||||
val useCase = SkillNormalizerUseCase()
|
||||
val useCase = CharacterSheetUseCase()
|
||||
|
||||
val samples = listOf(
|
||||
0 to 0,
|
||||
1 to 0,
|
||||
|
|
@ -19,6 +20,96 @@ class SkillNormalizerUseCaseText {
|
|||
8 to 5,
|
||||
9 to 5,
|
||||
10 to 10,
|
||||
11 to 10,
|
||||
12 to 10,
|
||||
13 to 10,
|
||||
14 to 10,
|
||||
15 to 15,
|
||||
16 to 15,
|
||||
17 to 15,
|
||||
18 to 15,
|
||||
19 to 15,
|
||||
20 to 20,
|
||||
21 to 20,
|
||||
22 to 20,
|
||||
23 to 20,
|
||||
24 to 20,
|
||||
25 to 25,
|
||||
26 to 25,
|
||||
27 to 25,
|
||||
28 to 25,
|
||||
29 to 25,
|
||||
30 to 30,
|
||||
31 to 30,
|
||||
32 to 30,
|
||||
33 to 30,
|
||||
34 to 30,
|
||||
35 to 35,
|
||||
36 to 35,
|
||||
37 to 35,
|
||||
38 to 35,
|
||||
39 to 35,
|
||||
40 to 40,
|
||||
41 to 40,
|
||||
42 to 40,
|
||||
43 to 40,
|
||||
44 to 40,
|
||||
45 to 45,
|
||||
46 to 45,
|
||||
47 to 45,
|
||||
48 to 45,
|
||||
49 to 45,
|
||||
50 to 50,
|
||||
51 to 50,
|
||||
52 to 50,
|
||||
53 to 50,
|
||||
54 to 50,
|
||||
55 to 55,
|
||||
56 to 55,
|
||||
57 to 55,
|
||||
58 to 55,
|
||||
59 to 55,
|
||||
60 to 60,
|
||||
61 to 60,
|
||||
62 to 60,
|
||||
63 to 60,
|
||||
64 to 60,
|
||||
65 to 65,
|
||||
66 to 65,
|
||||
67 to 65,
|
||||
68 to 65,
|
||||
69 to 65,
|
||||
70 to 70,
|
||||
71 to 70,
|
||||
72 to 70,
|
||||
73 to 70,
|
||||
74 to 70,
|
||||
75 to 75,
|
||||
76 to 75,
|
||||
77 to 75,
|
||||
78 to 75,
|
||||
79 to 75,
|
||||
80 to 80,
|
||||
81 to 80,
|
||||
82 to 80,
|
||||
83 to 80,
|
||||
84 to 80,
|
||||
85 to 85,
|
||||
86 to 85,
|
||||
87 to 85,
|
||||
88 to 85,
|
||||
89 to 85,
|
||||
90 to 90,
|
||||
91 to 90,
|
||||
92 to 90,
|
||||
93 to 90,
|
||||
94 to 90,
|
||||
95 to 95,
|
||||
96 to 95,
|
||||
97 to 95,
|
||||
98 to 95,
|
||||
99 to 95,
|
||||
100 to 100,
|
||||
)
|
||||
samples.forEach { (value, expected) ->
|
||||
assert(useCase.normalize(value) == expected) {
|
||||
|
|
|
|||
|
|
@ -7,8 +7,9 @@ class SkillStepUseCaseTest {
|
|||
|
||||
@Test
|
||||
fun testStepForSkill() {
|
||||
val useCase = SkillStepUseCase()
|
||||
(1..500).forEach { skill ->
|
||||
val step = SkillStepUseCase.computeSkillStep(
|
||||
val step = useCase.computeSkillStep(
|
||||
skill = skill,
|
||||
)
|
||||
val expected = expected[skill] ?: error(
|
||||
|
|
|
|||
|
|
@ -13,16 +13,16 @@ class InstructionParserTest {
|
|||
|
||||
fun test(
|
||||
instruction: String,
|
||||
expectedModifier: Instruction.Dice.Modifier.Dice.Modifier?,
|
||||
expectedModifier: Instruction.Dice.Modifier?,
|
||||
expectedQuantity: Int,
|
||||
expectedFaces: Int,
|
||||
) {
|
||||
val dice = parser.parseInstruction(instruction = instruction)
|
||||
val dice = parser.parse(value = instruction).first()
|
||||
|
||||
assert(dice is Instruction.Dice.Dice) {
|
||||
assert(dice is Instruction.Dice) {
|
||||
"Instruction should be ArithmeticInstruction.Dice but was: ${dice::class.java.simpleName}"
|
||||
}
|
||||
(dice as? Instruction.Dice.Dice)?.let {
|
||||
(dice as? Instruction.Dice)?.let {
|
||||
assert(dice.modifier == expectedModifier) {
|
||||
"$instruction modifier should be:\"$expectedModifier\", but was: ${dice.modifier}"
|
||||
}
|
||||
|
|
@ -66,14 +66,14 @@ class InstructionParserTest {
|
|||
val parser = ArithmeticParser()
|
||||
|
||||
ArithmeticParser.words.map { instruction ->
|
||||
val word = parser.parseInstruction(instruction = instruction)
|
||||
val word = parser.parse(value = instruction).first()
|
||||
|
||||
assert(word is Instruction.Word.Word) {
|
||||
assert(word is Instruction.Word) {
|
||||
"Instruction should be ArithmeticInstruction.Word but was: ${word::class.java.simpleName}"
|
||||
}
|
||||
(word as? Instruction.Word.Word)?.let {
|
||||
assert(it.name == instruction) {
|
||||
"Instruction should be $instruction, but was ${it.name}"
|
||||
(word as? Instruction.Word)?.let {
|
||||
assert(it.type.name == instruction) {
|
||||
"Instruction should be $instruction, but was ${it.type.name}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -84,12 +84,12 @@ class InstructionParserTest {
|
|||
val parser = ArithmeticParser()
|
||||
|
||||
"100".let { instruction ->
|
||||
val flat = parser.parseInstruction(instruction = instruction)
|
||||
val flat = parser.parse(value = instruction).first()
|
||||
|
||||
assert(flat is Instruction.Flat.Flat) {
|
||||
assert(flat is Instruction.Flat) {
|
||||
"Instruction should be ArithmeticInstruction.Flat but was: ${flat::class.java.simpleName}"
|
||||
}
|
||||
(flat as? Instruction.Flat.Flat)?.let {
|
||||
(flat as? Instruction.Flat)?.let {
|
||||
assert("${it.value}" == instruction) {
|
||||
"Instruction should be $instruction, but was ${it.value}"
|
||||
}
|
||||
|
|
@ -97,59 +97,42 @@ class InstructionParserTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testFailedInstructionParse() {
|
||||
val parser = ArithmeticParser()
|
||||
assertFails(
|
||||
message = "Instruction parse should failed with UnknownInstruction",
|
||||
) {
|
||||
parser.parseInstruction(instruction = "a110")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRollParse() {
|
||||
val parser = ArithmeticParser()
|
||||
|
||||
fun test(
|
||||
arithmetics: Instruction,
|
||||
expectedSign: Int,
|
||||
instruction: Instruction,
|
||||
expectedInstruction: Instruction,
|
||||
) {
|
||||
assert(arithmetics.sign == expectedSign) {
|
||||
"Arithmetic sign should be $expectedSign but was: ${arithmetics.sign}"
|
||||
}
|
||||
assert(arithmetics.instruction == expectedInstruction) {
|
||||
"Arithmetic instruction should be $expectedInstruction but was: ${arithmetics.instruction}"
|
||||
assert(instruction == expectedInstruction) {
|
||||
"Arithmetic instruction should be $expectedInstruction but was: $instruction"
|
||||
}
|
||||
}
|
||||
|
||||
val instructions = parser.parse(value = "1+1d6+2-BDC+BDD")
|
||||
val instructions = parser.parse(
|
||||
value = "1+1d6+2-BDC+BDD",
|
||||
)
|
||||
|
||||
test(
|
||||
arithmetics = instructions[0],
|
||||
expectedSign = 1,
|
||||
expectedInstruction = Instruction.Flat(value = 1),
|
||||
instruction = instructions[0],
|
||||
expectedInstruction = Instruction.Flat(sign = 1, value = 1),
|
||||
)
|
||||
test(
|
||||
arithmetics = instructions[1],
|
||||
expectedSign = 1,
|
||||
expectedInstruction = Instruction.Dice(quantity = 1, faces = 6, modifier = null),
|
||||
instruction = instructions[1],
|
||||
expectedInstruction = Instruction.Dice(sign = 1, modifier = null, quantity = 1, faces = 6),
|
||||
)
|
||||
test(
|
||||
arithmetics = instructions[2],
|
||||
expectedSign = 1,
|
||||
expectedInstruction = Instruction.Flat(value = 2),
|
||||
instruction = instructions[2],
|
||||
expectedInstruction = Instruction.Flat(sign = 1, value = 2),
|
||||
)
|
||||
test(
|
||||
arithmetics = instructions[3],
|
||||
expectedSign = -1,
|
||||
expectedInstruction = Instruction.Word.BDC,
|
||||
instruction = instructions[3],
|
||||
expectedInstruction = Instruction.Word(sign = -1, type = Instruction.Word.Type.BDC),
|
||||
)
|
||||
test(
|
||||
arithmetics = instructions[4],
|
||||
expectedSign = 1,
|
||||
expectedInstruction = Instruction.Word.BDD,
|
||||
instruction = instructions[4],
|
||||
expectedInstruction = Instruction.Word(sign = 1, type = Instruction.Word.Type.BDD),
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue