Skip to content

Commit

Permalink
p.55 added the function "html_statement" to Castomer class,
Browse files Browse the repository at this point in the history
and its test to TC_Customer class.
  • Loading branch information
kono committed Apr 11, 2010
1 parent 7e17d68 commit b079fdf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
14 changes: 14 additions & 0 deletions chapter1/Customer.rb
Expand Up @@ -27,6 +27,20 @@ def statement
print @result
end

def html_statement
result ="<h1>Rentals for <em>#{@name}</em></h1><p>\n"
@rentals.each do |element|
# このレンタル料金を表示
result += "\t" + element.movie.title+": " + element.charge.to_s + "<br>\n"
end
# フッターを追加
result += "<p>You owe <em>#{total_charge}</em><p>\n"
result += "On this rental you earned " +
"<em>#{total_frequent_renter_points}</em> " +
"frequent renter points<p>"
result
end

private

def total_charge
Expand Down
7 changes: 7 additions & 0 deletions chapter1/TC_Customer.rb
Expand Up @@ -29,4 +29,11 @@ def setup
result= "Rental Record for kono\n\tStar Wars\t9.5\n\tDistrict 9\t6\n\tPonyo\t4.5\nAmount owed is 20.0\nYou earned 4 frequent renter points"
assert_equal(result, @obj.result)
end
must "test2" do
@obj.add_rental(Rental.new(@movie1, 10))
@obj.add_rental(Rental.new(@movie2, 15))
@obj.add_rental(Rental.new(@movie3, 20))
result="<h1>Rentals for <em>kono</em></h1><p>\n\tStar Wars: 14.0<br>\n\tDistrict 9: 45<br>\n\tPonyo: 27.0<br>\n<p>You owe <em>86.0</em><p>\nOn this rental you earned <em>4</em> frequent renter points<p>"
assert_equal(result, @obj.html_statement)
end
end

0 comments on commit b079fdf

Please sign in to comment.