Skip to content

Instantly share code, notes, and snippets.

@sdoward
Created April 11, 2020 15:25
Show Gist options
  • Save sdoward/9c17939e69c8c61f1f30b5b74c017943 to your computer and use it in GitHub Desktop.
Save sdoward/9c17939e69c8c61f1f30b5b74c017943 to your computer and use it in GitHub Desktop.
Testing Examples
fun AppConfig.shouldUpdate(appVersion: String): Boolean {
val appNumbers = appVersion.substringBefore(" ").split(".").map { it.toInt() }
val minNumbers = minAndroidVersion.split(".").map { it.toInt() }
appNumbers.forEachIndexed { index, number ->
val minNumber = minNumbers.elementAtOrElse(index) { 0 }
if (number > minNumber) {
return false
} else if (number < minNumber) {
return true
}
}
return false
}
class AppConfigTest {
private val donationRequiredField = DonationReportRequiredFields(listOf("CA"), listOf("KO"))
@Test
fun `should return false when first min number is lower than app number`() {
assertFalse(AppConfig("5.4.0", donationRequiredField).shouldUpdate("6.4.0"))
}
@Test
fun `should return false when second min number is lower than app number`() {
assertFalse(AppConfig("6.3.0", donationRequiredField).shouldUpdate("6.4.0"))
}
@Test
fun `should return false when third min number is lower than app number`() {
assertFalse(AppConfig("6.4.11", donationRequiredField).shouldUpdate("6.4.12 qa test build"))
}
@Test
fun `should return false min supported version is the same as app version`() {
assertFalse(AppConfig("6.4.12", donationRequiredField).shouldUpdate("6.4.12"))
}
@Test
fun `should return true when first min number is higher than app number`() {
assertTrue(AppConfig("7.4.0", donationRequiredField).shouldUpdate("6.4.0"))
}
@Test
fun `should return true when second min number is higher than app number`() {
assertTrue(AppConfig("6.5.0", donationRequiredField).shouldUpdate("6.4.0"))
}
@Test
fun `should return true when third min number is higher than app number`() {
assertTrue(AppConfig("6.4.1", donationRequiredField).shouldUpdate("6.4.0"))
}
@Test
fun `should return false when third min does not exist`() {
assertFalse(AppConfig("6.4", donationRequiredField).shouldUpdate("6.4.0"))
}
@Test
fun `should return false when number after point is lower than min and first number is lower`() {
assertFalse(AppConfig("2.13", donationRequiredField).shouldUpdate("6.5.0"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment