Best Kotest code snippet using io.kotest.matchers.doubles.Between
DoubleMatchersTest.kt
Source:DoubleMatchersTest.kt
...15import io.kotest.matchers.doubles.lt16import io.kotest.matchers.doubles.lte17import io.kotest.matchers.doubles.negative18import io.kotest.matchers.doubles.positive19import io.kotest.matchers.doubles.shouldBeBetween20import io.kotest.matchers.doubles.shouldBeGreaterThan21import io.kotest.matchers.doubles.shouldBeGreaterThanOrEqual22import io.kotest.matchers.doubles.shouldBeLessThan23import io.kotest.matchers.doubles.shouldBeLessThanOrEqual24import io.kotest.matchers.doubles.shouldBeMultipleOf25import io.kotest.matchers.doubles.shouldBeNaN26import io.kotest.matchers.doubles.shouldBeNegative27import io.kotest.matchers.doubles.shouldBeNegativeInfinity28import io.kotest.matchers.doubles.shouldBePositive29import io.kotest.matchers.doubles.shouldBePositiveInfinity30import io.kotest.matchers.doubles.shouldBeZero31import io.kotest.matchers.doubles.shouldNotBeBetween32import io.kotest.matchers.doubles.shouldNotBeGreaterThan33import io.kotest.matchers.doubles.shouldNotBeGreaterThanOrEqual34import io.kotest.matchers.doubles.shouldNotBeLessThan35import io.kotest.matchers.doubles.shouldNotBeLessThanOrEqual36import io.kotest.matchers.doubles.shouldNotBeNaN37import io.kotest.matchers.doubles.shouldNotBeNegative38import io.kotest.matchers.doubles.shouldNotBeNegativeInfinity39import io.kotest.matchers.doubles.shouldNotBePositive40import io.kotest.matchers.doubles.shouldNotBePositiveInfinity41import io.kotest.matchers.doubles.shouldNotBeZero42import io.kotest.matchers.should43import io.kotest.matchers.shouldBe44import io.kotest.matchers.shouldNot45import io.kotest.matchers.shouldNotBe46import io.kotest.property.arbitrary.filterNot47import io.kotest.property.checkAll48import kotlin.Double.Companion.MAX_VALUE49import kotlin.Double.Companion.MIN_VALUE50import kotlin.Double.Companion.NEGATIVE_INFINITY51import kotlin.Double.Companion.NaN52import kotlin.Double.Companion.POSITIVE_INFINITY53import kotlin.math.absoluteValue54class DoubleMatchersTest : FreeSpec() {55 init {56 "Between matcher" - {57 "Every numeric double that is not Double.MAX_VALUE" - {58 "Should match between" - {59 "When it's equal to the first number of the range" - {60 "With tolerance" {61 checkAll(100, nonMinNorMaxValueDoubles) {62 it.shouldMatchBetween(it, it.slightlyGreater(), it.toleranceValue())63 }64 }65 "Without tolerance" {66 checkAll(100, nonMinNorMaxValueDoubles) {67 it.shouldMatchBetween(it, it.slightlyGreater(), 0.0)68 }69 }70 }71 "When it's between the first number of the range and the last one" - {72 "With tolerance" {73 checkAll(100, nonMinNorMaxValueDoubles) {74 it.shouldMatchBetween(it.slightlySmaller(), it.slightlyGreater(), it.toleranceValue())75 }76 }77 "Without tolerance" {78 checkAll(100, nonMinNorMaxValueDoubles) {79 it.shouldMatchBetween(it.slightlySmaller(), it.slightlyGreater(), 0.0)80 }81 }82 }83 "When it's equal to the last number of the range" - {84 "With tolerance" {85 checkAll(100, nonMinNorMaxValueDoubles) {86 it.shouldMatchBetween(it.slightlySmaller(), it, it.toleranceValue())87 }88 }89 "Without tolerance" {90 checkAll(100, nonMinNorMaxValueDoubles) {91 it.shouldMatchBetween(it.slightlySmaller(), it, 0.0)92 }93 }94 }95 }96 "Should not match between" - {97 "When it's smaller than the first number of the range" - {98 "With tolerance" {99 checkAll(100, nonMinNorMaxValueDoubles) {100 it.shouldNotMatchBetween(it.slightlyGreater(), it.muchGreater(), it.toleranceValue())101 }102 }103 "Without tolerance" {104 checkAll(100, nonMinNorMaxValueDoubles) {105 it.shouldNotMatchBetween(it.slightlyGreater(), it.muchGreater(), 0.0)106 }107 }108 }109 "When it's bigger than the last number of the range" - {110 "With tolerance" {111 checkAll(100, nonMinNorMaxValueDoubles) {112 it.shouldNotMatchBetween(it.muchSmaller(), it.slightlySmaller(), it.toleranceValue())113 }114 }115 "Without tolerance" {116 checkAll(100, nonMinNorMaxValueDoubles) {117 it.shouldNotMatchBetween(it.muchSmaller(), it.slightlySmaller(), 0.0)118 }119 }120 }121 }122 }123 }124 "Less than matcher" - {125 "Every numeric double" - {126 "Should be less than" - {127 "Numbers bigger than itself" {128 checkAll(100, nonMinNorMaxValueDoubles) {129 it shouldMatchLessThan it.slightlyGreater()130 it shouldMatchLessThan it.muchGreater()131 }132 }133 "Infinity" {134 checkAll(100, nonMinNorMaxValueDoubles) {135 it shouldMatchLessThan POSITIVE_INFINITY136 }137 }138 }139 "Should not be less than" - {140 "Itself" {141 checkAll(100, nonMinNorMaxValueDoubles) {142 it shouldNotMatchLessThan it143 }144 }145 "Numbers smaller than itself" {146 checkAll(100, nonMinNorMaxValueDoubles) {147 it shouldNotMatchLessThan it.slightlySmaller()148 it shouldNotMatchLessThan it.muchSmaller()149 }150 }151 "Negative Infinity" {152 checkAll(100, nonMinNorMaxValueDoubles) {153 it shouldNotMatchLessThan it154 }155 }156 "NaN" {157 checkAll(100, nonMinNorMaxValueDoubles) {158 it shouldNotMatchLessThan NaN159 }160 }161 }162 }163 "The non-numeric double" - {164 "NaN" - {165 "Should not be less than" - {166 "Any numeric double" {167 checkAll(100, nonMinNorMaxValueDoubles) {168 NaN shouldNotMatchLessThan it169 }170 }171 "Any non-numeric double" {172 nonNumericDoubles.forEach {173 NaN shouldNotMatchLessThan it174 }175 }176 }177 }178 "Positive Infinity" - {179 "Should not be less than" - {180 "Any numeric double" {181 checkAll(100, nonMinNorMaxValueDoubles) {182 POSITIVE_INFINITY shouldNotMatchLessThan it183 }184 }185 "Any non-numeric double" {186 nonNumericDoubles.forEach {187 POSITIVE_INFINITY shouldNotMatchLessThan it188 }189 }190 }191 }192 "Negative Infinity" - {193 "Should be less than" - {194 "Any numeric double" {195 checkAll(100, nonMinNorMaxValueDoubles) {196 NEGATIVE_INFINITY shouldMatchLessThan it197 }198 }199 "Positive Infinity" {200 NEGATIVE_INFINITY shouldMatchLessThan POSITIVE_INFINITY201 }202 }203 "Should not be less than" - {204 "Itself" {205 NEGATIVE_INFINITY shouldNotMatchLessThan NEGATIVE_INFINITY206 }207 "NaN" {208 NEGATIVE_INFINITY shouldNotMatchLessThan NaN209 }210 }211 }212 }213 }214 "Positive matcher" - {215 "Zero" - {216 "Should not be positive" {217 0.0.shouldNotMatchPositive()218 }219 }220 "Every positive number" - {221 "Should be positive" {222 checkAll(100, numericDoubles.filterNot { it == 0.0 }) {223 it.absoluteValue.shouldMatchPositive()224 }225 }226 }227 "Every non-positive number" - {228 "Should not be positive" {229 checkAll(100, numericDoubles) {230 (-it.absoluteValue).shouldNotMatchPositive()231 }232 }233 }234 "The non-numeric double" - {235 "Positive Infinity" - {236 "Should be positive" {237 POSITIVE_INFINITY.shouldMatchPositive()238 }239 }240 "Negative Infinity" - {241 "Should not be positive" {242 NEGATIVE_INFINITY.shouldNotMatchPositive()243 }244 }245 "NaN" - {246 "Should not be positive" {247 NaN.shouldNotMatchPositive()248 }249 }250 }251 }252 "Negative matcher" - {253 "Zero" - {254 "Should not be negative" {255 0.0.shouldNotMatchNegative()256 }257 }258 "Every negative number" - {259 "Should be negative" {260 checkAll(100, numericDoubles.filterNot { it == 0.0 }) {261 (-it.absoluteValue).shouldMatchNegative()262 }263 }264 }265 "Every non-negative number" - {266 "Should not be negative" {267 checkAll(100, numericDoubles) {268 it.absoluteValue.shouldNotMatchNegative()269 }270 }271 }272 "The non-numeric double" - {273 "Positive Infinity" - {274 "Should not be negative" {275 POSITIVE_INFINITY.shouldNotMatchNegative()276 }277 }278 "Negative Infinity" - {279 "Should be negative" {280 NEGATIVE_INFINITY.shouldMatchNegative()281 }282 }283 "NaN" - {284 "Should not be negative" {285 NaN.shouldNotMatchNegative()286 }287 }288 }289 }290 "MultipleOf matcher" - {291 "Matches a simple multiple" {292 300.0 shouldBeMultipleOf 1.0293 }294 "Fails due to precision problems" {295 shouldFail {296 3.6e300 shouldBeMultipleOf 1.2297 }298 }299 }300 "Less than or equal matcher" - {301 "Every numeric double" - {302 "Should be less than or equal" - {303 "Itself" {304 checkAll(100, nonMinNorMaxValueDoubles) {305 it shouldMatchLessThanOrEqual it306 }307 }308 "Numbers bigger than itself" {309 checkAll(100, nonMinNorMaxValueDoubles) {310 it shouldMatchLessThanOrEqual it.muchGreater()311 it shouldMatchLessThanOrEqual it.slightlyGreater()312 }313 }314 "Positive Infinity" {315 checkAll(100, nonMinNorMaxValueDoubles) {316 it shouldMatchLessThanOrEqual POSITIVE_INFINITY317 }318 }319 }320 "Should not be less than or equal" - {321 "Any number smaller than itself" {322 checkAll(100, nonMinNorMaxValueDoubles) {323 it shouldNotMatchLessThanOrEqual it.slightlySmaller()324 it shouldNotMatchLessThanOrEqual it.muchSmaller()325 }326 }327 "Negative Infinity" {328 checkAll(100, nonMinNorMaxValueDoubles) {329 it shouldNotMatchLessThanOrEqual NEGATIVE_INFINITY330 }331 }332 "NaN" {333 checkAll(100, nonMinNorMaxValueDoubles) {334 it shouldNotMatchLessThanOrEqual NaN335 }336 }337 }338 }339 "The non-numeric double" - {340 "NaN" {341 "Should not be less than or equal" - {342 "Any numeric double" {343 checkAll(100, nonMinNorMaxValueDoubles) {344 NaN shouldNotMatchLessThanOrEqual it345 }346 }347 "Positive Infinity" {348 NaN shouldNotMatchLessThanOrEqual POSITIVE_INFINITY349 }350 "Negative Infinity" {351 NaN shouldNotMatchLessThanOrEqual NEGATIVE_INFINITY352 }353 "Itself" {354 NaN shouldNotMatchLessThanOrEqual NaN355 }356 }357 }358 "Positive Infinity" - {359 "Should be less than or equal" - {360 "Positive Infinity" {361 POSITIVE_INFINITY shouldMatchLessThanOrEqual POSITIVE_INFINITY362 }363 }364 "Should not be less than or equal" - {365 "Any numeric double" {366 checkAll(100, nonMinNorMaxValueDoubles) {367 POSITIVE_INFINITY shouldNotMatchLessThanOrEqual it368 }369 }370 "Negative Infinity" {371 POSITIVE_INFINITY shouldNotMatchLessThanOrEqual NEGATIVE_INFINITY372 }373 "NaN" {374 POSITIVE_INFINITY shouldNotMatchLessThanOrEqual NaN375 }376 }377 }378 "Negative Infinity" - {379 "Should be less than or equal" - {380 "Any numeric double" {381 checkAll(100, nonMinNorMaxValueDoubles) {382 NEGATIVE_INFINITY shouldMatchLessThanOrEqual it383 }384 }385 "Positive Infinity" {386 NEGATIVE_INFINITY shouldMatchLessThanOrEqual POSITIVE_INFINITY387 }388 "Itself" {389 NEGATIVE_INFINITY shouldMatchLessThanOrEqual NEGATIVE_INFINITY390 }391 }392 "Should not be less than or equal" - {393 "NaN" {394 NEGATIVE_INFINITY shouldNotMatchLessThanOrEqual NaN395 }396 }397 }398 }399 }400 "Greater than matcher" - {401 "Every numeric double" - {402 "Should be greater than" - {403 "Numbers smaller than itself" {404 checkAll(100, nonMinNorMaxValueDoubles) {405 it shouldMatchGreaterThan it.slightlySmaller()406 it shouldMatchGreaterThan it.muchSmaller()407 }408 }409 "Negative infinity" {410 checkAll(100, nonMinNorMaxValueDoubles) {411 it shouldMatchGreaterThan NEGATIVE_INFINITY412 }413 }414 }415 "Should not be greater than" - {416 "Itself" {417 checkAll(100, nonMinNorMaxValueDoubles) {418 it shouldNotMatchGreaterThan it419 }420 }421 "Numbers greater than itself" {422 checkAll(100, nonMinNorMaxValueDoubles) {423 it shouldNotMatchGreaterThan it.slightlyGreater()424 it shouldNotMatchGreaterThan it.muchGreater()425 }426 }427 "NaN" {428 checkAll(100, nonMinNorMaxValueDoubles) {429 it shouldNotMatchGreaterThan NaN430 }431 }432 "Positive Infinity" {433 checkAll(100, nonMinNorMaxValueDoubles) {434 it shouldNotMatchGreaterThan POSITIVE_INFINITY435 }436 }437 }438 }439 "The non-numeric double" - {440 "NaN" - {441 "Should not be greater than" - {442 "Itself" {443 NaN shouldNotMatchGreaterThan NaN444 }445 "Any numeric double" {446 checkAll(100, numericDoubles) {447 NaN shouldNotMatchGreaterThan it448 }449 }450 "Positive Infinity" {451 NaN shouldNotMatchGreaterThan POSITIVE_INFINITY452 }453 "Negative Infinity" {454 NaN shouldNotMatchGreaterThan NEGATIVE_INFINITY455 }456 }457 }458 }459 }460 "Greater than or equal matcher" - {461 "Every numeric double" - {462 "Should be greater than or equal to" - {463 "Itself" {464 checkAll(100, nonMinNorMaxValueDoubles) {465 it shouldMatchGreaterThanOrEqual it466 }467 }468 "Numbers smaller than itself" {469 checkAll(100, nonMinNorMaxValueDoubles) {470 it shouldMatchGreaterThanOrEqual it.slightlySmaller()471 it shouldMatchGreaterThanOrEqual it.muchSmaller()472 }473 }474 "Negative Infinity" {475 checkAll(100, nonMinNorMaxValueDoubles) {476 it shouldMatchGreaterThanOrEqual NEGATIVE_INFINITY477 }478 }479 }480 "Should not be greater than or equal to" - {481 "Numbers bigger than itself" {482 checkAll(100, nonMinNorMaxValueDoubles) {483 it shouldNotMatchGreaterThanOrEqual it.slightlyGreater()484 it shouldNotMatchGreaterThanOrEqual it.muchGreater()485 }486 }487 "Positive Infinity" {488 checkAll(100, nonMinNorMaxValueDoubles) {489 it shouldNotMatchGreaterThanOrEqual POSITIVE_INFINITY490 }491 }492 "NaN" {493 checkAll(100, nonMinNorMaxValueDoubles) {494 it shouldNotMatchGreaterThanOrEqual NaN495 }496 }497 }498 }499 "The non-numeric double" - {500 "NaN" - {501 "Should not be greater than or equal to" - {502 "Itself" {503 NaN shouldNotMatchGreaterThanOrEqual NaN504 }505 "Any numeric double" {506 checkAll(100, numericDoubles) {507 NaN shouldNotMatchGreaterThanOrEqual it508 }509 }510 "Positive Infinity" {511 NaN shouldNotMatchGreaterThanOrEqual POSITIVE_INFINITY512 }513 "Negative Infinity" {514 NaN shouldNotMatchGreaterThanOrEqual NEGATIVE_INFINITY515 }516 }517 }518 "Positive Infinity" - {519 "Should be greater than or equal to" - {520 "Itself" {521 POSITIVE_INFINITY shouldMatchGreaterThanOrEqual POSITIVE_INFINITY522 }523 "Negative Infinity" {524 POSITIVE_INFINITY shouldMatchGreaterThanOrEqual NEGATIVE_INFINITY525 }526 "Any numeric double" {527 checkAll(100, numericDoubles) {528 POSITIVE_INFINITY shouldMatchGreaterThanOrEqual it529 }530 }531 }532 "Should not be greater than or equal to" - {533 "NaN" {534 POSITIVE_INFINITY shouldNotMatchGreaterThanOrEqual NaN535 }536 }537 }538 "Negative Infinity" - {539 "Should be greater than or equal to" - {540 "Itself" {541 NEGATIVE_INFINITY shouldMatchGreaterThanOrEqual NEGATIVE_INFINITY542 }543 }544 "Should not be greater than or equal to" - {545 "Any numeric double" {546 checkAll(100, numericDoubles) {547 NEGATIVE_INFINITY shouldNotMatchGreaterThanOrEqual it548 }549 }550 "Positive Infinity" {551 NEGATIVE_INFINITY shouldNotMatchGreaterThanOrEqual POSITIVE_INFINITY552 }553 "NaN" {554 NEGATIVE_INFINITY shouldNotMatchGreaterThanOrEqual NaN555 }556 }557 }558 }559 }560 "NaN matcher" - {561 "Every numeric double" - {562 "Should not be NaN" {563 checkAll(100, numericDoubles) {564 it.shouldNotMatchNaN()565 }566 }567 }568 "The non-numeric double" - {569 "NaN" - {570 "Should match NaN" {571 NaN.shouldMatchNaN()572 }573 }574 "Positive Infinity" - {575 "Should not match NaN" {576 POSITIVE_INFINITY.shouldNotMatchNaN()577 }578 }579 "Negative Infinity" - {580 "Should not match NaN" {581 NEGATIVE_INFINITY.shouldNotMatchNaN()582 }583 }584 }585 }586 "Positive Infinity matcher" - {587 "Any numeric double" - {588 "Should not match positive infinity" {589 checkAll(100, numericDoubles) {590 it.shouldNotMatchPositiveInfinity()591 }592 }593 }594 "The non-numeric double" - {595 "Positive Infinity" - {596 "Should match positive infinity" {597 POSITIVE_INFINITY.shouldMatchPositiveInfinity()598 }599 }600 "Negative Infinity" - {601 "Should not match positive infinity" {602 NEGATIVE_INFINITY.shouldNotMatchPositiveInfinity()603 }604 }605 "NaN" - {606 "Should not match positive infinity" {607 NaN.shouldNotMatchPositiveInfinity()608 }609 }610 }611 }612 "Negative Infinity matcher" - {613 "Any numeric double" - {614 "Should not match negative infinity" {615 checkAll(100, numericDoubles) {616 it.shouldNotMatchNegativeInfinity()617 }618 }619 }620 "The non-numeric double" - {621 "Negative Infinity" - {622 "Should match negative infinity" {623 NEGATIVE_INFINITY.shouldMatchNegativeInfinity()624 }625 }626 "Positive Infinity" - {627 "Should not match negative infinity" {628 POSITIVE_INFINITY.shouldNotMatchNegativeInfinity()629 }630 }631 "NaN" - {632 "Should not match negative infinity" {633 NaN.shouldNotMatchNegativeInfinity()634 }635 }636 }637 }638 "shouldBeZero" {639 (0.0).shouldBeZero()640 (-0.1).shouldNotBeZero()641 (0.1).shouldNotBeZero()642 MIN_VALUE.shouldNotBeZero()643 MAX_VALUE.shouldNotBeZero()644 NaN.shouldNotBeZero()645 POSITIVE_INFINITY.shouldNotBeZero()646 NEGATIVE_INFINITY.shouldNotBeZero()647 }648 }649 private fun shouldThrowAssertionError(message: String, vararg expression: () -> Any?) {650 expression.forEach {651 val exception = shouldThrow<AssertionError>(it)652 exception.message shouldBe message653 }654 }655 private fun Double.shouldMatchBetween(a: Double, b: Double, tolerance: Double) {656 this.shouldBeBetween(a, b, tolerance)657 this shouldBe between(a, b, tolerance)658 this.shouldThrowExceptionOnNotBetween(a, b, tolerance)659 }660 private fun Double.shouldNotMatchBetween(a: Double, b: Double, tolerance: Double) {661 this.shouldNotBeBetween(a, b, tolerance)662 this shouldNotBe between(a, b, tolerance)663 this.shouldThrowExceptionOnBetween(a, b, tolerance)664 }665 private fun Double.shouldThrowExceptionOnBetween(a: Double, b: Double, tolerance: Double) {666 when {667 this < a -> this.shouldThrowMinimumExceptionOnBetween(a, b, tolerance)668 this > b -> this.shouldThrowMaximumExceptionOnBetween(a, b, tolerance)669 else -> throw IllegalStateException()670 }671 }672 private fun Double.shouldThrowMinimumExceptionOnBetween(a: Double, b: Double, tolerance: Double) {673 val message = "$this should be bigger than $a"674 shouldThrowExceptionOnBetween(a, b, tolerance, message)675 }676 private fun Double.shouldThrowMaximumExceptionOnBetween(a: Double, b: Double, tolerance: Double) {677 val message = "$this should be smaller than $b"678 shouldThrowExceptionOnBetween(a, b, tolerance, message)679 }680 private fun Double.shouldThrowExceptionOnBetween(681 a: Double,682 b: Double,683 tolerance: Double,684 message: String = "$this should be smaller than $b and bigger than $a"685 ) {686 shouldThrowAssertionError(message,687 { this.shouldBeBetween(a, b, tolerance) },688 { this shouldBe between(a, b, tolerance) })689 }690 private fun Double.shouldThrowExceptionOnNotBetween(691 a: Double,692 b: Double,693 tolerance: Double,694 message: String = "$this should not be smaller than $b and should not be bigger than $a"695 ) {696 shouldThrowAssertionError(message,697 { this.shouldNotBeBetween(a, b, tolerance) },698 { this shouldNotBe between(a, b, tolerance) })699 }700 private infix fun Double.shouldMatchLessThan(x: Double) {701 this shouldBe lt(x)702 this shouldBeLessThan x703 this should beLessThan(x)704 this shouldThrowExceptionOnNotLessThan x705 }706 private infix fun Double.shouldThrowExceptionOnNotLessThan(x: Double) {707 shouldThrowAssertionError("$this should not be < $x",708 { this shouldNotBe lt(x) },709 { this shouldNotBeLessThan x },710 { this shouldNot beLessThan(x) })711 }...
matchers.kt
Source:matchers.kt
...46import 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"...
TestMapping.kt
Source:TestMapping.kt
1package org.openrndr.math2import kotlin.math.absoluteValue3import io.kotest.matchers.doubles.between4import io.kotest.matchers.doubles.plusOrMinus5import io.kotest.matchers.shouldBe6import io.kotest.matchers.shouldNotBe7import org.openrndr.math.test.it8import org.openrndr.math.test.it as describe9import kotlin.test.Test10class TestMapping {11 @Test12 fun shouldDoMappingOperations() {13 describe("Mapping Double from zero-width before domain to non-zero-width after domain") {14 it("should not produce NaN results") {15 map(0.0, 0.0, 0.0, 1.0, 0.0) shouldBe (0.0 plusOrMinus 10E-6)16 map(0.0, 0.0, 0.0, 1.0, 1.0) shouldBe (1.0 plusOrMinus 10E-6)17 }18 }19 describe("Mapping Double from zero-width before domain to zero-width after domain") {20 it("should not produce NaN results") {21 map(0.0, 0.0, 0.0, 0.0, 0.0) shouldBe (0.0 plusOrMinus 10E-6)22 map(0.0, 0.0, 0.0, 0.0, 1.0) shouldBe (0.0 plusOrMinus 10E-6)23 }24 }25 describe("Mapping Double") {26 val beforeLeft = 0.027 val beforeRight = 1.028 val beforeVal = beforeRight * 2.0 // out of range29 val afterLeft = 0.030 val afterRight = beforeRight * 2.031 it("should not clamp") {32 map(33 beforeLeft, beforeRight, afterLeft, afterRight, beforeVal34 ) shouldNotBe between(afterLeft, afterRight, 0.0)35 }36 it("should clamp") {37 map(38 beforeLeft, beforeRight, afterLeft, afterRight, beforeVal, true39 ) shouldBe between(afterLeft, afterRight, 0.0)40 }41 it("should not clamp") {42 beforeVal.map(43 beforeLeft, beforeRight, afterLeft, afterRight44 ) shouldNotBe between(afterLeft, afterRight, 0.0)45 }46 it("should clamp") {47 beforeVal.map(48 beforeLeft, beforeRight, afterLeft, afterRight, true49 ) shouldBe between(afterLeft, afterRight, 0.0)50 }51 }52 describe("Mapping Vector2") {53 val beforeLeft = Vector2.ZERO54 val beforeRight = Vector2.ONE55 val beforeVal = beforeRight * 2.0 // out of range56 val afterLeft = Vector2.ZERO57 val afterRight = beforeRight * 2.058 it("should not clamp") {59 val mapped = beforeVal.map(beforeLeft, beforeRight,60 afterLeft, afterRight)61 for (i in 0 until 2)62 mapped[i] shouldNotBe between(afterLeft[i], afterRight[i], 0.0)63 }64 it("should clamp") {65 val mapped = beforeVal.map(beforeLeft, beforeRight,66 afterLeft, afterRight, true)67 for (i in 0 until 2)68 mapped[i] shouldBe between(afterLeft[i], afterRight[i], 0.0)69 }70 }71 describe("Mapping Vector3") {72 val beforeLeft = Vector3.ZERO73 val beforeRight = Vector3.ONE74 val beforeVal = beforeRight * 2.0 // out of range75 val afterLeft = Vector3.ZERO76 val afterRight = beforeRight * 2.077 it("should not clamp") {78 val mapped = beforeVal.map(beforeLeft, beforeRight,79 afterLeft, afterRight)80 for (i in 0 until 3)81 mapped[i] shouldNotBe between(afterLeft[i], afterRight[i], 0.0)82 }83 it("should clamp") {84 val mapped = beforeVal.map(beforeLeft, beforeRight,85 afterLeft, afterRight, true)86 for (i in 0 until 3)87 mapped[i] shouldBe between(afterLeft[i], afterRight[i], 0.0)88 }89 }90 describe("Mapping Vector4") {91 val beforeLeft = Vector4.ZERO92 val beforeRight = Vector4.ONE93 val beforeVal = beforeRight * 2.0 // out of range94 val afterLeft = Vector4.ZERO95 val afterRight = beforeRight * 2.096 it("should not clamp") {97 val mapped = beforeVal.map(beforeLeft, beforeRight,98 afterLeft, afterRight)99 for (i in 0 until 4)100 mapped[i] shouldNotBe between(afterLeft[i], afterRight[i], 0.0)101 }102 it("should clamp") {103 val mapped = beforeVal.map(beforeLeft, beforeRight,104 afterLeft, afterRight, true)105 for (i in 0 until 4)106 mapped[i] shouldBe between(afterLeft[i], afterRight[i], 0.0)107 }108 }109 }110 @Test111 fun shouldDoMixingOperations() {112 describe("Mixing double") {113 it("should produce expected result") {114 mix(1.0, 3.0, 0.5) shouldBe (2.0 plusOrMinus 10E-6)115 mix(3.0, 1.0, 0.5) shouldBe (2.0 plusOrMinus 10E-6)116 }117 }118 describe("Mixing angles") {119 it("should interpolate via shortest side") {120 mixAngle(5.0, 355.0, 0.5) shouldBe (0.0 plusOrMinus 10E-6)121 mixAngle(355.0, 5.0, 0.5) shouldBe (0.0 plusOrMinus 10E-6)122 mixAngle(-100.0, 100.0, 0.5).absoluteValue shouldBe (180.0 plusOrMinus 10E-6)123 mixAngle(100.0, -100.0, 0.5).absoluteValue shouldBe (180.0 plusOrMinus 10E-6)124 }125 }126 }127}...
OsmTypesTest.kt
Source:OsmTypesTest.kt
1package com.jejking.kosmparser.osm2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.core.spec.style.FunSpec4import io.kotest.matchers.shouldBe5import io.kotest.property.Arb6import io.kotest.property.arbitrary.arbitrary7import io.kotest.property.arbitrary.numericDoubles8import io.kotest.property.forAll9import java.time.ZonedDateTime10class OsmTypesTest : FunSpec() {11 private val elementMetadata = ElementMetadata(1, "user", 1, ZonedDateTime.now(), true, 1, 1)12 private val tags = mapOf("foo" to "bar")13 init {14 context("point") {15 test("should accept lat values between -90 and 90 and long between -180 and 180") {16 val edgeCases = listOf(17 Point(0.0, 0.0),18 Point(-90.0, -180.0),19 Point(90.0, 180.0)20 )21 val pointArb: Arb<Point> = arbitrary(edgeCases) { rs ->22 val latitude = Arb.numericDoubles(-90.0, 90.0).sample(rs)23 val longitude = Arb.numericDoubles(-180.0, 180.0).sample(rs)24 Point(latitude.value, longitude.value)25 }26 forAll(pointArb) { p: Point -> LAT_RANGE.contains(p.lat) && LON_RANGE.contains(p.lon) }27 }28 test("should accept lat value of -90") {29 Point(-90.0, 0.0)30 }31 test("should accept lat value of 90") {32 Point(90.0, 0.0)33 }34 test("should accept long value of -180") {35 Point(0.0, -180.0)36 }37 test("should accept long value of 180") {38 Point(0.0, 180.0)39 }40 test("should reject lat value smaller than -90") {41 shouldThrow<IllegalStateException> {42 Point(-90.1, 0.0)43 }44 }45 test("should reject lat value greater than 90") {46 shouldThrow<IllegalStateException> {47 Point(90.1, 0.0)48 }49 }50 test("should reject long value smaller than -180") {51 shouldThrow<IllegalStateException> {52 Point(0.0, -180.1)53 }54 }55 test("should reject long value greater than 180") {56 shouldThrow<IllegalStateException> {57 Point(0.0, 180.1)58 }59 }60 }61 context("way") {62 test("should accept list of 2 nodes") {63 val way = Way(elementMetadata, tags, listOf(1, 2))64 way.isFaulty() shouldBe false65 way.isClosed() shouldBe false66 }67 test("should accept list of 2000 nodes") {68 val way = Way(elementMetadata, tags, (1..2000L).toList())69 way.isFaulty() shouldBe false70 }71 test("should reject list of nodes with 2001 elements") {72 shouldThrow<IllegalStateException> {73 Way(elementMetadata, tags, (1..2001L).toList())74 }75 }76 test("should declare a list of 1 node refs to be faulty") {77 val way = Way(elementMetadata, tags, listOf(1))78 way.isFaulty() shouldBe true79 }80 test("should declare a list of 0 node refs to be faulty") {81 val way = Way(elementMetadata, tags, emptyList())82 way.isFaulty() shouldBe true83 }84 test("should identify a closed way") {85 val way = Way(elementMetadata, tags, listOf(1, 2, 1))86 way.isClosed() shouldBe true87 }88 test("should not identify a faulty way as closed") {89 val way = Way(elementMetadata, tags, listOf(1))90 way.isClosed() shouldBe false91 val way2 = Way(elementMetadata, tags, emptyList())92 way2.isClosed() shouldBe false93 }94 }95 }96}...
TestQuaternion.kt
Source:TestQuaternion.kt
1package org.openrndr.math2import io.kotest.matchers.doubles.between3import io.kotest.matchers.shouldBe4import io.kotest.matchers.string.shouldMatch5import kotlinx.serialization.encodeToString6import kotlinx.serialization.json.Json7import org.openrndr.math.test.it8import kotlin.test.Test9class TestQuaternion {10 @Test11 fun shouldDoOperationsOnAQuaternion() {12 it("IDENTITY times IDENTITY should result in IDENTITY") {13 val q0 = Quaternion.IDENTITY14 val q1 = Quaternion.IDENTITY15 val qm = q0 * q116 qm.x shouldBe 0.017 qm.y shouldBe 0.018 qm.z shouldBe 0.019 qm.w shouldBe 1.020 }21 it ("matrix to quaternion to matrix") {22 val q0 = Quaternion.fromMatrix(Matrix33.IDENTITY)23 val m0 = q0.matrix24 m0 shouldBe Matrix33.IDENTITY25 }26 it ("quaternion look +Z") {27 val q0 = Quaternion.fromLookAt(Vector3.ZERO, Vector3(0.0, 0.0, 1.0), Vector3.UNIT_Y)28 val v0 = q0 * Vector3.UNIT_Z29 v0.x shouldBe between(-0.0001, 0.0001, 0.0)30 v0.y shouldBe between(-0.0001, 0.0001, 0.0)31 v0.z shouldBe between(1-0.0001, 1+0.0001, 0.0)32 }33 it ("quaternion look -Z") {34 val q0 = Quaternion.fromLookAt(Vector3.ZERO, Vector3(0.0, 0.0, -1.0), Vector3.UNIT_Y)35 val v0 = q0 * Vector3.UNIT_Z36 v0.x shouldBe between(-0.0001, 0.0001, 0.0)37 v0.y shouldBe between(-0.0001, 0.0001, 0.0)38 v0.z shouldBe between(-1-0.0001, -1+0.0001, 0.0)39 }40 it ("quaternion look +X") {41 val q0 = Quaternion.fromLookAt(Vector3.ZERO, Vector3(1.0, 0.0, 0.0), Vector3.UNIT_Y)42 val v0 = q0 * Vector3.UNIT_Z43 v0.x shouldBe between(1-0.0001, 1+0.0001, 0.0)44 v0.y shouldBe between(-0.0001, 0.0001, 0.0)45 v0.z shouldBe between(-0.0001, 0.0001, 0.0)46 }47 it ("quaternion look -X") {48 val q0 = Quaternion.fromLookAt(Vector3.ZERO, Vector3(-1.0, 0.0, 0.0), Vector3.UNIT_Y)49 val v0 = q0 * Vector3.UNIT_Z50 v0.x shouldBe between(-1-0.0001, -1+0.0001, 0.0)51 v0.y shouldBe between(-0.0001, 0.0001, 0.0)52 v0.z shouldBe between(-0.0001, 0.0001, 0.0)53 }54 it("quaternion.identity * vector3") {55 Quaternion.IDENTITY * Vector3.UNIT_X shouldBe Vector3.UNIT_X56 Quaternion.IDENTITY * Vector3.UNIT_Y shouldBe Vector3.UNIT_Y57 Quaternion.IDENTITY * Vector3.UNIT_Z shouldBe Vector3.UNIT_Z58 }59 }60 @Test61 fun shouldSerialize() {62 it("should serialize ZERO to JSON") {63 Json.encodeToString(Quaternion.ZERO) shouldMatch """\{"x":0(\.0)?,"y":0(\.0)?,"z":0(\.0)?,"w":0(\.0)?\}"""64 }65 it("should serialize IDENTITY to JSON") {66 Json.encodeToString(Quaternion.IDENTITY) shouldMatch """\{"x":0(\.0)?,"y":0(\.0)?,"z":0(\.0)?,"w":1(\.0)?\}"""67 }68 }69}...
TestInSightConnection.kt
Source:TestInSightConnection.kt
...29 val node1 = environment.getNodeByID(1)30 val rule = environment.linkingRule31 rule shouldBe instanceOf<ConnectIfInLineOfSigthOnMap<*>>()32 val maxRange = (rule as ConnectIfInLineOfSigthOnMap<*>).maxRange33 environment.getDistanceBetweenNodes(node0, node1) shouldBeLessThan maxRange34 val route = environment.computeRoute(node0, node1)35 route.length() shouldBeGreaterThan maxRange36 environment.getNeighborhood(node0).contains(node1).shouldBeFalse()37 }38 }39)...
CircleTest.kt
Source:CircleTest.kt
1package net.trivernis.chunkmaster.lib.shapes2import io.kotest.matchers.booleans.shouldBeTrue3import io.kotest.matchers.collections.shouldContainAll4import io.kotest.matchers.doubles.shouldBeBetween5import io.kotest.matchers.shouldBe6import org.junit.Test7import org.junit.jupiter.api.BeforeEach8class CircleTest {9 private val circle = Circle(center = Pair(0, 0), radius = 2, start = Pair(0, 0))10 @BeforeEach11 fun init() {12 circle.reset()13 }14 @Test15 fun `it generates coordinates`() {16 circle.next().shouldBe(Pair(0, 0))17 circle.next().shouldBe(Pair(-1, -1))18 circle.next().shouldBe(Pair(1, 0))19 circle.next().shouldBe(Pair(-1, 0))20 circle.next().shouldBe(Pair(1, -1))21 circle.next().shouldBe(Pair(-1, 1))22 circle.next().shouldBe(Pair(0, 1))23 circle.next().shouldBe(Pair(0, -1))24 circle.next().shouldBe(Pair(1, 1))25 }26 @Test27 fun `it reports when reaching the end`() {28 for (i in 1..25) {29 circle.next()30 }31 circle.endReached().shouldBeTrue()32 }33 @Test34 fun `it reports the radius`() {35 for (i in 1..9) {36 circle.next()37 }38 circle.currentRadius().shouldBe(1)39 }40 @Test41 fun `it returns the right edges`() {42 circle.getShapeEdgeLocations().shouldContainAll(43 listOf(44 Pair(2, -1),45 Pair(2, 0),46 Pair(2, 1),47 Pair(1, 2),48 Pair(0, 2),49 Pair(-1, 2),50 Pair(-2, 1),51 Pair(-2, 0),52 Pair(-2, -1),53 Pair(-1, -2),54 Pair(0, -2),55 Pair(1, -2),56 )57 )58 }59 @Test60 fun `it returns the progress`() {61 circle.progress(2).shouldBe(0)62 for (i in 1..7) {63 circle.next()64 }65 circle.progress(2).shouldBeBetween(.5, .8, .0)66 }67}...
AbstractGeneratorTest.kt
Source:AbstractGeneratorTest.kt
1package net.dinkla.raytracer.samplers2import io.kotest.core.spec.style.AnnotationSpec3import io.kotest.matchers.doubles.shouldBeGreaterThanOrEqual4import io.kotest.matchers.doubles.shouldBeLessThan5import io.kotest.matchers.shouldBe6import net.dinkla.raytracer.math.Histogram7import net.dinkla.raytracer.math.Point2D8abstract class AbstractGeneratorTest : AnnotationSpec() {9 private var samples: MutableList<Point2D> = mutableListOf()10 private val factorX = 10.011 private val factorY = 10.012 open val sizeOfX : Int = factorX.toInt()13 open val sizeOfY : Int = factorY.toInt()14 open val sizeOfXY : Int = factorX.toInt() * factorY.toInt()15 open val numberOfSamples: Int = NUM_SAMPLES * NUM_SETS16 abstract fun sample(): MutableList<Point2D>17 @BeforeEach18 fun initialize() {19 samples = sample()20 }21 @Test22 fun size() {23 samples.size shouldBe numberOfSamples24 }25 @Test26 fun betweenZeroAndOne() {27 for (p in samples) {28 p.x shouldBeGreaterThanOrEqual 0.029 p.x shouldBeLessThan 1.030 p.y shouldBeGreaterThanOrEqual 0.031 p.y shouldBeLessThan 1.032 }33 }34 @Test35 fun distribution() {36 val histX = Histogram()37 val histY = Histogram()38 val histXY = Histogram()39 for (p in samples) {40 val x = (p.x * factorX).toInt()41 val y = (p.y * factorY).toInt()42 histX.add(x)43 histY.add(y)44 histXY.add(x * 10 + y)45 }46 histX.keys().size shouldBe sizeOfX47 histY.keys().size shouldBe sizeOfY48 histXY.keys().size shouldBe sizeOfXY49 }50 companion object {51 internal const val NUM_SAMPLES = 100052 internal const val NUM_SETS = 1053 }54}...
Between
Using AI Code Generation
1public fun between(from: Double, to: Double): Between2public fun between(from: Int, to: Int): Between3public fun between(from: Long, to: Long): Between4public fun between(from: Float, to: Float): Between5public fun between(from: LocalDate, to: LocalDate): Between6public fun between(from: LocalDateTime, to: LocalDateTime): Between7public fun between(from: LocalTime, to: LocalTime): Between8public fun between(from: OffsetDateTime, to: OffsetDateTime): Between9public fun between(from: OffsetTime, to: OffsetTime): Between10public fun between(from: ZonedDateTime, to: ZonedDateTime): Between11public fun between(from: Year, to: Year): Between12public fun between(from: YearMonth, to: YearMonth
Between
Using AI Code Generation
1val between = Between(1.0, 10.0)2val between = Between(1.0f, 10.0f)3val between = Between(1, 10)4val between = Between(1L, 10L)5val between = Between(1.toShort(), 10.toShort())6between.shouldBeBetween(100.toShort(), 1000.toShort())
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!