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

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

matchers.kt

Source:matchers.kt Github

copy

Full Screen

1package tutorial.kotest2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.assertions.throwables.shouldThrowAny4import io.kotest.assertions.throwables.shouldThrowExactly5import io.kotest.core.spec.style.DescribeSpec6import io.kotest.core.test.AssertionMode7import io.kotest.matchers.booleans.shouldBeTrue8import io.kotest.matchers.collections.shouldBeIn9import io.kotest.matchers.collections.shouldBeOneOf10import io.kotest.matchers.collections.shouldBeSameSizeAs11import io.kotest.matchers.collections.shouldBeSingleton12import io.kotest.matchers.collections.shouldBeSmallerThan13import io.kotest.matchers.collections.shouldBeSorted14import io.kotest.matchers.collections.shouldBeUnique15import io.kotest.matchers.collections.shouldContain16import io.kotest.matchers.collections.shouldContainAll17import io.kotest.matchers.collections.shouldContainAnyOf18import io.kotest.matchers.collections.shouldContainDuplicates19import io.kotest.matchers.collections.shouldContainExactly20import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder21import io.kotest.matchers.collections.shouldContainInOrder22import io.kotest.matchers.collections.shouldContainNull23import io.kotest.matchers.collections.shouldEndWith24import io.kotest.matchers.collections.shouldHaveAtLeastSize25import io.kotest.matchers.collections.shouldHaveLowerBound26import io.kotest.matchers.collections.shouldHaveSingleElement27import io.kotest.matchers.collections.shouldHaveSize28import io.kotest.matchers.collections.shouldHaveUpperBound29import io.kotest.matchers.collections.shouldNotContainAnyOf30import io.kotest.matchers.collections.shouldNotHaveElementAt31import io.kotest.matchers.collections.shouldStartWith32import io.kotest.matchers.comparables.shouldBeEqualComparingTo33import io.kotest.matchers.comparables.shouldBeLessThanOrEqualTo34import io.kotest.matchers.date.shouldBeToday35import io.kotest.matchers.date.shouldHaveSameHoursAs36import io.kotest.matchers.doubles.Percentage37import io.kotest.matchers.doubles.beNaN38import io.kotest.matchers.doubles.plusOrMinus39import io.kotest.matchers.doubles.shouldBeNaN40import io.kotest.matchers.doubles.shouldNotBeNaN41import io.kotest.matchers.equality.shouldBeEqualToComparingFields42import io.kotest.matchers.equality.shouldBeEqualToComparingFieldsExcept43import io.kotest.matchers.equality.shouldBeEqualToIgnoringFields44import io.kotest.matchers.equality.shouldBeEqualToUsingFields45import io.kotest.matchers.file.shouldBeADirectory46import io.kotest.matchers.file.shouldBeAbsolute47import io.kotest.matchers.file.shouldExist48import io.kotest.matchers.file.shouldNotBeEmpty49import io.kotest.matchers.ints.beOdd50import io.kotest.matchers.ints.shouldBeBetween51import io.kotest.matchers.ints.shouldBeInRange52import io.kotest.matchers.ints.shouldBeLessThan53import io.kotest.matchers.ints.shouldBeLessThanOrEqual54import io.kotest.matchers.ints.shouldBeOdd55import io.kotest.matchers.ints.shouldBePositive56import io.kotest.matchers.ints.shouldBeZero57import io.kotest.matchers.iterator.shouldBeEmpty58import io.kotest.matchers.iterator.shouldHaveNext59import io.kotest.matchers.maps.shouldBeEmpty60import io.kotest.matchers.maps.shouldContain61import io.kotest.matchers.maps.shouldContainAll62import io.kotest.matchers.maps.shouldContainExactly63import io.kotest.matchers.maps.shouldContainKey64import io.kotest.matchers.nulls.shouldBeNull65import io.kotest.matchers.nulls.shouldNotBeNull66import io.kotest.matchers.shouldBe67import io.kotest.matchers.shouldNot68import io.kotest.matchers.shouldNotBe69import io.kotest.matchers.string.beEmpty70import io.kotest.matchers.string.shouldBeBlank71import io.kotest.matchers.string.shouldBeEmpty72import io.kotest.matchers.string.shouldBeEqualIgnoringCase73import io.kotest.matchers.string.shouldBeInteger74import io.kotest.matchers.string.shouldBeLowerCase75import io.kotest.matchers.string.shouldBeUpperCase76import io.kotest.matchers.string.shouldContain77import io.kotest.matchers.string.shouldContainADigit78import io.kotest.matchers.string.shouldContainIgnoringCase79import io.kotest.matchers.string.shouldContainOnlyDigits80import io.kotest.matchers.string.shouldContainOnlyOnce81import io.kotest.matchers.string.shouldEndWith82import io.kotest.matchers.string.shouldHaveLength83import io.kotest.matchers.string.shouldHaveLineCount84import io.kotest.matchers.string.shouldHaveMaxLength85import io.kotest.matchers.string.shouldHaveMinLength86import io.kotest.matchers.string.shouldHaveSameLengthAs87import io.kotest.matchers.string.shouldMatch88import io.kotest.matchers.string.shouldNotBeEmpty89import io.kotest.matchers.string.shouldStartWith90import io.kotest.matchers.throwable.shouldHaveCause91import io.kotest.matchers.throwable.shouldHaveCauseInstanceOf92import io.kotest.matchers.throwable.shouldHaveCauseOfType93import io.kotest.matchers.throwable.shouldHaveMessage94import io.kotest.matchers.types.shouldBeInstanceOf95import io.kotest.matchers.types.shouldBeSameInstanceAs96import io.kotest.matchers.types.shouldBeTypeOf97import io.kotest.matchers.uri.shouldHaveHost98import io.kotest.matchers.uri.shouldHavePort99import io.kotest.matchers.uri.shouldHaveScheme100import java.io.File101import java.net.URI102import java.time.LocalDate103import java.time.LocalTime104// https://kotest.io/docs/assertions/core-matchers.html105class MatchersTest : DescribeSpec({106 describe("general") {107 it("basics") {108 (1 == 1).shouldBeTrue()109 (2 + 2) shouldBe 4110 val foo: Any = "foobar"111 foo.shouldBeTypeOf<String>() shouldContain "fo"112 "".shouldBeEmpty()113 "x".shouldNot(beEmpty()) // manually negate114 "x".shouldNotBeEmpty() // reusable115 URI("https://tba") shouldHaveHost "tba"116 URI("https://tba:81") shouldHavePort 81117 URI("https://tba") shouldHaveScheme "https"118 File("/").apply {119 shouldExist()120 shouldBeADirectory()121 shouldBeAbsolute()122 shouldNotBeEmpty()123 }124 // executable, hidden, readable, smaller, writeable, containFile, extension, path, ...125 LocalDate.now().shouldBeToday()126 // before/after, within, same, between, have year/month/day/hour/...127 LocalTime.now().shouldHaveSameHoursAs(LocalTime.now())128 // before/after/between, sameMinute/Seconds/Nanos129 }130 it("numbers") {131 1 shouldBeLessThan 2132 1 shouldBeLessThanOrEqual 1 // Int-based; returns this133 1 shouldBeLessThanOrEqualTo 1 // Comparble-based; void134 1 shouldBeEqualComparingTo 1 // Comparable-based135 1.shouldBeBetween(0, 2)136 1 shouldBeInRange 0..2137 0.shouldBeZero()138 1.shouldBePositive()139 1.shouldBeOdd()140 (1.2).shouldBe(1.20001.plusOrMinus(Percentage(20.0)))141 (1.2).shouldNotBeNaN()142 }143 it("strings") {144 // generic: "abc" shouldBe "abc"145 "aBc" shouldBeEqualIgnoringCase "abc"146 "".shouldBeEmpty()147 " ".shouldBeBlank() // empty or whitespace148 "abc" shouldContain ("b")149 "aBc" shouldContainIgnoringCase "bc"150 "x-a-x" shouldContain """\-[a-z]\-""".toRegex()151 "-a-" shouldMatch """\-[a-z]\-""".toRegex()152 "abc" shouldStartWith ("a")153 "abc" shouldEndWith ("c")154 "ab aa" shouldContainOnlyOnce "aa"155 "abc".shouldBeLowerCase()156 "ABC".shouldBeUpperCase()157 "abc" shouldHaveLength 3158 "a\nb" shouldHaveLineCount 2159 "ab" shouldHaveMinLength 1 shouldHaveMaxLength 3160 "abc" shouldHaveSameLengthAs "foo"161 "1".shouldBeInteger()162 "12".shouldContainOnlyDigits()163 "abc1".shouldContainADigit() // at least one164 }165 it("types") {166 @Connotation167 open class SuperType()168 class SubType : SuperType()169 val sameRef = SuperType()170 sameRef.shouldBeSameInstanceAs(sameRef)171 val superType: SuperType = SubType()172 superType.shouldBeTypeOf<SubType>() // exact runtime match (SuperType won't work!)173 superType.shouldBeInstanceOf<SuperType>() // T or below174// SubType().shouldHaveAnnotation(Connotation::class)175 val nullable: String? = null176 nullable.shouldBeNull()177 }178 it("collections") {179 emptyList<Int>().iterator().shouldBeEmpty()180 listOf(1).iterator().shouldHaveNext()181 listOf(1, 2) shouldContain 1 // at least182 listOf(1, 2) shouldContainExactly listOf(1, 2) // in-order; not more183 listOf(1, 2) shouldContainExactlyInAnyOrder listOf(2, 1) // out-order; not more184 listOf(0, 3, 0, 4, 0).shouldContainInOrder(3, 4) // possible items in between185 listOf(1) shouldNotContainAnyOf listOf(2, 3) // black list186 listOf(1, 2, 3) shouldContainAll listOf(3, 2) // out-order; more187 listOf(1, 2, 3).shouldBeUnique() // no duplicates188 listOf(1, 2, 2).shouldContainDuplicates() // at least one duplicate189 listOf(1, 2).shouldNotHaveElementAt(1, 3)190 listOf(1, 2) shouldStartWith 1191 listOf(1, 2) shouldEndWith 2192 listOf(1, 2) shouldContainAnyOf listOf(2, 3)193 val x = SomeType(1)194 x shouldBeOneOf listOf(x) // by reference/instance195 x shouldBeIn listOf(SomeType(1)) // by equality/structural196 listOf(1, 2, null).shouldContainNull()197 listOf(1) shouldHaveSize 1198 listOf(1).shouldBeSingleton() // size == 1199 listOf(1).shouldBeSingleton {200 it.shouldBeOdd()201 }202 listOf(1).shouldHaveSingleElement {203 beOdd().test(it).passed() // have to return a boolean here :-/204 }205 listOf(2, 3) shouldHaveLowerBound 1 shouldHaveUpperBound 4206 listOf(1) shouldBeSmallerThan listOf(1, 2)207 listOf(1) shouldBeSameSizeAs listOf(2)208 listOf(1, 2) shouldHaveAtLeastSize 1209 listOf(1, 2).shouldBeSorted()210 mapOf(1 to "a").shouldContain(1, "a") // at least this211 mapOf(1 to "a") shouldContainAll mapOf(1 to "a") // at least those212 mapOf(1 to "a") shouldContainExactly mapOf(1 to "a") // not more213 mapOf(1 to "a") shouldContainKey 1214 emptyMap<Any, Any>().shouldBeEmpty()215 }216 it("exceptions") {217 class SubException() : Exception()...

Full Screen

Full Screen

CoordinateTest.kt

Source:CoordinateTest.kt Github

copy

Full Screen

1package de.gleex.pltcmd.model.world.coordinate2import de.gleex.pltcmd.util.measure.compass.points.CardinalPoint.*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 }140 checkedCoordinates++141 }142 log.info { "checked $checkedCoordinates different string representations of Coordinate" }143 }144 val expectedString = "(123|345)"145 "be $expectedString for $testCoordinate" {146 testCoordinate.toString() shouldBe expectedString147 }148 "be padded for single digits" {149 toCoordinateString(1, 1) shouldBe "(001|001)"150 toCoordinateString(0, 0) shouldBe "(000|000)"151 toCoordinateString(2, 9) shouldBe "(002|009)"152 toCoordinateString(-1, -9) shouldBe "(-001|-009)"153 toCoordinateString(7, -9) shouldBe "(007|-009)"154 toCoordinateString(-2, 8) shouldBe "(-002|008)"155 }156 "be padded for two digits" {157 toCoordinateString(99, 10) shouldBe "(099|010)"158 toCoordinateString(33, 33) shouldBe "(033|033)"159 toCoordinateString(-11, -99) shouldBe "(-011|-099)"160 toCoordinateString(58, -10) shouldBe "(058|-010)"161 toCoordinateString(-75, 45) shouldBe "(-075|045)"162 }163 }164 "A coordinate created from a string" should {165 forAll(166 row("(001|001)", Coordinate(1, 1)),167 row("(000|000)", Coordinate(0, 0)),168 row("(-100|001)", Coordinate(-100, 1)),169 row("(001|-100)", Coordinate(1, -100)),170 row("(-100|-100)", Coordinate(-100, -100)),171 row("(-123456789|123456789)", Coordinate(-123456789, 123456789)),172 row(" (-100|-100)\t", Coordinate(-100, -100))173 ) { string, validCoordinate ->174 "be valid when created from string '$string'" {175 Coordinate.fromString(string) shouldBe validCoordinate176 }177 }178 forAll(179 row("(123456789|1)"),180 row("(123456789|11)"),181 row("(123456789|-11)"),182 row("(00a1|001)"),183 row("(|000)"),184 row("(--100|001)"),185 row("001|-100)"),186 row("(-100-100)"),187 row("(123456789|1"),188 row(""),189 row(" "),190 row("coordinate")191 ) { someString ->192 "be null when created from invalid string '$someString'" {193 Coordinate.fromString(someString)194 .shouldBeNull()195 }196 }197 }198 "The bearing between coordinates" should {199 "be due for 45° angles" {200 for (delta in 1..100) {201 assertSoftly(202 testCoordinate bearingTo testCoordinate.withRelativeNorthing(delta)203 ) {204 angle shouldBe 0205 roundedCardinal shouldBe N206 isDue shouldBe true207 }208 assertSoftly(209 testCoordinate bearingTo testCoordinate.movedBy(delta, delta)210 ) {211 angle shouldBe 45212 roundedCardinal shouldBe NE213 isDue shouldBe true214 }215 assertSoftly(216 testCoordinate bearingTo testCoordinate.withRelativeEasting(delta)217 ) {218 angle shouldBe 90219 roundedCardinal shouldBe E220 isDue shouldBe true221 }222 assertSoftly(223 testCoordinate bearingTo testCoordinate.movedBy(delta, -delta)224 ) {225 angle shouldBe 135226 roundedCardinal shouldBe SE227 isDue shouldBe true228 }229 assertSoftly(230 testCoordinate bearingTo testCoordinate.withRelativeNorthing(-delta)231 ) {232 angle shouldBe 180233 roundedCardinal shouldBe S234 isDue shouldBe true235 }236 assertSoftly(237 testCoordinate bearingTo testCoordinate.movedBy(-delta, -delta)238 ) {239 angle shouldBe 225240 roundedCardinal shouldBe SW241 isDue shouldBe true242 }243 assertSoftly(244 testCoordinate bearingTo testCoordinate.withRelativeEasting(-delta)245 ) {246 angle shouldBe 270247 roundedCardinal shouldBe W248 isDue shouldBe true249 }250 assertSoftly(251 testCoordinate bearingTo testCoordinate.movedBy(-delta, delta)252 ) {253 angle shouldBe 315254 roundedCardinal shouldBe NW255 isDue shouldBe true256 }257 }258 }259 }260 "The range between two coordinates" should {261 val other = Coordinate(125, 342)262 val range = testCoordinate..other263 "contain all coordinates in the rectangle ordered by the direction from the first to the second point" {264 range shouldContainExactly sequenceOf(265 Coordinate(123, 345),266 Coordinate(124, 345),267 Coordinate(125, 345),268 Coordinate(123, 344),269 Coordinate(124, 344),270 Coordinate(125, 344),271 Coordinate(123, 343),272 Coordinate(124, 343),273 Coordinate(125, 343),274 Coordinate(123, 342),275 Coordinate(124, 342),276 Coordinate(125, 342)...

Full Screen

Full Screen

StringIT.kt

Source:StringIT.kt Github

copy

Full Screen

1package io.github.serpro69.kfaker.provider2import io.github.serpro69.kfaker.faker3import io.github.serpro69.kfaker.provider.misc.StringProvider4import io.kotest.core.spec.style.DescribeSpec5import io.kotest.core.test.TestCase6import io.kotest.matchers.collections.shouldNotContainAnyOf7import io.kotest.matchers.ints.shouldBeLessThan8import io.kotest.matchers.should9import io.kotest.matchers.shouldBe10import io.kotest.matchers.string.beLowerCase11import io.kotest.matchers.string.beUpperCase12import io.kotest.matchers.string.shouldContain13import io.kotest.matchers.string.shouldNotContain14class StringIT : DescribeSpec() {15 private val faker = faker {16 fakerConfig {17 uniqueGeneratorRetryLimit = 100018 }19 }20 private val sourceString = "foo###bar???"21 override fun beforeEach(testCase: TestCase) {22 faker.unique.clearAll()23 faker.string.unique.clearAll()24 }25 init {26 describe("String Provider") {27 context("numerify") {28 it("should NOT contain # chars") {29 faker.string.numerify(sourceString) shouldNotContain "#"30 faker.string.numerify(sourceString) shouldContain "?"31 }32 it("can have duplicates") {33 val list = List(1000) { faker.string.numerify(sourceString) }34 list.distinct().size shouldBeLessThan 100035 }...

Full Screen

Full Screen

WordGeneratorSpec.kt

Source:WordGeneratorSpec.kt Github

copy

Full Screen

...14 * limitations under the License.15 */16@file:Suppress("RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")17package br.com.colman.passphrase18import io.kotest.assertions.throwables.shouldNotThrowAny19import io.kotest.assertions.throwables.shouldThrowAny20import io.kotest.core.spec.style.FunSpec21import io.kotest.inspectors.forAll22import io.kotest.matchers.collections.shouldContainAll23import io.kotest.matchers.collections.shouldHaveSize24import io.kotest.matchers.collections.shouldNotContainDuplicates25import io.kotest.matchers.shouldBe26import io.kotest.matchers.types.shouldBeInstanceOf27import io.kotest.property.Arb28import io.kotest.property.arbitrary.int29import io.kotest.property.checkAll30import java.security.SecureRandom31import kotlin.random.Random32import java.lang.ClassLoader.getSystemResourceAsStream as resource33class WordGeneratorSpec : FunSpec({34 context("Word list") {35 test("Default word list to EFF big word list") {36 val wordlist = resource("eff_large_wordlist.txt").bufferedReader().readLines()37 BigWordList shouldBe wordlist38 WordGenerator.words shouldBe wordlist39 }40 }41 context("Word generator") {42 val target = WordGenerator43 test("Generates exactly how many words I expect") {44 target.generateWords(5) shouldHaveSize 545 target.generateWords(1) shouldHaveSize 146 }47 test("Generates 3 words by default") {48 target.generateWords() shouldHaveSize 349 }50 test("Generates words only from wordlist") {51 val generatedWords = List(1000) { target.generateWords(100) }.flatten()52 WordGenerator.words shouldContainAll generatedWords53 }54 test("Doesn't repeat words in the same generation") {55 val generatedLists = List(1000) { target.generateWords(1000) }56 generatedLists.forAll {57 it.shouldNotContainDuplicates()58 }59 }60 test("Doesn't exhaust word pool when running multiple times") {61 shouldNotThrowAny {62 List(WordGenerator.words.size) { target.generateWords(WordGenerator.words.size) }63 }64 }65 test("Throws an exception when trying to generate < 1 word") {66 Arb.int(max = 0).checkAll {67 shouldThrowAny { target.generateWords(it) }68 }69 }70 test("Throws an exception if trying to generate more words than available") {71 shouldThrowAny { target.generateWords(target.words.size + 1) }72 }73 }74 context("Generator constructor function") {75 test("Uses the list passed as argument") {76 val arg = listOf("a")77 val gen = WordGenerator(arg)78 gen.words shouldBe arg79 }80 test("Has BigWordList as the default word list") {81 val gen = WordGenerator()82 gen.words shouldBe BigWordList83 }84 }85 context("Random number generation") {86 test("Uses the provided random as numbers source") {87 val lists = List(1000) { WordGenerator(random = Random(1)).generateWords(100) }88 lists.forAll {89 it shouldBe lists.first()90 }91 }92 }93})...

Full Screen

Full Screen

UnitTransformationTest.kt

Source:UnitTransformationTest.kt Github

copy

Full Screen

1package de.gleex.pltcmd.game.ui.strings.transformations2import de.gleex.pltcmd.game.ui.strings.Format3import de.gleex.pltcmd.game.ui.strings.extensions.toFrontendString4import de.gleex.pltcmd.model.elements.units.Units5import io.kotest.core.spec.style.WordSpec6import io.kotest.inspectors.forAll7import io.kotest.matchers.collections.beUnique8import io.kotest.matchers.should9import io.kotest.matchers.shouldBe10import io.kotest.matchers.string.beUpperCase11import mu.KotlinLogging12private val log = KotlinLogging.logger {}13class UnitTransformationTest : WordSpec() {14 init {15 "The unit transformation" should {16 "work for units and unit blueprints" {17 Format.values()18 .forAll { format ->19 Units.values()20 .forAll { blueprint ->21 val blueprintValue: String = blueprint.toFrontendString(format).value22 val unitValue: String = blueprint.new()23 .toFrontendString(format).value24 blueprintValue shouldBe unitValue...

Full Screen

Full Screen

EnumGeneratorsTests.kt

Source:EnumGeneratorsTests.kt Github

copy

Full Screen

1package me.kerooker.rpgnpcgenerator.repository.model.random.npc2import io.kotest.matchers.collections.shouldNotContainDuplicates3import io.kotest.matchers.ints.shouldBeInRange4import io.kotest.shouldBe5import io.kotest.specs.FunSpec6class RandomDistributedTest : FunSpec() {7 enum class Randomized(override val distribution: Double):8 RandomDistributed {9 A(19.0),10 B(80.0),11 C(1.0)12 }13 init {14 test("Should have correct weight distribution") {15 val values = Randomized.values().toList()16 var a = 017 var b = 018 var c = 019 repeat(100_000) {20 when(values.distributedRandom()) {21 Randomized.A -> a++22 Randomized.B -> b++23 Randomized.C -> c++24 }25 }26 a shouldBeInRange 18000..2000027 c shouldBeInRange 900..110028 b shouldBeInRange 79000..8100029 }30 }31}32class EnumDistributionTests : FunSpec() {33 private val randomDistributed: Array<Array<out RandomDistributed>> = arrayOf(34 Age.values(),35 Alignment.values(),36 Gender.values(),37 Race.values(),38 Sexuality.values()39 )40 private val namedResources: Array<Array<out NamedResource>> = arrayOf(41 Age.values(),42 Alignment.values(),43 CommonLanguage.values(),44 ExoticLanguage.values(),45 Gender.values(),46 Race.values(),47 Sexuality.values()48 )49 init {50 test("All enums should have their distribution sum 100%") {51 verifyDistribution(*randomDistributed)52 }53 test("All enum named values should be distinct") {54 verifyDistinctNames(*namedResources)55 }56 }57 private fun verifyDistinctNames(vararg namedResources: Array<out NamedResource>) {58 namedResources.flatten().map { it.nameResource }.shouldNotContainDuplicates()59 }60 private fun verifyDistribution(vararg values: Array<out RandomDistributed>) {61 for (value in values) {62 value.toList().sumByDouble { it.distribution } shouldBe 100.063 }64 }65}...

Full Screen

Full Screen

DiceMetricRepositoryInMemoryTest.kt

Source:DiceMetricRepositoryInMemoryTest.kt Github

copy

Full Screen

1package dinf.domain2import io.kotest.core.spec.style.StringSpec3import io.kotest.matchers.collections.shouldContainInOrder4import io.kotest.matchers.collections.shouldHaveSize5import io.kotest.matchers.shouldBe6import io.kotest.matchers.shouldNotBe7import kotlinx.coroutines.flow.toList8class DiceMetricRepositoryInMemoryTest : StringSpec({9 val metrics = DiceMetricRepository.InMemory()10 beforeTest {11 metrics.clear()12 }13 "no metric for unknown id" {14 val metric = metrics.forID(ID.first())15 metric shouldBe null16 }17 "return metric for existing id" {18 val id = ID.first()19 metrics.create(id, Metric.zero())20 val metric = metrics.forID(id)...

Full Screen

Full Screen

ValuedEnumLaws.kt

Source:ValuedEnumLaws.kt Github

copy

Full Screen

1package org.tesserakt.diskordin.util.enums2import io.kotest.core.spec.style.FreeSpec3import io.kotest.core.spec.style.stringSpec4import io.kotest.inspectors.forAll5import io.kotest.matchers.booleans.shouldBeTrue6import io.kotest.matchers.collections.shouldNotContainDuplicates7import io.kotest.matchers.longs.shouldBeLessThanOrEqual8import org.tesserakt.diskordin.core.data.Permission9import org.tesserakt.diskordin.core.entity.IUser10import org.tesserakt.diskordin.core.entity.`object`.IActivity11import org.tesserakt.diskordin.gateway.shard.Intents12import org.tesserakt.diskordin.impl.util.typeclass.numeric13import org.tesserakt.diskordin.util.typeclass.Numeric14import java.util.*15class ValuedEnumLaws : FreeSpec({16 include("Permissions ", Long.numeric().testValuedEnum<Permission, Long>())17 include("Intents ", Short.numeric().testValuedEnum<Intents, Short>())18 include("User.Flags ", Int.numeric().testValuedEnum<IUser.Flags, Int>())19 include("Activity.Flags ", Short.numeric().testValuedEnum<IActivity.Flags, Short>())20})21fun <N> Numeric<N>.isPowerOf2(n: N): Boolean {22 tailrec fun f(init: N, input: N): Boolean = when {23 init > input -> false24 init < input -> f(init * 2.fromInt(), input)25 else -> true26 }27 return f(1.fromInt(), n)28}29inline fun <reified E, N : Any> Numeric<N>.testValuedEnum() where E : Enum<E>, E : IValued<E, N> = stringSpec {30 "All values should be power of two" {31 EnumSet.allOf(E::class.java)32 .map { it.code }.forAll { isPowerOf2(it).shouldBeTrue() }33 }34 "Sum of all codes should be less then MAX_VALUE" {35 EnumSet.allOf(E::class.java).map { it.code }36 .fold(zero) { acc, i -> acc + i }.toLong() shouldBeLessThanOrEqual maxValue.toLong()37 }38 "All values should be unique" {39 EnumSet.allOf(E::class.java).map { it.code }.shouldNotContainDuplicates()40 }41}...

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