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
|
|
@ -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