diff --git a/README.md b/README.md index 398ec0a..8cafe13 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,4 @@ * [第09章 歩幅の調整](https://github.com/at-grandpa/study-tdd/pull/13) * [第10章 テストに聞いてみる](https://github.com/at-grandpa/study-tdd/pull/14) * [第11章 不要になったら消す](https://github.com/at-grandpa/study-tdd/pull/15) + * [第12章 設計とメタファー](https://github.com/at-grandpa/study-tdd/pull/16) diff --git a/part01/spec/money_package_spec.cr b/part01/spec/money_package_spec.cr index 7ee6937..b390cb8 100644 --- a/part01/spec/money_package_spec.cr +++ b/part01/spec/money_package_spec.cr @@ -23,4 +23,13 @@ describe MoneyPackage do Money.franc(1).currency.should eq "CHF" end end + describe "testSimpleAddition()" do + it "足し算を計算できること" do + five = Money.dollar(5) + sum : Expression = five.plus(five) + bank = Bank.new + reduced = bank.reduce(sum, "USD") + reduced.should eq Money.dollar(10) + end + end end diff --git a/part01/src/money_package/bank.cr b/part01/src/money_package/bank.cr new file mode 100644 index 0000000..8586327 --- /dev/null +++ b/part01/src/money_package/bank.cr @@ -0,0 +1,7 @@ +module MoneyPackage + class Bank + def reduce(source : Expression, to : String) + Money.dollar(10) + end + end +end diff --git a/part01/src/money_package/expression.cr b/part01/src/money_package/expression.cr new file mode 100644 index 0000000..28b9362 --- /dev/null +++ b/part01/src/money_package/expression.cr @@ -0,0 +1,4 @@ +module MoneyPackage + module Expression + end +end diff --git a/part01/src/money_package/money.cr b/part01/src/money_package/money.cr index e413124..f0e12d1 100644 --- a/part01/src/money_package/money.cr +++ b/part01/src/money_package/money.cr @@ -1,5 +1,9 @@ +require "./expression" + module MoneyPackage class Money + include Expression + def initialize(@amount : Int32, @currency : String) end @@ -15,6 +19,10 @@ module MoneyPackage Money.new(@amount * multiplier, @currency) end + def plus(addend : self) : Expression + Money.new(@amount + addend.@amount, @currency) + end + def self.dollar(amount : Int32) : self Money.new(amount, "USD") end