Best Kotest code snippet using io.kotest.matchers.short.short.test
UrlControllerTest.kt
Source:UrlControllerTest.kt
...9import com.falcon.falcon.core.usecase.url.deleteshortenurl.DeleteShortenedUrl10import com.falcon.falcon.core.usecase.url.shortenurl.UrlShortener11import com.falcon.falcon.core.usecase.urlredirect.history.UrlRedirectHistoryUseCase12import com.falcon.falcon.validate13import io.kotest.matchers.collections.shouldBeEmpty14import io.kotest.matchers.ints.shouldBeExactly15import io.kotest.matchers.nulls.shouldBeNull16import io.kotest.matchers.shouldBe17import io.kotest.matchers.types.shouldBeTypeOf18import io.mockk.*19import org.junit.jupiter.api.BeforeEach20import org.junit.jupiter.api.Nested21import org.junit.jupiter.api.Test22import org.junit.jupiter.api.TestInstance23import org.junit.jupiter.api.extension.ExtensionContext24import org.junit.jupiter.params.ParameterizedTest25import org.junit.jupiter.params.provider.Arguments26import org.junit.jupiter.params.provider.ArgumentsProvider27import org.junit.jupiter.params.provider.ArgumentsSource28import org.springframework.http.HttpStatus29import org.springframework.http.ResponseEntity30import org.springframework.security.core.Authentication31import java.time.Instant32import java.util.stream.Stream33import javax.servlet.http.HttpServletRequest34@TestInstance(TestInstance.Lifecycle.PER_CLASS)35class UrlControllerTest {36 private val randomShortUrlUseCase: UrlShortener = mockk()37 private val customShortUrlUseCase: UrlShortener = mockk()38 private val getUserUrlsUseCase: GetUserUrlsUseCase = mockk()39 private val urlRedirectHistoryUseCase: UrlRedirectHistoryUseCase = mockk()40 private val servletRequest: HttpServletRequest = spyk()41 private val deleteShortenedUrlUseCase: DeleteShortenedUrl = mockk()42 private val authentication: Authentication = mockk()43 private val controller = UrlController(44 randomShortUrlUseCase,45 customShortUrlUseCase,46 deleteShortenedUrlUseCase,47 urlRedirectHistoryUseCase,48 getUserUrlsUseCase49 )50 @BeforeEach51 fun init() {52 clearAllMocks()53 }54 @Nested55 inner class ShortenToRandomUrl {56 @Test57 fun `Should convert then return ResponseEntity of ShortenUrlResponse with HttpStatus CREATED`() {58 // Given59 val request = CreationUtils.buildRandomShortenUrlRequest()60 val user = User("dummy-user", "dummy-password")61 val expectedRequest = Url(longUrl = request.longUrl!!, type = UrlType.RANDOM, expirationDate = null)62 val expectedResponse = CreationUtils.buildShortenUrlResponse()63 every {64 randomShortUrlUseCase.execute(65 expectedRequest,66 user67 )68 } returns Url(shortUrl = expectedResponse.shortUrl)69 every { authentication.principal } returns UserDetailsImpl(user)70 every { servletRequest.requestURL } returns StringBuffer("dummy")71 every { servletRequest.requestURI } returns "dummy"72 // When73 val result = controller.shortenToRandomUrl(request, authentication, servletRequest)74 // Then75 verify(exactly = 1) { randomShortUrlUseCase.execute(request.toDomain(), user) }76 result.statusCode.shouldBe(HttpStatus.CREATED)77 result.body!!.shortUrl.shouldBe("/${expectedResponse.shortUrl}")78 result.shouldBeTypeOf<ResponseEntity<ShortenUrlResponse>>()79 }80 }81 @Nested82 inner class ShortenToCustomUrl {83 @Test84 fun `Should convert then return ResponseEntity of ShortenUrlResponse with HttpStatus CREATED`() {85 // Given86 val request = CreationUtils.buildCustomShortenUrlRequest()87 val expectedRequest =88 Url(shortUrl = request.customUrl!!, longUrl = request.longUrl!!, type = UrlType.CUSTOM)89 val expectedResponse = CreationUtils.buildShortenUrlResponse()90 val user = User("dummy-username", "dummy-password")91 every { customShortUrlUseCase.execute(expectedRequest, user) } returns92 Url(shortUrl = expectedResponse.shortUrl)93 every { authentication.principal } returns UserDetailsImpl(user)94 every { servletRequest.requestURL } returns StringBuffer("dummy")95 every { servletRequest.requestURI } returns "dummy"96 // When97 val result = controller.shortenToCustomUrl(request, authentication, servletRequest)98 // Then99 verify(exactly = 1) { customShortUrlUseCase.execute(request.toDomain(), user) }100 result.statusCode.shouldBe(HttpStatus.CREATED)101 result.body!!.shortUrl.shouldBe("/${expectedResponse.shortUrl}")102 result.shouldBeTypeOf<ResponseEntity<ShortenUrlResponse>>()103 }104 }105 @Nested106 inner class DeleteShortenedLongUrl {107 @Test108 fun `Should convert then return ResponseEntity of Void with HttpStatus NO_CONTENT`() {109 // Given110 val request = "this-is-a-shortened-url"111 val user = User("dummy-username", "dummy-password")112 justRun { deleteShortenedUrlUseCase.execute(request, user) }113 every { authentication.principal } returns UserDetailsImpl(user)114 // When115 val result = controller.deleteShortenedUrl(request, authentication)116 // Then117 verify(exactly = 1) { deleteShortenedUrlUseCase.execute(request, user) }118 result.statusCode.shouldBe(HttpStatus.NO_CONTENT)119 result.body.shouldBeNull()120 result.shouldBeTypeOf<ResponseEntity<Void>>()121 }122 }123 @Nested124 inner class GetUrlsByUsername {125 @Test126 fun `Get empty list of urls by token valid`() {127 val user = User("dummy-username", "dummy-password")128 every { authentication.principal } returns UserDetailsImpl(user)129 every { getUserUrlsUseCase(any()) } returns emptyList()130 val result = controller.getUrlByUser(authentication, servletRequest)131 verify(exactly = 1) {getUserUrlsUseCase.invoke(any())}132 result.statusCode.shouldBe(HttpStatus.OK)133 result.body.shouldBeEmpty()134 }135 @Test136 fun `Get list of urls by token valid`() {137 val user = User("dummy-username", "dummy-password")138 every { authentication.principal } returns UserDetailsImpl(user)139 every { getUserUrlsUseCase(any()) } returns arrayListOf(Url("test","test","test", UrlType.RANDOM, Instant.now()))140 val result = controller.getUrlByUser(authentication, servletRequest)141 verify(exactly = 1) {getUserUrlsUseCase.invoke(any())}142 result.statusCode.shouldBe(HttpStatus.OK)143 result.body!!.size.shouldBe(1)144 }145 }146 @ParameterizedTest147 @ArgumentsSource(RandomShortenUrlRequestProvider::class)148 fun `Should validate RandomShortenUrlRequest correctly`(candidate: ValidateBeans<RandomShortenUrlRequest>) {149 candidate.input.validate().size.shouldBeExactly(candidate.errorsExpected)150 }151 @ParameterizedTest152 @ArgumentsSource(CustomShortenUrlRequestProvider::class)153 fun `Should validate CustomShortenUrlRequest correctly`(candidate: ValidateBeans<CustomShortenUrlRequest>) {...
UrlDataProviderImplTest.kt
Source:UrlDataProviderImplTest.kt
1package com.falcon.falcon.dataprovider.persistence.url2import com.falcon.falcon.core.entity.Url3import com.falcon.falcon.core.enumeration.UrlType4import io.kotest.matchers.booleans.shouldBeFalse5import io.kotest.matchers.booleans.shouldBeTrue6import io.kotest.matchers.nulls.shouldNotBeNull7import io.kotest.matchers.shouldBe8import io.kotest.matchers.types.shouldBeTypeOf9import io.mockk.clearAllMocks10import io.mockk.every11import io.mockk.justRun12import io.mockk.mockk13import io.mockk.verify14import org.junit.jupiter.api.BeforeEach15import org.junit.jupiter.api.Nested16import org.junit.jupiter.api.Test17import org.junit.jupiter.api.TestInstance18@TestInstance(TestInstance.Lifecycle.PER_CLASS)19class UrlDataProviderImplTest {20 private val repository: UrlRepository = mockk()21 private val provider: UrlDataProvider = UrlDataProviderImpl(repository)22 @BeforeEach23 fun init() {24 clearAllMocks()25 }26 @Nested27 inner class Save {28 @Test29 fun `Should convert before sending to repository and returning`() {30 // Given31 val shortUrl = "dummy-url"32 val longUrl = "long-url"33 val user = "user"34 val urlType = UrlType.RANDOM35 val request = Url(shortUrl, longUrl, user, urlType, expirationDate = null)36 val expectedRequest = UrlEntity(shortUrl, longUrl, user, urlType)37 every { repository.save(expectedRequest) } returns expectedRequest38 // When39 val result = provider.save(request)40 // Then41 verify(exactly = 1) { repository.save(expectedRequest) }42 result.shouldBeTypeOf<Url>()43 }44 }45 @Nested46 inner class UrlAlreadyExists {47 @Test48 fun `Should return true if exists by ID`() {49 // Given50 val request = "dummy-url"51 every { repository.existsById(request) } returns true52 // When53 val result = provider.urlAlreadyExists(request)54 // Then55 verify(exactly = 1) { repository.existsById(request) }56 result.shouldBeTrue()57 }58 @Test59 fun `Should return false if does not exist by ID`() {60 // Given61 val request = "dummy-url"62 every { repository.existsById(request) } returns false63 // When64 val result = provider.urlAlreadyExists(request)65 // Then66 verify(exactly = 1) { repository.existsById(request) }67 result.shouldBeFalse()68 }69 }70 @Nested71 inner class Delete {72 @Test73 fun `Should convert before sending to repository and return Unit`() {74 // Given75 val shortUrl = "dummy-url"76 val longUrl = "long-url"77 val user = "user"78 val urlType = UrlType.RANDOM79 val request = Url(shortUrl, longUrl, user, urlType, expirationDate = null)80 val expectedRequest = UrlEntity(shortUrl, longUrl, user, urlType)81 justRun { repository.delete(expectedRequest) }82 // When83 val result = provider.delete(request)84 // Then85 verify(exactly = 1) { repository.delete(expectedRequest) }86 result.shouldBeTypeOf<Unit>()87 }88 }89 @Nested90 inner class GetByShortUrl {91 @Test92 fun `Should convert and return if url exists`() {93 // Given94 val shortUrl = "dummy-url"95 val longUrl = "long-url"96 val user = "user"97 val urlType = UrlType.RANDOM98 val response = UrlEntity(shortUrl, longUrl, user, urlType)99 val expectedResponse = Url(shortUrl, longUrl, user, urlType, expirationDate = null)100 every { repository.findByShortUrl(shortUrl) } returns response101 // When102 val result = provider.getByShortUrl(shortUrl)103 // Then104 verify(exactly = 1) { repository.findByShortUrl(shortUrl) }105 result.shouldBe(expectedResponse)106 }107 @Test108 fun `Should return null if url does not exist`() {109 // Given110 val shortUrl = "dummy-url"111 every { repository.findByShortUrl(shortUrl) } returns null112 // When113 val result = provider.getByShortUrl(shortUrl)114 // Then115 verify(exactly = 1) { repository.findByShortUrl(shortUrl) }116 result.shouldBe(null)117 }118 }119 @Nested120 inner class GetByShortUrlAndUserIdentifier {121 @Test122 fun `Should return null if url and user exist`() {123 // Given124 val shortUrl = "dummy-url"125 val userIdentifier = "test"126 val urlEntity = UrlEntity("", "", "", UrlType.RANDOM, 1)127 every { repository.findByShortUrlAndUserIdentifier(shortUrl, userIdentifier) } returns urlEntity128 // When129 val result = provider.getByShortUrlAndUserIdentifier(shortUrl, userIdentifier)130 // Then131 verify(exactly = 1) { repository.findByShortUrlAndUserIdentifier(shortUrl, userIdentifier) }132 result.shouldNotBeNull()133 }134 @Test135 fun `Should return null if url and user does not exist`() {136 // Given137 val shortUrl = "dummy-url"138 val userIdentifier = "test"139 every { repository.findByShortUrlAndUserIdentifier(shortUrl, userIdentifier) } returns null140 // When141 val result = provider.getByShortUrlAndUserIdentifier(shortUrl, userIdentifier)142 // Then143 verify(exactly = 1) { repository.findByShortUrlAndUserIdentifier(shortUrl, userIdentifier) }144 result.shouldBe(null)145 }146 @Nested147 inner class GetAllUrlsByUserIdentifier {148 @Test149 fun `Should return null if user exist`() {150 // Given151 val userIdentifier = "test"152 val urlEntity = UrlEntity("", "", "", UrlType.RANDOM, 1)153 val list = listOf(urlEntity)154 every { repository.findAllByUserIdentifier(userIdentifier) } returns list155 // When156 val result = provider.getAllUrlsByUserIdentifier(userIdentifier)157 // Then158 verify(exactly = 1) { repository.findAllByUserIdentifier(userIdentifier) }159 result.shouldNotBeNull()160 }161 @Test162 fun `Should return null if user does not exist`() {163 // Given164 val userIdentifier = "test"165 every { repository.findAllByUserIdentifier(userIdentifier) } returns emptyList()166 // When167 val result = provider.getAllUrlsByUserIdentifier(userIdentifier)168 // Then169 verify(exactly = 1) { repository.findAllByUserIdentifier(userIdentifier) }170 result.size.shouldBe(0)171 }172 }173 }174}...
AttemptTest.kt
Source:AttemptTest.kt
...5import com.domingoslatorre.teacherbot.teacherbotdiscord.modules.quiz.question.ShortAnswer6import com.domingoslatorre.teacherbot.teacherbotdiscord.modules.quiz.question.ShortQuestion7import com.domingoslatorre.teacherbot.teacherbotdiscord.modules.quiz.question.TrueFalseAnswer8import com.domingoslatorre.teacherbot.teacherbotdiscord.modules.quiz.question.TrueFalseQuestion9import io.kotest.core.spec.style.StringSpec10import io.kotest.matchers.booleans.shouldBeFalse11import io.kotest.matchers.booleans.shouldBeTrue12import io.kotest.matchers.collections.shouldHaveSize13import io.kotest.matchers.nulls.shouldBeNull14import io.kotest.matchers.nulls.shouldNotBeNull15import io.kotest.matchers.shouldBe16class AttemptTest : StringSpec({17 "Create a quiz attempt" {18 val member1 = MemberFactory.member1()19 val question1 = ShortQuestion(20 text = "One plus one equals to ____",21 answers = ShortAnswer(setOf("dois", "2", "two"), "Correct!", true)22 )23 val question2 = TrueFalseQuestion(24 text = "One plus one equals to two",25 answers = listOf(26 TrueFalseAnswer(true, "Correct!", true),27 TrueFalseAnswer(false, "False!", false)28 )29 )...
RoomsKtTest.kt
Source:RoomsKtTest.kt
1package com.tylerkindy.betrayal.db2import com.tylerkindy.betrayal.Direction3import io.kotest.assertions.throwables.shouldThrow4import io.kotest.core.spec.style.DescribeSpec5import io.kotest.matchers.collections.shouldBeEmpty6import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder7import io.kotest.matchers.should8import io.kotest.matchers.shouldBe9import io.kotest.property.Arb10import io.kotest.property.Exhaustive11import io.kotest.property.arbitrary.ShortShrinker12import io.kotest.property.arbitrary.arbitrary13import io.kotest.property.arbitrary.enum14import io.kotest.property.arbitrary.set15import io.kotest.property.checkAll16import io.kotest.property.exhaustive.ints17import io.kotest.property.exhaustive.map18import io.kotest.property.forAll19import org.jetbrains.exposed.sql.insert20import org.jetbrains.exposed.sql.select21import org.jetbrains.exposed.sql.selectAll22import org.jetbrains.exposed.sql.transactions.transaction23import kotlin.random.nextInt24val directionSets = Arb.set(Arb.enum<Direction>(), 0..Direction.values().size)25val rotations = Exhaustive.ints(0..3).map { it.toShort() }26val invalidRotationValues = (Short.MIN_VALUE..Short.MAX_VALUE) - (0..3)27val invalidRotations = arbitrary(listOf(Short.MIN_VALUE, -1, 4, Short.MAX_VALUE), ShortShrinker) {28 it.random.nextInt(invalidRotationValues.indices).let { i -> invalidRotationValues[i] }.toShort()29}30class RoomsKtTest : DescribeSpec({31 useDatabase()32 describe("returnRoomToStack") {...
RandomShortUrlUseCaseTest.kt
Source:RandomShortUrlUseCaseTest.kt
...4import com.falcon.falcon.core.enumeration.UrlType5import com.falcon.falcon.core.enumeration.UserType6import com.falcon.falcon.core.exception.ShortenUrlLimitExceededException7import com.falcon.falcon.dataprovider.persistence.url.UrlDataProvider8import io.kotest.assertions.throwables.shouldThrowExactly9import io.kotest.matchers.ints.shouldBeExactly10import io.kotest.matchers.shouldBe11import io.kotest.matchers.types.shouldBeTypeOf12import io.mockk.clearAllMocks13import io.mockk.every14import io.mockk.mockk15import io.mockk.spyk16import io.mockk.verify17import org.junit.jupiter.api.BeforeEach18import org.junit.jupiter.api.Nested19import org.junit.jupiter.api.Test20import org.junit.jupiter.api.TestInstance21@TestInstance(TestInstance.Lifecycle.PER_CLASS)22class RandomShortUrlUseCaseTest {23 private val urlDataProvider: UrlDataProvider = mockk()24 private val useCase = spyk(RandomShortUrlUseCase(urlDataProvider, 1))25 @BeforeEach...
ResolversTest.kt
Source:ResolversTest.kt
1package org.tesserakt.diskordin.commands.resolver2import arrow.core.Either3import arrow.core.sequenceEither4import io.kotest.assertions.arrow.core.shouldBeLeft5import io.kotest.assertions.arrow.core.shouldBeRight6import io.kotest.core.spec.style.FunSpec7import io.kotest.matchers.collections.shouldContainInOrder8import io.kotest.matchers.should9import io.kotest.matchers.shouldBe10import io.kotest.matchers.types.beOfType11import io.kotest.property.Arb12import io.kotest.property.Gen13import io.kotest.property.PropertyTesting14import io.kotest.property.RandomSource15import io.kotest.property.arbitrary.string16import io.kotest.property.arbitrary.stringPattern17import io.kotest.property.exhaustive.exhaustive18import org.tesserakt.diskordin.commands.CommandContext19import org.tesserakt.diskordin.core.data.DeferredIdentified20import org.tesserakt.diskordin.core.data.EagerIdentified21import org.tesserakt.diskordin.core.entity.IMessage22import org.tesserakt.diskordin.core.entity.IMessageChannel23import org.tesserakt.diskordin.core.entity.IUser24import java.math.BigDecimal25import java.math.BigInteger26class ResolversTest : FunSpec() {27 private val testCount = PropertyTesting.defaultIterationCount.coerceAtMost(256)28 private suspend fun <T : Any, C : CommandContext> test(29 resolver: TypeResolver<T, C>,30 badInput: Gen<String>,31 goodInput: Gen<String>,32 ctx: C33 ): Pair<Either<ParseError, List<T>>, Either<ParseError, List<T>>> {34 val badResult = badInput.generate(RandomSource.default())35 .take(testCount).toList().map { resolver.parse(ctx, it.value) }.sequenceEither()36 val goodResult = goodInput.generate(RandomSource.default())37 .take(testCount).toList().map { resolver.parse(ctx, it.value) }.sequenceEither()38 return badResult to goodResult39 }40 init {41 val fakeContext = object : CommandContext {42 override val message: EagerIdentified<IMessage>43 get() = error("Fake")44 override val author: EagerIdentified<IUser>45 get() = error("Fake")46 override val commandArgs: Array<String>47 get() = error("Fake")48 override val channel: DeferredIdentified<IMessageChannel>49 get() = error("Fake")50 }51 test("Boolean resolver") {52 val bad = Arb.string(0, 100)53 val good = listOf("true", "TRuE", "FalSe", "false").exhaustive()54 val (fail, success) = test(BooleanResolver(), bad, good, fakeContext)55 fail.shouldBeLeft() should beOfType<BooleanResolver.BooleanConversionError>()56 success.shouldBeRight() shouldContainInOrder listOf(true, true, false, false)57 }58 test("String resolver") {59 val bad = Arb.string(0..100)60 val good = Arb.string(0..100)61 val (fail, success) = test(StringResolver(), bad, good, fakeContext)62 fail.shouldBeRight()63 success.shouldBeRight()64 }65 test("Char resolver") {66 val bad = Arb.string(2..100)67 val good = Arb.stringPattern(".")68 val (fail, success) = test(CharResolver(), bad, good, fakeContext)69 fail.shouldBeLeft() shouldBe beOfType<CharResolver.LengthError>()70 success.shouldBeRight()71 }72 context("Number resolvers") {73 fun generateNumberValues(maxSize: Int) =74 Arb.stringPattern("-?\\d{1,$maxSize}")75 suspend fun <N : Number> generateAndTest(maxValue: N, resolver: TypeResolver<N, CommandContext>) {76 val length = BigDecimal(maxValue.toString()).toPlainString().length - 177 println("Next length is $length")78 val bad = Arb.string(0, length)79 val (fail, success) = test(resolver, bad, generateNumberValues(length), fakeContext)80 fail.shouldBeLeft()81 success.shouldBeRight()82 }83 test("Int") { generateAndTest(Int.MAX_VALUE, IntResolver()) }84 test("Long") { generateAndTest(Long.MAX_VALUE, LongResolver()) }85 test("Short") { generateAndTest(Short.MAX_VALUE, ShortResolver()) }86 test("Byte") { generateAndTest(Byte.MAX_VALUE, ByteResolver()) }87 test("Float") { generateAndTest(Float.MAX_VALUE, FloatResolver()) }88 test("Double") { generateAndTest(Double.MAX_VALUE, DoubleResolver()) }89 test("BigInteger") { generateAndTest(BigInteger.valueOf(10).pow(1024), BigIntegerResolver()) }90 test("BigDecimal") { generateAndTest(BigDecimal(10).pow(1024), BigDecimalResolver()) }91 }92 }93}...
InMemoryMaltRepositoryTest.kt
Source:InMemoryMaltRepositoryTest.kt
...3import domain.malt.model.Malt4import domain.malt.model.MaltType5import domain.quantities.Percent6import fixtures.sampleMalt7import io.kotest.core.spec.style.ShouldSpec8import io.kotest.matchers.collections.shouldHaveSize9import io.kotest.matchers.maps.shouldHaveKeys10import io.kotest.matchers.maps.shouldHaveSize11import io.kotest.matchers.shouldBe12class InMemoryMaltRepositoryTest : ShouldSpec({13 val repoUnderTest = InMemoryMaltRepository()14 beforeEach {15 repoUnderTest.clear()16 }17 should("find malt by name") {18 // Given19 repoUnderTest.save(sampleMalt)20 repoUnderTest.save(21 sampleMalt.copy(22 name = "Munich II",23 type = MaltType.MUNICH,24 ebc = 25,25 bestFor = listOf(BeerType.DUBBEL, BeerType.BOCK),...
ValuedEnumLaws.kt
Source:ValuedEnumLaws.kt
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}...
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!!