Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第10章 テストに聞いてみる #14

Merged
merged 18 commits into from
Nov 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 5 additions & 0 deletions part01/spec/money_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 0 additions & 4 deletions part01/src/money_package/dollar.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 0 additions & 4 deletions part01/src/money_package/franc.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 5 additions & 3 deletions part01/src/money_package/money.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module MoneyPackage
abstract class Money
class Money
def initialize(@amount : Int32, @currency : String)
end

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