DB: fixed wrong result for night cards search (fixed double faced cards in test render dialog)

This commit is contained in:
Oleg Agafonov 2023-03-11 12:28:58 +04:00
parent 29e1c9b318
commit 18a3ec5247
4 changed files with 71 additions and 20 deletions

View file

@ -316,7 +316,7 @@ public class TestCardRenderDialog extends MageDialog {
//cardViews.add(createHandCard(game, playerYou.getId(), "ZNR", "134")); // Akoum Warrior
//*/
// test meld cards in hands and battlefield
/*// test meld cards in hands and battlefield
cardViews.add(createHandCard(game, playerYou.getId(), "EMN", "204")); // Hanweir Battlements
cardViews.add(createHandCard(game, playerYou.getId(), "EMN", "130a")); // Hanweir Garrison
cardViews.add(createHandCard(game, playerYou.getId(), "EMN", "130b")); // Hanweir, the Writhing Township
@ -325,7 +325,16 @@ public class TestCardRenderDialog extends MageDialog {
cardViews.add(createPermanentCard(game, playerYou.getId(), "EMN", "130b", 1, 1, 0, false, false, null)); // Hanweir, the Writhing Township
//*/
/* //test card icons
// test variant double faced cards (main and second sides must be same pair)
cardViews.add(createHandCard(game, playerYou.getId(), "VOW", "65")); // Jacob Hauken, Inspector
cardViews.add(createHandCard(game, playerYou.getId(), "VOW", "320")); // Jacob Hauken, Inspector
cardViews.add(createHandCard(game, playerYou.getId(), "VOW", "332")); // Jacob Hauken, Inspector
cardViews.add(createPermanentCard(game, playerYou.getId(), "VOW", "65", 1, 1, 0, false, false, null)); // Jacob Hauken, Inspector
cardViews.add(createPermanentCard(game, playerYou.getId(), "VOW", "320", 1, 1, 0, false, false, null)); // Jacob Hauken, Inspector
cardViews.add(createPermanentCard(game, playerYou.getId(), "VOW", "332", 1, 1, 0, false, false, null)); // Jacob Hauken, Inspector
//*/
/*//test card icons
cardViews.add(createHandCard(game, playerYou.getId(), "POR", "169")); // Grizzly Bears
cardViews.add(createHandCard(game, playerYou.getId(), "DKA", "140")); // Huntmaster of the Fells, transforms
cardViews.add(createPermanentCard(game, playerYou.getId(), "DKA", "140", 3, 3, 1, false, true, additionalIcons)); // Huntmaster of the Fells, transforms

View file

@ -2,7 +2,9 @@ package org.mage.test.utils;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.cards.repository.CardScanner;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.List;
@ -10,17 +12,22 @@ import java.util.List;
/**
* Testing of CardRepository functionality.
*
* @author Alex-Vasile
* @author Alex-Vasile, JayDi85
*/
public class CardRepositoryTest {
@Before
public void setUp() {
CardScanner.scan();
}
/**
* Test CardRepository.findCards for the difficult cases when provided with the full card name.
*
* <p>
* CardRepository.findCards is used only for testing purposes.
*/
@Test
public void testFindSplitCardsByFullName() {
public void test_FindSplitCardsByFullName() {
// Modal double-faced
assertFindCard("Malakir Rebirth // Malakir Mire");
// Transform double-faced
@ -35,11 +42,11 @@ public class CardRepositoryTest {
/**
* Test CardRepository.findCards for the difficult cases.
*
* <p>
* CardRepository.findCards is used only for testing purposes.
*/
@Test
public void testFindSplitCardsByMainName() {
public void test_FindSplitCardsByMainName() {
// Modal double-faced
assertFindCard("Malakir Rebirth");
// Transform double-faced
@ -54,11 +61,11 @@ public class CardRepositoryTest {
/**
* Test CardRepository.findCards for the difficult cases.
*
* <p>
* CardRepository.findCards is used only for testing purposes.
*/
@Test
public void testFindSplitCardsBySecondName() {
public void test_FindSplitCardsBySecondName() {
// Modal double-faced
assertFindCard("Malakir Mire");
// Transform double-faced
@ -73,11 +80,11 @@ public class CardRepositoryTest {
/**
* Test CardRepository.findCardsCaseInsensitive for the difficult cases.
*
* <p>
* CardRepository.findCardsCaseInsensitive is used for actual game
*/
@Test
public void testFindSplitCardsByFullNameCaseInsensitive() {
public void test_FindSplitCardsByFullNameCaseInsensitive() {
// Modal double-faced
assertFindCard("malakIR rebirTH // maLAkir mIRe");
// Transform double-faced
@ -92,11 +99,11 @@ public class CardRepositoryTest {
/**
* Test CardRepository.findCards for the difficult cases.
*
* <p>
* CardRepository.findCards is used only for testing purposes.
*/
@Test
public void testFindSplitCardsByMainNameCaseInsensitive() {
public void test_FindSplitCardsByMainNameCaseInsensitive() {
// Modal double-faced
assertFindCard("malakIR rebirTH");
// Transform double-faced
@ -111,11 +118,11 @@ public class CardRepositoryTest {
/**
* Test CardRepository.findCards for the difficult cases.
*
* <p>
* CardRepository.findCards is used only for testing purposes.
*/
@Test
public void testFindSplitCardsBySecondNameCaseInsensitive() {
public void test_FindSplitCardsBySecondNameCaseInsensitive() {
// Modal double-faced
assertFindCard("maLAkir mIRe");
// Transform double-faced
@ -130,13 +137,13 @@ public class CardRepositoryTest {
/**
* Reported bug: https://github.com/magefree/mage/issues/9533
*
* <p>
* Each half of a split card displays the combined information of both halves in the deck editor.
*
* <p>
* `findCards`'s `returnSplitCardHalf` parameter should handle this issue
*/
@Test
public void splitCardInfoIsntDoubled() {
public void test_splitCardInfoIsntDoubled() {
// Consecrate // Consume
// {1}{W/B} // {2}{W}{B}
List<CardInfo> fullCard1 = CardRepository.instance.findCards("Consecrate", 1, false);
@ -146,7 +153,7 @@ public class CardRepositoryTest {
Assert.assertTrue(fullCard2.get(0).isSplitCard());
Assert.assertEquals("Consecrate // Consume", fullCard2.get(0).getName());
List<CardInfo> splitHalfCardLeft = CardRepository.instance.findCards("Consecrate", 1, true);
List<CardInfo> splitHalfCardLeft = CardRepository.instance.findCards("Consecrate", 1, true);
Assert.assertTrue(splitHalfCardLeft.get(0).isSplitCardHalf());
Assert.assertEquals("Consecrate", splitHalfCardLeft.get(0).getName());
List<CardInfo> splitHalfCardRight = CardRepository.instance.findCards("Consume", 1, true);
@ -167,4 +174,21 @@ public class CardRepositoryTest {
foundCards.isEmpty()
);
}
/**
* Some set can contain both main and second side cards with same card numbers,
* so search result must return main side first
*/
@Test
public void test_SearchSetWithSecondSides() {
// XLN - Ixalan - Arguel's Blood Fast -> Temple of Aclazotz - 90
Assert.assertEquals("Arguel's Blood Fast", CardRepository.instance.findCard("XLN", "90").getName());
Assert.assertEquals("Arguel's Blood Fast", CardRepository.instance.findCard("XLN", "90", true).getName());
Assert.assertEquals("Arguel's Blood Fast", CardRepository.instance.findCard("XLN", "90", false).getName());
// VOW - Innistrad: Crimson Vow - Jacob Hauken, Inspector -> Hauken's Insight - 320
Assert.assertEquals("Jacob Hauken, Inspector", CardRepository.instance.findCard("VOW", "320").getName());
Assert.assertEquals("Jacob Hauken, Inspector", CardRepository.instance.findCard("VOW", "320", true).getName());
Assert.assertEquals("Jacob Hauken, Inspector", CardRepository.instance.findCard("VOW", "320", false).getName());
}
}

View file

@ -942,6 +942,7 @@ public class VerifyCardDataTest {
}
boolean containsDoubleSideCards = false;
Map<String, String> cardNumbers = new HashMap<>();
for (ExpansionSet.SetCardInfo cardInfo : set.getSetCardInfo()) {
Card card = CardImpl.createCard(cardInfo.getCardClass(), new CardSetInfo(cardInfo.getName(), set.getCode(),
cardInfo.getCardNumber(), cardInfo.getRarity(), cardInfo.getGraphicInfo()));
@ -973,7 +974,20 @@ public class VerifyCardDataTest {
+ " - " + card.getName() + " - " + card.getCardNumber()
+ " - " + card.getSecondCardFace().getName() + " - " + card.getSecondCardFace().getCardNumber());
}
*/
//*/
// CHECK: set contains both card sides
// related to second side cards usage
/*
String existedCardName = cardNumbers.getOrDefault(card.getCardNumber(), null);
if (existedCardName != null && !existedCardName.equals(card.getName())) {
String info = card.isNightCard() ? existedCardName + " -> " + card.getName() : card.getName() + " -> " + existedCardName;
errorsList.add("Error: set contains both card sides instead main only: "
+ set.getCode() + " - " + set.getName() + " - " + info + " - " + card.getCardNumber());
} else {
cardNumbers.put(card.getCardNumber(), card.getName());
}
//*/
}
// CHECK: double side cards must be in boosters

View file

@ -287,6 +287,10 @@ public enum CardRepository {
queryBuilder.limit(1L).where()
.eq("setCode", new SelectArg(setCode))
.and().eq("cardNumber", new SelectArg(cardNumber));
// some double faced cards can use second side card with same number as main side
// (example: vow - 65 - Jacob Hauken, Inspector), so make priority for main side first
queryBuilder.orderBy("nightCard", true);
}
List<CardInfo> result = cardDao.query(queryBuilder.prepare());
if (!result.isEmpty()) {