How to use containDuplicates method of io.kotest.matchers.collections.duplicates class

Best Kotest code snippet using io.kotest.matchers.collections.duplicates.containDuplicates

CollectionMatchersTest.kt

Source:CollectionMatchersTest.kt Github

copy

Full Screen

...11import io.kotest.matchers.collections.beLargerThan12import io.kotest.matchers.collections.beSameSizeAs13import io.kotest.matchers.collections.beSmallerThan14import io.kotest.matchers.collections.contain15import io.kotest.matchers.collections.containDuplicates16import io.kotest.matchers.collections.containNoNulls17import io.kotest.matchers.collections.containNull18import io.kotest.matchers.collections.containOnlyNulls19import io.kotest.matchers.collections.matchInOrder20import io.kotest.matchers.collections.existInOrder21import io.kotest.matchers.collections.haveElementAt22import io.kotest.matchers.collections.haveSize23import io.kotest.matchers.collections.matchEach24import io.kotest.matchers.collections.matchInOrderSubset25import io.kotest.matchers.collections.monotonicallyDecreasing26import io.kotest.matchers.collections.monotonicallyDecreasingWith27import io.kotest.matchers.collections.monotonicallyIncreasing28import io.kotest.matchers.collections.monotonicallyIncreasingWith29import io.kotest.matchers.collections.shouldBeIn30import io.kotest.matchers.collections.shouldBeLargerThan31import io.kotest.matchers.collections.shouldBeMonotonicallyDecreasing32import io.kotest.matchers.collections.shouldBeMonotonicallyDecreasingWith33import io.kotest.matchers.collections.shouldBeMonotonicallyIncreasing34import io.kotest.matchers.collections.shouldBeMonotonicallyIncreasingWith35import io.kotest.matchers.collections.shouldBeSameSizeAs36import io.kotest.matchers.collections.shouldBeSingleton37import io.kotest.matchers.collections.shouldBeSmallerThan38import io.kotest.matchers.collections.shouldBeSorted39import io.kotest.matchers.collections.shouldBeSortedBy40import io.kotest.matchers.collections.shouldBeSortedWith41import io.kotest.matchers.collections.shouldBeStrictlyDecreasing42import io.kotest.matchers.collections.shouldBeStrictlyDecreasingWith43import io.kotest.matchers.collections.shouldBeStrictlyIncreasing44import io.kotest.matchers.collections.shouldBeStrictlyIncreasingWith45import io.kotest.matchers.collections.shouldContainAnyOf46import io.kotest.matchers.collections.shouldContainDuplicates47import io.kotest.matchers.collections.shouldContainNoNulls48import io.kotest.matchers.collections.shouldContainNull49import io.kotest.matchers.collections.shouldContainOnlyNulls50import io.kotest.matchers.collections.shouldExist51import io.kotest.matchers.collections.shouldHaveAtLeastSize52import io.kotest.matchers.collections.shouldHaveAtMostSize53import io.kotest.matchers.collections.shouldHaveElementAt54import io.kotest.matchers.collections.shouldHaveSingleElement55import io.kotest.matchers.collections.shouldHaveSize56import io.kotest.matchers.collections.shouldMatchInOrder57import io.kotest.matchers.collections.shouldMatchInOrderSubset58import io.kotest.matchers.collections.shouldNotBeIn59import io.kotest.matchers.collections.shouldNotBeMonotonicallyDecreasing60import io.kotest.matchers.collections.shouldNotBeMonotonicallyDecreasingWith61import io.kotest.matchers.collections.shouldNotBeMonotonicallyIncreasing62import io.kotest.matchers.collections.shouldNotBeMonotonicallyIncreasingWith63import io.kotest.matchers.collections.shouldNotBeSingleton64import io.kotest.matchers.collections.shouldNotBeSorted65import io.kotest.matchers.collections.shouldNotBeSortedBy66import io.kotest.matchers.collections.shouldNotBeSortedWith67import io.kotest.matchers.collections.shouldNotBeStrictlyDecreasing68import io.kotest.matchers.collections.shouldNotBeStrictlyDecreasingWith69import io.kotest.matchers.collections.shouldNotBeStrictlyIncreasing70import io.kotest.matchers.collections.shouldNotBeStrictlyIncreasingWith71import io.kotest.matchers.collections.shouldNotContainAnyOf72import io.kotest.matchers.collections.shouldNotContainDuplicates73import io.kotest.matchers.collections.shouldNotContainNoNulls74import io.kotest.matchers.collections.shouldNotContainNull75import io.kotest.matchers.collections.shouldNotContainOnlyNulls76import io.kotest.matchers.collections.shouldNotHaveElementAt77import io.kotest.matchers.collections.shouldNotHaveSize78import io.kotest.matchers.collections.shouldNotMatchEach79import io.kotest.matchers.collections.shouldNotMatchInOrder80import io.kotest.matchers.collections.shouldNotMatchInOrderSubset81import io.kotest.matchers.collections.singleElement82import io.kotest.matchers.collections.sorted83import io.kotest.matchers.collections.strictlyDecreasing84import io.kotest.matchers.collections.strictlyDecreasingWith85import io.kotest.matchers.collections.strictlyIncreasing86import io.kotest.matchers.collections.strictlyIncreasingWith87import io.kotest.matchers.ints.shouldBeGreaterThan88import io.kotest.matchers.ints.shouldBeInRange89import io.kotest.matchers.should90import io.kotest.matchers.shouldBe91import io.kotest.matchers.shouldHave92import io.kotest.matchers.shouldNot93import io.kotest.matchers.shouldNotBe94import io.kotest.matchers.shouldNotHave95import io.kotest.matchers.throwable.shouldHaveMessage96class CollectionMatchersTest : WordSpec() {97 private val countdown = (10 downTo 0).toList()98 private val asc = { a: Int, b: Int -> a - b }99 private val desc = { a: Int, b: Int -> b - a }100 init {101 "a descending non-empty list" should {102 "fail to ascend" {103 shouldFail {104 countdown.shouldBeSortedWith(asc)105 }106 }107 "descend" {108 countdown.shouldBeSortedWith(desc)109 }110 "not ascend" {111 countdown.shouldNotBeSortedWith(asc)112 }113 "fail not to descend" {114 shouldFail {115 countdown.shouldNotBeSortedWith(desc)116 }117 }118 }119 "sortedWith" should {120 val items = listOf(121 1 to "I",122 2 to "II",123 4 to "IV",124 5 to "V",125 6 to "VI",126 9 to "IX",127 10 to "X"128 )129 "work on non-Comparable given a Comparator" {130 items.shouldBeSortedWith(Comparator { a, b -> asc(a.first, b.first) })131 }132 "work on non-Comparable given a compare function" {133 items.shouldBeSortedWith { a, b -> asc(a.first, b.first) }134 }135 }136 "haveElementAt" should {137 "test that a collection contains the specified element at the given index" {138 listOf("a", "b", "c") should haveElementAt(1, "b")139 listOf("a", "b", "c") shouldNot haveElementAt(1, "c")140 listOf("a", "b", null) should haveElementAt(2, null)141 listOf("a", "b", null) shouldNot haveElementAt(3, null)142 listOf("a", "b", "c").shouldHaveElementAt(1, "b")143 listOf("a", "b", "c").shouldNotHaveElementAt(1, "c")144 listOf("a", "b", null).shouldHaveElementAt(2, null)145 }146 "support type inference for subtypes of collection" {147 val tests = listOf(148 TestSealed.Test1("test1"),149 TestSealed.Test2(2)150 )151 tests should haveElementAt(0, TestSealed.Test1("test1"))152 tests.shouldHaveElementAt(1, TestSealed.Test2(2))153 }154 }155 "containNull()" should {156 "test that a collection contains at least one null" {157 listOf(1, 2, null) should containNull()158 listOf(null) should containNull()159 listOf(1, 2) shouldNot containNull()160 listOf(1, 2, null).shouldContainNull()161 listOf(null).shouldContainNull()162 listOf(1, 2).shouldNotContainNull()163 }164 }165 "sorted" should {166 "test that a collection is sorted" {167 emptyList<Int>() shouldBe sorted<Int>()168 listOf(1) shouldBe sorted<Int>()169 listOf(1, 2, 3, 4) shouldBe sorted<Int>()170 shouldThrow<AssertionError> {171 listOf(2, 1) shouldBe sorted<Int>()172 }.shouldHaveMessage("List [2, 1] should be sorted. Element 2 at index 0 was greater than element 1")173 listOf(1, 2, 6, 9).shouldBeSorted()174 shouldThrow<AssertionError> {175 listOf(2, 1).shouldBeSorted()176 }.shouldHaveMessage("List [2, 1] should be sorted. Element 2 at index 0 was greater than element 1")177 shouldThrow<AssertionError> {178 listOf(1, 2, 3).shouldNotBeSorted()179 }.shouldHaveMessage("List [1, 2, 3] should not be sorted")180 }181 "restrict items at the error message" {182 val longList = (1..1000).toList()183 shouldThrow<AssertionError> {184 longList.shouldNotBeSorted()185 }.shouldHaveMessage("List [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...and 980 more (set the 'kotest.assertions.collection.print.size' JVM property to see more / less items)] should not be sorted")186 }187 }188 "sortedBy" should {189 val items = listOf(190 1 to "I",191 2 to "II",192 4 to "IV",193 5 to "V",194 6 to "VI",195 9 to "IX",196 10 to "X"197 )198 "compare by the tranformed value" {199 items.shouldBeSortedBy { it.first }200 items.shouldNotBeSortedBy { it.second }201 }202 }203 "shouldBeIncreasing" should {204 "test that a collection is monotonically increasing" {205 listOf(1, 2, 2, 3) shouldBe monotonicallyIncreasing<Int>()206 listOf(6, 5) shouldNotBe monotonicallyIncreasing<Int>()207 listOf(1, 2, 2, 3).shouldBeMonotonicallyIncreasing()208 listOf(6, 5).shouldNotBeMonotonicallyIncreasing()209 }210 "test that a collection is monotonically increasing according to comparator" {211 val comparator = Comparator(desc)212 listOf(3, 2, 2, 1) shouldBe monotonicallyIncreasingWith(comparator)213 listOf(5, 6) shouldNotBe monotonicallyIncreasingWith(comparator)214 listOf(3, 2, 2, 1).shouldBeMonotonicallyIncreasingWith(comparator)215 listOf(5, 6).shouldNotBeMonotonicallyIncreasingWith(comparator)216 }217 "test that a collection is strictly increasing" {218 listOf(1, 2, 3) shouldBe strictlyIncreasing<Int>()219 listOf(1, 2, 2, 3) shouldNotBe strictlyIncreasing<Int>()220 listOf(6, 5) shouldNotBe strictlyIncreasing<Int>()221 listOf(1, 2, 3).shouldBeStrictlyIncreasing()222 listOf(1, 2, 2, 3).shouldNotBeStrictlyIncreasing()223 listOf(6, 5).shouldNotBeStrictlyIncreasing()224 }225 "test that a collection is strictly increasing according to comparator" {226 val comparator = Comparator(desc)227 listOf(3, 2, 1) shouldBe strictlyIncreasingWith(comparator)228 listOf(3, 2, 2, 1) shouldNotBe strictlyIncreasingWith(comparator)229 listOf(5, 6) shouldNotBe strictlyIncreasingWith(comparator)230 listOf(3, 2, 1).shouldBeStrictlyIncreasingWith(comparator)231 listOf(3, 2, 2, 1).shouldNotBeStrictlyIncreasingWith(comparator)232 listOf(5, 6).shouldNotBeStrictlyIncreasingWith(comparator)233 }234 }235 "shouldBeDecreasing" should {236 "test that a collection is monotonically decreasing" {237 listOf(3, 2, 2, -4) shouldBe monotonicallyDecreasing<Int>()238 listOf(5, 6) shouldNotBe monotonicallyDecreasing<Int>()239 listOf(3, 2, 2, -4).shouldBeMonotonicallyDecreasing()240 listOf(5, 6).shouldNotBeMonotonicallyDecreasing()241 }242 "test that a collection is monotonically decreasing according to comparator" {243 val comparator = Comparator(desc)244 listOf(-4, 2, 2, 3) shouldBe monotonicallyDecreasingWith(comparator)245 listOf(6, 5) shouldNotBe monotonicallyDecreasingWith(comparator)246 listOf(-4, 2, 2, 3).shouldBeMonotonicallyDecreasingWith(comparator)247 listOf(6, 5).shouldNotBeMonotonicallyDecreasingWith(comparator)248 }249 "test that a collection is strictly decreasing" {250 listOf(3, 2, -4) shouldBe strictlyDecreasing<Int>()251 listOf(3, 2, 2, -4) shouldNotBe strictlyDecreasing<Int>()252 listOf(5, 6) shouldNotBe strictlyDecreasing<Int>()253 listOf(3, 2, -4).shouldBeStrictlyDecreasing()254 listOf(3, 2, 2, -4).shouldNotBeStrictlyDecreasing()255 listOf(5, 6).shouldNotBeStrictlyDecreasing()256 }257 "test that a collection is strictly decreasing according to comparator" {258 val comparator = Comparator(desc)259 listOf(-4, 2, 3) shouldBe strictlyDecreasingWith(comparator)260 listOf(-4, 2, 2, 3) shouldNotBe strictlyDecreasingWith(comparator)261 listOf(6, 5) shouldNotBe strictlyDecreasingWith(comparator)262 listOf(-4, 2, 3).shouldBeStrictlyDecreasingWith(comparator)263 listOf(-4, 2, 2, 3).shouldNotBeStrictlyDecreasingWith(comparator)264 listOf(6, 5).shouldNotBeStrictlyDecreasingWith(comparator)265 }266 }267 "haveDuplicates" should {268 "test that a collection is unique" {269 listOf(1, 2, 3, 3) should containDuplicates()270 listOf(1, 2, 3, 4) shouldNot containDuplicates()271 listOf(1, 2, 3, 3).shouldContainDuplicates()272 listOf(1, 2, 3, 4).shouldNotContainDuplicates()273 }274 }275 "singleElement" should {276 "test that a collection contains a single given element" {277 listOf(1) shouldBe singleElement(1)278 listOf(1).shouldHaveSingleElement(1)279 shouldThrow<AssertionError> {280 listOf(1) shouldBe singleElement(2)281 }.shouldHaveMessage("Collection should be a single element of 2 but has 1 elements: [1]")282 shouldThrow<AssertionError> {283 listOf(1, 2) shouldBe singleElement(2)284 }.shouldHaveMessage("Collection should be a single element of 2 but has 2 elements: [1, 2]")...

Full Screen

Full Screen

matchers.kt

Source:matchers.kt Github

copy

Full Screen

...123 )124}125fun <T> Iterable<T>.shouldContainDuplicates() = toList().shouldContainDuplicates()126fun <T> Array<T>.shouldContainDuplicates() = asList().shouldContainDuplicates()127fun <T> Collection<T>.shouldContainDuplicates() = this should containDuplicates()128fun <T> Iterable<T>.shouldNotContainDuplicates() = toList().shouldNotContainDuplicates()129fun <T> Array<T>.shouldNotContainDuplicates() = asList().shouldNotContainDuplicates()130fun <T> Collection<T>.shouldNotContainDuplicates() = this shouldNot containDuplicates()131fun <T> containDuplicates() = object : Matcher<Collection<T>> {132 override fun test(value: Collection<T>) = MatcherResult(133 value.toSet().size < value.size,134 "Collection should contain duplicates",135 "Collection should not contain duplicates"136 )137}138fun <T> beSortedWith(comparator: Comparator<in T>): Matcher<List<T>> = sortedWith(comparator)139fun <T> beSortedWith(cmp: (T, T) -> Int): Matcher<List<T>> = sortedWith(cmp)140fun <T> sortedWith(comparator: Comparator<in T>): Matcher<List<T>> = sortedWith { a, b ->141 comparator.compare(a, b)142}143fun <T> sortedWith(cmp: (T, T) -> Int): Matcher<List<T>> = object : Matcher<List<T>> {144 override fun test(value: List<T>): MatcherResult {145 val failure = value.withIndex().firstOrNull { (i, it) -> i != value.lastIndex && cmp(it, value[i + 1]) > 0 }...

Full Screen

Full Screen

UniqueDataProvierIT.kt

Source:UniqueDataProvierIT.kt Github

copy

Full Screen

2import io.github.serpro69.kfaker.provider.Address3import io.kotest.assertions.assertSoftly4import io.kotest.core.spec.style.DescribeSpec5import io.kotest.matchers.collections.beUnique6import io.kotest.matchers.collections.containDuplicates7import io.kotest.matchers.collections.shouldContainAnyOf8import io.kotest.matchers.collections.shouldNotContainAnyOf9import io.kotest.matchers.should10import io.kotest.matchers.shouldBe11import io.kotest.matchers.shouldNot12import io.kotest.matchers.shouldNotBe13@Suppress("UNCHECKED_CAST")14class UniqueDataProviderIT : DescribeSpec({15 describe("unique generation of values enabled for provider through configuration") {16 val config = FakerConfig.builder().create { uniqueGeneratorRetryLimit = 100 }17 // repeat 10 times to make sure values are not included in the collection18 repeat(10) {19 context("collection of values is generated #run$it") {20 val faker = Faker(config)21 faker.unique.configuration { enable(faker::address) }22 val countries = (0..18).map { faker.address.country() }23 val newCountries = (0..30).map { faker.address.country() }24 it("should have unique values") {25 assertSoftly {26 countries should beUnique()27 newCountries should beUnique()28 newCountries shouldNotContainAnyOf countries29 }30 }31 }32 }33 }34 describe("collection of values is used to exclude values from being generated for specific provider") {35 val config = FakerConfig.builder().create { uniqueGeneratorRetryLimit = 100 }36 // repeat 10 times to make sure values are not included in the collection37 repeat(10) {38 val faker = Faker(config)39 faker.unique.configuration { enable(faker::address) }40 val countries = (0..30).map { faker.address.country() }41 context("collection of unique values is generated run#$it") {42 val excludedCountries = listOf(43 "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola"44 )45 faker.unique.configuration { excludeFromFunction(Address::country, excludedCountries) }46 val newCountries = (0..30).map { faker.address.country() }47 val moreExcludedCountries = listOf(48 "Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic"49 )50 faker.unique.configuration { excludeFromProvider<Address>(moreExcludedCountries) }51 val moreCountries = (0..30).map { faker.address.country() }52 val excludedCountryCodes = listOf("AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ")53 faker.unique.configuration { excludeFromProvider<Address>(excludedCountryCodes) }54 val countryCodes = (0..30).map { faker.address.countryCode() }55 it("excluded values through config should not be included in the generation") {56 assertSoftly {57 newCountries shouldNotContainAnyOf excludedCountries58 moreCountries shouldNotContainAnyOf moreExcludedCountries59 countryCodes shouldNotContainAnyOf excludedCountryCodes60 }61 }62 it("already generated values through config should not be included in the generation") {63 assertSoftly {64 newCountries shouldNotContainAnyOf countries65 moreCountries shouldNotContainAnyOf newCountries66 moreCountries shouldNotContainAnyOf countries67 }68 }69 }70 }71 }72 describe("use collections to exclude values from being generated for all providers") {73 // repeat 10 times to make sure values are not included in the collection74 repeat(10) {75 val faker = Faker()76 val excludedCountries = listOf(77 "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra",78 "Angola", "Anguilla", "Antarctica (the territory South of 60 deg S)", "Antigua and Barbuda",79 "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain",80 "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia",81 "Bosnia and Herzegovina", "Botswana", "Bouvet Island (Bouvetoya)", "Brazil",82 "British Indian Ocean Territory (Chagos Archipelago)", "Brunei Darussalam", "Bulgaria",83 "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands",84 "Central African Republic", "Chad", "Chile", "China", "Christmas Island", "Cocos (Keeling) Islands",85 "Colombia", "Comoros", "Congo", "Congo", "Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia",86 "Cuba", "Cyprus", "Czech Republic",87 )88 val excludedNames = listOf(89 "Abbott", "Abernathy", "Abshire", "Adams", "Altenwerth", "Anderson", "Ankunding", "Armstrong", "Auer",90 "Aufderhar", "Bahringer", "Bailey", "Balistreri", "Barrows", "Bartell", "Bartoletti", "Barton",91 "Bashirian", "Batz", "Bauch", "Baumbach", "Bayer", "Beahan", "Beatty", "Bechtelar", "Becker", "Bednar",92 "Beer", "Beier", "Berge", "Bergnaum", "Bergstrom", "Bernhard", "Bernier", "Bins", "Blanda", "Blick",93 "Block", "Bode", "Boehm", "Bogan", "Bogisich", "Borer", "Bosco", "Botsford", "Boyer", "Boyle",94 "Bradtke", "Brakus", "Braun", "Breitenberg", "Brekke", "Brown", "Bruen", "Buckridge"95 )96 val excludedBicCodes = listOf(97 "AACCGB21", "AACNGB21", "AAFMGB21", "AAHOGB21", "AAHVGB21", "AANLGB21",98 "AANLGB2L", "AAOGGB21", "AAPEGB21", "AAPUGB21", "AAQIGB21", "ABBYGB2L",99 "BCYPGB2LCBB", "BCYPGB2LHGB", "BCYPGB2LHHB", "BCYPGB2LPGB", "BCYPGB2LSSB", "BCYPGB2LMBB"100 )101 val excludeAll = listOf(excludedCountries, excludedNames, excludedBicCodes).flatten()102 faker.unique.configuration {103 enable(faker::address)104 enable(faker::name)105 exclude(excludeAll)106 }107 context("collection of unique values is generated run#$it") {108 val countries = (0..30).map { faker.address.country() }109 val names = (0..30).map { faker.name.lastName() }110 // Unique generation not enabled for Bank111 val bicCodes = (0..30).map { faker.bank.swiftBic() }112 it("should not contain excluded values") {113 assertSoftly {114 countries shouldNotContainAnyOf excludeAll115 names shouldNotContainAnyOf excludeAll116 // Unique generation not enabled for Bank117 bicCodes shouldNot beUnique()118 bicCodes shouldContainAnyOf excludedBicCodes119 }120 }121 }122 }123 }124 describe("use regex patterns to exclude values from being generated for all providers") {125 repeat(10) {126 val faker = Faker()127 faker.unique.configuration {128 // Enable unique generation129 enable(faker::address)130 enable(faker::name)131 // Exclude all values starting with "A"132 exclude { listOf(Regex("^A")) }133 }134 it("should not contain values matching pattern run#$it") {135 val countries = (0..30).map { faker.address.country() }136 val names = (0..30).map { faker.name.lastName() }137 // Unique generation not enabled for Bank138 val bicCodes = (0..30).map { faker.bank.swiftBic() }139 assertSoftly {140 countries.none { s -> s.startsWith("A") } shouldBe true141 countries should beUnique()142 names.none { s -> s.startsWith("A") } shouldBe true143 names should beUnique()144 // Unique generation not enabled for Bank145 bicCodes.any { s -> s.startsWith("A") } shouldBe true146 bicCodes shouldNot beUnique()147 }148 }149 }150 }151 describe("use regex patterns to exclude values from being generated for specific provider") {152 repeat(10) {153 val faker = Faker()154 faker.unique.configuration {155 // Enable unique generation and exclude by patterns156 enable(faker::address) {157 excludeFromProvider<Address> { listOf(Regex("^A")) }158 excludeFromFunction(Address::country) { listOf(Regex("^B")) }159 }160 }161 it("excluded values by pattern should not be included in the generation for the provider run#$it") {162 val countries = (0..30).map { faker.address.country() }163 val cities = (0..30).map { faker.address.city() }164 assertSoftly {165 countries.none { s -> s.startsWith("A") } shouldBe true166 countries.none { s -> s.startsWith("B") } shouldBe true167 cities.none { s -> s.startsWith("A") } shouldBe true168 }169 }170 }171 }172 describe("unique generation of values for category") {173 val config = FakerConfig.builder().create { uniqueGeneratorRetryLimit = 100 }174 context("collection of values is generated") {175 val faker = Faker(config)176 faker.unique.enable(faker::address)177 faker.unique.enable(faker::ancient)178 val countries = (0..20).map { faker.address.country() }179 it("should not contain duplicates") {180 countries should beUnique()181 }182 }183 context("used values are cleared") {184 val faker = Faker(config).also {185 it.unique.enable(it::address)186 }187 val countries = (0..20).map { faker.address.country() }188 faker.unique.clear(faker::address)189 val newCountries = (0..20).map { faker.address.country() }190 it("new collection should not contain duplicates") {191 newCountries should beUnique()192 }193 it("new collection should not equal old collection") {194 newCountries shouldNotBe countries195 }196 }197 context("exclude values from being generated") {198 // repeat 10 times to make sure values are not included in the collection199 repeat(10) {200 val faker = Faker(config)201 faker.unique.enable(faker::address)202 val countries = (0..5).map { faker.address.country() }203 context("collection of values was marked for exclusion run#$it") {204 val excludedCountries = listOf(205 "Afghanistan",206 "Albania",207 "Algeria",208 "American Samoa",209 "Andorra",210 "Angola"211 )212 faker.unique.exclude<Address>("country", excludedCountries)213 val newCountries = (0..20).map { faker.address.country() }214 it("excluded values should not be included in the generation") {215 newCountries shouldNotContainAnyOf excludedCountries216 }217 it("already generated values should not be included in the generation") {218 newCountries shouldNotContainAnyOf countries219 }220 }221 }222 }223 context("unique generation is not enabled for category") {224 val faker = Faker(config)225 context("some values were marked for exclusion") {226 val excludedCountries = listOf(227 "Afghanistan",228 "Albania",229 "Algeria",230 "American Samoa",231 "Andorra",232 "Angola",233 "Anguilla",234 "Antarctica",235 "Antigua And Barbuda",236 "Argentina",237 "Armenia",238 "Aruba",239 "Australia",240 "Austria",241 "Aland Islands",242 "Azerbaijan",243 "Bahamas",244 "Bahrain",245 "Bangladesh",246 "Barbados",247 "Belarus",248 "Belgium",249 "Belize",250 "Benin",251 "Bermuda",252 "Bhutan",253 "Bolivia",254 "Bonaire",255 "Bosnia And Herzegovina",256 "Botswana",257 "Bouvet Island"258 )259 faker.unique.exclude<Address>("country", excludedCountries)260 val countries = (0..100).map { faker.address.country() }261 it("collection can have duplicates") {262 countries should containDuplicates()263 }264 it("collection can have excluded values") {265 countries.any { excludedCountries.contains(it) } shouldBe true266 }267 }268 }269 context("values are generated for another category that is not marked for unique generation") {270 val faker = Faker(config)271 faker.unique.enable(faker::address)272 val animalNames = (0..100).map { faker.animal.name() }273 it("collection can have duplicates") {274 animalNames shouldNot beUnique()275 }276 }...

Full Screen

Full Screen

CoordinateTest.kt

Source:CoordinateTest.kt Github

copy

Full Screen

...3import io.kotest.assertions.assertSoftly4import io.kotest.core.spec.style.WordSpec5import io.kotest.data.forAll6import io.kotest.data.row7import io.kotest.matchers.collections.containDuplicates8import io.kotest.matchers.collections.shouldContainInOrder9import io.kotest.matchers.collections.shouldHaveSize10import io.kotest.matchers.comparables.beGreaterThan11import io.kotest.matchers.comparables.beLessThan12import io.kotest.matchers.nulls.shouldBeNull13import io.kotest.matchers.sequences.shouldContainExactly14import io.kotest.matchers.should15import io.kotest.matchers.shouldBe16import io.kotest.matchers.shouldNot17import io.kotest.matchers.string.shouldHaveMinLength18import io.kotest.matchers.string.shouldMatch19import io.kotest.property.checkAll20import mu.KotlinLogging21private val log = KotlinLogging.logger {}22class CoordinateTest : WordSpec({23 val testCoordinate = Coordinate(123, 345)24 "A coordinate $testCoordinate" should {25 val expectedMainCoordinate = MainCoordinate(1, 3)26 "have main coordinate $expectedMainCoordinate" {27 testCoordinate.toMainCoordinate() shouldBe expectedMainCoordinate28 }29 "return the correct Coordinate when moving it east/west" {30 for (eastingDelta in -1000..1000) {31 testCoordinate.withRelativeEasting(eastingDelta) shouldBe Coordinate(123 + eastingDelta, 345)32 }33 }34 "return the correct Coordinate when moving it north/south" {35 for (northingDelta in -1000..1000) {36 testCoordinate.withRelativeNorthing(northingDelta) shouldBe Coordinate(123, 345 + +northingDelta)37 }38 }39 "must be subtract able" {40 forAll(41 row(Coordinate.zero, Coordinate(testCoordinate.eastingFromLeft - 0, testCoordinate.northingFromBottom - 0)),42 row(Coordinate.oneEast, Coordinate(testCoordinate.eastingFromLeft - 1, testCoordinate.northingFromBottom - 0)),43 row(Coordinate.oneNorth, Coordinate(testCoordinate.eastingFromLeft - 0, testCoordinate.northingFromBottom - 1)),44 row(Coordinate.one, Coordinate(testCoordinate.eastingFromLeft - 1, testCoordinate.northingFromBottom - 1)),45 row(Coordinate.minusOneEast, Coordinate(testCoordinate.eastingFromLeft - -1, testCoordinate.northingFromBottom - 0)),46 row(Coordinate.minusOneNorth, Coordinate(testCoordinate.eastingFromLeft - 0, testCoordinate.northingFromBottom - -1)),47 row(Coordinate.minusOne, Coordinate(testCoordinate.eastingFromLeft - -1, testCoordinate.northingFromBottom - -1))48 ) { other, expected ->49 (testCoordinate - other) shouldBe expected50 }51 }52 }53 "A coordinate $testCoordinate" When {54 val coordinateWithDifferentNorthing = Coordinate(123, 344)55 "compared to $coordinateWithDifferentNorthing" should {56 "be bigger (because of higher northing)" {57 testCoordinate should beGreaterThan(coordinateWithDifferentNorthing)58 }59 }60 "being compared with $coordinateWithDifferentNorthing" should {61 "be less (because of lower northing)" {62 coordinateWithDifferentNorthing should beLessThan(testCoordinate)63 }64 }65 val coordinateWithDifferentEasting = Coordinate(122, 345)66 "compared to $coordinateWithDifferentEasting" should {67 "be bigger (because of higher easting)" {68 testCoordinate should beGreaterThan(coordinateWithDifferentEasting)69 }70 }71 "being compared with $coordinateWithDifferentEasting" should {72 "be less (because of lower easting)" {73 coordinateWithDifferentEasting should beLessThan(testCoordinate)74 }75 }76 "compared to itself" should {77 "be 0" {78 testCoordinate.compareTo(testCoordinate) shouldBe 079 }80 }81 }82 "The minimum coordinate" should {83 "be less than zero" {84 Coordinate.minimum should beLessThan(Coordinate.zero)85 }86 "be less than one" {87 Coordinate.minimum should beLessThan(Coordinate.one)88 }89 "be less than minusOne" {90 Coordinate.minimum should beLessThan(Coordinate.minusOne)91 }92 "be less than maximum" {93 Coordinate.minimum should beLessThan(Coordinate.maximum)94 }95 }96 "The maximum coordinate" should {97 "be greater than zero" {98 Coordinate.maximum should beGreaterThan(Coordinate.zero)99 }100 "be greater than one" {101 Coordinate.maximum should beGreaterThan(Coordinate.one)102 }103 "be greater than minusOne" {104 Coordinate.maximum should beGreaterThan(Coordinate.minusOne)105 }106 "be greater than minimum" {107 Coordinate.maximum should beGreaterThan(Coordinate.minimum)108 }109 }110 val c11 = Coordinate.one111 val c12 = Coordinate(1, 2)112 val c13 = Coordinate(1, 3)113 val c21 = Coordinate(2, 1)114 val c22 = Coordinate(2, 2)115 val c23 = Coordinate(2, 3)116 val c31 = Coordinate(3, 1)117 val c32 = Coordinate(3, 2)118 val c33 = Coordinate(3, 3)119 val unorderedListOfCoordinates = listOf(c31, c21, c11, c32, c33, c23, c12, c22, c13)120 "A list of ${unorderedListOfCoordinates.size} coordinates" should {121 "have the correct order when sorted" {122 val sorted = unorderedListOfCoordinates.sorted()123 assertSoftly {124 sorted shouldHaveSize 9125 sorted shouldNot containDuplicates()126 sorted shouldContainInOrder listOf(c11, c21, c31, c12, c22, c32, c13, c23, c33)127 }128 }129 }130 "The string representation of a coordinate in the form of (xxx|yyy)" should {131 val regex = Coordinate.REGEX_STRING.pattern132 "always have a length of at least 9 and match '$regex'" {133 var checkedCoordinates = 0134 checkAll<Int, Int> { x, y ->135 val coordinateString = Coordinate(x, y).toString()136 assertSoftly {137 coordinateString shouldHaveMinLength 9138 coordinateString shouldMatch regex139 }...

Full Screen

Full Screen

duplicates.kt

Source:duplicates.kt Github

copy

Full Screen

...10fun <T> Array<T>.shouldContainDuplicates() {11 asList().shouldContainDuplicates()12}13fun <T> Collection<T>.shouldContainDuplicates(): Collection<T> {14 this should containDuplicates()15 return this16}17fun <T> Iterable<T>.shouldNotContainDuplicates(): Iterable<T> {18 toList().shouldNotContainDuplicates()19 return this20}21fun <T> Array<T>.shouldNotContainDuplicates(): Array<T> {22 asList().shouldNotContainDuplicates()23 return this24}25fun <T> Collection<T>.shouldNotContainDuplicates(): Collection<T> {26 this shouldNot containDuplicates()27 return this28}29fun <T> containDuplicates() = object : Matcher<Collection<T>> {30 override fun test(value: Collection<T>) = MatcherResult(31 value.toSet().size < value.size,32 { "Collection should contain duplicates" },33 {34 "Collection should not contain duplicates"35 })36}...

Full Screen

Full Screen

containDuplicates

Using AI Code Generation

copy

Full Screen

1import io.kotest.core.spec.style.StringSpec2import io.kotest.matchers.collections.duplicates3import io.kotest.matchers.shouldBe4class DuplicatesTest : StringSpec({5"containDuplicates" {6val list = listOf(1, 2, 3, 4, 5, 1, 2, 3)7list.containDuplicates() shouldBe true8}9})

Full Screen

Full Screen

containDuplicates

Using AI Code Generation

copy

Full Screen

1 fun `test containDuplicates method`(){2 val list = listOf(1, 2, 3, 4, 5, 5)3 list should containDuplicates()4 }5 fun `test shouldContainDuplicates method`(){6 val list = listOf(1, 2, 3, 4, 5, 5)7 }8 fun `test shouldNotContainDuplicates method`(){9 val list = listOf(1, 2, 3, 4, 5, 5)10 }11 fun `test shouldContainDuplicatesExactly method`(){12 val list = listOf(1, 2, 3, 4, 5, 5)13 }14 fun `test shouldContainDuplicatesExactlyInAnyOrder method`(){15 val list = listOf(1, 2, 3, 4, 5, 5)16 }17 fun `test shouldContainDuplicatesExactlyInAnyOrder method`(){18 val list = listOf(1, 2, 3, 4, 5, 5)19 }20 fun `test shouldContainDuplicatesExactlyInAnyOrder method`(){21 val list = listOf(1, 2, 3, 4, 5, 5)

Full Screen

Full Screen

containDuplicates

Using AI Code Generation

copy

Full Screen

1val list = listOf(1, 2, 3, 4, 4)2list should containDuplicates()3list should containDuplicates(4)4list should not containDuplicates(1)5list should containDuplicates(4, 4)6list should not containDuplicates(1, 2, 3)7list should containDuplicates(4, 4, 4)8list should containDuplicates(1, 2, 3, 4, 4)9list should containDuplicates(1, 2, 3, 4, 4, 4)10list should containDuplicates(1, 2, 3, 4, 4, 4, 5)11list should containDuplicates(1, 2, 3, 4, 4, 4, 5, 6)12list should not containDuplicates(1, 2, 3, 4, 4, 4, 5, 6, 7)13val list = listOf(1, 2, 3, 4, 4)14list should containDuplicates()15list should containDuplicates(4)16list should not containDuplicates(1)17list should containDuplicates(4, 4)18list should not containDuplicates(1, 2, 3)19list should containDuplicates(4, 4, 4)20list should containDuplicates(1, 2, 3, 4, 4)21list should containDuplicates(1, 2, 3, 4, 4, 4)22list should containDuplicates(1, 2, 3, 4, 4, 4, 5)23list should containDuplicates(1, 2, 3, 4, 4, 4, 5, 6)24list should not containDuplicates(1, 2, 3, 4, 4, 4, 5, 6, 7)

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