How to use containAll method of io.kotest.matchers.sequences.matchers class

Best Kotest code snippet using io.kotest.matchers.sequences.matchers.containAll

AbstractDependencyNavigatorTest.kt

Source:AbstractDependencyNavigatorTest.kt Github

copy

Full Screen

...19package org.ossreviewtoolkit.model20import io.kotest.core.spec.style.WordSpec21import io.kotest.matchers.collections.beEmpty22import io.kotest.matchers.collections.contain23import io.kotest.matchers.collections.containAll24import io.kotest.matchers.collections.containExactly25import io.kotest.matchers.collections.containExactlyInAnyOrder26import io.kotest.matchers.collections.haveSize27import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder28import io.kotest.matchers.maps.containExactly as containExactlyEntries29import io.kotest.matchers.sequences.beEmpty as beEmptySequence30import io.kotest.matchers.sequences.containExactly as containSequenceExactly31import io.kotest.matchers.should32import io.kotest.matchers.shouldBe33import io.kotest.matchers.shouldNot34import io.kotest.matchers.shouldNotBe35import java.io.File36import java.time.Instant37import org.ossreviewtoolkit.utils.test.readOrtResult38import org.ossreviewtoolkit.utils.test.shouldNotBeNull39/**40 * A base class for tests of concrete [DependencyNavigator] implementations.41 *42 * The class is configured with an ORT result file that contains the expected results in a specific format. It then43 * runs tests on the [DependencyNavigator] of this result and checks whether it returns the correct dependency44 * information.45 */46abstract class AbstractDependencyNavigatorTest : WordSpec() {47 /** The name of the result file to be used by all test cases. */48 protected abstract val resultFileName: String49 /**50 * The name of the file with a result that contains issues. This is used by tests of the collectIssues() function.51 */52 protected abstract val resultWithIssuesFileName: String53 private val testResult by lazy { readOrtResult(resultFileName) }54 private val testProject by lazy { testResult.getProject(PROJECT_ID)!! }55 protected val navigator by lazy { testResult.dependencyNavigator }56 init {57 "scopeNames" should {58 "return the scope names of a project" {59 navigator.scopeNames(testProject) should containExactlyInAnyOrder("compile", "test")60 }61 }62 "directDependencies" should {63 "return the direct dependencies of a project" {64 navigator.directDependencies(testProject, "test").map { it.id } should containSequenceExactly(65 Identifier("Maven:org.scalacheck:scalacheck_2.12:1.13.5"),66 Identifier("Maven:org.scalatest:scalatest_2.12:3.0.4")67 )68 }69 "return an empty sequence for an unknown scope" {70 navigator.directDependencies(testProject, "unknownScope") should beEmptySequence()71 }72 }73 "scopeDependencies" should {74 "return a map with scopes and their dependencies for a project" {75 val scopeDependencies = navigator.scopeDependencies(testProject)76 scopeDependencies.keys should containExactlyInAnyOrder("compile", "test")77 scopeDependencies["compile"] shouldNotBeNull {78 this should haveSize(17)79 this should containAll(80 Identifier("Maven:com.typesafe.akka:akka-actor_2.12:2.5.6"),81 Identifier("Maven:org.scala-lang:scala-reflect:2.12.2"),82 Identifier("Maven:org.scala-lang:scala-library:2.12.3")83 )84 }85 scopeDependencies["test"] shouldNotBeNull {86 this should haveSize(6)87 this should containAll(88 Identifier("Maven:org.scalacheck:scalacheck_2.12:1.13.5"),89 Identifier("Maven:org.scalactic:scalactic_2.12:3.0.4")90 )91 }92 }93 "return a map with scopes and their direct dependencies by using maxDepth = 1" {94 val scopeDependencies = navigator.scopeDependencies(testProject, maxDepth = 1)95 scopeDependencies["compile"] shouldNotBeNull {96 this should haveSize(7)97 this shouldNot contain(Identifier("Maven:com.typesafe.akka:akka-actor_2.12:2.5.6"))98 }99 }100 "return a map with scopes and their dependencies up to a given maxDepth" {101 val scopeDependencies = navigator.scopeDependencies(testProject, maxDepth = 2)102 scopeDependencies["compile"] shouldNotBeNull {103 this should haveSize(14)104 this shouldNot contain(105 Identifier("Maven:org.scala-lang.modules:scala-java8-compat_2.12:0.8.0")106 )107 }108 }109 "return a map with scopes and their dependencies with filter criteria" {110 val matchedIds = mutableSetOf<Identifier>()111 val scopeDependencies = navigator.scopeDependencies(testProject) { node ->112 matchedIds += node.id113 node.id.namespace == "com.typesafe.akka"114 }115 scopeDependencies["compile"] shouldNotBeNull {116 this should containExactlyInAnyOrder(117 Identifier("Maven:com.typesafe.akka:akka-actor_2.12:2.5.6"),118 Identifier("Maven:com.typesafe.akka:akka-stream_2.12:2.5.6")119 )120 }121 matchedIds should haveSize(23)122 }123 }124 "dependenciesForScope" should {125 "return an empty set for an unknown scope" {126 navigator.dependenciesForScope(testProject, "unknownScope") should beEmpty()127 }128 "return the dependencies of a specific scope" {129 val compileDependencies = navigator.dependenciesForScope(testProject, "compile")130 compileDependencies should haveSize(17)131 compileDependencies should containAll(132 Identifier("Maven:com.typesafe.akka:akka-actor_2.12:2.5.6"),133 Identifier("Maven:org.scala-lang:scala-reflect:2.12.2"),134 Identifier("Maven:org.scala-lang:scala-library:2.12.3")135 )136 }137 "return the dependencies of a specific scope up to a given maxDepth" {138 val compileDependencies = navigator.dependenciesForScope(testProject, "compile", maxDepth = 2)139 compileDependencies should haveSize(14)140 compileDependencies shouldNot contain(141 Identifier("Maven:org.scala-lang.modules:scala-java8-compat_2.12:0.8.0")142 )143 }144 "return the dependencies of a specific scope with filter criteria" {145 val akkaDependencies = navigator.dependenciesForScope(testProject, "compile") { node ->...

Full Screen

Full Screen

matchers.kt

Source:matchers.kt Github

copy

Full Screen

...85 )86}87@Deprecated("use shouldNotContainAllInAnyOrder", ReplaceWith("shouldNotContainAllInAnyOrder"))88infix fun <T, C : Sequence<T>> C?.shouldNotContainExactlyInAnyOrder(expected: C) =89 this shouldNot containAllInAnyOrder(expected)90@Deprecated("use shouldNotContainAllInAnyOrder", ReplaceWith("shouldNotContainAllInAnyOrder"))91fun <T, C : Sequence<T>> C?.shouldNotContainExactlyInAnyOrder(vararg expected: T) =92 this shouldNot containAllInAnyOrder(*expected)93@Deprecated("use shouldContainAllInAnyOrder", ReplaceWith("shouldContainAllInAnyOrder"))94infix fun <T, C : Sequence<T>> C?.shouldContainExactlyInAnyOrder(expected: C) =95 this should containAllInAnyOrder(expected)96@Deprecated("use shouldContainAllInAnyOrder", ReplaceWith("shouldContainAllInAnyOrder"))97fun <T, C : Sequence<T>> C?.shouldContainExactlyInAnyOrder(vararg expected: T) =98 this should containAllInAnyOrder(*expected)99@Deprecated("use containAllInAnyOrder", ReplaceWith("containAllInAnyOrder"))100fun <T> containExactlyInAnyOrder(vararg expected: T): Matcher<Sequence<T>?> =101 containAllInAnyOrder(expected.asSequence())102@Deprecated("use containAllInAnyOrder", ReplaceWith("containAllInAnyOrder"))103/** Assert that a sequence contains the given values and nothing else, in any order. */104fun <T, C : Sequence<T>> containExactlyInAnyOrder(expected: C): Matcher<C?> = containAllInAnyOrder(expected)105infix fun <T, C : Sequence<T>> C?.shouldNotContainAllInAnyOrder(expected: C) =106 this shouldNot containAllInAnyOrder(expected)107fun <T, C : Sequence<T>> C?.shouldNotContainAllInAnyOrder(vararg expected: T) =108 this shouldNot containAllInAnyOrder(*expected)109infix fun <T, C : Sequence<T>> C?.shouldContainAllInAnyOrder(expected: C) =110 this should containAllInAnyOrder(expected)111fun <T, C : Sequence<T>> C?.shouldContainAllInAnyOrder(vararg expected: T) =112 this should containAllInAnyOrder(*expected)113fun <T> containAllInAnyOrder(vararg expected: T): Matcher<Sequence<T>?> =114 containAllInAnyOrder(expected.asSequence())115/** Assert that a sequence contains all the given values and nothing else, in any order. */116fun <T, C : Sequence<T>> containAllInAnyOrder(expected: C): Matcher<C?> = neverNullMatcher { value ->117 val passed = value.count() == expected.count() && expected.all { value.contains(it) }118 MatcherResult(119 passed,120 { "Sequence should contain the values of $expected in any order, but was $value" },121 { "Sequence should not contain the values of $expected in any order" }122 )123}124infix fun <T : Comparable<T>, C : Sequence<T>> C.shouldHaveUpperBound(t: T) = this should haveUpperBound(t)125fun <T : Comparable<T>, C : Sequence<T>> haveUpperBound(t: T) = object : Matcher<C> {126 override fun test(value: C) = MatcherResult(127 (value.maxOrNull() ?: t) <= t,128 { "Sequence should have upper bound $t" },129 { "Sequence should not have upper bound $t" }130 )131}132infix fun <T : Comparable<T>, C : Sequence<T>> C.shouldHaveLowerBound(t: T) = this should haveLowerBound(t)133fun <T : Comparable<T>, C : Sequence<T>> haveLowerBound(t: T) = object : Matcher<C> {134 override fun test(value: C) = MatcherResult(135 (value.minOrNull() ?: t) >= t,136 { "Sequence should have lower bound $t" },137 { "Sequence should not have lower bound $t" }138 )139}140fun <T> Sequence<T>.shouldBeUnique() = this should beUnique()141fun <T> Sequence<T>.shouldNotBeUnique() = this shouldNot beUnique()142fun <T> beUnique() = object : Matcher<Sequence<T>> {143 override fun test(value: Sequence<T>) = MatcherResult(144 value.toSet().size == value.count(),145 { "Sequence should be Unique" },146 { "Sequence should contain at least one duplicate element" }147 )148}149fun <T> Sequence<T>.shouldContainDuplicates() = this should containDuplicates()150fun <T> Sequence<T>.shouldNotContainDuplicates() = this shouldNot containDuplicates()151fun <T> containDuplicates() = object : Matcher<Sequence<T>> {152 override fun test(value: Sequence<T>) = MatcherResult(153 value.toSet().size < value.count(),154 { "Sequence should contain duplicates" },155 { "Sequence should not contain duplicates" }156 )157}158fun <T : Comparable<T>> Sequence<T>.shouldBeSorted() = this should beSorted()159fun <T : Comparable<T>> Sequence<T>.shouldNotBeSorted() = this shouldNot beSorted()160fun <T : Comparable<T>> beSorted(): Matcher<Sequence<T>> = sorted()161fun <T : Comparable<T>> sorted(): Matcher<Sequence<T>> = object : Matcher<Sequence<T>> {162 override fun test(value: Sequence<T>): MatcherResult {163 @Suppress("UNUSED_DESTRUCTURED_PARAMETER_ENTRY")164 val failure = value.zipWithNext().withIndex().firstOrNull { (i, it) -> it.first > it.second }165 val snippet = value.joinToString(",", limit = 10)166 val elementMessage = when (failure) {167 null -> ""168 else -> ". Element ${failure.value.first} at index ${failure.index} was greater than element ${failure.value.second}"169 }170 return MatcherResult(171 failure == null,172 { "Sequence $snippet should be sorted$elementMessage" },173 { "Sequence $snippet should not be sorted" }174 )175 }176}177infix fun <T> Sequence<T>.shouldBeSortedWith(comparator: Comparator<in T>) = this should beSortedWith(comparator)178infix fun <T> Sequence<T>.shouldBeSortedWith(cmp: (T, T) -> Int) = this should beSortedWith(cmp)179fun <T> beSortedWith(comparator: Comparator<in T>): Matcher<Sequence<T>> = sortedWith(comparator)180fun <T> beSortedWith(cmp: (T, T) -> Int): Matcher<Sequence<T>> = sortedWith(cmp)181fun <T> sortedWith(comparator: Comparator<in T>): Matcher<Sequence<T>> = sortedWith { a, b ->182 comparator.compare(a, b)183}184fun <T> sortedWith(cmp: (T, T) -> Int): Matcher<Sequence<T>> = object : Matcher<Sequence<T>> {185 override fun test(value: Sequence<T>): MatcherResult {186 @Suppress("UNUSED_DESTRUCTURED_PARAMETER_ENTRY")187 val failure = value.zipWithNext().withIndex().firstOrNull { (i, it) -> cmp(it.first, it.second) > 0 }188 val snippet = value.joinToString(",", limit = 10)189 val elementMessage = when (failure) {190 null -> ""191 else -> ". Element ${failure.value.first} at index ${failure.index} shouldn't precede element ${failure.value.second}"192 }193 return MatcherResult(194 failure == null,195 { "Sequence $snippet should be sorted$elementMessage" },196 { "Sequence $snippet should not be sorted" }197 )198 }199}200infix fun <T> Sequence<T>.shouldNotBeSortedWith(comparator: Comparator<in T>) = this shouldNot beSortedWith(comparator)201infix fun <T> Sequence<T>.shouldNotBeSortedWith(cmp: (T, T) -> Int) = this shouldNot beSortedWith(cmp)202infix fun <T> Sequence<T>.shouldHaveSingleElement(t: T) = this should singleElement(t)203infix fun <T> Sequence<T>.shouldNotHaveSingleElement(t: T) = this shouldNot singleElement(t)204fun <T> singleElement(t: T) = object : Matcher<Sequence<T>> {205 override fun test(value: Sequence<T>) = MatcherResult(206 value.count() == 1 && value.first() == t,207 { "Sequence should be a single element of $t but has ${value.count()} elements" },208 { "Sequence should not be a single element of $t" }209 )210}211infix fun <T> Sequence<T>.shouldHaveCount(count: Int) = this should haveCount(count)212infix fun <T> Sequence<T>.shouldNotHaveCount(count: Int) = this shouldNot haveCount(213 count)214infix fun <T> Sequence<T>.shouldHaveSize(size: Int) = this should haveCount(size)215infix fun <T> Sequence<T>.shouldNotHaveSize(size: Int) = this shouldNot haveCount(size)216//fun <T> haveSize(size: Int) = haveCount(size)217fun <T> haveSize(size: Int): Matcher<Sequence<T>> = haveCount(size)218fun <T> haveCount(count: Int): Matcher<Sequence<T>> = object : Matcher<Sequence<T>> {219 override fun test(value: Sequence<T>) =220 MatcherResult(221 value.count() == count,222 { "Sequence should have count $count but has count ${value.count()}" },223 { "Sequence should not have count $count" }224 )225}226infix fun <T, U> Sequence<T>.shouldBeLargerThan(other: Sequence<U>) = this should beLargerThan(other)227fun <T, U> beLargerThan(other: Sequence<U>) = object : Matcher<Sequence<T>> {228 override fun test(value: Sequence<T>) = MatcherResult(229 value.count() > other.count(),230 { "Sequence of count ${value.count()} should be larger than sequence of count ${other.count()}" },231 { "Sequence of count ${value.count()} should not be larger than sequence of count ${other.count()}" }232 )233}234infix fun <T, U> Sequence<T>.shouldBeSmallerThan(other: Sequence<U>) = this should beSmallerThan(other)235fun <T, U> beSmallerThan(other: Sequence<U>) = object : Matcher<Sequence<T>> {236 override fun test(value: Sequence<T>) = MatcherResult(237 value.count() < other.count(),238 { "Sequence of count ${value.count()} should be smaller than sequence of count ${other.count()}" },239 { "Sequence of count ${value.count()} should not be smaller than sequence of count ${other.count()}" }240 )241}242infix fun <T, U> Sequence<T>.shouldBeSameCountAs(other: Sequence<U>) = this should beSameCountAs(243 other)244fun <T, U> beSameCountAs(other: Sequence<U>) = object : Matcher<Sequence<T>> {245 override fun test(value: Sequence<T>) = MatcherResult(246 value.count() == other.count(),247 { "Sequence of count ${value.count()} should be the same count as sequence of count ${other.count()}" },248 { "Sequence of count ${value.count()} should not be the same count as sequence of count ${other.count()}" }249 )250}251infix fun <T, U> Sequence<T>.shouldBeSameSizeAs(other: Sequence<U>) = this.shouldBeSameCountAs(other)252infix fun <T> Sequence<T>.shouldHaveAtLeastCount(n: Int) = this shouldHave atLeastCount(n)253fun <T> atLeastCount(n: Int) = object : Matcher<Sequence<T>> {254 override fun test(value: Sequence<T>) = MatcherResult(255 value.count() >= n,256 { "Sequence should contain at least $n elements" },257 { "Sequence should contain less than $n elements" }258 )259}260infix fun <T> Sequence<T>.shouldHaveAtLeastSize(n: Int) = this.shouldHaveAtLeastCount(n)261infix fun <T> Sequence<T>.shouldHaveAtMostCount(n: Int) = this shouldHave atMostCount(n)262fun <T> atMostCount(n: Int) = object : Matcher<Sequence<T>> {263 override fun test(value: Sequence<T>) = MatcherResult(264 value.count() <= n,265 { "Sequence should contain at most $n elements" },266 { "Sequence should contain more than $n elements" }267 )268}269infix fun <T> Sequence<T>.shouldHaveAtMostSize(n: Int) = this shouldHave atMostCount(n)270infix fun <T> Sequence<T>.shouldExist(p: (T) -> Boolean) = this should exist(p)271fun <T> exist(p: (T) -> Boolean) = object : Matcher<Sequence<T>> {272 override fun test(value: Sequence<T>) = MatcherResult(273 value.any { p(it) },274 { "Sequence should contain an element that matches the predicate $p" },275 { "Sequence should not contain an element that matches the predicate $p" }276 )277}278fun <T : Comparable<T>> Sequence<T>.shouldContainInOrder(vararg ts: T) =279 this should containsInOrder(ts.asSequence())280infix fun <T : Comparable<T>> Sequence<T>.shouldContainInOrder(expected: Sequence<T>) =281 this should containsInOrder(expected)282fun <T : Comparable<T>> Sequence<T>.shouldNotContainInOrder(expected: Sequence<T>) =283 this shouldNot containsInOrder(expected)284/** Assert that a sequence contains a given subsequence, possibly with values in between. */285fun <T> containsInOrder(subsequence: Sequence<T>): Matcher<Sequence<T>?> = neverNullMatcher { actual ->286 val subsequenceCount = subsequence.count()287 require(subsequenceCount > 0) { "expected values must not be empty" }288 var subsequenceIndex = 0289 val actualIterator = actual.iterator()290 while (actualIterator.hasNext() && subsequenceIndex < subsequenceCount) {291 if (actualIterator.next() == subsequence.elementAt(subsequenceIndex)) subsequenceIndex += 1292 }293 MatcherResult(294 subsequenceIndex == subsequence.count(),295 { "[$actual] did not contain the elements [$subsequence] in order" },296 { "[$actual] should not contain the elements [$subsequence] in order" }297 )298}299fun <T> Sequence<T>.shouldBeEmpty() = this should beEmpty()300fun <T> Sequence<T>.shouldNotBeEmpty() = this shouldNot beEmpty()301fun <T> beEmpty(): Matcher<Sequence<T>> = object : Matcher<Sequence<T>> {302 override fun test(value: Sequence<T>): MatcherResult = MatcherResult(303 value.count() == 0,304 { "Sequence should be empty" },305 { "Sequence should not be empty" }306 )307}308fun <T> Sequence<T>.shouldContainAll(vararg ts: T) = this should containAll(ts.asSequence())309infix fun <T> Sequence<T>.shouldContainAll(ts: Collection<T>) = this should containAll(ts.asSequence())310infix fun <T> Sequence<T>.shouldContainAll(ts: Sequence<T>) = this should containAll(ts)311fun <T> Sequence<T>.shouldNotContainAll(vararg ts: T) = this shouldNot containAll(ts.asSequence())312infix fun <T> Sequence<T>.shouldNotContainAll(ts: Collection<T>) = this shouldNot containAll(ts.asSequence())313infix fun <T> Sequence<T>.shouldNotContainAll(ts: Sequence<T>) = this shouldNot containAll(ts)314fun <T, C : Sequence<T>> containAll(ts: C): Matcher<Sequence<T>> = object : Matcher<Sequence<T>> {315 override fun test(value: Sequence<T>): MatcherResult = MatcherResult(316 ts.all { value.contains(it) },317 { "Sequence should contain all of ${value.joinToString(",", limit = 10)}" },318 { "Sequence should not contain all of ${value.joinToString(",", limit = 10)}" }319 )320}...

Full Screen

Full Screen

containAll

Using AI Code Generation

copy

Full Screen

1val list = listOf(1, 2, 3, 4, 5)2list should containAll(1, 2, 3)3list should containAll(1, 2, 3, 4, 5)4list should containAll(1, 2, 3, 4)5list should containAll(1, 2, 3, 5)6list should containAll(1, 2, 3, 4, 5, 6)7val list = listOf(1, 2, 3, 4, 5)8list should containAll(1, 2, 3)9list should containAll(1, 2, 3, 4, 5)10list should containAll(1, 2, 3, 4)11list should containAll(1, 2, 3, 5)12list should containAll(1, 2, 3, 4, 5, 6)13at io.kotest.matchers.sequences.containAll(containAll.kt:35)14at io.kotest.matchers.sequences.containAll$default(containAll.kt:34)15at io.kotest.matchers.sequences.containAll(containAll.kt:34)16at io.kotest.matchers.sequences.containAll$default(containAll.kt:33)17at io.kotest.matchers.sequences.containAll(containAll.kt:33)18at io.kotest.matchers.sequences.containAll$default(containAll.kt:32)19at io.kotest.matchers.sequences.containAll(containAll.kt:32)20at io.kotest.matchers.sequences.containAll$default(containAll.kt:31)21at io.kotest.matchers.sequences.containAll(containAll.kt:31)22at io.kotest.matchers.sequences.containAll$default(containAll.kt:30)23at io.kotest.matchers.sequences.containAll(containAll.kt:

Full Screen

Full Screen

containAll

Using AI Code Generation

copy

Full Screen

1fun testContainAll() {2 val seq = sequenceOf(1, 2, 3, 4, 5)3 seq should containAll(1, 2, 3, 4, 5)4}5fun testContainNone() {6 val seq = sequenceOf(1, 2, 3, 4, 5)7 seq should containNone(6, 7, 8, 9, 10)8}9fun testContainExactlyInAnyOrder() {10 val seq = sequenceOf(1, 2, 3, 4, 5)11 seq should containExactlyInAnyOrder(5, 4, 3, 2, 1)12}13fun testContainExactlyInOrder() {14 val seq = sequenceOf(1, 2, 3, 4, 5)15 seq should containExactlyInOrder(1, 2, 3, 4, 5)16}17fun testContainInAnyOrder() {18 val seq = sequenceOf(1, 2, 3, 4, 5)19 seq should containInAnyOrder(5, 4, 3, 2, 1)20}21fun testContainInOrder() {22 val seq = sequenceOf(1, 2, 3, 4, 5)23 seq should containInOrder(1, 2, 3, 4, 5)24}25fun testContainOnly() {26 val seq = sequenceOf(1, 2, 3, 4, 5)27 seq should containOnly(1, 2, 3, 4, 5)28}

Full Screen

Full Screen

containAll

Using AI Code Generation

copy

Full Screen

1 import io.kotest.matchers.sequences.*2 import io.kotest.core.spec.style.StringSpec3 import io.kotest.matchers.shouldBe4 class SequenceMatchersTest : StringSpec({5 "containAll" {6 val seq = sequenceOf(1, 2, 3)7 seq should containAll(1, 2, 3)8 }9 })

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful