From 77209073e9bfd130bb752d7bae9e22aec30c179e Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Tue, 21 Mar 2023 17:19:57 +0400 Subject: [PATCH] Tests: improved mtgjson's card search in verify, added debug info to mtgjson's data; --- .../java/mage/verify/mtgjson/MtgJsonCard.java | 23 +++++++++++-- .../mage/verify/mtgjson/MtgJsonService.java | 5 +-- .../java/mage/verify/mtgjson/MtgJsonSet.java | 5 +++ .../java/mage/verify/VerifyCardDataTest.java | 32 ++++++++++--------- 4 files changed, 46 insertions(+), 19 deletions(-) diff --git a/Mage.Verify/src/main/java/mage/verify/mtgjson/MtgJsonCard.java b/Mage.Verify/src/main/java/mage/verify/mtgjson/MtgJsonCard.java index 63adfaa443..1702cf6cd9 100644 --- a/Mage.Verify/src/main/java/mage/verify/mtgjson/MtgJsonCard.java +++ b/Mage.Verify/src/main/java/mage/verify/mtgjson/MtgJsonCard.java @@ -33,7 +33,26 @@ public final class MtgJsonCard { public boolean isFullArt; public List printings; // set codes with that card - public String getRealCardName() { + @Override + public String toString() { + return number + " - " + this.getNameAsFull() + + (this.getNameAsFull().equals(this.getNameAsFace()) ? "" : String.format(" (face: %s)", this.getNameAsFace())); + } + + /** + * + * @return single side name like Ice from Fire // Ice + */ + public String getNameAsFace() { + // return single side name + return faceName != null ? faceName : (asciiName != null ? asciiName : name); + } + + /** + * + * @return full card name like Fire // Ice + */ + public String getNameAsFull() { // xmage split a double faced card to two different cards, but mtgjson/scryfall uses full name, // so use faceName property for full name searching if ("transform".equals(layout) @@ -42,7 +61,7 @@ public final class MtgJsonCard { || "modal_dfc".equals(layout) || "reversible_card".equals(layout) // reversible_card - example: Zndrsplt, Eye of Wisdom || "meld".equals(layout)) { // meld - mtgjson uses composite names for meld cards, but scryfall uses simple face names - return faceName; + return getNameAsFace(); } return asciiName != null ? asciiName : name; diff --git a/Mage.Verify/src/main/java/mage/verify/mtgjson/MtgJsonService.java b/Mage.Verify/src/main/java/mage/verify/mtgjson/MtgJsonService.java index 6171d0774d..1e38c861cb 100644 --- a/Mage.Verify/src/main/java/mage/verify/mtgjson/MtgJsonService.java +++ b/Mage.Verify/src/main/java/mage/verify/mtgjson/MtgJsonService.java @@ -77,9 +77,10 @@ public final class MtgJsonService { return new ArrayList<>(); } + // for a double faced cards each side goes here as one card, so must search by face name String needName = convertXmageToMtgJsonCardName(name); return set.cards.stream() - .filter(c -> needName.equals(c.getRealCardName())) + .filter(c -> needName.equals(c.getNameAsFace())) .collect(Collectors.toList()); } @@ -147,7 +148,7 @@ public final class MtgJsonService { public HashMap> data; private boolean containsSameNames(ArrayList list) { - Set names = list.stream().map(MtgJsonCard::getRealCardName).collect(Collectors.toSet()); + Set names = list.stream().map(MtgJsonCard::getNameAsFace).collect(Collectors.toSet()); return names.size() == 1; } diff --git a/Mage.Verify/src/main/java/mage/verify/mtgjson/MtgJsonSet.java b/Mage.Verify/src/main/java/mage/verify/mtgjson/MtgJsonSet.java index e15acdf206..4f287f9266 100644 --- a/Mage.Verify/src/main/java/mage/verify/mtgjson/MtgJsonSet.java +++ b/Mage.Verify/src/main/java/mage/verify/mtgjson/MtgJsonSet.java @@ -12,4 +12,9 @@ public final class MtgJsonSet { public String name; public String releaseDate; public int totalSetSize; + + @Override + public String toString() { + return code + " - " + name; + } } diff --git a/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java b/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java index 09740d41ca..a938aedbc5 100644 --- a/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java +++ b/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java @@ -62,10 +62,11 @@ public class VerifyCardDataTest { private static final Logger logger = Logger.getLogger(VerifyCardDataTest.class); private static final String FULL_ABILITIES_CHECK_SET_CODE = "40K"; // check all abilities and output cards with wrong abilities texts; - private static final boolean AUTO_FIX_SAMPLE_DECKS = false; // debug only: auto-fix sample decks by test_checkSampleDecks test run - private static final boolean ONLY_TEXT = false; // use when checking text locally, suppresses unnecessary checks and output messages + private static final boolean CHECK_ONLY_ABILITIES_TEXT = false; // use when checking text locally, suppresses unnecessary checks and output messages - private static final Set checkedNames = new HashSet<>(); + private static final boolean AUTO_FIX_SAMPLE_DECKS = false; // debug only: auto-fix sample decks by test_checkSampleDecks test run + + private static final Set checkedNames = new HashSet<>(); // skip already checked cards private static final HashMap> skipCheckLists = new HashMap<>(); private static final Set subtypesToIgnore = new HashSet<>(); private static final String SKIP_LIST_PT = "PT"; @@ -631,7 +632,7 @@ public class VerifyCardDataTest { } // index for missing cards - String code = MtgJsonService.xMageToMtgJsonCodes.getOrDefault(set.getCode(), set.getCode()) + " - " + jsonCard.getRealCardName() + " - " + jsonCard.number; + String code = MtgJsonService.xMageToMtgJsonCodes.getOrDefault(set.getCode(), set.getCode()) + " - " + jsonCard.getNameAsFull() + " - " + jsonCard.number; foundedJsonCards.add(code); // CHECK: only lands can use full art in current version; @@ -678,12 +679,12 @@ public class VerifyCardDataTest { } for (MtgJsonCard jsonCard : jsonSet.cards) { - String code = jsonSet.code + " - " + jsonCard.getRealCardName() + " - " + jsonCard.number; + String code = jsonSet.code + " - " + jsonCard.getNameAsFull() + " - " + jsonCard.number; if (!foundedJsonCards.contains(code)) { - if (!implementedIndex.contains(jsonCard.getRealCardName())) { - warningsList.add("Warning: un-implemented card from mtgjson: " + jsonSet.code + " - " + jsonCard.getRealCardName() + " - " + jsonCard.number); + if (!implementedIndex.contains(jsonCard.getNameAsFull())) { + warningsList.add("Warning: un-implemented card from mtgjson: " + jsonSet.code + " - " + jsonCard.getNameAsFull() + " - " + jsonCard.number); } else { - errorsList.add("Error: missing card from xmage's set: " + jsonSet.code + " - " + jsonCard.getRealCardName() + " - " + jsonCard.number); + errorsList.add("Error: missing card from xmage's set: " + jsonSet.code + " - " + jsonCard.getNameAsFull() + " - " + jsonCard.number); } } } @@ -1314,19 +1315,20 @@ public class VerifyCardDataTest { return options != null && options.contains(value); } - private static boolean checkName(MtgJsonCard ref) { - if (!ONLY_TEXT) { + private static boolean wasCheckedByAbilityText(MtgJsonCard ref) { + // ignore already checkd cards, so no bloated logs from duplicated cards + if (!CHECK_ONLY_ABILITIES_TEXT) { return true; } - if (checkedNames.contains(ref.getRealCardName())) { + if (checkedNames.contains(ref.getNameAsFace())) { return false; } - checkedNames.add(ref.getRealCardName()); + checkedNames.add(ref.getNameAsFace()); return true; } private void checkAll(Card card, MtgJsonCard ref, int cardIndex) { - if (!ONLY_TEXT) { + if (!CHECK_ONLY_ABILITIES_TEXT) { checkCost(card, ref); checkPT(card, ref); checkSubtypes(card, ref); @@ -1679,7 +1681,7 @@ public class VerifyCardDataTest { private void checkWrongAbilitiesText(Card card, MtgJsonCard ref, int cardIndex) { // checks missing or wrong text - if (!card.getExpansionSetCode().equals(FULL_ABILITIES_CHECK_SET_CODE) || !checkName(ref)) { + if (!card.getExpansionSetCode().equals(FULL_ABILITIES_CHECK_SET_CODE) || !wasCheckedByAbilityText(ref)) { return; } @@ -1782,7 +1784,7 @@ public class VerifyCardDataTest { if (!isAbilityFounded && cardRules[i].length() > 0) { isFine = false; - if (!ONLY_TEXT) { + if (!CHECK_ONLY_ABILITIES_TEXT) { warn(card, "card ability can't be found in ref [" + card.getName() + ": " + cardRules[i] + "]"); } cardRules[i] = "- " + cardRules[i];