Best Kotest code snippet using io.kotest.matchers.collections.bounds.test
PersistentListTest.kt
Source:PersistentListTest.kt
...11import com.github.whyrising.y.toPlist12import com.github.whyrising.y.util.HASH_PRIME13import com.github.whyrising.y.util.Murmur314import com.github.whyrising.y.v15import io.kotest.assertions.throwables.shouldThrow16import io.kotest.assertions.throwables.shouldThrowExactly17import io.kotest.core.spec.style.FreeSpec18import io.kotest.matchers.booleans.shouldBeFalse19import io.kotest.matchers.booleans.shouldBeTrue20import io.kotest.matchers.ints.shouldBeExactly21import io.kotest.matchers.nulls.shouldBeNull22import io.kotest.matchers.nulls.shouldNotBeNull23import io.kotest.matchers.shouldBe24import io.kotest.matchers.types.shouldBeSameInstanceAs25import io.kotest.property.checkAll26class PersistentListTest : FreeSpec({27 "PersistentList" - {28 "invoke() should return Empty list" {29 val emptyList = PersistentList<Int>()30 emptyList shouldBe Empty31 }32 "invoke(vararg) should return a PersistentList.Cons list" {33 val list = PersistentList(1, 2, 3, 4)34 list.count shouldBeExactly 435 list.first() shouldBeExactly 136 }37 "conj() should return a persistent list of 1 element" {38 val list = PersistentList(1, 2, 3, 4)39 val r = list.conj(5)...
HistogramTests.kt
Source:HistogramTests.kt
1package dev.evo.elasticmagic.aggs2import dev.evo.elasticmagic.query.Sort3import io.kotest.assertions.throwables.shouldThrow4import io.kotest.matchers.shouldBe5import io.kotest.matchers.collections.shouldBeEmpty6import io.kotest.matchers.collections.shouldHaveSize7import io.kotest.matchers.maps.shouldContainExactly8import kotlinx.datetime.LocalDate9import kotlin.test.Test10class HistogramTests : TestAggregation() {11 @Test12 fun histogram() {13 HistogramAgg(MovieDoc.rating, interval = 10F).let { agg ->14 agg.compile() shouldContainExactly mapOf(15 "histogram" to mapOf(16 "field" to "rating",17 "interval" to 10.0F,18 )19 )20 shouldThrow<IllegalStateException> {21 process(agg, emptyMap())22 }23 process(...
EvolutionaryExtensionsTest.kt
Source:EvolutionaryExtensionsTest.kt
1package pl.edu.agh.kemo.tools2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.core.spec.style.StringSpec4import io.kotest.inspectors.forAll5import io.kotest.matchers.collections.shouldContainAll6import io.kotest.matchers.collections.shouldHaveSize7import io.kotest.matchers.doubles.plusOrMinus8import io.kotest.matchers.shouldBe9import io.kotest.matchers.shouldNotBe10import org.moeaframework.analysis.collector.Accumulator11import org.moeaframework.core.Population12import org.moeaframework.core.Solution13import org.moeaframework.core.variable.RealVariable14import java.lang.IndexOutOfBoundsException15class EvolutionaryExtensionsTest : StringSpec({16 "choose random elements from a list" {17 // given18 val elements = listOf(1, 2, 3, 4, 5)19 // when20 val sampled = elements.sample(3)21 // then22 println(sampled)23 sampled.size shouldBe 3...
GroupSpec.kt
Source:GroupSpec.kt
1package test.model.shapes2import io.kotest.core.spec.style.FunSpec3import io.kotest.matchers.collections.shouldBeEmpty4import io.kotest.matchers.collections.shouldContain5import io.kotest.matchers.nulls.shouldBeNull6import io.kotest.matchers.nulls.shouldNotBeNull7import io.kotest.matchers.shouldBe8import io.kotest.matchers.types.shouldBeInstanceOf9import krater.geometry.*10import krater.model.shapes.Group11import krater.model.Ray12import krater.model.shapes.BoundingBox13import krater.model.shapes.Cylinder14import krater.model.shapes.Sphere15import kotlin.math.PI16class GroupSpec : FunSpec({17 test("Creating a group") {18 val g = Group()19 g.transform.shouldBe(IDENTITY_4X4_MATRIX)20 }21 test("Adding a child to a group") {22 val s = TestShape()23 val g = Group(shapes = listOf(s))24 g.shapes.shouldContain(s)25 s.parent.shouldBe(g)26 }27 test("Intersecting a ray with an empty group") {28 val g = Group()29 val r = Ray(point(0, 0, 0), vector(0, 0, 1))30 val xs = g.localIntersect(r)31 xs.shouldBeEmpty()32 }33 test("Intersecting a ray with a non-empty group") {34 val s1 = Sphere()35 val s2 = Sphere(transform = translation(0, 0, -3))36 val s3 = Sphere(transform = translation(5, 0, 0))37 val g = Group(shapes = listOf(s1, s2, s3))38 val r = Ray(point(0, 0, -5), vector(0, 0, 1))39 val xs = g.localIntersect(r)40 xs.size.shouldBe(4)41 xs[0].shape.shouldBe(s2)42 xs[1].shape.shouldBe(s2)43 xs[2].shape.shouldBe(s1)44 xs[3].shape.shouldBe(s1)45 }46 test("Intersecting a transformed group") {47 val s = Sphere(transform = translation(5, 0, 0))48 val g = Group(shapes = listOf(s), transform = scaling(2, 2, 2))49 val r = Ray(point(10, 0, -10), vector(0, 0, 1))50 val xs = g.intersect(r)51 xs.size.shouldBe(2)52 }53 test("A group has a bounding box that contains its children") {54 val s = Sphere(transform = translation(2, 5, -3) * scaling(2, 2, 2))55 val c = Cylinder(minimum = -2.0, maximum = 2.0, transform = translation(-4, -1, 4) * scaling(0.5, 1, 0.5))56 val shape = Group(shapes = listOf(s, c))57 shape.boundingBox.min.shouldBe(point(-4.5, -3, -5))58 shape.boundingBox.max.shouldBe(point(4, 7, 4.5))59 }60 test("Intersecting ray+group doesn't test children if box is missed") {61 val child = TestShape()62 val shape = Group(shapes = listOf(child))63 val r = Ray(point(0, 0, -5), vector(0, 1, 0))64 val xs = shape.intersect(r)65 child.savedRay.shouldBeNull()66 }67 test("Intersecting ray+group tests children if box is hit") {68 val child = TestShape()69 val shape = Group(shapes = listOf(child))70 val r = Ray(point(0, 0, -5), vector(0, 0, 1))71 val xs = shape.intersect(r)72 child.savedRay.shouldNotBeNull()73 }74 test("Parent bounding box of an empty transformed group is empty") {75 val group = Group(transform = rotationX(PI / 4))76 group.parentSpaceBounds.shouldBe(BoundingBox())77 }78 test("Partitioning a group into sub-groups") {79 val s1 = Sphere(transform = translation(-2, 0, 0))80 val s2 = Sphere(transform = translation(2, 0, 0))81 val s3 = Sphere()82 val transform = rotationX(PI /4)83 val g = Group(shapes = listOf(s1, s2, s3), transform = transform)84 val partitioned = g.partition()85 partitioned.transform.shouldBe(transform)86 val (left, right, remainder) = partitioned.shapes87 left as Group88 right as Group89 remainder as Group90 left.shapes.shouldBe(listOf(s1))91 right.shapes.shouldBe(listOf(s2))92 remainder.shapes.shouldBe(listOf(s3))93 }94 test("Subdividing a group partitions its children") {95 val s1 = Sphere(transform = translation(-2, -2, 0))96 val s2 = Sphere(transform = translation(-2, 2, 0))97 val s3 = Sphere(transform = scaling(4, 4, 4))98 val g = Group(shapes = listOf(s1, s2, s3), transform = rotationX(PI / 4))99 val divide1 = g.divide(1) as Group100 divide1.shapes.forEach { println(it) }101 divide1.transform.shouldBe(g.transform)102 divide1.shapes.size.shouldBe(2)103 divide1.shapes.forEach { it.shouldBeInstanceOf<Group>() }104 divide1.shapes.map {105 it as Group106 it.shapes.size107 }.sum().shouldBe(3)108 val divide3 = g.divide(3) as Group...
SignTest.kt
Source:SignTest.kt
1package land.vani.mockpaper.block.state2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.assertions.throwables.shouldThrowUnit4import io.kotest.core.spec.style.ShouldSpec5import io.kotest.matchers.collections.shouldContainExactly6import io.kotest.matchers.collections.shouldHaveSize7import io.kotest.matchers.shouldBe8import io.kotest.matchers.types.shouldBeInstanceOf9import land.vani.mockpaper.UnimplementedOperationException10import net.kyori.adventure.text.Component11import org.bukkit.DyeColor12import org.bukkit.Material13class SignTest : ShouldSpec({14 lateinit var sign: SignMock15 beforeEach {16 sign = SignMock(Material.OAK_SIGN)17 }18 should("getSnapshot is SignMock") {19 sign.getSnapshot().shouldBeInstanceOf<SignMock>()20 }21 should("getColor is not implemented yet") {22 shouldThrow<UnimplementedOperationException> {...
MinHeapTest.kt
Source:MinHeapTest.kt
1package datastructures2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.matchers.collections.shouldContainAll4import io.kotest.matchers.shouldBe5import org.junit.jupiter.api.Test6import org.junit.jupiter.params.ParameterizedTest7import org.junit.jupiter.params.provider.Arguments8import org.junit.jupiter.params.provider.MethodSource9class MinHeapTest {10 @ParameterizedTest11 @MethodSource("providesInsertValues")12 fun `insert success`(inputs: List<Int>, expectedValues: List<Int>) {13 val minHeap = MinHeap<Int>()14 for(i in inputs) {15 minHeap.insert(i)16 }17 validate(minHeap, expectedValues)18 }...
DoubleShrinkerTest.kt
Source:DoubleShrinkerTest.kt
1package com.sksamuel.kotest.property.shrinking2import io.kotest.core.spec.style.FunSpec3import io.kotest.data.forAll4import io.kotest.data.row5import io.kotest.matchers.collections.beEmpty6import io.kotest.matchers.collections.shouldHaveAtMostSize7import io.kotest.matchers.collections.shouldHaveLowerBound8import io.kotest.matchers.collections.shouldHaveUpperBound9import io.kotest.matchers.should10import io.kotest.matchers.shouldBe11import io.kotest.property.Arb12import io.kotest.property.RandomSource13import io.kotest.property.ShrinkingMode14import io.kotest.property.arbitrary.DoubleShrinker15import io.kotest.property.arbitrary.numericDouble16import io.kotest.property.internal.doShrinking17class DoubleShrinkerTest : FunSpec() {18 init {19 test("shrunk Arb.numericDouble values should stay within bounds") {20 val min = 12363.021 val max = 772183.022 val generator = Arb.numericDouble(min = min, max = max)23 val (v, s) = generator.sample(RandomSource.seeded(39084345))24 val collector = mutableListOf(v)25 doShrinking(s, ShrinkingMode.Bounded(100)) {26 collector.add(it)27 1.0 shouldBe 0.0 // failing assertion to keep on shrinking28 }29 collector shouldHaveLowerBound min30 collector shouldHaveUpperBound max31 }32 test("special values that cannot be shrunk") {33 val values = listOf(34 Double.NaN,35 Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY,36 Double.MIN_VALUE, -Double.MIN_VALUE,37 0.0, -0.0, 1.0, -1.0,38 10.0, -10.0, 100.0, 1e10039 ).map(::row).toTypedArray()40 forAll(*values) { value ->41 DoubleShrinker.shrink(value) should beEmpty()42 }43 }44 test("shrunken numeric values get smaller string representations") {45 val values = listOf(46 1.2 to 1.0, -1.2 to -1.0,47 12.0 to 10.0, -12.0 to -10.0,48 10000200003.0 to 10000200000.0,49 1234567890123456789E-40 to 1234567890123456E-37,50 4.9E-323 to 4.0E-32351 ).map { (input, output) -> row(input, output) }.toTypedArray()52 forAll(*values) { input, expectedOutput ->53 val actualOutput = DoubleShrinker.shrink(input)54 actualOutput shouldHaveAtMostSize 155 actualOutput.firstOrNull() shouldBe expectedOutput56 }57 }58 }...
MapEntryTest.kt
Source:MapEntryTest.kt
1package com.github.whyrising.y.collections.map2import com.github.whyrising.y.collections.concretions.map.MapEntry3import com.github.whyrising.y.collections.concretions.vector.PersistentVector4import com.github.whyrising.y.collections.concretions.vector.PersistentVector.EmptyVector5import io.kotest.assertions.throwables.shouldThrowExactly6import io.kotest.core.spec.style.FreeSpec7import io.kotest.matchers.booleans.shouldBeFalse8import io.kotest.matchers.booleans.shouldBeTrue9import io.kotest.matchers.ints.shouldBeExactly10import io.kotest.matchers.shouldBe11import io.kotest.matchers.types.shouldBeSameInstanceAs12class MapEntryTest : FreeSpec({13 "key/value" {14 val entry: IMapEntry<String, Int> = MapEntry("a", 1)15 entry.key shouldBe "a"16 entry.value shouldBeExactly 117 }18 "nth(index)" {19 val entry = MapEntry("a", 1)20 entry.nth(0) shouldBe "a"21 entry.nth(1) shouldBe 122 val e = shouldThrowExactly<IndexOutOfBoundsException> {23 entry.nth(2)24 }25 e.message shouldBe "index = 2"...
test
Using AI Code Generation
1 import io.kotest.matchers.collections.shouldBeEmpty2 import io.kotest.matchers.collections.shouldBeIn3 import io.kotest.matchers.collections.shouldBeNotEmpty4 import io.kotest.matchers.collections.shouldBeOneOf5 import io.kotest.matchers.collections.shouldBeSorted6 import io.kotest.matchers.collections.shouldBeSortedBy7 import io.kotest.matchers.collections.shouldBeSortedWith8 import io.kotest.matchers.collections.shouldContain9 import io.kotest.matchers.collections.shouldContainAll10 import io.kotest.matchers.collections.shouldContainAnyOf11 import io.kotest.matchers.collections.shouldContainExactly12 import io.kotest.matchers.collections.shouldContainInOrder13 import io.kotest.matchers.collections.shouldContainInOrderExactly14 import io.kotest.matchers.collections.shouldContainKey15 import io.kotest.matchers.collections.shouldContainKeys16 import io.kotest.matchers.collections.shouldContainOnly17 import io.kotest.matchers.collections.shouldContainOnlyNulls18 import io.kotest.matchers.collections.shouldContainValue19 import io.kotest.matchers.collections.shouldContainValues20 import io.kotest.matchers.collections.shouldEndWith21 import io.kotest.matchers.collections.shouldHaveAtLeastSize22 import io.kotest.matchers.collections.shouldHaveAtMostSize23 import io.kotest.matchers.collections.shouldHaveSingleElement24 import io.kotest.matchers.collections.shouldHaveSize25 import io.kotest.matchers.collections.shouldHaveTheSameElementsAs26 import io.kotest.matchers.collections.shouldHaveUniqueElements27 import io.kotest.matchers.collections.shouldHaveUniqueSize28 import io.kotest.matchers.collections.shouldNotBeEmpty29 import io.kotest.matchers.collections.shouldNotBeIn30 import io.kotest.matchers.collections.shouldNotBeOneOf31 import io.kotest.matchers.collections.shouldNotBeSorted32 import io.kotest.matchers.collections.shouldNotBeSortedBy33 import io.kotest.matchers.collections.shouldNotBeSortedWith34 import io.kotest.matchers.collections.shouldNotContain35 import io.kotest.matchers.collections.shouldNotContainAll36 import io.kotest.matchers.collections.shouldNotContainAnyOf
test
Using AI Code Generation
1import io.kotest.matchers.collections.bounds2import io.kotest.matchers.should3import io.kotest.matchers.shouldBe4import io.kotest.matchers.shouldNot5import io.kotest.matchers.shouldNotBe6import io.kotest.matchers.shouldNotBeNull7import io.kotest.matchers.shouldNotBeSameInstanceAs8import io.kotest.matchers.shouldNotThrow9import io.kotest.matchers.shouldThrow10import io.kotest.matchers.shouldThrowAny11import io.kotest.matchers.shouldThrowExactly12import io.kotest.matchers.shouldThrowInstanceOf13import io.kotest.matchers.shouldThrowNothing14import io.kotest.matchers.string.shouldContain15import io.kotest.matchers.string.shouldHaveLength16import io.kotest.matchers.string.shouldHaveSameLengthAs17import io.kotest.matchers.string.shouldMatch18import io.kotest.matchers.string.shouldNotBeEmpty19import io.kotest.matchers.string.shouldNotBeBlank20import io.kotest.matchers.string.shouldNotContain21import io.kotest.matchers.string.shouldNotHaveLength22import io.kotest.matchers.string.shouldNotHaveSameLengthAs23import io.kotest.matchers.string.shouldNotMatch24import io.kotest.matchers.string.shouldNotStartWith25import io.kotest.matchers.string.shouldNotStartWithIgnoringCase26import io.kotest.matchers.string.shouldNotEndWith27import io.kotest.matchers.string.shouldNotEndWithIgnoringCase28import io.kotest.matchers.string.shouldNotBeEmpty29import io.kotest.matchers.string.shouldNotBeBlank30import io.kotest.matchers.string.shouldStartWith31import io.kotest.matchers.string.shouldStartWithIgnoringCase32import io.kotest.matchers.string.shouldEndWith33import io.kotest.matchers.string.shouldEndWithIgnoringCase34import io.kotest.matchers.string.shouldNotBeEmpty35import io.kotest.matchers.string.shouldNotBeBlank36import io.kotest.matchers.string.shouldBeEmpty37import io.kotest.matchers.string.shouldBeBlank38import io.kotest.matchers.string.shouldBeLowerCase39import io.kotest.matchers.string.shouldBeUpperCase40import io.kotest.matchers.string.shouldHaveLineCount41import io.kotest.matchers.string.shouldHaveLine
test
Using AI Code Generation
1 fun testBounds() {2 bounds()3 }4 fun testContain() {5 contain()6 }7 fun testContainAll() {8 containAll()9 }10 fun testContainInAnyOrder() {11 containInAnyOrder()12 }13 fun testContainInOrder() {14 containInOrder()15 }16 fun testContainKey() {17 containKey()18 }19 fun testContainKeys() {20 containKeys()21 }22 fun testContainValue() {23 containValue()24 }25 fun testContainValues() {26 containValues()27 }28 fun testEmpty() {29 empty()30 }31 fun testExactly() {32 exactly()33 }34 fun testHaveSize() {35 haveSize()36 }37 fun testHaveSizeGreaterThan() {38 haveSizeGreaterThan()39 }40 fun testHaveSizeGreaterThanOrEqual() {
test
Using AI Code Generation
1class TestBounds {2 fun testBounds() {3 val list = listOf(1, 2, 3, 4, 5, 6, 7, 8)4 list should startWith(1, 2)5 list should endWith(7, 8)6 list should contain(1, 2, 3, 4, 5, 6, 7, 8)7 list should containInOrder(1, 2, 3, 4, 5, 6, 7, 8)8 list should containInAnyOrder(8, 7, 6, 5, 4, 3, 2, 1)9 list should containAll(1, 2, 3, 4, 5, 6, 7, 8)10 list should containAllInOrder(1, 2, 3, 4, 5, 6, 7, 8)11 list should containAllInAnyOrder(8, 7, 6, 5, 4, 3, 2, 1)12 list should containNone(9, 10)13 }14}
test
Using AI Code Generation
1 import io.kotest.matchers.collections.bounds2 import io.kotest.matchers.shouldBe3 import io.kotest.matchers.shouldNotBe4 import org.junit.Test5 class MyTest {6 fun test() {7 val list = listOf(1, 2, 3, 4, 5)8 list shouldBe bounds(1, 5)9 list shouldNotBe bounds(1, 6)10 list shouldNotBe bounds(0, 5)11 list shouldNotBe bounds(0, 6)12 }13 }14 import io.kotest.matchers.collections.containInAnyOrder15 import io.kotest.matchers.shouldBe16 import io.kotest.matchers.shouldNotBe17 import org.junit.Test18 class MyTest {19 fun test() {20 val list = listOf(1, 2, 3, 4, 5)21 list shouldBe containInAnyOrder(1, 2, 3, 4, 5)22 list shouldNotBe containInAnyOrder(1, 2, 3, 4, 6)23 list shouldNotBe containInAnyOrder(1, 2, 3, 4, 5, 6)24 }25 }26 import io.kotest.matchers.collections.containInOrder27 import io.kotest.matchers.shouldBe28 import io.kotest.matchers.shouldNotBe29 import org.junit.Test30 class MyTest {31 fun test() {32 val list = listOf(1, 2, 3, 4, 5)33 list shouldBe containInOrder(1, 2, 3, 4, 5)34 list shouldNotBe containInOrder(1, 2, 3, 4, 6)35 list shouldNotBe containInOrder(1, 2, 3, 4)36 }37 }38 import io.kotest.matchers.collections.contain
test
Using AI Code Generation
1+ fun `should return true if the list contains a given element`() {2+ val list = listOf("one", "two", "three")3+ list should contain("one")4+ }5+ fun `should return true if the list contains a given element at a given index`() {6+ val list = listOf("one", "two", "three")7+ list should contain("two", 1)8+ }9+ fun `should return true if the list contains all given elements`() {10+ val list = listOf("one", "two", "three")11+ list should containAll("one", "three")12+ }13+ fun `should return true if the list contains all given elements at given indices`() {14+ val list = listOf("one", "two", "three")15+ list should containAll("one", "three", atIndices = 0, 2)16+ }17+ fun `should return true if the list contains all given elements at any order`() {18+ val list = listOf("one", "two", "three")19+ list should containAllInAnyOrder("three", "two", "one")20+ }21+ fun `should return true if the list contains all given elements at given indices in any order`() {22+ val list = listOf("one", "two", "three")23+ list should containAllInAnyOrder("one", "three", atIndices = 0, 2)24+ }25+ fun `should return true if the list contains given elements in order`() {26+ val list = listOf("one", "two", "three")27+ list should containInOrder("one", "two")28+ }29+ fun `should return true if the list contains given elements in order at given indices`() {30+ val list = listOf("one", "two", "three")31+ list should containInOrder("two", "three", atIndices = 1, 2)32+ }33+ fun `should return true if the list contains given elements in order at given indices with duplicates`() {
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!