Skip to content

Commit

Permalink
Fixed #100 - Fixed promo legal override issues where cards in the cut…
Browse files Browse the repository at this point in the history
…off were being marked as unlimited
  • Loading branch information
r0adkll committed Oct 23, 2019
1 parent 87eec53 commit 974d930
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.r0adkll.deckbuilder.arch.data.features.validation.repository

import android.annotation.SuppressLint
import com.r0adkll.deckbuilder.R
import com.r0adkll.deckbuilder.arch.domain.features.cards.model.Expansion
import com.r0adkll.deckbuilder.arch.domain.features.remote.Remote
import com.r0adkll.deckbuilder.arch.domain.features.cards.model.PokemonCard
import com.r0adkll.deckbuilder.arch.domain.features.cards.repository.CardRepository
import com.r0adkll.deckbuilder.arch.domain.features.decks.repository.DeckRepository
import com.r0adkll.deckbuilder.arch.domain.features.editing.repository.EditRepository
import com.r0adkll.deckbuilder.arch.domain.features.remote.model.BanList
import com.r0adkll.deckbuilder.arch.domain.features.remote.Remote
import com.r0adkll.deckbuilder.arch.domain.features.validation.model.Rule
import com.r0adkll.deckbuilder.arch.domain.features.validation.model.Validation
import com.r0adkll.deckbuilder.arch.domain.features.validation.repository.DeckValidator
Expand All @@ -17,7 +15,6 @@ import io.pokemontcg.model.SubType
import io.pokemontcg.model.SuperType
import io.reactivex.Observable
import javax.inject.Inject
import kotlin.math.exp

@SuppressLint("DefaultLocale")
class DefaultDeckValidator @Inject constructor(
Expand Down Expand Up @@ -89,7 +86,7 @@ class DefaultDeckValidator @Inject constructor(
val reprints = remote.reprints
val banList = remote.banList
val legalOverrides = remote.legalOverrides
val legalPromoOverride = legalOverrides?.promos
val legalPromoOverride = legalOverrides?.expandedPromos
return cards.isNotEmpty() && cards.all { card ->
if (card.supertype == SuperType.ENERGY && card.subtype == SubType.BASIC) {
true
Expand All @@ -99,7 +96,7 @@ class DefaultDeckValidator @Inject constructor(
val cardsExpansionCode = singlesOverride?.sourceSetCode ?: card.expansion?.code
when {
legalPromoOverride != null && cardsExpansionCode == legalPromoOverride.setCode -> {
card.sortableNumber >= legalOverrides.promos.startNumber
card.sortableNumber >= legalOverrides.expandedPromos.startNumber
}
expansions.find { it.code == cardsExpansionCode }?.expandedLegal == true -> {
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.r0adkll.deckbuilder.arch.domain.features.remote.model

data class LegalOverrides(
val promos: Promo?,
val expandedPromos: Promo?,
val singles: List<Single>
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class DefaultDeckValidatorTest {
fun testValidateLegalPromoOverrideLegal() {
setupExpansionMock(EXPANSIONS.toList())
val pokemon = createPokemonCard(name = "Charizard", expansionCode = "smp").copy(id = "smp-sm100", number = "SM100")
val override = LegalOverrides(LegalOverrides.Promo("smp", 94), emptyList())
val override = LegalOverrides(LegalOverrides.Promo("smp", 94), null, emptyList())
When calling remote.legalOverrides itReturns override

val result = validator.validate(listOf(pokemon)).blockingFirst()
Expand All @@ -151,7 +151,35 @@ class DefaultDeckValidatorTest {
fun testValidateLegalPromoOverrideLegalFail() {
setupExpansionMock(EXPANSIONS.toList())
val pokemon = createPokemonCard(name = "Charizard", expansionCode = "smp").copy(id = "smp-sm54", number = "SM54")
val override = LegalOverrides(LegalOverrides.Promo("smp", 94), emptyList())
val override = LegalOverrides(LegalOverrides.Promo("smp", 94), null, emptyList())
When calling remote.legalOverrides itReturns override

val result = validator.validate(listOf(pokemon)).blockingFirst()

result.shouldNotBeNull()
result.standard.shouldBeFalse()
result.expanded.shouldBeTrue()
}

@Test
fun testValidateLegalExpandedPromoOverrideLegal() {
setupExpansionMock(EXPANSIONS.toList())
val pokemon = createPokemonCard(name = "Charizard", expansionCode = "xy9").copy(id = "xy9-sm100", number = "SM100")
val override = LegalOverrides(null, LegalOverrides.Promo("xy9", 94), emptyList())
When calling remote.legalOverrides itReturns override

val result = validator.validate(listOf(pokemon)).blockingFirst()

result.shouldNotBeNull()
result.standard.shouldBeFalse()
result.expanded.shouldBeTrue()
}

@Test
fun testValidateLegalExpandedPromoOverrideLegalFail() {
setupExpansionMock(EXPANSIONS.toList())
val pokemon = createPokemonCard(name = "Charizard", expansionCode = "xy9").copy(id = "xy9-sm54", number = "SM54")
val override = LegalOverrides(null, LegalOverrides.Promo("xy9", 94), emptyList())
When calling remote.legalOverrides itReturns override

val result = validator.validate(listOf(pokemon)).blockingFirst()
Expand All @@ -165,7 +193,7 @@ class DefaultDeckValidatorTest {
fun testValidateLegalOverrideSingles() {
setupExpansionMock(EXPANSIONS.toList())
val pokemon = createPokemonCard(name = "Charizard", expansionCode = "sm115").copy(id = "sm115-SV5")
val override = LegalOverrides(null, listOf(LegalOverrides.Single("sm115-SV5", "sm5-15", "sm5")))
val override = LegalOverrides(null, null, listOf(LegalOverrides.Single("sm115-SV5", "sm5-15", "sm5")))
When calling remote.legalOverrides itReturns override

val result = validator.validate(listOf(pokemon)).blockingFirst()
Expand Down

0 comments on commit 974d930

Please sign in to comment.