How to use PropTest class of io.kotest.property package

Best Kotest code snippet using io.kotest.property.PropTest

PropTestConfigConstraintsTest.kt

Source:PropTestConfigConstraintsTest.kt Github

copy

Full Screen

...4import io.kotest.matchers.longs.shouldBeLessThan5import io.kotest.matchers.shouldBe6import io.kotest.property.Arb7import io.kotest.property.Constraints8import io.kotest.property.PropTestConfig9import io.kotest.property.arbitrary.int10import io.kotest.property.arbitrary.string11import io.kotest.property.checkAll12import io.kotest.property.internal.proptest13import kotlin.time.Duration.Companion.milliseconds14import kotlin.time.TimeSource15class PropTestConfigConstraintsTest : FunSpec() {16 init {17 test("PropTestConfig constraints should be used by proptest1 if present") {18 checkAll(Arb.int(1..1000)) { iterations ->19 var iterationCount = 020 proptest(21 Arb.int(),22 PropTestConfig(constraints = Constraints.iterations(iterations))23 ) {24 iterationCount++25 }26 iterationCount shouldBe iterations27 }28 }29 test("PropTestConfig constraints should be used by proptest2 if present") {30 checkAll(Arb.int(1..1000)) { iterations ->31 var iterationCount = 032 proptest(33 Arb.int(),34 Arb.int(),35 PropTestConfig(constraints = Constraints.iterations(iterations))36 ) { _, _ ->37 iterationCount++38 }39 iterationCount shouldBe iterations40 }41 }42 test("PropTestConfig constraints should be used by proptest3 if present") {43 checkAll(Arb.int(1..1000)) { iterations ->44 var iterationCount = 045 proptest(46 Arb.int(),47 Arb.int(),48 Arb.int(),49 PropTestConfig(constraints = Constraints.iterations(iterations))50 )51 { _, _, _ ->52 iterationCount++53 }54 iterationCount shouldBe iterations55 }56 }57 test("PropTestConfig constraints should be used by proptest4 if present") {58 checkAll(Arb.int(1..1000)) { iterations ->59 var iterationCount = 060 proptest(61 Arb.int(),62 Arb.int(),63 Arb.int(),64 Arb.int(),65 PropTestConfig(constraints = Constraints.iterations(iterations))66 )67 { _, _, _, _ ->68 iterationCount++69 }70 iterationCount shouldBe iterations71 }72 }73 test("PropTestConfig constraints should be used by proptest5 if present") {74 checkAll(Arb.int(1..1000)) { iterations ->75 var iterationCount = 076 proptest(77 Arb.int(),78 Arb.int(),79 Arb.int(),80 Arb.int(),81 Arb.int(),82 PropTestConfig(constraints = Constraints.iterations(iterations))83 )84 { _, _, _, _, _ ->85 iterationCount++86 }87 iterationCount shouldBe iterations88 }89 }90 test("PropTestConfig constraints should be used by proptest6 if present") {91 checkAll(Arb.int(1..1000)) { iterations ->92 var iterationCount = 093 proptest(94 Arb.int(),95 Arb.int(),96 Arb.int(),97 Arb.int(),98 Arb.int(),99 Arb.int(),100 PropTestConfig(constraints = Constraints.iterations(iterations))101 )102 { _, _, _, _, _, _ ->103 iterationCount++104 }105 iterationCount shouldBe iterations106 }107 }108 test("PropTestConfig constraints should be used by proptest7 if present") {109 checkAll(Arb.int(1..1000)) { iterations ->110 var iterationCount = 0111 proptest(112 Arb.int(),113 Arb.int(),114 Arb.int(),115 Arb.int(),116 Arb.int(),117 Arb.int(),118 Arb.int(),119 PropTestConfig(constraints = Constraints.iterations(iterations))120 )121 { _, _, _, _, _, _, _ ->122 iterationCount++123 }124 iterationCount shouldBe iterations125 }126 }127 test("PropTestConfig constraints should be used by proptest8 if present") {128 checkAll(Arb.int(1..1000)) { iterations ->129 var iterationCount = 0130 proptest(131 Arb.int(),132 Arb.int(),133 Arb.int(),134 Arb.int(),135 Arb.int(),136 Arb.int(),137 Arb.int(),138 Arb.int(),139 PropTestConfig(constraints = Constraints.iterations(iterations))140 )141 { _, _, _, _, _, _, _, _ ->142 iterationCount++143 }144 iterationCount shouldBe iterations145 }146 }147 test("PropTestConfig constraints should be used by proptest9 if present") {148 checkAll(Arb.int(1..1000)) { iterations ->149 var iterationCount = 0150 proptest(151 Arb.int(),152 Arb.int(),153 Arb.int(),154 Arb.int(),155 Arb.int(),156 Arb.int(),157 Arb.int(),158 Arb.int(),159 Arb.int(),160 PropTestConfig(constraints = Constraints.iterations(iterations))161 )162 { _, _, _, _, _, _, _, _, _ ->163 iterationCount++164 }165 iterationCount shouldBe iterations166 }167 }168 test("PropTestConfig constraints should be used by proptest10 if present") {169 checkAll(Arb.int(1..1000)) { iterations ->170 var iterationCount = 0171 proptest(172 Arb.int(),173 Arb.int(),174 Arb.int(),175 Arb.int(),176 Arb.int(),177 Arb.int(),178 Arb.int(),179 Arb.int(),180 Arb.int(),181 Arb.int(),182 PropTestConfig(constraints = Constraints.iterations(iterations))183 )184 { _, _, _, _, _, _, _, _, _, _ ->185 iterationCount++186 }187 iterationCount shouldBe iterations188 }189 }190 test("PropTestConfig constraints should be used by proptest11 if present") {191 checkAll(Arb.int(1..1000)) { iterations ->192 var iterationCount = 0193 proptest(194 Arb.int(),195 Arb.int(),196 Arb.int(),197 Arb.int(),198 Arb.int(),199 Arb.int(),200 Arb.int(),201 Arb.int(),202 Arb.int(),203 Arb.int(),204 Arb.int(),205 PropTestConfig(constraints = Constraints.iterations(iterations))206 )207 { _, _, _, _, _, _, _, _, _, _, _ ->208 iterationCount++209 }210 iterationCount shouldBe iterations211 }212 }213 test("PropTestConfig constraints should be used by proptest12 if present") {214 checkAll(Arb.int(1..1000)) { iterations ->215 var iterationCount = 0216 proptest(217 Arb.int(),218 Arb.int(),219 Arb.int(),220 Arb.int(),221 Arb.int(),222 Arb.int(),223 Arb.int(),224 Arb.int(),225 Arb.int(),226 Arb.int(),227 Arb.int(),228 Arb.int(),229 PropTestConfig(constraints = Constraints.iterations(iterations))230 )231 { _, _, _, _, _, _, _, _, _, _, _, _ ->232 iterationCount++233 }234 iterationCount shouldBe iterations235 }236 }237 test("PropTestConfig constraints should support durations") {238 val config = PropTestConfig(constraints = Constraints.duration(200.milliseconds))239 val start = TimeSource.Monotonic.markNow()240 checkAll(config, Arb.string()) { _ -> }241 // we should have exited around 200 millis242 start.elapsedNow().inWholeMilliseconds.shouldBeGreaterThan(150)243 start.elapsedNow().inWholeMilliseconds.shouldBeLessThan(300)244 }245 }246}...

Full Screen

Full Screen

propertyTest3.kt

Source:propertyTest3.kt Github

copy

Full Screen

...11): PropertyContext = proptest(12 genA,13 genB,14 genC,15 PropTestConfig(),16 property17)18suspend fun <A, B, C> checkAll(19 config: PropTestConfig,20 genA: Gen<A>,21 genB: Gen<B>,22 genC: Gen<C>,23 property: suspend PropertyContext.(A, B, C) -> Unit24): PropertyContext =25 proptest(genA, genB, genC, config, property)26suspend fun <A, B, C> checkAll(27 iterations: Int,28 genA: Gen<A>,29 genB: Gen<B>,30 genC: Gen<C>,31 property: suspend PropertyContext.(A, B, C) -> Unit32): PropertyContext = proptest(genA, genB, genC, PropTestConfig(constraints = Constraints.iterations(iterations)), property)33suspend fun <A, B, C> checkAll(34 iterations: Int,35 config: PropTestConfig,36 genA: Gen<A>,37 genB: Gen<B>,38 genC: Gen<C>,39 property: suspend PropertyContext.(A, B, C) -> Unit40): PropertyContext = proptest(genA, genB, genC, config.copy(iterations = iterations), property)41suspend inline fun <reified A, reified B, reified C> checkAll(42 noinline property: suspend PropertyContext.(A, B, C) -> Unit43) = proptest(44 Arb.default(),45 Arb.default(),46 Arb.default(),47 PropTestConfig(),48 property49)50suspend inline fun <reified A, reified B, reified C> checkAll(51 config: PropTestConfig,52 noinline property: suspend PropertyContext.(A, B, C) -> Unit53) = proptest(54 Arb.default(),55 Arb.default(),56 Arb.default(),57 config,58 property59)60suspend inline fun <reified A, reified B, reified C> checkAll(61 iterations: Int,62 noinline property: suspend PropertyContext.(A, B, C) -> Unit63) = proptest(64 Arb.default(),65 Arb.default(),66 Arb.default(),67 PropTestConfig(constraints = Constraints.iterations(iterations)),68 property69)70suspend inline fun <reified A, reified B, reified C> checkAll(71 iterations: Int,72 config: PropTestConfig,73 noinline property: suspend PropertyContext.(A, B, C) -> Unit74) = proptest(75 Arb.default(),76 Arb.default(),77 Arb.default(),78 config.copy(iterations = iterations),79 property80)81suspend fun <A, B, C> forAll(82 genA: Gen<A>,83 genB: Gen<B>,84 genC: Gen<C>,85 property: suspend PropertyContext.(A, B, C) -> Boolean86) = forAll(87 PropTestConfig(),88 genA,89 genB,90 genC,91 property92)93suspend fun <A, B, C> forAll(94 config: PropTestConfig = PropTestConfig(),95 genA: Gen<A>,96 genB: Gen<B>,97 genC: Gen<C>,98 property: suspend PropertyContext.(A, B, C) -> Boolean99) = proptest(genA, genB, genC, config) { a, b, c -> property(a, b, c) shouldBe true }100suspend fun <A, B, C> forAll(101 iterations: Int,102 genA: Gen<A>,103 genB: Gen<B>,104 genC: Gen<C>,105 property: suspend PropertyContext.(A, B, C) -> Boolean106) = forAll(iterations, PropTestConfig(), genA, genB, genC, property)107suspend fun <A, B, C> forAll(108 iterations: Int,109 config: PropTestConfig,110 genA: Gen<A>,111 genB: Gen<B>,112 genC: Gen<C>,113 property: suspend PropertyContext.(A, B, C) -> Boolean114) = forAll(config.copy(iterations = iterations), genA, genB, genC, property)115suspend inline fun <reified A, reified B, reified C> forAll(116 crossinline property: PropertyContext.(A, B, C) -> Boolean117): PropertyContext = forAll(PropTestConfig(), property)118suspend inline fun <reified A, reified B, reified C> forAll(119 config: PropTestConfig = PropTestConfig(),120 crossinline property: PropertyContext.(A, B, C) -> Boolean121): PropertyContext = proptest<A, B, C>(122 Arb.default(),123 Arb.default(),124 Arb.default(),125 config126) { a, b, c -> property(a, b, c) shouldBe true }127suspend inline fun <reified A, reified B, reified C> forAll(128 iterations: Int,129 crossinline property: PropertyContext.(A, B, C) -> Boolean130) = forAll(iterations, PropTestConfig(), property)131suspend inline fun <reified A, reified B, reified C> forAll(132 iterations: Int,133 config: PropTestConfig,134 crossinline property: PropertyContext.(A, B, C) -> Boolean135) = forAll(config.copy(iterations = iterations), property)136suspend fun <A, B, C> forNone(137 genA: Gen<A>,138 genB: Gen<B>,139 genC: Gen<C>,140 property: suspend PropertyContext.(A, B, C) -> Boolean141) = forNone(142 PropTestConfig(),143 genA,144 genB,145 genC,146 property147)148suspend fun <A, B, C> forNone(149 config: PropTestConfig = PropTestConfig(),150 genA: Gen<A>,151 genB: Gen<B>,152 genC: Gen<C>,153 property: suspend PropertyContext.(A, B, C) -> Boolean154) = proptest(genA, genB, genC, config) { a, b, c -> property(a, b, c) shouldBe false }155suspend fun <A, B, C> forNone(156 iterations: Int,157 genA: Gen<A>,158 genB: Gen<B>,159 genC: Gen<C>,160 property: suspend PropertyContext.(A, B, C) -> Boolean161) = forNone(iterations, PropTestConfig(), genA, genB, genC, property)162suspend fun <A, B, C> forNone(163 iterations: Int,164 config: PropTestConfig,165 genA: Gen<A>,166 genB: Gen<B>,167 genC: Gen<C>,168 property: suspend PropertyContext.(A, B, C) -> Boolean169) = forNone(config.copy(iterations = iterations), genA, genB, genC, property)170suspend inline fun <reified A, reified B, reified C> forNone(171 crossinline property: PropertyContext.(A, B, C) -> Boolean172): PropertyContext = forNone(PropTestConfig(), property)173suspend inline fun <reified A, reified B, reified C> forNone(174 config: PropTestConfig = PropTestConfig(),175 crossinline property: PropertyContext.(A, B, C) -> Boolean176): PropertyContext = proptest(177 Arb.default<A>(),178 Arb.default<B>(),179 Arb.default<C>(),180 config181) { a, b, c -> property(a, b, c) shouldBe false }182suspend inline fun <reified A, reified B, reified C> forNone(183 iterations: Int,184 crossinline property: PropertyContext.(A, B, C) -> Boolean185) = forNone(iterations, PropTestConfig(), property)186suspend inline fun <reified A, reified B, reified C> forNone(187 iterations: Int,188 config: PropTestConfig,189 crossinline property: PropertyContext.(A, B, C) -> Boolean190) = forNone(config.copy(iterations = iterations), property)...

Full Screen

Full Screen

propertyTest2.kt

Source:propertyTest2.kt Github

copy

Full Screen

...6suspend fun <A, B> checkAll(7 genA: Gen<A>,8 genB: Gen<B>,9 property: suspend PropertyContext.(A, B) -> Unit10): PropertyContext = proptest(genA, genB, PropTestConfig(), property)11suspend fun <A, B> checkAll(12 config: PropTestConfig,13 genA: Gen<A>,14 genB: Gen<B>,15 property: suspend PropertyContext.(A, B) -> Unit16): PropertyContext = proptest(genA, genB, config, property)17suspend fun <A, B> checkAll(18 iterations: Int,19 genA: Gen<A>,20 genB: Gen<B>,21 property: suspend PropertyContext.(A, B) -> Unit22): PropertyContext = proptest(genA, genB, PropTestConfig(constraints = Constraints.iterations(iterations)), property)23suspend fun <A, B> checkAll(24 iterations: Int,25 config: PropTestConfig,26 genA: Gen<A>,27 genB: Gen<B>,28 property: suspend PropertyContext.(A, B) -> Unit29): PropertyContext = proptest(genA, genB, config.copy(iterations = iterations), property)30suspend inline fun <reified A, reified B> checkAll(31 noinline property: suspend PropertyContext.(A, B) -> Unit32) = proptest(33 Arb.default(),34 Arb.default(),35 PropTestConfig(),36 property37)38suspend inline fun <reified A, reified B> PropTest.checkAll(39 noinline property: suspend PropertyContext.(A, B) -> Unit40) = proptest(41 Arb.default(),42 Arb.default(),43 this.toPropTestConfig(),44 property45)46suspend inline fun <reified A, reified B> checkAll(47 config: PropTestConfig,48 noinline property: suspend PropertyContext.(A, B) -> Unit49) = proptest(50 Arb.default(),51 Arb.default(),52 config,53 property54)55suspend inline fun <reified A, reified B> checkAll(56 iterations: Int,57 noinline property: suspend PropertyContext.(A, B) -> Unit58) = proptest(59 Arb.default(),60 Arb.default(),61 PropTestConfig(constraints = Constraints.iterations(iterations)),62 property63)64suspend inline fun <reified A, reified B> checkAll(65 iterations: Int,66 config: PropTestConfig,67 noinline property: suspend PropertyContext.(A, B) -> Unit68) = proptest(69 Arb.default(),70 Arb.default(),71 config.copy(iterations = iterations),72 property73)74suspend fun <A, B> forAll(75 genA: Gen<A>,76 genB: Gen<B>,77 property: suspend PropertyContext.(A, B) -> Boolean78) = forAll(PropTestConfig(), genA, genB, property)79suspend fun <A, B> forAll(80 config: PropTestConfig = PropTestConfig(),81 genA: Gen<A>,82 genB: Gen<B>,83 property: suspend PropertyContext.(A, B) -> Boolean84) = proptest(genA, genB, config) { a, b -> property(a, b) shouldBe true }85suspend fun <A, B> forAll(86 iterations: Int,87 genA: Gen<A>,88 genB: Gen<B>,89 property: suspend PropertyContext.(A, B) -> Boolean90) = forAll(iterations, PropTestConfig(), genA, genB, property)91suspend fun <A, B> forAll(92 iterations: Int,93 config: PropTestConfig,94 genA: Gen<A>,95 genB: Gen<B>,96 property: suspend PropertyContext.(A, B) -> Boolean97) = forAll(config.copy(iterations = iterations), genA, genB, property)98suspend inline fun <reified A, reified B> forAll(99 crossinline property: PropertyContext.(A, B) -> Boolean100): PropertyContext = forAll(PropTestConfig(), property)101suspend inline fun <reified A, reified B> forAll(102 config: PropTestConfig = PropTestConfig(),103 crossinline property: PropertyContext.(A, B) -> Boolean104): PropertyContext = proptest<A, B>(105 Arb.default(),106 Arb.default(),107 config,108) { a, b -> property(a, b) shouldBe true }109suspend inline fun <reified A, reified B> forAll(110 iterations: Int,111 crossinline property: PropertyContext.(A, B) -> Boolean112) = forAll(iterations, PropTestConfig(), property)113suspend inline fun <reified A, reified B> forAll(114 iterations: Int,115 config: PropTestConfig,116 crossinline property: PropertyContext.(A, B) -> Boolean117) = forAll(config.copy(iterations = iterations), property)118suspend fun <A, B> forNone(119 genA: Gen<A>,120 genB: Gen<B>,121 property: suspend PropertyContext.(A, B) -> Boolean122) = forNone(PropTestConfig(), genA, genB, property)123suspend fun <A, B> forNone(124 config: PropTestConfig = PropTestConfig(),125 genA: Gen<A>,126 genB: Gen<B>,127 property: suspend PropertyContext.(A, B) -> Boolean128) = proptest(genA, genB, config) { a, b -> property(a, b) shouldBe false }129suspend fun <A, B> forNone(130 iterations: Int,131 genA: Gen<A>,132 genB: Gen<B>,133 property: suspend PropertyContext.(A, B) -> Boolean134) = forNone(iterations, PropTestConfig(), genA, genB, property)135suspend fun <A, B> forNone(136 iterations: Int,137 config: PropTestConfig,138 genA: Gen<A>,139 genB: Gen<B>,140 property: suspend PropertyContext.(A, B) -> Boolean141) = forNone(config.copy(iterations = iterations), genA, genB, property)142suspend inline fun <reified A, reified B> forNone(143 crossinline property: PropertyContext.(A, B) -> Boolean144): PropertyContext = forNone(PropTestConfig(), property)145suspend inline fun <reified A, reified B> forNone(146 config: PropTestConfig = PropTestConfig(),147 crossinline property: PropertyContext.(A, B) -> Boolean148): PropertyContext = proptest<A, B>(149 Arb.default(),150 Arb.default(),151 config152) { a, b -> property(a, b) shouldBe false }153suspend inline fun <reified A, reified B> forNone(154 iterations: Int,155 crossinline property: PropertyContext.(A, B) -> Boolean156) = forNone(iterations, PropTestConfig(), property)157suspend inline fun <reified A, reified B> forNone(158 iterations: Int,159 config: PropTestConfig,160 crossinline property: PropertyContext.(A, B) -> Boolean161) = forNone(config.copy(iterations = iterations), property)...

Full Screen

Full Screen

config.kt

Source:config.kt Github

copy

Full Screen

...34 }35 var defaultShrinkingMode: ShrinkingMode by AtomicProperty {36 ShrinkingMode.Bounded(1000)37 }38 var defaultListeners: List<PropTestListener> by AtomicProperty {39 listOf()40 }41 var defaultEdgecasesGenerationProbability: Double by AtomicProperty {42 sysprop("kotest.proptest.arb.edgecases-generation-probability", 0.02)43 }44 var defaultOutputClassifications: Boolean by AtomicProperty {45 sysprop("kotest.proptest.arb.output.classifications", false)46 }47 var failOnSeed: Boolean by AtomicProperty {48 sysprop("kotest.proptest.seed.fail-if-set", false)49 }50 var writeFailedSeed: Boolean by AtomicProperty {51 sysprop("kotest.proptest.seed.write-failed", true)52 }53}54fun EdgeConfig.Companion.default(): EdgeConfig = EdgeConfig(55 edgecasesGenerationProbability = PropertyTesting.defaultEdgecasesGenerationProbability56)57data class PropTest(58 val seed: Long? = PropertyTesting.defaultSeed,59 val minSuccess: Int = PropertyTesting.defaultMinSuccess,60 val maxFailure: Int = PropertyTesting.defaultMaxFailure,61 val shrinkingMode: ShrinkingMode = PropertyTesting.defaultShrinkingMode,62 val iterations: Int? = null,63 val listeners: List<PropTestListener> = PropertyTesting.defaultListeners,64 val edgeConfig: EdgeConfig = EdgeConfig.default(),65 val constraints: Constraints? = null,66)67fun PropTest.toPropTestConfig() =68 PropTestConfig(69 seed = seed,70 minSuccess = minSuccess,71 maxFailure = maxFailure,72 iterations = iterations,73 shrinkingMode = shrinkingMode,74 listeners = listeners,75 edgeConfig = edgeConfig76 )77/**78 * Property Test Configuration to be used by the underlying property test runner79 *80 * @param iterations The number of iterations to run. If null either the global [PropertyTesting]'s default value81 * will be used, or the minimum iterations required for the supplied generations. Whichever is82 * greater.83 *84 * @param constraints controls the loop for properties. See [Constraints].85 */86@OptIn(ExperimentalKotest::class)87data class PropTestConfig(88 val seed: Long? = PropertyTesting.defaultSeed,89 val minSuccess: Int = PropertyTesting.defaultMinSuccess,90 val maxFailure: Int = PropertyTesting.defaultMaxFailure,91 val shrinkingMode: ShrinkingMode = PropertyTesting.defaultShrinkingMode,92 val iterations: Int? = null,93 val listeners: List<PropTestListener> = PropertyTesting.defaultListeners,94 val edgeConfig: EdgeConfig = EdgeConfig.default(),95 val outputClassifications: Boolean = PropertyTesting.defaultOutputClassifications,96 val labelsReporter: LabelsReporter = StandardLabelsReporter,97 val constraints: Constraints? = null,98)99interface PropTestListener {100 suspend fun beforeTest(): Unit = Unit101 suspend fun afterTest(): Unit = Unit102}...

Full Screen

Full Screen

ShortTest.kt

Source:ShortTest.kt Github

copy

Full Screen

...5import io.kotest.inspectors.forAll6import io.kotest.matchers.short.shouldBeBetween7import io.kotest.matchers.shouldBe8import io.kotest.property.Arb9import io.kotest.property.PropTest10import io.kotest.property.arbitrary.*11import io.kotest.property.checkAll12import io.kotest.property.checkCoverage13class ShortTest : FunSpec({14 test("<Short, Short> should give values between min and max inclusive") {15 // Test parameters include the test for negative bounds16 forAll(17 row(-10, -1),18 row(1, 3),19 row(-100, 100),20 row((Short.MAX_VALUE - 10).toShort(), Short.MAX_VALUE),21 row(Short.MIN_VALUE, (Short.MIN_VALUE + 10).toShort())22 ) { vMin, vMax ->23 val expectedValues = (vMin..vMax).map { it.toShort() }.toSet()24 val actualValues = (1..100_000).map { Arb.short(vMin, vMax).single() }.toSet()25 actualValues shouldBe expectedValues26 }27 }28 test("Arb.short edge cases should respect min and max bounds") {29 checkCoverage("run", 25.0) {30 PropTest(iterations = 1000).checkAll<Short, Short> { min, max ->31 if (min < max) {32 classify("run")33 Arb.short(min, max).edgecases().forAll {34 it.shouldBeBetween(min, max)35 }36 }37 }38 }39 }40})41class UShortTest : FunSpec({42 test("<UShort, UShort> should give values between min and max inclusive") {43 forAll(44 row(1u, 3u),45 row(0u, 100u),46 row((UShort.MAX_VALUE - 10u).toUShort(), UShort.MAX_VALUE),47 row(UShort.MIN_VALUE, (UShort.MIN_VALUE + 10u).toUShort())48 ) { vMin, vMax ->49 val expectedValues = (vMin..vMax).map { it.toUShort() }.toSet()50 val actualValues = (1..100_000).map { Arb.uShort(vMin, vMax).single() }.toSet()51 actualValues shouldBe expectedValues52 }53 }54 test("Arb.uShort edge cases should respect min and max bounds") {55 checkCoverage("run", 25.0) {56 PropTest(iterations = 1000).checkAll<UShort, UShort> { min, max ->57 if (min < max) {58 classify("run")59 Arb.uShort(min, max).edgecases().forAll {60 it.shouldBeBetween(min, max)61 }62 }63 }64 }65 }66})...

Full Screen

Full Screen

ByteTest.kt

Source:ByteTest.kt Github

copy

Full Screen

...5import io.kotest.inspectors.forAll6import io.kotest.matchers.bytes.shouldBeBetween7import io.kotest.matchers.shouldBe8import io.kotest.property.Arb9import io.kotest.property.PropTest10import io.kotest.property.arbitrary.*11import io.kotest.property.checkAll12import io.kotest.property.checkCoverage13class ByteTest : FunSpec({14 test("<Byte, Byte> should give values between min and max inclusive") {15 // Test parameters include the test for negative bounds16 forAll(17 row(-10, -1),18 row(1, 3),19 row(-100, 100),20 row((Byte.MAX_VALUE - 10).toByte(), Byte.MAX_VALUE),21 row(Byte.MIN_VALUE, (Byte.MIN_VALUE + 10).toByte())22 ) { vMin, vMax ->23 val expectedValues = (vMin..vMax).map { it.toByte() }.toSet()24 val actualValues = (1..100_000).map { Arb.byte(vMin, vMax).single() }.toSet()25 actualValues shouldBe expectedValues26 }27 }28 test("Arb.byte edge cases should respect min and max bounds") {29 checkCoverage("run", 25.0) {30 PropTest(iterations = 1000).checkAll<Byte, Byte> { min, max ->31 if (min < max) {32 classify("run")33 Arb.byte(min, max).edgecases().forAll {34 it.shouldBeBetween(min, max)35 }36 }37 }38 }39 }40})41class UByteTest : FunSpec({42 test("<UByte, UByte> should give values between min and max inclusive") {43 forAll(44 row(1u, 3u),45 row(0u, 100u),46 row((UByte.MAX_VALUE - 10u).toUByte(), UByte.MAX_VALUE),47 row(UByte.MIN_VALUE, (UByte.MIN_VALUE + 10u).toUByte())48 ) { vMin, vMax ->49 val expectedValues = (vMin..vMax).map { it.toUByte() }.toSet()50 val actualValues = (1..100_000).map { Arb.uByte(vMin, vMax).single() }.toSet()51 actualValues shouldBe expectedValues52 }53 }54 test("Arb.uByte edge cases should respect min and max bounds") {55 checkCoverage("run", 25.0) {56 PropTest(iterations = 1000).checkAll<UByte, UByte> { min, max ->57 if (min < max) {58 classify("run")59 Arb.uByte(min, max).edgecases().forAll {60 it.shouldBeBetween(min, max)61 }62 }63 }64 }65 }66})...

Full Screen

Full Screen

build.gradle.kts

Source:build.gradle.kts Github

copy

Full Screen

1import org.jetbrains.kotlin.gradle.tasks.KotlinCompile2plugins {3 kotlin("jvm") version "1.5.21"4 kotlin("plugin.allopen") version "1.5.21"5 id("io.quarkus") version "2.7.0.Final"6 java7 application8 idea9}10group = "org.acme"11java { toolchain { languageVersion.set(JavaLanguageVersion.of(11)) } }12object Versions {13 val quarkus = "2.7.0.Final"14}15dependencies {16 implementation(kotlin("stdlib-jdk8"))17 // quarkus18 implementation(enforcedPlatform("io.quarkus:quarkus-universe-bom:${Versions.quarkus}"))19 implementation(quarkus("kotlin"))20 implementation(quarkus("cache"))21 testImplementation(quarkus("junit5"))22 testImplementation("io.kotest:kotest-runner-junit5:4.6.3")23 testImplementation("io.kotest:kotest-property:4.6.3")24 testImplementation("io.kotest:kotest-assertions-core:4.6.3")25 testImplementation("io.mockk:mockk:1.12.0")26 testImplementation(quarkus("junit5-mockito"))27 testImplementation("org.mockito.kotlin:mockito-kotlin:3.2.0")28}29tasks.test {30 useJUnitPlatform()31 systemProperty("kotest.proptest.default.iteration.count", "10")32}33tasks.withType<KotlinCompile> {34 kotlinOptions {35 freeCompilerArgs = listOf("-Xjsr305=strict")36 jvmTarget = "11"37 }38}39fun quarkus(module: String) = "io.quarkus:quarkus-$module"...

Full Screen

Full Screen

Libs.kt

Source:Libs.kt Github

copy

Full Screen

1object Libs {2 const val kotlinVersion = "1.6.10"3 // const val dokkaVersion = "1.4.20"4 const val kotestGradlePlugin = "0.3.9"5 const val versionsPlugin = "0.41.0"6 object Kotest {7 private const val version = "5.0.3"8 const val assertionsCore = "io.kotest:kotest-assertions-core:$version"9 const val assertionsJson = "io.kotest:kotest-assertions-json:$version"10 const val junit5 = "io.kotest:kotest-runner-junit5:$version"11 const val proptest = "io.kotest:kotest-property:$version"12 }13 object Kotlinx {14 private const val version = "1.3.2"15 const val serializationCore = "org.jetbrains.kotlinx:kotlinx-serialization-core:$version"16 const val serializationJson = "org.jetbrains.kotlinx:kotlinx-serialization-json:$version"17 }18 object Xerial {19 const val snappy = "org.xerial.snappy:snappy-java:1.1.8.4"20 }21 object Avro {22 private const val version = "1.11.0"23 const val avro = "org.apache.avro:avro:$version"24 }25}...

Full Screen

Full Screen

PropTest

Using AI Code Generation

copy

Full Screen

1import io.kotest.property.PropTest2import io.kotest.property.forAll3import io.kotest.property.prop4class PropTestTest : PropTest() {5 init {6 property("forAll") {7 forAll { a: Int, b: Int ->8 }9 }10 property("prop") {11 prop { a: Int, b: Int ->12 }13 }14 }15}16import io.kotest.property.CheckTest17import io.kotest.property.checkAll18import io.kotest.property.checkConfig19import io.kotest.property.check20class CheckTestTest : CheckTest() {21 init {22 property("checkAll") {23 checkAll { a: Int, b: Int ->24 }25 }26 property("checkConfig") {27 checkConfig(iterations = 10) {28 check { a: Int, b: Int ->29 }30 }31 }32 }33}

Full Screen

Full Screen

PropTest

Using AI Code Generation

copy

Full Screen

1 fun testPropTest() {2 PropTest {3 forAll { a: Int, b: Int ->4 }5 }6 }7}8 fun testPropTest() {9 PropTest {10 forAll { a: Int, b: Int ->11 }12 }13 }14}15 fun testPropTest() {16 PropTest {17 forAll { a: Int, b: Int ->18 }19 }20 }21}22 fun testPropTest() {23 PropTest {24 forAll { a: Int, b: Int ->25 }26 }27 }28}29 fun testPropTest() {30 PropTest {31 forAll { a: Int, b: Int ->32 }33 }34 }35}36 fun testPropTest() {37 PropTest {38 forAll { a: Int, b: Int ->39 }40 }41 }42}43 fun testPropTest() {44 PropTest {45 forAll { a: Int, b: Int ->46 }47 }48 }49}50 fun testPropTest() {51 PropTest {52 forAll { a: Int, b: Int ->53 }54 }55 }56}57 fun testPropTest() {58 PropTest {59 forAll { a: Int, b: Int ->

Full Screen

Full Screen

PropTest

Using AI Code Generation

copy

Full Screen

1 fun `test with property based testing`() {2 PropTest(100).forAll { a: Int, b: Int ->3 }4 }5 fun `test with property based testing using assertions`() {6 forAll(100) { a: Int, b: Int ->7 }8 }9 fun `test with property based testing using assertions with custom config`() {10 forAll(100, PropTestConfig(invocations = 100)) { a: Int, b: Int ->11 }12 }13 fun `test with property based testing using assertions with custom config and custom generator`() {14 forAll(100, PropTestConfig(invocations = 100), Gen.choose(0, 10)) { a: Int, b: Int ->15 }16 }17 fun `test with property based testing using assertions with custom config and custom generator and custom edge cases`() {18 forAll(100, PropTestConfig(invocations = 100), Gen.choose(0, 10), listOf(1, 2, 3)) { a: Int, b: Int ->19 }20 }21 fun `test with property based testing using assertions with custom config and custom generator and custom edge cases and custom seed`() {22 forAll(100, PropTestConfig(invocations = 100), Gen.choose(0, 10), listOf(1, 2, 3), 123456) { a: Int, b: Int ->23 }24 }25}

Full Screen

Full Screen

PropTest

Using AI Code Generation

copy

Full Screen

1 fun testPropTest() {2 PropTest(100, 10).forAll { a, b ->3 }4 }5 fun testPropTest() {6 PropTest(100, 10).forAll { a, b ->7 }8 }9 fun testPropTest() {10 PropTest(100, 10).forAll { a, b ->11 }12 }13 fun testPropTest() {14 PropTest(100, 10).forAll { a, b ->15 }16 }17 fun testPropTest() {18 PropTest(100, 10).forAll { a, b ->19 }20 }21 fun testPropTest() {22 PropTest(100, 10).forAll { a, b ->23 }24 }25 fun testPropTest() {26 PropTest(100, 10).forAll { a, b ->27 }28 }29 fun testPropTest() {30 PropTest(100, 10).forAll { a, b ->31 }32 }33 fun testPropTest() {34 PropTest(100, 10).forAll { a, b ->35 }36 }

Full Screen

Full Screen

PropTest

Using AI Code Generation

copy

Full Screen

1data class Person(val name: String, val age: Int)2val personGen = gen { Person("Alice", 20) }3val personArb = arbitrary { Person("Alice", 20) }4val personConfig = propTestConfig(maxTests = 100)5class PersonTest : StringSpec() {6init {7"Person should have a name" {8forAll(personGen) { person ->9person.name.isNotBlank()10}11}12"Person should have an age" {13forAll(personArb) { person ->14}15}16"Person should have a name and age" {17forAll(personConfig, personGen) { person ->18person.name.isNotBlank() && person.age > 019}20}21}22}23class PersonTest : StringSpec() {24val personGen = gen { Person("Alice", 20) }25val personArb = arbitrary { Person("Alice", 20) }26val personConfig = propTestConfig(maxTests = 100)27init {28"Person should have a name" {29forAll(personGen) { person ->30person.name.isNotBlank()31}32}33"Person should have an age" {34forAll(personArb) { person ->35}36}37"Person should have a name and age" {38forAll(personConfig, personGen) { person ->39person.name.isNotBlank() && person.age > 040}41}42}43}44class PersonTest : StringSpec() {45init {46"Person should have a name" {47checkAll<Person> { person ->48person.name.isNotBlank()49}50}51"Person should have an age" {52checkAll<Person> { person ->53}54}55"Person should have a name and age" {56checkAll<Person>(100) { person ->57person.name.isNotBlank() && person.age > 058}59}60}61}62class PersonTest : StringSpec() {63init {64"Person should have a name" {65checkAll<Person> { person ->66person.name.isNotBlank()67}68}69"Person should have an age" {70checkAll<Person> { person ->71}72}73"Person should have a name and age" {

Full Screen

Full Screen

PropTest

Using AI Code Generation

copy

Full Screen

1 fun `prop test`() {2 PropTestConfig(maxSuccess = 1000).run {3 forAll<String> { s ->4 }5 }6 }7}

Full Screen

Full Screen

PropTest

Using AI Code Generation

copy

Full Screen

1 fun testProp() {2 PropTest.property { x: Int ->3 }4 }5}6class PropertyTest : FunSpec({7 test("testProp") {8 PropertyTesting.property { x: Int ->9 }10 }11})12class PropertyTest : FunSpec({13 property("testProp") {14 forAll { x: Int ->15 }16 }17})18class PropertyTest : FunSpec({19 property("testProp") {20 checkAll { x: Int ->21 }22 }23})24class PropertyTest : FunSpec({25 property("testProp") {26 checkAll<Int> { x ->27 }28 }29})30class PropertyTest : FunSpec({31 property("testProp") {32 forAll<Int> { x ->33 }34 }35})36class PropertyTest : FunSpec({37 property("testProp") {38 forAll<Int> { x ->39 }40 }41})42class PropertyTest : FunSpec({43 property("testProp") {44 forAll<Int> { x ->45 }46 }47})48class PropertyTest : FunSpec({49 property("testProp") {50 forAll<Int> { x ->51 }52 }53})54class PropertyTest : FunSpec({55 property("testProp") {

Full Screen

Full Screen

PropTest

Using AI Code Generation

copy

Full Screen

1 fun `test property of add function`() {2 checkAll<Long, Long> { a, b ->3 add(a, b) == a + b4 }5 }6}7fun add(a: Long, b: Long): Long {8}9fun add(a: Int, b: Int): Int {10}11fun add(a: Double, b: Double): Double {12}13fun add(a: Float, b: Float): Float {14}15fun add(a: Short, b: Short): Short {16 return (a + b).toShort()17}18fun add(a: Byte, b: Byte): Byte {19 return (a + b).toByte()20}21fun add(a: Char, b: Char): Char {22 return (a + b).toChar()23}24fun add(a: Boolean, b: Boolean): Boolean {25}26fun add(a: String, b: String): String {27}28fun add(a: Array<Int>, b: Array<Int>): Array<Int> {29}

Full Screen

Full Screen

PropTest

Using AI Code Generation

copy

Full Screen

1+fun `randomly generated values`(){2+ PropTest(1000).forAll<Int> { it > 0 }.checkAll {3+ println(it)4+ }5+}6+fun `randomly generated values and test result`(){7+ PropTest(1000).forAll<Int> { it > 0 }.checkAll {8+ println(it)9+ println(it > 0)10+ }11+}12+fun `randomly generated values and test result and iteration number`(){13+ PropTest(1000).forAll<Int> { it > 0 }.checkAll {14+ println(it)15+ println(it > 0)16+ println(it)17+ }18+}19+fun `randomly generated values and test result and iteration number and test name`(){20+ PropTest(1000).forAll<Int> { it > 0 }.checkAll {21+ println(it)22+ println(it > 0)23+ println(it)24+ println("test")

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful