How to use Zero class of io.kotest.matchers.doubles package

Best Kotest code snippet using io.kotest.matchers.doubles.Zero

DoubleMatchersTest.kt

Source:DoubleMatchersTest.kt Github

copy

Full Screen

...26import 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) {...

Full Screen

Full Screen

matchers.kt

Source:matchers.kt Github

copy

Full Screen

...52import 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()...

Full Screen

Full Screen

FrequencyIntervalTest.kt

Source:FrequencyIntervalTest.kt Github

copy

Full Screen

1package net.paploo.kmusical.core2import io.kotest.assertions.throwables.shouldThrowAny3import io.kotest.core.spec.style.DescribeSpec4import io.kotest.matchers.doubles.ToleranceMatcher5import io.kotest.matchers.doubles.plusOrMinus6import io.kotest.matchers.should7import io.kotest.matchers.shouldBe8import io.kotest.matchers.types.beInstanceOf9import io.kotest.property.Arb10import io.kotest.property.arbitrary.arbitrary11import io.kotest.property.arbitrary.pair12import io.kotest.property.arbitrary.triple13import io.kotest.property.checkAll14import net.paploo.kmusical.testutil.plusOrMinus15import kotlin.math.absoluteValue16class FrequencyRatioTest : DescribeSpec({17 val frequencyRatioGen = arbitrary { rs ->18 FrequencyRatio(rs.random.nextDouble().absoluteValue)19 }20 describe("instantiation") {21 it("should not allow negative values") {22 shouldThrowAny { Frequency(-0.5) }23 shouldThrowAny { Frequency(-2.0) }24 }25 it("should not instantiate with a zero frequency") {26 shouldThrowAny { Frequency(0.0) }27 }28 }29 describe("plus") {30 it("The result should be typed as a frequency ratio") {31 val a = FrequencyRatio(1.5)32 val r: FrequencyRatio = a + a // Won't compile if typed wrong.33 r should beInstanceOf(FrequencyRatio::class)34 }35 it("should be the product of the value in hertz") {36 Arb.pair(frequencyRatioGen, frequencyRatioGen).checkAll { (a, b) ->37 val r = a + b38 r.value shouldBe (a.value * b.value).plusOrMinus()39 }40 }41 describe("it should be monoidal") {42 it("should be associative") {43 Arb.triple(frequencyRatioGen, frequencyRatioGen, frequencyRatioGen).checkAll { (a, b, c) ->44 val left = (a + b) + c45 val right = a + (b + c)46 left.value shouldBe (right.value.plusOrMinus())47 }48 }49 it("should have left identity") {50 frequencyRatioGen.checkAll {51 it + FrequencyRatio.unison shouldBe it52 }53 }54 it("should have right identity") {55 frequencyRatioGen.checkAll {56 FrequencyRatio.unison + it shouldBe it57 }58 }59 }60 }61 describe("minus") {62 it("The result should be typed as a frequency ratio") {63 val a = FrequencyRatio(1.5)64 val r: FrequencyRatio = a - a // Won't compile if typed wrong.65 r should beInstanceOf(FrequencyRatio::class)66 }67 it("should be the div of the value in hertz") {68 Arb.pair(frequencyRatioGen, frequencyRatioGen).checkAll { (a,b) ->69 val r = a - b70 r.value shouldBe (a.value / b.value).plusOrMinus()71 }72 }73 }74 describe("unaryMinus") {75 it("should be the additive inverse") {76 frequencyRatioGen.checkAll {77 (it + (-it)).value shouldBe ((FrequencyRatio.unison).value.plusOrMinus())78 }79 }80 }81 describe("toCents") {82 it("should convert unison constant") {83 FrequencyRatio.unison.toCents() shouldBe Cent.unison84 }85 it("should convert octave constant") {86 FrequencyRatio.octave.toCents() shouldBe Cent.octave87 }88 it("should convert a just fifth to the nearest whole cent value") {89 FrequencyRatio(3.0 / 2.0).toCents() shouldBe Cent(702)90 }91 it("should convert a value down by one fourth to the nearest whole cent value") {92 FrequencyRatio(3.0/4.0).toCents() shouldBe Cent(-498)93 }94 }95 describe("toFrequencyRatio") {96 it("should return the same value") {97 frequencyRatioGen.checkAll {98 it.toFrequencyRatio() shouldBe it99 }100 }101 }102})103class CentTest : DescribeSpec({104 val centGen = arbitrary { rs ->105 Cent(rs.random.nextInt(-12000,12000).absoluteValue)106 }107 describe("plus") {108 it("The result should be typed as a cent") {109 val a = Cent(702)110 val r: Cent = a + a // Won't compile if typed wrong.111 r should beInstanceOf(Cent::class)112 }113 it("should be the sum of the raw value") {114 Arb.pair(centGen, centGen).checkAll { (a,b) ->115 val r = a + b116 r.value shouldBe a.value + b.value117 }118 }119 describe("it should be monoidal") {120 it("should be associative") {121 Arb.triple(centGen, centGen, centGen).checkAll { (a, b, c) ->122 val left = (a + b) + c123 val right = a + (b + c)124 left shouldBe right125 }126 }127 it("should have left identity") {128 centGen.checkAll {129 it + Cent.unison shouldBe it130 }131 }132 it("should have right identity") {133 centGen.checkAll {134 Cent.unison + it shouldBe it135 }136 }137 }138 }139 describe("minus") {140 it("The result should be typed as a cent") {141 val a = Cent(702)142 val r: Cent = a - a // Won't compile if typed wrong.143 r should beInstanceOf(Cent::class)144 }145 it("should be the difference of the raw value") {146 Arb.pair(centGen, centGen).checkAll { (a,b) ->147 val r = a - b148 r.value shouldBe (a.value - b.value)149 }150 }151 }152 describe("unaryMinus") {153 it("should be the additive inverse") {154 centGen.checkAll {155 (it + (-it)) shouldBe Cent.unison156 }157 }158 }159 describe("toCents") {160 it("should return the same value") {161 centGen.checkAll {162 it.toCents() shouldBe it163 }164 }165 }166 describe("toFrequencyRatio") {167 it("should convert unison constant") {168 Cent.unison.toFrequencyRatio() shouldBe FrequencyRatio.unison169 }170 it("should convert octave constant") {171 Cent.octave.toFrequencyRatio() shouldBe FrequencyRatio.octave172 }173 //This is not very tight, since we only keep precision to one cent for cents.174 val tolerance = 1e-4175 it("should convert a just fifth (within rounding error)") {176 val converted = Cent(702).toFrequencyRatio()177 val expected = FrequencyRatio(1.5)178 converted.value shouldBe expected.value.plusOrMinus(tolerance)179 }180 it("should convert a value down by one fourth (within rounding error)") {181 val converted = Cent(-498).toFrequencyRatio()182 val expected = FrequencyRatio(3.0/4.0)183 converted.value shouldBe expected.value.plusOrMinus(tolerance)184 }185 }186})...

Full Screen

Full Screen

TestMapping.kt

Source:TestMapping.kt Github

copy

Full Screen

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

Full Screen

Full Screen

TestQuaternion.kt

Source:TestQuaternion.kt Github

copy

Full Screen

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

Full Screen

Full Screen

AbstractGeneratorTest.kt

Source:AbstractGeneratorTest.kt Github

copy

Full Screen

...22 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()...

Full Screen

Full Screen

BmiForCmKgTest.kt

Source:BmiForCmKgTest.kt Github

copy

Full Screen

...6 test("Bmi should be calculated correctly") {7 BmiForCmKg(68.0, 182.0).count() shouldBe(20.52 plusOrMinus 0.01)8 BmiForCmKg(52.0, 163.0).count() shouldBe(19.57 plusOrMinus 0.01)9 }10 test("Zero height should return BMI equal to zero") {11 BmiForCmKg(68.0, 0.0).count() shouldBe 012 }13})...

Full Screen

Full Screen

BmiForInLbTest.kt

Source:BmiForInLbTest.kt Github

copy

Full Screen

...6 test("Bmi should be calculated correctly") {7 BmiForInLb(68.0, 182.0).count() shouldBe(1.44 plusOrMinus 0.01)8 BmiForInLb(52.0, 163.0).count() shouldBe(1.37 plusOrMinus 0.01)9 }10 test("Zero height should return BMI equal to zero") {11 BmiForInLb(68.0, 0.0).count() shouldBe 012 }13})...

Full Screen

Full Screen

Zero

Using AI Code Generation

copy

Full Screen

1import io.kotest.matchers.doubles.*2import io.kotest.matchers.longs.*3import io.kotest.matchers.ints.*4import io.kotest.matchers.shorts.*5import io.kotest.matchers.bytes.*6import io.kotest.matchers.chars.*7import io.kotest.matchers.booleans.*8import io.kotest.matchers.floats.*9import io.kotest.matchers.ints.*10import io.kotest.matchers.shorts.*11import io.kotest.matchers.bytes.*12import io.kotest.matchers.chars.*13import io.kotest.matchers.booleans.*14import io.kotest.matchers.floats.*15import io.kotest.matchers.ints.*16import io.kotest.matchers.shorts.*17import io.kotest.matchers.bytes.*18import io.kotest.matchers.chars.*19import io.kotest.matchers.booleans.*

Full Screen

Full Screen

Zero

Using AI Code Generation

copy

Full Screen

1 import io.kotest.matchers.doubles.plusOrMinus2 import io.kotest.matchers.shouldBe3 import io.kotest.matchers.longs.plusOrMinus4 import io.kotest.matchers.shouldBe5 import io.kotest.matchers.shorts.plusOrMinus6 import io.kotest.matchers.shouldBe7 import io.kotest.matchers.bytes.plusOrMinus8 import io.kotest.matchers.shouldBe9 import io.kotest.matchers.floats.plusOrMinus10 import io.kotest.matchers.shouldBe11 import io.kotest.matchers.ints.plusOrMinus12 import io.kotest.matchers.shouldBe13 import io.kotest.matchers.longs.plusOrMinus14 import io.kotest.matchers.shouldBe15 import io.kotest.matchers.shorts.plusOrMinus16 import io.kotest.matchers.shouldBe17 import io.kotest.matchers.bytes.plusOrMinus18 import io.kotest.matchers.shouldBe19 import io.kotest.matchers.floats.plusOrMinus20 import io.kotest.matchers.shouldBe21 import io.kotest.matchers.ints.plusOrMinus22 import io.kotest.matchers.shouldBe23 import io.kotest.matchers.longs.plusOrMinus24 import io.kotest.matchers.shouldBe

Full Screen

Full Screen

Zero

Using AI Code Generation

copy

Full Screen

1 import io.kotest.matchers.doubles.plusOrMinus2 import io.kotest.matchers.shouldBe3 import org.junit.jupiter.api.Assertions.assertEquals4 class MyTest {5 fun `should compare doubles`() {6 assertEquals(0.1, 0.1, 0.000001)7 }8 }9 java.lang.NoSuchMethodError: 'void org.junit.jupiter.api.Assertions.assertEquals(double, double, double)'10 dependencies {11 }

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful