How to use file class of io.kotest.property.exhaustive package

Best Kotest code snippet using io.kotest.property.exhaustive.file

HardCodedDispatcherUsageTest.kt

Source:HardCodedDispatcherUsageTest.kt Github

copy

Full Screen

1/*2 * Copyright (C) 2021 Rick Busarow3 * Licensed under the Apache License, Version 2.0 (the "License");4 * you may not use this file except in compliance with the License.5 * You may obtain a copy of the License at6 *7 * http://www.apache.org/licenses/LICENSE-2.08 *9 * Unless required by applicable law or agreed to in writing, software10 * distributed under the License is distributed on an "AS IS" BASIS,11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12 * See the License for the specific language governing permissions and13 * limitations under the License.14 */15package dispatch.detekt.rules16import io.gitlab.arturbosch.detekt.test.*17import io.kotest.core.spec.style.*18import io.kotest.data.*19import io.kotest.matchers.*20import io.kotest.property.*21import io.kotest.property.exhaustive.*22internal class HardCodedDispatcherTest : FreeSpec(23 {24 fun findingMessage(expression: String) =25 "Using Dispatchers singleton reference (`$expression`) instead of a DispatcherProvider property."26 "positive cases" {27 forAll(28 row("import kotlinx.coroutines.Dispatchers.Default", "Default"),29 row("import kotlinx.coroutines.Dispatchers.IO", "IO"),30 row("import kotlinx.coroutines.Dispatchers.Main", "Main"),31 row("import kotlinx.coroutines.Dispatchers.Main", "Main.immediate"),32 row("import kotlinx.coroutines.Dispatchers.Unconfined", "Unconfined"),33 row("import kotlinx.coroutines.Dispatchers.*", "Default"),34 row("import kotlinx.coroutines.Dispatchers.*", "IO"),35 row("import kotlinx.coroutines.Dispatchers.*", "Main"),36 row("import kotlinx.coroutines.Dispatchers.*", "Main.immediate"),37 row("import kotlinx.coroutines.Dispatchers.*", "Unconfined"),38 row("import kotlinx.coroutines.Dispatchers", "Dispatchers.Default"),39 row("import kotlinx.coroutines.Dispatchers", "Dispatchers.IO"),40 row("import kotlinx.coroutines.Dispatchers", "Dispatchers.Main"),41 row("import kotlinx.coroutines.Dispatchers", "Dispatchers.Main.immediate"),42 row("import kotlinx.coroutines.Dispatchers", "Dispatchers.Unconfined"),43 row("import kotlinx.coroutines.*", "Dispatchers.Default"),44 row("import kotlinx.coroutines.*", "Dispatchers.IO"),45 row("import kotlinx.coroutines.*", "Dispatchers.Main"),46 row("import kotlinx.coroutines.*", "Dispatchers.Main.immediate"),47 row("import kotlinx.coroutines.*", "Dispatchers.Unconfined"),48 row("", "kotlinx.coroutines.Dispatchers.Default"),49 row("", "kotlinx.coroutines.Dispatchers.IO"),50 row("", "kotlinx.coroutines.Dispatchers.Main"),51 row("", "kotlinx.coroutines.Dispatchers.Main.immediate"),52 row("", "kotlinx.coroutines.Dispatchers.Unconfined")53 ) { import, expression ->54 val code = """55 |package a.b.c56 |57 |$import58 |59 |class MyClass {60 |61 | suspend fun bad() = withContext($expression) { }62 |63 |}64 |65 """.trimMargin()66 val rule = HardCodedDispatcher()67 val findings = rule.lint(code)68 findings.messages shouldBe listOf(findingMessage(expression))69 }70 }71 "importing without using it should not report finding" {72 forAll(73 row("import kotlinx.coroutines.Dispatchers.Default"),74 row("import kotlinx.coroutines.Dispatchers.IO"),75 row("import kotlinx.coroutines.Dispatchers.Main"),76 row("import kotlinx.coroutines.Dispatchers.Main"),77 row("import kotlinx.coroutines.Dispatchers.Unconfined"),78 row("import kotlinx.coroutines.Dispatchers.*"),79 row("import kotlinx.coroutines.Dispatchers.*"),80 row("import kotlinx.coroutines.Dispatchers.*"),81 row("import kotlinx.coroutines.Dispatchers.*"),82 row("import kotlinx.coroutines.Dispatchers.*"),83 row("import kotlinx.coroutines.Dispatchers"),84 row("import kotlinx.coroutines.Dispatchers"),85 row("import kotlinx.coroutines.Dispatchers"),86 row("import kotlinx.coroutines.Dispatchers"),87 row("import kotlinx.coroutines.Dispatchers"),88 row("import kotlinx.coroutines.*"),89 row("import kotlinx.coroutines.*"),90 row("import kotlinx.coroutines.*"),91 row("import kotlinx.coroutines.*"),92 row("import kotlinx.coroutines.*")93 ) { import ->94 val code = """95 |package a.b.c96 |97 |$import98 |99 |class MyClass {100 |101 | suspend fun bad() = withContext(MyDispatcher) { }102 |103 |}104 |105 """.trimMargin()106 val rule = HardCodedDispatcher()107 val findings = rule.lint(code)108 findings.messages shouldBe emptyList()109 }110 }111 "issue id should be AndroidXLifecycleScope" {112 val rule = HardCodedDispatcher()113 rule.issue.id shouldBe "HardCodedDispatcher"114 }115 "issue should not be reported if suppressing HardCodedDispatcher" {116 forAll(117 row("import kotlinx.coroutines.Dispatchers.Default", "Default"),118 row("import kotlinx.coroutines.Dispatchers.IO", "IO"),119 row("import kotlinx.coroutines.Dispatchers.Main", "Main"),120 row("import kotlinx.coroutines.Dispatchers.Main", "Main.immediate"),121 row("import kotlinx.coroutines.Dispatchers.Unconfined", "Unconfined"),122 row("import kotlinx.coroutines.Dispatchers.*", "Default"),123 row("import kotlinx.coroutines.Dispatchers.*", "IO"),124 row("import kotlinx.coroutines.Dispatchers.*", "Main"),125 row("import kotlinx.coroutines.Dispatchers.*", "Main.immediate"),126 row("import kotlinx.coroutines.Dispatchers.*", "Unconfined"),127 row("import kotlinx.coroutines.Dispatchers", "Dispatchers.Default"),128 row("import kotlinx.coroutines.Dispatchers", "Dispatchers.IO"),129 row("import kotlinx.coroutines.Dispatchers", "Dispatchers.Main"),130 row("import kotlinx.coroutines.Dispatchers", "Dispatchers.Main.immediate"),131 row("import kotlinx.coroutines.Dispatchers", "Dispatchers.Unconfined"),132 row("import kotlinx.coroutines.*", "Dispatchers.Default"),133 row("import kotlinx.coroutines.*", "Dispatchers.IO"),134 row("import kotlinx.coroutines.*", "Dispatchers.Main"),135 row("import kotlinx.coroutines.*", "Dispatchers.Main.immediate"),136 row("import kotlinx.coroutines.*", "Dispatchers.Unconfined"),137 row("", "kotlinx.coroutines.Dispatchers.Default"),138 row("", "kotlinx.coroutines.Dispatchers.IO"),139 row("", "kotlinx.coroutines.Dispatchers.Main"),140 row("", "kotlinx.coroutines.Dispatchers.Main.immediate"),141 row("", "kotlinx.coroutines.Dispatchers.Unconfined")142 ) { import, expression ->143 val code = """144 |@file:Suppress("HardCodedDispatcher")145 |146 |package a.b.c147 |148 |$import149 |150 |class MyClass {151 |152 | suspend fun bad() = withContext($expression) { }153 |154 |}155 |156 """.trimMargin()157 val rule = HardCodedDispatcher()158 val findings = rule.lint(code)...

Full Screen

Full Screen

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>> =...

Full Screen

Full Screen

HelperMethodsTest.kt

Source:HelperMethodsTest.kt Github

copy

Full Screen

...4import io.github.ricardorlg.devicefarm.tractor.utils.HelperMethods.validateFileExtensionByType5import io.kotest.assertions.arrow.core.shouldBeLeft6import io.kotest.assertions.arrow.core.shouldBeRight7import io.kotest.core.spec.style.StringSpec8import io.kotest.engine.spec.tempfile9import io.kotest.matchers.should10import io.kotest.matchers.shouldBe11import io.kotest.matchers.throwable.shouldHaveMessage12import io.kotest.matchers.types.shouldBeInstanceOf13import io.kotest.property.Exhaustive14import io.kotest.property.checkAll15import io.kotest.property.exhaustive.collection16import software.amazon.awssdk.services.devicefarm.model.UploadType17class HelperMethodsTest : StringSpec({18 "When Android upload type is used, file must end with .apk" {19 //GIVEN20 val file = tempfile("testFile", ".apk")21 //WHEN22 val response = file.validateFileExtensionByType(UploadType.ANDROID_APP)23 //THEN24 response.shouldBeRight() shouldBe file25 }26 "When Android upload type is used, and file does not have .apk extension an error is returned" {27 //GIVEN28 val file = tempfile("testFile")29 val expectedErrorMessage =30 "the file ${file.nameWithoutExtension} is not a valid Android app. It should has .apk extension"31 //WHEN32 val response = file.validateFileExtensionByType(UploadType.ANDROID_APP)33 //THEN34 response.shouldBeLeft() should {35 it.shouldBeInstanceOf<DeviceFarmIllegalArtifactExtension>()36 it shouldHaveMessage expectedErrorMessage37 it.cause.shouldBeInstanceOf<IllegalArgumentException>()38 }39 }40 "When IOS upload type is used, file must end with .ipa" {41 //GIVEN42 val file = tempfile("testFile", ".ipa")43 //WHEN44 val response = file.validateFileExtensionByType(UploadType.IOS_APP)45 //THEN46 response.shouldBeRight() shouldBe file47 }48 "When IOS upload type is used, and file does not have .ipa extension an error is returned" {49 //GIVEN50 val file = tempfile("testFile")51 val expectedErrorMessage =52 "the file ${file.nameWithoutExtension} is not a valid IOS app. It should has .ipa extension"53 //WHEN54 val response = file.validateFileExtensionByType(UploadType.IOS_APP)55 //THEN56 response.shouldBeLeft() should {57 it.shouldBeInstanceOf<DeviceFarmIllegalArtifactExtension>()58 it shouldHaveMessage expectedErrorMessage59 it.cause.shouldBeInstanceOf<IllegalArgumentException>()60 }61 }62 "When Appium Node Test Spec upload type is used, file must end with .yml" {63 //GIVEN64 val file = tempfile("testFile", ".yml")65 //WHEN66 val response = file.validateFileExtensionByType(UploadType.APPIUM_NODE_TEST_SPEC)67 //THEN68 response.shouldBeRight() shouldBe file69 }70 "When Appium Node Test Spec upload type is used, and file does not have .yml extension an error is returned" {71 //GIVEN72 val file = tempfile("testFile")73 val expectedErrorMessage =74 "the file ${file.nameWithoutExtension} is not a valid test spec file. It should has .yml extension"75 //WHEN76 val response = file.validateFileExtensionByType(UploadType.APPIUM_NODE_TEST_SPEC)77 //THEN78 response.shouldBeLeft() should {79 it.shouldBeInstanceOf<DeviceFarmIllegalArtifactExtension>()80 it shouldHaveMessage expectedErrorMessage81 it.cause.shouldBeInstanceOf<IllegalArgumentException>()82 }83 }84 "When Upload type is not Android,IOS or Appium, the file must have .zip extension" {85 //GIVEN86 val file = tempfile("testFile", ".zip")87 //WHEN88 val response = file.validateFileExtensionByType(UploadType.WEB_APP)89 //THEN90 response.shouldBeRight() shouldBe file91 }92 "When Upload type is not Android,IOS or Appium, and file does not have .zip extension an error is returned" {93 //GIVEN94 val file = tempfile("testFile")95 val expectedErrorMessage =96 "the file ${file.nameWithoutExtension} is not a valid general file. It should has .zip extension"97 //WHEN98 val response = file.validateFileExtensionByType(UploadType.WEB_APP)99 //THEN100 response.shouldBeLeft() should {101 it.shouldBeInstanceOf<DeviceFarmIllegalArtifactExtension>()102 it shouldHaveMessage expectedErrorMessage103 it.cause.shouldBeInstanceOf<IllegalArgumentException>()104 }105 }106 "When unknown Upload type is used, an error should be returned"{107 //WHEN108 val response = tempfile().validateFileExtensionByType(UploadType.UNKNOWN_TO_SDK_VERSION)109 //THEN110 response.shouldBeLeft() should {111 it.shouldBeInstanceOf<DeviceFarmIllegalArtifactExtension.UnsupportedException>()112 it.cause.shouldBeInstanceOf<IllegalArgumentException>()113 }114 }115 "When loading a file from a given path, it should return it as a right" {116 //GIVEN117 val expectedFile = tempfile("testFile")118 //WHEN119 val response = HelperMethods.loadFileFromPath(expectedFile.path)120 //THEN121 response.shouldBeRight() shouldBe expectedFile122 }123 "When loading a file from a given path, if the files doesn't exists an error should be returned as a Left" {124 //WHEN125 val path = "path/to/non_existing/file"126 val response = HelperMethods.loadFileFromPath(path)127 //THEN128 response.shouldBeLeft() should {129 it.shouldBeInstanceOf<DeviceFarmTractorGeneralError>()130 it shouldHaveMessage "The file at $path does not exists"131 it.cause.shouldBeInstanceOf<java.lang.IllegalArgumentException>()132 }133 }134 "When no path is provided an Illegal Argument error should be returned as a left " {135 //WHEN136 val response = HelperMethods.loadFileFromPath(" ")137 //THEN138 response.shouldBeLeft() should {139 it.shouldBeInstanceOf<DeviceFarmTractorErrorIllegalArgumentException>()140 }141 }142 "When no path is provided getting the upload type of a path, an Illegal Argument error should be returned as a left"{143 //WHEN144 val response = " ".uploadType()145 //THEN146 response.shouldBeLeft() should {147 it.shouldBeInstanceOf<DeviceFarmTractorErrorIllegalArgumentException>()148 it shouldHaveMessage MANDATORY_PATH_PARAMETER149 }150 }151 "When getting the upload type of an unsupported file, an Illegal Argument error should be returned as a left"{152 //GIVEN153 val app = tempfile("testApp", ".zip")154 //WHEN155 val response = app.path.uploadType()156 //THEN157 response.shouldBeLeft() should {158 it.shouldBeInstanceOf<DeviceFarmTractorErrorIllegalArgumentException>()159 it shouldHaveMessage UNSUPPORTED_APP_FILE_EXTENSION.format(app.extension)160 }161 }162 "When getting the upload type of a valid file, it should return it as a right"{163 checkAll(164 Exhaustive.collection(165 listOf(166 ".apk" to UploadType.ANDROID_APP,167 ".ipa" to UploadType.IOS_APP168 )169 )170 ) { (extension, expectedUploadType) ->171 //GIVEN172 val app = tempfile("testApp", extension)173 //WHEN174 val response = app.path.uploadType()175 //THEN176 response.shouldBeRight() shouldBe expectedUploadType177 }178 }179})...

Full Screen

Full Screen

PublicComposablePreviewTest.kt

Source:PublicComposablePreviewTest.kt Github

copy

Full Screen

...9import io.kotest.property.Exhaustive10import io.kotest.property.checkAll11import io.kotest.property.exhaustive.of12class PublicComposablePreviewTest : ShouldSpec({13 should("report error if file has public preview function") {14 // language=kotlin15 val code = """16 @Composable17 @Preview18 fun Test(modifier: Modifier, value: Int) {19 Text(20 text = "3",21 )22 }23 """.trimIndent()24 val findings = PublicComposablePreview().lint(code)25 findings shouldHaveSize 126 }27 should("report error if class has public preview function") {28 // language=kotlin29 val code = """30 class MyClass {31 @Composable32 @Preview33 fun Test(modifier: Modifier, value: Int) {34 Text(35 text = "3",36 )37 }38 }39 """.trimIndent()40 val findings = PublicComposablePreview().lint(code)41 findings shouldHaveSize 142 }43 should("report error if object has public preview function") {44 // language=kotlin45 val code = """46 object MyClass {47 @Composable48 @Preview49 fun Test(modifier: Modifier, value: Int) {50 Text(51 text = "3",52 )53 }54 }55 """.trimIndent()56 val findings = PublicComposablePreview().lint(code)57 findings shouldHaveSize 158 }59 should("not report error if file has public preview function") {60 checkAll(Exhaustive.of("internal", "private")) { modifier ->61 // language=kotlin62 val code = """63 @Composable64 @Preview65 $modifier fun Test(modifier: Modifier, value: Int) {66 Text(67 text = "3",68 )69 }70 """.trimIndent()71 val findings = PublicComposablePreview().lint(code)72 findings.shouldBeEmpty()73 }...

Full Screen

Full Screen

NewBase60Tests.kt

Source:NewBase60Tests.kt Github

copy

Full Screen

1/*2 * Copyright (c) 2021 Maxim Pavlov.3 * Licensed under the Apache License, Version 2.0 (the "License");4 * you may not use this file except in compliance with the License.5 * You may obtain a copy of the License at6 *7 * http://www.apache.org/licenses/LICENSE-2.08 *9 * Unless required by applicable law or agreed to in writing, software10 * distributed under the License is distributed on an "AS IS" BASIS,11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12 * See the License for the specific language governing permissions and13 * limitations under the License.14 */15package online.senpai.newbase6016import io.kotest.assertions.throwables.shouldThrowExactly17import io.kotest.common.ExperimentalKotest18import io.kotest.core.spec.style.FunSpec...

Full Screen

Full Screen

LoggerKtTest.kt

Source:LoggerKtTest.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.handler.framework.azurefunctions17import com.microsoft.azure.functions.ExecutionContext18import com.sparetimedevs.pofpaf.test.generator.executionContextArb19import com.sparetimedevs.pofpaf.test.generator.logLevel...

Full Screen

Full Screen

RomanNumeralsConverterTest.kt

Source:RomanNumeralsConverterTest.kt Github

copy

Full Screen

1package guru.drako.trainings.kotlin.day22import guru.drako.trainings.kotlin.Day2Test3import io.kotest.matchers.ints.shouldBeExactly4import io.kotest.matchers.shouldBe5import io.kotest.property.Exhaustive6import io.kotest.property.checkAll7import io.kotest.property.exhaustive.ints8import kotlinx.coroutines.runBlocking9import org.junit.jupiter.api.Tag10import org.junit.jupiter.api.Test11import org.junit.jupiter.api.TestInstance12import org.junit.jupiter.api.TestInstance.Lifecycle13import org.junit.jupiter.api.assertThrows14import org.junit.jupiter.params.ParameterizedTest15import org.junit.jupiter.params.provider.CsvFileSource16import org.junit.jupiter.params.provider.ValueSource17// assertj -> assertk18// hamcrest -> hamkrest19// kotest20@TestInstance(Lifecycle.PER_CLASS)21@Tag(Day2Test)22class RomanNumeralsConverterTest {23 private val converter = RomanNumeralsConverter()24 @ParameterizedTest(name = "{index} ==> {1} should be {0}")25 @CsvFileSource(resources = ["RomanNumerals.csv"])26 fun `Conversion Roman to Arabic`(arabic: Int, roman: String) {27 converter.roman2arabic(roman) shouldBeExactly arabic28 }29 @ParameterizedTest(name = "{index} ==> {0} should throw")30 @ValueSource(strings = ["N", "ABC", "IL", "CDC"])31 fun `Roman to Arabic should fail if number is not a roman numeral`(n: String) {32 assertThrows<IllegalArgumentException> {33 converter.roman2arabic(n)34 }35 }36 @ParameterizedTest(name = "{index} ==> {0} should be {1}")37 @CsvFileSource(resources = ["RomanNumerals.csv"])38 fun `Conversion Arabic to Roman`(arabic: Int, roman: String) {39 converter.arabic2roman(arabic) shouldBe roman40 }41 @ParameterizedTest(name = "{index} ==> {0} should throw")42 @ValueSource(ints = [0, 4000])43 fun `Arabic to Roman should fail if number out of bounds`(n: Int) {44 assertThrows<IllegalArgumentException> {45 converter.arabic2roman(n)46 }47 }48 @Test49 fun `Back and forth should work`(): Unit = runBlocking {50 checkAll(Exhaustive.ints(1..3999)) { n ->51 converter.roman2arabic(converter.arabic2roman(n)) shouldBeExactly n52 }53 }54}...

Full Screen

Full Screen

Logs.kt

Source:Logs.kt Github

copy

Full Screen

1package org.example.log2import io.kotest.property.Arb3import io.kotest.property.Gen4import io.kotest.property.arbitrary.*5import io.kotest.property.exhaustive.exhaustive6import org.example.GenWrapper7import org.example.TestResources8import org.koin.dsl.module9val logsModule = module {10 single(lineLogQ) { StringLogs(logs(11 get(),12 get<StringLogFactories>(lineLogQ).gen,13 Arb.string()14 )) }15 single(binaryLogQ) { BinaryLogs(logs(16 get(),17 get<ByteArrayLogFactories>(binaryLogQ).gen,18 Arb.byteArray((1..10).toList().exhaustive(), Arb.byte())19 ))}20}21data class StringLogs(22 override val gen: Gen<Log<String>>23) : GenWrapper<Log<String>>24data class BinaryLogs(25 override val gen: Gen<Log<ByteArray>>26) : GenWrapper<Log<ByteArray>>27private val testableSizes = listOf(0, 1, 10).exhaustive()28private fun <T> logs(29 resources: TestResources,30 factories: Gen<LogFactoryB<T>>,31 valueGenerator: Arb<T>32) = Arb.bind(33 factories,34 testableSizes35) { factory, size ->36 factory.create(resources.allocateTempLogFile())37 .also { log ->38 (0..size).map { valueGenerator.next() }39 .forEach(log::append)40 }41}...

Full Screen

Full Screen

file

Using AI Code Generation

copy

Full Screen

1 val file = File("src/test/resources/testdata.txt")2 val lines = file.readLines()3 val int = lines[1].toInt()4 val double = lines[2].toDouble()5 println("String: $string")6 println("Int: $int")7 println("Double: $double")8 val file = File("src/test/resources/testdata.txt")9 val lines = file.readLines()10 val int = lines[1].toInt()11 val double = lines[2].toDouble()12 println("String: $string")13 println("Int: $int")14 println("Double: $double")15 val file = File("src/test/resources/testdata.txt")16 val lines = file.readLines()17 val int = lines[1].toInt()18 val double = lines[2].toDouble()19 println("String: $string")20 println("Int: $int")21 println("Double: $double")22 val file = File("src/test/resources/testdata.txt")23 val lines = file.readLines()24 val int = lines[1].toInt()25 val double = lines[2].toDouble()26 println("String: $string")27 println("Int: $int")28 println("Double: $double")29 val file = File("src/test/resources/testdata.txt")30 val lines = file.readLines()31 val int = lines[1].toInt()32 val double = lines[2].toDouble()33 println("String: $string")34 println("Int: $int")35 println("Double: $double")36 val file = File("src/test/resources/testdata.txt")37 val lines = file.readLines()38 val int = lines[1].toInt()39 val double = lines[2].toDouble()40 println("String: $string")41 println("Int: $int")42 println("Double: $double")

Full Screen

Full Screen

file

Using AI Code Generation

copy

Full Screen

1val files = Exhaustive.constant(File(""))2val files = Exhaustive.constant(File("")) files.assertAll { file -> file.exists() }3files.assertAll { file -> file.exists() }4val strings = Exhaustive.constant("")5val strings = Exhaustive.constant("") strings.assertAll { string -> string.length == 3 }6strings.assertAll { string -> string.length == 3 }7val ints = Exhaustive.constant(0)8val ints = Exhaustive.constant(0) ints.assertAll { int -> int > 0 }9ints.assertAll { int -> int > 0 }10val longs = Exhaustive.constant(0L)11val longs = Exhaustive.constant(0L) longs.assertAll { long -> long > 0 }12longs.assertAll { long -> long > 0 }13val shorts = Exhaustive.constant(0.toShort())14val shorts = Exhaustive.constant(0.toShort()) shorts.assertAll { short -> short > 0 }15shorts.assertAll { short -> short > 0 }16val bytes = Exhaustive.constant(0.toByte())17val bytes = Exhaustive.constant(0.toByte()) bytes.assertAll { byte -> byte > 0 }18bytes.assertAll { byte -> byte > 0 }19val doubles = Exhaustive.constant(0.0)20val doubles = Exhaustive.constant(0.0) doubles.assertAll { double -> double > 0 }21doubles.assertAll { double -> double > 0 }22val floats = Exhaustive.constant(0.0F)23val floats = Exhaustive.constant(0.0F) floats.assertAll { float -> float > 0 }24floats.assertAll { float -> float > 0 }25val chars = Exhaustive.constant('a')26val chars = Exhaustive.constant('a') chars

Full Screen

Full Screen

file

Using AI Code Generation

copy

Full Screen

1val file = File ( "src/test/resources/test.txt" )2val fileContent = file . readText ()3fileContent . shouldContain ( "Hello" )4fileContent . shouldContain ( "world" )5}6}7}8val file = File ( "src/test/resources/test.txt" )9val fileContent = file . readText ()10fileContent . shouldContain ( "Hello" )11fileContent . shouldContain ( "world" )12}13}14}15val file = File ( "src/test/resources/test.txt" )16val fileContent = file . readText ()17fileContent . shouldContain ( "Hello" )18fileContent . shouldContain ( "world" )19}20}21}22val file = File ( "src/test/resources/test.txt" )23val fileContent = file . readText ()24fileContent . shouldContain ( "Hello" )25fileContent . shouldContain ( "world" )26}27}28}29val file = File ( "src/test/resources/test.txt" )30val fileContent = file . readText ()31fileContent . shouldContain ( "Hello" )32fileContent . shouldContain ( "world" )33}34}35}36val file = File ( "src/test/resources/test.txt" )37val fileContent = file . readText ()38fileContent . shouldContain ( "Hello" )39fileContent . shouldContain ( "world" )40}41}42}43val file = File ( "src/test/resources/test.txt" )44val fileContent = file . readText ()45fileContent . shouldContain ( "Hello" )46fileContent . shouldContain ( "world" )47}48}49}50val file = File ( "src/test/resources/test.txt" )51val fileContent = file . readText ()52fileContent . shouldContain ( "Hello" )53fileContent . shouldContain ( "world" )54}55}56}

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 file

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful