mirror of
https://github.com/magefree/mage.git
synced 2026-01-10 04:42:07 -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
|
|
@ -78,7 +78,7 @@ public class TestableDialogsTest extends CardTestPlayerBaseWithAIHelps {
|
|||
@Test
|
||||
@Ignore // debug only - run single dialog by reg number
|
||||
public void test_RunSingle_Debugging() {
|
||||
int needRedNumber = 95;
|
||||
int needRegNumber = 7;
|
||||
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 6);
|
||||
addCard(Zone.HAND, playerA, "Forest", 6);
|
||||
|
|
@ -86,7 +86,7 @@ public class TestableDialogsTest extends CardTestPlayerBaseWithAIHelps {
|
|||
aiPlayStep(1, PhaseStep.PRECOMBAT_MAIN, PhaseStep.END_TURN, playerA);
|
||||
aiPlayStep(1, PhaseStep.PRECOMBAT_MAIN, PhaseStep.END_TURN, playerB);
|
||||
runCode("run by number", 1, PhaseStep.POSTCOMBAT_MAIN, playerA, (info, player, game) -> {
|
||||
TestableDialog dialog = findDialog(runner, needRedNumber);
|
||||
TestableDialog dialog = findDialog(runner, needRegNumber);
|
||||
dialog.prepare();
|
||||
dialog.showDialog(playerA, fakeAbility, game, playerB);
|
||||
});
|
||||
|
|
@ -148,20 +148,31 @@ public class TestableDialogsTest extends CardTestPlayerBaseWithAIHelps {
|
|||
}
|
||||
|
||||
private void assertAndPrintRunnerResults(boolean showFullList, boolean failOnBadResults) {
|
||||
// print text table with full dialogs list and results
|
||||
// print table with full dialogs list and assert results
|
||||
|
||||
// found table sizes
|
||||
// auto-size for columns
|
||||
int maxNumberLength = "9999".length();
|
||||
int maxGroupLength = "Group".length();
|
||||
int maxNameLength = "Name".length();
|
||||
int maxResultLength = "Result".length();
|
||||
int needTotalsSize = 0;
|
||||
for (TestableDialog dialog : runner.getDialogs()) {
|
||||
if (!showFullList && !dialog.getResult().isFinished()) {
|
||||
continue;
|
||||
}
|
||||
maxGroupLength = Math.max(maxGroupLength, dialog.getGroup().length());
|
||||
maxNameLength = Math.max(maxNameLength, dialog.getName().length());
|
||||
|
||||
// resize group to keep space for bigger total message like assert res
|
||||
String resAssert = dialog.getResult().getResAssert();
|
||||
resAssert = resAssert == null ? "" : resAssert;
|
||||
needTotalsSize = Math.max(needTotalsSize, dialog.getResult().getResDebugSource().length());
|
||||
needTotalsSize = Math.max(needTotalsSize, resAssert.length());
|
||||
int currentTotalsSize = maxNumberLength + maxGroupLength + maxNameLength + maxResultLength + 9;
|
||||
if (currentTotalsSize < needTotalsSize) {
|
||||
maxGroupLength = maxGroupLength + needTotalsSize - currentTotalsSize;
|
||||
}
|
||||
}
|
||||
int maxResultLength = "Result".length();
|
||||
|
||||
String rowFormat = "| %-" + maxNumberLength + "s | %-" + maxGroupLength + "s | %-" + maxNameLength + "s | %-" + maxResultLength + "s |%n";
|
||||
String horizontalBorder = "+-" +
|
||||
|
|
@ -172,12 +183,12 @@ public class TestableDialogsTest extends CardTestPlayerBaseWithAIHelps {
|
|||
String totalsLeftFormat = "| %-" + (maxNumberLength + maxGroupLength + maxNameLength + maxResultLength + 9) + "s |%n";
|
||||
String totalsRightFormat = "| %" + (maxNumberLength + maxGroupLength + maxNameLength + maxResultLength + 9) + "s |%n";
|
||||
|
||||
// header
|
||||
// print header row
|
||||
System.out.println(horizontalBorder);
|
||||
System.out.printf(rowFormat, "N", "Group", "Name", "Result");
|
||||
System.out.println(horizontalBorder);
|
||||
|
||||
// data
|
||||
// print data rows
|
||||
String prevGroup = "";
|
||||
int totalDialogs = 0;
|
||||
int totalGood = 0;
|
||||
|
|
@ -203,6 +214,7 @@ public class TestableDialogsTest extends CardTestPlayerBaseWithAIHelps {
|
|||
String status;
|
||||
coloredTexts.clear();
|
||||
String resAssert = dialog.getResult().getResAssert();
|
||||
String resDebugSource = dialog.getResult().getResDebugSource();
|
||||
String assertError = "";
|
||||
if (resAssert == null) {
|
||||
totalUnknown++;
|
||||
|
|
@ -231,7 +243,9 @@ public class TestableDialogsTest extends CardTestPlayerBaseWithAIHelps {
|
|||
if (!assertError.isEmpty()) {
|
||||
coloredTexts.clear();
|
||||
coloredTexts.put(resAssert, asRed(resAssert));
|
||||
System.out.print(getColoredRow(totalsRightFormat, coloredTexts, String.format("%s", resAssert)));
|
||||
coloredTexts.put(resDebugSource, asRed(resDebugSource));
|
||||
System.out.print(getColoredRow(totalsRightFormat, coloredTexts, resAssert));
|
||||
System.out.print(getColoredRow(totalsRightFormat, coloredTexts, resDebugSource));
|
||||
System.out.println(horizontalBorder);
|
||||
usedHorizontalBorder = true;
|
||||
}
|
||||
|
|
@ -241,10 +255,9 @@ public class TestableDialogsTest extends CardTestPlayerBaseWithAIHelps {
|
|||
usedHorizontalBorder = true;
|
||||
}
|
||||
|
||||
// totals dialogs
|
||||
// print totals
|
||||
System.out.printf(totalsLeftFormat, "Total dialogs: " + totalDialogs);
|
||||
usedHorizontalBorder = false;
|
||||
// totals results
|
||||
String goodStats = String.format("%d good", totalGood);
|
||||
String badStats = String.format("%d bad", totalBad);
|
||||
String unknownStats = String.format("%d unknown", totalUnknown);
|
||||
|
|
|
|||
|
|
@ -2267,6 +2267,13 @@ public class TestPlayer implements Player {
|
|||
|
||||
@Override
|
||||
public boolean choose(Outcome outcome, Target target, Ability source, Game game, Map<String, Serializable> options) {
|
||||
|
||||
// choose itself for starting player all the time
|
||||
if (target.getMessage(game).equals("Select a starting player")) {
|
||||
target.add(this.getId(), game);
|
||||
return true;
|
||||
}
|
||||
|
||||
UUID abilityControllerId = this.getId();
|
||||
if (target.getTargetController() != null && target.getAbilityController() != null) {
|
||||
abilityControllerId = target.getAbilityController();
|
||||
|
|
@ -2276,11 +2283,6 @@ public class TestPlayer implements Player {
|
|||
// most use cases - discard and other cost with choice like that method
|
||||
// must migrate all choices.remove(xxx) to choices.remove(0), takeMaxTargetsPerChoose can help to find it
|
||||
|
||||
// ignore player select
|
||||
if (target.getMessage(game).equals("Select a starting player")) {
|
||||
return computerPlayer.choose(outcome, target, source, game, options);
|
||||
}
|
||||
|
||||
boolean isAddedSomething = false; // must return true on any changes in targets, so game can ask next choose dialog until finish
|
||||
|
||||
assertAliasSupportInChoices(true);
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ public class DebugUtilTest extends CardTestPlayerBase {
|
|||
}
|
||||
|
||||
private void secondMethod() {
|
||||
String resCurrent = DebugUtil.getMethodNameWithSource(0);
|
||||
String resPrev = DebugUtil.getMethodNameWithSource(1);
|
||||
String resPrevPrev = DebugUtil.getMethodNameWithSource(2);
|
||||
String resCurrent = DebugUtil.getMethodNameWithSource(0, "method");
|
||||
String resPrev = DebugUtil.getMethodNameWithSource(1, "method");
|
||||
String resPrevPrev = DebugUtil.getMethodNameWithSource(2, "method");
|
||||
Assert.assertTrue("must find secondMethod, but get " + resCurrent, resCurrent.startsWith("secondMethod"));
|
||||
Assert.assertTrue("must find firstMethod, but get " + resPrev, resPrev.startsWith("firstMethod"));
|
||||
Assert.assertTrue("must find test_StackTraceWithSourceName, but get " + resPrevPrev, resPrevPrev.startsWith("test_StackTraceWithSourceName"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue