Updated on 2026-08-14
This commit is contained in:
parent
03b11300e3
commit
e996fe1228
2 changed files with 62 additions and 10 deletions
|
|
@ -51,17 +51,19 @@ object TwinsHelper {
|
|||
* cb64 <-> cb65
|
||||
*/
|
||||
fun isTwinsCompatible(firstCardId: String, secondCardId: String): Boolean {
|
||||
if (firstCardId.startsWith(FIRST_CARD_FIRST_SERIES) &&
|
||||
secondCardId.startsWith(SECOND_CARD_FIRST_SERIES)
|
||||
) {
|
||||
return true
|
||||
return secondCardId.startsWith(getCompatibleTwinCardId(firstCardId))
|
||||
}
|
||||
|
||||
private fun getCompatibleTwinCardId(cardId: String): String {
|
||||
return when {
|
||||
cardId.startsWith(FIRST_CARD_FIRST_SERIES) -> SECOND_CARD_FIRST_SERIES
|
||||
cardId.startsWith(FIRST_CARD_SECOND_SERIES) -> SECOND_CARD_SECOND_SERIES
|
||||
cardId.startsWith(SECOND_CARD_FIRST_SERIES) -> FIRST_CARD_FIRST_SERIES
|
||||
cardId.startsWith(SECOND_CARD_SECOND_SERIES) -> FIRST_CARD_SECOND_SERIES
|
||||
else -> {
|
||||
"unknown"
|
||||
}
|
||||
}
|
||||
if (firstCardId.startsWith(FIRST_CARD_SECOND_SERIES) &&
|
||||
secondCardId.startsWith(SECOND_CARD_SECOND_SERIES)
|
||||
) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
package com.tangem.domain.common
|
||||
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class TwinsHelperTest {
|
||||
|
||||
private val pack1Twins = listOf(
|
||||
"CB610000021",
|
||||
"CB620000031",
|
||||
)
|
||||
|
||||
private val pack2Twins = listOf(
|
||||
"CB640000012",
|
||||
"CB650000011",
|
||||
)
|
||||
|
||||
@Test
|
||||
fun `twins compatibility pack 1 success`() {
|
||||
assertTrue(TwinsHelper.isTwinsCompatible(pack1Twins[0], pack1Twins[1]))
|
||||
assertTrue(TwinsHelper.isTwinsCompatible(pack1Twins[1], pack1Twins[0]))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `twins compatibility pack 1 same cards`() {
|
||||
assertFalse(TwinsHelper.isTwinsCompatible(pack1Twins[0], pack1Twins[0]))
|
||||
assertFalse(TwinsHelper.isTwinsCompatible(pack1Twins[1], pack1Twins[1]))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `twins compatibility pack 2 success`() {
|
||||
assertTrue(TwinsHelper.isTwinsCompatible(pack2Twins[0], pack2Twins[1]))
|
||||
assertTrue(TwinsHelper.isTwinsCompatible(pack2Twins[1], pack2Twins[0]))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `twins compatibility pack 2 same cards`() {
|
||||
assertFalse(TwinsHelper.isTwinsCompatible(pack2Twins[0], pack2Twins[0]))
|
||||
assertFalse(TwinsHelper.isTwinsCompatible(pack2Twins[1], pack2Twins[1]))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `twins compatibility false for different packs`() {
|
||||
assertFalse(TwinsHelper.isTwinsCompatible(pack2Twins[0], pack1Twins[1]))
|
||||
assertFalse(TwinsHelper.isTwinsCompatible(pack1Twins[1], pack2Twins[0]))
|
||||
assertFalse(TwinsHelper.isTwinsCompatible(pack1Twins[0], pack2Twins[1]))
|
||||
assertFalse(TwinsHelper.isTwinsCompatible(pack2Twins[1], pack1Twins[0]))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue