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

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

FixedBigRationalTest.kt

Source:FixedBigRationalTest.kt Github

copy

Full Screen

1package hm.binkley.math.fixed2import hm.binkley.math.BFixed3import hm.binkley.math.BFloating4import hm.binkley.math.big5import hm.binkley.math.compareTo6import hm.binkley.math.fixed.FixedBigRational.Companion.ONE7import hm.binkley.math.fixed.FixedBigRational.Companion.TEN8import 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`() {34 (ONE..TEN).equals(this).shouldBeFalse()35 (ONE..TEN) shouldNotBe36 FloatingBigRational.ONE..FloatingBigRational.TEN37 (ONE..TEN).hashCode() shouldNotBe38 (FloatingBigRational.ONE..FloatingBigRational.TEN).hashCode()39 }40 }41 @Nested42 inner class ConversionTests {43 @Test44 fun `should convert BigDecimal in infix constructor`() {45 0.0.big.toBigRational() shouldBe ZERO46 30.0.big.toBigRational() shouldBe (30 over 1)47 3.0.big.toBigRational() shouldBe (3 over 1)48 BFloating("0.3").toBigRational() shouldBe (3 over 10)49 BFloating("7.70").toBigRational() shouldBe (77 over 10)50 (1.0.big over 1.0.big) shouldBe ONE51 (1.big over 1.0.big) shouldBe ONE52 (1L over 1.0.big) shouldBe ONE53 (1 over 1.0.big) shouldBe ONE54 (1.0 over 1.0.big) shouldBe ONE55 (1.0f over 1.0.big) shouldBe ONE56 (1.0.big over 1L) shouldBe ONE57 (1.0.big over 1) shouldBe ONE58 }59 @Test60 fun `should convert BigInteger in infix constructor`() {61 0.big.toBigRational() shouldBe ZERO62 BFixed.valueOf(30L).toBigRational() shouldBe (30 over 1)63 3.big.toBigRational() shouldBe (3 over 1)64 (1.big over 1.big) shouldBe ONE65 (1.0.big over 1.big) shouldBe ONE66 (1L over 1.big) shouldBe ONE67 (1 over 1.big) shouldBe ONE68 (1.0 over 1.big) shouldBe ONE69 (1.0f over 1.big) shouldBe ONE70 (1.big over 1L) shouldBe ONE71 (1.big over 1) shouldBe ONE72 }73 @Test74 fun `should convert double in infix constructor`() {75 (1.0.big over 1.0) shouldBe ONE76 (1.big over 1.0) shouldBe ONE77 (1L over 1.0) shouldBe ONE78 (1 over 1.0) shouldBe ONE79 (1.0 over 1.0) shouldBe ONE80 (1.0f over 1.0) shouldBe ONE81 (1.0 over 1.big) shouldBe ONE82 (1.0 over 1L) shouldBe ONE83 (1.0 over 1) shouldBe ONE84 }85 @Test86 fun `should not convert non-finite doubles`() {87 shouldThrow<ArithmeticException> {88 valueOf(Double.NaN)89 }90 shouldThrow<ArithmeticException> {91 valueOf(Double.POSITIVE_INFINITY)92 }93 shouldThrow<ArithmeticException> {94 valueOf(Double.NEGATIVE_INFINITY)95 }96 }97 @Test98 fun `should convert float in infix constructor`() {99 (1.0.big over 1.0f) shouldBe ONE100 (1.big over 1.0f) shouldBe ONE101 (1L over 1.0f) shouldBe ONE102 (1 over 1.0f) shouldBe ONE103 (1.0 over 1.0f) shouldBe ONE104 (1.0f over 1.0f) shouldBe ONE105 (1.0f over 1.big) shouldBe ONE106 (1.0f over 1L) shouldBe ONE107 (1.0f over 1) shouldBe ONE108 }109 @Test110 fun `should convert integral types in infix constructor`() {111 (1L over 1) shouldBe ONE112 (1 over 1L) shouldBe ONE113 }114 @Test115 fun `should convert to and from big decimal`() {116 val decimals = listOf(117 -4.0,118 -3.0,119 -2.0,120 -1.0,121 -0.5,122 -0.3,123 -0.1,124 0.0,125 0.1,126 0.3,127 0.5,128 1.0,129 2.0,130 3.0,131 4.0,132 123.456133 ).map { it.toBigDecimal() }134 val rationals = listOf(135 -4 over 1,136 -3 over 1,137 -2 over 1,138 -1 over 1,139 -1 over 2,140 -3 over 10,141 -1 over 10,142 ZERO,143 1 over 10,144 3 over 10,145 1 over 2,146 ONE,147 2 over 1,148 3 over 1,149 4 over 1,150 15432 over 125151 )152 decimals.map {153 it.toBigRational()154 } shouldBe rationals155 rationals.map {156 it.toBigDecimal()157 } shouldBe decimals158 }159 @Test160 fun `should convert to and from double`() {161 val doubles = listOf(162 -4.0,163 -3.0,164 -2.0,165 -1.0,166 -0.5,167 -0.3,168 -0.1,169 0.0,170 0.1,171 0.3,172 0.5,173 1.0,174 2.0,175 3.0,176 4.0,177 123.456178 )179 val rationals = listOf(180 -4 over 1,181 -3 over 1,182 -2 over 1,183 -1 over 1,184 -1 over 2,185 -3 over 10,186 -1 over 10,187 ZERO,188 1 over 10,189 3 over 10,190 1 over 2,191 ONE,192 2 over 1,193 3 over 1,194 4 over 1,195 15432 over 125196 )197 doubles.map {198 it.toBigRational()199 } shouldBe rationals200 rationals.map {201 it.toDouble()202 } shouldBe doubles203 }204 @Test205 fun `should convert to and from float`() {206 val floats = listOf(207 -4.0f,208 -3.0f,209 -2.0f,210 -1.0f,211 -0.5f,212 -0.3f,213 -0.1f,214 0.0f,215 0.1f,216 0.3f,217 0.5f,218 1.0f,219 2.0f,220 3.0f,221 4.0f,222 123.456f223 )224 val rationals = listOf(225 -4 over 1,226 -3 over 1,227 -2 over 1,228 -1 over 1,229 -1 over 2,230 -3 over 10,231 -1 over 10,232 ZERO,233 1 over 10,234 3 over 10,235 1 over 2,236 ONE,237 2 over 1,238 3 over 1,239 4 over 1,240 15432 over 125241 )242 floats.map {243 it.toBigRational()244 } shouldBe rationals245 rationals.map {246 it.toFloat()247 } shouldBe floats248 }249 @Test250 fun `should convert to floating equivalent`() {251 ONE.toFloatingBigRational() shouldBe FloatingBigRational.ONE252 }253 }254 @Nested255 inner class FunctionTests {256 @Test257 fun `should compare other number types`() {258 shouldThrow<ArithmeticException> {259 Double.POSITIVE_INFINITY > ZERO260 }261 shouldThrow<ArithmeticException> {262 ZERO < Double.POSITIVE_INFINITY263 }264 shouldThrow<ArithmeticException> {265 ZERO > Double.NEGATIVE_INFINITY266 }267 shouldThrow<ArithmeticException> {268 Double.NEGATIVE_INFINITY < ZERO269 }270 shouldThrow<ArithmeticException> {271 Float.NaN > ZERO272 }273 shouldThrow<ArithmeticException> {274 ZERO < Float.NaN275 }276 }277 @Test278 fun `should multiplicatively invert`() {279 shouldThrow<ArithmeticException> {280 ZERO.unaryDiv()281 }282 }283 }284}...

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

IntersectionSpec.kt

Source:IntersectionSpec.kt Github

copy

Full Screen

1package test.model2import io.kotest.core.spec.style.FunSpec3import io.kotest.data.forAll4import io.kotest.data.headers5import io.kotest.data.row6import io.kotest.data.table7import io.kotest.matchers.booleans.shouldBeFalse8import io.kotest.matchers.booleans.shouldBeTrue9import io.kotest.matchers.doubles.shouldBeGreaterThan10import io.kotest.matchers.doubles.shouldBeLessThan11import io.kotest.matchers.shouldBe12import krater.geometry.*13import krater.model.*14import krater.model.shapes.Plane15import krater.model.shapes.Sphere16import krater.model.shapes.Triangle17import kotlin.math.sqrt18class IntersectionSpec : FunSpec({19 val root2by2 = sqrt(2.0) / 2.020 val glassSphere = Sphere(material = Material(transparency = 1.0, refractiveIndex = 1.5))21 test("An intersection encapsulates t and object") {22 val s = Sphere()23 val i = Intersection(3.5, s)24 i.t.shouldBe(3.5)25 i.shape.shouldBe(s)26 }27 test("The hit when all intersections have positive t") {28 val s = Sphere()29 val i1 = Intersection(1.0, s)30 val i2 = Intersection(2.0, s)31 val xs = listOf(i1, i2)32 val i = xs.hit()33 i.shouldBe(i1)34 }35 test("The hit when some intersections have negative t") {36 val s = Sphere()37 val i1 = Intersection(-1.0, s)38 val i2 = Intersection(1.0, s)39 val xs = listOf(i1, i2)40 val i = xs.hit()41 i.shouldBe(i2)42 }43 test("The hit when all intersections have negative t") {44 val s = Sphere()45 val i1 = Intersection(-2.0, s)46 val i2 = Intersection(-1.0, s)47 val xs = listOf(i1, i2)48 val i = xs.hit()49 i.shouldBe(NO_INTERSECTION)50 }51 test("The hit is always the lowest non-negative intersection") {52 val s = Sphere()53 val i1 = Intersection(5.0, s)54 val i2 = Intersection(7.0, s)55 val i3 = Intersection(-3.0, s)56 val i4 = Intersection(2.0, s)57 val xs = listOf(i1, i2, i3, i4)58 val i = xs.hit()59 i.shouldBe(i4)60 }61 test("Pre-computing the state of an intersection") {62 val r = Ray(point(0, 0, -5), vector(0, 0, 1))63 val shape = Sphere()64 val i = Intersection(4.0, shape)65 val comps = PreparedComputation(i, r)66 comps.intersection.shouldBe(i)67 comps.point.shouldBe(point(0, 0, -1))68 comps.eyev.shouldBe(vector(0, 0, -1))69 comps.normalv.shouldBe(vector(0, 0, -1))70 }71 test("The hit, when an intersection occurs on the outside") {72 val r = Ray(point(0, 0, -5), vector(0, 0, 1))73 val shape = Sphere()74 val i = Intersection(4.0, shape)75 val comps = PreparedComputation(i, r)76 comps.inside.shouldBeFalse()77 }78 test("The hit, when an intersection occurs on the inside") {79 val r = Ray(point(0, 0, 0), vector(0, 0, 1))80 val shape = Sphere()81 val i = Intersection(1.0, shape)82 val comps = PreparedComputation(i, r)83 comps.point.shouldBe(point(0, 0, 1))84 comps.eyev.shouldBe(vector(0, 0, -1))85 comps.inside.shouldBeTrue()86 comps.normalv.shouldBe(vector(0, 0, -1))87 }88 test("Recomputing the reflection vector") {89 val shape = Plane()90 val r = Ray(point(0, 1, -1), vector(0, -root2by2, root2by2))91 val i = Intersection(sqrt(2.0), shape)92 val comps = PreparedComputation(i, r)93 comps.reflectv.shouldBe(vector(0, root2by2, root2by2))94 }95 test("Finding n1 and n2 at various intersections") {96 table(97 headers("index", "n1", "n2"),98 row(0, 1.0, 1.5),99 row(1, 1.5, 2.0),100 row(2, 2.0, 2.5),101 row(3, 2.5, 2.5),102 row(4, 2.5, 1.5),103 row(5, 1.5, 1.0),104 ).forAll { index, n1, n2 ->105 val a = Sphere(106 material = Material(transparency = 1.0, refractiveIndex = 1.5),107 transform = scaling(2, 2, 2)108 )109 val b = Sphere(110 material = Material(transparency = 1.0, refractiveIndex = 2.0),111 transform = translation(0, 0, -0.25)112 )113 val c = Sphere(114 material = Material(transparency = 1.0, refractiveIndex = 2.5),115 transform = translation(0, 0, 0.25)116 )117 val r = Ray(point(0, 0, -4), vector(0, 0, 1))118 val xs = listOf(119 Intersection(2.0, a),120 Intersection(2.75, b),121 Intersection(3.25, c),122 Intersection(4.75, b),123 Intersection(5.25, c),124 Intersection(6.0, a),125 )126 val comps = PreparedComputation(xs[index], r, xs)127 comps.n1.shouldBe(n1)128 comps.n2.shouldBe(n2)129 }130 }131 test("The under point is offset below the surface") {132 val r = Ray(point(0, 0, -5), vector(0, 0, 1))133 val shape = Sphere(material = Material(transparency = 1.0, refractiveIndex = 1.5), transform = translation(0, 0, 1))134 val i = Intersection(5.0, shape)135 val xs = listOf(i)136 val comps = PreparedComputation(i, r, xs)137 comps.underPoint.z.shouldBeGreaterThan(EPSILON / 2)138 comps.point.z.shouldBeLessThan(comps.underPoint.z)139 }140 test("The Schlick approximation under total internal reflection") {141 val shape = glassSphere142 val r = Ray(point(0, 0, root2by2), vector(0, 1, 0))143 val xs = listOf(Intersection(-root2by2, shape), Intersection(root2by2, shape))144 val comps = PreparedComputation(xs[1], r, xs)145 comps.schlickReflectance.shouldBe(1.0)146 }147 test("The Schlick approximation with a perpendicular viewing angle") {148 val shape = glassSphere149 val r = Ray(point(0, 0, 0), vector(0, 1, 0))150 val xs = listOf(Intersection(-1.0, shape), Intersection(1.0, shape))151 val comps = PreparedComputation(xs[1], r, xs)152 comps.schlickReflectance.near(0.04)shouldBe(true)153 }154 test("The Schlick approximation with small angle and n2 > n1") {155 val shape = glassSphere156 val r = Ray(point(0, 0.99, -2), vector(0, 0, 1))157 val xs = listOf(Intersection(1.8589, shape))158 val comps = PreparedComputation(xs[0], r, xs)159 comps.schlickReflectance.near(0.48873).shouldBe(true)160 }161 test("An intersection can encapsulate u and v") {162 val s = Triangle(point(0, 1, 0), point(-1, 0, 0), point(1, 0, 0))163 val i = Intersection(3.5, s, u = 0.2, v = 0.4)164 i.u.shouldBe(0.2)165 i.v.shouldBe(0.4)166 }167})...

Full Screen

Full Screen

DoublesSpec.kt

Source:DoublesSpec.kt Github

copy

Full Screen

...3import io.kotest.matchers.should4import io.monkeypatch.kaval.core.validator.Doubles.inRange5import io.monkeypatch.kaval.core.validator.Doubles.negative6import io.monkeypatch.kaval.core.validator.Doubles.positive7import io.monkeypatch.kaval.core.validator.Doubles.strictlyNegative8import io.monkeypatch.kaval.core.validator.Doubles.strictlyPositive9import io.monkeypatch.kaval.kotlintest.beInvalidWithReason10import io.monkeypatch.kaval.kotlintest.beValid11class DoublesSpec : DescribeSpec() {12 init {13 describe("inRange") {14 val validator = inRange((5.0)..(10.0))15 it("inRange should reject a lower number") {16 val result = validator(0.0)17 result should beInvalidWithReason(18 "requires to be in range 5.0..10.0, got 0.0"19 )20 }21 it("inRange should reject a higher number") {22 val result = validator(42.0)23 result should beInvalidWithReason(24 "requires to be in range 5.0..10.0, got 42.0"25 )26 }27 it("inRange should accept value lower bound") {28 val result = validator(5.0)29 result should beValid()30 }31 it("inRange should accept in range") {32 val result = validator(10.0)33 result should beValid()34 }35 it("inRange should accept value upper bound") {36 val result = validator(7.0)37 result should beValid()38 }39 }40 describe("strictlyPositive") {41 val validator = strictlyPositive42 it("strictlyPositive should reject a negative number") {43 val result = validator(-1.0)44 result should beInvalidWithReason(45 "requires to be strictly positive"46 )47 }48 it("strictlyPositive should reject zero") {49 val result = validator(0.0)50 result should beInvalidWithReason(51 "requires to be strictly positive"52 )53 }54 it("strictlyPositive should accept a positive number") {55 val result = validator(5.0)56 result should beValid()57 }58 }59 describe("positive") {60 val validator = positive61 it("positive should reject a negative number") {62 val result = validator(-1.0)63 result should beInvalidWithReason(64 "requires to be positive"65 )66 }67 it("positive should reject zero") {68 val result = validator(0.0)69 result should beValid()70 }71 it("positive should accept a positive number") {72 val result = validator(5.0)73 result should beValid()74 }75 }76 describe("strictlyNegative") {77 val validator = strictlyNegative78 it("strictlyNegative should reject a positive number") {79 val result = validator(1.0)80 result should beInvalidWithReason(81 "requires to be strictly negative"82 )83 }84 it("strictlyNegative should reject zero") {85 val result = validator(0.0)86 result should beInvalidWithReason(87 "requires to be strictly negative"88 )89 }90 it("strictlyNegative should accept a negative number") {91 val result = validator(-5.0)92 result should beValid()93 }94 }95 describe("negative") {96 val validator = negative97 it("negative should reject a postive number") {98 val result = validator(1.0)99 result should beInvalidWithReason(100 "requires to be negative"101 )102 }103 it("negative should reject zero") {104 val result = validator(0.0)...

Full Screen

Full Screen

BLEDistanceUnscentedKalmanFilterTest.kt

Source:BLEDistanceUnscentedKalmanFilterTest.kt Github

copy

Full Screen

1package uk.nhs.riskscore.internal2import io.kotest.core.spec.style.StringSpec3import io.kotest.matchers.booleans.shouldBeTrue4import io.kotest.matchers.doubles.shouldBeGreaterThanOrEqual5import io.kotest.matchers.ints.shouldBeExactly6import io.kotest.property.arbitrary.orNull7import io.kotest.property.checkAll8import uk.nhs.riskscore.internal.kotest.bleDistanceUnscentedKalmanFilter9import uk.nhs.riskscore.internal.kotest.nonEmptyList10import uk.nhs.riskscore.internal.kotest.smallNumericDoubles11import uk.nhs.riskscore.internal.kotest.smallPositiveDoubles12internal class BLEDistanceUnscentedKalmanFilterTest : StringSpec({13 "transition function is non-negative" {14 checkAll(15 smallNumericDoubles,16 smallNumericDoubles,17 bleDistanceUnscentedKalmanFilter) { state, noise, filter ->18 val result = filter.transitionFunction(state, noise)19 result shouldBeGreaterThanOrEqual 0.020 }21 }22 "smooth function returns the same number of elements as the input" {23 checkAll(24 100,25 bleDistanceUnscentedKalmanFilter,26 smallPositiveDoubles.orNull(0.1).nonEmptyList(2)27 ) { filter, attenutations ->28 filter.smooth(attenutations).size shouldBeExactly attenutations.size29 }30 }31 "smooth function returns finite results" {32 checkAll(33 100,34 bleDistanceUnscentedKalmanFilter,35 smallPositiveDoubles.orNull(0.1).nonEmptyList(2)36 ) { filter, attenutations ->37 filter.smooth(attenutations).all { (mean, covariance) ->38 mean.isFinite() && covariance.isFinite()39 }.shouldBeTrue()40 }41 }42})...

Full Screen

Full Screen

BmiEnglishUnitsTest.kt

Source:BmiEnglishUnitsTest.kt Github

copy

Full Screen

1package pl.mprzymus.bmi.bmi_count2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.core.spec.style.FunSpec4import io.kotest.matchers.doubles.plusOrMinus5import io.kotest.matchers.shouldBe6class BmiEnglishUnitsTest : FunSpec({7 val tested = BmiEnglishUnits()8 test("should count BMI properly with good input") {9 tested.countBmi(85.0, 200.0) shouldBe (19.55 plusOrMinus 0.1)10 }11 test("BMI should be 0 when weight is 0") {12 tested.countBmi(180.0, 0.0) shouldBe 0.013 }14 test("should return infinity when height is 0") {15 tested.countBmi(0.0, 70.0) shouldBe Double.POSITIVE_INFINITY16 }17 test("should throw when get negative height") {18 shouldThrow <IllegalArgumentException> { tested.countBmi(-1.0, 10.0) }19 }20})...

Full Screen

Full Screen

BmiMetricTest.kt

Source:BmiMetricTest.kt Github

copy

Full Screen

1package pl.mprzymus.bmi.bmi_count2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.core.spec.style.FunSpec4import io.kotest.matchers.doubles.plusOrMinus5import io.kotest.matchers.shouldBe6class BmiMetricTest : FunSpec({7 val tested = BmiMetric()8 test("should count BMI properly with good input") {9 tested.countBmi(180.0, 70.0) shouldBe (21.55 plusOrMinus 0.1)10 }11 test("BMI should be 0 when weight is 0") {12 tested.countBmi(180.0, 0.0) shouldBe 0.013 }14 test("should return infinity when height is 0") {15 tested.countBmi(0.0, 70.0) shouldBe Double.POSITIVE_INFINITY16 }17 test("should throw when get negative height") {18 shouldThrow <IllegalArgumentException> { tested.countBmi(-1.0, 10.0) }19 }20})...

Full Screen

Full Screen

SquareTest.kt

Source:SquareTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.example.allure2import io.kotest.core.spec.style.FunSpec3import io.kotest.matchers.doubles.shouldBeExactly4import kotlin.math.pow5class SquareTest : FunSpec({6 test("positive square") {7 2.0.pow(2.0) shouldBeExactly 4.08 4.0.pow(2.0) shouldBeExactly 16.09 9.0.pow(2.0) shouldBeExactly 81.010 }11 test("negative square") {12 (-2.0).pow(2.0) shouldBeExactly 4.013 (-4.0).pow(2.0) shouldBeExactly 16.014 (-9.0).pow(2.0) shouldBeExactly 81.015 }16})...

Full Screen

Full Screen

Negative

Using AI Code Generation

copy

Full Screen

1 import io.kotest.matchers.doubles.*2 import io.kotest.matchers.floats.*3 import io.kotest.matchers.ints.*4 import io.kotest.matchers.longs.*5 import io.kotest.matchers.shorts.*6 import io.kotest.matchers.strings.*7 import io.kotest.matchers.types.*8 import io.kotest.matchers.uuids.*9You can also import all the matchers in one go:10 import io.kotest.matchers.*11 import io.kotest.matchers.ints.*12 import io.kotest.matchers.longs.*13 import io.kotest.matchers.shorts.*14 import io.kotest.matchers.floats.*15 import io.kotest.matchers.doubles.*16 import io.kotest.matchers.booleans.*17 import io.kot

Full Screen

Full Screen

Negative

Using AI Code Generation

copy

Full Screen

1 import io.kotest.matchers.doubles.*2 import io.kotest.matchers.ints.*3 import io.kotest.matchers.longs.*4 import io.kotest.matchers.shorts.*5 import io.kotest.matchers.strings.*6 import io.kotest.matchers.throwable.*7 import io.kotest.matchers.types.*8 import io.kotest.matchers.uri.*9 import io.kotest.matchers.version.*10 import io.kotest.matchers.xml.*11 import io.kotest.matchers.collections.*12 import io.kotest.matchers.comparables.*13 import io.kotest.matchers.doubles.*14 import io.kotest.matchers.ints.*15 import io.kotest.matchers.longs.*16 import io.kotest.matchers.shorts.*17 import io.kotest.matchers.strings.*18 import io.kotest.matchers.throwable.*

Full Screen

Full Screen

Negative

Using AI Code Generation

copy

Full Screen

1 import io.kotest.matchers.doubles.*2 import io.kotest.matchers.doubles.*3 import io.kotest.matchers.doubles.*4 import io.kotest.matchers.doubles.*5 import io.kotest.matchers.doubles.*6 import io.kotest.matchers.doubles.*7 import io.kotest.matchers.doubles.*

Full Screen

Full Screen

Negative

Using AI Code Generation

copy

Full Screen

1+should("be negative") {2+ -0.1 shouldBe negative()3+}4+should("be positive") {5+ 0.1 shouldBe positive()6+}7+should("be zero") {8+ 0.0 shouldBe zero()9+}10+should("be close to") {11+ 0.1 shouldBe closeTo(0.11, 0.01)12+ 0.1 shouldBe closeTo(0.11, 0.01)13+}14+should("be greater than") {15+ 0.1 shouldBe greater(0.01)16+ 0.1 shouldBe greater(0.01)17+}18+should("be greater than or equal") {19+ 0.1 shouldBe greaterOrEqual(0.1)20+ 0.1 shouldBe greaterOrEqual(0.1)21+}22+should("be less than") {23+ 0.1 shouldBe less(0.2)24+ 0.1 shouldBe less(0.2)25+}26+should("be less than or equal") {27+ 0.1 shouldBe lessOrEqual(0.1)28+ 0.1 shouldBe lessOrEqual(0.1)29+}30+should("be in range") {31+ 0.1 shouldBe inRange(0.0..1.0)32+ 0.1 shouldBe inRange(0.0..1.0)33+}

Full Screen

Full Screen

Negative

Using AI Code Generation

copy

Full Screen

1import io.kotest.matchers.doubles.*2import io.kotest.matchers.doubles.*3import io.kotest.matchers.doubles.*4import io.kotest.matchers.doubles.*5import io.kotest.matchers.doubles.*6import io.kotest.matchers.doubles.*7import io.kotest.matchers.doubles.*8import io.kotest.matchers.doubles.*9import io.kotest.matchers.doubles.*

Full Screen

Full Screen

Negative

Using AI Code Generation

copy

Full Screen

1+import io.kotest.matchers.doubles.*2 class SimpleTest {3@@ -17,8 +18,8 @@ class SimpleTest {4 val collection = listOf(1, 2, 3)5 collection.shouldContain(1)6- collection.shouldHaveSize(3)7- collection.shouldBeEmpty()8+ collection.shouldHaveSize(4)9+ collection.shouldBeEmpty()10 }11-import io.kotest.matchers.shouldBe12+import io.kotest.matchers.doubles.*13 import org.junit.jupiter.api.Test14 class CalculatorTest {15@@ -7,7 +7,7 @@ class CalculatorTest {16 fun `addition of two numbers`() {17- calculator.add(1, 2).shouldBe(3)18+ calculator.add(1, 2).shouldBe(4)19 }20-import io.kotest.matchers.shouldBe21+import io.kotest.matchers.ints.*22 import org.junit.jupiter.api.Test23 class PersonTest {24@@ -7,7 +7,7 @@ class PersonTest {25 fun `get person name`() {26- person.name.shouldBe("John")27+ person.name.shouldBe("John ")28 }

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