Last active
December 27, 2015 06:09
-
-
Save oblakeerickson/7279065 to your computer and use it in GitHub Desktop.
Learning about minitest from Steve Klabnik
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing this code... :)