mirror of
https://github.com/magefree/mage.git
synced 2025-12-23 03:51:58 -08:00
This commit is contained in:
parent
d43e96eaf2
commit
a98f72649a
17 changed files with 123 additions and 83 deletions
|
|
@ -8,6 +8,7 @@ import mage.constants.Zone;
|
|||
import mage.utils.testers.TestableDialog;
|
||||
import mage.utils.testers.TestableDialogsRunner;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.player.TestPlayer;
|
||||
import org.mage.test.serverside.base.CardTestPlayerBaseWithAIHelps;
|
||||
|
|
@ -19,7 +20,7 @@ import java.util.stream.Collectors;
|
|||
|
||||
/**
|
||||
* Try to test all possible game dialogs by TestableDialogsRunner
|
||||
*
|
||||
* <p>
|
||||
* TODO: fill ai results for all generated dialogs
|
||||
*
|
||||
* @author JayDi85
|
||||
|
|
@ -50,7 +51,7 @@ public class TestableDialogsTest extends CardTestPlayerBaseWithAIHelps {
|
|||
setStopAt(1, PhaseStep.END_TURN);
|
||||
execute();
|
||||
|
||||
printRunnerResults(false);
|
||||
printRunnerResults(false, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -71,10 +72,11 @@ public class TestableDialogsTest extends CardTestPlayerBaseWithAIHelps {
|
|||
setStopAt(1, PhaseStep.END_TURN);
|
||||
execute();
|
||||
|
||||
printRunnerResults(false);
|
||||
printRunnerResults(false, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // TODO: enable and fix all failed dialogs
|
||||
public void test_RunAll_AI() {
|
||||
// it's impossible to setup 700+ dialogs, so all choices made by AI
|
||||
// current AI uses only simple choices in dialogs, not simulations
|
||||
|
|
@ -103,7 +105,7 @@ public class TestableDialogsTest extends CardTestPlayerBaseWithAIHelps {
|
|||
setStopAt(1, PhaseStep.END_TURN);
|
||||
execute();
|
||||
|
||||
printRunnerResults(true);
|
||||
printRunnerResults(true, true);
|
||||
}
|
||||
|
||||
private List<TestableDialog> findDialogs(TestableDialogsRunner runner, String byGroup, String byName) {
|
||||
|
|
@ -113,14 +115,14 @@ public class TestableDialogsTest extends CardTestPlayerBaseWithAIHelps {
|
|||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private void printRunnerResults(boolean showFullList) {
|
||||
private void printRunnerResults(boolean showFullList, boolean assertGoodResults) {
|
||||
// print text table with full dialogs list and results
|
||||
|
||||
// found table sizes
|
||||
int maxGroupLength = "Group".length();
|
||||
int maxNameLength = "Name".length();
|
||||
for (TestableDialog dialog : runner.getDialogs()) {
|
||||
if (!showFullList && !dialog.getResult().isSaved()) {
|
||||
if (!showFullList && !dialog.getResult().isFinished()) {
|
||||
continue;
|
||||
}
|
||||
maxGroupLength = Math.max(maxGroupLength, dialog.getGroup().length());
|
||||
|
|
@ -142,8 +144,11 @@ public class TestableDialogsTest extends CardTestPlayerBaseWithAIHelps {
|
|||
// data
|
||||
String prevGroup = "";
|
||||
int totalDialogs = 0;
|
||||
int totalGood = 0;
|
||||
int totalBad = 0;
|
||||
int totalUnknown = 0;
|
||||
for (TestableDialog dialog : runner.getDialogs()) {
|
||||
if (!showFullList && !dialog.getResult().isSaved()) {
|
||||
if (!showFullList && !dialog.getResult().isFinished()) {
|
||||
continue;
|
||||
}
|
||||
totalDialogs++;
|
||||
|
|
@ -151,7 +156,17 @@ public class TestableDialogsTest extends CardTestPlayerBaseWithAIHelps {
|
|||
System.out.println(horizontalBorder);
|
||||
}
|
||||
prevGroup = dialog.getGroup();
|
||||
String status = dialog.getResult().isOk() ? "OK" : "FAIL";
|
||||
String status;
|
||||
if (dialog.getResult().getResAssert() == null) {
|
||||
status = asYellow("?");
|
||||
totalUnknown++;
|
||||
} else if (dialog.getResult().getResAssert()) {
|
||||
totalGood++;
|
||||
status = asGreen("OK");
|
||||
} else {
|
||||
totalBad++;
|
||||
status = asRed("FAIL");
|
||||
}
|
||||
System.out.printf(rowFormat, dialog.getGroup(), dialog.getName(), status);
|
||||
}
|
||||
System.out.println(horizontalBorder);
|
||||
|
|
@ -160,7 +175,28 @@ public class TestableDialogsTest extends CardTestPlayerBaseWithAIHelps {
|
|||
System.out.printf("| %-" + (maxGroupLength + maxNameLength + maxResultLength + 6) + "s |%n",
|
||||
"Total dialogs: " + totalDialogs);
|
||||
System.out.printf("| %-" + (maxGroupLength + maxNameLength + maxResultLength + 6) + "s |%n",
|
||||
"Total results: TODO");
|
||||
String.format("Total results: %s good, %s bad, %s unknown",
|
||||
asGreen(String.valueOf(totalGood)),
|
||||
asRed(String.valueOf(totalBad)),
|
||||
asYellow(String.valueOf(totalUnknown))
|
||||
)
|
||||
);
|
||||
System.out.println(horizontalBorder);
|
||||
|
||||
if (assertGoodResults && totalBad > 0) {
|
||||
Assert.fail(String.format("Testable dialogs has %d bad results, try to fix it", totalBad));
|
||||
}
|
||||
}
|
||||
|
||||
private String asRed(String text) {
|
||||
return "\u001B[31m" + text + "\u001B[0m";
|
||||
}
|
||||
|
||||
private String asGreen(String text) {
|
||||
return "\u001B[32m" + text + "\u001B[0m";
|
||||
}
|
||||
|
||||
private String asYellow(String text) {
|
||||
return "\u001B[33m" + text + "\u001B[0m";
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue