Added a unit test which helped to find a parantheses bug

This commit is contained in:
Gonk
2020-02-02 20:00:07 +01:00
parent 08e6f1be27
commit d9b8683e59
2 changed files with 35 additions and 2 deletions

View File

@@ -488,7 +488,7 @@ public final class CombatController implements VisualEffectCompletedCallback {
}
// see this post for explenations about the calculation: https://andorstrail.com/viewtopic.php?f=3&t=6661
private static float getAverageDamagePerHit(final Actor attacker, final Actor target) {
public static float getAverageDamagePerHit(final Actor attacker, final Actor target) {
final int numPossibleOutcomes = attacker.getDamagePotential().max - attacker.getDamagePotential().current + 1;
float avgNonCriticalDamage = 0;
for (int n = 0; n < numPossibleOutcomes; n++) {
@@ -502,7 +502,7 @@ public final class CombatController implements VisualEffectCompletedCallback {
}
if (effectiveCriticalChance > 0) {
for (int n = 0; n < numPossibleOutcomes; n++) {
avgCriticalDamage += max(0, (n + Math.floor(attacker.getDamagePotential().current) * attacker.getCriticalMultiplier()) - target.getDamageResistance()) / numPossibleOutcomes;
avgCriticalDamage += max(0, Math.floor((n + attacker.getDamagePotential().current) * attacker.getCriticalMultiplier()) - target.getDamageResistance()) / numPossibleOutcomes;
}
}

View File

@@ -0,0 +1,33 @@
package com.gpl.rpg.AndorsTrail.controller;
import com.gpl.rpg.AndorsTrail.model.actor.Actor;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Created by gonk on 02.02.2020.
*/
public class CombatControllerTest {
@Test
public void getAverageDamagePerHit() throws Exception {
Actor attacker = new Actor(null, false, false);
attacker.attackChance = 100;
attacker.damagePotential.set(5, 3);
Actor target = new Actor(null, false, false);
target.damageResistance = 3;
target.blockChance = 50;
float averageDamagePerHit = CombatController.getAverageDamagePerHit(attacker, target);
assertEquals(0.5, averageDamagePerHit, 0.01);
attacker.criticalSkill = 30;
attacker.criticalMultiplier = 2.5f;
averageDamagePerHit = CombatController.getAverageDamagePerHit(attacker, target);
assertEquals(1.038, averageDamagePerHit, 0.01);
}
}