mirror of
https://github.com/correl/mage.git
synced 2024-11-29 03:00:12 +00:00
Tests: improved performance in game tests;
This commit is contained in:
parent
c87477178a
commit
f107c1e4db
2 changed files with 24 additions and 3 deletions
|
@ -672,7 +672,8 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
Assert.fail("Can't add card " + cardName + " - alias " + aliasName + " already exists for " + player.getName());
|
||||
}
|
||||
|
||||
CardInfo cardInfo = CardRepository.instance.findCard(cardName);
|
||||
// game tests don't need cards from a specific set, so it can be from any set
|
||||
CardInfo cardInfo = CardRepository.instance.findCard(cardName, true);
|
||||
if (cardInfo == null) {
|
||||
throw new IllegalArgumentException("[TEST] Couldn't find a card: " + cardName);
|
||||
}
|
||||
|
|
|
@ -369,12 +369,18 @@ public enum CardRepository {
|
|||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public CardInfo findCard(String name) {
|
||||
return findCard(name, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param returnAnySet return card from first available set (WARNING, it's a performance optimization for tests,
|
||||
* don't use it in real games - users must get random set)
|
||||
* @return random card with the provided name or null if none is found
|
||||
*/
|
||||
public CardInfo findCard(String name) {
|
||||
List<CardInfo> cards = findCards(name);
|
||||
public CardInfo findCard(String name, boolean returnAnySet) {
|
||||
List<CardInfo> cards = returnAnySet ? findCards(name, 1) : findCards(name);
|
||||
if (!cards.isEmpty()) {
|
||||
return cards.get(RandomUtil.nextInt(cards.size()));
|
||||
}
|
||||
|
@ -447,9 +453,23 @@ public enum CardRepository {
|
|||
}
|
||||
|
||||
public List<CardInfo> findCards(String name) {
|
||||
return findCards(name, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find card's reprints from all sets
|
||||
*
|
||||
* @param name
|
||||
* @param limitByMaxAmount return max amount of different cards (if 0 then return card from all sets)
|
||||
* @return
|
||||
*/
|
||||
public List<CardInfo> findCards(String name, long limitByMaxAmount) {
|
||||
try {
|
||||
QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder();
|
||||
queryBuilder.where().eq("name", new SelectArg(name));
|
||||
if (limitByMaxAmount > 0) {
|
||||
queryBuilder.limit(limitByMaxAmount);
|
||||
}
|
||||
return cardDao.query(queryBuilder.prepare());
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue