mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
tests: improved testable dialogs (added source code ref in result table for better IDE navigation, part of #13643, #13638);
This commit is contained in:
parent
4f8eb30e4c
commit
d893d52190
21 changed files with 127 additions and 49 deletions
|
|
@ -11,8 +11,8 @@ public class AmountTestableResult extends BaseTestableResult {
|
|||
|
||||
int amount = 0;
|
||||
|
||||
public void onFinish(boolean status, List<String> info, int amount) {
|
||||
this.onFinish(status, info);
|
||||
public void onFinish(String resDebugSource, boolean status, List<String> info, int amount) {
|
||||
this.onFinish(resDebugSource, status, info);
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package mage.utils.testers;
|
|||
import mage.abilities.Ability;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.util.DebugUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -37,12 +38,12 @@ class AnnounceXTestableDialog extends BaseTestableDialog {
|
|||
public void showDialog(Player player, Ability source, Game game, Player opponent) {
|
||||
Player choosingPlayer = this.isYou ? player : opponent;
|
||||
String message = "<font color=green>message</font> with html";
|
||||
int chooseRes;
|
||||
chooseRes = choosingPlayer.announceX(this.min, this.max, message, game, source, this.isMana);
|
||||
String chooseDebugSource = DebugUtil.getMethodNameWithSource(0, "class");
|
||||
int chooseRes = choosingPlayer.announceX(this.min, this.max, message, game, source, this.isMana);
|
||||
List<String> res = new ArrayList<>();
|
||||
res.add(getGroup() + " - " + this.getName() + " selected " + chooseRes);
|
||||
|
||||
((AmountTestableResult) this.getResult()).onFinish(true, res, chooseRes);
|
||||
((AmountTestableResult) this.getResult()).onFinish(chooseDebugSource, true, res, chooseRes);
|
||||
}
|
||||
|
||||
static public void register(TestableDialogsRunner runner) {
|
||||
|
|
|
|||
|
|
@ -11,9 +11,15 @@ import java.util.List;
|
|||
public class BaseTestableResult implements TestableResult {
|
||||
|
||||
boolean isFinished = false;
|
||||
String resDebugSource = ""; // source code line to find starting place to debug
|
||||
boolean resStatus = false;
|
||||
List<String> resInfo = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public String getResDebugSource() {
|
||||
return this.resDebugSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getResStatus() {
|
||||
return this.resStatus;
|
||||
|
|
@ -30,8 +36,9 @@ public class BaseTestableResult implements TestableResult {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onFinish(boolean resStatus, List<String> resDetails) {
|
||||
public void onFinish(String resDebugSource, boolean resStatus, List<String> resDetails) {
|
||||
this.isFinished = true;
|
||||
this.resDebugSource = resDebugSource;
|
||||
this.resStatus = resStatus;
|
||||
this.resInfo = resDetails;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ public class ChoiceTestableResult extends BaseTestableResult {
|
|||
|
||||
String choice = null;
|
||||
|
||||
public void onFinish(boolean status, List<String> info, String choice) {
|
||||
this.onFinish(status, info);
|
||||
public void onFinish(String resDebugSource, boolean status, List<String> info, String choice) {
|
||||
this.onFinish(resDebugSource, status, info);
|
||||
this.choice = choice;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import mage.players.Player;
|
|||
import mage.target.TargetAmount;
|
||||
import mage.target.Targets;
|
||||
import mage.target.common.TargetAnyTargetAmount;
|
||||
import mage.util.DebugUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -46,6 +47,7 @@ class ChooseAmountTestableDialog extends BaseTestableDialog {
|
|||
Player choosingPlayer = this.isYou ? player : opponent;
|
||||
|
||||
// TODO: add "damage" word in ability text, so chooseTargetAmount an show diff dialog (due inner logic - distribute damage or 1/1)
|
||||
String chooseDebugSource = DebugUtil.getMethodNameWithSource(0, "class");
|
||||
boolean chooseRes = choosingPlayer.chooseTargetAmount(Outcome.Benefit, choosingTarget, source, game);
|
||||
List<String> res = new ArrayList<>();
|
||||
if (chooseRes) {
|
||||
|
|
@ -54,7 +56,7 @@ class ChooseAmountTestableDialog extends BaseTestableDialog {
|
|||
Targets.printDebugTargets(getGroup() + " - " + this.getName() + " - " + "FALSE", new Targets(choosingTarget), source, game, res);
|
||||
}
|
||||
|
||||
((TargetTestableResult) this.getResult()).onFinish(chooseRes, res, choosingTarget);
|
||||
((TargetTestableResult) this.getResult()).onFinish(chooseDebugSource, chooseRes, res, choosingTarget);
|
||||
}
|
||||
|
||||
static public void register(TestableDialogsRunner runner) {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import mage.players.Player;
|
|||
import mage.target.TargetCard;
|
||||
import mage.target.Targets;
|
||||
import mage.target.common.TargetCardInHand;
|
||||
import mage.util.DebugUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -57,9 +58,12 @@ class ChooseCardsTestableDialog extends BaseTestableDialog {
|
|||
Cards choosingCards = new CardsImpl(all.stream().limit(100).collect(Collectors.toList()));
|
||||
|
||||
boolean chooseRes;
|
||||
String chooseDebugSource;
|
||||
if (this.isTargetChoice) {
|
||||
chooseDebugSource = DebugUtil.getMethodNameWithSource(0, "class");
|
||||
chooseRes = choosingPlayer.chooseTarget(Outcome.Benefit, choosingCards, choosingTarget, source, game);
|
||||
} else {
|
||||
chooseDebugSource = DebugUtil.getMethodNameWithSource(0, "class");
|
||||
chooseRes = choosingPlayer.choose(Outcome.Benefit, choosingCards, choosingTarget, source, game);
|
||||
}
|
||||
|
||||
|
|
@ -70,7 +74,7 @@ class ChooseCardsTestableDialog extends BaseTestableDialog {
|
|||
Targets.printDebugTargets(getGroup() + " - " + this.getName() + " - " + "FALSE", new Targets(choosingTarget), source, game, res);
|
||||
}
|
||||
|
||||
((TargetTestableResult) this.getResult()).onFinish(chooseRes, res, choosingTarget);
|
||||
((TargetTestableResult) this.getResult()).onFinish(chooseDebugSource, chooseRes, res, choosingTarget);
|
||||
}
|
||||
|
||||
static public void register(TestableDialogsRunner runner) {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import mage.choices.*;
|
|||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.util.DebugUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -37,6 +38,7 @@ class ChooseChoiceTestableDialog extends BaseTestableDialog {
|
|||
public void showDialog(Player player, Ability source, Game game, Player opponent) {
|
||||
Player choosingPlayer = this.isYou ? player : opponent;
|
||||
Choice dialog = this.choice.copy();
|
||||
String chooseDebugSource = DebugUtil.getMethodNameWithSource(0, "class");
|
||||
boolean chooseRes = choosingPlayer.choose(Outcome.Benefit, dialog, game);
|
||||
|
||||
List<String> res = new ArrayList<>();
|
||||
|
|
@ -52,7 +54,7 @@ class ChooseChoiceTestableDialog extends BaseTestableDialog {
|
|||
res.add(String.format("* selected value: %s", choice));
|
||||
}
|
||||
|
||||
((ChoiceTestableResult) this.getResult()).onFinish(chooseRes, res, choice);
|
||||
((ChoiceTestableResult) this.getResult()).onFinish(chooseDebugSource, chooseRes, res, choice);
|
||||
}
|
||||
|
||||
static public void register(TestableDialogsRunner runner) {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import mage.constants.Outcome;
|
|||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.util.CardUtil;
|
||||
import mage.util.DebugUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -51,12 +52,13 @@ class ChoosePileTestableDialog extends BaseTestableDialog {
|
|||
List<Card> pile2 = all.stream().limit(this.pileSize2).collect(Collectors.toList());
|
||||
|
||||
Player choosingPlayer = this.isYou ? player : opponent;
|
||||
String chooseDebugSource = DebugUtil.getMethodNameWithSource(0, "class");
|
||||
boolean chooseRes = choosingPlayer.choosePile(Outcome.Benefit, mainMessage, pile1, pile2, game);
|
||||
List<String> res = new ArrayList<>();
|
||||
res.add(getGroup() + " - " + this.getName() + " - " + (chooseRes ? "TRUE" : "FALSE"));
|
||||
res.add(" * selected pile: " + (chooseRes ? "pile 1" : "pile 2"));
|
||||
|
||||
this.getResult().onFinish(chooseRes, res);
|
||||
this.getResult().onFinish(chooseDebugSource, chooseRes, res);
|
||||
}
|
||||
|
||||
static public void register(TestableDialogsRunner runner) {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import mage.game.Game;
|
|||
import mage.players.Player;
|
||||
import mage.target.Target;
|
||||
import mage.target.Targets;
|
||||
import mage.util.DebugUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -51,18 +52,23 @@ class ChooseTargetTestableDialog extends BaseTestableDialog {
|
|||
Player choosingPlayer = this.isYou ? player : opponent;
|
||||
|
||||
boolean chooseRes;
|
||||
String chooseDebugSource;
|
||||
if (this.isPlayerChoice) {
|
||||
// player.chooseXXX
|
||||
if (this.isTargetChoice) {
|
||||
chooseDebugSource = DebugUtil.getMethodNameWithSource(0, "class");
|
||||
chooseRes = choosingPlayer.chooseTarget(Outcome.Benefit, choosingTarget, source, game);
|
||||
} else {
|
||||
chooseDebugSource = DebugUtil.getMethodNameWithSource(0, "class");
|
||||
chooseRes = choosingPlayer.choose(Outcome.Benefit, choosingTarget, source, game);
|
||||
}
|
||||
} else {
|
||||
// target.chooseXXX
|
||||
if (this.isTargetChoice) {
|
||||
chooseDebugSource = DebugUtil.getMethodNameWithSource(0, "class");
|
||||
chooseRes = choosingTarget.chooseTarget(Outcome.Benefit, choosingPlayer.getId(), source, game);
|
||||
} else {
|
||||
chooseDebugSource = DebugUtil.getMethodNameWithSource(0, "class");
|
||||
chooseRes = choosingTarget.choose(Outcome.Benefit, choosingPlayer.getId(), source, game);
|
||||
}
|
||||
}
|
||||
|
|
@ -74,7 +80,7 @@ class ChooseTargetTestableDialog extends BaseTestableDialog {
|
|||
Targets.printDebugTargets(getGroup() + " - " + this.getName() + " - " + "FALSE", new Targets(choosingTarget), source, game, res);
|
||||
}
|
||||
|
||||
((TargetTestableResult) this.getResult()).onFinish(chooseRes, res, choosingTarget);
|
||||
((TargetTestableResult) this.getResult()).onFinish(chooseDebugSource, chooseRes, res, choosingTarget);
|
||||
}
|
||||
|
||||
private ChooseTargetTestableDialog aiMustChoose(boolean resStatus, int targetsCount) {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import mage.constants.Outcome;
|
|||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.util.CardUtil;
|
||||
import mage.util.DebugUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -48,6 +49,7 @@ class ChooseUseTestableDialog extends BaseTestableDialog {
|
|||
@Override
|
||||
public void showDialog(Player player, Ability source, Game game, Player opponent) {
|
||||
Player choosingPlayer = this.isYou ? player : opponent;
|
||||
String chooseDebugSource = DebugUtil.getMethodNameWithSource(0, "class");
|
||||
boolean chooseRes = choosingPlayer.chooseUse(
|
||||
Outcome.Benefit,
|
||||
messageMain,
|
||||
|
|
@ -60,7 +62,7 @@ class ChooseUseTestableDialog extends BaseTestableDialog {
|
|||
List<String> res = new ArrayList<>();
|
||||
res.add(chooseRes ? "TRUE" : "FALSE");
|
||||
|
||||
this.getResult().onFinish(chooseRes, res);
|
||||
this.getResult().onFinish(chooseDebugSource, chooseRes, res);
|
||||
}
|
||||
|
||||
static public void register(TestableDialogsRunner runner) {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package mage.utils.testers;
|
|||
import mage.abilities.Ability;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.util.DebugUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -39,12 +40,12 @@ class GetAmountTestableDialog extends BaseTestableDialog {
|
|||
public void showDialog(Player player, Ability source, Game game, Player opponent) {
|
||||
Player choosingPlayer = this.isYou ? player : opponent;
|
||||
String message = "<font color=green>message</font> with html";
|
||||
int chooseRes;
|
||||
chooseRes = choosingPlayer.getAmount(this.min, this.max, message, source, game);
|
||||
String chooseDebugSource = DebugUtil.getMethodNameWithSource(0, "class");
|
||||
int chooseRes = choosingPlayer.getAmount(this.min, this.max, message, source, game);
|
||||
List<String> res = new ArrayList<>();
|
||||
res.add(getGroup() + " - " + this.getName() + " selected " + chooseRes);
|
||||
|
||||
((AmountTestableResult) this.getResult()).onFinish(true, res, chooseRes);
|
||||
((AmountTestableResult) this.getResult()).onFinish(chooseDebugSource, true, res, chooseRes);
|
||||
}
|
||||
|
||||
static public void register(TestableDialogsRunner runner) {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import mage.constants.MultiAmountType;
|
|||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.util.DebugUtil;
|
||||
import mage.util.MultiAmountMessage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -54,9 +55,9 @@ class GetMultiAmountTestableDialog extends BaseTestableDialog {
|
|||
public void showDialog(Player player, Ability source, Game game, Player opponent) {
|
||||
Player choosingPlayer = this.isYou ? player : opponent;
|
||||
//String message = "<font color=green>message</font> with html";
|
||||
List<Integer> chooseRes;
|
||||
List<MultiAmountMessage> options = this.amountOptions.stream().map(MultiAmountMessage::copy).collect(Collectors.toList());
|
||||
chooseRes = choosingPlayer.getMultiAmountWithIndividualConstraints(
|
||||
String chooseDebugSource = DebugUtil.getMethodNameWithSource(0, "class");
|
||||
List<Integer> chooseRes = choosingPlayer.getMultiAmountWithIndividualConstraints(
|
||||
Outcome.Benefit,
|
||||
options,
|
||||
this.totalMin,
|
||||
|
|
@ -82,7 +83,7 @@ class GetMultiAmountTestableDialog extends BaseTestableDialog {
|
|||
}
|
||||
res.add("total selected: " + selectedTotal);
|
||||
|
||||
((MultiAmountTestableResult) this.getResult()).onFinish(true, res, chooseRes);
|
||||
((MultiAmountTestableResult) this.getResult()).onFinish(chooseDebugSource, true, res, chooseRes);
|
||||
}
|
||||
|
||||
static public void register(TestableDialogsRunner runner) {
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ public class MultiAmountTestableResult extends BaseTestableResult {
|
|||
|
||||
List<Integer> values = new ArrayList<>();
|
||||
|
||||
public void onFinish(boolean status, List<String> info, List<Integer> values) {
|
||||
this.onFinish(status, info);
|
||||
public void onFinish(String resDebugSource, boolean status, List<String> info, List<Integer> values) {
|
||||
this.onFinish(resDebugSource, status, info);
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ public class TargetTestableResult extends BaseTestableResult {
|
|||
boolean aiAssertResStatus = false;
|
||||
int aiAssertTargetsCount = 0;
|
||||
|
||||
public void onFinish(boolean status, List<String> info, Target target) {
|
||||
this.onFinish(status, info);
|
||||
public void onFinish(String resDebugSource, boolean status, List<String> info, Target target) {
|
||||
this.onFinish(resDebugSource, status, info);
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,11 @@ import java.util.List;
|
|||
*/
|
||||
public interface TestableResult {
|
||||
|
||||
/**
|
||||
* Get source code line with called dialog, use it as starting debug point
|
||||
*/
|
||||
String getResDebugSource();
|
||||
|
||||
/**
|
||||
* Dialog's result
|
||||
*/
|
||||
|
|
@ -22,7 +27,7 @@ public interface TestableResult {
|
|||
/**
|
||||
* Save new result after show dialog
|
||||
*/
|
||||
void onFinish(boolean resStatus, List<String> resDetails);
|
||||
void onFinish(String chooseDebugSource, boolean resStatus, List<String> resDetails);
|
||||
|
||||
boolean isFinished();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue