mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
tests: improved testable dialogs (added assert messages in result table, added single dialog debugging, part of #13643, #13638);
This commit is contained in:
parent
7a44ee2a97
commit
4732fdf527
10 changed files with 166 additions and 53 deletions
|
|
@ -17,7 +17,7 @@ public class AmountTestableResult extends BaseTestableResult {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Boolean getResAssert() {
|
||||
public String getResAssert() {
|
||||
return null; // TODO: implement
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import mage.target.common.TargetPermanentOrPlayer;
|
|||
*/
|
||||
abstract class BaseTestableDialog implements TestableDialog {
|
||||
|
||||
private Integer regNumber; // dialog number in runner (use it to find results and debugging)
|
||||
private final String group;
|
||||
private final String name;
|
||||
private final String description;
|
||||
|
|
@ -27,6 +28,16 @@ abstract class BaseTestableDialog implements TestableDialog {
|
|||
this.result = result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRegNumber(Integer regNumber) {
|
||||
this.regNumber = regNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getRegNumber() {
|
||||
return this.regNumber;
|
||||
}
|
||||
|
||||
@Override
|
||||
final public String getGroup() {
|
||||
return this.group;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public class BaseTestableResult implements TestableResult {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Boolean getResAssert() {
|
||||
public String getResAssert() {
|
||||
return null; // TODO: implement
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public class ChoiceTestableResult extends BaseTestableResult {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Boolean getResAssert() {
|
||||
public String getResAssert() {
|
||||
return null; // TODO: implement
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public class MultiAmountTestableResult extends BaseTestableResult {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Boolean getResAssert() {
|
||||
public String getResAssert() {
|
||||
return null; // TODO: implement
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class TargetTestableResult extends BaseTestableResult {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Boolean getResAssert() {
|
||||
public String getResAssert() {
|
||||
if (!this.aiAssertEnabled) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -35,16 +35,22 @@ public class TargetTestableResult extends BaseTestableResult {
|
|||
|
||||
// wrong choose
|
||||
if (this.getResStatus() != this.aiAssertResStatus) {
|
||||
return false;
|
||||
return String.format("Wrong status: need %s, but get %s",
|
||||
this.aiAssertResStatus,
|
||||
this.getResStatus()
|
||||
);
|
||||
}
|
||||
|
||||
// wrong targets
|
||||
if (this.target.getTargets().size() != this.aiAssertTargetsCount) {
|
||||
return false;
|
||||
return String.format("Wrong targets count: need %d, but get %d",
|
||||
this.aiAssertTargetsCount,
|
||||
this.target.getTargets().size()
|
||||
);
|
||||
}
|
||||
|
||||
// all fine
|
||||
return true;
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -17,6 +17,10 @@ import mage.players.Player;
|
|||
*/
|
||||
public interface TestableDialog {
|
||||
|
||||
void setRegNumber(Integer regNumber);
|
||||
|
||||
Integer getRegNumber();
|
||||
|
||||
String getGroup();
|
||||
|
||||
String getName();
|
||||
|
|
|
|||
|
|
@ -8,8 +8,10 @@ import mage.constants.Outcome;
|
|||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
|
@ -55,7 +57,7 @@ import java.util.stream.Collectors;
|
|||
*/
|
||||
public class TestableDialogsRunner {
|
||||
|
||||
private final List<TestableDialog> dialogs = new ArrayList<>();
|
||||
private final Map<Integer, TestableDialog> dialogs = new LinkedHashMap<>();
|
||||
|
||||
static final int LAST_SELECTED_GROUP_ID = 997;
|
||||
static final int LAST_SELECTED_DIALOG_ID = 998;
|
||||
|
|
@ -79,12 +81,14 @@ public class TestableDialogsRunner {
|
|||
}
|
||||
|
||||
void registerDialog(TestableDialog dialog) {
|
||||
this.dialogs.add(dialog);
|
||||
Integer regNumber = this.dialogs.size() + 1;
|
||||
dialog.setRegNumber(regNumber);
|
||||
this.dialogs.put(regNumber, dialog);
|
||||
}
|
||||
|
||||
public void selectAndShowTestableDialog(Player player, Ability source, Game game, Player opponent) {
|
||||
// select group or fast links
|
||||
List<String> groups = this.dialogs.stream()
|
||||
List<String> groups = this.dialogs.values().stream()
|
||||
.map(TestableDialog::getGroup)
|
||||
.distinct()
|
||||
.sorted()
|
||||
|
|
@ -201,8 +205,8 @@ public class TestableDialogsRunner {
|
|||
return choice;
|
||||
}
|
||||
|
||||
public List<TestableDialog> getDialogs() {
|
||||
return this.dialogs;
|
||||
public Collection<TestableDialog> getDialogs() {
|
||||
return this.dialogs.values();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ public interface TestableResult {
|
|||
|
||||
/**
|
||||
* Save new result after show dialog
|
||||
*
|
||||
*/
|
||||
void onFinish(boolean resStatus, List<String> resDetails);
|
||||
|
||||
|
|
@ -29,5 +28,11 @@ public interface TestableResult {
|
|||
|
||||
void onClear();
|
||||
|
||||
Boolean getResAssert();
|
||||
/**
|
||||
* Assert dialog result
|
||||
* - null - not ready (dev must setup wanted result)
|
||||
* - empty - good
|
||||
* - not empty - fail (return error message)
|
||||
*/
|
||||
String getResAssert();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue