Best Kotest code snippet using io.kotest.property.arbitrary.const
Generators.kt
Source:Generators.kt
...20import io.kotest.property.arbitrary.bind21import io.kotest.property.arbitrary.boolean22import io.kotest.property.arbitrary.byte23import io.kotest.property.arbitrary.choice24import io.kotest.property.arbitrary.constant25import io.kotest.property.arbitrary.filter26import io.kotest.property.arbitrary.flatMap27import io.kotest.property.arbitrary.int28import io.kotest.property.arbitrary.long29import io.kotest.property.arbitrary.map30import io.kotest.property.arbitrary.numericDoubles31import io.kotest.property.arbitrary.numericFloats32import io.kotest.property.arbitrary.of33import io.kotest.property.arbitrary.orNull34import io.kotest.property.arbitrary.short35import io.kotest.property.arbitrary.string36import kotlin.Result.Companion.failure37import kotlin.Result.Companion.success38import kotlin.math.abs39public fun <A, B> Arb.Companion.functionAToB(arb: Arb<B>): Arb<(A) -> B> =40 arb.map { b: B -> { _: A -> b } }41public fun <A> Arb.Companion.functionAAToA(arb: Arb<A>): Arb<(A, A) -> A> =42 arb.map { a: A -> { _: A, _: A -> a } }43public fun <A, B> Arb.Companion.functionBAToB(arb: Arb<B>): Arb<(B, A) -> B> =44 arb.map { b: B -> { _: B, _: A -> b } }45public fun <A, B> Arb.Companion.functionABToB(arb: Arb<B>): Arb<(A, B) -> B> =46 arb.map { b: B -> { _: A, _: B -> b } }47public fun <A> Arb.Companion.functionToA(arb: Arb<A>): Arb<() -> A> =48 arb.map { a: A -> { a } }49public fun Arb.Companion.throwable(): Arb<Throwable> =50 Arb.of(listOf(RuntimeException(), NoSuchElementException(), IllegalArgumentException()))51public fun <A> Arb.Companion.result(arbA: Arb<A>): Arb<Result<A>> =52 Arb.choice(arbA.map(::success), throwable().map(::failure))53public fun Arb.Companion.doubleSmall(): Arb<Double> =54 Arb.numericDoubles(from = 0.0, to = 100.0)55public fun Arb.Companion.floatSmall(): Arb<Float> =56 Arb.numericFloats(from = 0F, to = 100F)57public fun Arb.Companion.intSmall(factor: Int = 10000): Arb<Int> =58 Arb.int((Int.MIN_VALUE / factor)..(Int.MAX_VALUE / factor))59public fun Arb.Companion.byteSmall(): Arb<Byte> =60 Arb.byte(min = (Byte.MIN_VALUE / 10).toByte(), max = (Byte.MAX_VALUE / 10).toByte())61public fun Arb.Companion.shortSmall(): Arb<Short> {62 val range = (Short.MIN_VALUE / 1000)..(Short.MAX_VALUE / 1000)63 return Arb.short().filter { it in range }64}65public fun Arb.Companion.longSmall(): Arb<Long> =66 Arb.long((Long.MIN_VALUE / 100000L)..(Long.MAX_VALUE / 100000L))67public fun <A, B, C, D> Arb.Companion.tuple4(arbA: Arb<A>, arbB: Arb<B>, arbC: Arb<C>, arbD: Arb<D>): Arb<Tuple4<A, B, C, D>> =68 Arb.bind(arbA, arbB, arbC, arbD, ::Tuple4)69public fun <A, B, C, D, E> Arb.Companion.tuple5(70 arbA: Arb<A>,71 arbB: Arb<B>,72 arbC: Arb<C>,73 arbD: Arb<D>,74 arbE: Arb<E>75): Arb<Tuple5<A, B, C, D, E>> =76 Arb.bind(arbA, arbB, arbC, arbD, arbE, ::Tuple5)77public fun <A, B, C, D, E, F> Arb.Companion.tuple6(78 arbA: Arb<A>,79 arbB: Arb<B>,80 arbC: Arb<C>,81 arbD: Arb<D>,82 arbE: Arb<E>,83 arbF: Arb<F>84): Arb<Tuple6<A, B, C, D, E, F>> =85 Arb.bind(arbA, arbB, arbC, arbD, arbE, arbF, ::Tuple6)86public fun <A, B, C, D, E, F, G> Arb.Companion.tuple7(87 arbA: Arb<A>,88 arbB: Arb<B>,89 arbC: Arb<C>,90 arbD: Arb<D>,91 arbE: Arb<E>,92 arbF: Arb<F>,93 arbG: Arb<G>94): Arb<Tuple7<A, B, C, D, E, F, G>> =95 Arb.bind(arbA, arbB, arbC, arbD, arbE, arbF, arbG, ::Tuple7)96public fun <A, B, C, D, E, F, G, H> Arb.Companion.tuple8(97 arbA: Arb<A>,98 arbB: Arb<B>,99 arbC: Arb<C>,100 arbD: Arb<D>,101 arbE: Arb<E>,102 arbF: Arb<F>,103 arbG: Arb<G>,104 arbH: Arb<H>105): Arb<Tuple8<A, B, C, D, E, F, G, H>> =106 Arb.bind(107 Arb.tuple7(arbA, arbB, arbC, arbD, arbE, arbF, arbG),108 arbH109 ) { (a, b, c, d, e, f, g), h ->110 Tuple8(a, b, c, d, e, f, g, h)111 }112public fun <A, B, C, D, E, F, G, H, I> Arb.Companion.tuple9(113 arbA: Arb<A>,114 arbB: Arb<B>,115 arbC: Arb<C>,116 arbD: Arb<D>,117 arbE: Arb<E>,118 arbF: Arb<F>,119 arbG: Arb<G>,120 arbH: Arb<H>,121 arbI: Arb<I>122): Arb<Tuple9<A, B, C, D, E, F, G, H, I>> =123 Arb.bind(124 Arb.tuple8(arbA, arbB, arbC, arbD, arbE, arbF, arbG, arbH),125 arbI126 ) { (a, b, c, d, e, f, g, h), i ->127 Tuple9(a, b, c, d, e, f, g, h, i)128 }129public fun <A, B, C, D, E, F, G, H, I, J> Arb.Companion.tuple10(130 arbA: Arb<A>,131 arbB: Arb<B>,132 arbC: Arb<C>,133 arbD: Arb<D>,134 arbE: Arb<E>,135 arbF: Arb<F>,136 arbG: Arb<G>,137 arbH: Arb<H>,138 arbI: Arb<I>,139 arbJ: Arb<J>140): Arb<Tuple10<A, B, C, D, E, F, G, H, I, J>> =141 Arb.bind(142 Arb.tuple9(arbA, arbB, arbC, arbD, arbE, arbF, arbG, arbH, arbI),143 arbJ144 ) { (a, b, c, d, e, f, g, h, i), j ->145 Tuple10(a, b, c, d, e, f, g, h, i, j)146 }147public fun Arb.Companion.nonZeroInt(): Arb<Int> = Arb.int().filter { it != 0 }148public fun Arb.Companion.intPredicate(): Arb<(Int) -> Boolean> =149 Arb.nonZeroInt().flatMap { num ->150 val absNum = abs(num)151 Arb.of(152 listOf<(Int) -> Boolean>(153 { it > num },154 { it <= num },155 { it % absNum == 0 },156 { it % absNum == absNum - 1 }157 )158 )159 }160public fun <A> Arb.Companion.endo(arb: Arb<A>): Arb<Endo<A>> = arb.map { a: A -> Endo<A> { a } }161public fun <B> Arb.Companion.option(arb: Arb<B>): Arb<Option<B>> =162 arb.orNull().map { it.toOption() }163public fun <E, A> Arb.Companion.either(arbE: Arb<E>, arbA: Arb<A>): Arb<Either<E, A>> {164 val arbLeft = arbE.map { Either.Left(it) }165 val arbRight = arbA.map { Either.Right(it) }166 return Arb.choice(arbLeft, arbRight)167}168public fun <E, A> Arb<E>.or(arbA: Arb<A>): Arb<Either<E, A>> = Arb.either(this, arbA)169public fun <E, A> Arb.Companion.validated(arbE: Arb<E>, arbA: Arb<A>): Arb<Validated<E, A>> =170 Arb.either(arbE, arbA).map { Validated.fromEither(it) }171public fun Arb.Companion.unit(): Arb<Unit> =172 Arb.constant(Unit)173public fun <A, B> Arb.Companion.ior(arbA: Arb<A>, arbB: Arb<B>): Arb<Ior<A, B>> =174 arbA.alignWith(arbB) { it }175public fun <A, B> Arb.Companion.arbConst(arb: Arb<A>): Arb<Const<A, B>> =176 arb.map { Const<A, B>(it) }177public fun <A> Arb<A>.eval(): Arb<Eval<A>> =178 map { Eval.now(it) }179private fun <A, B, R> Arb<A>.alignWith(arbB: Arb<B>, transform: (Ior<A, B>) -> R): Arb<R> =180 Arb.bind(this, arbB) { a, b -> transform(Ior.Both(a, b)) }181public fun Arb.Companion.suspendFunThatReturnsEitherAnyOrAnyOrThrows(): Arb<suspend () -> Either<Any, Any>> =182 choice(183 suspendFunThatReturnsAnyRight(),184 suspendFunThatReturnsAnyLeft(),185 suspendFunThatThrows()186 )...
RealTest.kt
Source:RealTest.kt
1package com.mattmik.rapira.objects2import com.mattmik.rapira.CONST_YES3import io.kotest.core.spec.style.WordSpec4import io.kotest.data.forAll5import io.kotest.data.row6import io.kotest.property.Arb7import io.kotest.property.arbitrary.double8import io.kotest.property.arbitrary.negativeInts9import io.kotest.property.arbitrary.positiveDoubles10import io.kotest.property.arbitrary.positiveInts11import io.kotest.property.checkAll12import kotlin.math.exp13import kotlin.math.ln14class RealTest : WordSpec({15 "plus" should {16 "succeed with real when given integer" {17 checkAll<Double, Int> { a, b ->18 Real(a) + RInteger(b) shouldSucceedWith Real(a + b)19 }20 }21 "succeed with real when given real" {22 checkAll<Double, Double> { a, b ->23 Real(a) + Real(b) shouldSucceedWith Real(a + b)24 }25 }26 "error when given other types" {27 forAll(28 row(Empty),29 row(Procedure()),30 row(Function()),31 row(CONST_YES),32 row(Text("hello")),33 row(Sequence())34 ) { obj ->35 (Real(123.0) + obj).shouldError()36 }37 }38 }39 "minus" should {40 "succeed with real when given integer" {41 checkAll<Double, Int> { a, b ->42 Real(a) - RInteger(b) shouldSucceedWith Real(a - b)43 }44 }45 "succeed with real when given real" {46 checkAll<Double, Double> { a, b ->47 Real(a) - Real(b) shouldSucceedWith Real(a - b)48 }49 }50 "error when given other types" {51 forAll(52 row(Empty),53 row(Procedure()),54 row(Function()),55 row(CONST_YES),56 row(Text("hello")),57 row(Sequence())58 ) { obj ->59 (Real(123.0) - obj).shouldError()60 }61 }62 }63 "negate" should {64 "succeed with real" {65 checkAll<Double> { num ->66 Real(num).negate() shouldSucceedWith Real(-num)67 }68 }69 }70 "times" should {71 "succeed with real when given integer" {72 checkAll<Double, Int> { a, b ->73 Real(a) * RInteger(b) shouldSucceedWith Real(a * b)74 }75 }76 "succeed with real when given real" {77 checkAll<Double, Double> { a, b ->78 Real(a) * Real(b) shouldSucceedWith Real(a * b)79 }80 }81 "error when given other types" {82 forAll(83 row(Empty),84 row(Procedure()),85 row(Function()),86 row(CONST_YES),87 row(Text("hello")),88 row(Sequence())89 ) { obj ->90 (Real(123.0) * obj).shouldError()91 }92 }93 }94 "div" should {95 "succeed with real when given positive integer" {96 checkAll(Arb.double(), Arb.positiveInts()) { a, b ->97 Real(a) / RInteger(b) shouldSucceedWith Real(a / b)98 }99 }100 "succeed with real when given negative integer" {101 checkAll(Arb.double(), Arb.negativeInts()) { a, b ->102 Real(a) / RInteger(b) shouldSucceedWith Real(a / b)103 }104 }105 "error when given integer zero" {106 checkAll<Double> { num ->107 (num.toReal() / RInteger(0)).shouldError()108 }109 }110 "succeed with real when given positive real" {111 checkAll(Arb.double(), Arb.positiveDoubles()) { a, b ->112 Real(a) / Real(b) shouldSucceedWith Real(a / b)113 }114 }115 "succeed with real when given negative real" {116 checkAll(Arb.double(), Arb.positiveDoubles()) { a, b ->117 Real(a) / Real(-b) shouldSucceedWith Real(a / -b)118 }119 }120 "error when given real zero" {121 checkAll<Double> { num ->122 (num.toReal() / Real(0.0)).shouldError()123 (num.toReal() / Real(-0.0)).shouldError()124 }125 }126 "error when given other types" {127 forAll(128 row(Empty),129 row(Procedure()),130 row(Function()),131 row(CONST_YES),132 row(Text("hello")),133 row(Sequence())134 ) { obj ->135 (Real(123.0) / obj).shouldError()136 }137 }138 }139 "power" should {140 "succeed with real when given integer" {141 checkAll<Double, Int> { a, b ->142 Real(a).power(RInteger(b)) shouldSucceedWith exp(ln(a) * b).toReal()143 }144 }145 "succeed with real when given real" {146 checkAll<Double, Double> { a, b ->147 Real(a).power(Real(b)) shouldSucceedWith exp(ln(a) * b).toReal()148 }149 }150 "error when given other types" {151 forAll(152 row(Empty),153 row(Procedure()),154 row(Function()),155 row(CONST_YES),156 row(Text("hello")),157 row(Sequence())158 ) { obj ->159 Real(123.0).power(obj).shouldError()160 }161 }162 }163 "compare" should {164 "succeed when given integer" {165 checkAll<Double, Int> { a, b ->166 a.toReal().compare(b.toRInteger()) shouldSucceedWith a.compareTo(b)167 }168 }169 "succeed when given real" {170 checkAll<Double, Double> { a, b ->171 a.toReal().compare(b.toReal()) shouldSucceedWith a.compareTo(b)172 }173 }174 "error when given other types" {175 forAll(176 row(Empty),177 row(Procedure()),178 row(Function()),179 row(CONST_YES),180 row(Text("hello")),181 row(Sequence())182 ) { obj ->183 Real(123.0).compare(obj).shouldError()184 }185 }186 }187 "toString" should {188 "return user friendly representation" {189 checkAll<Double> { num ->190 Real(num) shouldConvertToString "$num"191 }192 }193 }194})...
CategoryRepositoryCreateSpec.kt
Source:CategoryRepositoryCreateSpec.kt
...28class CategoryRepositoryCreateSpec(29 private val categoryRepository: CategoryRepository30) : ExpectSpec() {31 companion object {32 private const val ONE_TO_FIFTY_MESSAGE = "í¬ê¸°ê° 0ìì 50 ì¬ì´ì¬ì¼ í©ëë¤"33 }34 init {35 context("Category ìì±ì í ë") {36 val targetCategory = Mock.category().single()37 expect("Nameë§ ìì¼ë©´ Categoryê° ìì±ëë¤.") {38 val savedCategory = categoryRepository.save(targetCategory)39 savedCategory.id shouldNot beNull()40 savedCategory.name shouldBe targetCategory.name41 }42 expect("Nameì´ ë¹ì´ìì´ë Categoryê° ìì±ëë¤.") {43 targetCategory.name = ""44 val savedCategory = categoryRepository.save(targetCategory)45 savedCategory.id shouldNot beNull()46 savedCategory.name shouldBe targetCategory.name47 }48 expect("Nameê³¼ íì Category ì ë³´ë¡ Categoryê° ìì±ëë¤.") {49 val categoryChildren = Mock.category().chunked(10, 10).single()50 targetCategory.children = categoryChildren51 val savedCategory = categoryRepository.save(targetCategory)52 savedCategory.id shouldNot beNull()53 savedCategory.name shouldBe targetCategory.name54 savedCategory.children shouldNot beNull()55 savedCategory.children!! shouldHaveSize categoryChildren.size56 }57 expect("Nameê³¼ 2Depthì íì Categoriesë¡ Categoryê° ìì±ëë¤.") {58 val childrenOfChildrenOfChildren = Mock.category().chunked(10, 10).single()59 val childrenOfChildren = Mock.category(children = childrenOfChildrenOfChildren).chunked(10, 10).single()60 val categoryChildren = Mock.category(children = childrenOfChildren).chunked(20, 20).single()61 targetCategory.children = categoryChildren62 val savedCategory = categoryRepository.save(targetCategory)63 savedCategory.id shouldNot beNull()64 savedCategory.name shouldBe targetCategory.name65 savedCategory.children shouldNot beNull()66 savedCategory.children!! shouldHaveSize categoryChildren.size67 savedCategory.children!!.forEach { children ->68 children.children shouldNot beNull()69 children.children!! shouldHaveSize childrenOfChildren.size70 children.children!!.forEach { childrenOfChildren ->71 childrenOfChildren.children shouldNot beNull()72 childrenOfChildren.children!! shouldHaveSize childrenOfChildrenOfChildren.size73 }74 }75 }76 expect("Nameì´ ìê³ì¹ë¥¼ ì´ê³¼íë©´ Category를 ìì±í ì ìë¤.") {77 val nameThreshold = 5178 targetCategory.name = Arb.string(nameThreshold, nameThreshold).next()79 val constraintViolationException = shouldThrow<ConstraintViolationException> {80 categoryRepository.save(targetCategory)81 }82 constraintViolationException.constraintViolations shouldHave83 singleElement {84 isEqualCheckOneToFiftyMessage(it) && isEqualTestName(it, targetCategory)85 }86 }87 }88 }89 private fun isEqualCheckOneToFiftyMessage(it: ConstraintViolation<*>) =90 it.message == ONE_TO_FIFTY_MESSAGE91 private fun isEqualTestName(92 it: ConstraintViolation<*>,93 targetCategory: Category94 ) = it.invalidValue.toString() == targetCategory.name95}...
TextTest.kt
Source:TextTest.kt
1package com.mattmik.rapira.objects2import com.mattmik.rapira.CONST_YES3import io.kotest.core.spec.style.WordSpec4import io.kotest.data.forAll5import io.kotest.data.row6import io.kotest.property.Arb7import io.kotest.property.arbitrary.negativeInts8import io.kotest.property.arbitrary.positiveInts9import io.kotest.property.arbitrary.string10import io.kotest.property.checkAll11class TextTest : WordSpec({12 "plus" should {13 "succeed with text when given text" {14 checkAll<String, String> { a, b ->15 Text(a) + Text(b) shouldSucceedWith Text(a + b)16 }17 }18 "error when given other types" {19 forAll(20 row(Empty),21 row(Procedure()),22 row(Function()),23 row(RInteger(1)),24 row(CONST_YES),25 row(Real(1.0)),26 row(Sequence())27 ) { obj ->28 (Text("Hello, world!") + obj).shouldError()29 }30 }31 }32 "times" should {33 "succeed with empty string when given 0" {34 checkAll<String> { str ->35 Text(str) * RInteger(0) shouldSucceedWith Text("")36 }37 }38 "succeed with text when given positive integer" {39 checkAll(Arb.string(), Arb.positiveInts(max = 500)) { str, num ->40 Text(str) * RInteger(num) shouldSucceedWith str.repeat(num).toText()41 }42 }43 "error when given negative integer" {44 checkAll(Arb.string(), Arb.negativeInts()) { str, num ->45 (str.toText() * num.toRInteger()).shouldError()46 }47 }48 "error when given other types" {49 forAll(50 row(Empty),51 row(Procedure()),52 row(Function()),53 row(Text("Hello, world!")),54 row(CONST_YES),55 row(Real(1.0)),56 row(Sequence())57 ) { obj ->58 (Text("Hello, world!") * obj).shouldError()59 }60 }61 }62 "length" should {63 "succeed with integer" {64 checkAll<String> { str ->65 Text(str).length() shouldSucceedWith RInteger(str.length)66 }67 }68 }69 "element at" should {70 val text = "case".toText()71 "succeed with text when given valid integer" {72 text.elementAt(RInteger(2)) shouldSucceedWith "a".toText()73 }74 "error when given out of bounds integer" {75 text.elementAt(RInteger(0)).shouldError()76 text.elementAt(RInteger(5)).shouldError()77 }78 "error when given other types" {79 forAll(80 row(Empty),81 row(Procedure()),82 row(Function()),83 row(Text("Hello, world!")),84 row(CONST_YES),85 row(Real(1.0)),86 row(Sequence())87 ) { obj ->88 Text("Hello, world!").elementAt(obj).shouldError()89 }90 }91 }92 "slice" should {93 "succeed with text when given integer" {94 val text = Text("Hello, world!")95 text.slice(null, null) shouldSucceedWith text96 text.slice(8.toRInteger(), null) shouldSucceedWith "world!".toText()97 text.slice(4.toRInteger(), 9.toRInteger()) shouldSucceedWith "lo, wo".toText()98 text.slice(null, 5.toRInteger()) shouldSucceedWith "Hello".toText()99 text.slice(1.toRInteger(), 0.toRInteger()) shouldSucceedWith "".toText()100 text.slice(14.toRInteger(), 13.toRInteger()) shouldSucceedWith "".toText()101 }102 "error when start index is out of bounds" {103 val text = Text("Hello, world!")104 text.slice(0.toRInteger(), null).shouldError()105 text.slice((-1).toRInteger(), null).shouldError()106 }107 "error when end index is out of bounds" {108 val text = Text("Hello, world!")109 text.slice(null, 14.toRInteger()).shouldError()110 }111 "error when given other types" {112 forAll(113 row(Empty),114 row(Procedure()),115 row(Function()),116 row(Text("Hello, world!")),117 row(CONST_YES),118 row(Real(1.0)),119 row(Sequence())120 ) { obj ->121 Text("Hello, world!").slice(null, obj).shouldError()122 Text("Hello, world!").slice(obj, null).shouldError()123 Text("Hello, world!").slice(obj, obj).shouldError()124 }125 }126 }127 "toString" should {128 "return user friendly representation" {129 Text("Hello, world!") shouldConvertToString "\"Hello, world!\""130 Text("How about some \"\"double quotes\"\"? Fancy, eh?") shouldConvertToString "\"How about some \"double quotes\"? Fancy, eh?\""131 }132 }133})...
SnowflakeTest.kt
Source:SnowflakeTest.kt
...14import io.kotest.property.exhaustive.azstring15import org.tesserakt.diskordin.core.data.Snowflake.ConstructionError.LessThenDiscordEpoch16import org.tesserakt.diskordin.core.data.Snowflake.ConstructionError.NotNumber17import kotlin.random.nextLong18private const val MIN_SNOWFLAKE = 4194305L19@ExperimentalUnsignedTypes20class SnowflakeTest : FunSpec() {21 private val snowflakes = arbitrary { it.random.nextLong(MIN_SNOWFLAKE..Long.MAX_VALUE) }22 init {23 test("Snowflake.toString should return number in string") {24 checkAll(snowflakes) {25 it.asSnowflake().toString() shouldBe "$it"26 }27 }28 context("Non-safe converts should throw errors comparing their rules") {29 test("String, that hasn't digits") {30 checkAll(Exhaustive.azstring(1..30)) {31 shouldThrow<IllegalArgumentException> {32 it.asSnowflake()...
EvalJvmTest.kt
Source:EvalJvmTest.kt
...31 )32 }33 }34 companion object {35 const val maxDepth = 1000036 fun build(leaf: () -> Eval<Int>, os: List<O>) = run {37 tailrec fun step(i: Int, leaf: () -> Eval<Int>, cbs: MutableList<(Eval<Int>) -> Eval<Int>>): Eval<Int> =38 if (i >= os.size) {39 cbs.fold(leaf()) { e, f -> f(e) }40 } else {41 val o = os[i]42 when (o) {43 is O.Defer -> Eval.defer {44 @Suppress("NON_TAIL_RECURSIVE_CALL")45 step(i + 1, leaf, cbs)46 }47 is O.Memoize -> step(i + 1, leaf, cbs.also { it.add(0) { e: Eval<Int> -> e.memoize() } })48 is O.Map -> step(i + 1, leaf, cbs.also { it.add(0) { e: Eval<Int> -> e.map(o.f) } })49 is O.FlatMap -> step(i + 1, leaf, cbs.also { it.add(0) { e: Eval<Int> -> e.flatMap(o.f) } })...
Date.kt
Source:Date.kt
2import io.kotest.property.Arb3import io.kotest.property.arbitrary.long4import io.kotest.property.arbitrary.map5import java.util.*6private const val TWENTY_FOUR_HOURS = 864000007private const val LAST_HOUR = 238private const val LAST_MINUTE = 599private const val LAST_SECOND = 5910fun Calendar.startOfToday(): Date {11 set(Calendar.HOUR_OF_DAY, 0)12 set(Calendar.MINUTE, 0)13 set(Calendar.SECOND, 0)14 return time15}16fun Calendar.startOfYesterday(): Date {17 return Date(startOfToday().time - TWENTY_FOUR_HOURS)18}19fun Calendar.endOfToday(): Date {20 set(Calendar.HOUR_OF_DAY, LAST_HOUR)21 set(Calendar.MINUTE, LAST_MINUTE)22 set(Calendar.SECOND, LAST_SECOND)23 return time...
ConsInstanceTest.kt
Source:ConsInstanceTest.kt
1package arrow.optics.instances2import arrow.core.test.UnitSpec3import arrow.core.test.generators.functionAToB4import arrow.optics.test.laws.PrismLaws5import arrow.optics.typeclasses.Cons6import io.kotest.property.Arb7import io.kotest.property.arbitrary.char8import io.kotest.property.arbitrary.int9import io.kotest.property.arbitrary.list10import io.kotest.property.arbitrary.pair11import io.kotest.property.arbitrary.string12class ConsInstanceTest : UnitSpec() {13 init {14 testLaws(15 "Const list - ",16 PrismLaws.laws(17 prism = Cons.list<Int>().cons(),18 aGen = Arb.list(Arb.int()),19 bGen = Arb.pair(Arb.int(), Arb.list(Arb.int())),20 funcGen = Arb.functionAToB(Arb.pair(Arb.int(), Arb.list(Arb.int()))),21 )22 )23 testLaws(24 "Cons string - ",25 PrismLaws.laws(26 prism = Cons.string().cons(),27 aGen = Arb.string(),28 bGen = Arb.pair(Arb.char(), Arb.string()),29 funcGen = Arb.functionAToB(Arb.pair(Arb.char(), Arb.string())),30 )31 )32 }33}...
const
Using AI Code Generation
1import io.kotest.property.arbitrary.const2import io.kotest.property.arbitrary.int3import io.kotest.property.arbitrary.string4import io.kotest.property.arbitrary.uuid5import io.kotest.property.forAll6fun main() {7 forAll({ int() }, { string() }, { uuid() }, { a: Int, b: String, c: UUID ->8 const(a).value == a &&9 const(b).value == b &&10 const(c).value == c11 })12}13import io.kotlintest.properties.forAll14import io.kotlintest.shouldBe15import io.kotlintest.specs.StringSpec16import io.kotlintest.tables.row17import java.util.UUID18class ConstTest : StringSpec({19 "const should return always the same value" {20 forAll(21 row(1),22 row("a"),23 row(UUID.randomUUID())24 ) { value ->25 const(value).value shouldBe value26 }27 }28})
const
Using AI Code Generation
1import io.kotest.property.arbitrary.map2import io.kotest.property.Arb3import io.kotest.property.arbitrary.int4import io.kotest.property.arbitrary.string5import io.kotest.core.spec.style.FunSpec6import io.kotest.matchers.shouldBe7class PropertyTestingSample : FunSpec({8 test("property testing test") {9 Arb.string().forAll { s ->10 s.length == s.reversed().length11 }12 }13})14import io.kotest.core.spec.style.FunSpec15import io.kotest.matchers.shouldBe16class PropertyTestingSample : FunSpec({17 test("property testing test") {18 Arb.int(0..100).forAll { i ->19 }20 }21})22import io.kotest.core.spec.style.FunSpec23import io.kotest.matchers.shouldBe24class PropertyTestingSample : FunSpec({25 test("property testing test") {26 Arb.int(0..100).forAll { i ->27 }28 }29})30import io.kotest.core.spec.style.FunSpec31import io.kotest.matchers.shouldBe32class PropertyTestingSample : FunSpec({33 test("property testing test") {34 Arb.int(0..100).forAll { i ->35 }36 }37})38import io.kotest.core.spec.style.FunSpec39import io.kotest.matchers.shouldBe40class PropertyTestingSample : FunSpec({41 test("property testing test") {
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!