How to use output class of io.kotest.property.classifications package

Best Kotest code snippet using io.kotest.property.classifications.output

proptest.kt

Source:proptest.kt Github

copy

Full Screen

...5import io.kotest.property.Gen6import io.kotest.property.PropTestConfig7import io.kotest.property.PropertyContext8import io.kotest.property.PropertyTesting9import io.kotest.property.classifications.outputClassifications10import io.kotest.property.seed.createRandom11suspend fun <A> proptest(12   genA: Gen<A>,13   config: PropTestConfig,14   property: suspend PropertyContext.(A) -> Unit15): PropertyContext {16   config.checkFailOnSeed()17   val constraints = config.constraints18      ?: config.iterations?.let { Constraints.iterations(it) }19      ?: Constraints.iterations(PropertyTesting.defaultIterationCount)20   val context = PropertyContext()21   val random = createRandom(config)22   when (genA) {23      is Arb -> {24         genA.generate(random, config.edgeConfig)25            .takeWhile { constraints.evaluate() }26            .forEach { a ->27               val shrinkfn = shrinkfn(a, property, config.shrinkingMode)28               config.listeners.forEach { it.beforeTest() }29               test(30                  context,31                  config,32                  shrinkfn,33                  listOf(a.value),34                  listOf(genA.classifier),35                  random.seed36               ) {37                  context.property(a.value)38               }39               config.listeners.forEach { it.afterTest() }40            }41      }42      is Exhaustive -> {43         genA.values.forEach { a ->44            config.listeners.forEach { it.beforeTest() }45            test(46               context,47               config,48               { emptyList() },49               listOf(a),50               listOf(genA.classifier),51               random.seed52            ) {53               context.property(a)54            }55            config.listeners.forEach { it.afterTest() }56         }57      }58   }59   context.outputClassifications(1, config, random.seed)60   context.checkMaxSuccess(config, random.seed)61   return context62}63suspend fun <A, B> proptest(64   genA: Gen<A>,65   genB: Gen<B>,66   config: PropTestConfig,67   property: suspend PropertyContext.(A, B) -> Unit68): PropertyContext {69   config.checkFailOnSeed()70   val constraints = config.constraints71      ?: config.iterations?.let { Constraints.iterations(it) }72      ?: Constraints.iterations(PropertyTesting.defaultIterationCount)73   val context = PropertyContext()74   val random = createRandom(config)75   if (genA is Exhaustive && genB is Exhaustive) {76      genA.values.forEach { a ->77         genB.values.forEach { b ->78            config.listeners.forEach { it.beforeTest() }79            test(80               context,81               config,82               { emptyList() },83               listOf(a, b),84               listOf(genA.classifier, genB.classifier),85               random.seed86            ) {87               context.property(a, b)88            }89            config.listeners.forEach { it.afterTest() }90         }91      }92   } else {93      genA.generate(random, config.edgeConfig)94         .zip(genB.generate(random, config.edgeConfig))95         .takeWhile { constraints.evaluate() }96         .forEach { (a, b) ->97            val shrinkfn = shrinkfn(a, b, property, config.shrinkingMode)98            config.listeners.forEach { it.beforeTest() }99            test(100               context,101               config,102               shrinkfn,103               listOf(a.value, b.value),104               listOf(genA.classifier, genB.classifier),105               random.seed106            ) {107               context.property(a.value, b.value)108            }109            config.listeners.forEach { it.afterTest() }110         }111   }112   context.outputClassifications(2, config, random.seed)113   context.checkMaxSuccess(config, random.seed)114   return context115}116suspend fun <A, B, C> proptest(117   genA: Gen<A>,118   genB: Gen<B>,119   genC: Gen<C>,120   config: PropTestConfig,121   property: suspend PropertyContext.(A, B, C) -> Unit122): PropertyContext {123   config.checkFailOnSeed()124   val constraints = config.constraints125      ?: config.iterations?.let { Constraints.iterations(it) }126      ?: Constraints.iterations(PropertyTesting.defaultIterationCount)127   val context = PropertyContext()128   val random = createRandom(config)129   if (genA is Exhaustive && genB is Exhaustive && genC is Exhaustive) {130      genA.values.forEach { a ->131         genB.values.forEach { b ->132            genC.values.forEach { c ->133               config.listeners.forEach { it.beforeTest() }134               test(135                  context,136                  config,137                  { emptyList() },138                  listOf(a, b, c),139                  listOf(genA.classifier, genB.classifier, genC.classifier),140                  random.seed141               ) {142                  context.property(a, b, c)143               }144               config.listeners.forEach { it.afterTest() }145            }146         }147      }148   } else {149      genA.generate(random, config.edgeConfig)150         .zip(genB.generate(random, config.edgeConfig))151         .zip(genC.generate(random, config.edgeConfig))152         .takeWhile { constraints.evaluate() }153         .forEach { (ab, c) ->154            val (a, b) = ab155            val shrinkfn = shrinkfn(a, b, c, property, config.shrinkingMode)156            config.listeners.forEach { it.beforeTest() }157            test(158               context,159               config,160               shrinkfn,161               listOf(a.value, b.value, c.value),162               listOf(genA.classifier, genB.classifier, genC.classifier),163               random.seed164            ) {165               context.property(a.value, b.value, c.value)166            }167            config.listeners.forEach { it.afterTest() }168         }169   }170   context.outputClassifications(3, config, random.seed)171   context.checkMaxSuccess(config, random.seed)172   return context173}174suspend fun <A, B, C, D> proptest(175   genA: Gen<A>,176   genB: Gen<B>,177   genC: Gen<C>,178   genD: Gen<D>,179   config: PropTestConfig,180   property: suspend PropertyContext.(A, B, C, D) -> Unit181): PropertyContext {182   config.checkFailOnSeed()183   val constraints = config.constraints184      ?: config.iterations?.let { Constraints.iterations(it) }185      ?: Constraints.iterations(PropertyTesting.defaultIterationCount)186   val context = PropertyContext()187   val random = createRandom(config)188   if (genA is Exhaustive && genB is Exhaustive && genC is Exhaustive && genD is Exhaustive) {189      genA.values.forEach { a ->190         genB.values.forEach { b ->191            genC.values.forEach { c ->192               genD.values.forEach { d ->193                  config.listeners.forEach { it.beforeTest() }194                  test(195                     context, config, { emptyList() }, listOf(a, b, c, d),196                     listOf(genA.classifier, genB.classifier, genC.classifier, genD.classifier), random.seed197                  ) {198                     context.property(a, b, c, d)199                  }200                  config.listeners.forEach { it.afterTest() }201               }202            }203         }204      }205   } else {206      genA.generate(random, config.edgeConfig)207         .zip(genB.generate(random, config.edgeConfig))208         .zip(genC.generate(random, config.edgeConfig))209         .zip(genD.generate(random, config.edgeConfig))210         .takeWhile { constraints.evaluate() }211         .forEach { (abc, d) ->212            val (ab, c) = abc213            val (a, b) = ab214            val shrinkfn = shrinkfn(a, b, c, d, property, config.shrinkingMode)215            config.listeners.forEach { it.beforeTest() }216            test(217               context, config, shrinkfn,218               listOf(a.value, b.value, c.value, d.value),219               listOf(genA.classifier, genB.classifier, genC.classifier, genD.classifier),220               random.seed221            ) {222               context.property(a.value, b.value, c.value, d.value)223            }224            config.listeners.forEach { it.afterTest() }225         }226   }227   context.outputClassifications(4, config, random.seed)228   context.checkMaxSuccess(config, random.seed)229   return context230}231suspend fun <A, B, C, D, E> proptest(232   genA: Gen<A>,233   genB: Gen<B>,234   genC: Gen<C>,235   genD: Gen<D>,236   genE: Gen<E>,237   config: PropTestConfig,238   property: suspend PropertyContext.(A, B, C, D, E) -> Unit239): PropertyContext {240   config.checkFailOnSeed()241   val constraints = config.constraints242      ?: config.iterations?.let { Constraints.iterations(it) }243      ?: Constraints.iterations(PropertyTesting.defaultIterationCount)244   val context = PropertyContext()245   val random = createRandom(config)246   if (genA is Exhaustive && genB is Exhaustive && genC is Exhaustive && genD is Exhaustive && genE is Exhaustive) {247      genA.values.forEach { a ->248         genB.values.forEach { b ->249            genC.values.forEach { c ->250               genD.values.forEach { d ->251                  genE.values.forEach { e ->252                     config.listeners.forEach { it.beforeTest() }253                     test(254                        context,255                        config,256                        { emptyList() },257                        listOf(a, b, c, d, e),258                        listOf(259                           genA.classifier,260                           genB.classifier,261                           genC.classifier,262                           genD.classifier,263                           genE.classifier,264                        ),265                        random.seed266                     ) {267                        context.property(a, b, c, d, e)268                     }269                     config.listeners.forEach { it.afterTest() }270                  }271               }272            }273         }274      }275   } else {276      genA.generate(random, config.edgeConfig)277         .zip(genB.generate(random, config.edgeConfig))278         .zip(genC.generate(random, config.edgeConfig))279         .zip(genD.generate(random, config.edgeConfig))280         .zip(genE.generate(random, config.edgeConfig))281         .takeWhile { constraints.evaluate() }282         .forEach { (abcd, e) ->283            val (abc, d) = abcd284            val (ab, c) = abc285            val (a, b) = ab286            val shrinkfn = shrinkfn(a, b, c, d, e, property, config.shrinkingMode)287            config.listeners.forEach { it.beforeTest() }288            test(289               context,290               config,291               shrinkfn,292               listOf(a.value, b.value, c.value, d.value, e.value),293               listOf(294                  genA.classifier,295                  genB.classifier,296                  genC.classifier,297                  genD.classifier,298                  genE.classifier,299               ),300               random.seed301            ) {302               context.property(a.value, b.value, c.value, d.value, e.value)303            }304            config.listeners.forEach { it.afterTest() }305         }306   }307   context.outputClassifications(5, config, random.seed)308   context.checkMaxSuccess(config, random.seed)309   return context310}311suspend fun <A, B, C, D, E, F> proptest(312   genA: Gen<A>,313   genB: Gen<B>,314   genC: Gen<C>,315   genD: Gen<D>,316   genE: Gen<E>,317   genF: Gen<F>,318   config: PropTestConfig,319   property: suspend PropertyContext.(A, B, C, D, E, F) -> Unit320): PropertyContext {321   config.checkFailOnSeed()322   val constraints = config.constraints323      ?: config.iterations?.let { Constraints.iterations(it) }324      ?: Constraints.iterations(PropertyTesting.defaultIterationCount)325   val context = PropertyContext()326   val random = createRandom(config)327   genA.generate(random, config.edgeConfig)328      .zip(genB.generate(random, config.edgeConfig))329      .zip(genC.generate(random, config.edgeConfig))330      .zip(genD.generate(random, config.edgeConfig))331      .zip(genE.generate(random, config.edgeConfig))332      .zip(genF.generate(random, config.edgeConfig))333      .takeWhile { constraints.evaluate() }334      .forEach { (abcde, f) ->335         val (abcd, e) = abcde336         val (abc, d) = abcd337         val (ab, c) = abc338         val (a, b) = ab339         val shrinkfn = shrinkfn(a, b, c, d, e, f, property, config.shrinkingMode)340         config.listeners.forEach { it.beforeTest() }341         test(342            context,343            config,344            shrinkfn,345            listOf(a.value, b.value, c.value, d.value, e.value, f.value),346            listOf(347               genA.classifier,348               genB.classifier,349               genC.classifier,350               genD.classifier,351               genE.classifier,352               genF.classifier,353            ),354            random.seed355         ) {356            context.property(a.value, b.value, c.value, d.value, e.value, f.value)357         }358         config.listeners.forEach { it.afterTest() }359      }360   context.outputClassifications(6, config, random.seed)361   context.checkMaxSuccess(config, random.seed)362   return context363}364suspend fun <A, B, C, D, E, F, G> proptest(365   genA: Gen<A>,366   genB: Gen<B>,367   genC: Gen<C>,368   genD: Gen<D>,369   genE: Gen<E>,370   genF: Gen<F>,371   genG: Gen<G>,372   config: PropTestConfig,373   property: suspend PropertyContext.(A, B, C, D, E, F, G) -> Unit374): PropertyContext {375   config.checkFailOnSeed()376   val constraints = config.constraints377      ?: config.iterations?.let { Constraints.iterations(it) }378      ?: Constraints.iterations(PropertyTesting.defaultIterationCount)379   val context = PropertyContext()380   val random = createRandom(config)381   genA.generate(random, config.edgeConfig)382      .zip(genB.generate(random, config.edgeConfig))383      .zip(genC.generate(random, config.edgeConfig))384      .zip(genD.generate(random, config.edgeConfig))385      .zip(genE.generate(random, config.edgeConfig))386      .zip(genF.generate(random, config.edgeConfig))387      .zip(genG.generate(random, config.edgeConfig))388      .takeWhile { constraints.evaluate() }389      .forEach { (abcdef, g) ->390         val (abcde, f) = abcdef391         val (abcd, e) = abcde392         val (abc, d) = abcd393         val (ab, c) = abc394         val (a, b) = ab395         val shrinkfn = shrinkfn(a, b, c, d, e, f, g, property, config.shrinkingMode)396         config.listeners.forEach { it.beforeTest() }397         test(398            context,399            config,400            shrinkfn,401            listOf(a.value, b.value, c.value, d.value, e.value, f.value, g.value),402            listOf(403               genA.classifier,404               genB.classifier,405               genC.classifier,406               genD.classifier,407               genE.classifier,408               genF.classifier,409               genG.classifier410            ),411            random.seed412         ) {413            context.property(a.value, b.value, c.value, d.value, e.value, f.value, g.value)414         }415         config.listeners.forEach { it.afterTest() }416      }417   context.outputClassifications(7, config, random.seed)418   context.checkMaxSuccess(config, random.seed)419   return context420}421suspend fun <A, B, C, D, E, F, G, H> proptest(422   genA: Gen<A>,423   genB: Gen<B>,424   genC: Gen<C>,425   genD: Gen<D>,426   genE: Gen<E>,427   genF: Gen<F>,428   genG: Gen<G>,429   genH: Gen<H>,430   config: PropTestConfig,431   property: suspend PropertyContext.(A, B, C, D, E, F, G, H) -> Unit432): PropertyContext {433   config.checkFailOnSeed()434   val constraints = config.constraints435      ?: config.iterations?.let { Constraints.iterations(it) }436      ?: Constraints.iterations(PropertyTesting.defaultIterationCount)437   val context = PropertyContext()438   val random = createRandom(config)439   genA.generate(random, config.edgeConfig)440      .zip(genB.generate(random, config.edgeConfig))441      .zip(genC.generate(random, config.edgeConfig))442      .zip(genD.generate(random, config.edgeConfig))443      .zip(genE.generate(random, config.edgeConfig))444      .zip(genF.generate(random, config.edgeConfig))445      .zip(genG.generate(random, config.edgeConfig))446      .zip(genH.generate(random, config.edgeConfig))447      .takeWhile { constraints.evaluate() }448      .forEach { (abcdefg, h) ->449         val (abcdef, g) = abcdefg450         val (abcde, f) = abcdef451         val (abcd, e) = abcde452         val (abc, d) = abcd453         val (ab, c) = abc454         val (a, b) = ab455         val shrinkfn = shrinkfn(a, b, c, d, e, f, g, h, property, config.shrinkingMode)456         config.listeners.forEach { it.beforeTest() }457         test(458            context,459            config,460            shrinkfn,461            listOf(a.value, b.value, c.value, d.value, e.value, f.value, g.value, h.value),462            listOf(463               genA.classifier,464               genB.classifier,465               genC.classifier,466               genD.classifier,467               genE.classifier,468               genF.classifier,469               genG.classifier,470               genH.classifier471            ),472            random.seed473         ) {474            context.property(a.value, b.value, c.value, d.value, e.value, f.value, g.value, h.value)475         }476         config.listeners.forEach { it.afterTest() }477      }478   context.outputClassifications(8, config, random.seed)479   context.checkMaxSuccess(config, random.seed)480   return context481}482suspend fun <A, B, C, D, E, F, G, H, I> proptest(483   genA: Gen<A>,484   genB: Gen<B>,485   genC: Gen<C>,486   genD: Gen<D>,487   genE: Gen<E>,488   genF: Gen<F>,489   genG: Gen<G>,490   genH: Gen<H>,491   genI: Gen<I>,492   config: PropTestConfig,493   property: suspend PropertyContext.(A, B, C, D, E, F, G, H, I) -> Unit494): PropertyContext {495   config.checkFailOnSeed()496   val constraints = config.constraints497      ?: config.iterations?.let { Constraints.iterations(it) }498      ?: Constraints.iterations(PropertyTesting.defaultIterationCount)499   val context = PropertyContext()500   val random = createRandom(config)501   genA.generate(random, config.edgeConfig)502      .zip(genB.generate(random, config.edgeConfig))503      .zip(genC.generate(random, config.edgeConfig))504      .zip(genD.generate(random, config.edgeConfig))505      .zip(genE.generate(random, config.edgeConfig))506      .zip(genF.generate(random, config.edgeConfig))507      .zip(genG.generate(random, config.edgeConfig))508      .zip(genH.generate(random, config.edgeConfig))509      .zip(genI.generate(random, config.edgeConfig))510      .takeWhile { constraints.evaluate() }511      .forEach { (abcdefgh, i) ->512         val (abcdefg, h) = abcdefgh513         val (abcdef, g) = abcdefg514         val (abcde, f) = abcdef515         val (abcd, e) = abcde516         val (abc, d) = abcd517         val (ab, c) = abc518         val (a, b) = ab519         val shrinkfn = shrinkfn(a, b, c, d, e, f, g, h, i, property, config.shrinkingMode)520         config.listeners.forEach { it.beforeTest() }521         test(522            context,523            config,524            shrinkfn,525            listOf(a.value, b.value, c.value, d.value, e.value, f.value, g.value, h.value, i.value),526            listOf(527               genA.classifier,528               genB.classifier,529               genC.classifier,530               genD.classifier,531               genE.classifier,532               genF.classifier,533               genG.classifier,534               genH.classifier,535               genI.classifier536            ),537            random.seed538         ) {539            context.property(a.value, b.value, c.value, d.value, e.value, f.value, g.value, h.value, i.value)540         }541         config.listeners.forEach { it.afterTest() }542      }543   context.outputClassifications(9, config, random.seed)544   context.checkMaxSuccess(config, random.seed)545   return context546}547suspend fun <A, B, C, D, E, F, G, H, I, J> proptest(548   genA: Gen<A>,549   genB: Gen<B>,550   genC: Gen<C>,551   genD: Gen<D>,552   genE: Gen<E>,553   genF: Gen<F>,554   genG: Gen<G>,555   genH: Gen<H>,556   genI: Gen<I>,557   genJ: Gen<J>,558   config: PropTestConfig,559   property: suspend PropertyContext.(A, B, C, D, E, F, G, H, I, J) -> Unit560): PropertyContext {561   config.checkFailOnSeed()562   val constraints = config.constraints563      ?: config.iterations?.let { Constraints.iterations(it) }564      ?: Constraints.iterations(PropertyTesting.defaultIterationCount)565   val context = PropertyContext()566   val random = createRandom(config)567   genA.generate(random, config.edgeConfig)568      .zip(genB.generate(random, config.edgeConfig))569      .zip(genC.generate(random, config.edgeConfig))570      .zip(genD.generate(random, config.edgeConfig))571      .zip(genE.generate(random, config.edgeConfig))572      .zip(genF.generate(random, config.edgeConfig))573      .zip(genG.generate(random, config.edgeConfig))574      .zip(genH.generate(random, config.edgeConfig))575      .zip(genI.generate(random, config.edgeConfig))576      .zip(genJ.generate(random, config.edgeConfig))577      .takeWhile { constraints.evaluate() }578      .forEach { (abcdefghi, j) ->579         val (abcdefgh, i) = abcdefghi580         val (abcdefg, h) = abcdefgh581         val (abcdef, g) = abcdefg582         val (abcde, f) = abcdef583         val (abcd, e) = abcde584         val (abc, d) = abcd585         val (ab, c) = abc586         val (a, b) = ab587         val shrinkfn = shrinkfn(a, b, c, d, e, f, g, h, i, j, property, config.shrinkingMode)588         config.listeners.forEach { it.beforeTest() }589         test(590            context,591            config,592            shrinkfn,593            listOf(a.value, b.value, c.value, d.value, e.value, f.value, g.value, h.value, i.value, j.value),594            listOf(595               genA.classifier,596               genB.classifier,597               genC.classifier,598               genD.classifier,599               genE.classifier,600               genF.classifier,601               genG.classifier,602               genH.classifier,603               genI.classifier,604               genJ.classifier605            ),606            random.seed607         ) {608            context.property(a.value, b.value, c.value, d.value, e.value, f.value, g.value, h.value, i.value, j.value)609         }610         config.listeners.forEach { it.afterTest() }611      }612   context.outputClassifications(10, config, random.seed)613   context.checkMaxSuccess(config, random.seed)614   return context615}616suspend fun <A, B, C, D, E, F, G, H, I, J, K> proptest(617   genA: Gen<A>,618   genB: Gen<B>,619   genC: Gen<C>,620   genD: Gen<D>,621   genE: Gen<E>,622   genF: Gen<F>,623   genG: Gen<G>,624   genH: Gen<H>,625   genI: Gen<I>,626   genJ: Gen<J>,627   genK: Gen<K>,628   config: PropTestConfig,629   property: suspend PropertyContext.(A, B, C, D, E, F, G, H, I, J, K) -> Unit630): PropertyContext {631   config.checkFailOnSeed()632   val constraints = config.constraints633      ?: config.iterations?.let { Constraints.iterations(it) }634      ?: Constraints.iterations(PropertyTesting.defaultIterationCount)635   val context = PropertyContext()636   val random = createRandom(config)637   genA.generate(random, config.edgeConfig)638      .zip(genB.generate(random, config.edgeConfig))639      .zip(genC.generate(random, config.edgeConfig))640      .zip(genD.generate(random, config.edgeConfig))641      .zip(genE.generate(random, config.edgeConfig))642      .zip(genF.generate(random, config.edgeConfig))643      .zip(genG.generate(random, config.edgeConfig))644      .zip(genH.generate(random, config.edgeConfig))645      .zip(genI.generate(random, config.edgeConfig))646      .zip(genJ.generate(random, config.edgeConfig))647      .zip(genK.generate(random, config.edgeConfig))648      .takeWhile { constraints.evaluate() }649      .forEach { (abcdefghij, k) ->650         val (abcdefghi, j) = abcdefghij651         val (abcdefgh, i) = abcdefghi652         val (abcdefg, h) = abcdefgh653         val (abcdef, g) = abcdefg654         val (abcde, f) = abcdef655         val (abcd, e) = abcde656         val (abc, d) = abcd657         val (ab, c) = abc658         val (a, b) = ab659         val shrinkfn = shrinkfn(a, b, c, d, e, f, g, h, i, j, k, property, config.shrinkingMode)660         config.listeners.forEach { it.beforeTest() }661         test(662            context,663            config,664            shrinkfn,665            listOf(a.value, b.value, c.value, d.value, e.value, f.value, g.value, h.value, i.value, j.value, k.value),666            listOf(667               genA.classifier,668               genB.classifier,669               genC.classifier,670               genD.classifier,671               genE.classifier,672               genF.classifier,673               genG.classifier,674               genH.classifier,675               genI.classifier,676               genJ.classifier,677               genK.classifier678            ),679            random.seed680         ) {681            context.property(682               a.value,683               b.value,684               c.value,685               d.value,686               e.value,687               f.value,688               g.value,689               h.value,690               i.value,691               j.value,692               k.value693            )694         }695         config.listeners.forEach { it.afterTest() }696      }697   context.outputClassifications(11, config, random.seed)698   context.checkMaxSuccess(config, random.seed)699   return context700}701suspend fun <A, B, C, D, E, F, G, H, I, J, K, L> proptest(702   genA: Gen<A>,703   genB: Gen<B>,704   genC: Gen<C>,705   genD: Gen<D>,706   genE: Gen<E>,707   genF: Gen<F>,708   genG: Gen<G>,709   genH: Gen<H>,710   genI: Gen<I>,711   genJ: Gen<J>,712   genK: Gen<K>,713   genL: Gen<L>,714   config: PropTestConfig,715   property: suspend PropertyContext.(A, B, C, D, E, F, G, H, I, J, K, L) -> Unit716): PropertyContext {717   config.checkFailOnSeed()718   val constraints = config.constraints719      ?: config.iterations?.let { Constraints.iterations(it) }720      ?: Constraints.iterations(PropertyTesting.defaultIterationCount)721   val context = PropertyContext()722   val random = createRandom(config)723   genA.generate(random, config.edgeConfig)724      .zip(genB.generate(random, config.edgeConfig))725      .zip(genC.generate(random, config.edgeConfig))726      .zip(genD.generate(random, config.edgeConfig))727      .zip(genE.generate(random, config.edgeConfig))728      .zip(genF.generate(random, config.edgeConfig))729      .zip(genG.generate(random, config.edgeConfig))730      .zip(genH.generate(random, config.edgeConfig))731      .zip(genI.generate(random, config.edgeConfig))732      .zip(genJ.generate(random, config.edgeConfig))733      .zip(genK.generate(random, config.edgeConfig))734      .zip(genL.generate(random, config.edgeConfig))735      .takeWhile { constraints.evaluate() }736      .forEach { (abcdefghijk, l) ->737         val (abcdefghij, k) = abcdefghijk738         val (abcdefghi, j) = abcdefghij739         val (abcdefgh, i) = abcdefghi740         val (abcdefg, h) = abcdefgh741         val (abcdef, g) = abcdefg742         val (abcde, f) = abcdef743         val (abcd, e) = abcde744         val (abc, d) = abcd745         val (ab, c) = abc746         val (a, b) = ab747         val shrinkfn = shrinkfn(a, b, c, d, e, f, g, h, i, j, k, l, property, config.shrinkingMode)748         config.listeners.forEach { it.beforeTest() }749         test(750            context,751            config,752            shrinkfn,753            listOf(754               a.value,755               b.value,756               c.value,757               d.value,758               e.value,759               f.value,760               g.value,761               h.value,762               i.value,763               j.value,764               k.value,765               l.value766            ),767            listOf(768               genA.classifier,769               genB.classifier,770               genC.classifier,771               genD.classifier,772               genE.classifier,773               genF.classifier,774               genG.classifier,775               genH.classifier,776               genI.classifier,777               genJ.classifier,778               genK.classifier,779               genL.classifier780            ),781            random.seed782         ) {783            context.property(784               a.value,785               b.value,786               c.value,787               d.value,788               e.value,789               f.value,790               g.value,791               h.value,792               i.value,793               j.value,794               k.value,795               l.value796            )797         }798         config.listeners.forEach { it.afterTest() }799      }800   context.outputClassifications(12, config, random.seed)801   context.checkMaxSuccess(config, random.seed)802   return context803}...

Full Screen

Full Screen

ClassifierArityTest.kt

Source:ClassifierArityTest.kt Github

copy

Full Screen

...7class ClassifierArityTest : FunSpec() {8   init {9      test("classifiers for prop test arity 2") {10         val out = captureStandardOut {11            checkAll<String, Int>(PropTestConfig(outputClassifications = true, seed = 678673131234)) { _, _ -> }12         }13         repeat(2) { k ->14            out.shouldContain("Label statistics for arg $k (1000 inputs):")15         }16      }17      test("classifiers for prop test arity 3") {18         val out = captureStandardOut {19            checkAll<Int, Int, Int>(20               PropTestConfig(21                  outputClassifications = true,22                  seed = 67867313123423               )24            ) { _, _, _ -> }25         }26         repeat(3) { k ->27            out.shouldContain("Label statistics for arg $k (1000 inputs):")28         }29      }30      test("classifiers for prop test arity 4") {31         val out = captureStandardOut {32            checkAll<Int, Int, Int, Int>(33               PropTestConfig(34                  outputClassifications = true,35                  seed = 67867313123436               )37            ) { _, _, _, _ -> }38         }39         repeat(4) { k ->40            out.shouldContain("Label statistics for arg $k (1000 inputs):")41         }42      }43      test("classifiers for prop test arity 5") {44         val out = captureStandardOut {45            checkAll<Int, Int, Int, Int, Int>(46               PropTestConfig(47                  outputClassifications = true,48                  seed = 67867313123449               )50            ) { _, _, _, _, _ -> }51         }52         repeat(5) { k ->53            out.shouldContain("Label statistics for arg $k (1000 inputs):")54         }55      }56      test("classifiers for prop test arity 6") {57         val out = captureStandardOut {58            checkAll<Int, Int, Int, Int, Int, Int>(59               PropTestConfig(60                  outputClassifications = true,61                  seed = 67867313123462               )63            ) { _, _, _, _, _, _ -> }64         }65         repeat(6) { k ->66            out.shouldContain("Label statistics for arg $k (1000 inputs):")67         }68      }69      test("classifiers for prop test arity 7") {70         val out = captureStandardOut {71            checkAll<Int, Int, Int, Int, Int, Int, Int>(72               PropTestConfig(73                  outputClassifications = true,74                  seed = 67867313123475               )76            ) { _, _, _, _, _, _, _ -> }77         }78         repeat(7) { k ->79            out.shouldContain("Label statistics for arg $k (1000 inputs):")80         }81      }82      test("classifiers for prop test arity 8") {83         val out = captureStandardOut {84            checkAll<Int, Int, Int, Int, Int, Int, Int, Int>(85               PropTestConfig(86                  outputClassifications = true,87                  seed = 67867313123488               )89            ) { _, _, _, _, _, _, _, _ -> }90         }91         repeat(8) { k ->92            out.shouldContain("Label statistics for arg $k (1000 inputs):")93         }94      }95      test("classifiers for prop test arity 9") {96         val out = captureStandardOut {97            checkAll<Int, Int, Int, Int, Int, Int, Int, Int, Int>(98               PropTestConfig(99                  outputClassifications = true,100                  seed = 678673131234101               )102            ) { _, _, _, _, _, _, _, _, _ -> }103         }104         repeat(9) { k ->105            out.shouldContain("Label statistics for arg $k (1000 inputs):")106         }107      }108      test("classifiers for prop test arity 10") {109         val out = captureStandardOut {110            checkAll<Int, Int, Int, Int, Int, Int, Int, Int, Int, Int>(111               PropTestConfig(112                  outputClassifications = true,113                  seed = 678673131234114               )115            ) { _, _, _, _, _, _, _, _, _, _ -> }116         }117         repeat(10) { k ->118            out.shouldContain("Label statistics for arg $k (1000 inputs):")119         }120      }121      test("classifiers for prop test arity 11") {122         val out = captureStandardOut {123            checkAll<Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int>(124               PropTestConfig(125                  outputClassifications = true,126                  seed = 678673131234127               )128            ) { _, _, _, _, _, _, _, _, _, _, _ -> }129         }130         repeat(11) { k ->131            out.shouldContain("Label statistics for arg $k (1000 inputs):")132         }133      }134      test("classifiers for prop test arity 12") {135         val out = captureStandardOut {136            checkAll<Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int>(137               PropTestConfig(138                  outputClassifications = true,139                  seed = 678673131234140               )141            ) { _, _, _, _, _, _, _, _, _, _, _, _ -> }142         }143         repeat(12) { k ->144            out.shouldContain("Label statistics for arg $k (1000 inputs):")145         }146      }147   }148}...

Full Screen

Full Screen

config.kt

Source:config.kt Github

copy

Full Screen

...11   var maxFilterAttempts: Int by AtomicProperty {12      1013   }14   var shouldPrintShrinkSteps: Boolean by AtomicProperty {15      sysprop("kotest.proptest.output.shrink-steps", true)16   }17   var shouldPrintGeneratedValues: Boolean by AtomicProperty {18      sysprop("kotest.proptest.output.generated-values", false)19   }20   var edgecasesBindDeterminism: Double by AtomicProperty {21      sysprop("kotest.proptest.arb.edgecases-bind-determinism", 0.9)22   }23   var defaultSeed: Long? by AtomicProperty {24      sysprop("kotest.proptest.default.seed", null) { it.toLong() }25   }26   var defaultMinSuccess: Int by AtomicProperty {27      sysprop("kotest.proptest.default.min-success", Int.MAX_VALUE)28   }29   var defaultMaxFailure: Int by AtomicProperty {30      sysprop("kotest.proptest.default.max-failure", 0)31   }32   var defaultIterationCount: Int by AtomicProperty {33      sysprop("kotest.proptest.default.iteration.count", 1000)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

DefaultClassifierTest.kt

Source:DefaultClassifierTest.kt Github

copy

Full Screen

...9class DefaultClassifierTest : FunSpec() {10   init {11      test("String classifier should be provided by default string arb") {12         val out = captureStandardOut {13            checkAll<String>(PropTestConfig(outputClassifications = true, seed = 123123123)) {}14         }15         println(out)16         out.shouldContain("Label statistics for arg 0 (1000 inputs):")17         out.shouldContain("ANY LENGTH LETTER OR DIGITS                                    13 (1%)")18         out.shouldContain("SINGLE CHARACTER LETTER                                        13 (1%)")19         out.shouldContain("EMPTY STRING                                                   11 (1%)")20         out.shouldContain("MAX LENGTH                                                     11 (1%)")21         out.shouldContain("OTHER                                                         952 (95%)")22      }23      test("int classifier should be provided by default int arb") {24         val out = captureStandardOut {25            checkAll<Int>(PropTestConfig(outputClassifications = true, seed = 9848976132)) {}26         }27         Arb.long()28         println(out)29         out.shouldContain("Label statistics for arg 0 (1000 inputs):")30         out.shouldContain("POSITIVE EVEN                                                 242 (24%)")31         out.shouldContain("POSITIVE ODD                                                  254 (25%)")32         out.shouldContain("NEGATIVE EVEN                                                 237 (24%)")33         out.shouldContain("MIN                                                             5 (1%)")34         out.shouldContain("NEGATIVE ODD                                                  254 (25%)")35         out.shouldContain("ZERO                                                            6 (1%)")36         out.shouldContain("MAX                                                             2 (1%)")37      }38      test("long classifier should be provided by default long arb") {39         val out = captureStandardOut {40            checkAll<Long>(PropTestConfig(outputClassifications = true, seed = 1234864124)) {}41         }42         println(out)43         out.shouldContain("Label statistics for arg 0 (1000 inputs):")44         out.shouldContain("NEGATIVE ODD                                                  234 (23%)")45         out.shouldContain("POSITIVE ODD                                                  258 (26%)")46         out.shouldContain("NEGATIVE EVEN                                                 251 (25%)")47         out.shouldContain("MIN                                                             3 (1%)")48         out.shouldContain("POSITIVE EVEN                                                 246 (25%)")49         out.shouldContain("MAX                                                             3 (1%)")50         out.shouldContain("ZERO                                                            5 (1%)")51      }52   }53}...

Full Screen

Full Screen

ConfigTests.kt

Source:ConfigTests.kt Github

copy

Full Screen

1package io.kotest.property2import io.kotest.assertions.throwables.shouldNotThrow3import io.kotest.matchers.shouldBe4import kotlin.native.concurrent.isFrozen5import kotlin.test.Test6class ConfigTests {7   @Test8   fun `The PropertyTesting object is frozen`() {9      PropertyTesting.isFrozen shouldBe true10   }11   @Test12   fun `The frozen PropertyTesting object's properties can be modified without exception`() {13         shouldNotThrow<kotlin.native.concurrent.InvalidMutabilityException> {14            PropertyTesting.maxFilterAttempts = PropertyTesting.maxFilterAttempts15            PropertyTesting.shouldPrintShrinkSteps = PropertyTesting.shouldPrintShrinkSteps16            PropertyTesting.shouldPrintGeneratedValues = PropertyTesting.shouldPrintGeneratedValues17            PropertyTesting.edgecasesBindDeterminism = PropertyTesting.edgecasesBindDeterminism18            PropertyTesting.defaultSeed = PropertyTesting.defaultSeed19            PropertyTesting.defaultMinSuccess = PropertyTesting.defaultMinSuccess20            PropertyTesting.defaultMaxFailure = PropertyTesting.defaultMaxFailure21            PropertyTesting.defaultIterationCount = PropertyTesting.defaultIterationCount22            PropertyTesting.defaultShrinkingMode = PropertyTesting.defaultShrinkingMode23            PropertyTesting.defaultListeners = PropertyTesting.defaultListeners24            PropertyTesting.defaultEdgecasesGenerationProbability = PropertyTesting.defaultEdgecasesGenerationProbability25            PropertyTesting.defaultOutputClassifications = PropertyTesting.defaultOutputClassifications26            true27         }28   }29}...

Full Screen

Full Screen

DailyBalancesPropKotestTest.kt

Source:DailyBalancesPropKotestTest.kt Github

copy

Full Screen

...12  describe("properties") {13    val arbBalance = Arb.bind(Arb.localDate(), Arb.bigDecimal()) { d, a -> Balance(d, a) }14    fun arbUniqueList(minLength: Int = 0) = Arb.list(arbBalance, minLength..100).map { it.distinctBy { it.date } }15    it("contains all original elements") {16      checkAll(PropTestConfig(outputClassifications = true), arbUniqueList()) { list ->17        val result = list.expandToDaily()18        result.shouldContainAll(list)19      }20    }21    it("result is strictly increasing by the balance date") {22      checkAll(arbUniqueList()) { list ->23        val result = list.expandToDaily()24        result.shouldBeStrictlyIncreasingWith(compareBy { it.date })25      }26    }27    it("returns the whole range") {28      checkAll(arbUniqueList(minLength = 1)) { list ->29        val result = list.expandToDaily()30        result.map { it.date } shouldBe wholeDateRange(result.minOf { it.date }, result.maxOf { it.date })...

Full Screen

Full Screen

LabelsReporter.kt

Source:LabelsReporter.kt Github

copy

Full Screen

...3import io.kotest.property.PropertyResult4import kotlin.math.max5import kotlin.math.roundToInt6/**7 * Pluggable interface for outputting input value labels used in property testing.8 */9@ExperimentalKotest10interface LabelsReporter {11   fun output(result: PropertyResult)12}13@ExperimentalKotest14object StandardLabelsReporter : LabelsReporter {15   private fun row(label: String, count: Int, attempts: Int, countPad: Int) {16      val percentage = max(((count / attempts.toDouble() * 100.0)).roundToInt(), 1)17      println("${label.padEnd(60, ' ')} ${count.toString().padStart(countPad, ' ')} ($percentage%)")18   }19   override fun output(result: PropertyResult) {20      val countPad = result.attempts.toString().length21      result.inputs.forEach { arg ->22         println("Label statistics for arg $arg (${result.attempts} inputs):")23         result.labels[arg]?.forEach { (label, count) ->24            row(label, count, result.attempts, countPad)25         }26         val other = result.attempts - (result.labels[arg]?.values?.sum() ?: 0)27         if (other > 0) {28            row("OTHER", other, result.attempts, countPad)29         }30         println()31      }32   }33}...

Full Screen

Full Screen

output.kt

Source:output.kt Github

copy

Full Screen

2import io.kotest.property.PropTestConfig3import io.kotest.property.PropertyContext4import io.kotest.property.PropertyResult5import io.kotest.property.PropertyTesting6fun PropertyContext.outputClassifications(inputs: Int, config: PropTestConfig, seed: Long) {7   val result =8      PropertyResult(List(inputs) { it.toString() }, seed, attempts(), successes(), failures(), autoclassifications())9   if (config.outputClassifications) config.labelsReporter.output(result)10}...

Full Screen

Full Screen

output

Using AI Code Generation

copy

Full Screen

1+import io.kotest.property.classifications.output2+import io.kotest.property.classifications.printClassification3+import io.kotest.property.classifications.printSummary4+import io.kotest.property.classifications.summary5+class PropertyTest : FunSpec({6+   test("property test") {7+      checkAll(1000, Gen.int()) { a ->8+      }9+   }10+   test("property test with labels") {11+      checkAll(1000, Gen.int().label("a")) { a ->12+      }13+   }14+   test("property test with labels and output") {15+      checkAll(1000, Gen.int().label("a"), output) { a ->16+      }17+   }18+   test("property test with labels and summary") {19+      checkAll(1000, Gen.int().label("a"), summary) { a ->20+      }21+   }22+   test("property test with labels and printSummary") {23+      checkAll(1000, Gen.int().label("a"), printSummary) { a ->24+      }25+   }26+   test("property test with labels and printClassification") {27+      checkAll(1000, Gen.int().label("a"), printClassification) { a ->28+      }29+   }30+   test("property test with labels and printClassification and printSummary") {31+      checkAll(1000, Gen.int().label("a"), printClassification, printSummary) { a ->32+      }33+   }34+   test("property test with labels and printClassification and printSummary and output") {35+      checkAll(1000, Gen.int().label("a"), printClassification, printSummary, output) { a ->36+      }37+   }38+   test("property test with labels and printClassification and output") {39+      checkAll(1000, Gen.int().label("a"), printClassification, output) { a ->

Full Screen

Full Screen

output

Using AI Code Generation

copy

Full Screen

1+import io.kotest.property.classifications.Output2+import io.kotest.property.classifications.kotestOutput3+import io.kotest.property.classifications.Output4+import io.kotest.property.classifications.kotestOutput5+import io.kotest.property.classifications.Output6+import io.kotest.property.classifications.kotestOutput7+import io.kotest.property.classifications.Output8+import io.kotest.property.classifications.kotestOutput9+import io.kotest.property.classifications.Output10+import io.kotest.property.classifications.kotestOutput11+import io.kotest.property.classifications.Output12+import io.kotest.property.classifications.kotestOutput13+import io.kotest.property.classifications.Output14+import io.kotest.property.classifications.kotestOutput15+import io.kotest.property.classifications.Output16+import io.kotest.property.classifications.kotestOutput17+import io.kotest.property.classifications.Output18+import io.kotest.property.classifications.kotestOutput19+import io.kotest.property.classifications.Output20+import io.kotest.property.classifications.kotestOutput21+import io.kotest.property.classifications.Output22+import io.kotest.property.classifications.kotestOutput23+import io.kotest.property.classifications.Output24+import io.kotest.property.classifications.kotestOutput

Full Screen

Full Screen

output

Using AI Code Generation

copy

Full Screen

1+import io.kotest.property.classifications.output2+import io.kotest.property.classifications.printClassification3+import io.kotest.property.classifications.Classification4+import io.kotest.property.classifications.printClassification5+class CustomClassificationTest : FunSpec({6+    test("Custom classification test") {7+        val output = output()8+        forAll<Int> { a ->9+            when {10+                a > 0 -> output.positive(a)11+                a < 0 -> output.negative(a)12+                else -> output.zero(a)13+            }14+        }15+        output.printClassification()16+    }17+})18+class CustomClassification(val name: String, val count: Int = 0) : Classification19+class CustomClassificationOutput : AbstractClassificationOutput() {20+    val customClassification = mutableListOf<CustomClassification>()21+    fun customClassification(name: String) {22+        val index = customClassification.indexOfFirst { it.name == name }23+        if (index == -1) {24+            customClassification.add(CustomClassification(name, 1))25+        } else {26+            customClassification[index] = CustomClassification(name, customClassification[index].count + 1)27+        }28+    }29+}

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.

Most used methods in output

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful