Tests: improved verify tests:

- added checks for duplicated indefinite articles in the rules;
 - improved test_showCardInfo - now it can search cards by simple class name too;
 - fixed some card/token texts;
This commit is contained in:
Oleg Agafonov 2023-04-30 18:49:22 +04:00
parent e848f85e81
commit 255a050025
6 changed files with 42 additions and 26 deletions

View file

@ -66,7 +66,7 @@ public final class GideonOfTheTrials extends CardImpl {
class GideonOfTheTrialsToken extends TokenImpl {
public GideonOfTheTrialsToken() {
super("", "a 4/4 Human Soldier creature with indestructible");
super("", "4/4 Human Soldier creature with indestructible");
cardType.add(CardType.CREATURE);
subtype.add(SubType.HUMAN);
subtype.add(SubType.SOLDIER);

View file

@ -23,11 +23,10 @@ import mage.target.common.TargetAnyTarget;
*/
public final class NightfireGiant extends CardImpl {
private static final FilterPermanent filter = new FilterPermanent("a Mountain");
private static final FilterPermanent filter = new FilterPermanent("Mountain");
static {
filter.add(SubType.MOUNTAIN.getPredicate());
}
public NightfireGiant(UUID ownerId, CardSetInfo setInfo) {

View file

@ -87,13 +87,18 @@ public class VerifyCardDataTest {
"plainswalk", "islandwalk", "swampwalk", "mountainwalk", "forestwalk", "myriad", "prowess", "convoke"
);
private static final List<String> doubleNumbers = new ArrayList<>();
private static final List<String> doubleWords = new ArrayList<>();
{
// numbers
for (int i = 1; i <= 9; i++) {
String s = CardUtil.numberToText(i).toLowerCase(Locale.ENGLISH);
doubleNumbers.add(s + " " + s);
doubleWords.add(s + " " + s);
}
// additional checks
doubleWords.add(" an an ");
doubleWords.add(" a a ");
}
static {
@ -279,7 +284,7 @@ public class VerifyCardDataTest {
}
@Test
public void test_verifyCards() throws IOException {
public void test_verifyCards() {
int cardIndex = 0;
for (Card card : CardScanner.getAllCards()) {
cardIndex++;
@ -1684,15 +1689,15 @@ public class VerifyCardDataTest {
fail(card, "abilities", "mutate cards aren't implemented and shouldn't be available");
}
// special check: duplicated numbers in ability text (wrong target/filter usage)
// special check: duplicated words in ability text (wrong target/filter usage)
// example: You may exile __two two__ blue cards
// possible fixes:
// - remove numbers from filter's text
// - use target.getDescription() in ability instead target.getTargetName()
for (String rule : card.getRules()) {
for (String doubleNumber : doubleNumbers) {
if (rule.contains(doubleNumber)) {
fail(card, "abilities", "duplicated numbers: " + rule);
for (String doubleNumber : doubleWords) {
if (rule.toLowerCase(Locale.ENGLISH).contains(doubleNumber)) {
fail(card, "abilities", "duplicated numbers/words: " + rule);
}
}
}
@ -1792,18 +1797,29 @@ public class VerifyCardDataTest {
}
@Test
public void test_showCardInfo() throws Exception {
// debug only: show direct card info (takes it from class file, not from db repository)
// can check multiple cards at once, example: name1;name2;name3
String cardNames = "Spark Double";
public void test_showCardInfo() {
// debug only: show direct card info from class file without db-recreate
// - search by card name: Spark Double
// - search by class name: SparkDouble
// - multiple searches: name1;class2;name3
String cardSearches = "Spark Double";
CardScanner.scan();
Arrays.stream(cardNames.split(";")).forEach(cardName -> {
cardName = cardName.trim();
CardSetInfo testSet = new CardSetInfo(cardName, "test", "123", Rarity.COMMON);
CardInfo cardInfo = CardRepository.instance.findCard(cardName);
Arrays.stream(cardSearches.split(";")).forEach(searchName -> {
searchName = searchName.trim();
CardInfo cardInfo = CardRepository.instance.findCard(searchName);
if (cardInfo == null) {
Assert.fail("Can't find card name: " + cardName);
String searchClass = String.format("mage.cards.%s.%s",
searchName.substring(0, 1).toLowerCase(Locale.ENGLISH),
searchName);
cardInfo = CardRepository.instance.findCardsByClass(searchClass)
.stream()
.findFirst()
.orElse(null);
}
if (cardInfo == null) {
Assert.fail("Can't find card by name or class: " + searchName);
}
CardSetInfo testSet = new CardSetInfo(cardInfo.getName(), "test", "123", Rarity.COMMON);
Card card = CardImpl.createCard(cardInfo.getClassName(), testSet);
System.out.println();
System.out.println(card.getName() + " " + card.getManaCost().getText());
@ -2197,11 +2213,12 @@ public class VerifyCardDataTest {
@Test
public void test_checkCardConstructors() {
// create all cards, can catch additional verify and runtime checks from abilities and effects
// example: wrong code usage errors
Collection<String> errorsList = new ArrayList<>();
Collection<ExpansionSet> sets = Sets.getInstance().values();
for (ExpansionSet set : sets) {
for (ExpansionSet.SetCardInfo setInfo : set.getSetCardInfo()) {
// catch cards creation errors and report (e.g. on wrong card code or construction checks fail)
try {
Card card = CardImpl.createCard(setInfo.getCardClass(), new CardSetInfo(setInfo.getName(), set.getCode(),
setInfo.getCardNumber(), setInfo.getRarity(), setInfo.getGraphicInfo()));

View file

@ -359,11 +359,6 @@ public enum CardRepository {
return findPreferredOrLatestCard(cards, preferredSetCode);
}
public CardInfo findPreferredCoreExpansionCardByClassName(String canonicalClassName, String preferredSetCode) {
List<CardInfo> cards = findCardsByClass(canonicalClassName);
return findPreferredOrLatestCard(cards, preferredSetCode);
}
private CardInfo findPreferredOrLatestCard(List<CardInfo> cards, String preferredSetCode) {
if (!cards.isEmpty()) {
Date lastReleaseDate = null;

View file

@ -54,6 +54,11 @@ public abstract class TokenImpl extends MageObjectImpl implements Token {
public TokenImpl(String name, String description) {
this.name = name;
this.description = description;
// verify check: indefinite article
if (description.startsWith("a ") || description.startsWith("an ")) {
throw new IllegalArgumentException("Wrong code usage: don't use indefinite article here - " + description);
}
}
protected TokenImpl(final TokenImpl token) {

View file

@ -17,7 +17,7 @@ public final class ZombieKnightToken extends TokenImpl {
}
public ZombieKnightToken(){
super("Zombie Knight Token", "a 2/2 black Zombie Knight creature token with menace");
super("Zombie Knight Token", "2/2 black Zombie Knight creature token with menace");
availableImageSetCodes = tokenImageSets;
color.setBlack(true);
cardType.add(CardType.CREATURE);