How to use test method of io.kotest.matchers.bigdecimal.matchers class

Best Kotest code snippet using io.kotest.matchers.bigdecimal.matchers.test

PizzaTest.kt

Source:PizzaTest.kt Github

copy

Full Screen

1package ru.mplain.store.pizza2import com.fasterxml.jackson.databind.ObjectMapper3import com.fasterxml.jackson.module.kotlin.readValue4import com.ninjasquad.springmockk.MockkBean5import io.kotest.core.extensions.Extension6import io.kotest.core.spec.style.FeatureSpec7import io.kotest.core.test.TestCase8import io.kotest.core.test.TestResult9import io.kotest.extensions.spring.SpringExtension10import io.kotest.matchers.longs.shouldBeGreaterThan11import io.kotest.matchers.nulls.shouldBeNull12import io.kotest.matchers.should13import io.kotest.matchers.shouldBe14import io.mockk.clearAllMocks15import io.mockk.every16import kotlinx.coroutines.delay17import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc18import org.springframework.boot.test.context.SpringBootTest19import org.springframework.http.HttpStatus20import org.springframework.test.web.servlet.MockMvc21import org.springframework.test.web.servlet.ResultActionsDsl22import org.springframework.test.web.servlet.get23import org.springframework.test.web.servlet.post24import ru.mplain.store.accounting.model.FoodType25import ru.mplain.store.accounting.model.Order26import ru.mplain.store.accounting.model.Status27import ru.mplain.store.accounting.service.client.PricesClient28import ru.mplain.store.accounting.service.client.PricesClientDev29import ru.mplain.store.pizza.model.PizzaInMenu30import java.math.BigDecimal31import kotlin.text.Charsets.UTF_832@SpringBootTest33@AutoConfigureMockMvc34class PizzaTest(private val mockMvc: MockMvc, private val objectMapper: ObjectMapper) : FeatureSpec() {35 @MockkBean36 private lateinit var pricesClient: PricesClient37 private val pricesClientDev = PricesClientDev()38 override fun extensions(): List<Extension> = listOf(SpringExtension)39 override suspend fun beforeEach(testCase: TestCase) {40 every { pricesClient.getIngredientPrice(any()) } answers { pricesClientDev.getIngredientPrice(firstArg()) }41 }42 override suspend fun afterEach(testCase: TestCase, result: TestResult) {43 clearAllMocks()44 }45 init {46 feature("order pizza") {47 scenario("success") {48 val pizzaMenu = getPizzaMenu()49 val pizza = pizzaMenu.first()50 val cash = pizza.price + BigDecimal.ONE51 val order = orderPizza(pizza.name, cash)52 order should {53 it.id shouldBeGreaterThan 054 it.type shouldBe FoodType.PIZZA55 it.name shouldBe pizza.name56 it.cash shouldBe cash...

Full Screen

Full Screen

CoffeeTest.kt

Source:CoffeeTest.kt Github

copy

Full Screen

1package ru.mplain.store.coffee2import com.fasterxml.jackson.databind.ObjectMapper3import com.fasterxml.jackson.module.kotlin.readValue4import com.ninjasquad.springmockk.MockkBean5import io.kotest.core.extensions.Extension6import io.kotest.core.spec.style.FeatureSpec7import io.kotest.core.test.TestCase8import io.kotest.core.test.TestResult9import io.kotest.extensions.spring.SpringExtension10import io.kotest.matchers.longs.shouldBeGreaterThan11import io.kotest.matchers.nulls.shouldBeNull12import io.kotest.matchers.should13import io.kotest.matchers.shouldBe14import io.mockk.clearAllMocks15import io.mockk.every16import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc17import org.springframework.boot.test.context.SpringBootTest18import org.springframework.http.HttpStatus19import org.springframework.test.web.servlet.MockMvc20import org.springframework.test.web.servlet.ResultActionsDsl21import org.springframework.test.web.servlet.get22import org.springframework.test.web.servlet.post23import ru.mplain.store.accounting.model.FoodType24import ru.mplain.store.accounting.model.Order25import ru.mplain.store.accounting.model.Status26import ru.mplain.store.accounting.service.client.PricesClient27import ru.mplain.store.accounting.service.client.PricesClientDev28import ru.mplain.store.coffee.model.CoffeeInMenu29import java.math.BigDecimal30import kotlin.text.Charsets.UTF_831@SpringBootTest32@AutoConfigureMockMvc33class CoffeeTest(private val mockMvc: MockMvc, private val objectMapper: ObjectMapper) : FeatureSpec() {34 @MockkBean35 private lateinit var pricesClient: PricesClient36 private val pricesClientDev = PricesClientDev()37 override fun extensions(): List<Extension> = listOf(SpringExtension)38 override suspend fun beforeEach(testCase: TestCase) {39 every { pricesClient.getCoffeePrice(any()) } answers { pricesClientDev.getCoffeePrice(firstArg()) }40 }41 override suspend fun afterEach(testCase: TestCase, result: TestResult) {42 clearAllMocks()43 }44 init {45 feature("order coffee") {46 scenario("success") {47 val coffeeMenu = getCoffeeMenu()48 val coffee = coffeeMenu.first()49 val cash = coffee.price + BigDecimal.ONE50 val order = orderCoffee(coffee.name, cash)51 order should {52 it.id shouldBeGreaterThan 053 it.type shouldBe FoodType.COFFEE54 it.name shouldBe coffee.name55 it.cash shouldBe cash...

Full Screen

Full Screen

ResolversTest.kt

Source:ResolversTest.kt Github

copy

Full Screen

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}...

Full Screen

Full Screen

OrderTest.kt

Source:OrderTest.kt Github

copy

Full Screen

...7import com.polyakovworkbox.stringconcatcourse.flightManagement.domain.orderId8import com.polyakovworkbox.stringconcatcourse.flightManagement.domain.passenger9import com.polyakovworkbox.stringconcatcourse.flightManagement.domain.price10import com.polyakovworkbox.stringconcatcourse.flightManagement.domain.ticketId11import io.kotest.assertions.arrow.either.shouldBeLeft12import io.kotest.assertions.arrow.either.shouldBeRight13import io.kotest.matchers.collections.shouldBeEmpty14import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder15import io.kotest.matchers.comparables.shouldBeEqualComparingTo16import io.kotest.matchers.shouldBe17import org.junit.jupiter.api.Test18import java.math.BigDecimal19internal class OrderTest {20 val orderId = orderId()21 private val idGenerator = object : OrderIdGenerator {22 override fun generate() = orderId23 }24 @Test25 fun `create order - success`() {26 val email = email()27 val orderItems = listOf(orderItem(), orderItem(), orderItem())28 val result = Order.createOrder(idGenerator, TicketIsAvailable, email, orderItems)29 result shouldBeRight {30 it.email shouldBe email...

Full Screen

Full Screen

OrderServiceUnitTest.kt

Source:OrderServiceUnitTest.kt Github

copy

Full Screen

...3import com.rarible.flow.api.createOrder4import com.rarible.flow.core.domain.FlowAssetFungible5import com.rarible.flow.core.domain.ItemId6import com.rarible.flow.core.repository.OrderRepository7import io.kotest.core.spec.style.FunSpec8import io.kotest.matchers.collections.shouldContainAll9import io.kotest.matchers.collections.shouldContainExactly10import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder11import io.kotest.matchers.collections.shouldHaveSize12import io.mockk.every13import io.mockk.mockk14import kotlinx.coroutines.flow.toList15import reactor.core.publisher.Flux16import java.math.BigDecimal17internal class OrderServiceUnitTest: FunSpec({18 test("should return sell orders currencies") {19 val repo = mockk<OrderRepository>() {20 every { findAllByMake(any(), any()) } returns Flux.fromIterable(21 listOf(22 createOrder(),23 createOrder(),24 createOrder().copy(take = FlowAssetFungible("FUSD", BigDecimal.TEN)),25 )26 )27 }28 OrderService(repo).sellCurrenciesByItemId(29 ItemId(FlowAddress("0x01").formatted, 1)30 ).toList() shouldContainExactlyInAnyOrder listOf(31 FlowAssetFungible("FLOW", BigDecimal.ZERO),32 FlowAssetFungible("FUSD", BigDecimal.ZERO),33 )34 }35 test("should return sell orders currencies - empty") {36 val repo = mockk<OrderRepository>() {37 every { findAllByMake(any(), any()) } returns Flux.empty()38 }39 OrderService(repo).sellCurrenciesByItemId(40 ItemId(FlowAddress("0x01").formatted, 1)41 ).toList() shouldHaveSize 042 }43 test("should return bid orders currencies") {44 val repo = mockk<OrderRepository>() {45 every { findAllByTake(any(), any()) } returns Flux.fromIterable(46 listOf(47 createOrder().let {48 it.copy(make = it.take, take = it.make)49 },50 createOrder().copy(make = FlowAssetFungible("FUSD", BigDecimal.TEN)),51 createOrder().copy(make = FlowAssetFungible("FUSD", BigDecimal.TEN))52 )53 )54 }55 OrderService(repo).bidCurrenciesByItemId(56 ItemId(FlowAddress("0x01").formatted, 1)57 ).toList() shouldContainExactlyInAnyOrder listOf(58 FlowAssetFungible("FLOW", BigDecimal.ZERO),59 FlowAssetFungible("FUSD", BigDecimal.ZERO),60 )61 }62 test("should return bid orders currencies - empty") {63 val repo = mockk<OrderRepository>() {64 every { findAllByTake(any(), any()) } returns Flux.empty()65 }66 OrderService(repo).bidCurrenciesByItemId(67 ItemId(FlowAddress("0x01").formatted, 1)68 ).toList() shouldHaveSize 069 }70})

Full Screen

Full Screen

UseRepositoryTest.kt

Source:UseRepositoryTest.kt Github

copy

Full Screen

...15 * You should have received a copy of the GNU Affero General Public License16 * along with this program. If not, see <https://www.gnu.org/licenses/>.17 */18package br.com.colman.petals.use.repository19import io.kotest.core.spec.IsolationMode20import io.kotest.core.spec.style.FunSpec21import io.kotest.matchers.collections.shouldBeEmpty22import io.kotest.matchers.collections.shouldNotBeEmpty23import io.kotest.matchers.shouldBe24import io.objectbox.kotlin.boxFor25import kotlinx.coroutines.flow.first26import java.math.BigDecimal27class UseRepositoryTest : FunSpec({28 val box = MyObjectBox.builder().build().boxFor<Use>()29 beforeEach { box.removeAll() }30 val target = UseRepository(box)31 val use = Use(amountGrams = BigDecimal("1234.567"), costPerGram = BigDecimal("123.01"))32 test("Insert") {33 target.insert(use)34 box.all.single() shouldBe use35 }36 test("Get all") {37 box.put(use)38 target.all().first().single() shouldBe use39 }40 test("Delete") {41 box.put(use)42 box.all.shouldNotBeEmpty()43 target.delete(use)44 box.all.shouldBeEmpty()45 }46 test("Last use") {47 val useBefore = use.copy(date = use.date.minusYears(1), id = 0)48 box.put(use)49 box.put(useBefore)50 target.getLastUse().first() shouldBe use51 target.getLastUseDate().first() shouldBe use.date52 }53 isolationMode = IsolationMode.SingleInstance54})...

Full Screen

Full Screen

TransactionTest.kt

Source:TransactionTest.kt Github

copy

Full Screen

1import io.kotest.matchers.comparables.shouldBeEqualComparingTo2import io.kotest.matchers.date.shouldBeBefore3import io.kotest.matchers.should4import io.kotest.matchers.shouldBe5import org.junit.jupiter.api.BeforeEach6import org.junit.jupiter.api.Test7import java.math.BigDecimal8import java.time.LocalDateTime9internal class TransactionTest {10 private lateinit var instance: Transaction;11 @BeforeEach12 fun setup() {13 instance = Transaction(14 "test",15 LocalDateTime.now(),16 BigDecimal.valueOf(5.0),17 "testMerchant",18 TransactionType.PAYMENT,19 ""20 )21 }22 @Test23 fun `verify the Transaction instance`() {24 instance.id shouldBe "test"25 instance.transactedAt shouldBeBefore LocalDateTime.now()26 instance.amount shouldBeEqualComparingTo BigDecimal.valueOf(5.0)27 instance.merchantName shouldBe "testMerchant"28 instance.type shouldBe TransactionType.PAYMENT29 instance.relatedTransactionId shouldBe ""30 instance should {31 it.id shouldBe "test"32 }33 }34}...

Full Screen

Full Screen

BigDecimalConverterTest.kt

Source:BigDecimalConverterTest.kt Github

copy

Full Screen

1package br.com.colman.petals.use.repository.converter2import io.kotest.core.spec.style.FunSpec3import io.kotest.matchers.shouldBe4import io.kotest.matchers.string.shouldMatch5import io.kotest.property.Arb6import io.kotest.property.arbitrary.bigDecimal7import io.kotest.property.arbitrary.map8import io.kotest.property.checkAll9class BigDecimalConverterTest : FunSpec({10 val target = BigDecimalConverter()11 include(propertyConverterTests(target))12 test("Converts BigDecimal to numeric, decimal strings") {13 Arb.bigDecimal().map { target.convertToDatabaseValue(it)!! }.checkAll {14 it shouldMatch "[-]?[0-9]+\\.[0-9]+"15 }16 }17 test("Converts numeric strings to big decimal") {18 Arb.bigDecimal().map { it to it.toPlainString() }.checkAll {19 val (bigDecimal, str) = it20 target.convertToEntityProperty(str) shouldBe bigDecimal21 }22 }23})...

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1import io.kotest.matchers.bigdecimal.matchers2import org.junit.Test3import java.math.BigDecimal4import java.math.MathContext5import java.math.RoundingMode6import kotlin.test.assertEquals7import kotlin.test.assertTrue8class BigDecimalTest {9fun testBigDecimal() {10val a = BigDecimal(1.0)11val b = BigDecimal(0.9)12val c = BigDecimal(0.8)13val d = BigDecimal(0.7)14val e = BigDecimal(0.6)15val f = BigDecimal(0.5)16val g = BigDecimal(0.4)17val h = BigDecimal(0.3)18val i = BigDecimal(0.2)19val j = BigDecimal(0.1)20val k = BigDecimal(0.0)21val l = BigDecimal(1.0)22val m = BigDecimal(0.9)23val n = BigDecimal(0.8)24val o = BigDecimal(0.7)25val p = BigDecimal(0.6)26val q = BigDecimal(0.5)27val r = BigDecimal(0.4)28val s = BigDecimal(0.3)29val t = BigDecimal(0.2)30val u = BigDecimal(0.1)31val v = BigDecimal(0.0)32val w = BigDecimal(1.0)33val x = BigDecimal(0.9)34val y = BigDecimal(0.8)35val z = BigDecimal(0.7)36val aa = BigDecimal(0.6)37val bb = BigDecimal(0.5)38val cc = BigDecimal(0.4)39val dd = BigDecimal(0.3)40val ee = BigDecimal(0.2)41val ff = BigDecimal(0.1)42val gg = BigDecimal(0.0)43val hh = BigDecimal(1.0)44val ii = BigDecimal(0.9)45val jj = BigDecimal(0.8)46val kk = BigDecimal(0.7)47val ll = BigDecimal(0.6)48val mm = BigDecimal(0.5)49val nn = BigDecimal(0.4)50val oo = BigDecimal(0.3)51val pp = BigDecimal(0.2)52val qq = BigDecimal(0.1)53val rr = BigDecimal(0.0)54val ss = BigDecimal(1.0)55val tt = BigDecimal(0.9)56val uu = BigDecimal(0.8)57val vv = BigDecimal(0.7)58val ww = BigDecimal(0.6

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.

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful