How to use positive method of io.kotest.matchers.ints.int class

Best Kotest code snippet using io.kotest.matchers.ints.int.positive

MonomialTest.kt

Source:MonomialTest.kt Github

copy

Full Screen

...22import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder23import io.kotest.matchers.shouldBe24import io.kotest.property.Arb25import io.kotest.property.arbitrary.negativeInts26import io.kotest.property.arbitrary.positiveInts27import io.kotest.property.checkAll28import io.kotest.property.exhaustive.exhaustive29val monomialTestTag = NamedTag("Monomial")30class MonomialTest : FreeSpec({31 tags(monomialTestTag)32 "indeterminate list with mixed degrees is not allowed" {33 checkAll(Arb.positiveInts(), Arb.negativeInts()) { positiveDegree, negativeDegree ->34 val indeterminateList = listOf(35 Indeterminate("x", positiveDegree),36 Indeterminate("y", negativeDegree)37 )38 shouldThrow<IllegalArgumentException> {39 FreeMonoid(indeterminateList)40 }41 }42 }43 "degree 0 is not allowed" {44 val indeterminateList = listOf(45 Indeterminate("x", 0)46 )47 shouldThrow<IllegalArgumentException> {48 FreeMonoid(indeterminateList)49 }50 }51 "positive degrees should be allowed" {52 val indeterminateList = listOf(53 Indeterminate("x", 1),54 Indeterminate("x", 2),55 Indeterminate("x", 3),56 )57 val monoid = FreeMonoid(indeterminateList)58 shouldNotThrowAny {59 monoid.listElements(0)60 }61 }62 "negative degrees should be allowed" {63 val indeterminateList = listOf(64 Indeterminate("x", -1),65 Indeterminate("x", -2),66 Indeterminate("x", -3),67 )68 val monoid = FreeMonoid(indeterminateList)69 shouldNotThrowAny {70 monoid.listElements(0)71 }72 }73 "two generators of even degrees" {74 val indeterminateList = listOf(75 Indeterminate("x", 2),76 Indeterminate("y", 2),77 )78 val monoid = FreeMonoid(indeterminateList)79 val gen = exhaustive(listOf(Pair(0, 1), Pair(1, 0), Pair(2, 2), Pair(3, 0), Pair(4, 3)))80 checkAll(gen) { (degree, size) ->81 monoid.listElements(degree).size shouldBe size82 }83 }84 "two generators of negative even degrees" {85 val indeterminateList = listOf(86 Indeterminate("x", -2),87 Indeterminate("y", -2),88 )89 val monoid = FreeMonoid(indeterminateList)90 val gen = exhaustive(listOf(Pair(0, 1), Pair(-1, 0), Pair(-2, 2), Pair(-3, 0), Pair(-4, 3)))91 checkAll(gen) { (degree, size) ->92 monoid.listElements(degree).size shouldBe size93 }94 }95 "two generators of odd degrees" {96 val indeterminateList = listOf(97 Indeterminate("x", 1),98 Indeterminate("y", 1),99 )100 val monoid = FreeMonoid(indeterminateList)101 val gen = exhaustive(listOf(Pair(0, 1), Pair(1, 2), Pair(2, 1), Pair(3, 0), Pair(4, 0)))102 checkAll(gen) { (degree, size) ->103 monoid.listElements(degree).size shouldBe size104 }105 }106 "two generators of negative odd degrees" {107 val indeterminateList = listOf(108 Indeterminate("x", -1),109 Indeterminate("y", -1),110 )111 val monoid = FreeMonoid(indeterminateList)112 val gen = exhaustive(listOf(Pair(0, 1), Pair(-1, 2), Pair(-2, 1), Pair(-3, 0), Pair(-4, 0)))113 checkAll(gen) { (degree, size) ->114 monoid.listElements(degree).size shouldBe size115 }116 }117 "polynomial algebra tensor exterior algebra" {118 val indeterminateList = listOf(119 Indeterminate("x", 1),120 Indeterminate("y", 2),121 )122 val monoid = FreeMonoid(indeterminateList)123 val gen = exhaustive(listOf(0, 1, 2, 3, 4))124 checkAll(gen) { degree ->125 monoid.listElements(degree).size shouldBe 1126 }127 }128 "listElements() should return the empty list for a negative degree if the generators are positive" {129 val indeterminateList = listOf(130 Indeterminate("x", 1),131 Indeterminate("y", 2),132 )133 val monoid = FreeMonoid(indeterminateList)134 checkAll(Arb.negativeInts()) { degree ->135 monoid.listElements(degree).isEmpty().shouldBeTrue()136 }137 }138 "listElements() should return the empty list for a positive degree if the generators are negative" {139 val indeterminateList = listOf(140 Indeterminate("x", -1),141 Indeterminate("y", -2),142 )143 val monoid = FreeMonoid(indeterminateList)144 checkAll(Arb.positiveInts()) { degree ->145 monoid.listElements(degree).isEmpty().shouldBeTrue()146 }147 }148 "listDegreesForAugmentedDegree() test" - {149 val degreeGroup = MultiDegreeGroup(150 listOf(151 DegreeIndeterminate("N", 1)152 )153 )154 val (n) = degreeGroup.generatorList155 degreeGroup.context.run {156 val indeterminateList = listOf(157 Indeterminate("a", 2 * n),158 Indeterminate("b", 2 * n),...

Full Screen

Full Screen

SemaphoreTest.kt

Source:SemaphoreTest.kt Github

copy

Full Screen

...4import io.kotest.matchers.shouldBe5import io.kotest.property.Arb6import io.kotest.property.arbitrary.int7import io.kotest.property.arbitrary.map8import io.kotest.property.arbitrary.positiveInts9import io.kotest.property.arbitrary.string10import io.kotest.property.checkAll11import kotlinx.coroutines.withTimeoutOrNull12import kotlin.time.ExperimentalTime13import kotlin.time.milliseconds14@ExperimentalTime15class SemaphoreTest : ArrowFxSpec(16 spec = {17 "acquire n times synchronously" {18 checkAll(Arb.positiveInts(max = 20).map(Int::toLong)) { n ->19 val s = Semaphore(n)20 repeat(n.toInt()) {21 s.acquire()22 }23 s.available() shouldBe 024 }25 }26 "acquireN synchronously" {27 checkAll(Arb.positiveInts().map(Int::toLong)) { n ->28 val s = Semaphore(n)29 s.acquireN(n)30 s.available() shouldBe 031 }32 }33 "releaseN can add permits" {34 checkAll(Arb.positiveInts().map(Int::toLong)) { n ->35 val s = Semaphore(n)36 s.releaseN(n)37 s.available() shouldBe n * 238 }39 }40 "releaseN hands out outstanding permits to waiting acquireN" {41 checkAll(Arb.positiveInts().map(Int::toLong), Arb.string()) { n, x ->42 val s = Semaphore(n / 2)43 val start = Promise<Unit>()44 val f = ForkAndForget {45 start.complete(Unit)46 s.acquireN(n)47 x48 }49 start.get()50 s.releaseN(n)51 f.join() shouldBe x52 }53 }54 "tryAcquire with available permits" {55 checkAll(Arb.positiveInts().map(Int::toLong)) { n ->56 val s = Semaphore(n)57 s.acquireN(n - 1)58 s.tryAcquire() shouldBe true59 }60 }61 "tryAcquire with no available permits" {62 checkAll(Arb.positiveInts().map(Int::toLong)) { n ->63 val s = Semaphore(n)64 s.acquireN(n)65 s.tryAcquire() shouldBe false66 }67 }68 "available with available permits" {69 val minPermits = 1070 checkAll(71 Arb.int(minPermits, Int.MAX_VALUE).map(Int::toLong),72 Arb.int(1, minPermits).map(Int::toLong)73 ) { n, x ->74 val s = Semaphore(n)75 s.acquireN(n - x)76 s.available() shouldBe x77 }78 }79 "available with no available permits" {80 checkAll(Arb.positiveInts().map(Int::toLong)) { n ->81 val s = Semaphore(n)82 s.acquireN(n)83 s.available() shouldBe 084 }85 }86 "tryAcquireN with no available permits" {87 checkAll(Arb.positiveInts().map(Int::toLong)) { n ->88 val s = Semaphore(n)89 s.acquireN(n)90 s.tryAcquireN(1) shouldBe false91 }92 }93 "count with available permits" {94 val minPermits = 1095 checkAll(96 Arb.int(minPermits, Int.MAX_VALUE).map(Int::toLong),97 Arb.int(1, minPermits)98 ) { n, x ->99 val s = Semaphore(n)100 repeat(x) { s.acquire() }101 s.available() shouldBe s.count()102 }103 }104 "count with no available permits" {105 checkAll(Arb.positiveInts().map(Int::toLong)) { n ->106 val s = Semaphore(n)107 s.acquireN(n)108 s.count() shouldBe 0109 }110 }111 suspend fun testOffsettingReleasesAcquires(112 acquires: suspend (Semaphore, List<Long>) -> Unit,113 releases: suspend (Semaphore, List<Long>) -> Unit114 ): Unit {115 val permits = listOf(1L, 0, 20, 4, 0, 5, 2, 1, 1, 3)116 val s = Semaphore(0)117 parTupledN(118 { acquires(s, permits) },119 { releases(s, permits) }120 )121 s.count() shouldBe 0122 }123 "offsetting acquires/releases - acquires parallel with releases" {124 testOffsettingReleasesAcquires(125 { s, p -> p.forEach { s.acquireN(it) } },126 { s, p -> p.reversed().forEach { s.releaseN(it) } }127 )128 }129 "offsetting acquires/releases - individual acquires/increment in parallel" {130 testOffsettingReleasesAcquires(131 { s, p -> p.parTraverse { s.acquireN(it) } },132 { s, p -> p.reversed().parTraverse { s.releaseN(it) } }133 )134 }135 "Failure in withPermitN results in correct error & releases permits" {136 checkAll(Arb.positiveInts().map(Int::toLong), Arb.throwable()) { n, e ->137 val s = Semaphore(n)138 val p = Promise<Long>()139 val r = Either.catch {140 s.withPermitN(n) {141 p.complete(s.available())142 throw e143 }144 }145 r shouldBe Either.Left(e)146 p.get() shouldBe 0147 s.available() shouldBe n148 }149 }150 "withPermitN does not leak fibers or permits upon failure" {151 checkAll(Arb.positiveInts().map(Int::toLong), Arb.throwable()) { n, e ->152 val s = Semaphore(n)153 val r = Either.catch {154 parTupledN(155 {156 s.withPermitN(n + 1) { // Requests a n + 1 permits, puts count to -1157 s.release() // Never runs due to async exception158 }159 },160 { throw e }161 ) // Cancels other parallel op162 }163 r should leftException(e) // Proof parallel op failed164 s.count() shouldBe n // Proof that withPermitN released on cancel165 }166 }167 "withPermitN does not leak fibers or permits upon cancellation" {168 checkAll(Arb.positiveInts().map(Int::toLong)) { n -> // 100 iterations takes 1 second169 val s = Semaphore(n)170 val r = withTimeoutOrNull(10.milliseconds) {171 s.withPermitN(n + 1) { // Requests a n + 1 permits, puts count to -1172 s.release() // Timeouts out due to no permit173 } // cancel should put count back to 0174 }175 r shouldBe null // proof of timeout176 // proof of permit cancel, if release ran it would be 1L177 s.count() shouldBe n178 }179 }180 "acquireN does not leak fibers or permits upon failure" {181 checkAll(Arb.positiveInts().map(Int::toLong), Arb.throwable()) { n, e ->182 val s = Semaphore(n)183 val r = Either.catch {184 parTupledN(185 {186 s.acquireN(n + 1) // Puts count to -1, and gets cancelled by async exception187 },188 { throw e }189 )190 }191 r should leftException(e) // Proof parallel op failed192 s.count() shouldBe n // Proof that acquireN released on cancel193 }194 }195 "acquireN does not leak permits upon cancellation" {196 checkAll(Arb.positiveInts().map(Int::toLong)) { n -> // 100 iterations takes 1 second197 val s = Semaphore(n)198 val x = withTimeoutOrNull(10.milliseconds) {199 // Puts count to -1, and times out before acquired so should out count back to 1200 s.acquireN(n + 1)201 s.release() // Never runs202 }203 x shouldBe null // proof of timeout204 // proof of cancel, if release ran then would be 2L205 s.count() shouldBe n206 }207 }208 }209)...

Full Screen

Full Screen

ItemsTests.kt

Source:ItemsTests.kt Github

copy

Full Screen

...7import io.kotest.matchers.maps.shouldContainKey8import io.kotest.matchers.maps.shouldContainKeys9import io.kotest.matchers.shouldBe10import io.kotest.property.Arb11import io.kotest.property.arbitrary.positiveInts12import io.kotest.property.checkAll13import io.kotest.property.forAll14@Suppress("unused")15class ItemsTests : StringSpec({16 "new items should be empty" {17 with(Items<Int>({ it.toString() })) {18 all.shouldBeEmpty()19 items.shouldBeEmpty()20 filters.shouldBeEmpty()21 selected.shouldBeEmpty()22 sortInfo shouldBe null23 }24 }25 "adding items should return the correct collection properties" {26 checkAll(Arb.positiveInts(100)) { size ->27 val numbers = (0 until size).toList()28 with(Items<Int>({ it.toString() }).addAll(numbers)) {29 all shouldContainInOrder numbers30 items shouldContainInOrder numbers31 filters.shouldBeEmpty()32 selected.shouldBeEmpty()33 sortInfo shouldBe null34 }35 }36 }37 "filtering items should work" {38 val numbers = (1..10).toList()39 var numberItems = Items<Int>({ it.toString() }).addAll(numbers)40 numberItems = numberItems.addFilter("even") { it % 2 == 0 }41 with(numberItems) {42 all shouldContainInOrder numbers43 items shouldContainInOrder listOf(2, 4, 6, 8, 10)44 filters shouldContainKey "even"45 }46 numberItems = numberItems.addFilter("three") { it % 3 == 0 }47 with(numberItems) {48 all shouldContainInOrder numbers49 items shouldContainInOrder listOf(6)50 filters.shouldContainKeys("even", "three")51 }52 numberItems = numberItems.removeFilter("even")53 with(numberItems) {54 all shouldContainInOrder numbers55 items shouldContainInOrder listOf(3, 6, 9)56 filters shouldContainKey "three"57 }58 numberItems = numberItems.removeFilter("foo")59 with(numberItems) {60 all shouldContainInOrder numbers61 items shouldContainInOrder listOf(3, 6, 9)62 filters shouldContainKey "three"63 }64 numberItems = numberItems.removeFilter("three")65 with(numberItems) {66 all shouldContainInOrder numbers67 items shouldContainInOrder numbers68 filters.shouldBeEmpty()69 }70 }71 "sorting items should work" {72 val numbers = listOf(2, 65, 7, 89, 33, 123, 38, 75)73 var numberItems = Items<Int>({ it.toString() }).addAll(numbers)74 val asc = SortInfo<Int>("nat", "Natural", comparator = naturalOrder())75 numberItems = numberItems.sortWith(asc)76 with(numberItems) {77 all shouldContainInOrder numbers78 items shouldContainInOrder listOf(2, 7, 33, 38, 65, 75, 89, 123)79 sortInfo shouldBe asc80 }81 val desc = asc.toggle()82 numberItems = numberItems.sortWith(desc)83 with(numberItems) {84 all shouldContainInOrder numbers85 items shouldContainInOrder listOf(123, 89, 75, 65, 38, 33, 7, 2)86 sortInfo shouldBe desc87 }88 }89 "selecting no items should work" {90 forAll(Arb.positiveInts(100)) { size ->91 val numbers = (0 until size).toList()92 with(Items<Int>({ it.toString() }).addAll(numbers).selectNone()) {93 selected.isEmpty()94 }95 }96 }97 "selecting all items of the current page should work" {98 forAll(Arb.positiveInts(100), Arb.positiveInts(100)) { size, pageSize ->99 val numbers = (0 until size).toList()100 with(101 Items<Int>(idProvider = { it.toString() }, pageInfo = PageInfo(pageSize = pageSize))102 .addAll(numbers)103 .selectPage()104 ) {105 selected.size == if (size < pageSize) pageInfo.total else pageInfo.pageSize106 }107 }108 }109 "select all items should work" {110 forAll(Arb.positiveInts(100)) { size ->111 val numbers = (0 until size).toList()112 with(Items<Int>({ it.toString() }).addAll(numbers).selectAll()) {113 selected.size == items.size114 }115 }116 }117 "select multiple items items should work" {118 val numbers = (1..10).toList()119 var numberItems = Items<Int>({ it.toString() }).addAll(numbers)120 numberItems = numberItems.select(2, true)121 with(numberItems) {122 selected.size shouldBe 1123 selected shouldContain "2"124 }...

Full Screen

Full Screen

PageInfoTests.kt

Source:PageInfoTests.kt Github

copy

Full Screen

...7import io.kotest.matchers.shouldBe8import io.kotest.property.Arb9import io.kotest.property.arbitrary.int10import io.kotest.property.arbitrary.negativeInts11import io.kotest.property.arbitrary.positiveInts12import io.kotest.property.checkAll13import kotlin.math.min14@Suppress("EmptyRange", "unused")15class PageInfoTests : StringSpec({16 "new page info should be empty" {17 with(PageInfo()) {18 range shouldBe 0..019 pages shouldBe 120 firstPage shouldBe true21 lastPage shouldBe true22 }23 }24 "using an illegal page size should result in an exception" {25 checkAll(Arb.int(Int.MIN_VALUE..0)) { pageSize ->26 shouldThrow<IllegalArgumentException> {27 PageInfo(pageSize = pageSize)28 }29 }30 }31 "using an illegal page should result in an exception" {32 checkAll(Arb.negativeInts()) { page ->33 shouldThrow<IllegalArgumentException> {34 PageInfo(page = page)35 }36 }37 }38 "using an illegal total should result in an exception" {39 checkAll(Arb.negativeInts()) { total ->40 shouldThrow<IllegalArgumentException> {41 PageInfo(total = total)42 }43 }44 }45 "using valid ranges and pages should work" {46 checkAll(Arb.positiveInts(), Arb.positiveInts()) { pageSize, total ->47 with(PageInfo(pageSize = pageSize, total = total)) {48 range.first shouldBeGreaterThanOrEqual 149 range.last shouldBeLessThanOrEqual total50 page shouldBeInRange (0 until pages)51 firstPage shouldBe (page == 0)52 lastPage shouldBe (page == pages - 1)53 }54 }55 }56 "going to the first page should work" {57 checkAll(Arb.positiveInts(), Arb.positiveInts()) { pageSize, total ->58 val pageInfo = PageInfo(pageSize = pageSize, total = total).gotoFirstPage()59 with(pageInfo) {60 range.first shouldBe 161 range.last shouldBe min(total, pageSize)62 page shouldBe 063 firstPage shouldBe true64 lastPage shouldBe (pages == 1)65 }66 }67 }68 "going to the last page should work" {69 checkAll(Arb.positiveInts(), Arb.positiveInts()) { pageSize, total ->70 val pageInfo = PageInfo(pageSize = pageSize, total = total).gotoLastPage()71 with(pageInfo) {72 range.first shouldBe (page * pageSize) + 173 range.last shouldBe min(total, range.first + pageSize - 1)74 page shouldBe pages - 175 firstPage shouldBe (pages == 1)76 lastPage shouldBe true77 }78 }79 }80 "going to a specific page should work" {81 checkAll(Arb.positiveInts(), Arb.positiveInts(), Arb.int()) { pageSize, total, pg ->82 val pageInfo = PageInfo(pageSize = pageSize, total = total).gotoPage(pg)83 with(pageInfo) {84 range.first shouldBeGreaterThanOrEqual 185 range.last shouldBeLessThanOrEqual total86 page shouldBeInRange (0 until pages)87 firstPage shouldBe (page == 0)88 lastPage shouldBe (page == pages - 1)89 }90 }91 }92 "changing the page size should work" {93 checkAll(Arb.positiveInts(), Arb.positiveInts(), Arb.positiveInts()) { pageSize, total, ps ->94 val pageInfo = PageInfo(pageSize = pageSize, total = total).pageSize(ps)95 with(pageInfo) {96 range.first shouldBeGreaterThanOrEqual 197 range.last shouldBeLessThanOrEqual total98 page shouldBeInRange (0 until pages)99 firstPage shouldBe (page == 0)100 lastPage shouldBe (page == pages - 1)101 }102 }103 }104 "changing the total number of items should work" {105 checkAll(Arb.positiveInts(), Arb.positiveInts(), Arb.positiveInts()) { pageSize, total, tt ->106 val pageInfo = PageInfo(pageSize = pageSize, total = total).total(tt)107 with(pageInfo) {108 range.first shouldBeGreaterThanOrEqual 1109 range.last shouldBeLessThanOrEqual tt110 page shouldBeInRange (0 until pages)111 firstPage shouldBe (page == 0)112 lastPage shouldBe (page == pages - 1)113 }114 }115 }116})...

Full Screen

Full Screen

EmployeeSpec.kt

Source:EmployeeSpec.kt Github

copy

Full Screen

...7import io.kotest.matchers.nulls.shouldNotBeNull8import io.kotest.matchers.shouldBe9import io.kotest.property.Arb10import io.kotest.property.arbitrary.next11import io.kotest.property.arbitrary.positiveInts12import io.kotest.property.arbitrary.stringPattern13import io.qameta.allure.Epic14import io.qameta.allure.Feature15import io.qameta.allure.Link16import io.qameta.allure.Story17import okhttp3.Credentials18import retrofit2.Response19import retrofit2.awaitResponse20import ru.iopump.qa.sample.RegistryAndProjectConfiguration.employeeService21import ru.iopump.qa.sample.RegistryAndProjectConfiguration.wiremockClient22import ru.iopump.qa.sample.model.Employee23@ExperimentalKotest24@Epic("Tproger example")25@Feature("Employee endpoint")26@Story("CRUD")27@Link("tproger.ru", url = "https://tproger.ru/")28class EmployeeSpec : FreeSpec() {29 override fun concurrency(): Int = 230 init {31 "Scenario: Getting employee by id" - {32 var expectedId = 033 "Given test environment is up and test data prepared" {34 expectedId = Arb.positiveInts().next()35 }36 lateinit var response: Response<Employee>37 "When client sent request to get the employee by id=$expectedId" {38 response = employeeService.get(expectedId).awaitResponse()39 }40 "Then client received response with status 200 and id=$expectedId" {41 response.asClue {42 it.code() shouldBe 20043 it.body().shouldNotBeNull().asClue { employee ->44 employee.name shouldBe "Max"45 employee.id shouldBe expectedId46 }47 }48 }...

Full Screen

Full Screen

FindPairWithSumSpec.kt

Source:FindPairWithSumSpec.kt Github

copy

Full Screen

...11import io.kotest.property.checkAll12import io.kotest.property.forAll13val rangeAtLeastTwoNumbersLong = Arb.int(min = 1).map { (0..1).toList() }14val pairOfPositiveInts: Arb<Pair<Int, Int>> =15 Arb.bind(Arb.positiveInt(), Arb.positiveInt()) { x, y -> Pair(x, y) }16class FindPairWithSumSpec : FunSpec({17 context("returns null with less than 2 elements") {18 withData(listOf(), listOf(0)) { rows -> Unit19 checkAll<Int> { i ->20 rows.pairsWithSum(i).shouldBeEmpty()21 }22 }23 }24 test("findPairWithSum returns pair of numbers that sum to specified amount") {25 checkAll(Arb.list(Arb.int()), pairOfPositiveInts) { otherNumbers, pair ->26 val sum = pair.first + pair.second27 pair shouldBeIn (listOf(pair.first, pair.second) + otherNumbers).pairsWithSum(sum)28 }29 }...

Full Screen

Full Screen

FlowTest.kt

Source:FlowTest.kt Github

copy

Full Screen

...4import io.kotest.matchers.longs.shouldBeLessThan5import io.kotest.matchers.shouldBe6import io.kotest.property.Arb7import io.kotest.property.arbitrary.int8import io.kotest.property.arbitrary.positiveInts9import kotlinx.coroutines.flow.collect10import kotlinx.coroutines.flow.flow11import kotlinx.coroutines.flow.reduce12import kotlinx.coroutines.test.runBlockingTest13import kotlin.time.ExperimentalTime14import kotlin.time.milliseconds15@ExperimentalTime16class FlowTest : ArrowFxSpec(17 spec = {18 "Retry - flow fails" {19 checkAll(Arb.int(), Arb.positiveInts(10)) { a, n ->20 var counter = 021 val e = shouldThrow<RuntimeException> {22 flow {23 emit(a)24 if (++counter <= 11) throw RuntimeException("Bang!")25 }.retry(Schedule.recurs(n))26 .collect()27 }28 e.message shouldBe "Bang!"29 }30 }31 "Retry - flow succeeds" {32 checkAll(Arb.int(), Arb.int(5, 10)) { a, n ->33 var counter = 0...

Full Screen

Full Screen

PropertyBasedTestingSpec.kt

Source:PropertyBasedTestingSpec.kt Github

copy

Full Screen

...7import io.kotest.matchers.types.shouldBeInstanceOf8import io.kotest.property.Arb9import io.kotest.property.arbitrary.bind10import io.kotest.property.arbitrary.default11import io.kotest.property.arbitrary.positiveInts12import io.kotest.property.arbitrary.string13import io.kotest.property.checkAll14class PropertyBasedTestingSpec : StringSpec() {15 data class Person(val name: String, val age: Int)16 init {17 "can do property-based testing - with 100 examples" {18 checkAll<String, String> { a, b ->19 (a + b) shouldHaveLength(a.length + b.length)20 }21 }22 // This does not work :-(23 /*24 "can run a defined number of tests" {25 forAll(100) { a: String, b: String ->26 (a + b).length shouldBe a.length + b.length27 }28 }29 */30 "generate the defaults for list" {31 val gen = Arb.default<List<Int>>()32 checkAll(10, gen) { list ->33 list.forAll { i ->34 i.shouldBeInstanceOf<Int>()35 }36 }37 }38 "generate the defaults for set" {39 val gen = Arb.default<Set<String>>()40 checkAll(gen) { inst ->41 inst.forAll { i ->42 i.shouldBeInstanceOf<String>()43 }44 }45 }46 "string size" {47 checkAll<String, String> { a, b ->48 (a + b) shouldHaveLength(a.length + b.length)49 }50 }51 "person generator" {52 val gen = Arb.bind(Arb.string(), Arb.positiveInts(), ::Person)53 checkAll(gen) {54 it.name shouldNotBe null55 it.age shouldBeGreaterThan(0)56 }57 }58 }59}...

Full Screen

Full Screen

positive

Using AI Code Generation

copy

Full Screen

1io.kotest.matchers.ints.shouldBeGreaterThan(10)2io.kotest.matchers.ints.shouldBeGreaterThanOrEqual(10)3io.kotest.matchers.ints.shouldBeLessThan(10)4io.kotest.matchers.ints.shouldBeLessThanOrEqual(10)5io.kotest.matchers.ints.shouldBeBetween(5, 10)6io.kotest.matchers.ints.shouldBeBetween(5, 10, true, true)7io.kotest.matchers.ints.shouldBeBetween(5, 10, true, false)8io.kotest.matchers.ints.shouldBeBetween(5, 10, false, true)9io.kotest.matchers.ints.shouldBeBetween(5, 10, false, false)10io.kotest.matchers.ints.shouldBePositive()11io.kotest.matchers.ints.shouldBeNegative()12io.kotest.matchers.ints.shouldBeZero()13io.kotest.matchers.ints.shouldBeOdd()14io.kotest.matchers.ints.shouldBeEven()15io.kotest.matchers.ints.shouldBeMultipleOf(3)16io.kotest.matchers.ints.shouldBeOneOf(1, 2, 3)17io.kotest.matchers.ints.shouldBeOneOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)18io.kotest.matchers.ints.shouldNotBeOneOf(1, 2, 3)19io.kotest.matchers.ints.shouldNotBeOneOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)20io.kotest.matchers.ints.shouldBeInRange(5, 10)21io.kotest.matchers.ints.shouldNotBeInRange(5, 10)22io.kotest.matchers.ints.shouldBeCloseTo(10, 1)23io.kotest.matchers.ints.shouldBeCloseTo(10, 1, 1)24io.kotest.matchers.ints.shouldBeCloseTo(10, 1, 1, 1)25io.kotest.matchers.ints.shouldBeCloseTo(10, 1, 1, 1, 1)

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful