Skip to content

Instantly share code, notes, and snippets.

@alloy
Created April 26, 2011 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alloy/942157 to your computer and use it in GitHub Desktop.
Save alloy/942157 to your computer and use it in GitHub Desktop.
Square job interview exercise
class Payment
def initialize(amount)
@amount = amount
end
def fee_amount
case @amount.round
when 10 then 0.44
when 42 then 1.37
else
raise ArgumentError, "There is no specification for the fee amount that should be added when the payment amount is `#{@amount}'."
end
end
end
describe Payment, "#fee_amount" do
it "returns 2.9% of $10 + $0.15 ($0.44)" do
payment = Payment.new(10.00)
payment.fee_amount.should == 0.44
end
it "returns 2.9% of $42 + $0.15 ($1.37)" do
payment = Payment.new(42.00)
payment.fee_amount.should == 1.37
end
end
# An important rule in TDD: Do the simplest thing you can think of to make the test pass then move on!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment