forked from External/mage
Test framework: added commands for real time checks/assertions:
* new checks: color, subtype, ability, PT, permanent and hand count; * more info in #4936;
This commit is contained in:
parent
f30c0a7054
commit
4851ba9e84
5 changed files with 344 additions and 106 deletions
|
|
@ -30,7 +30,6 @@ import java.util.regex.Pattern;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JayDi85
|
||||
*/
|
||||
public class VerifyCardDataTest {
|
||||
|
|
@ -39,9 +38,18 @@ public class VerifyCardDataTest {
|
|||
private static final boolean CHECK_SOURCE_TOKENS = false;
|
||||
|
||||
private static final HashMap<String, Set<String>> skipCheckLists = new HashMap<>();
|
||||
private static void skipListCreate(String listName){ skipCheckLists.put(listName, new LinkedHashSet<>()); }
|
||||
private static void skipListAddName(String listName, String name){ skipCheckLists.get(listName).add(name); }
|
||||
private static boolean skipListHaveName(String listName, String name){ return skipCheckLists.get(listName).contains(name); }
|
||||
|
||||
private static void skipListCreate(String listName) {
|
||||
skipCheckLists.put(listName, new LinkedHashSet<>());
|
||||
}
|
||||
|
||||
private static void skipListAddName(String listName, String name) {
|
||||
skipCheckLists.get(listName).add(name);
|
||||
}
|
||||
|
||||
private static boolean skipListHaveName(String listName, String name) {
|
||||
return skipCheckLists.get(listName).contains(name);
|
||||
}
|
||||
|
||||
static {
|
||||
// skip lists for checks (example: unstable cards with same name may have different stats)
|
||||
|
|
@ -114,7 +122,7 @@ public class VerifyCardDataTest {
|
|||
|
||||
private void fail(Card card, String category, String message) {
|
||||
failed++;
|
||||
System.out.println("Error: (" + category + ") " + message + " for " + card.getName() + " (" + card.getExpansionSetCode() + ")");
|
||||
System.out.println("Error: (" + category + ") " + message + " for " + card.getName() + " (" + card.getExpansionSetCode() + ")");
|
||||
}
|
||||
|
||||
private int failed = 0;
|
||||
|
|
@ -136,31 +144,31 @@ public class VerifyCardDataTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void checkDuplicateCardNumbersInDB(){
|
||||
public void checkDuplicateCardNumbersInDB() {
|
||||
Collection<String> doubleErrors = new ArrayList<>();
|
||||
|
||||
Collection<ExpansionSet> sets = Sets.getInstance().values();
|
||||
for (ExpansionSet set : sets) {
|
||||
Map<String, ExpansionSet.SetCardInfo> cardsList = new HashMap<>();
|
||||
for (ExpansionSet.SetCardInfo checkCard: set.getSetCardInfo()) {
|
||||
for (ExpansionSet.SetCardInfo checkCard : set.getSetCardInfo()) {
|
||||
String cardNumber = checkCard.getCardNumber();
|
||||
|
||||
// ignore double faced
|
||||
Card realCard = CardImpl.createCard(checkCard.getCardClass(), new CardSetInfo(checkCard.getName(), set.getCode(),
|
||||
checkCard.getCardNumber(), checkCard.getRarity(), checkCard.getGraphicInfo()));
|
||||
if (realCard.isNightCard()){
|
||||
if (realCard.isNightCard()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cardsList.containsKey(cardNumber)){
|
||||
if (cardsList.containsKey(cardNumber)) {
|
||||
ExpansionSet.SetCardInfo prevCard = cardsList.get(cardNumber);
|
||||
|
||||
String errorType;
|
||||
if (checkCard.getName().equals(prevCard.getName())){
|
||||
if (checkCard.getName().equals(prevCard.getName())) {
|
||||
errorType = " founded DUPLICATED cards"
|
||||
+ " set (" + set.getCode() + " - " + set.getName() + ")"
|
||||
+ " (" + checkCard.getCardNumber() + " - " + checkCard.getName() + ")";
|
||||
}else{
|
||||
} else {
|
||||
errorType = " founded TYPOS in card numbers"
|
||||
+ " set (" + set.getCode() + " - " + set.getName() + ")"
|
||||
+ " (" + prevCard.getCardNumber() + " - " + prevCard.getName() + ")"
|
||||
|
|
@ -171,23 +179,23 @@ public class VerifyCardDataTest {
|
|||
String error = "Error: " + errorType;
|
||||
|
||||
doubleErrors.add(error);
|
||||
}else{
|
||||
} else {
|
||||
cardsList.put(cardNumber, checkCard);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (String error: doubleErrors) {
|
||||
for (String error : doubleErrors) {
|
||||
System.out.println(error);
|
||||
}
|
||||
|
||||
if (doubleErrors.size() > 0){
|
||||
if (doubleErrors.size() > 0) {
|
||||
Assert.fail("DB have duplicated card numbers, founded errors: " + doubleErrors.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkWrongCardClasses(){
|
||||
public void checkWrongCardClasses() {
|
||||
Collection<String> errorsList = new ArrayList<>();
|
||||
Map<String, String> classesIndex = new HashMap<>();
|
||||
int totalCards = 0;
|
||||
|
|
@ -202,7 +210,7 @@ public class VerifyCardDataTest {
|
|||
String needClass = classesIndex.get(checkCard.getName());
|
||||
if (!needClass.equals(currentClass)) {
|
||||
// workaround to star wars set with same card names
|
||||
if(!checkCard.getName().equals("Syndicate Enforcer")) {
|
||||
if (!checkCard.getName().equals("Syndicate Enforcer")) {
|
||||
errorsList.add("Error: founded wrong class in set " + set.getCode() + " - " + checkCard.getName() + " (" + currentClass + " <> " + needClass + ")");
|
||||
}
|
||||
}
|
||||
|
|
@ -212,45 +220,45 @@ public class VerifyCardDataTest {
|
|||
}
|
||||
}
|
||||
|
||||
for (String error: errorsList) {
|
||||
for (String error : errorsList) {
|
||||
System.out.println(error);
|
||||
}
|
||||
|
||||
// unique cards stats
|
||||
System.out.println("Total unique cards: " + classesIndex.size() + ", total non unique cards (reprints): " + totalCards);
|
||||
|
||||
if (errorsList.size() > 0){
|
||||
if (errorsList.size() > 0) {
|
||||
Assert.fail("DB have wrong card classes, founded errors: " + errorsList.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkMissingSets(){
|
||||
public void checkMissingSets() {
|
||||
|
||||
Collection<String> errorsList = new ArrayList<>();
|
||||
|
||||
int totalMissingSets = 0;
|
||||
int totalMissingCards = 0;
|
||||
Collection<ExpansionSet> sets = Sets.getInstance().values();
|
||||
for(Map.Entry<String, JsonSet> refEntry: MtgJson.sets().entrySet()){
|
||||
for (Map.Entry<String, JsonSet> refEntry : MtgJson.sets().entrySet()) {
|
||||
JsonSet refSet = refEntry.getValue();
|
||||
|
||||
// replace codes for aliases
|
||||
String searchSet = MtgJson.mtgJsonToXMageCodes.getOrDefault(refSet.code, refSet.code);
|
||||
|
||||
ExpansionSet mageSet = Sets.findSet(searchSet);
|
||||
if(mageSet == null){
|
||||
if (mageSet == null) {
|
||||
totalMissingSets = totalMissingSets + 1;
|
||||
totalMissingCards = totalMissingCards + refSet.cards.size();
|
||||
errorsList.add("Warning: missing set " + refSet.code + " - " + refSet.name + " (cards: " + refSet.cards.size() + ")");
|
||||
}
|
||||
}
|
||||
if(errorsList.size() > 0){
|
||||
if (errorsList.size() > 0) {
|
||||
errorsList.add("Warning: total missing sets: " + totalMissingSets + ", with missing cards: " + totalMissingCards);
|
||||
}
|
||||
|
||||
// only warnings
|
||||
for (String error: errorsList) {
|
||||
for (String error : errorsList) {
|
||||
System.out.println(error);
|
||||
}
|
||||
}
|
||||
|
|
@ -383,7 +391,7 @@ public class VerifyCardDataTest {
|
|||
|
||||
printMessages(warningsList);
|
||||
printMessages(errorsList);
|
||||
if(errorsList.size() > 0){
|
||||
if (errorsList.size() > 0) {
|
||||
Assert.fail("Founded token errors: " + errorsList.size());
|
||||
}
|
||||
}
|
||||
|
|
@ -455,7 +463,9 @@ public class VerifyCardDataTest {
|
|||
}
|
||||
|
||||
private void checkColors(Card card, JsonCard ref) {
|
||||
if (skipListHaveName("COLOR", card.getName())){ return; }
|
||||
if (skipListHaveName("COLOR", card.getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Collection<String> expected = ref.colors;
|
||||
ObjectColor color = card.getColor(null);
|
||||
|
|
@ -473,14 +483,16 @@ public class VerifyCardDataTest {
|
|||
}
|
||||
|
||||
private void checkSubtypes(Card card, JsonCard ref) {
|
||||
if (skipListHaveName("SUBTYPE", card.getName())){ return; }
|
||||
if (skipListHaveName("SUBTYPE", card.getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Collection<String> expected = ref.subtypes;
|
||||
|
||||
// fix names (e.g. Urza’s to Urza's)
|
||||
if (expected != null && expected.contains("Urza’s")) {
|
||||
expected = new ArrayList<>(expected);
|
||||
for (ListIterator<String> it = ((List<String>) expected).listIterator(); it.hasNext();) {
|
||||
for (ListIterator<String> it = ((List<String>) expected).listIterator(); it.hasNext(); ) {
|
||||
if (it.next().equals("Urza’s")) {
|
||||
it.set("Urza's");
|
||||
}
|
||||
|
|
@ -493,7 +505,9 @@ public class VerifyCardDataTest {
|
|||
}
|
||||
|
||||
private void checkSupertypes(Card card, JsonCard ref) {
|
||||
if (skipListHaveName("SUPERTYPE", card.getName())){ return; }
|
||||
if (skipListHaveName("SUPERTYPE", card.getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Collection<String> expected = ref.supertypes;
|
||||
if (!eqSet(card.getSuperType().stream().map(s -> s.toString()).collect(Collectors.toList()), expected)) {
|
||||
|
|
@ -502,7 +516,9 @@ public class VerifyCardDataTest {
|
|||
}
|
||||
|
||||
private void checkTypes(Card card, JsonCard ref) {
|
||||
if (skipListHaveName("TYPE", card.getName())){ return; }
|
||||
if (skipListHaveName("TYPE", card.getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Collection<String> expected = ref.types;
|
||||
List<String> type = new ArrayList<>();
|
||||
|
|
@ -522,7 +538,9 @@ public class VerifyCardDataTest {
|
|||
}
|
||||
|
||||
private void checkPT(Card card, JsonCard ref) {
|
||||
if (skipListHaveName("PT", card.getName())){ return; }
|
||||
if (skipListHaveName("PT", card.getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!eqPT(card.getPower().toString(), ref.power) || !eqPT(card.getToughness().toString(), ref.toughness)) {
|
||||
String pt = card.getPower() + "/" + card.getToughness();
|
||||
|
|
@ -540,7 +558,9 @@ public class VerifyCardDataTest {
|
|||
}
|
||||
|
||||
private void checkCost(Card card, JsonCard ref) {
|
||||
if (skipListHaveName("COST", card.getName())){ return; }
|
||||
if (skipListHaveName("COST", card.getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
String expected = ref.manaCost;
|
||||
String cost = join(card.getManaCost().getSymbols());
|
||||
|
|
@ -556,7 +576,9 @@ public class VerifyCardDataTest {
|
|||
}
|
||||
|
||||
private void checkNumbers(Card card, JsonCard ref) {
|
||||
if (skipListHaveName("NUMBER", card.getName())){ return; }
|
||||
if (skipListHaveName("NUMBER", card.getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
String expected = ref.number;
|
||||
String current = card.getCardNumber();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue