Skip to content

Commit

Permalink
Merge pull request #16 from at-grandpa/chapter12
Browse files Browse the repository at this point in the history
第12章 設計とメタファー
  • Loading branch information
at-grandpa authored Nov 9, 2017
2 parents 696e999 + f0b6e4b commit d77ba26
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
9 changes: 9 additions & 0 deletions part01/spec/money_package_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions part01/src/money_package/bank.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module MoneyPackage
class Bank
def reduce(source : Expression, to : String)
Money.dollar(10)
end
end
end
4 changes: 4 additions & 0 deletions part01/src/money_package/expression.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module MoneyPackage
module Expression
end
end
8 changes: 8 additions & 0 deletions part01/src/money_package/money.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
require "./expression"

module MoneyPackage
class Money
include Expression

def initialize(@amount : Int32, @currency : String)
end

Expand All @@ -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
Expand Down

0 comments on commit d77ba26

Please sign in to comment.