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

Best Kotest code snippet using io.kotest.matchers.floats.NaN.test

ReadOnlyJSONValTests.kt

Source:ReadOnlyJSONValTests.kt Github

copy

Full Screen

...16 */17package com.github.oneandolaf.jsonext.readonly18import com.github.oneandolaf.jsonext.extensions.asReadOnly19import com.github.oneandolaf.jsonext.impl.Conversions20import com.github.oneandolaf.jsonext.testutils.*21import io.kotest.core.spec.style.FunSpec22import io.kotest.matchers.booleans.shouldBeFalse23import io.kotest.matchers.booleans.shouldBeTrue24import io.kotest.matchers.nulls.shouldBeNull25import io.kotest.matchers.shouldBe26import io.kotest.matchers.string.shouldBeEmpty27import io.kotest.matchers.types.shouldBeInstanceOf28import io.kotest.property.Exhaustive29import io.kotest.property.checkAll30import io.kotest.property.exhaustive.enum31import io.kotest.property.exhaustive.times32import org.json.JSONArray33import org.json.JSONObject34import java.math.BigDecimal35import java.math.BigInteger36class ReadOnlyJSONValTests : FunSpec({37 test("orNull") {38 checkAll(JSONGenerators.values) {39 val value = ReadOnlyJSONVal(it)40 value.orNull() shouldBeSimilarTo it41 if (it is JSONObject) {42 value.orNull().shouldBeInstanceOf<ReadOnlyJSONObject>()43 } else if (it is JSONArray) {44 value.orNull().shouldBeInstanceOf<ReadOnlyJSONArray>()45 }46 }47 ReadOnlyJSONVal(null).orNull().shouldBeNull()48 }49 test("orDefault") {50 checkAll(JSONGenerators.values * JSONGenerators.values) { data ->51 val value = ReadOnlyJSONVal(data.first)52 value.orDefault(data.second) shouldBeSimilarTo data.first53 ReadOnlyJSONVal(null).orDefault(data.second) shouldBeSimilarTo data.second54 }55 }56 test("orElse") {57 checkAll(JSONGenerators.values * JSONGenerators.values) { data ->58 val value = ReadOnlyJSONVal(data.first)59 value.orElse { data.second } shouldBeSimilarTo data.first60 ReadOnlyJSONVal(null).orElse { data.second } shouldBeSimilarTo data.second61 }62 }63 test("isArray") {64 checkAll(JSONGenerators.arrays) {65 ReadOnlyJSONVal(it).isArray().shouldBeTrue()66 }67 checkAll(JSONGenerators.nonArrays) {68 ReadOnlyJSONVal(it).isArray().shouldBeFalse()69 }70 ReadOnlyJSONVal(null).isArray().shouldBeFalse()71 }72 test("asArrayOrNull") {73 checkAll(JSONGenerators.arrays) {74 ReadOnlyJSONVal(it).asArrayOrNull() shouldBeSimilarTo it75 }76 checkAll(JSONGenerators.nonArrays) {77 ReadOnlyJSONVal(it).asArrayOrNull().shouldBeNull()78 }79 ReadOnlyJSONVal(null).asArrayOrNull().shouldBeNull()80 }81 test("asArrayOrDefault") {82 checkAll(JSONGenerators.arrays * JSONGenerators.arrays) { data ->83 ReadOnlyJSONVal(data.first).asArrayOrDefault(data.second.asReadOnly()) shouldBeSimilarTo data.first84 }85 checkAll(JSONGenerators.nonArrays * JSONGenerators.arrays) { data ->86 ReadOnlyJSONVal(data.first).asArrayOrDefault(data.second.asReadOnly()) shouldBeSimilarTo data.second87 }88 checkAll(JSONGenerators.arrays) {89 ReadOnlyJSONVal(null).asArrayOrDefault(it.asReadOnly()) shouldBeSimilarTo it90 }91 }92 test("asArrayOrEmpty") {93 checkAll(JSONGenerators.arrays) {94 ReadOnlyJSONVal(it).asArrayOrEmpty() shouldBeSimilarTo it95 }96 checkAll(JSONGenerators.nonArrays) {97 ReadOnlyJSONVal(it).asArrayOrEmpty() shouldBeSimilarTo ReadOnlyJSONArray.EMPTY98 }99 ReadOnlyJSONVal(null).asArrayOrEmpty() shouldBeSimilarTo ReadOnlyJSONArray.EMPTY100 }101 test("asArrayOrElse") {102 checkAll(JSONGenerators.arrays * JSONGenerators.arrays) { data ->103 ReadOnlyJSONVal(data.first).asArrayOrElse { data.second.asReadOnly() } shouldBeSimilarTo data.first104 }105 checkAll(JSONGenerators.nonArrays * JSONGenerators.arrays) { data ->106 ReadOnlyJSONVal(data.first).asArrayOrElse { data.second.asReadOnly() } shouldBeSimilarTo data.second107 }108 checkAll(JSONGenerators.arrays) {109 ReadOnlyJSONVal(null).asArrayOrElse { it.asReadOnly() } shouldBeSimilarTo it110 }111 }112 test("isBigDecimal") {113 checkAll(JSONGenerators.numberLikes) {114 ReadOnlyJSONVal(it).isBigDecimal().shouldBeTrue()115 }116 checkAll(JSONGenerators.nonNumberLikes) {117 ReadOnlyJSONVal(it).isBigDecimal().shouldBeFalse()118 }119 ReadOnlyJSONVal(null).isBigDecimal().shouldBeFalse()120 }121 test("asBigDecimalOrNull") {122 checkAll(JSONGenerators.numberLikes) {123 ReadOnlyJSONVal(it).asBigDecimalOrNull() shouldBe Conversions.toBigDecimal(it)!!124 }125 checkAll(JSONGenerators.nonNumberLikes) {126 ReadOnlyJSONVal(it).asBigDecimalOrNull().shouldBeNull()127 }128 ReadOnlyJSONVal(null).asBigDecimalOrNull().shouldBeNull()129 }130 test("asBigDecimalOrDefault") {131 checkAll(JSONGenerators.numberLikes * JSONGenerators.bigDecimals) { data ->132 ReadOnlyJSONVal(data.first).asBigDecimalOrDefault(data.second) shouldBe Conversions.toBigDecimal(133 data.first134 )!!135 }136 checkAll(JSONGenerators.nonNumberLikes * JSONGenerators.bigDecimals) { data ->137 ReadOnlyJSONVal(data.first).asBigDecimalOrDefault(data.second) shouldBe data.second138 }139 checkAll(JSONGenerators.bigDecimals) {140 ReadOnlyJSONVal(null).asBigDecimalOrDefault(it) shouldBe it141 }142 }143 test("asBigDecimalOrZero") {144 checkAll(JSONGenerators.numberLikes) {145 ReadOnlyJSONVal(it).asBigDecimalOrZero() shouldBe Conversions.toBigDecimal(it)!!146 }147 checkAll(JSONGenerators.nonNumberLikes) {148 ReadOnlyJSONVal(it).asBigDecimalOrZero() shouldBe BigDecimal.ZERO149 }150 ReadOnlyJSONVal(null).asBigDecimalOrZero() shouldBe BigDecimal.ZERO151 }152 test("asBigDecimalOrOne") {153 checkAll(JSONGenerators.numberLikes) {154 ReadOnlyJSONVal(it).asBigDecimalOrOne() shouldBe Conversions.toBigDecimal(it)!!155 }156 checkAll(JSONGenerators.nonNumberLikes) {157 ReadOnlyJSONVal(it).asBigDecimalOrOne() shouldBe BigDecimal.ONE158 }159 ReadOnlyJSONVal(null).asBigDecimalOrOne() shouldBe BigDecimal.ONE160 }161 test("asBigDecimalOrMinusOne") {162 checkAll(JSONGenerators.numberLikes) {163 ReadOnlyJSONVal(it).asBigDecimalOrMinusOne() shouldBe Conversions.toBigDecimal(it)!!164 }165 checkAll(JSONGenerators.nonNumberLikes) {166 ReadOnlyJSONVal(it).asBigDecimalOrMinusOne() shouldBe BigDecimal.valueOf(-1L)167 }168 ReadOnlyJSONVal(null).asBigDecimalOrMinusOne() shouldBe BigDecimal.valueOf(-1L)169 }170 test("asBigDecimalOrElse") {171 checkAll(JSONGenerators.numberLikes * JSONGenerators.bigDecimals) { data ->172 ReadOnlyJSONVal(data.first).asBigDecimalOrElse { data.second } shouldBe Conversions.toBigDecimal(173 data.first174 )!!175 }176 checkAll(JSONGenerators.nonNumberLikes * JSONGenerators.bigDecimals) { data ->177 ReadOnlyJSONVal(data.first).asBigDecimalOrElse { data.second } shouldBe data.second178 }179 checkAll(JSONGenerators.bigDecimals) {180 ReadOnlyJSONVal(null).asBigDecimalOrElse { it } shouldBe it181 }182 }183 test("isBigInteger") {184 checkAll(JSONGenerators.numberLikes) {185 ReadOnlyJSONVal(it).isBigInteger().shouldBeTrue()186 }187 checkAll(JSONGenerators.nonNumberLikes) {188 ReadOnlyJSONVal(it).isBigInteger().shouldBeFalse()189 }190 ReadOnlyJSONVal(null).isBigInteger().shouldBeFalse()191 }192 test("asBigIntegerOrNull") {193 checkAll(JSONGenerators.numberLikes) {194 ReadOnlyJSONVal(it).asBigIntegerOrNull() shouldBe Conversions.toBigInteger(it)!!195 }196 checkAll(JSONGenerators.nonNumberLikes) {197 ReadOnlyJSONVal(it).asBigIntegerOrNull().shouldBeNull()198 }199 ReadOnlyJSONVal(null).asBigIntegerOrNull().shouldBeNull()200 }201 test("asBigIntegerOrDefault") {202 checkAll(JSONGenerators.numberLikes * JSONGenerators.bigIntegers) { data ->203 ReadOnlyJSONVal(data.first).asBigIntegerOrDefault(data.second) shouldBe Conversions.toBigInteger(204 data.first205 )!!206 }207 checkAll(JSONGenerators.nonNumberLikes * JSONGenerators.bigIntegers) { data ->208 ReadOnlyJSONVal(data.first).asBigIntegerOrDefault(data.second) shouldBe data.second209 }210 checkAll(JSONGenerators.bigIntegers) {211 ReadOnlyJSONVal(null).asBigIntegerOrDefault(it) shouldBe it212 }213 }214 test("asBigIntegerOrZero") {215 checkAll(JSONGenerators.numberLikes) {216 ReadOnlyJSONVal(it).asBigIntegerOrZero() shouldBe Conversions.toBigInteger(it)!!217 }218 checkAll(JSONGenerators.nonNumberLikes) {219 ReadOnlyJSONVal(it).asBigIntegerOrZero() shouldBe BigInteger.ZERO220 }221 ReadOnlyJSONVal(null).asBigIntegerOrZero() shouldBe BigInteger.ZERO222 }223 test("asBigIntegerOrOne") {224 checkAll(JSONGenerators.numberLikes) {225 ReadOnlyJSONVal(it).asBigIntegerOrOne() shouldBe Conversions.toBigInteger(it)!!226 }227 checkAll(JSONGenerators.nonNumberLikes) {228 ReadOnlyJSONVal(it).asBigIntegerOrOne() shouldBe BigInteger.ONE229 }230 ReadOnlyJSONVal(null).asBigIntegerOrOne() shouldBe BigInteger.ONE231 }232 test("asBigIntegerOrMinusOne") {233 checkAll(JSONGenerators.numberLikes) {234 ReadOnlyJSONVal(it).asBigIntegerOrMinusOne() shouldBe Conversions.toBigInteger(it)!!235 }236 checkAll(JSONGenerators.nonNumberLikes) {237 ReadOnlyJSONVal(it).asBigIntegerOrMinusOne() shouldBe BigInteger.valueOf(-1L)238 }239 ReadOnlyJSONVal(null).asBigIntegerOrMinusOne() shouldBe BigInteger.valueOf(-1L)240 }241 test("asBigIntegerOrElse") {242 checkAll(JSONGenerators.numberLikes * JSONGenerators.bigIntegers) { data ->243 ReadOnlyJSONVal(data.first).asBigIntegerOrElse { data.second } shouldBe Conversions.toBigInteger(244 data.first245 )!!246 }247 checkAll(JSONGenerators.nonNumberLikes * JSONGenerators.bigIntegers) { data ->248 ReadOnlyJSONVal(data.first).asBigIntegerOrElse { data.second } shouldBe data.second249 }250 checkAll(JSONGenerators.bigIntegers) {251 ReadOnlyJSONVal(null).asBigIntegerOrElse { it } shouldBe it252 }253 }254 test("isBoolean") {255 checkAll(JSONGenerators.booleanLikes) {256 ReadOnlyJSONVal(it).isBoolean().shouldBeTrue()257 }258 checkAll(JSONGenerators.nonBooleanLikes) {259 ReadOnlyJSONVal(it).isBoolean().shouldBeFalse()260 }261 ReadOnlyJSONVal(null).isBoolean().shouldBeFalse()262 }263 test("asBooleanOrNull") {264 checkAll(JSONGenerators.booleanLikes) {265 ReadOnlyJSONVal(it).asBooleanOrNull() shouldBe Conversions.toBoolean(it)!!266 }267 checkAll(JSONGenerators.nonBooleanLikes) {268 ReadOnlyJSONVal(it).asBooleanOrNull().shouldBeNull()269 }270 ReadOnlyJSONVal(null).asBooleanOrNull().shouldBeNull()271 }272 test("asBooleanOrDefault") {273 checkAll(JSONGenerators.booleanLikes * JSONGenerators.bools) { data ->274 ReadOnlyJSONVal(data.first).asBooleanOrDefault(data.second) shouldBe Conversions.toBoolean(data.first)!!275 }276 checkAll(JSONGenerators.nonBooleanLikes * JSONGenerators.bools) { data ->277 ReadOnlyJSONVal(data.first).asBooleanOrDefault(data.second) shouldBe data.second278 }279 checkAll(JSONGenerators.bools) {280 ReadOnlyJSONVal(null).asBooleanOrDefault(it) shouldBe it281 }282 }283 test("asBooleanOrTrue") {284 checkAll(JSONGenerators.booleanLikes) {285 ReadOnlyJSONVal(it).asBooleanOrTrue() shouldBe Conversions.toBoolean(it)!!286 }287 checkAll(JSONGenerators.nonBooleanLikes) {288 ReadOnlyJSONVal(it).asBooleanOrTrue().shouldBeTrue()289 }290 ReadOnlyJSONVal(null).asBooleanOrTrue().shouldBeTrue()291 }292 test("asBooleanOrFalse") {293 checkAll(JSONGenerators.booleanLikes) {294 ReadOnlyJSONVal(it).asBooleanOrFalse() shouldBe Conversions.toBoolean(it)!!295 }296 checkAll(JSONGenerators.nonBooleanLikes) {297 ReadOnlyJSONVal(it).asBooleanOrFalse().shouldBeFalse()298 }299 ReadOnlyJSONVal(null).asBooleanOrFalse().shouldBeFalse()300 }301 test("asBooleanOrElse") {302 checkAll(JSONGenerators.booleanLikes * JSONGenerators.bools) { data ->303 ReadOnlyJSONVal(data.first).asBooleanOrElse { data.second } shouldBe Conversions.toBoolean(data.first)!!304 }305 checkAll(JSONGenerators.nonBooleanLikes * JSONGenerators.bools) { data ->306 ReadOnlyJSONVal(data.first).asBooleanOrElse { data.second } shouldBe data.second307 }308 checkAll(JSONGenerators.bools) {309 ReadOnlyJSONVal(null).asBooleanOrElse { it } shouldBe it310 }311 }312 test("isDouble") {313 checkAll(JSONGenerators.numberLikes) {314 ReadOnlyJSONVal(it).isDouble().shouldBeTrue()315 }316 checkAll(JSONGenerators.nonNumberLikes) {317 ReadOnlyJSONVal(it).isDouble().shouldBeFalse()318 }319 ReadOnlyJSONVal(null).isDouble().shouldBeFalse()320 }321 test("asDoubleOrNull") {322 checkAll(JSONGenerators.numberLikes) {323 ReadOnlyJSONVal(it).asDoubleOrNull() shouldBe Conversions.toDouble(it)!!324 }325 checkAll(JSONGenerators.nonNumberLikes) {326 ReadOnlyJSONVal(it).asDoubleOrNull().shouldBeNull()327 }328 ReadOnlyJSONVal(null).asDoubleOrNull().shouldBeNull()329 }330 test("asDoubleOrDefault") {331 checkAll(JSONGenerators.numberLikes * JSONGenerators.doubles) { data ->332 ReadOnlyJSONVal(data.first).asDoubleOrDefault(data.second) shouldBe Conversions.toDouble(data.first)!!333 }334 checkAll(JSONGenerators.nonNumberLikes * JSONGenerators.doubles) { data ->335 ReadOnlyJSONVal(data.first).asDoubleOrDefault(data.second) shouldBe data.second336 }337 checkAll(JSONGenerators.doubles) {338 ReadOnlyJSONVal(null).asDoubleOrDefault(it) shouldBe it339 }340 }341 test("asDoubleOrZero") {342 checkAll(JSONGenerators.numberLikes) {343 ReadOnlyJSONVal(it).asDoubleOrZero() shouldBe Conversions.toDouble(it)!!344 }345 checkAll(JSONGenerators.nonNumberLikes) {346 ReadOnlyJSONVal(it).asDoubleOrZero() shouldBe 0.0347 }348 ReadOnlyJSONVal(null).asDoubleOrZero() shouldBe 0.0349 }350 test("asDoubleOrOne") {351 checkAll(JSONGenerators.numberLikes) {352 ReadOnlyJSONVal(it).asDoubleOrOne() shouldBe Conversions.toDouble(it)!!353 }354 checkAll(JSONGenerators.nonNumberLikes) {355 ReadOnlyJSONVal(it).asDoubleOrOne() shouldBe 1.0356 }357 ReadOnlyJSONVal(null).asDoubleOrOne() shouldBe 1.0358 }359 test("asDoubleOrMinusOne") {360 checkAll(JSONGenerators.numberLikes) {361 ReadOnlyJSONVal(it).asDoubleOrMinusOne() shouldBe Conversions.toDouble(it)!!362 }363 checkAll(JSONGenerators.nonNumberLikes) {364 ReadOnlyJSONVal(it).asDoubleOrMinusOne() shouldBe -1.0365 }366 ReadOnlyJSONVal(null).asDoubleOrMinusOne() shouldBe -1.0367 }368 test("asDoubleOrNaN") {369 checkAll(JSONGenerators.numberLikes) {370 ReadOnlyJSONVal(it).asDoubleOrNaN() shouldBe Conversions.toDouble(it)!!371 }372 checkAll(JSONGenerators.nonNumberLikes) {373 ReadOnlyJSONVal(it).asDoubleOrNaN() shouldBe Double.NaN374 }375 ReadOnlyJSONVal(null).asDoubleOrNaN() shouldBe Double.NaN376 }377 test("asDoubleOrElse") {378 checkAll(JSONGenerators.numberLikes * JSONGenerators.doubles) { data ->379 ReadOnlyJSONVal(data.first).asDoubleOrElse { data.second } shouldBe Conversions.toDouble(data.first)!!380 }381 checkAll(JSONGenerators.nonNumberLikes * JSONGenerators.doubles) { data ->382 ReadOnlyJSONVal(data.first).asDoubleOrElse { data.second } shouldBe data.second383 }384 checkAll(JSONGenerators.doubles) {385 ReadOnlyJSONVal(null).asDoubleOrElse { it } shouldBe it386 }387 }388 test("isEnum") {389 checkAll(Exhaustive.enum<TestEnum>()) {390 ReadOnlyJSONVal(it).isEnum<TestEnum>().shouldBeTrue()391 ReadOnlyJSONVal(it).isEnum(TestEnum::class.java).shouldBeTrue()392 }393 checkAll(JSONGenerators.values) {394 ReadOnlyJSONVal(it).isEnum<TestEnum>().shouldBeFalse()395 ReadOnlyJSONVal(it).isEnum(TestEnum::class.java).shouldBeFalse()396 }397 ReadOnlyJSONVal(null).isEnum<TestEnum>().shouldBeFalse()398 ReadOnlyJSONVal(null).isEnum(TestEnum::class.java).shouldBeFalse()399 }400 test("asEnumOrNull") {401 checkAll(Exhaustive.enum<TestEnum>()) {402 ReadOnlyJSONVal(it).asEnumOrNull<TestEnum>() shouldBe it403 ReadOnlyJSONVal(it).asEnumOrNull(TestEnum::class.java) shouldBe it404 }405 checkAll(JSONGenerators.values) {406 ReadOnlyJSONVal(it).asEnumOrNull<TestEnum>().shouldBeNull()407 ReadOnlyJSONVal(it).asEnumOrNull(TestEnum::class.java).shouldBeNull()408 }409 ReadOnlyJSONVal(null).asEnumOrNull<TestEnum>().shouldBeNull()410 ReadOnlyJSONVal(null).asEnumOrNull(TestEnum::class.java).shouldBeNull()411 }412 test("asEnumOrDefault") {413 checkAll(Exhaustive.enum<TestEnum>() cross Exhaustive.enum<TestEnum>()) {414 ReadOnlyJSONVal(it.first).asEnumOrDefault(it.second) shouldBe it.first415 }416 checkAll(JSONGenerators.values cross Exhaustive.enum<TestEnum>()) {417 ReadOnlyJSONVal(it.first).asEnumOrDefault(it.second) shouldBe it.second418 }419 checkAll(Exhaustive.enum<TestEnum>()) {420 ReadOnlyJSONVal(null).asEnumOrDefault(it) shouldBe it421 }422 }423 test("asEnumOrElse") {424 checkAll(Exhaustive.enum<TestEnum>() cross Exhaustive.enum<TestEnum>()) {425 ReadOnlyJSONVal(it.first).asEnumOrElse { it.second } shouldBe it.first426 ReadOnlyJSONVal(it.first).asEnumOrElse(TestEnum::class.java) { it.second } shouldBe it.first427 }428 checkAll(JSONGenerators.values cross Exhaustive.enum<TestEnum>()) {429 ReadOnlyJSONVal(it.first).asEnumOrElse { it.second } shouldBe it.second430 ReadOnlyJSONVal(it.first).asEnumOrElse(TestEnum::class.java) { it.second } shouldBe it.second431 }432 checkAll(Exhaustive.enum<TestEnum>()) {433 ReadOnlyJSONVal(null).asEnumOrElse { it } shouldBe it434 ReadOnlyJSONVal(null).asEnumOrElse(TestEnum::class.java) { it } shouldBe it435 }436 }437 test("isFloat") {438 checkAll(JSONGenerators.numberLikes) {439 ReadOnlyJSONVal(it).isFloat().shouldBeTrue()440 }441 checkAll(JSONGenerators.nonNumberLikes) {442 ReadOnlyJSONVal(it).isFloat().shouldBeFalse()443 }444 ReadOnlyJSONVal(null).isFloat().shouldBeFalse()445 }446 test("asFloatOrNull") {447 checkAll(JSONGenerators.numberLikes) {448 ReadOnlyJSONVal(it).asFloatOrNull() shouldBe Conversions.toFloat(it)!!449 }450 checkAll(JSONGenerators.nonNumberLikes) {451 ReadOnlyJSONVal(it).asFloatOrNull().shouldBeNull()452 }453 ReadOnlyJSONVal(null).asFloatOrNull().shouldBeNull()454 }455 test("asFloatOrDefault") {456 checkAll(JSONGenerators.numberLikes * JSONGenerators.floats) { data ->457 ReadOnlyJSONVal(data.first).asFloatOrDefault(data.second) shouldBe Conversions.toFloat(data.first)!!458 }459 checkAll(JSONGenerators.nonNumberLikes * JSONGenerators.floats) { data ->460 ReadOnlyJSONVal(data.first).asFloatOrDefault(data.second) shouldBe data.second461 }462 checkAll(JSONGenerators.floats) {463 ReadOnlyJSONVal(null).asFloatOrDefault(it) shouldBe it464 }465 }466 test("asFloatOrZero") {467 checkAll(JSONGenerators.numberLikes) {468 ReadOnlyJSONVal(it).asFloatOrZero() shouldBe Conversions.toFloat(it)!!469 }470 checkAll(JSONGenerators.nonNumberLikes) {471 ReadOnlyJSONVal(it).asFloatOrZero() shouldBe 0.0f472 }473 ReadOnlyJSONVal(null).asFloatOrZero() shouldBe 0.0f474 }475 test("asFloatOrOne") {476 checkAll(JSONGenerators.numberLikes) {477 ReadOnlyJSONVal(it).asFloatOrOne() shouldBe Conversions.toFloat(it)!!478 }479 checkAll(JSONGenerators.nonNumberLikes) {480 ReadOnlyJSONVal(it).asFloatOrOne() shouldBe 1.0f481 }482 ReadOnlyJSONVal(null).asFloatOrOne() shouldBe 1.0f483 }484 test("asFloatOrMinusOne") {485 checkAll(JSONGenerators.numberLikes) {486 ReadOnlyJSONVal(it).asFloatOrMinusOne() shouldBe Conversions.toFloat(it)!!487 }488 checkAll(JSONGenerators.nonNumberLikes) {489 ReadOnlyJSONVal(it).asFloatOrMinusOne() shouldBe -1.0f490 }491 ReadOnlyJSONVal(null).asFloatOrMinusOne() shouldBe -1.0f492 }493 test("asFloatOrNaN") {494 checkAll(JSONGenerators.numberLikes) {495 ReadOnlyJSONVal(it).asFloatOrNaN() shouldBe Conversions.toFloat(it)!!496 }497 checkAll(JSONGenerators.nonNumberLikes) {498 ReadOnlyJSONVal(it).asFloatOrNaN() shouldBe Float.NaN499 }500 ReadOnlyJSONVal(null).asFloatOrNaN() shouldBe Float.NaN501 }502 test("asFloatOrElse") {503 checkAll(JSONGenerators.numberLikes * JSONGenerators.floats) { data ->504 ReadOnlyJSONVal(data.first).asFloatOrElse { data.second } shouldBe Conversions.toFloat(data.first)!!505 }506 checkAll(JSONGenerators.nonNumberLikes * JSONGenerators.floats) { data ->507 ReadOnlyJSONVal(data.first).asFloatOrElse { data.second } shouldBe data.second508 }509 checkAll(JSONGenerators.floats) {510 ReadOnlyJSONVal(null).asFloatOrElse { it } shouldBe it511 }512 }513 test("isInt") {514 checkAll(JSONGenerators.intLikes) {515 ReadOnlyJSONVal(it).isInt().shouldBeTrue()516 }517 checkAll(JSONGenerators.nonIntLikes) {518 ReadOnlyJSONVal(it).isInt().shouldBeFalse()519 }520 ReadOnlyJSONVal(null).isInt().shouldBeFalse()521 }522 test("asIntOrNull") {523 checkAll(JSONGenerators.intLikes) {524 ReadOnlyJSONVal(it).asIntOrNull() shouldBe Conversions.toInt(it)!!525 }526 checkAll(JSONGenerators.nonIntLikes) {527 ReadOnlyJSONVal(it).asIntOrNull().shouldBeNull()528 }529 ReadOnlyJSONVal(null).asIntOrNull().shouldBeNull()530 }531 test("asIntOrDefault") {532 checkAll(JSONGenerators.intLikes * JSONGenerators.ints) { data ->533 ReadOnlyJSONVal(data.first).asIntOrDefault(data.second) shouldBe Conversions.toInt(data.first)!!534 }535 checkAll(JSONGenerators.nonIntLikes * JSONGenerators.ints) { data ->536 ReadOnlyJSONVal(data.first).asIntOrDefault(data.second) shouldBe data.second537 }538 checkAll(JSONGenerators.ints) {539 ReadOnlyJSONVal(null).asIntOrDefault(it) shouldBe it540 }541 }542 test("asIntOrZero") {543 checkAll(JSONGenerators.intLikes) {544 ReadOnlyJSONVal(it).asIntOrZero() shouldBe Conversions.toInt(it)!!545 }546 checkAll(JSONGenerators.nonIntLikes) {547 ReadOnlyJSONVal(it).asIntOrZero() shouldBe 0548 }549 ReadOnlyJSONVal(null).asIntOrZero() shouldBe 0550 }551 test("asIntOrOne") {552 checkAll(JSONGenerators.intLikes) {553 ReadOnlyJSONVal(it).asIntOrOne() shouldBe Conversions.toInt(it)!!554 }555 checkAll(JSONGenerators.nonIntLikes) {556 ReadOnlyJSONVal(it).asIntOrOne() shouldBe 1557 }558 ReadOnlyJSONVal(null).asIntOrOne() shouldBe 1559 }560 test("asIntOrMinusOne") {561 checkAll(JSONGenerators.intLikes) {562 ReadOnlyJSONVal(it).asIntOrMinusOne() shouldBe Conversions.toInt(it)!!563 }564 checkAll(JSONGenerators.nonIntLikes) {565 ReadOnlyJSONVal(it).asIntOrMinusOne() shouldBe -1566 }567 ReadOnlyJSONVal(null).asIntOrMinusOne() shouldBe -1568 }569 test("asIntOrElse") {570 checkAll(JSONGenerators.intLikes * JSONGenerators.ints) { data ->571 ReadOnlyJSONVal(data.first).asIntOrElse { data.second } shouldBe Conversions.toInt(data.first)!!572 }573 checkAll(JSONGenerators.nonIntLikes * JSONGenerators.ints) { data ->574 ReadOnlyJSONVal(data.first).asIntOrElse { data.second } shouldBe data.second575 }576 checkAll(JSONGenerators.ints) {577 ReadOnlyJSONVal(null).asIntOrElse { it } shouldBe it578 }579 }580 test("isLong") {581 checkAll(JSONGenerators.intLikes) {582 ReadOnlyJSONVal(it).isLong().shouldBeTrue()583 }584 checkAll(JSONGenerators.nonIntLikes) {585 ReadOnlyJSONVal(it).isLong().shouldBeFalse()586 }587 ReadOnlyJSONVal(null).isLong().shouldBeFalse()588 }589 test("asLongOrNull") {590 checkAll(JSONGenerators.intLikes) {591 ReadOnlyJSONVal(it).asLongOrNull() shouldBe Conversions.toLong(it)!!592 }593 checkAll(JSONGenerators.nonIntLikes) {594 ReadOnlyJSONVal(it).asLongOrNull().shouldBeNull()595 }596 ReadOnlyJSONVal(null).asLongOrNull().shouldBeNull()597 }598 test("asLongOrDefault") {599 checkAll(JSONGenerators.intLikes * JSONGenerators.longs) { data ->600 ReadOnlyJSONVal(data.first).asLongOrDefault(data.second) shouldBe Conversions.toLong(data.first)!!601 }602 checkAll(JSONGenerators.nonIntLikes * JSONGenerators.longs) { data ->603 ReadOnlyJSONVal(data.first).asLongOrDefault(data.second) shouldBe data.second604 }605 checkAll(JSONGenerators.longs) {606 ReadOnlyJSONVal(null).asLongOrDefault(it) shouldBe it607 }608 }609 test("asLongOrZero") {610 checkAll(JSONGenerators.intLikes) {611 ReadOnlyJSONVal(it).asLongOrZero() shouldBe Conversions.toLong(it)!!612 }613 checkAll(JSONGenerators.nonIntLikes) {614 ReadOnlyJSONVal(it).asLongOrZero() shouldBe 0L615 }616 ReadOnlyJSONVal(null).asLongOrZero() shouldBe 0L617 }618 test("asLongOrOne") {619 checkAll(JSONGenerators.intLikes) {620 ReadOnlyJSONVal(it).asLongOrOne() shouldBe Conversions.toLong(it)!!621 }622 checkAll(JSONGenerators.nonIntLikes) {623 ReadOnlyJSONVal(it).asLongOrOne() shouldBe 1L624 }625 ReadOnlyJSONVal(null).asLongOrOne() shouldBe 1L626 }627 test("asLongOrMinusOne") {628 checkAll(JSONGenerators.intLikes) {629 ReadOnlyJSONVal(it).asLongOrMinusOne() shouldBe Conversions.toLong(it)!!630 }631 checkAll(JSONGenerators.nonIntLikes) {632 ReadOnlyJSONVal(it).asLongOrMinusOne() shouldBe -1L633 }634 ReadOnlyJSONVal(null).asLongOrMinusOne() shouldBe -1L635 }636 test("asLongOrElse") {637 checkAll(JSONGenerators.intLikes * JSONGenerators.longs) { data ->638 ReadOnlyJSONVal(data.first).asLongOrElse { data.second } shouldBe Conversions.toLong(data.first)!!639 }640 checkAll(JSONGenerators.nonIntLikes * JSONGenerators.longs) { data ->641 ReadOnlyJSONVal(data.first).asLongOrElse { data.second } shouldBe data.second642 }643 checkAll(JSONGenerators.longs) {644 ReadOnlyJSONVal(null).asLongOrElse { it } shouldBe it645 }646 }647 test("isNumber") {648 checkAll(JSONGenerators.numberLikes) {649 ReadOnlyJSONVal(it).isNumber().shouldBeTrue()650 }651 checkAll(JSONGenerators.nonNumberLikes) {652 ReadOnlyJSONVal(it).isNumber().shouldBeFalse()653 }654 ReadOnlyJSONVal(null).isNumber().shouldBeFalse()655 }656 test("asNumberOrNull") {657 checkAll(JSONGenerators.numberLikes) {658 ReadOnlyJSONVal(it).asNumberOrNull() shouldBe Conversions.toNumber(it)!!659 }660 checkAll(JSONGenerators.nonNumberLikes) {661 ReadOnlyJSONVal(it).asNumberOrNull().shouldBeNull()662 }663 ReadOnlyJSONVal(null).asNumberOrNull().shouldBeNull()664 }665 test("asNumberOrDefault") {666 checkAll(JSONGenerators.numberLikes * JSONGenerators.floats) { data ->667 ReadOnlyJSONVal(data.first).asNumberOrDefault(data.second) shouldBe Conversions.toNumber(data.first)!!668 }669 checkAll(JSONGenerators.nonNumberLikes * JSONGenerators.floats) { data ->670 ReadOnlyJSONVal(data.first).asNumberOrDefault(data.second) shouldBe data.second671 }672 checkAll(JSONGenerators.floats) {673 ReadOnlyJSONVal(null).asNumberOrDefault(it) shouldBe it674 }675 }676 test("asNumberOrElse") {677 checkAll(JSONGenerators.numberLikes * JSONGenerators.floats) { data ->678 ReadOnlyJSONVal(data.first).asNumberOrElse { data.second } shouldBe Conversions.toNumber(data.first)!!679 }680 checkAll(JSONGenerators.nonNumberLikes * JSONGenerators.floats) { data ->681 ReadOnlyJSONVal(data.first).asNumberOrElse { data.second } shouldBe data.second682 }683 checkAll(JSONGenerators.floats) {684 ReadOnlyJSONVal(null).asNumberOrElse { it } shouldBe it685 }686 }687 test("isObject") {688 checkAll(JSONGenerators.objects) {689 ReadOnlyJSONVal(it).isObject().shouldBeTrue()690 }691 checkAll(JSONGenerators.nonObjects) {692 ReadOnlyJSONVal(it).isObject().shouldBeFalse()693 }694 ReadOnlyJSONVal(null).isObject().shouldBeFalse()695 }696 test("asObjectOrNull") {697 checkAll(JSONGenerators.objects) {698 ReadOnlyJSONVal(it).asObjectOrNull() shouldBeSimilarTo it699 }700 checkAll(JSONGenerators.nonObjects) {701 ReadOnlyJSONVal(it).asObjectOrNull().shouldBeNull()702 }703 ReadOnlyJSONVal(null).asObjectOrNull().shouldBeNull()704 }705 test("asObjectOrDefault") {706 checkAll(JSONGenerators.objects * JSONGenerators.objects) { data ->707 ReadOnlyJSONVal(data.first).asObjectOrDefault(data.second.asReadOnly()) shouldBeSimilarTo data.first708 }709 checkAll(JSONGenerators.nonObjects * JSONGenerators.objects) { data ->710 ReadOnlyJSONVal(data.first).asObjectOrDefault(data.second.asReadOnly()) shouldBeSimilarTo data.second711 }712 checkAll(JSONGenerators.objects) {713 ReadOnlyJSONVal(null).asObjectOrDefault(it.asReadOnly()) shouldBeSimilarTo it714 }715 }716 test("asObjectOrEmpty") {717 checkAll(JSONGenerators.objects) {718 ReadOnlyJSONVal(it).asObjectOrEmpty() shouldBeSimilarTo it719 }720 checkAll(JSONGenerators.nonObjects) {721 ReadOnlyJSONVal(it).asObjectOrEmpty() shouldBeSimilarTo ReadOnlyJSONObject.EMPTY722 }723 ReadOnlyJSONVal(null).asObjectOrEmpty() shouldBeSimilarTo ReadOnlyJSONObject.EMPTY724 }725 test("asObjectOrElse") {726 checkAll(JSONGenerators.objects * JSONGenerators.objects) { data ->727 ReadOnlyJSONVal(data.first).asObjectOrElse { data.second.asReadOnly() } shouldBeSimilarTo data.first728 }729 checkAll(JSONGenerators.nonObjects * JSONGenerators.objects) { data ->730 ReadOnlyJSONVal(data.first).asObjectOrElse { data.second.asReadOnly() } shouldBeSimilarTo data.second731 }732 checkAll(JSONGenerators.objects) {733 ReadOnlyJSONVal(null).asObjectOrElse { it.asReadOnly() } shouldBeSimilarTo it734 }735 }736 test("isString") {737 checkAll(JSONGenerators.allStrings) {738 ReadOnlyJSONVal(it).isString().shouldBeTrue()739 ReadOnlyJSONVal(it).isString(false).shouldBeTrue()740 ReadOnlyJSONVal(it).isString(true).shouldBeTrue()741 }742 checkAll(JSONGenerators.nonStrings) {743 ReadOnlyJSONVal(it).isString().shouldBeFalse()744 ReadOnlyJSONVal(it).isString(false).shouldBeFalse()745 ReadOnlyJSONVal(it).isString(true).shouldBeTrue()746 }747 ReadOnlyJSONVal(null).isString().shouldBeFalse()748 ReadOnlyJSONVal(null).isString(false).shouldBeFalse()749 ReadOnlyJSONVal(null).isString(true).shouldBeFalse()750 }751 test("asStringOrNull") {752 checkAll(JSONGenerators.allStrings) {753 ReadOnlyJSONVal(it).asStringOrNull() shouldBe it754 ReadOnlyJSONVal(it).asStringOrNull(false) shouldBe it755 ReadOnlyJSONVal(it).asStringOrNull(true) shouldBe it756 }757 checkAll(JSONGenerators.nonStrings) {758 ReadOnlyJSONVal(it).asStringOrNull().shouldBeNull()759 ReadOnlyJSONVal(it).asStringOrNull(false).shouldBeNull()760 ReadOnlyJSONVal(it).asStringOrNull(true) shouldBeSimilarStringAs it761 }762 ReadOnlyJSONVal(null).asStringOrNull().shouldBeNull()763 ReadOnlyJSONVal(null).asStringOrNull(false).shouldBeNull()764 ReadOnlyJSONVal(null).asStringOrNull(true).shouldBeNull()765 }766 test("asStringOrDefault") {767 checkAll(JSONGenerators.allStrings cross JSONGenerators.basicStrings) {768 ReadOnlyJSONVal(it.first).asStringOrDefault(it.second) shouldBe it.first769 ReadOnlyJSONVal(it.first).asStringOrDefault(it.second, false) shouldBe it.first770 ReadOnlyJSONVal(it.first).asStringOrDefault(it.second, true) shouldBe it.first771 }772 checkAll(JSONGenerators.nonStrings cross JSONGenerators.basicStrings) {773 ReadOnlyJSONVal(it.first).asStringOrDefault(it.second) shouldBe it.second774 ReadOnlyJSONVal(it.first).asStringOrDefault(it.second, false) shouldBe it.second775 ReadOnlyJSONVal(it.first).asStringOrDefault(it.second, true) shouldBe Conversions.toString(it.first, true)776 }777 checkAll(JSONGenerators.basicStrings) {778 ReadOnlyJSONVal(null).asStringOrDefault(it) shouldBe it779 ReadOnlyJSONVal(null).asStringOrDefault(it, false) shouldBe it780 ReadOnlyJSONVal(null).asStringOrDefault(it, true) shouldBe it781 }782 }783 test("asStringOrEmpty") {784 checkAll(JSONGenerators.allStrings) {785 ReadOnlyJSONVal(it).asStringOrEmpty() shouldBe it786 ReadOnlyJSONVal(it).asStringOrEmpty(false) shouldBe it787 ReadOnlyJSONVal(it).asStringOrEmpty(true) shouldBe it788 }789 checkAll(JSONGenerators.nonStrings) {790 ReadOnlyJSONVal(it).asStringOrEmpty().shouldBeEmpty()791 ReadOnlyJSONVal(it).asStringOrEmpty(false).shouldBeEmpty()792 ReadOnlyJSONVal(it).asStringOrEmpty(true) shouldBeSimilarStringAs it793 }794 ReadOnlyJSONVal(null).asStringOrEmpty().shouldBeEmpty()795 ReadOnlyJSONVal(null).asStringOrEmpty().shouldBeEmpty()796 ReadOnlyJSONVal(null).asStringOrEmpty().shouldBeEmpty()797 }798 test("asStringOrElse") {799 checkAll(JSONGenerators.allStrings cross JSONGenerators.basicStrings) {800 ReadOnlyJSONVal(it.first).asStringOrElse { it.second } shouldBe it.first801 ReadOnlyJSONVal(it.first).asStringOrElse({ it.second }, false) shouldBe it.first802 ReadOnlyJSONVal(it.first).asStringOrElse(false) { it.second } shouldBe it.first803 ReadOnlyJSONVal(it.first).asStringOrElse({ it.second }, true) shouldBe Conversions.toString(it.first, true)804 ReadOnlyJSONVal(it.first).asStringOrElse(true) { it.second } shouldBe Conversions.toString(it.first, true)805 }806 checkAll(JSONGenerators.nonStrings cross JSONGenerators.basicStrings) {807 ReadOnlyJSONVal(it.first).asStringOrElse { it.second } shouldBe it.second808 ReadOnlyJSONVal(it.first).asStringOrElse({ it.second }, false) shouldBe it.second809 ReadOnlyJSONVal(it.first).asStringOrElse(false) { it.second } shouldBe it.second810 ReadOnlyJSONVal(it.first).asStringOrElse({ it.second }, true) shouldBe Conversions.toString(it.first, true)811 ReadOnlyJSONVal(it.first).asStringOrElse(true) { it.second } shouldBe Conversions.toString(it.first, true)812 }...

Full Screen

Full Screen

FloatingBigRationalTest.kt

Source:FloatingBigRationalTest.kt Github

copy

Full Screen

...23import 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 @Test...

Full Screen

Full Screen

FzyFloatEqualityTest.kt

Source:FzyFloatEqualityTest.kt Github

copy

Full Screen

1package com.xrpn.order.fuzzy2import io.kotest.core.spec.style.FunSpec3import io.kotest.matchers.shouldBe4import io.kotest.property.Arb5import io.kotest.property.checkAll6import com.xrpn.order.fuzzy.FzyFloat.Companion.fzyEqual7import com.xrpn.order.fuzzy.FzyFloat.Companion.fzyIsZero8import com.xrpn.order.fuzzy.FzyFloat.Companion.asFzyFloat9import com.xrpn.order.fuzzy.FzyFloat.Companion.fzyIsUnity10import io.kotest.assertions.throwables.shouldThrow11import io.kotest.property.arbitrary.float12import io.kotest.property.arbitrary.numericFloats13class FzyFloatEqualityTest : FunSpec({14 beforeTest {15 }16 test("pathology") {17 Float.NaN.fzyEqual(1.0f) shouldBe false18 Float.NaN.fzyEqual(Float.NaN) shouldBe false19 Float.NaN.asFzyFloat().isZero() shouldBe false20 Float.POSITIVE_INFINITY.fzyEqual(Float.POSITIVE_INFINITY) shouldBe true21 Float.NEGATIVE_INFINITY.fzyEqual(Float.POSITIVE_INFINITY) shouldBe false22 Float.POSITIVE_INFINITY.fzyEqual(Float.NEGATIVE_INFINITY) shouldBe false23 Float.NEGATIVE_INFINITY.fzyEqual(Float.NEGATIVE_INFINITY) shouldBe true24 FzyFloat(Float.NaN).equals(Float.NaN) shouldBe false25 (FzyFloat(Float.NaN) == FzyFloat(Float.NaN)) shouldBe false26 FzyFloat(Float.POSITIVE_INFINITY).equals(Float.POSITIVE_INFINITY) shouldBe true27 FzyFloat(Float.NEGATIVE_INFINITY).equals(Float.POSITIVE_INFINITY) shouldBe false28 FzyFloat(Float.POSITIVE_INFINITY).equals(Float.NEGATIVE_INFINITY) shouldBe false29 FzyFloat(Float.NEGATIVE_INFINITY).equals(Float.NEGATIVE_INFINITY) shouldBe true30 Float.MAX_VALUE.fzyEqual(Float.MAX_VALUE) shouldBe true31 }32 test("zeroes") {33 val ff0 = FzyFloat(0.0f)34 val ff1 = FzyFloat(Float.MIN_VALUE)35 val ff2 = FzyFloat(-Float.MIN_VALUE)36 val ff3 = FzyFloat(1.0f)37 ff0.isZero() shouldBe true38 ff1.isZero() shouldBe true39 ff2.isZero() shouldBe true40 ff3.isZero() shouldBe false41 Float.MIN_VALUE.fzyIsZero() shouldBe true42 0.0f.fzyIsZero() shouldBe true43 (-Float.MIN_VALUE).fzyIsZero() shouldBe true44 1.0f.fzyIsZero() shouldBe false45 Float.NaN.fzyIsZero() shouldBe false46 Float.POSITIVE_INFINITY.fzyIsZero() shouldBe false47 Float.NEGATIVE_INFINITY.fzyIsZero() shouldBe false48 }49 test("unity") {50 val fd0 = FzyFloat(1.0f)51 val fd00 = FzyFloat(1.0f, floatEps, true)52 val fd1 = FzyFloat(1.0f+defaultFloatTol)53 val fd2 = FzyFloat(1.0f-defaultFloatTol)54 val fd3 = FzyFloat(1.0f+defaultFloatTol, 2.0f*defaultFloatTol)55 val fd4 = FzyFloat(1.0f-defaultFloatTol, 2.0f*defaultFloatTol)56 fd0.isUnity() shouldBe true57 fd00.isUnity() shouldBe true58 fd1.isUnity() shouldBe false59 fd2.isUnity() shouldBe false60 fd3.isUnity() shouldBe true61 fd4.isUnity() shouldBe true62 1.0f.fzyIsUnity() shouldBe true63 (1.0f+defaultFloatTol).fzyIsUnity() shouldBe false64 (1.0f-defaultFloatTol).fzyIsUnity() shouldBe false65 Float.NaN.fzyIsUnity() shouldBe false66 Float.NEGATIVE_INFINITY.fzyIsUnity() shouldBe false67 Float.POSITIVE_INFINITY.fzyIsUnity() shouldBe false68 }69 test("throw if defeated"){70 shouldThrow<IllegalArgumentException> {71 FzyFloat(1.0f, floatEps)72 }73 shouldThrow<IllegalArgumentException> {74 FzyFloat(1.0f, -0.0004f)75 }76 }77 test("bounds") {78 (FzyFloat(Float.MAX_VALUE) == FzyFloat(Float.MAX_VALUE)) shouldBe true79 (FzyFloat(-Float.MAX_VALUE) == FzyFloat(-Float.MAX_VALUE)) shouldBe true80 FzyFloat(Float.MAX_VALUE).equals(Float.MAX_VALUE) shouldBe true81 FzyFloat(-Float.MAX_VALUE).equals(-Float.MAX_VALUE) shouldBe true82 (FzyFloat(Float.MIN_VALUE) == FzyFloat(Float.MIN_VALUE)) shouldBe true83 (FzyFloat(Float.MIN_VALUE) == FzyFloat(-Float.MIN_VALUE)) shouldBe true84 (FzyFloat(-Float.MIN_VALUE) == FzyFloat(-Float.MIN_VALUE)) shouldBe true85 FzyFloat(Float.MIN_VALUE).equals(Float.MIN_VALUE) shouldBe true86 FzyFloat(Float.MIN_VALUE).equals(-Float.MIN_VALUE) shouldBe true87 FzyFloat(-Float.MIN_VALUE).equals(-Float.MIN_VALUE) shouldBe true88 Float.MAX_VALUE.fzyEqual(Float.MAX_VALUE) shouldBe true89 (-Float.MAX_VALUE).fzyEqual(-Float.MAX_VALUE) shouldBe true90 Float.MAX_VALUE.fzyEqual(FzyFloat(Float.MAX_VALUE)) shouldBe true91 (-Float.MAX_VALUE).fzyEqual(FzyFloat(-Float.MAX_VALUE)) shouldBe true92 Float.MIN_VALUE.fzyEqual(Float.MIN_VALUE) shouldBe true93 Float.MIN_VALUE.fzyEqual(-Float.MIN_VALUE) shouldBe true94 (-Float.MIN_VALUE).fzyEqual(-Float.MIN_VALUE) shouldBe true95 Float.MIN_VALUE.fzyEqual(FzyFloat(Float.MIN_VALUE)) shouldBe true96 Float.MIN_VALUE.fzyEqual(FzyFloat(-Float.MIN_VALUE)) shouldBe true97 (-Float.MIN_VALUE).fzyEqual(FzyFloat(-Float.MIN_VALUE)) shouldBe true98 }99 test("underflow") {100 (FzyFloat(Float.MAX_VALUE) == FzyFloat(1E-10f)) shouldBe false101 (FzyFloat(-Float.MAX_VALUE) == FzyFloat(-1E-10f)) shouldBe false102 FzyFloat(Float.MAX_VALUE).equals(1E-10f) shouldBe false103 FzyFloat(-Float.MAX_VALUE).equals(-1E-10f) shouldBe false104 }105 test("overflow") {106 (FzyFloat(1E-10f) == FzyFloat(Float.MAX_VALUE)) shouldBe false107 (FzyFloat(-1E-10f) == FzyFloat(-Float.MAX_VALUE)) shouldBe false108 FzyFloat(1E-10f).equals(Float.MAX_VALUE) shouldBe false109 FzyFloat(-1E-10f).equals(-Float.MAX_VALUE) shouldBe false110 }111 test("same zeroes") {112 val fd0a = FzyFloat.zero()113 val fd0b = FzyFloat.zero()114 val fd00 = FzyFloat.zero(defaultFloatTol*2.0f)115 val fd1 = FzyFloat.unity()116 FzyFloatEquality.isSameZeroes(fd0a, fd0a) shouldBe true117 FzyFloatEquality.isSameZeroes(fd0a, fd0b) shouldBe true118 FzyFloatEquality.isSameZeroes(fd0b, fd0a) shouldBe true119 FzyFloatEquality.isSameZeroes(fd0a, fd00) shouldBe false120 FzyFloatEquality.isSameZeroes(fd00, fd0a) shouldBe false121 FzyFloatEquality.isSameZeroes(fd0a, fd1) shouldBe false122 FzyFloatEquality.isSameZeroes(fd1, fd0a) shouldBe false123 }124 test("float properties, reflexive") {125 checkAll(Arb.float(), Arb.numericFloats()) { f1, f2 ->126 val ff1a = FzyFloat(f1)127 val ff1b = FzyFloat(f1)128 val ff2a = FzyFloat(f2)129 val ff2b = FzyFloat(f2)130 ff1a.equals(f1) shouldBe !f1.isNaN()131 ff1b.equals(f1) shouldBe !f1.isNaN()132 ff2a.equals(f2) shouldBe true133 ff2b.equals(f2) shouldBe true134 f1.fzyEqual(f1) shouldBe !f1.isNaN()135 f1.fzyEqual(ff1a) shouldBe !f1.isNaN()136 f1.fzyEqual(ff1b) shouldBe !f1.isNaN()137 ff1a.equals(f1) shouldBe !f1.isNaN()138 ff1b.equals(f1) shouldBe !f1.isNaN()139 (ff1a == ff1b) shouldBe !f1.isNaN()140 (ff1b == ff1a) shouldBe !f1.isNaN()141 ff2a.equals(f2) shouldBe true142 ff2b.equals(f2) shouldBe true143 (ff2a == ff2b) shouldBe true144 (ff2b == ff2a) shouldBe true145 }146 }147 test("float properties, symmetric") {148 checkAll(Arb.float(), Arb.numericFloats()) { f1, f2 ->149 val ff1 = FzyFloat(f1)150 val f1d = ff1.qty / (1.0f + (defaultFloatTol /2.0f))151 val ff1d = FzyFloat(f1d)152 val ff2 = FzyFloat(f2)153 val f2d = ff2.qty / (1.0f + (defaultFloatTol /2.0f))154 val ff2d = FzyFloat(f2d)155 (!ff1.equals(f1d) && f1.fzyIsZero()) shouldBe false156 (f1.fzyIsZero() && ff1 != ff1d) shouldBe false157 f1.fzyEqual(f1d) shouldBe !f1.isNaN()158 f1.fzyEqual(ff1d) shouldBe !f1.isNaN()159 f1d.fzyEqual(f1) shouldBe !f1.isNaN()160 f1d.fzyEqual(ff1) shouldBe !f1.isNaN()161 ff1.equals(f1d) shouldBe !f1.isNaN()162 (ff1d == ff1) shouldBe !f1.isNaN()163 ff1d.equals(f1) shouldBe !f1.isNaN()164 ff1.equals(f1d) shouldBe !f1.isNaN()165 (!ff2.equals(f2d) && f2.fzyIsZero()) shouldBe false166 (f2.fzyIsZero() && ff2 != ff2d) shouldBe false167 f2.fzyEqual(f2d) shouldBe true168 f2.fzyEqual(ff2d) shouldBe true169 f2d.fzyEqual(f2) shouldBe true170 f2d.fzyEqual(ff2) shouldBe true171 ff2.equals(f2d) shouldBe true172 (ff2d == ff2) shouldBe true173 ff2d.equals(f2) shouldBe true174 ff2.equals(f2d) shouldBe true175 }176 }177 test("float properties, transitive") {178 checkAll(Arb.float(), Arb.numericFloats()) { f1, f2 ->179 val ff1 = FzyFloat(f1)180 val f1a = f1 / (1.0f + (defaultFloatTol /1.7f))181 val ff1a = FzyFloat(f1a)182 val f1b = f1 / (1.0f + (defaultFloatTol /1.3f))183 val ff1b = FzyFloat(f1b)184 val ff2 = FzyFloat(f2)185 val f2a = f2 / (1.0f + (defaultFloatTol /1.9f))186 val ff2a = FzyFloat(f2a)187 val f2b = f2 / (1.0f + (defaultFloatTol /1.5f))188 val ff2b = FzyFloat(f2b)189 (!ff1.equals(f1a) && f1.fzyIsZero()) shouldBe false190 (f1.fzyIsZero() && ff1 != ff1a) shouldBe false191 (!ff1.equals(f1b) && f1.fzyIsZero()) shouldBe false...

Full Screen

Full Screen

FixedBigRationalTest.kt

Source:FixedBigRationalTest.kt Github

copy

Full Screen

...8import hm.binkley.math.fixed.FixedBigRational.Companion.ZERO9import hm.binkley.math.fixed.FixedBigRational.Companion.valueOf10import hm.binkley.math.floating.FloatingBigRational11import hm.binkley.math.rangeTo12import io.kotest.assertions.throwables.shouldThrow13import io.kotest.matchers.booleans.shouldBeFalse14import io.kotest.matchers.shouldBe15import io.kotest.matchers.shouldNotBe16import org.junit.jupiter.api.Nested17import org.junit.jupiter.api.Test18/**19 * NB -- the tests use a mixture of constructors while testing functionality.20 * This is intentional, and raises coverage.21 */22@Suppress("RedundantInnerClassModifier")23internal class FixedBigRationalTest {24 @Test25 fun `should not divide by 0 when constructing`() {26 shouldThrow<ArithmeticException> {27 (1 over 0)28 }29 }30 @Nested31 inner class ProgressionTests {32 @Test33 fun `should equate`() {...

Full Screen

Full Screen

FloatMatchersTest.kt

Source:FloatMatchersTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.matchers.floats2import io.kotest.core.spec.style.StringSpec3import io.kotest.matchers.floats.shouldBeExactly4import io.kotest.matchers.floats.shouldBeGreaterThan5import io.kotest.matchers.floats.shouldBeGreaterThanOrEqual6import io.kotest.matchers.floats.shouldBeLessThan7import io.kotest.matchers.floats.shouldBeLessThanOrEqual8import io.kotest.matchers.floats.shouldBeZero9import io.kotest.matchers.floats.shouldNotBeExactly10import io.kotest.matchers.floats.shouldNotBeGreaterThan11import io.kotest.matchers.floats.shouldNotBeGreaterThanOrEqual12import io.kotest.matchers.floats.shouldNotBeLessThan13import io.kotest.matchers.floats.shouldNotBeLessThanOrEqual14import io.kotest.matchers.floats.shouldNotBeZero15class FloatMatchersTest : StringSpec() {16 init {17 "shouldBeLessThan" {18 1f shouldBeLessThan 2f19 1.99999f shouldBeLessThan 2f20 Float.MIN_VALUE shouldBeLessThan Float.MAX_VALUE21 Float.NEGATIVE_INFINITY shouldBeLessThan Float.POSITIVE_INFINITY22 }23 "shouldBeLessThanOrEqual" {24 1f shouldBeLessThanOrEqual 2f25 1.5f shouldBeLessThanOrEqual 1.5f26 1f shouldBeLessThanOrEqual 1f27 2f shouldBeLessThanOrEqual 2f28 Float.MIN_VALUE shouldBeLessThanOrEqual Float.MAX_VALUE...

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

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

FloatMatchers.kt

Source:FloatMatchers.kt Github

copy

Full Screen

1package io.kotest.matchers.floats2import io.kotest.matchers.Matcher3import io.kotest.matchers.MatcherResult4import kotlin.math.abs5infix fun Float.plusOrMinus(tolerance: Float): FloatToleranceMatcher = FloatToleranceMatcher(this, tolerance)6class FloatToleranceMatcher(private val expected: Float, private val tolerance: Float) : Matcher<Float> {7 override fun test(value: Float): MatcherResult {8 return if (expected.isNaN() && value.isNaN()) {9 println("[WARN] By design, Float.Nan != Float.Nan; see https://stackoverflow.com/questions/8819738/why-does-double-nan-double-nan-return-false/8819776#8819776")10 MatcherResult(11 false,12 "By design, Float.Nan != Float.Nan; see https://stackoverflow.com/questions/8819738/why-does-double-nan-double-nan-return-false/8819776#8819776",13 "By design, Float.Nan != Float.Nan; see https://stackoverflow.com/questions/8819738/why-does-double-nan-double-nan-return-false/8819776#8819776"14 )15 } else {16 if (tolerance == 0.0F)17 println("[WARN] When comparing Float consider using tolerance, eg: a shouldBe b plusOrMinus c")18 val diff = abs(value - expected)19 MatcherResult(diff <= tolerance, "$value should be equal to $expected", "$value should not be equal to $expected")20 }21 }...

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1 import io.kotest.matchers.floats.NaN2 NaN.shouldBeNaN()3 import io.kotest.matchers.floats.NaN4 NaN.shouldNotBeNaN()5 import io.kotest.assertions.floats.NaN6 NaN.shouldBeNaN()7 import io.kotest.assertions.floats.NaN8 NaN.shouldNotBeNaN()9 import io.kotest.core.spec.style.scopes.NaN10 NaN.shouldBeNaN()11 import io.kotest.core.spec.style.scopes.NaN12 NaN.shouldNotBeNaN()13 import io.kotest.core.spec.style.scopes.NaN14 NaN.shouldBeNaN()15 import io.kotest.core.spec.style.scopes.NaN16 NaN.shouldNotBeNaN()

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1import io.kotest.matchers.floats.NaN2NaN.shouldBeNaN()3import io.kotest.matchers.floats.shouldNotBeNaN4shouldNotBeNaN()5import io.kotest.matchers.floats.shouldBeZero6shouldBeZero()7import io.kotest.matchers.floats.shouldNotBeZero8shouldNotBeZero()9import io.kotest.matchers.floats.shouldBePositive10shouldBePositive()11import io.kotest.matchers.floats.shouldBeNegative12shouldBeNegative()13import io.kotest.matchers.floats.shouldBeInRange14shouldBeInRange()15import io.kotest.matchers.floats.shouldNotBeInRange16shouldNotBeInRange()17import io.kotest.matchers.floats.shouldBeGreaterThan18shouldBeGreaterThan()19import io.kotest.matchers.floats.shouldBeGreaterThanOrEqual20shouldBeGreaterThanOrEqual()21import io.kotest.matchers.floats.shouldBeLessThan22shouldBeLessThan()23import io.kotest.matchers.floats.shouldBeLessThanOrEqual24shouldBeLessThanOrEqual()25import io.kotest.matchers.floats.shouldBeBetween26shouldBeBetween()27import

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1  fun `should be NaN`(){2    value should beNaN()3  }4}5import io.kotest.matchers.floats.*6import org.junit.jupiter.api.Test7class NaNTest{8  fun `should not be NaN`(){9    value shouldNot beNaN()10  }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