Skip to content

Instantly share code, notes, and snippets.

@oblakeerickson
Last active December 27, 2015 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oblakeerickson/7279065 to your computer and use it in GitHub Desktop.
Save oblakeerickson/7279065 to your computer and use it in GitHub Desktop.
Learning about minitest from Steve Klabnik
require 'minitest/autorun'
class TestCashRegister < MiniTest::Unit::TestCase
def setup
@register = CashRegister.new
end
def test_default_is_zero
assert_equal 0, @register.total
end
def test_total_calculation
@register.scan 1
@register.scan 2
assert_equal 3, @register.total
end
def test_total_is_zero_after_clear
@register.scan 1
@register.clear
assert_equal 0, @register.total
end
end
class CashRegister
def initialize
@items = []
end
def total
@items.inject(0, &:+)
end
def scan(item)
@items << item
end
def clear
@items = []
end
end
@aruprakshit
Copy link

Thanks for sharing this code... :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment