How to use date class of io.kotest.property.arbitrary package

Best Kotest code snippet using io.kotest.property.arbitrary.date

GenHelper.kt

Source:GenHelper.kt Github

copy

Full Screen

1/*2 * Copyright (c) 2020 sparetimedevs and respective authors and developers.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package com.sparetimedevs.pofpaf.test.generator17import arrow.core.Either18import arrow.core.left19import arrow.core.right20import com.microsoft.azure.functions.HttpMethod21import com.sparetimedevs.pofpaf.test.implementation.general.log.Level22import io.kotest.property.Arb23import io.kotest.property.Exhaustive24import io.kotest.property.arbitrary.bool25import io.kotest.property.arbitrary.byte26import io.kotest.property.arbitrary.choice27import io.kotest.property.arbitrary.create28import io.kotest.property.arbitrary.double29import io.kotest.property.arbitrary.element30import io.kotest.property.arbitrary.file31import io.kotest.property.arbitrary.float32import io.kotest.property.arbitrary.int33import io.kotest.property.arbitrary.localDate34import io.kotest.property.arbitrary.localDateTime35import io.kotest.property.arbitrary.localTime36import io.kotest.property.arbitrary.long37import io.kotest.property.arbitrary.map38import io.kotest.property.arbitrary.next39import io.kotest.property.arbitrary.period40import io.kotest.property.arbitrary.short41import io.kotest.property.arbitrary.string42import io.kotest.property.arbitrary.uuid43import io.kotest.property.exhaustive.exhaustive44import java.net.URI45fun Arb.Companion.suspendFunThatReturnsEitherAnyOrAnyOrThrows(): Arb<suspend () -> Either<Any, Any>> =46 choice(47 suspendFunThatReturnsAnyRight(),48 suspendFunThatReturnsAnyLeft(),49 suspendFunThatThrows()50 )51fun Arb.Companion.suspendFunThatReturnsEitherAnyOrUnitOrThrows(): Arb<suspend () -> Either<Any, Unit>> =52 choice(53 suspendFunThatReturnsUnitRight() as Arb<suspend () -> Either<Any, Unit>>,54 suspendFunThatReturnsAnyLeft() as Arb<suspend () -> Either<Any, Unit>>,55 suspendFunThatThrows() as Arb<suspend () -> Either<Any, Unit>>56 )57fun Arb.Companion.suspendFunThatReturnsUnitRight(): Arb<suspend () -> Either<Any, Unit>> =58 unit().map { suspend { it.right() } }59fun Arb.Companion.suspendFunThatReturnsAnyRight(): Arb<suspend () -> Either<Any, Any>> =60 any().map { suspend { it.right() } }61fun Arb.Companion.suspendFunThatReturnsAnyLeft(): Arb<suspend () -> Either<Any, Any>> =62 any().map { suspend { it.left() } }63fun Arb.Companion.suspendFunThatThrows(): Arb<suspend () -> Either<Any, Any>> =64 throwable().map { suspend { throw it } } as Arb<suspend () -> Either<Any, Any>>65fun Arb.Companion.suspendFunThatThrowsFatalThrowable(): Arb<suspend () -> Either<Any, Any>> =66 fatalThrowable().map { suspend { throw it } } as Arb<suspend () -> Either<Any, Any>>67fun Arb.Companion.throwable(): Arb<Throwable> =68 element(69 Exception(),70 RuntimeException(),71 IllegalArgumentException(),72 IllegalStateException(),73 IndexOutOfBoundsException(),74 UnsupportedOperationException(),75 ArithmeticException(),76 NumberFormatException(),77 NullPointerException(),78 ClassCastException(),79 AssertionError(),80 NoSuchElementException(),81 ConcurrentModificationException()82 )83fun Arb.Companion.fatalThrowable(): Arb<Throwable> =84 element(85 MyVirtualMachineError(),86 ThreadDeath(),87 InterruptedException(),88 LinkageError()89 )90class MyVirtualMachineError : VirtualMachineError()91fun Arb.Companion.any(): Arb<Any> =92 choice(93 string() as Arb<Any>,94 int() as Arb<Any>,95 short() as Arb<Any>,96 long() as Arb<Any>,97 float() as Arb<Any>,98 double() as Arb<Any>,99 bool() as Arb<Any>,100 byte() as Arb<Any>,101 uuid() as Arb<Any>,102 file() as Arb<Any>,103 localDate() as Arb<Any>,104 localTime() as Arb<Any>,105 localDateTime() as Arb<Any>,106 period() as Arb<Any>,107 throwable() as Arb<Any>,108 fatalThrowable() as Arb<Any>,109 mapOfStringAndStringGenerator() as Arb<Any>,110 uri() as Arb<Any>,111 httpMethod() as Arb<Any>,112 unit() as Arb<Any>113 )114fun Arb.Companion.unit(): Arb<Unit> =115 create { Unit }116fun Arb.Companion.mapOfStringAndStringGenerator(): Arb<Map<String, String>> =117 element(118 listOf(119 emptyMap(),120 mapOf(121 string().next() to string().next()122 ),123 mapOf(124 string().next() to string().next(),125 string().next() to string().next()126 ),127 mapOf(128 string().next() to string().next(),129 string().next() to string().next(),130 string().next() to string().next()131 ),132 mapOf(133 string().next() to string().next(),134 string().next() to string().next(),135 string().next() to string().next(),136 string().next() to string().next(),137 string().next() to string().next(),138 string().next() to string().next()139 ),140 mapOf(141 string().next() to string().next(),142 string().next() to string().next(),143 string().next() to string().next(),144 string().next() to string().next(),145 string().next() to string().next(),146 string().next() to string().next(),147 string().next() to string().next(),148 string().next() to string().next(),149 string().next() to string().next(),150 string().next() to string().next(),151 string().next() to string().next(),152 string().next() to string().next()153 ),154 mapOf(155 string().next() to string().next(),156 string().next() to string().next(),157 string().next() to string().next(),158 string().next() to string().next(),159 string().next() to string().next(),160 string().next() to string().next(),161 string().next() to string().next(),162 string().next() to string().next(),163 string().next() to string().next(),164 string().next() to string().next(),165 string().next() to string().next(),166 string().next() to string().next(),167 string().next() to string().next(),168 string().next() to string().next(),169 string().next() to string().next(),170 string().next() to string().next(),171 string().next() to string().next(),172 string().next() to string().next(),173 string().next() to string().next(),174 string().next() to string().next(),175 string().next() to string().next(),176 string().next() to string().next(),177 string().next() to string().next(),178 string().next() to string().next()179 )180 )181 )182fun Arb.Companion.uri(): Arb<URI> =183 element(184 listOf(185 URI.create("https://sparetimedevs.com"),186 URI.create("https://www.sparetimedevs.com"),187 URI.create("https://something.sparetimedevs.com"),188 URI.create("https://something.sparetimedevs.com/another/thing"),189 URI.create("https://something.sparetimedevs.com/another/thing?query=param")190 )191 )192fun Arb.Companion.httpMethod(): Arb<HttpMethod> =193 element(194 listOf(195 HttpMethod.GET,196 HttpMethod.HEAD,197 HttpMethod.POST,198 HttpMethod.PUT,199 HttpMethod.DELETE,200 HttpMethod.CONNECT,201 HttpMethod.OPTIONS,202 HttpMethod.TRACE203 )204 )205fun Exhaustive.Companion.logLevel(): Exhaustive<Level> =206 listOf(207 Level.INFO,208 Level.DEBUG,209 Level.WARN,210 Level.ERROR211 ).exhaustive()212fun Arb.Companion.stringOrNull(): Arb<String?> =213 choice(214 string() as Arb<String?>,215 create { null } as Arb<String?>216 )...

Full Screen

Full Screen

DataValidationExtensionsUnitTest.kt

Source:DataValidationExtensionsUnitTest.kt Github

copy

Full Screen

...41 }42 }43 }44 "Timestamp.isValid" should {45 "return true for any UTC date" {46 forAll(Arb.localDateTime()) { randomLocalDateTime ->47 randomLocalDateTime.atOffset(ZoneOffset.UTC).toProtoTimestamp().isValid()48 }49 }50 }51 "Date.isValid" should {52 "return false for a default instance" {53 FigureTechDate.getDefaultInstance().isValid() shouldBe false54 }55 "return true for any valid date" {56 forAll(Arb.localDate()) { randomLocalDate ->57 FigureTechDate.newBuilder().apply {58 value = randomLocalDate.toString()59 }.build().isValid()60 }61 }62 }63 "Checksum.isValid" should {64 "return false for a default instance" {65 FigureTechChecksum.getDefaultInstance().isValid() shouldBe false66 }67 "return false for an invalid instance" {68 FigureTechChecksum.newBuilder().apply {69 checksum = ""...

Full Screen

Full Screen

EmoticonServiceSpec.kt

Source:EmoticonServiceSpec.kt Github

copy

Full Screen

1package com.kakao.ifkakao.studio.test.domain.emoticon2import com.kakao.ifkakao.studio.domain.emoticon.EmoticonInformation3import com.kakao.ifkakao.studio.domain.emoticon.EmoticonRepository4import com.kakao.ifkakao.studio.domain.emoticon.EmoticonService5import com.kakao.ifkakao.studio.test.Mock6import com.kakao.ifkakao.studio.test.SpringDataConfig7import io.kotest.core.spec.style.ExpectSpec8import io.kotest.matchers.collections.shouldContainAll9import io.kotest.matchers.collections.shouldHaveSize10import io.kotest.matchers.longs.shouldBeGreaterThan11import io.kotest.matchers.shouldBe12import io.kotest.property.Arb13import io.kotest.property.arbitrary.chunked14import io.kotest.property.arbitrary.flatMap15import io.kotest.property.arbitrary.int16import io.kotest.property.arbitrary.localDate17import io.kotest.property.arbitrary.single18import io.kotest.property.arbitrary.string19import io.kotest.property.arbitrary.stringPattern20import org.springframework.test.context.ContextConfiguration21import java.time.LocalDate22import java.time.ZoneId23@ContextConfiguration(classes = [SpringDataConfig::class])24class EmoticonServiceSpec(25 private val emoticonRepository: EmoticonRepository26) : ExpectSpec() {27 private val emoticonService = EmoticonService(repository = emoticonRepository)28 init {29 context("이모티콘 생성을 할 때") {30 val account = Mock.account(identified = true)31 val information = information()32 val images = images()33 expect("계정과 이모티콘 정보, 이미지가 있으면 이모티콘이 생성된다.") {34 val emoticon = emoticonService.create(account, information, images)35 emoticon.id shouldBeGreaterThan 036 emoticon.authorId shouldBe account.id37 emoticon.title shouldBe information.title38 emoticon.description shouldBe information.description39 emoticon.choco shouldBe information.choco40 emoticon.images shouldContainAll images41 }42 }43 context("이모티콘을 조회할때") {44 val saved = Arb.localDate(45 minDate = LocalDate.of(2020, 1, 1),46 maxDate = LocalDate.of(2020, 1, 10)47 ).flatMap {48 Mock.emoticonEntity(it, ZoneId.systemDefault()).chunked(1..10).single()49 }.let {50 emoticonRepository.saveAll(it.chunked(100..1000).single())51 }52 expect("생성 시작 시간의 범위로 조회하면 해당 구간에 생성된 이모티콘을 조회 할 수 있다.") {53 val from = LocalDate.of(2020, 1, 5).atStartOfDay().atZone(ZoneId.systemDefault())54 val to = LocalDate.of(2020, 1, 8).atStartOfDay().atZone(ZoneId.systemDefault())55 val target = with(saved) {56 val fromInstant = from.toInstant()57 val toInstant = to.toInstant()58 filter {59 fromInstant <= it.createdAt && toInstant >= it.createdAt60 }.map { it.id }61 }62 val emoticons = emoticonService.getAllCreatedAt(from, to)63 emoticons shouldHaveSize target.count()64 emoticons.map { it.id } shouldContainAll target65 }66 }67 }68 private fun information() = EmoticonInformation(69 title = Arb.string(10..100).single(),70 description = Arb.string(100..300).single(),71 choco = Arb.int(100..500).single()72 )73 private fun images() = Arb.stringPattern("([a-zA-Z0-9]{1,10})/([a-zA-Z0-9]{1,10})\\.jpg")74 .chunked(1..10)75 .single()76}...

Full Screen

Full Screen

RestaurantItemArb.kt

Source:RestaurantItemArb.kt Github

copy

Full Screen

1/*2 * Jopiter APP3 * Copyright (C) 2021 Leonardo Colman Lopes4 *5 * This program is free software: you can redistribute it and/or modify6 * it under the terms of the GNU Affero General Public License as published by7 * the Free Software Foundation, either version 3 of the License, or8 * (at your option) any later version.9 *10 * This program is distributed in the hope that it will be useful,11 * but WITHOUT ANY WARRANTY; without even the implied warranty of12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13 * GNU Affero General Public License for more details.14 *15 * You should have received a copy of the GNU Affero General Public License16 * along with this program. If not, see <https://www.gnu.org/licenses/>.17 */18package app.jopiter.restaurants.model19import io.kotest.property.Arb20import io.kotest.property.arbitrary.arbitrary21import io.kotest.property.arbitrary.enum22import io.kotest.property.arbitrary.int23import io.kotest.property.arbitrary.list24import io.kotest.property.arbitrary.localDate25import io.kotest.property.arbitrary.long26import io.kotest.property.arbitrary.next27import io.kotest.property.arbitrary.orNull28import io.kotest.property.arbitrary.string29val restaurantItemArb = arbitrary {30 RestaurantItem(31 Arb.int(1, 100).next(),32 Arb.localDate().next(),33 Arb.enum<Period>().next(),34 Arb.long().orNull(0.1).next(),35 Arb.string(minSize = 1).next(),36 Arb.string(minSize = 1).next(),37 Arb.string(minSize = 1).next(),38 Arb.list(Arb.string(minSize = 1)).next(),39 Arb.string(minSize = 1).next(),40 Arb.string(1, 50).next()41 )42}...

Full Screen

Full Screen

LocalDateTimeConverterTest.kt

Source:LocalDateTimeConverterTest.kt Github

copy

Full Screen

...15 }16 }17 test("Converts ISO DateTime String to LocalDateTime") {18 Arb.localDateTime().map { it to it.format(ISO_LOCAL_DATE_TIME) }.checkAll {19 val (dateTime, str) = it20 target.convertToEntityProperty(str) shouldBe dateTime21 }22 }23 test("Converts anything itself generate to something itself accepts") {24 Arb.localDateTime().checkAll {25 var string = target.convertToDatabaseValue(it)26 var dateTime = target.convertToEntityProperty(string)27 repeat(1000) {28 string = target.convertToDatabaseValue(dateTime)29 dateTime = target.convertToEntityProperty(string)30 }31 dateTime shouldBe it32 string shouldBe it.format(ISO_LOCAL_DATE_TIME)33 }34 }35})

Full Screen

Full Screen

transactions.kt

Source:transactions.kt Github

copy

Full Screen

...5import io.kotest.property.arbitrary.int6import io.kotest.property.arbitrary.long7import io.kotest.property.arbs.geo.Country8import io.kotest.property.arbs.geo.country9import io.kotest.property.kotlinx.datetime.datetime10import kotlinx.datetime.LocalDateTime11enum class CardType {12 Visa, Mastercard, Amex, Discover, Paypal, GooglePay, ApplePay13}14enum class TransactionType {15 Online, InStore, Recurring16}17data class Transaction(18 val date: LocalDateTime,19 val txType: TransactionType,20 val cardNumber: String,21 val cardType: CardType,22 val country: Country,23 val amount: Int,24)25fun Arb.Companion.transactions() = Arb.bind(26 Arb.datetime(),27 Arb.enum<TransactionType>(),28 Arb.enum<CardType>(),29 Arb.long(100000000000..10000000000000L),30 Arb.int(100..1000000),31 Arb.country(),32) { date, txType, cardType, number, amount, country ->33 Transaction(date, txType, number.toString().padStart(16, '4'), cardType, country, amount)34}...

Full Screen

Full Screen

UserPropertyTest.kt

Source:UserPropertyTest.kt Github

copy

Full Screen

...9 private val user = User(firstname = "Hasta", lastname = "La Vista", birthday = LocalDate.of(1991, 5, 2), friends = setOf())10 @Test11 suspend fun `is always birthday`() {12 forAll(Arb.localDate(LocalDate.of(1991, 5, 2))13 .filter { date -> date.month == user.birthday.month && date.dayOfMonth == user.birthday.dayOfMonth }) { generatedDate ->14 user.isBirthday(generatedDate)15 }16 }17 @Test18 suspend fun `is never birthday`() {19 forAll(Arb.localDate(LocalDate.of(1991, 5, 2))20 .filter { date -> date.month != user.birthday.month || date.dayOfMonth != user.birthday.dayOfMonth }) { generatedDate ->21 !user.isBirthday(generatedDate)22 }23 }24}...

Full Screen

Full Screen

Mock.kt

Source:Mock.kt Github

copy

Full Screen

1package com.gaveship.category2import com.gaveship.category.domain.model.Category3import io.kotest.property.Arb4import io.kotest.property.arbitrary.arbitrary5import io.kotest.property.arbitrary.next6import io.kotest.property.arbitrary.string7import java.time.LocalDateTime8object Mock {9 fun category(10 id: Long? = null,11 name: String? = null,12 children: List<Category>? = null,13 ) = arbitrary {14 Category(15 id = id,16 name = name ?: Arb.string(0, 50).next(it),17 createdDate = LocalDateTime.now(),18 modifiedDate = LocalDateTime.now(),19 children = children20 )21 }22}...

Full Screen

Full Screen

date

Using AI Code Generation

copy

Full Screen

1import io.kotest.property.arbitrary.date2import io.kotest.property.arbitrary.dateRange3import java.time.LocalDate4import java.time.ZoneId5import java.time.ZonedDateTime6import java.util.Date7import java.util.Date8import org.joda.time.DateTime9import org.joda.time.LocalDate10import org.threeten.bp.LocalDate11import org.threeten.bp.ZonedDateTime12import io.kotest.property.arbitrary.date13import io.kotest.property.arbitrary.dateRange14import io.kotest.core.spec.style.StringSpec15import io.kotest.matchers.shouldBe16import io.kotest.property.forAll17class DateGeneratorWithIoKotestPropertyArbitraryDateClassTest : StringSpec({18 "should generate date between two dates" {19 val dateRange = dateRange(20 start = date(year = 2019, month = 1, day = 1),21 end = date(year = 2019, month = 12, day = 31)22 forAll(dateRange) { date ->23 date.monthValue shouldBe inRange(1..12)24 date.dayOfMonth shouldBe inRange(1..31)25 }26 }27})28import java.time.LocalDate29import java.time.ZoneId30import java.time.ZonedDateTime31import java

Full Screen

Full Screen

date

Using AI Code Generation

copy

Full Screen

1 val date = DateArbitrary.default().next()2 println(date)3 val date = DateArbitrary.default().next()4 println(date)5 val date = DateArbitrary.default().next()6 println(date)7 val date = DateArbitrary.default().next()8 println(date)9 val date = DateArbitrary.default().next()10 println(date)11 val date = DateArbitrary.default().next()12 println(date)13 val date = DateArbitrary.default().next()14 println(date)15 val date = DateArbitrary.default().next()16 println(date)17 val date = DateArbitrary.default().next()18 println(date)19 val date = DateArbitrary.default().next()20 println(date)21 val date = DateArbitrary.default().next()22 println(date)23 val date = DateArbitrary.default().next()24 println(date)25 val date = DateArbitrary.default().next()26 println(date)27 val date = DateArbitrary.default().next()28 println(date)29}

Full Screen

Full Screen

date

Using AI Code Generation

copy

Full Screen

1val dateGen = date()2val dateGen = date(LocalDate.of(2017, 1, 1), LocalDate.of(2017, 12, 31))3val dateGen = localDate()4val dateGen = localDate(LocalDate.of(2017, 1, 1), LocalDate.of(2017, 12, 31))5val timeGen = localTime()6val timeGen = localTime(LocalTime.of(10, 0, 0), LocalTime.of(20, 0, 0))7val dateTimeGen = localDateTime()8val dateTimeGen = localDateTime(LocalDateTime.of(2017, 1, 1, 10, 0, 0), LocalDateTime.of(2017, 12, 31, 20, 0, 0))9val dateTimeGen = zonedDateTime()10val dateTimeGen = zonedDateTime(ZonedDateTime.of(2017, 1, 1, 10, 0, 0, 0, ZoneId.of("America/Los_Angeles")), ZonedDateTime.of(2017, 12, 31, 20, 0, 0, 0, ZoneId.of("America/Los_Angeles")))11val timeGen = offsetTime()12val timeGen = offsetTime(OffsetTime.of(10, 0, 0, 0, ZoneOffset.ofHours(-8)), OffsetTime.of(20, 0, 0, 0, ZoneOffset.ofHours(-8)))13val dateTimeGen = offsetDateTime()14val dateTimeGen = offsetDateTime(OffsetDateTime.of(2017, 1, 1, 10, 0, 0, 0, ZoneOffset.ofHours(-8)), OffsetDateTime.of(2017, 12, 31, 20, 0, 0, 0, ZoneOffset.ofHours(-8)))

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 date

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful