Created
June 29, 2020 14:17
-
-
Save masahitojp/0a748aa0b78d16294e46b21ebf3a663b to your computer and use it in GitHub Desktop.
example for shrinking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.kotest.core.spec.style.FunSpec | |
import io.kotest.matchers.shouldBe | |
import io.kotest.property.* | |
import io.kotest.property.arbitrary.* | |
class BusinessLogicTests : FunSpec({ | |
fun isPrimeNumber(number: Int): Boolean { | |
val root: Int = kotlin.math.floor(kotlin.math.sqrt(number.toDouble())).toInt() | |
for (i in 2..root) { | |
if (i % 2 == 0 && i != 2) { | |
continue | |
} else if (number % i == 0) { | |
return false | |
} | |
} | |
return true | |
} | |
test("素数の判定"){ | |
checkAll(PropTestConfig(shrinkingMode = ShrinkingMode.Bounded(50)),Arb.int(2..Int.MAX_VALUE)){ | |
i -> | |
isPrimeNumber(i) shouldBe true | |
} | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Attempting to shrink failed arg 1776894914 | |
Shrink #1: RTree(value=592298304, children=Lazy value not initialized yet.) fail | |
Shrink #2: RTree(value=197432768, children=Lazy value not initialized yet.) fail | |
Shrink #3: RTree(value=65810922, children=Lazy value not initialized yet.) fail | |
Shrink #4: RTree(value=21936974, children=Lazy value not initialized yet.) fail | |
Shrink #5: RTree(value=7312324, children=Lazy value not initialized yet.) fail | |
Shrink #6: RTree(value=2437441, children=Lazy value not initialized yet.) pass | |
Shrink #7: RTree(value=3656162, children=Lazy value not initialized yet.) fail | |
Shrink #8: RTree(value=1218720, children=Lazy value not initialized yet.) fail | |
Shrink #9: RTree(value=406240, children=Lazy value not initialized yet.) fail | |
Shrink #10: RTree(value=135413, children=Lazy value not initialized yet.) fail | |
Shrink #11: RTree(value=45137, children=Lazy value not initialized yet.) pass | |
Shrink #12: RTree(value=67706, children=Lazy value not initialized yet.) fail | |
Shrink #13: RTree(value=22568, children=Lazy value not initialized yet.) fail | |
Shrink #14: RTree(value=7522, children=Lazy value not initialized yet.) fail | |
Shrink #15: RTree(value=2507, children=Lazy value not initialized yet.) fail | |
Shrink #16: RTree(value=835, children=Lazy value not initialized yet.) fail | |
Shrink #17: RTree(value=278, children=Lazy value not initialized yet.) fail | |
Shrink #18: RTree(value=92, children=Lazy value not initialized yet.) fail | |
Shrink #19: RTree(value=30, children=Lazy value not initialized yet.) fail | |
Shrink #20: RTree(value=10, children=Lazy value not initialized yet.) fail | |
Shrink #21: RTree(value=3, children=Lazy value not initialized yet.) pass | |
Shrink #22: RTree(value=5, children=Lazy value not initialized yet.) pass | |
Shrink #23: RTree(value=6, children=Lazy value not initialized yet.) fail | |
Shrink #24: RTree(value=2, children=Lazy value not initialized yet.) pass | |
Shrink #25: RTree(value=4, children=Lazy value not initialized yet.) fail | |
Shrink #26: RTree(value=1, children=Lazy value not initialized yet.) pass | |
Shrink result (after 26 shrinks) => 4 | |
Property failed after 2 attempts | |
Arg 0: 4 (shrunk from 1776894914) | |
Caused by AssertionFailedError: expected:<true> but was:<false> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment