How to use Float.shouldBeNaN method of io.kotest.matchers.floats.NaN class

Best Kotest code snippet using io.kotest.matchers.floats.NaN.Float.shouldBeNaN

FloatingBigRationalTest.kt

Source:FloatingBigRationalTest.kt Github

copy

Full Screen

1@file:Suppress("NonAsciiCharacters", "RedundantInnerClassModifier")2package hm.binkley.math.floating3import hm.binkley.math.BFixed4import hm.binkley.math.BFloating5import hm.binkley.math.`^`6import hm.binkley.math.big7import hm.binkley.math.ceil8import hm.binkley.math.compareTo9import hm.binkley.math.dec10import hm.binkley.math.divideAndRemainder11import hm.binkley.math.fixed.FixedBigRational12import hm.binkley.math.floating.FloatingBigRational.Companion.NEGATIVE_INFINITY13import hm.binkley.math.floating.FloatingBigRational.Companion.NaN14import hm.binkley.math.floating.FloatingBigRational.Companion.ONE15import hm.binkley.math.floating.FloatingBigRational.Companion.POSITIVE_INFINITY16import hm.binkley.math.floating.FloatingBigRational.Companion.TEN17import hm.binkley.math.floating.FloatingBigRational.Companion.TWO18import hm.binkley.math.floating.FloatingBigRational.Companion.ZERO19import hm.binkley.math.floor20import hm.binkley.math.inc21import hm.binkley.math.isDyadic22import hm.binkley.math.rangeTo23import hm.binkley.math.sqrt24import hm.binkley.math.sqrtApproximated25import hm.binkley.math.toBigInteger26import hm.binkley.math.truncate27import io.kotest.assertions.throwables.shouldThrow28import io.kotest.matchers.booleans.shouldBeFalse29import io.kotest.matchers.booleans.shouldBeTrue30import io.kotest.matchers.shouldBe31import io.kotest.matchers.shouldNotBe32import io.kotest.matchers.types.shouldBeSameInstanceAs33import org.junit.jupiter.api.Nested34import org.junit.jupiter.api.Test35private typealias BigRationalAssertion = (FloatingBigRational) -> Unit36/**37 * NB -- the tests use a mixture of constructors while testing functionality.38 * This is intentional, and raises coverage.39 */40internal class FloatingBigRationalTest {41 @Nested42 inner class ConstructionTests {43 @Test44 fun `should use constant NaN`() {45 (0 over 0) shouldBeSameInstanceAs NaN46 }47 @Test48 fun `should use constant +∞`() {49 (Long.MAX_VALUE over 0L) shouldBeSameInstanceAs POSITIVE_INFINITY50 }51 @Test52 fun `should use constant -∞`() {53 (Long.MIN_VALUE over 0.big) shouldBeSameInstanceAs NEGATIVE_INFINITY54 }55 @Test56 fun `should provide over as a convenience`() {57 (10L over 1) shouldBe TEN58 (10 over 1L) shouldBe TEN59 }60 }61 @Test62 fun `should not be a floating big rational`() {63 FixedBigRational.valueOf(1.big, 1.big).hashCode() shouldNotBe64 (1 over 1).hashCode()65 (FixedBigRational.ONE..FixedBigRational.TWO) shouldNotBe ONE..TWO66 (FixedBigRational.ONE..FixedBigRational.TWO).hashCode() shouldNotBe67 (ONE..TWO).hashCode()68 }69 @Test70 fun `should pretty print`() {71 POSITIVE_INFINITY.toString() shouldBe "Infinity"72 NEGATIVE_INFINITY.toString() shouldBe "-Infinity"73 NaN.toString() shouldBe "NaN"74 }75 @Test76 fun `should divide with remainder`() {77 fun nonFiniteCheck(78 dividend: FloatingBigRational,79 divisor: FloatingBigRational,80 assertion: BigRationalAssertion,81 ) {82 val (quotient, remainder) = dividend.divideAndRemainder(divisor)83 assertion(quotient)84 assertion(remainder)85 }86 nonFiniteCheck((13 over 2), POSITIVE_INFINITY) {87 it.isPositiveInfinity()88 }89 nonFiniteCheck(POSITIVE_INFINITY, (3 over 1)) {90 it.isPositiveInfinity()91 }92 nonFiniteCheck(POSITIVE_INFINITY, POSITIVE_INFINITY) {93 it.isPositiveInfinity()94 }95 nonFiniteCheck((13 over 2), NEGATIVE_INFINITY) {96 it.isNegativeInfinity()97 }98 nonFiniteCheck(NEGATIVE_INFINITY, (3 over 1)) {99 it.isNegativeInfinity()100 }101 nonFiniteCheck(NEGATIVE_INFINITY, NEGATIVE_INFINITY) {102 it.isPositiveInfinity()103 }104 nonFiniteCheck((13 over 2), NaN) {105 it.isNaN()106 }107 nonFiniteCheck(NaN, (3 over 1)) {108 it.isNaN()109 }110 nonFiniteCheck(NaN, NaN) {111 it.isNaN()112 }113 }114 @Nested115 inner class OperatorTests {116 @Test117 fun `should add`() {118 (ONE + POSITIVE_INFINITY).shouldBePositiveInfinity()119 (POSITIVE_INFINITY + POSITIVE_INFINITY).shouldBePositiveInfinity()120 (POSITIVE_INFINITY + NEGATIVE_INFINITY).shouldBeNaN()121 (ONE + NEGATIVE_INFINITY).shouldBeNegativeInfinity()122 (NEGATIVE_INFINITY + NEGATIVE_INFINITY).shouldBeNegativeInfinity()123 (NEGATIVE_INFINITY + POSITIVE_INFINITY).shouldBeNaN()124 }125 @Test126 fun `should subtract`() {127 (POSITIVE_INFINITY - ONE).shouldBePositiveInfinity()128 (POSITIVE_INFINITY - POSITIVE_INFINITY).shouldBeNaN()129 (POSITIVE_INFINITY - NEGATIVE_INFINITY).shouldBePositiveInfinity()130 (NEGATIVE_INFINITY - ONE).shouldBeNegativeInfinity()131 (NEGATIVE_INFINITY - NEGATIVE_INFINITY).shouldBeNaN()132 (NEGATIVE_INFINITY - POSITIVE_INFINITY).shouldBeNegativeInfinity()133 }134 @Test135 fun `should multiply`() {136 (ONE * POSITIVE_INFINITY).shouldBePositiveInfinity()137 (ONE * NEGATIVE_INFINITY).shouldBeNegativeInfinity()138 (ZERO * POSITIVE_INFINITY).shouldBeNaN()139 (POSITIVE_INFINITY * ZERO).shouldBeNaN()140 (ZERO * NEGATIVE_INFINITY).shouldBeNaN()141 (NEGATIVE_INFINITY * ZERO).shouldBeNaN()142 (POSITIVE_INFINITY * POSITIVE_INFINITY).shouldBePositiveInfinity()143 }144 @Test145 fun `should divide`() {146 (ZERO / POSITIVE_INFINITY) shouldBe ZERO147 (ONE / ZERO).shouldBePositiveInfinity()148 (ZERO / NEGATIVE_INFINITY) shouldBe ZERO149 (-ONE / ZERO).shouldBeNegativeInfinity()150 (NEGATIVE_INFINITY / NEGATIVE_INFINITY).shouldBeNaN()151 (POSITIVE_INFINITY / POSITIVE_INFINITY).shouldBeNaN()152 (ONE / NaN).shouldBeNaN()153 (NaN / ONE).shouldBeNaN()154 (ZERO / ZERO).shouldBeNaN()155 }156 @Test157 fun `should find remainder`() {158 (ONE % POSITIVE_INFINITY) shouldBe ZERO159 (POSITIVE_INFINITY % ONE) shouldBe ZERO160 (ONE % NEGATIVE_INFINITY) shouldBe ZERO161 (NEGATIVE_INFINITY % ONE) shouldBe ZERO162 (ONE % NaN).shouldBeNaN()163 (NaN % ONE).shouldBeNaN()164 (ZERO % ZERO).shouldBeNaN()165 }166 @Test167 fun `should increment`() {168 var nonFinite = POSITIVE_INFINITY169 (++nonFinite).shouldBePositiveInfinity()170 nonFinite = NEGATIVE_INFINITY171 (++nonFinite).shouldBeNegativeInfinity()172 nonFinite = NaN173 (++nonFinite).shouldBeNaN()174 }175 @Test176 fun `should decrement`() {177 var nonFinite = POSITIVE_INFINITY178 (--nonFinite).shouldBePositiveInfinity()179 nonFinite = NEGATIVE_INFINITY180 (--nonFinite).shouldBeNegativeInfinity()181 nonFinite = NaN182 (--nonFinite).shouldBeNaN()183 }184 }185 @Nested186 inner class RoundingTests {187 @Test188 fun `should round towards ceiling`() {189 POSITIVE_INFINITY.ceil().shouldBePositiveInfinity()190 NEGATIVE_INFINITY.ceil().shouldBeNegativeInfinity()191 NaN.ceil().shouldBeNaN()192 }193 @Test194 fun `should round towards floor`() {195 POSITIVE_INFINITY.floor().shouldBePositiveInfinity()196 NEGATIVE_INFINITY.floor().shouldBeNegativeInfinity()197 NaN.floor().shouldBeNaN()198 }199 @Test200 fun `should round towards 0`() {201 POSITIVE_INFINITY.truncate().shouldBePositiveInfinity()202 NEGATIVE_INFINITY.truncate().shouldBeNegativeInfinity()203 NaN.truncate().shouldBeNaN()204 }205 }206 @Nested207 inner class SpecialCasesTests {208 @Test209 fun `should round trip NaN and infinities`() {210 POSITIVE_INFINITY.toDouble().toBigRational() shouldBe211 POSITIVE_INFINITY212 NEGATIVE_INFINITY.toDouble().toBigRational() shouldBe213 NEGATIVE_INFINITY214 NaN.toDouble().toBigRational() shouldBe NaN215 POSITIVE_INFINITY.toFloat().toBigRational() shouldBe216 POSITIVE_INFINITY217 NEGATIVE_INFINITY.toFloat().toBigRational() shouldBe218 NEGATIVE_INFINITY219 NaN.toFloat().toBigRational() shouldBe NaN220 }221 @Test222 fun `should be infinity`() {223 (2 over 0).shouldBePositiveInfinity()224 (-2 over 0).shouldBeNegativeInfinity()225 }226 @Test227 fun `should check finitude`() {228 ZERO.isFinite().shouldBeTrue()229 POSITIVE_INFINITY.isFinite().shouldBeFalse()230 NEGATIVE_INFINITY.isFinite().shouldBeFalse()231 NaN.isFinite().shouldBeFalse()232 }233 @Test234 fun `should check infinitude`() {235 ZERO.isInfinite().shouldBeFalse()236 POSITIVE_INFINITY.isInfinite().shouldBeTrue()237 NEGATIVE_INFINITY.isInfinite().shouldBeTrue()238 NaN.isInfinite().shouldBeFalse()239 }240 @Test241 fun `should propagate NaN`() {242 (ZERO + NaN).shouldBeNaN()243 (NaN + NaN).shouldBeNaN()244 (NaN + ONE).shouldBeNaN()245 (NaN - ZERO).shouldBeNaN()246 (NaN - NaN).shouldBeNaN()247 (ZERO - NaN).shouldBeNaN()248 (ONE * NaN).shouldBeNaN()249 (NaN * NaN).shouldBeNaN()250 (NaN * ONE).shouldBeNaN()251 (NaN / ONE).shouldBeNaN()252 (NaN / NaN).shouldBeNaN()253 (ONE / NaN).shouldBeNaN()254 (NaN % ONE).shouldBeNaN()255 (NaN % NaN).shouldBeNaN()256 (ONE % NaN).shouldBeNaN()257 }258 @Test259 fun `should propagate infinities`() {260 (-NEGATIVE_INFINITY).shouldBePositiveInfinity()261 (ONE + POSITIVE_INFINITY).shouldBePositiveInfinity()262 (NEGATIVE_INFINITY - ONE).shouldBeNegativeInfinity()263 (POSITIVE_INFINITY + NEGATIVE_INFINITY).shouldBeNaN()264 (POSITIVE_INFINITY * POSITIVE_INFINITY).shouldBePositiveInfinity()265 (POSITIVE_INFINITY * NEGATIVE_INFINITY).shouldBeNegativeInfinity()266 (NEGATIVE_INFINITY * NEGATIVE_INFINITY).shouldBePositiveInfinity()267 (POSITIVE_INFINITY / POSITIVE_INFINITY).shouldBeNaN()268 (POSITIVE_INFINITY / NEGATIVE_INFINITY).shouldBeNaN()269 (NEGATIVE_INFINITY / NEGATIVE_INFINITY).shouldBeNaN()270 }271 @Test272 fun `should invert infinities incorrectly`() {273 (ONE / POSITIVE_INFINITY) shouldBe ZERO274 (ONE / NEGATIVE_INFINITY) shouldBe ZERO275 }276 @Test277 fun `should cope with various infinities`() {278 (ZERO * POSITIVE_INFINITY).shouldBeNaN()279 (ZERO / POSITIVE_INFINITY) shouldBe ZERO280 (POSITIVE_INFINITY / ZERO).shouldBePositiveInfinity()281 (ZERO * NEGATIVE_INFINITY).shouldBeNaN()282 (ZERO / NEGATIVE_INFINITY) shouldBe ZERO283 (NEGATIVE_INFINITY / ZERO).shouldBeNegativeInfinity()284 (POSITIVE_INFINITY * NEGATIVE_INFINITY).shouldBeNegativeInfinity()285 (POSITIVE_INFINITY / NEGATIVE_INFINITY).shouldBeNaN()286 }287 @Test288 fun `should understand equalities of non-finite values`() {289 POSITIVE_INFINITY shouldBe POSITIVE_INFINITY290 NEGATIVE_INFINITY shouldBe NEGATIVE_INFINITY291 // Cannot use shouldNotBe: It short-circuits for === objects292 @Suppress("KotlinConstantConditions")293 (NaN == NaN).shouldBeFalse()294 }295 }296 @Test297 fun `should note integer rationals`() {298 POSITIVE_INFINITY.isWhole().shouldBeFalse()299 NEGATIVE_INFINITY.isWhole().shouldBeFalse()300 NaN.isWhole().shouldBeFalse()301 }302 @Test303 fun `should note p-adic rationals`() {304 (1 over 3).isPAdic(3).shouldBeTrue()305 (2 over 5).isPAdic(3).shouldBeFalse()306 POSITIVE_INFINITY.isPAdic(3).shouldBeFalse()307 NEGATIVE_INFINITY.isPAdic(3).shouldBeFalse()308 NaN.isPAdic(3).shouldBeFalse()309 }310 @Test311 fun `should note dyadic rationals`() {312 (1 over 2).isDyadic().shouldBeTrue()313 POSITIVE_INFINITY.isDyadic().shouldBeFalse()314 NEGATIVE_INFINITY.isDyadic().shouldBeFalse()315 NaN.isDyadic().shouldBeFalse()316 }317 @Nested318 inner class ProgressionTests {319 @Test320 fun `should equate`() {321 (ONE..TEN).equals(this).shouldBeFalse()322 (ONE..TEN) shouldNotBe323 FixedBigRational.ONE..FixedBigRational.TEN324 (ONE..TEN).hashCode() shouldNotBe325 (FixedBigRational.ONE..FixedBigRational.TEN).hashCode()326 }327 }328 @Nested329 inner class ConversionTests {330 @Test331 fun `should be a number`() {332 ONE.toDouble() shouldBe 1.0333 POSITIVE_INFINITY.toDouble() shouldBe Double.POSITIVE_INFINITY334 NEGATIVE_INFINITY.toDouble() shouldBe Double.NEGATIVE_INFINITY335 NaN.toDouble() shouldBe Double.NaN336 ONE.toFloat() shouldBe 1.0f337 POSITIVE_INFINITY.toFloat() shouldBe Float.POSITIVE_INFINITY338 NEGATIVE_INFINITY.toFloat() shouldBe Float.NEGATIVE_INFINITY339 NaN.toFloat() shouldBe Float.NaN340 }341 @Test342 fun `should not convert extrema to big decimal`() {343 // Note JDK rules for BigDecimal->Double->BigDecimal, and handling344 // of string _vs_ double/long inputs345 ONE.toBigDecimal() shouldBe BFloating("1.0")346 ONE.toBigDecimal(1) shouldBe BFloating("1.0")347 shouldThrow<ArithmeticException> {348 POSITIVE_INFINITY.toBigDecimal()349 }350 shouldThrow<ArithmeticException> {351 POSITIVE_INFINITY.toBigDecimal(1)352 }353 shouldThrow<ArithmeticException> {354 NEGATIVE_INFINITY.toBigDecimal()355 }356 shouldThrow<ArithmeticException> {357 NEGATIVE_INFINITY.toBigDecimal(1)358 }359 shouldThrow<ArithmeticException> {360 NaN.toBigDecimal()361 }362 shouldThrow<ArithmeticException> {363 NaN.toBigDecimal(1)364 }365 }366 @Test367 fun `should not convert extrema to big integer`() {368 ONE.toBigInteger() shouldBe BFixed.ONE369 shouldThrow<ArithmeticException> {370 POSITIVE_INFINITY.toBigInteger()371 }372 shouldThrow<ArithmeticException> {373 NEGATIVE_INFINITY.toBigInteger()374 }375 shouldThrow<ArithmeticException> {376 NaN.toBigInteger()377 }378 }379 @Test380 fun `should not convert extrema to long`() {381 shouldThrow<ArithmeticException> {382 POSITIVE_INFINITY.toLong()383 }384 shouldThrow<ArithmeticException> {385 NEGATIVE_INFINITY.toLong()386 }387 shouldThrow<ArithmeticException> {388 NaN.toLong()389 }390 }391 @Test392 fun `should not convert extrema to int`() {393 shouldThrow<ArithmeticException> {394 POSITIVE_INFINITY.toInt()395 }396 shouldThrow<ArithmeticException> {397 NEGATIVE_INFINITY.toInt()398 }399 shouldThrow<ArithmeticException> {400 NaN.toInt()401 }402 }403 @Test404 fun `should convert big decimal in infix constructor`() {405 0.0.big.toBigRational() shouldBe ZERO406 30.0.big.toBigRational() shouldBe (30 over 1)407 3.0.big.toBigRational() shouldBe (3 over 1)408 BFloating("0.3").toBigRational() shouldBe (3 over 10)409 BFloating("7.70").toBigRational() shouldBe (77 over 10)410 (1.0.big over 1.0.big) shouldBe ONE411 (1.big over 1.0.big) shouldBe ONE412 (1L over 1.0.big) shouldBe ONE413 (1 over 1.0.big) shouldBe ONE414 (1.0 over 1.0.big) shouldBe ONE415 (1.0f over 1.0.big) shouldBe ONE416 (1.0.big over 1L) shouldBe ONE417 (1.0.big over 1) shouldBe ONE418 }419 @Test420 fun `should convert big integer in infix constructor`() {421 0.big.toBigRational() shouldBe ZERO422 BFixed.valueOf(30L).toBigRational() shouldBe (30 over 1)423 3.big.toBigRational() shouldBe (3 over 1)424 (1.big over 1.big) shouldBe ONE425 (1.0.big over 1.big) shouldBe ONE426 (1L over 1.big) shouldBe ONE427 (1 over 1.big) shouldBe ONE428 (1.0 over 1.big) shouldBe ONE429 (1.0f over 1.big) shouldBe ONE430 (1.big over 1L) shouldBe ONE431 (1.big over 1) shouldBe ONE432 }433 @Test434 fun `should convert double in infix constructor`() {435 (1.0.big over 1.0) shouldBe ONE436 (1.big over 1.0) shouldBe ONE437 (1L over 1.0) shouldBe ONE438 (1 over 1.0) shouldBe ONE439 (1.0 over 1.0) shouldBe ONE440 (1.0f over 1.0) shouldBe ONE441 (1.0 over 1.big) shouldBe ONE442 (1.0 over 1L) shouldBe ONE443 (1.0 over 1) shouldBe ONE444 }445 @Test446 fun `should convert float in infix constructor`() {447 (1.0.big over 1.0f) shouldBe ONE448 (1.big over 1.0f) shouldBe ONE449 (1L over 1.0f) shouldBe ONE450 (1 over 1.0f) shouldBe ONE451 (1.0 over 1.0f) shouldBe ONE452 (1.0f over 1.0f) shouldBe ONE453 (1.0f over 1.big) shouldBe ONE454 (1.0f over 1L) shouldBe ONE455 (1.0f over 1) shouldBe ONE456 }457 @Test458 fun `should convert from double`() {459 val doubles = listOf(460 -4.0,461 -3.0,462 -2.0,463 -1.0,464 -0.5,465 -0.3,466 -0.1,467 0.0,468 0.1,469 0.3,470 0.5,471 1.0,472 2.0,473 3.0,474 4.0,475 10.0,476 123.456477 )478 val rationals = listOf(479 -4 over 1,480 -3 over 1,481 -2 over 1,482 -1 over 1,483 -1 over 2,484 -3 over 10,485 -1 over 10,486 ZERO,487 1 over 10,488 3 over 10,489 1 over 2,490 ONE,491 TWO,492 3 over 1,493 4 over 1,494 TEN,495 15432 over 125496 )497 Double.POSITIVE_INFINITY.toBigRational().shouldBePositiveInfinity()498 Double.NEGATIVE_INFINITY.toBigRational().shouldBeNegativeInfinity()499 Double.NaN.toBigRational().shouldBeNaN()500 (-0.0).toBigRational() shouldBe ZERO501 doubles.map {502 it.toBigRational()503 } shouldBe rationals504 rationals.map {505 it.toDouble()506 } shouldBe doubles507 }508 @Test509 fun `should convert from float`() {510 val floats = listOf(511 -4.0f,512 -3.0f,513 -2.0f,514 -1.0f,515 -0.5f,516 -0.3f,517 -0.1f,518 0.0f,519 0.1f,520 0.3f,521 0.5f,522 1.0f,523 2.0f,524 3.0f,525 4.0f,526 10.0f,527 123.456f528 )529 val rationals = listOf(530 -4 over 1,531 -3 over 1,532 -2 over 1,533 -1 over 1,534 -1 over 2,535 -3 over 10,536 -1 over 10,537 ZERO,538 1 over 10,539 3 over 10,540 1 over 2,541 ONE,542 TWO,543 3 over 1,544 4 over 1,545 TEN,546 15432 over 125547 )548 Float.POSITIVE_INFINITY.toBigRational().shouldBePositiveInfinity()549 Float.NEGATIVE_INFINITY.toBigRational().shouldBeNegativeInfinity()550 Float.NaN.toBigRational().shouldBeNaN()551 (-0.0f).toBigRational() shouldBe ZERO552 floats.map {553 it.toBigRational()554 } shouldBe rationals555 rationals.map {556 it.toFloat()557 } shouldBe floats558 }559 @Test560 fun `should convert to fixed equivalent or complain`() {561 ONE.toFixedBigRational() shouldBe FixedBigRational.ONE562 shouldThrow<ArithmeticException> {563 NaN.toFixedBigRational()564 }565 shouldThrow<ArithmeticException> {566 POSITIVE_INFINITY.toFixedBigRational()567 }568 shouldThrow<ArithmeticException> {569 NEGATIVE_INFINITY.toFixedBigRational()570 }571 }572 }573 @Nested574 inner class FunctionTests {575 @Test576 fun `should sort like double`() {577 val sorted = listOf(578 POSITIVE_INFINITY,579 NaN,580 ZERO,581 POSITIVE_INFINITY,582 NaN,583 NEGATIVE_INFINITY,584 ZERO,585 NEGATIVE_INFINITY586 ).sorted()587 val doubleSorted = listOf(588 Double.POSITIVE_INFINITY,589 Double.NaN,590 0.0,591 Double.POSITIVE_INFINITY,592 Double.NaN,593 Double.NEGATIVE_INFINITY,594 0.0,595 Double.NEGATIVE_INFINITY596 ).sorted()597 (sorted.map { it.toDouble() }) shouldBe doubleSorted598 }599 @Test600 fun `should compare other number types`() {601 (Double.POSITIVE_INFINITY > ZERO).shouldBeTrue()602 (ZERO > Double.NEGATIVE_INFINITY).shouldBeTrue()603 (Float.NaN > ZERO).shouldBeTrue()604 (NaN > Float.MAX_VALUE).shouldBeTrue()605 }606 @Test607 fun `should not order NaN values`() {608 @Suppress("KotlinConstantConditions")609 (NaN == NaN).shouldBeFalse()610 (NaN > NaN).shouldBeFalse()611 (NaN < NaN).shouldBeFalse()612 }613 @Test614 fun `should reciprocate`() {615 POSITIVE_INFINITY.unaryDiv() shouldBe ZERO616 NEGATIVE_INFINITY.unaryDiv() shouldBe ZERO617 NaN.unaryDiv().shouldBeNaN()618 }619 @Test620 fun `should absolute`() {621 NaN.absoluteValue.shouldBeNaN()622 POSITIVE_INFINITY.absoluteValue623 .shouldBePositiveInfinity()624 NEGATIVE_INFINITY.absoluteValue625 .shouldBePositiveInfinity()626 }627 @Test628 fun `should signum`() {629 ZERO.sign shouldBe ZERO630 NEGATIVE_INFINITY.sign shouldBe -ONE631 POSITIVE_INFINITY.sign shouldBe ONE632 NaN.sign.shouldBeNaN()633 }634 @Test635 fun `should raise`() {636 POSITIVE_INFINITY `^` 2 shouldBe POSITIVE_INFINITY637 POSITIVE_INFINITY `^` -1 shouldBe ZERO638 NEGATIVE_INFINITY `^` 3 shouldBe NEGATIVE_INFINITY639 NEGATIVE_INFINITY `^` 2 shouldBe POSITIVE_INFINITY640 NEGATIVE_INFINITY `^` -1 shouldBe ZERO641 (NaN `^` 2).shouldBeNaN()642 (POSITIVE_INFINITY `^` 0).shouldBeNaN()643 (NEGATIVE_INFINITY `^` 0).shouldBeNaN()644 }645 @Test646 fun `should square root`() {647 NaN.sqrt().shouldBeNaN()648 POSITIVE_INFINITY.sqrt() shouldBe POSITIVE_INFINITY649 }650 @Test651 fun `should square root approximately`() {652 NaN.sqrtApproximated().shouldBeNaN()653 POSITIVE_INFINITY.sqrtApproximated() shouldBe POSITIVE_INFINITY654 }655 @Test656 fun `should find between`() {657 NaN.mediant(NaN).shouldBeNaN()658 NaN.mediant(POSITIVE_INFINITY).shouldBeNaN()659 NaN.mediant(NEGATIVE_INFINITY).shouldBeNaN()660 POSITIVE_INFINITY.mediant(POSITIVE_INFINITY)661 .shouldBePositiveInfinity()662 NEGATIVE_INFINITY.mediant(NEGATIVE_INFINITY)663 .shouldBeNegativeInfinity()664 NaN.mediant(ZERO).shouldBeNaN()665 ZERO.mediant(NaN).shouldBeNaN()666 POSITIVE_INFINITY.mediant(NaN).shouldBeNaN()667 NEGATIVE_INFINITY.mediant(NaN).shouldBeNaN()668 POSITIVE_INFINITY.mediant(NEGATIVE_INFINITY) shouldBe ZERO669 NEGATIVE_INFINITY.mediant(POSITIVE_INFINITY) shouldBe ZERO670 POSITIVE_INFINITY.mediant(ZERO) shouldBe ONE671 ZERO.mediant(POSITIVE_INFINITY) shouldBe ONE672 ZERO.mediant(NEGATIVE_INFINITY) shouldBe -ONE673 NEGATIVE_INFINITY.mediant(ZERO) shouldBe -ONE674 }675 @Test676 fun `should find continued fraction`() {677 val cfA = (3245 over 1000).toContinuedFraction()678 cfA.isFinite().shouldBeTrue()679 val negCfA = (-3245 over 1000).toContinuedFraction()680 negCfA.isFinite().shouldBeTrue()681 val cfNaN = NaN.toContinuedFraction()682 cfNaN.isFinite().shouldBeFalse()683 cfNaN.toBigRational().shouldBeNaN()684 cfNaN.integerPart.shouldBeNaN()685 val cfPosInf = POSITIVE_INFINITY.toContinuedFraction()686 cfPosInf.isFinite().shouldBeFalse()687 cfPosInf.toBigRational().shouldBeNaN()688 cfPosInf.integerPart.shouldBeNaN()689 val cfNegInf = NEGATIVE_INFINITY.toContinuedFraction()690 cfNegInf.isFinite().shouldBeFalse()691 cfNegInf.toBigRational().shouldBeNaN()692 cfNegInf.integerPart.shouldBeNaN()693 }694 }695}696private fun FloatingBigRational.shouldBePositiveInfinity() =697 isPositiveInfinity().shouldBeTrue()698private fun FloatingBigRational.shouldBeNegativeInfinity() =699 isNegativeInfinity().shouldBeTrue()700private fun FloatingBigRational.shouldBeNaN() = isNaN().shouldBeTrue()...

Full Screen

Full Screen

FloatNaNTest.kt

Source:FloatNaNTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.matchers.floats2import com.sksamuel.kotest.matchers.doubles.numericFloats3import io.kotest.assertions.throwables.shouldThrow4import io.kotest.core.spec.style.FunSpec5import io.kotest.matchers.floats.beNaN6import io.kotest.matchers.floats.shouldBeNaN7import io.kotest.matchers.floats.shouldNotBeNaN8import io.kotest.matchers.should9import io.kotest.matchers.shouldBe10import io.kotest.matchers.shouldNot11import io.kotest.property.checkAll12class FloatNaNTest : FunSpec() {13 init {14 context("NaN matcher") {15 test("Every numeric float should not be NaN") {16 checkAll(100, numericFloats) {17 it.shouldNotMatchNaN()18 }19 }20 test("The non-numeric floats") {21 Float.NaN.shouldMatchNaN()22 Float.POSITIVE_INFINITY.shouldNotMatchNaN()23 Float.NEGATIVE_INFINITY.shouldNotMatchNaN()24 }25 }26 }27 private fun Float.shouldMatchNaN() {28 this should beNaN()29 this.shouldBeNaN()30 this.shouldThrowExceptionOnNotBeNaN()31 }32 private fun Float.shouldNotMatchNaN() {33 this shouldNot beNaN()34 this.shouldNotBeNaN()35 this.shouldThrowExceptionOnBeNaN()36 }37 private fun Float.shouldThrowExceptionOnNotBeNaN() {38 shouldThrowAssertionError("$this should not be NaN",39 { this.shouldNotBeNaN() },40 { this shouldNot beNaN() })41 }42 private fun Float.shouldThrowExceptionOnBeNaN() {43 shouldThrowAssertionError("$this should be NaN",44 { this.shouldBeNaN() },45 { this should beNaN() })46 }47 private fun shouldThrowAssertionError(message: String, vararg expression: () -> Any?) {48 expression.forEach {49 val exception = shouldThrow<AssertionError>(it)50 exception.message shouldBe message51 }52 }53}...

Full Screen

Full Screen

NaN.kt

Source:NaN.kt Github

copy

Full Screen

1package io.kotest.matchers.floats2import io.kotest.matchers.Matcher3import io.kotest.matchers.MatcherResult4import io.kotest.matchers.should5import io.kotest.matchers.shouldNot6/**7 * Asserts that this [Float] is [Float.NaN]8 *9 * Verifies that this [Float] is the Not-a-Number constant [Float.NaN]10 *11 * Opposite of [shouldNotBeNaN]12 *13 * ```14 * Float.NaN.shouldBeNaN() // Assertion passes15 * 1f.shouldBeNaN() // Assertion fails16 * ```17 * @see [beNaN]18 */19fun Float.shouldBeNaN(): Float {20 this should beNaN()21 return this22}23/**24 * Assert that this [Float] is not [Float.NaN]25 *26 * Verifies that this [Float] is NOT the Not-a-Number constant [Float.NaN]27 *28 * Opposite of [shouldBeNaN]29 *30 * ```31 * 1f.shouldNotBeNaN() // Assertion passes32 * Float.NaN.shouldNotBeNaN() // Assertion fails33 * ```34 * @see [beNaN]35 */36fun Float.shouldNotBeNaN(): Float {37 this shouldNot beNaN()38 return this39}40/**41 * Matcher that matches [Float.NaN]42 *43 * Verifies that a specific [Float] is the Not-a-Number constant [Float.NaN]44 *45 * ```46 * 0.5f should beNaN() // Assertion fails47 * Float.NaN should beNaN() // Assertion passes48 * ```49 *50 * @see [Float.shouldBeNaN]51 * @see [Float.shouldNotBeNaN]52 */53fun beNaN() = object : Matcher<Float> {54 override fun test(value: Float) = MatcherResult(55 value.isNaN(),56 { "$value should be NaN" },57 { "$value should not be NaN" })58}...

Full Screen

Full Screen

Float.shouldBeNaN

Using AI Code Generation

copy

Full Screen

1fun main() { Float . shouldBeNaN ( 0.0f / 0.0f ) }2fun main() { Float . shouldNotBeNaN ( 1.0f ) }3fun main() { Double . shouldBeNaN ( 0.0 / 0.0 ) }4fun main() { Double . shouldNotBeNaN ( 1.0 ) }5fun main() { Double . shouldBeNaN ( 0.0 / 0.0 ) }6fun main() { Double . shouldNotBeNaN ( 1.0 ) }7fun main() { Double . shouldBeNaN ( 0.0 / 0.0 ) }8fun main() { Double . shouldNotBeNaN ( 1.0 ) }9fun main() { Double . shouldBeNaN ( 0.0 / 0.0 ) }10fun main() { Double . shouldNotBeNaN ( 1.0 ) }11fun main() { Double . shouldBeNaN ( 0.0 / 0.0 ) }12fun main() { Double . shouldNotBeNaN ( 1.0 ) }13fun main() { Double . shouldBeNaN ( 0.0 /

Full Screen

Full Screen

Float.shouldBeNaN

Using AI Code Generation

copy

Full Screen

1Float.shouldBeNaN(functionUnderTest())2Float.shouldBeNaN( functionUnderTest ())3Float.shouldBeNaN( functionUnderTest ())4Float.shouldBeNaN(functionUnderTest())5Float.shouldBeNaN( functionUnderTest ())6Float.shouldBeNaN( functionUnderTest ())7Float.shouldBeNaN(functionUnderTest())8Float.shouldBeNaN( functionUnderTest ())9Float.shouldBeNaN( functionUnderTest ())10Float.shouldBeNaN(functionUnderTest())11Float.shouldBeNaN( functionUnderTest ())12Float.shouldBeNaN( functionUnderTest ())13Float.shouldBeNaN(functionUnderTest())

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