diff --git a/README.md b/README.md index 43f597f..d6d15a7 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,4 @@ * [第07章 疑念をテストに翻訳する](https://github.com/at-grandpa/study-tdd/pull/11) * [第08章 実装を隠す](https://github.com/at-grandpa/study-tdd/pull/12) * [第09章 歩幅の調整](https://github.com/at-grandpa/study-tdd/pull/13) + * [第10章 テストに聞いてみる](https://github.com/at-grandpa/study-tdd/pull/14) diff --git a/part01/spec/money_spec.cr b/part01/spec/money_spec.cr index c662996..cbcebff 100644 --- a/part01/spec/money_spec.cr +++ b/part01/spec/money_spec.cr @@ -30,4 +30,9 @@ describe MoneyPackage do MoneyPackage::Money.franc(1).currency.should eq "CHF" end end + describe "testDifferentClassEquality()" do + it "クラスが違っても通貨で等価比較できること" do + (MoneyPackage::Money.new(10, "CHF") == MoneyPackage::Franc.new(10, "CHF")).should be_true + end + end end diff --git a/part01/src/money_package/dollar.cr b/part01/src/money_package/dollar.cr index 8b039ca..e1e7020 100644 --- a/part01/src/money_package/dollar.cr +++ b/part01/src/money_package/dollar.cr @@ -3,9 +3,5 @@ module MoneyPackage def initialize(@amount : Int32, @currency : String) super(@amount, @currency) end - - def times(multiplier : Int32) - Money.dollar(@amount * multiplier) - end end end diff --git a/part01/src/money_package/franc.cr b/part01/src/money_package/franc.cr index cabe75e..f9dc748 100644 --- a/part01/src/money_package/franc.cr +++ b/part01/src/money_package/franc.cr @@ -3,9 +3,5 @@ module MoneyPackage def initialize(@amount : Int32, @currency : String) super(@amount, @currency) end - - def times(multiplier : Int32) - Money.franc(@amount * multiplier) - end end end diff --git a/part01/src/money_package/money.cr b/part01/src/money_package/money.cr index 9eebe05..d284d63 100644 --- a/part01/src/money_package/money.cr +++ b/part01/src/money_package/money.cr @@ -1,5 +1,5 @@ module MoneyPackage - abstract class Money + class Money def initialize(@amount : Int32, @currency : String) end @@ -8,10 +8,12 @@ module MoneyPackage end def ==(other : MoneyPackage::Money) - (@amount == other.@amount) && (other.class == self.class) + (@amount == other.@amount) && (other.currency == self.currency) end - abstract def times(multiplier : Int32) + def times(multiplier : Int32) + MoneyPackage::Money.new(@amount * multiplier, @currency) + end def self.dollar(amount : Int32) : self MoneyPackage::Dollar.new(amount, "USD")