Tests: Add Rarity Verify Test out of mtgjson data. (#10782)

* Tests: Add Rarity Verify Test out of mtgjson data.

* skip some of the Special rarity.

* remove skip (fixed in master)
This commit is contained in:
Susucre 2023-08-12 22:16:22 +02:00 committed by GitHub
parent 2d53668c96
commit 23cc483a09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 3 deletions

View file

@ -1,5 +1,7 @@
package mage.verify.mtgjson;
import mage.constants.Rarity;
import java.util.List;
public final class MtgJsonCard {
@ -9,7 +11,8 @@ public final class MtgJsonCard {
public String name;
public String asciiName; // mtgjson uses it for some cards like El-Hajjaj
public String number; // from sets source only, see https://mtgjson.com/data-models/card/
public String number; // from sets source only, see https://mtgjson.com/data-models/card-set/
public String rarity; // from sets source only, see https://mtgjson.com/data-models/card-set/
public String faceName;
public String side;
@ -79,4 +82,32 @@ public final class MtgJsonCard {
public boolean isUseUnicodeName() {
return this.asciiName != null && this.name != null && !this.asciiName.equals(this.name);
}
/**
* @return the Rarity of the card if present in the mtgjson file
* null if not present.
*/
public Rarity getRarity() {
if (rarity.isEmpty()) {
return null;
}
switch (rarity) {
case "common":
return Rarity.COMMON;
case "uncommon":
return Rarity.UNCOMMON;
case "rare":
return Rarity.RARE;
case "mythic":
return Rarity.MYTHIC;
case "special":
return Rarity.SPECIAL;
case "bonus":
return Rarity.BONUS;
default: // Maybe a new rarity has been introduced?
throw new EnumConstantNotPresentException(Rarity.class, rarity);
}
}
}

View file

@ -74,6 +74,7 @@ public class VerifyCardDataTest {
private static final String SKIP_LIST_TYPE = "TYPE";
private static final String SKIP_LIST_SUBTYPE = "SUBTYPE";
private static final String SKIP_LIST_NUMBER = "NUMBER";
private static final String SKIP_LIST_RARITY = "RARITY";
private static final String SKIP_LIST_MISSING_ABILITIES = "MISSING_ABILITIES";
private static final String SKIP_LIST_DOUBLE_RARE = "DOUBLE_RARE";
private static final String SKIP_LIST_UNSUPPORTED_SETS = "UNSUPPORTED_SETS";
@ -137,6 +138,10 @@ public class VerifyCardDataTest {
// number
skipListCreate(SKIP_LIST_NUMBER);
// rarity
skipListCreate(SKIP_LIST_RARITY);
skipListAddName(SKIP_LIST_RARITY, "CMR", "The Prismatic Piper"); // Collation is not yet set up for CMR https://www.lethe.xyz/mtg/collation/cmr.html
// missing abilities
skipListCreate(SKIP_LIST_MISSING_ABILITIES);
@ -1605,7 +1610,7 @@ public class VerifyCardDataTest {
checkSupertypes(card, ref);
checkTypes(card, ref);
checkColors(card, ref);
checkBasicLands(card, ref);
checkRarityAndBasicLands(card, ref);
checkMissingAbilities(card, ref);
checkWrongSymbolsInRules(card);
checkCardCanBeCopied(card);
@ -2291,7 +2296,10 @@ public class VerifyCardDataTest {
|| name.equals("Mountain");
}
private void checkBasicLands(Card card, MtgJsonCard ref) {
private void checkRarityAndBasicLands(Card card, MtgJsonCard ref) {
if (skipListHaveName(SKIP_LIST_RARITY, card.getExpansionSetCode(), card.getName())) {
return;
}
// basic lands must have Rarity.LAND and SuperType.BASIC
// other cards can't have that stats
@ -2314,6 +2322,8 @@ public class VerifyCardDataTest {
// non lands
if (card.getRarity() == Rarity.LAND) {
fail(card, "rarity", "only basic land can be Rarity.LAND");
} else if (!card.getRarity().equals(ref.getRarity())) {
fail(card, "rarity", "mismatched. MtgJson has " + ref.getRarity() + " while set file has " + card.getRarity());
}
if (card.isBasic()) {