From f34282750168eb2c5e9bc0f85b7a47ac2005620a Mon Sep 17 00:00:00 2001 From: Sergey Date: Sun, 21 Feb 2021 16:33:04 +0800 Subject: [PATCH 1/5] dollar created --- .../kotlin/com/stringconcat/tdd/Dollar.kt | 13 ++++++++- .../kotlin/com/stringconcat/com/DollarTest.kt | 14 --------- .../kotlin/com/stringconcat/tdd/DollarTest.kt | 29 +++++++++++++++++++ 3 files changed, 41 insertions(+), 15 deletions(-) delete mode 100644 src/test/kotlin/com/stringconcat/com/DollarTest.kt create mode 100644 src/test/kotlin/com/stringconcat/tdd/DollarTest.kt diff --git a/src/main/kotlin/com/stringconcat/tdd/Dollar.kt b/src/main/kotlin/com/stringconcat/tdd/Dollar.kt index e77bb26..76a7478 100644 --- a/src/main/kotlin/com/stringconcat/tdd/Dollar.kt +++ b/src/main/kotlin/com/stringconcat/tdd/Dollar.kt @@ -2,4 +2,15 @@ package com.stringconcat.tdd class Dollar( val amount: Int -) +) { + + override fun equals(other: Any?): Boolean { + if (other !is Dollar) return false + if (amount == other.amount) return true + return false + } + + operator fun times(multiplier: Int): Dollar { + return Dollar(amount * multiplier) + } +} \ No newline at end of file diff --git a/src/test/kotlin/com/stringconcat/com/DollarTest.kt b/src/test/kotlin/com/stringconcat/com/DollarTest.kt deleted file mode 100644 index 45783be..0000000 --- a/src/test/kotlin/com/stringconcat/com/DollarTest.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.stringconcat.com - -import com.stringconcat.tdd.Dollar -import io.kotest.matchers.shouldBe -import kotlin.test.Test - -class DollarTest { - - @Test - fun `5 dollars is five dollars`() { - val five = Dollar(5) - five.amount shouldBe 5 - } -} \ No newline at end of file diff --git a/src/test/kotlin/com/stringconcat/tdd/DollarTest.kt b/src/test/kotlin/com/stringconcat/tdd/DollarTest.kt new file mode 100644 index 0000000..b423214 --- /dev/null +++ b/src/test/kotlin/com/stringconcat/tdd/DollarTest.kt @@ -0,0 +1,29 @@ +package com.stringconcat.tdd + +import io.kotest.matchers.shouldBe +import io.kotest.matchers.shouldNotBe +import org.junit.jupiter.api.Test + +internal class DollarTest { + + @Test + fun `5 USD has amount of 5`() { + Dollar(5).amount shouldBe 5 + } + + @Test + fun `10 Usd is 10 USD`() { + Dollar(10) shouldBe Dollar(10) + } + + @Test + fun `10 Usd is not 5 USD`() { + Dollar(10) shouldNotBe Dollar(5) + } + + @Test + fun `5 dollar multiply 2 is 10 USD`() { + val ten = Dollar(5) * 2 + ten shouldBe Dollar(10) + } +} \ No newline at end of file From 602235f273cd02a82ada62fb453a50cb497610ed Mon Sep 17 00:00:00 2001 From: Sergey Date: Sun, 21 Feb 2021 16:39:55 +0800 Subject: [PATCH 2/5] franc and money created --- src/main/kotlin/com/stringconcat/tdd/Franc.kt | 16 ++++++++++ src/main/kotlin/com/stringconcat/tdd/Money.kt | 4 +++ .../kotlin/com/stringconcat/tdd/DollarTest.kt | 5 ++++ .../kotlin/com/stringconcat/tdd/FrancTest.kt | 29 +++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 src/main/kotlin/com/stringconcat/tdd/Franc.kt create mode 100644 src/main/kotlin/com/stringconcat/tdd/Money.kt create mode 100644 src/test/kotlin/com/stringconcat/tdd/FrancTest.kt diff --git a/src/main/kotlin/com/stringconcat/tdd/Franc.kt b/src/main/kotlin/com/stringconcat/tdd/Franc.kt new file mode 100644 index 0000000..fdb5880 --- /dev/null +++ b/src/main/kotlin/com/stringconcat/tdd/Franc.kt @@ -0,0 +1,16 @@ +package com.stringconcat.tdd + +class Franc( + val amount: Int +) { + + override fun equals(other: Any?): Boolean { + if (other !is Franc) return false + if (amount == other.amount) return true + return false + } + + operator fun times(multiplier: Int): Franc { + return Franc(amount * multiplier) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/stringconcat/tdd/Money.kt b/src/main/kotlin/com/stringconcat/tdd/Money.kt new file mode 100644 index 0000000..b0a7592 --- /dev/null +++ b/src/main/kotlin/com/stringconcat/tdd/Money.kt @@ -0,0 +1,4 @@ +package com.stringconcat.tdd + +class Money { +} \ No newline at end of file diff --git a/src/test/kotlin/com/stringconcat/tdd/DollarTest.kt b/src/test/kotlin/com/stringconcat/tdd/DollarTest.kt index b423214..eea3441 100644 --- a/src/test/kotlin/com/stringconcat/tdd/DollarTest.kt +++ b/src/test/kotlin/com/stringconcat/tdd/DollarTest.kt @@ -26,4 +26,9 @@ internal class DollarTest { val ten = Dollar(5) * 2 ten shouldBe Dollar(10) } + + @Test + fun `5 USD is not 5 CHF`() { + Dollar(5) shouldNotBe Franc(5) + } } \ No newline at end of file diff --git a/src/test/kotlin/com/stringconcat/tdd/FrancTest.kt b/src/test/kotlin/com/stringconcat/tdd/FrancTest.kt new file mode 100644 index 0000000..f3aeca3 --- /dev/null +++ b/src/test/kotlin/com/stringconcat/tdd/FrancTest.kt @@ -0,0 +1,29 @@ +package com.stringconcat.tdd + +import io.kotest.matchers.shouldBe +import io.kotest.matchers.shouldNotBe +import org.junit.jupiter.api.Test + +internal class FrancTest { + + @Test + fun `5 CHF has amount of 5`() { + Franc(5).amount shouldBe 5 + } + + @Test + fun `10 CHF is 10 CHF`() { + Franc(10) shouldBe Franc(10) + } + + @Test + fun `10 CHF is not 5 CHF`() { + Franc(10) shouldNotBe Franc(5) + } + + @Test + fun `5 CHF multiply 2 is 10 CHF`() { + val ten = Franc(5) * 2 + ten shouldBe Franc(10) + } +} \ No newline at end of file From 2d25ef7384f1e5b542f2c7dbecf9ee878e4df9c1 Mon Sep 17 00:00:00 2001 From: Sergey Date: Sun, 21 Feb 2021 16:50:16 +0800 Subject: [PATCH 3/5] factories created --- src/main/kotlin/com/stringconcat/tdd/Dollar.kt | 10 +++++++--- src/main/kotlin/com/stringconcat/tdd/Franc.kt | 10 +++++++--- src/main/kotlin/com/stringconcat/tdd/Money.kt | 8 +++++++- src/test/kotlin/com/stringconcat/tdd/DollarTest.kt | 12 ++++++------ src/test/kotlin/com/stringconcat/tdd/FrancTest.kt | 10 +++++----- 5 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/com/stringconcat/tdd/Dollar.kt b/src/main/kotlin/com/stringconcat/tdd/Dollar.kt index 76a7478..37d78e8 100644 --- a/src/main/kotlin/com/stringconcat/tdd/Dollar.kt +++ b/src/main/kotlin/com/stringconcat/tdd/Dollar.kt @@ -1,8 +1,8 @@ package com.stringconcat.tdd -class Dollar( - val amount: Int -) { +class Dollar internal constructor( + amount: Int +): Money(amount = amount) { override fun equals(other: Any?): Boolean { if (other !is Dollar) return false @@ -13,4 +13,8 @@ class Dollar( operator fun times(multiplier: Int): Dollar { return Dollar(amount * multiplier) } + + override fun toString(): String { + return "Dollar($amount)" + } } \ No newline at end of file diff --git a/src/main/kotlin/com/stringconcat/tdd/Franc.kt b/src/main/kotlin/com/stringconcat/tdd/Franc.kt index fdb5880..c311933 100644 --- a/src/main/kotlin/com/stringconcat/tdd/Franc.kt +++ b/src/main/kotlin/com/stringconcat/tdd/Franc.kt @@ -1,8 +1,8 @@ package com.stringconcat.tdd -class Franc( - val amount: Int -) { +class Franc internal constructor( + amount: Int +): Money(amount) { override fun equals(other: Any?): Boolean { if (other !is Franc) return false @@ -13,4 +13,8 @@ class Franc( operator fun times(multiplier: Int): Franc { return Franc(amount * multiplier) } + + override fun toString(): String { + return "Franc($amount)" + } } \ No newline at end of file diff --git a/src/main/kotlin/com/stringconcat/tdd/Money.kt b/src/main/kotlin/com/stringconcat/tdd/Money.kt index b0a7592..e62f633 100644 --- a/src/main/kotlin/com/stringconcat/tdd/Money.kt +++ b/src/main/kotlin/com/stringconcat/tdd/Money.kt @@ -1,4 +1,10 @@ package com.stringconcat.tdd -class Money { +abstract class Money( + val amount: Int +) { + companion object { + fun dollar(amount: Int) = Dollar(amount) + fun franc(amount: Int) = Franc(amount) + } } \ No newline at end of file diff --git a/src/test/kotlin/com/stringconcat/tdd/DollarTest.kt b/src/test/kotlin/com/stringconcat/tdd/DollarTest.kt index eea3441..c4170ed 100644 --- a/src/test/kotlin/com/stringconcat/tdd/DollarTest.kt +++ b/src/test/kotlin/com/stringconcat/tdd/DollarTest.kt @@ -8,27 +8,27 @@ internal class DollarTest { @Test fun `5 USD has amount of 5`() { - Dollar(5).amount shouldBe 5 + Money.dollar(5).amount shouldBe 5 } @Test fun `10 Usd is 10 USD`() { - Dollar(10) shouldBe Dollar(10) + Money.dollar(10) shouldBe Money.dollar(10) } @Test fun `10 Usd is not 5 USD`() { - Dollar(10) shouldNotBe Dollar(5) + Money.dollar(10) shouldNotBe Money.dollar(5) } @Test fun `5 dollar multiply 2 is 10 USD`() { - val ten = Dollar(5) * 2 - ten shouldBe Dollar(10) + val ten = Money.dollar(5) * 2 + ten shouldBe Money.dollar(10) } @Test fun `5 USD is not 5 CHF`() { - Dollar(5) shouldNotBe Franc(5) + Money.dollar(5) shouldNotBe Money.franc(5) } } \ No newline at end of file diff --git a/src/test/kotlin/com/stringconcat/tdd/FrancTest.kt b/src/test/kotlin/com/stringconcat/tdd/FrancTest.kt index f3aeca3..f03ae82 100644 --- a/src/test/kotlin/com/stringconcat/tdd/FrancTest.kt +++ b/src/test/kotlin/com/stringconcat/tdd/FrancTest.kt @@ -8,22 +8,22 @@ internal class FrancTest { @Test fun `5 CHF has amount of 5`() { - Franc(5).amount shouldBe 5 + Money.franc(5).amount shouldBe 5 } @Test fun `10 CHF is 10 CHF`() { - Franc(10) shouldBe Franc(10) + Money.franc(10) shouldBe Money.franc(10) } @Test fun `10 CHF is not 5 CHF`() { - Franc(10) shouldNotBe Franc(5) + Money.franc(10) shouldNotBe Money.franc(5) } @Test fun `5 CHF multiply 2 is 10 CHF`() { - val ten = Franc(5) * 2 - ten shouldBe Franc(10) + val ten = Money.franc(5) * 2 + ten shouldBe Money.franc(10) } } \ No newline at end of file From ebaf0c1279825629465b4159bcc9d6e4224dd51a Mon Sep 17 00:00:00 2001 From: Sergey Date: Sun, 21 Feb 2021 17:10:51 +0800 Subject: [PATCH 4/5] dollars and francs have been removed --- .../kotlin/com/stringconcat/tdd/Dollar.kt | 20 ------ src/main/kotlin/com/stringconcat/tdd/Franc.kt | 20 ------ src/main/kotlin/com/stringconcat/tdd/Money.kt | 28 ++++++-- .../kotlin/com/stringconcat/tdd/DollarTest.kt | 34 ---------- .../kotlin/com/stringconcat/tdd/FrancTest.kt | 29 --------- .../kotlin/com/stringconcat/tdd/MoneyTest.kt | 65 +++++++++++++++++++ 6 files changed, 89 insertions(+), 107 deletions(-) delete mode 100644 src/main/kotlin/com/stringconcat/tdd/Dollar.kt delete mode 100644 src/main/kotlin/com/stringconcat/tdd/Franc.kt delete mode 100644 src/test/kotlin/com/stringconcat/tdd/DollarTest.kt delete mode 100644 src/test/kotlin/com/stringconcat/tdd/FrancTest.kt create mode 100644 src/test/kotlin/com/stringconcat/tdd/MoneyTest.kt diff --git a/src/main/kotlin/com/stringconcat/tdd/Dollar.kt b/src/main/kotlin/com/stringconcat/tdd/Dollar.kt deleted file mode 100644 index 37d78e8..0000000 --- a/src/main/kotlin/com/stringconcat/tdd/Dollar.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.stringconcat.tdd - -class Dollar internal constructor( - amount: Int -): Money(amount = amount) { - - override fun equals(other: Any?): Boolean { - if (other !is Dollar) return false - if (amount == other.amount) return true - return false - } - - operator fun times(multiplier: Int): Dollar { - return Dollar(amount * multiplier) - } - - override fun toString(): String { - return "Dollar($amount)" - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/stringconcat/tdd/Franc.kt b/src/main/kotlin/com/stringconcat/tdd/Franc.kt deleted file mode 100644 index c311933..0000000 --- a/src/main/kotlin/com/stringconcat/tdd/Franc.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.stringconcat.tdd - -class Franc internal constructor( - amount: Int -): Money(amount) { - - override fun equals(other: Any?): Boolean { - if (other !is Franc) return false - if (amount == other.amount) return true - return false - } - - operator fun times(multiplier: Int): Franc { - return Franc(amount * multiplier) - } - - override fun toString(): String { - return "Franc($amount)" - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/stringconcat/tdd/Money.kt b/src/main/kotlin/com/stringconcat/tdd/Money.kt index e62f633..73b3174 100644 --- a/src/main/kotlin/com/stringconcat/tdd/Money.kt +++ b/src/main/kotlin/com/stringconcat/tdd/Money.kt @@ -1,10 +1,30 @@ package com.stringconcat.tdd -abstract class Money( - val amount: Int +open class Money internal constructor( + val amount: Int, + val currency: Currency ) { + + override fun equals(other: Any?): Boolean { + if (other !is Money) return false + if (amount == other.amount && currency == other.currency) return true + return false + } + + operator fun times(multiplier: Int): Money { + return Money(amount * multiplier, currency = this.currency) + } + + override fun toString(): String { + return "Money(amount=$amount, currency=$currency)" + } + + enum class Currency { + USD, CHF + } + companion object { - fun dollar(amount: Int) = Dollar(amount) - fun franc(amount: Int) = Franc(amount) + fun dollar(amount: Int) = Money(amount = amount, currency = Currency.USD) + fun franc(amount: Int) = Money(amount = amount, currency = Currency.CHF) } } \ No newline at end of file diff --git a/src/test/kotlin/com/stringconcat/tdd/DollarTest.kt b/src/test/kotlin/com/stringconcat/tdd/DollarTest.kt deleted file mode 100644 index c4170ed..0000000 --- a/src/test/kotlin/com/stringconcat/tdd/DollarTest.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.stringconcat.tdd - -import io.kotest.matchers.shouldBe -import io.kotest.matchers.shouldNotBe -import org.junit.jupiter.api.Test - -internal class DollarTest { - - @Test - fun `5 USD has amount of 5`() { - Money.dollar(5).amount shouldBe 5 - } - - @Test - fun `10 Usd is 10 USD`() { - Money.dollar(10) shouldBe Money.dollar(10) - } - - @Test - fun `10 Usd is not 5 USD`() { - Money.dollar(10) shouldNotBe Money.dollar(5) - } - - @Test - fun `5 dollar multiply 2 is 10 USD`() { - val ten = Money.dollar(5) * 2 - ten shouldBe Money.dollar(10) - } - - @Test - fun `5 USD is not 5 CHF`() { - Money.dollar(5) shouldNotBe Money.franc(5) - } -} \ No newline at end of file diff --git a/src/test/kotlin/com/stringconcat/tdd/FrancTest.kt b/src/test/kotlin/com/stringconcat/tdd/FrancTest.kt deleted file mode 100644 index f03ae82..0000000 --- a/src/test/kotlin/com/stringconcat/tdd/FrancTest.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.stringconcat.tdd - -import io.kotest.matchers.shouldBe -import io.kotest.matchers.shouldNotBe -import org.junit.jupiter.api.Test - -internal class FrancTest { - - @Test - fun `5 CHF has amount of 5`() { - Money.franc(5).amount shouldBe 5 - } - - @Test - fun `10 CHF is 10 CHF`() { - Money.franc(10) shouldBe Money.franc(10) - } - - @Test - fun `10 CHF is not 5 CHF`() { - Money.franc(10) shouldNotBe Money.franc(5) - } - - @Test - fun `5 CHF multiply 2 is 10 CHF`() { - val ten = Money.franc(5) * 2 - ten shouldBe Money.franc(10) - } -} \ No newline at end of file diff --git a/src/test/kotlin/com/stringconcat/tdd/MoneyTest.kt b/src/test/kotlin/com/stringconcat/tdd/MoneyTest.kt new file mode 100644 index 0000000..980e880 --- /dev/null +++ b/src/test/kotlin/com/stringconcat/tdd/MoneyTest.kt @@ -0,0 +1,65 @@ +package com.stringconcat.tdd + +import io.kotest.matchers.shouldBe +import io.kotest.matchers.shouldNotBe +import org.junit.jupiter.api.Test + +internal class MoneyTest { + + @Test + fun `5 USD has amount of 5`() { + Money.dollar(5).amount shouldBe 5 + } + + @Test + fun `10 Usd is 10 USD`() { + Money.dollar(10) shouldBe Money.dollar(10) + } + + @Test + fun `10 Usd is not 5 USD`() { + Money.dollar(10) shouldNotBe Money.dollar(5) + } + + @Test + fun `5 dollar multiply 2 is 10 USD`() { + val ten = Money.dollar(5) * 2 + ten shouldBe Money.dollar(10) + } + + @Test + fun `5 USD is not 5 CHF`() { + Money.dollar(5) shouldNotBe Money.franc(5) + } + + @Test + fun `5 CHF has amount of 5`() { + Money.franc(5).amount shouldBe 5 + } + + @Test + fun `10 CHF is 10 CHF`() { + Money.franc(10) shouldBe Money.franc(10) + } + + @Test + fun `10 CHF is not 5 CHF`() { + Money.franc(10) shouldNotBe Money.franc(5) + } + + @Test + fun `5 CHF multiply 2 is 10 CHF`() { + val ten = Money.franc(5) * 2 + ten shouldBe Money.franc(10) + } + + @Test + fun `Dollar has currency of USD`() { + Money.dollar(1).currency shouldBe Money.Currency.USD + } + + @Test + fun `Franc has currency of CHF`() { + Money.franc(1).currency shouldBe Money.Currency.CHF + } +} \ No newline at end of file From 38e462b0beb4f5033b01202504de7158e308f32c Mon Sep 17 00:00:00 2001 From: Sergey Date: Mon, 22 Feb 2021 15:22:01 +0800 Subject: [PATCH 5/5] dollars and francs have been removed --- src/main/kotlin/com/stringconcat/tdd/Bank.kt | 14 +++++ .../kotlin/com/stringconcat/tdd/Expression.kt | 4 ++ src/main/kotlin/com/stringconcat/tdd/Money.kt | 2 +- .../kotlin/com/stringconcat/tdd/Pocket.kt | 21 ++++++++ .../kotlin/com/stringconcat/tdd/MoneyTest.kt | 3 ++ .../kotlin/com/stringconcat/tdd/PocketTest.kt | 54 +++++++++++++++++++ 6 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/com/stringconcat/tdd/Bank.kt create mode 100644 src/main/kotlin/com/stringconcat/tdd/Expression.kt create mode 100644 src/main/kotlin/com/stringconcat/tdd/Pocket.kt create mode 100644 src/test/kotlin/com/stringconcat/tdd/PocketTest.kt diff --git a/src/main/kotlin/com/stringconcat/tdd/Bank.kt b/src/main/kotlin/com/stringconcat/tdd/Bank.kt new file mode 100644 index 0000000..e88d175 --- /dev/null +++ b/src/main/kotlin/com/stringconcat/tdd/Bank.kt @@ -0,0 +1,14 @@ +package com.stringconcat.tdd + +//class Bank { +// fun addRate(from: Money.Currency, to: Money.Currency, rate: Int) { +// +// +// } +// +// fun exchange(money: Expression, to: Money.Currency): Money { +// money as Pocket +// money.a +// } +// +//} diff --git a/src/main/kotlin/com/stringconcat/tdd/Expression.kt b/src/main/kotlin/com/stringconcat/tdd/Expression.kt new file mode 100644 index 0000000..791dc09 --- /dev/null +++ b/src/main/kotlin/com/stringconcat/tdd/Expression.kt @@ -0,0 +1,4 @@ +package com.stringconcat.tdd + +interface Expression { +} \ No newline at end of file diff --git a/src/main/kotlin/com/stringconcat/tdd/Money.kt b/src/main/kotlin/com/stringconcat/tdd/Money.kt index 73b3174..5284e3b 100644 --- a/src/main/kotlin/com/stringconcat/tdd/Money.kt +++ b/src/main/kotlin/com/stringconcat/tdd/Money.kt @@ -3,7 +3,7 @@ package com.stringconcat.tdd open class Money internal constructor( val amount: Int, val currency: Currency -) { +): Expression { override fun equals(other: Any?): Boolean { if (other !is Money) return false diff --git a/src/main/kotlin/com/stringconcat/tdd/Pocket.kt b/src/main/kotlin/com/stringconcat/tdd/Pocket.kt new file mode 100644 index 0000000..f811021 --- /dev/null +++ b/src/main/kotlin/com/stringconcat/tdd/Pocket.kt @@ -0,0 +1,21 @@ +package com.stringconcat.tdd + +class Pocket( + val a: Money, + val b: Money +): Expression { + fun reduce( + to: Money.Currency, + rateProvider: (Pair) -> Int + ): Money { + return if (a.currency == to && b.currency == to) { + Money((a.amount + b.amount), to) + } else { + Money((a.amount + b.amount)* 2, to) + } + } +} + +operator fun Money.plus(other: Money): Pocket { + return Pocket(this, other) +} \ No newline at end of file diff --git a/src/test/kotlin/com/stringconcat/tdd/MoneyTest.kt b/src/test/kotlin/com/stringconcat/tdd/MoneyTest.kt index 980e880..13718bf 100644 --- a/src/test/kotlin/com/stringconcat/tdd/MoneyTest.kt +++ b/src/test/kotlin/com/stringconcat/tdd/MoneyTest.kt @@ -62,4 +62,7 @@ internal class MoneyTest { fun `Franc has currency of CHF`() { Money.franc(1).currency shouldBe Money.Currency.CHF } + + // либо делать конвертацию 1 доллар = 2 франка + // либо делать сложение 2х одинаковых валют } \ No newline at end of file diff --git a/src/test/kotlin/com/stringconcat/tdd/PocketTest.kt b/src/test/kotlin/com/stringconcat/tdd/PocketTest.kt new file mode 100644 index 0000000..1423080 --- /dev/null +++ b/src/test/kotlin/com/stringconcat/tdd/PocketTest.kt @@ -0,0 +1,54 @@ +package com.stringconcat.tdd + +import io.kotest.matchers.shouldBe +import org.junit.jupiter.api.Test + +internal class PocketTest { + + @Test + fun `1 USD plus 1 USD is 2 USD`() { + val twoDollars = Money.dollar(1) + Money.dollar(1) + twoDollars.a shouldBe Money.dollar(1) + twoDollars.b shouldBe Money.dollar(1) + } + + @Test + fun `1 CHF plus 1 CHF is 2 CHF`() { + val twoFrancs = Money.franc(1) + Money.franc(1) + + twoFrancs.a shouldBe Money.franc(1) + twoFrancs.b shouldBe Money.franc(1) + } + + @Test + fun `10 USD and 5 CHF in pocket`() { + val pocket = Money.dollar(10) + Money.franc(5) + + pocket.a shouldBe Money.dollar(10) + pocket.b shouldBe Money.franc(5) + } + + @Test + fun `5 USD + 5 USD is 10 USD`() { + val pocket = Money.dollar(5) + Money.dollar(5) + pocket.reduce(to = Money.Currency.USD, rateProvider = {1}) shouldBe Money.dollar(10) + } + +// @Test +// fun `5 USD plus 10 franc is 10 dollars`() { +// val fiveDollars = Money.dollar(5) +// val tenFrancs = Money.franc(10) +// +// val pocket = fiveDollars + tenFrancs +// val converted = pocket.reduce(Money.Currency.USD, rate?? ) +// +// converted shouldBe Money.dollar(10) +// } + + @Test + fun `5 USD + 5 USD reduced to 20 CHF`() { + val pocket = Money.dollar(5) + Money.dollar(5) + + pocket.reduce(to = Money.Currency.CHF, {2}) shouldBe Money.franc(20) + } +} \ No newline at end of file