From 3a1facb4573b8bff2044450a9b671dc08de74beb Mon Sep 17 00:00:00 2001 From: Hiroshi Kono Date: Tue, 11 May 2010 22:24:18 +0900 Subject: [PATCH] p.133 complexed outstanding(before refactoring) --- chapter6/Extract_Method.rb | 14 +++++++++----- chapter6/TC_Extract_Method.rb | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/chapter6/Extract_Method.rb b/chapter6/Extract_Method.rb index a1f90e3..f46aed8 100644 --- a/chapter6/Extract_Method.rb +++ b/chapter6/Extract_Method.rb @@ -16,9 +16,16 @@ def order_entry(amount) @orders << Extract_Method_Order.new(amount) end - def print_owing + def print_owing(previous_amount) + outstanding = previous_amount * 1.2 + print_banner - outstanding = calculate_outstanding + + # 勘定を計算(calculate outstanding) + @orders.each do |order| + outstanding += order.amount + end + print_details outstanding end @@ -35,7 +42,4 @@ def print_details(outstanding) puts "amount: #{outstanding}" end - def calculate_outstanding - @orders.inject(0.0){|result, order| result + order.amount } - end end diff --git a/chapter6/TC_Extract_Method.rb b/chapter6/TC_Extract_Method.rb index b66cce0..beec386 100644 --- a/chapter6/TC_Extract_Method.rb +++ b/chapter6/TC_Extract_Method.rb @@ -25,12 +25,12 @@ def setup must "test1" do temp=Tempfile::new("foobar") $stdout=temp - @obj.print_owing + @obj.print_owing(10) $stdout=STDOUT temp.close temp.open result= temp.read - expectation = "*************************\n***** Customer Owes *****\n*************************\nname: kono\namount: 60.0\n" + expectation = "*************************\n***** Customer Owes *****\n*************************\nname: kono\namount: 72.0\n" temp.close assert_equal(result, expectation) end