How to use test method of io.kotest.matchers.doubles.Exactly class

Best Kotest code snippet using io.kotest.matchers.doubles.Exactly.test

matchers.kt

Source:matchers.kt Github

copy

Full Screen

1package tutorial.kotest2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.assertions.throwables.shouldThrowAny4import io.kotest.assertions.throwables.shouldThrowExactly5import io.kotest.core.spec.style.DescribeSpec6import io.kotest.core.test.AssertionMode7import io.kotest.matchers.booleans.shouldBeTrue8import io.kotest.matchers.collections.shouldBeIn9import io.kotest.matchers.collections.shouldBeOneOf10import io.kotest.matchers.collections.shouldBeSameSizeAs11import io.kotest.matchers.collections.shouldBeSingleton12import io.kotest.matchers.collections.shouldBeSmallerThan13import io.kotest.matchers.collections.shouldBeSorted14import io.kotest.matchers.collections.shouldBeUnique15import io.kotest.matchers.collections.shouldContain16import io.kotest.matchers.collections.shouldContainAll17import io.kotest.matchers.collections.shouldContainAnyOf18import io.kotest.matchers.collections.shouldContainDuplicates19import io.kotest.matchers.collections.shouldContainExactly20import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder21import io.kotest.matchers.collections.shouldContainInOrder22import io.kotest.matchers.collections.shouldContainNull23import io.kotest.matchers.collections.shouldEndWith24import io.kotest.matchers.collections.shouldHaveAtLeastSize25import io.kotest.matchers.collections.shouldHaveLowerBound26import io.kotest.matchers.collections.shouldHaveSingleElement27import io.kotest.matchers.collections.shouldHaveSize28import io.kotest.matchers.collections.shouldHaveUpperBound29import io.kotest.matchers.collections.shouldNotContainAnyOf30import io.kotest.matchers.collections.shouldNotHaveElementAt31import io.kotest.matchers.collections.shouldStartWith32import io.kotest.matchers.comparables.shouldBeEqualComparingTo33import io.kotest.matchers.comparables.shouldBeLessThanOrEqualTo34import io.kotest.matchers.date.shouldBeToday35import io.kotest.matchers.date.shouldHaveSameHoursAs36import io.kotest.matchers.doubles.Percentage37import io.kotest.matchers.doubles.beNaN38import io.kotest.matchers.doubles.plusOrMinus39import io.kotest.matchers.doubles.shouldBeNaN40import io.kotest.matchers.doubles.shouldNotBeNaN41import io.kotest.matchers.equality.shouldBeEqualToComparingFields42import io.kotest.matchers.equality.shouldBeEqualToComparingFieldsExcept43import io.kotest.matchers.equality.shouldBeEqualToIgnoringFields44import io.kotest.matchers.equality.shouldBeEqualToUsingFields45import io.kotest.matchers.file.shouldBeADirectory46import io.kotest.matchers.file.shouldBeAbsolute47import io.kotest.matchers.file.shouldExist48import io.kotest.matchers.file.shouldNotBeEmpty49import io.kotest.matchers.ints.beOdd50import io.kotest.matchers.ints.shouldBeBetween51import io.kotest.matchers.ints.shouldBeInRange52import io.kotest.matchers.ints.shouldBeLessThan53import io.kotest.matchers.ints.shouldBeLessThanOrEqual54import io.kotest.matchers.ints.shouldBeOdd55import io.kotest.matchers.ints.shouldBePositive56import io.kotest.matchers.ints.shouldBeZero57import io.kotest.matchers.iterator.shouldBeEmpty58import io.kotest.matchers.iterator.shouldHaveNext59import io.kotest.matchers.maps.shouldBeEmpty60import io.kotest.matchers.maps.shouldContain61import io.kotest.matchers.maps.shouldContainAll62import io.kotest.matchers.maps.shouldContainExactly63import io.kotest.matchers.maps.shouldContainKey64import io.kotest.matchers.nulls.shouldBeNull65import io.kotest.matchers.nulls.shouldNotBeNull66import io.kotest.matchers.shouldBe67import io.kotest.matchers.shouldNot68import io.kotest.matchers.shouldNotBe69import io.kotest.matchers.string.beEmpty70import io.kotest.matchers.string.shouldBeBlank71import io.kotest.matchers.string.shouldBeEmpty72import io.kotest.matchers.string.shouldBeEqualIgnoringCase73import io.kotest.matchers.string.shouldBeInteger74import io.kotest.matchers.string.shouldBeLowerCase75import io.kotest.matchers.string.shouldBeUpperCase76import io.kotest.matchers.string.shouldContain77import io.kotest.matchers.string.shouldContainADigit78import io.kotest.matchers.string.shouldContainIgnoringCase79import io.kotest.matchers.string.shouldContainOnlyDigits80import io.kotest.matchers.string.shouldContainOnlyOnce81import io.kotest.matchers.string.shouldEndWith82import io.kotest.matchers.string.shouldHaveLength83import io.kotest.matchers.string.shouldHaveLineCount84import io.kotest.matchers.string.shouldHaveMaxLength85import io.kotest.matchers.string.shouldHaveMinLength86import io.kotest.matchers.string.shouldHaveSameLengthAs87import io.kotest.matchers.string.shouldMatch88import io.kotest.matchers.string.shouldNotBeEmpty89import io.kotest.matchers.string.shouldStartWith90import io.kotest.matchers.throwable.shouldHaveCause91import io.kotest.matchers.throwable.shouldHaveCauseInstanceOf92import io.kotest.matchers.throwable.shouldHaveCauseOfType93import io.kotest.matchers.throwable.shouldHaveMessage94import io.kotest.matchers.types.shouldBeInstanceOf95import io.kotest.matchers.types.shouldBeSameInstanceAs96import io.kotest.matchers.types.shouldBeTypeOf97import io.kotest.matchers.uri.shouldHaveHost98import io.kotest.matchers.uri.shouldHavePort99import io.kotest.matchers.uri.shouldHaveScheme100import java.io.File101import java.net.URI102import java.time.LocalDate103import java.time.LocalTime104// https://kotest.io/docs/assertions/core-matchers.html105class MatchersTest : DescribeSpec({106 describe("general") {107 it("basics") {108 (1 == 1).shouldBeTrue()109 (2 + 2) shouldBe 4110 val foo: Any = "foobar"111 foo.shouldBeTypeOf<String>() shouldContain "fo"112 "".shouldBeEmpty()113 "x".shouldNot(beEmpty()) // manually negate114 "x".shouldNotBeEmpty() // reusable115 URI("https://tba") shouldHaveHost "tba"116 URI("https://tba:81") shouldHavePort 81117 URI("https://tba") shouldHaveScheme "https"118 File("/").apply {119 shouldExist()120 shouldBeADirectory()121 shouldBeAbsolute()122 shouldNotBeEmpty()123 }124 // executable, hidden, readable, smaller, writeable, containFile, extension, path, ...125 LocalDate.now().shouldBeToday()126 // before/after, within, same, between, have year/month/day/hour/...127 LocalTime.now().shouldHaveSameHoursAs(LocalTime.now())128 // before/after/between, sameMinute/Seconds/Nanos129 }130 it("numbers") {131 1 shouldBeLessThan 2132 1 shouldBeLessThanOrEqual 1 // Int-based; returns this133 1 shouldBeLessThanOrEqualTo 1 // Comparble-based; void134 1 shouldBeEqualComparingTo 1 // Comparable-based135 1.shouldBeBetween(0, 2)136 1 shouldBeInRange 0..2137 0.shouldBeZero()138 1.shouldBePositive()139 1.shouldBeOdd()140 (1.2).shouldBe(1.20001.plusOrMinus(Percentage(20.0)))141 (1.2).shouldNotBeNaN()142 }143 it("strings") {144 // generic: "abc" shouldBe "abc"145 "aBc" shouldBeEqualIgnoringCase "abc"146 "".shouldBeEmpty()147 " ".shouldBeBlank() // empty or whitespace148 "abc" shouldContain ("b")149 "aBc" shouldContainIgnoringCase "bc"150 "x-a-x" shouldContain """\-[a-z]\-""".toRegex()151 "-a-" shouldMatch """\-[a-z]\-""".toRegex()152 "abc" shouldStartWith ("a")153 "abc" shouldEndWith ("c")154 "ab aa" shouldContainOnlyOnce "aa"155 "abc".shouldBeLowerCase()156 "ABC".shouldBeUpperCase()157 "abc" shouldHaveLength 3158 "a\nb" shouldHaveLineCount 2159 "ab" shouldHaveMinLength 1 shouldHaveMaxLength 3160 "abc" shouldHaveSameLengthAs "foo"161 "1".shouldBeInteger()162 "12".shouldContainOnlyDigits()163 "abc1".shouldContainADigit() // at least one164 }165 it("types") {166 @Connotation167 open class SuperType()168 class SubType : SuperType()169 val sameRef = SuperType()170 sameRef.shouldBeSameInstanceAs(sameRef)171 val superType: SuperType = SubType()172 superType.shouldBeTypeOf<SubType>() // exact runtime match (SuperType won't work!)173 superType.shouldBeInstanceOf<SuperType>() // T or below174// SubType().shouldHaveAnnotation(Connotation::class)175 val nullable: String? = null176 nullable.shouldBeNull()177 }178 it("collections") {179 emptyList<Int>().iterator().shouldBeEmpty()180 listOf(1).iterator().shouldHaveNext()181 listOf(1, 2) shouldContain 1 // at least182 listOf(1, 2) shouldContainExactly listOf(1, 2) // in-order; not more183 listOf(1, 2) shouldContainExactlyInAnyOrder listOf(2, 1) // out-order; not more184 listOf(0, 3, 0, 4, 0).shouldContainInOrder(3, 4) // possible items in between185 listOf(1) shouldNotContainAnyOf listOf(2, 3) // black list186 listOf(1, 2, 3) shouldContainAll listOf(3, 2) // out-order; more187 listOf(1, 2, 3).shouldBeUnique() // no duplicates188 listOf(1, 2, 2).shouldContainDuplicates() // at least one duplicate189 listOf(1, 2).shouldNotHaveElementAt(1, 3)190 listOf(1, 2) shouldStartWith 1191 listOf(1, 2) shouldEndWith 2192 listOf(1, 2) shouldContainAnyOf listOf(2, 3)193 val x = SomeType(1)194 x shouldBeOneOf listOf(x) // by reference/instance195 x shouldBeIn listOf(SomeType(1)) // by equality/structural196 listOf(1, 2, null).shouldContainNull()197 listOf(1) shouldHaveSize 1198 listOf(1).shouldBeSingleton() // size == 1199 listOf(1).shouldBeSingleton {200 it.shouldBeOdd()201 }202 listOf(1).shouldHaveSingleElement {203 beOdd().test(it).passed() // have to return a boolean here :-/204 }205 listOf(2, 3) shouldHaveLowerBound 1 shouldHaveUpperBound 4206 listOf(1) shouldBeSmallerThan listOf(1, 2)207 listOf(1) shouldBeSameSizeAs listOf(2)208 listOf(1, 2) shouldHaveAtLeastSize 1209 listOf(1, 2).shouldBeSorted()210 mapOf(1 to "a").shouldContain(1, "a") // at least this211 mapOf(1 to "a") shouldContainAll mapOf(1 to "a") // at least those212 mapOf(1 to "a") shouldContainExactly mapOf(1 to "a") // not more213 mapOf(1 to "a") shouldContainKey 1214 emptyMap<Any, Any>().shouldBeEmpty()215 }216 it("exceptions") {217 class SubException() : Exception()...

Full Screen

Full Screen

TimeSeriesDBTest.kt

Source:TimeSeriesDBTest.kt Github

copy

Full Screen

1package org.raspikiln.tsdb2import io.kotest.core.spec.style.FunSpec3import io.kotest.matchers.collections.shouldBeMonotonicallyIncreasingWith4import io.kotest.matchers.doubles.shouldBeGreaterThan5import io.kotest.matchers.doubles.shouldBeGreaterThanOrEqual6import io.kotest.matchers.doubles.shouldBeLessThan7import io.kotest.matchers.ints.shouldBeExactly8import io.kotest.matchers.ints.shouldBeLessThan9import io.kotest.matchers.shouldBe10import kotlinx.coroutines.delay11import java.io.File12import java.time.Instant13import java.util.Comparator14import kotlin.random.Random15import kotlin.time.Duration16import kotlin.time.Duration.Companion.hours17import kotlin.time.Duration.Companion.seconds18class TimeSeriesDBTest : FunSpec({19 test("able to write and do things") {20 val db = timeSeriesDb(retention = 10.hours)21 val temperatureA = MetricGenerator(MetricIdentifier(name = "temperatureA"), 0..20)22 val temperatureB = MetricGenerator(MetricIdentifier(name = "temperatureB"), 40..60)23 var metricCount = 024 repeat(2_000) { _ ->25 val metricsAdded = (1..10).random()26 metricCount += metricsAdded27 repeat(metricsAdded) {28 db.write(listOf(temperatureA.next(), temperatureB.next()))29 }30 listOf(temperatureA, temperatureB).forEach { metric ->31 val query = db.query(metric.identifier, Instant.now().minusSeconds(3_000)..Instant.now()).toList()32 query.forEach { metric shouldContain it.value }33 query.shouldBeMonotonicallyIncreasingWith(Comparator.comparing { it.timestamp })34 query.count() shouldBe metricCount35 }36 delay(5)37 }38 }39 test("clear partitions after retention") {40 val db = timeSeriesDb(retention = 10.seconds)41 val metricMeasurement = MetricGenerator(MetricIdentifier(name = "temperatureA"), 0..20)42 repeat(500) {43 db.write(metricMeasurement.next())44 }45 delay(12_000)46 db.write(metricMeasurement.next())47 db.query(48 metricName = metricMeasurement.identifier,49 timestampRange = Instant.now().minusSeconds(20)..Instant.now()50 ).count() shouldBeExactly 151 }52})53data class MetricGenerator(54 val identifier: MetricIdentifier,55 val range: IntRange56) {57 infix fun shouldContain(value: Double) {58 range.first.toDouble() shouldBeLessThan value59 range.last.toDouble() shouldBeGreaterThanOrEqual value60 }61 fun next(): Measurement =62 Measurement(63 metric = identifier,64 datapoint = Datapoint(65 timestamp = Instant.now(),66 value = nextValue()67 )68 )69 private fun nextValue() = Random.Default.nextDouble(range.first.toDouble(), range.last.toDouble())70}71private fun timeSeriesDb(retention: Duration = 10.hours) =72 StandardTimeSeriesDB(options = StandardTimeSeriesDB.Options(73 directory = File("data-test"),74 partitionDuration = 10.seconds,75 partitionCapacity = 1_000,76 retention = retention,77 deleteDelayTime = 0.seconds78 )).apply { purgeAll() }...

Full Screen

Full Screen

RandomTest.kt

Source:RandomTest.kt Github

copy

Full Screen

1package net.dinkla.raytracer.math2import io.kotest.core.spec.style.AnnotationSpec3import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder4import io.kotest.matchers.doubles.shouldBeGreaterThanOrEqual5import io.kotest.matchers.doubles.shouldBeLessThan6import io.kotest.matchers.ints.shouldBeGreaterThanOrEqual7import io.kotest.matchers.ints.shouldBeLessThan8import io.kotest.matchers.shouldBe9import net.dinkla.raytracer.interfaces.Random10class RandomTest : AnnotationSpec() {11 private val NUM = 100012 @Test13 fun randInt() {14 for (i in 0 until NUM) {15 val r = Random.int(10)16 r shouldBeGreaterThanOrEqual 017 r shouldBeLessThan 1018 }19 for (i in 0 until NUM) {20 val r = Random.int(18, 44)21 r shouldBeGreaterThanOrEqual 1822 r shouldBeLessThan 44...

Full Screen

Full Screen

BLEDistanceUnscentedKalmanFilterTest.kt

Source:BLEDistanceUnscentedKalmanFilterTest.kt Github

copy

Full Screen

1package uk.nhs.riskscore.internal2import io.kotest.core.spec.style.StringSpec3import io.kotest.matchers.booleans.shouldBeTrue4import io.kotest.matchers.doubles.shouldBeGreaterThanOrEqual5import io.kotest.matchers.ints.shouldBeExactly6import io.kotest.property.arbitrary.orNull7import io.kotest.property.checkAll8import uk.nhs.riskscore.internal.kotest.bleDistanceUnscentedKalmanFilter9import uk.nhs.riskscore.internal.kotest.nonEmptyList10import uk.nhs.riskscore.internal.kotest.smallNumericDoubles11import uk.nhs.riskscore.internal.kotest.smallPositiveDoubles12internal class BLEDistanceUnscentedKalmanFilterTest : StringSpec({13 "transition function is non-negative" {14 checkAll(15 smallNumericDoubles,16 smallNumericDoubles,17 bleDistanceUnscentedKalmanFilter) { state, noise, filter ->18 val result = filter.transitionFunction(state, noise)19 result shouldBeGreaterThanOrEqual 0.020 }21 }22 "smooth function returns the same number of elements as the input" {23 checkAll(24 100,25 bleDistanceUnscentedKalmanFilter,...

Full Screen

Full Screen

TestVec2.kt

Source:TestVec2.kt Github

copy

Full Screen

1import io.kotest.matchers.doubles.shouldBeExactly2import io.kotest.matchers.ints.shouldBeExactly3import io.kotest.matchers.types.shouldHaveSameHashCodeAs4import io.lacuna.artifex.Vec25import kotlin.test.Test6import org.openrndr.kartifex.Vec2 as KVec27class TestVec2 {8 @Test9 fun testHash() {10 run {11 val v2 = Vec2(0.0, 0.0)12 val kv2 = KVec2(0.0, 0.0)13 v2.shouldHaveSameHashCodeAs(kv2)14 }15 run {16 val v2 = Vec2(2.0, 2.1231)17 val kv2 = KVec2(2.0, 2.1231)18 v2.shouldHaveSameHashCodeAs(kv2)19 }20 }21 @Test22 fun testCompare() {23 val v2 = Vec2(0.0, 0.0)24 val kv2 = KVec2(0.0, 0.0)25 v2.compareTo(v2).shouldBeExactly(kv2.compareTo(kv2))26 val v2a = Vec2(1.0, 0.0)27 val kv2a = KVec2(1.0, 0.0)28 v2a.compareTo(v2).shouldBeExactly(kv2a.compareTo(kv2))29 v2.compareTo(v2a).shouldBeExactly(kv2.compareTo(kv2a))30 }31 @Test32 fun testPseudoNorm() {33 val v2 = Vec2(2100.0, 3220.0)34 val pn = v2.pseudoNorm()35 val kv2 = KVec2(2100.0, 3220.0)36 val kpn = kv2.pseudoNorm()37 pn.x.shouldBeExactly(kpn.x)38 pn.y.shouldBeExactly(kpn.y)39 }40}

Full Screen

Full Screen

FightingTests.kt

Source:FightingTests.kt Github

copy

Full Screen

2import com.gogo.steelbotrun.vkbot.game.battle.actions.ActionType3import com.gogo.steelbotrun.vkbot.game.battle.actions.Area4import com.gogo.steelbotrun.vkbot.game.moves.MovesRepository5import com.gogo.steelbotrun.vkbot.game.character.stats.Stats6import io.kotest.core.spec.style.StringSpec7import io.kotest.matchers.comparables.shouldBeEqualComparingTo8import io.kotest.matchers.doubles.shouldBeExactly9class FightingTests : StringSpec({10 "Moves Repository should contain moves from file" {11 val moves = MovesRepository("/src/test/resources/static/test_moves.txt").get()12 moves.first().name shouldBeEqualComparingTo "Kick"13 moves[1].name shouldBeEqualComparingTo "Side Kick"14 moves.first().getEffect(ActionType.Attack, Area.Body) shouldBeExactly 15.015 moves[1].getEffect(ActionType.Attack, Area.Body) shouldBeExactly 0.016 moves[1].getEffect(ActionType.Attack, Area.Head, Stats("Strength" to 2.0, "Agility" to 1.0)) shouldBeExactly 18.517 moves.first().description shouldBeEqualComparingTo "Kick from Karate movies"18 moves[1].description shouldBeEqualComparingTo "Cool move from fighting on ps3"19 }20})...

Full Screen

Full Screen

exercise11.kt

Source:exercise11.kt Github

copy

Full Screen

1package dev.programadorthi2import io.kotest.core.spec.style.FunSpec3import io.kotest.matchers.doubles.shouldBeExactly4import io.kotest.matchers.string.shouldBeEqualIgnoringCase5import kotlin.random.Random6import kotlin.random.nextULong7class Exercise11Test : FunSpec({8 val random = Random.Default9 val f = { a: Int, b: Double -> a * (1 + b / 100) }10 repeat(6) {11 test("swapArgs $it") {12 val a = random.nextInt()13 val b = random.nextDouble(until = Double.MAX_VALUE)14 val result = swapArgs(curry(f))(b)(a)15 result shouldBeExactly f(a, b)16 }17 }18})...

Full Screen

Full Screen

exercise10.kt

Source:exercise10.kt Github

copy

Full Screen

1package dev.programadorthi2import io.kotest.core.spec.style.FunSpec3import io.kotest.matchers.doubles.shouldBeExactly4import io.kotest.matchers.string.shouldBeEqualIgnoringCase5import kotlin.random.Random6import kotlin.random.nextULong7class Exercise10Test : FunSpec({8 val random = Random.Default9 val f = { a: Int, b: Double -> a * (1 + b / 100) }10 repeat(6) {11 test("curry $it") {12 val a = random.nextInt()13 val b = random.nextDouble(until = Double.MAX_VALUE)14 val result = curry(f)(a)(b)15 result shouldBeExactly f(a, b)16 }17 }18})...

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1 import io.kotest.matchers.doubles.Exactly2 import io.kotest.matchers.doubles.shouldBeExactly3 import io.kotest.matchers.doubles.Tolerance4 import io.kotest.matchers.doubles.shouldBeWithinTolerance5import io.kotest.matchers.doubles.Exactly6import io.kotest.matchers.doubles.shouldBeExactly7import io.kotest.matchers.doubles.Tolerance8import io.kotest.matchers.doubles.shouldBeWithinTolerance

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1 fun test() {2 d1.shouldBeExactly(d2)3 }4`testImplementation("io.kotest:kotest-runner-junit5:4.1.1")` 5`testImplementation("io.kotest:kotest-assertions-core:4.1.1")` 6`testImplementation("io.kotest:kotest-assertions-shared:4.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.

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in Exactly

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful