Tests: simplify mtgjson code in verify test;

This commit is contained in:
Oleg Agafonov 2020-08-14 21:04:18 +04:00
parent bdac0b3d72
commit e1806f808c
11 changed files with 74 additions and 209 deletions

View file

@ -1,58 +0,0 @@
package mage.verify;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.List;
import static mage.verify.MtgJson.MTGJSON_IGNORE_NEW_PROPERTIES;
@JsonIgnoreProperties(ignoreUnknown = MTGJSON_IGNORE_NEW_PROPERTIES)
class JsonCard {
// docs: https://mtgjson.com/v4/docs.html
public String artist;
public String borderColor;
public List<String> colorIdentity;
public List<String> colorIndicator;
public List<String> colors;
public float convertedManaCost;
public float faceConvertedManaCost;
public String flavorText;
public List<JsonForeignData> foreignData;
public String frameVersion;
public boolean hasFoil;
public boolean hasNonFoil;
public boolean isOnlineOnly;
public boolean isOversized;
public boolean isReserved;
public boolean isTimeshifted;
public String layout;
public JsonLegalities legalities;
public String loyalty;
public String manaCost;
public int multiverseId;
public String name;
public List<String> names;
public String number;
public String originalText;
public String originalType;
public List<String> printings;
public String power;
public String rarity;
public boolean starter;
public String side;
public List<JsonRuling> rulings;
public List<String> subtypes;
public List<String> supertypes;
public String text;
public String toughness;
public String type;
public List<String> types;
public String uuid;
public List<String> variations;
public String watermark;
public String tcgplayerProductId;
public String scryfallId;
public boolean isAlternative;
public String frameEffect;
}

View file

@ -1,15 +0,0 @@
package mage.verify;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import static mage.verify.MtgJson.MTGJSON_IGNORE_NEW_PROPERTIES;
@JsonIgnoreProperties(ignoreUnknown = MTGJSON_IGNORE_NEW_PROPERTIES)
public class JsonForeignData {
public String flavorText;
public String language;
public int multiverseId;
public String name;
public String text;
public String type;
}

View file

@ -1,24 +0,0 @@
package mage.verify;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import static mage.verify.MtgJson.MTGJSON_IGNORE_NEW_PROPERTIES;
@JsonIgnoreProperties(ignoreUnknown = MTGJSON_IGNORE_NEW_PROPERTIES)
public class JsonLegalities {
@JsonProperty("1v1")
public String oneVersusOne;
public String brawl;
public String commander;
public String duel;
public String frontier;
public String future;
public String legacy;
public String modern;
public String penny;
public String pauper;
public String standard;
public String vintage;
public String oldschool;
}

View file

@ -1,11 +0,0 @@
package mage.verify;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import static mage.verify.MtgJson.MTGJSON_IGNORE_NEW_PROPERTIES;
@JsonIgnoreProperties(ignoreUnknown = MTGJSON_IGNORE_NEW_PROPERTIES)
public class JsonMeta {
public String date;
public String version;
}

View file

@ -1,11 +0,0 @@
package mage.verify;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import static mage.verify.MtgJson.MTGJSON_IGNORE_NEW_PROPERTIES;
@JsonIgnoreProperties(ignoreUnknown = MTGJSON_IGNORE_NEW_PROPERTIES)
public class JsonRuling {
public String date;
public String text;
}

View file

@ -1,26 +0,0 @@
package mage.verify;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.List;
import static mage.verify.MtgJson.MTGJSON_IGNORE_NEW_PROPERTIES;
@JsonIgnoreProperties(ignoreUnknown = MTGJSON_IGNORE_NEW_PROPERTIES)
class JsonSet {
public int baseSetSize;
public String block;
public List<Object> boosterV3; // [["rare", "mythic rare"], "uncommon", "uncommon", "uncommon", "common"]
public List<JsonCard> cards;
public String code;
public boolean isFoilOnly;
public boolean isOnlineOnly;
public JsonMeta meta;
public String mtgoCode;
public String name;
public String releaseDate;
public List<JsonToken> tokens;
public int totalSetSize;
public String type;
public String tcgplayerGroupId;
}

View file

@ -1,29 +0,0 @@
package mage.verify;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.List;
import static mage.verify.MtgJson.MTGJSON_IGNORE_NEW_PROPERTIES;
@JsonIgnoreProperties(ignoreUnknown = MTGJSON_IGNORE_NEW_PROPERTIES)
public class JsonToken {
public String artist;
public String borderColor;
public List<String> colorIdentity;
public List<String> colorIndicator;
public List<String> colors;
public String loyalty;
public String name;
public String number;
public String power;
public List<String> reverseRelated;
public String side;
public String text;
public String toughness;
public String type;
public String uuid;
public String watermark;
public boolean isOnlineOnly;
public String scryfallId;
}

View file

@ -0,0 +1,23 @@
package mage.verify;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.List;
import static mage.verify.MtgJsonService.MTGJSON_IGNORE_NEW_PROPERTIES;
@JsonIgnoreProperties(ignoreUnknown = MTGJSON_IGNORE_NEW_PROPERTIES)
class MtgJsonCard {
// docs: https://mtgjson.com/v4/docs.html
public List<String> colorIdentity;
public List<String> colors;
public String layout;
public String manaCost;
public String number;
public String power;
public List<String> subtypes;
public List<String> supertypes;
public String text;
public String toughness;
public List<String> types;
}

View file

@ -18,7 +18,7 @@ import java.util.List;
import java.util.Map;
import java.util.zip.ZipInputStream;
public final class MtgJson {
public final class MtgJsonService {
public static Map<String, String> mtgJsonToXMageCodes = new HashMap<>();
public static Map<String, String> xMageToMtgJsonCodes = new HashMap<>();
@ -49,11 +49,11 @@ public final class MtgJson {
}
}
private MtgJson() {
private MtgJsonService() {
}
private static final class CardHolder {
private static final Map<String, JsonCard> cards;
private static final Map<String, MtgJsonCard> cards;
static {
try {
@ -62,7 +62,7 @@ public final class MtgJson {
List<String> keysToDelete = new ArrayList<>();
// fix names
Map<String, JsonCard> newKeys = new HashMap<>();
Map<String, MtgJsonCard> newKeys = new HashMap<>();
for (String key : cards.keySet()) {
if (key.contains("(")) {
newKeys.put(key.replaceAll("\\(.*\\)", "").trim(), cards.get(key));
@ -74,7 +74,7 @@ public final class MtgJson {
// remove wrong data (tokens)
keysToDelete.clear();
for (Map.Entry<String, JsonCard> record : cards.entrySet()) {
for (Map.Entry<String, MtgJsonCard> record : cards.entrySet()) {
if (record.getValue().layout.equals("token") || record.getValue().layout.equals("double_faced_token")) {
keysToDelete.add(record.getKey());
}
@ -89,7 +89,7 @@ public final class MtgJson {
}
private static final class SetHolder {
private static final Map<String, JsonSet> sets;
private static final Map<String, MtgJsonSet> sets;
static {
try {
@ -100,18 +100,18 @@ public final class MtgJson {
}
}
private static Map<String, JsonCard> loadAllCards() throws IOException {
return readFromZip("AllCards.json.zip", new TypeReference<Map<String, JsonCard>>() {
private static Map<String, MtgJsonCard> loadAllCards() throws IOException {
return readFromZip("AllCards.json.zip", new TypeReference<Map<String, MtgJsonCard>>() {
});
}
private static Map<String, JsonSet> loadAllSets() throws IOException {
return readFromZip("AllPrintings.json.zip", new TypeReference<Map<String, JsonSet>>() {
private static Map<String, MtgJsonSet> loadAllSets() throws IOException {
return readFromZip("AllPrintings.json.zip", new TypeReference<Map<String, MtgJsonSet>>() {
});
}
private static <T> T readFromZip(String filename, TypeReference<T> ref) throws IOException {
InputStream stream = MtgJson.class.getResourceAsStream(filename);
InputStream stream = MtgJsonService.class.getResourceAsStream(filename);
if (stream == null) {
File file = new File(filename);
if (!file.exists()) {
@ -133,11 +133,11 @@ public final class MtgJson {
}
public static Map<String, JsonSet> sets() {
public static Map<String, MtgJsonSet> sets() {
return SetHolder.sets;
}
public static JsonCard card(String name) {
public static MtgJsonCard card(String name) {
return findReference(CardHolder.cards, name);
}

View file

@ -0,0 +1,16 @@
package mage.verify;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.List;
import static mage.verify.MtgJsonService.MTGJSON_IGNORE_NEW_PROPERTIES;
@JsonIgnoreProperties(ignoreUnknown = MTGJSON_IGNORE_NEW_PROPERTIES)
class MtgJsonSet {
public List<MtgJsonCard> cards;
public String code;
public String name;
public String releaseDate;
public int totalSetSize;
}

View file

@ -426,12 +426,12 @@ public class VerifyCardDataTest {
Collection<ExpansionSet> sets = Sets.getInstance().values();
// official sets
for (Map.Entry<String, JsonSet> refEntry : MtgJson.sets().entrySet()) {
JsonSet refSet = refEntry.getValue();
for (Map.Entry<String, MtgJsonSet> refEntry : MtgJsonService.sets().entrySet()) {
MtgJsonSet refSet = refEntry.getValue();
mtgCards += refSet.totalSetSize;
// replace codes for aliases
String searchSet = MtgJson.mtgJsonToXMageCodes.getOrDefault(refSet.code, refSet.code);
String searchSet = MtgJsonService.mtgJsonToXMageCodes.getOrDefault(refSet.code, refSet.code);
if (skipListHaveName(SKIP_LIST_UNSUPPORTED_SETS, searchSet)) {
unsupportedSets++;
unsupportedCards += refSet.totalSetSize;
@ -455,7 +455,7 @@ public class VerifyCardDataTest {
// unofficial sets info
for (ExpansionSet set : sets) {
if (MtgJson.sets().containsKey(set.getCode())) {
if (MtgJsonService.sets().containsKey(set.getCode())) {
continue;
}
@ -468,10 +468,10 @@ public class VerifyCardDataTest {
printMessages(info);
System.out.println();
System.out.println("Official sets implementation stats:");
System.out.println("* MTG sets: " + MtgJson.sets().size() + ", cards: " + mtgCards);
System.out.println("* MTG sets: " + MtgJsonService.sets().size() + ", cards: " + mtgCards);
System.out.println("* Implemented sets: " + mtgSets + ", cards: " + xmageCards);
System.out.println("* Unsupported sets: " + unsupportedSets + ", cards: " + unsupportedCards);
System.out.println("* TODO sets: " + (MtgJson.sets().size() - mtgSets - unsupportedSets) + ", cards: " + (mtgCards - xmageCards - unsupportedCards));
System.out.println("* TODO sets: " + (MtgJsonService.sets().size() - mtgSets - unsupportedSets) + ", cards: " + (mtgCards - xmageCards - unsupportedCards));
System.out.println();
System.out.println("Unofficial sets implementation stats:");
System.out.println("* Implemented sets: " + xmageUnofficialSets + ", cards: " + xmageUnofficialCards);
@ -998,16 +998,16 @@ public class VerifyCardDataTest {
}
private void check(Card card, Set<String> tokens, int cardIndex) {
JsonCard ref = MtgJson.card(card.getName());
MtgJsonCard ref = MtgJsonService.card(card.getName());
if (ref == null) {
warn(card, "Missing card reference");
return;
}
checkAll(card, ref, cardIndex);
if (tokens != null) {
JsonCard ref2 = null;
MtgJsonCard ref2 = null;
if (card.isFlipCard()) {
ref2 = MtgJson.card(card.getFlipCardName());
ref2 = MtgJsonService.card(card.getFlipCardName());
}
for (String token : tokens) {
if (!(token.equals(card.getName())
@ -1020,7 +1020,7 @@ public class VerifyCardDataTest {
}
}
private boolean containsInTypesOrText(JsonCard ref, String token) {
private boolean containsInTypesOrText(MtgJsonCard ref, String token) {
return contains(ref.types, token)
|| contains(ref.subtypes, token)
|| contains(ref.supertypes, token)
@ -1031,7 +1031,7 @@ public class VerifyCardDataTest {
return options != null && options.contains(value);
}
private void checkAll(Card card, JsonCard ref, int cardIndex) {
private void checkAll(Card card, MtgJsonCard ref, int cardIndex) {
checkCost(card, ref);
checkPT(card, ref);
checkSubtypes(card, ref);
@ -1045,7 +1045,7 @@ public class VerifyCardDataTest {
checkWrongAbilitiesText(card, ref, cardIndex);
}
private void checkColors(Card card, JsonCard ref) {
private void checkColors(Card card, MtgJsonCard ref) {
if (skipListHaveName(SKIP_LIST_COLOR, card.getExpansionSetCode(), card.getName())) {
return;
}
@ -1070,7 +1070,7 @@ public class VerifyCardDataTest {
}
}
private void checkSubtypes(Card card, JsonCard ref) {
private void checkSubtypes(Card card, MtgJsonCard ref) {
if (skipListHaveName(SKIP_LIST_SUBTYPE, card.getExpansionSetCode(), card.getName())) {
return;
}
@ -1104,7 +1104,7 @@ public class VerifyCardDataTest {
}
}
private void checkSupertypes(Card card, JsonCard ref) {
private void checkSupertypes(Card card, MtgJsonCard ref) {
if (skipListHaveName(SKIP_LIST_SUPERTYPE, card.getExpansionSetCode(), card.getName())) {
return;
}
@ -1115,7 +1115,7 @@ public class VerifyCardDataTest {
}
}
private void checkMissingAbilities(Card card, JsonCard ref) {
private void checkMissingAbilities(Card card, MtgJsonCard ref) {
if (skipListHaveName(SKIP_LIST_MISSING_ABILITIES, card.getExpansionSetCode(), card.getName())) {
return;
}
@ -1180,7 +1180,7 @@ public class VerifyCardDataTest {
}
}
private void checkLegalityFormats(Card card, JsonCard ref) {
private void checkLegalityFormats(Card card, MtgJsonCard ref) {
if (skipListHaveName("LEGALITY", card.getExpansionSetCode(), card.getName())) {
return;
}
@ -1297,7 +1297,7 @@ public class VerifyCardDataTest {
}
}*/
private void checkWrongAbilitiesText(Card card, JsonCard ref, int cardIndex) {
private void checkWrongAbilitiesText(Card card, MtgJsonCard ref, int cardIndex) {
// checks missing or wrong text
if (!card.getExpansionSetCode().equals(FULL_ABILITIES_CHECK_SET_CODE)) {
return;
@ -1365,7 +1365,7 @@ public class VerifyCardDataTest {
}
}
private void checkTypes(Card card, JsonCard ref) {
private void checkTypes(Card card, MtgJsonCard ref) {
if (skipListHaveName(SKIP_LIST_TYPE, card.getExpansionSetCode(), card.getName())) {
return;
}
@ -1380,7 +1380,7 @@ public class VerifyCardDataTest {
}
}
private void checkPT(Card card, JsonCard ref) {
private void checkPT(Card card, MtgJsonCard ref) {
if (skipListHaveName(SKIP_LIST_PT, card.getExpansionSetCode(), card.getName())) {
return;
}
@ -1400,7 +1400,7 @@ public class VerifyCardDataTest {
}
}
private void checkCost(Card card, JsonCard ref) {
private void checkCost(Card card, MtgJsonCard ref) {
if (skipListHaveName(SKIP_LIST_COST, card.getExpansionSetCode(), card.getName())) {
return;
}
@ -1418,7 +1418,7 @@ public class VerifyCardDataTest {
}
}
private void checkNumbers(Card card, JsonCard ref) {
private void checkNumbers(Card card, MtgJsonCard ref) {
if (skipListHaveName(SKIP_LIST_NUMBER, card.getExpansionSetCode(), card.getName())) {
return;
}
@ -1446,7 +1446,7 @@ public class VerifyCardDataTest {
|| checkName.equals("Wastes");
}
private void checkBasicLands(Card card, JsonCard ref) {
private void checkBasicLands(Card card, MtgJsonCard ref) {
// basic lands must have Rarity.LAND and SuperType.BASIC
// other cards can't have that stats