第3章
require 'test/unit'
class Test_Money < Test::Unit::TestCase
def test_multiplication
five = Dollar.new(5)
product = five.times(2)
assert_equal(10, product.get_amount)
product = five.times(3)
assert_equal(15, product.get_amount)
end
def test_equality
assert(Dollar.new(5).equals(Dollar.new(5) ) )
assert(!Dollar.new(5).equals(Dollar.new(6) ) )
end
end
class Dollar
def initialize(amount)
@amount = amount
end
def times(multiplier)
return Dollar.new(@amount * multiplier)
end
def equals(object)
dollar = object
return @amount == dollar.get_amount
end
def get_amount()
return @amount
end
end