Skip to content

Instantly share code, notes, and snippets.

@dce
Created April 23, 2013 16:20
Show Gist options
  • Save dce/5445051 to your computer and use it in GitHub Desktop.
Save dce/5445051 to your computer and use it in GitHub Desktop.
require "test/unit"
def balanced?(string)
# ...
end
def count_change(money, coins)
# ...
end
class BalanceSuite < Test::Unit::TestCase
def test_some_lisp
assert balanced?("(if (zero? x) max (/ 1 x))")
end
def test_i_told_him
assert balanced?("I told him (that it's not (yet) done).\n(But he wasn't listening)")
end
def test_smiley_is_unbalanced
assert !balanced?(":-)")
end
def test_counting_is_not_enough
assert !balanced?("())(")
end
end
class CountChangeSuite < Test::Unit::TestCase
def test_four_from_one_and_two
assert count_change(4, [1, 2]) == 3
end
def test_sorted_swiss_francs
assert count_change(300, [5, 10, 20, 50, 100, 200, 500]) == 1022
end
def test_unsorted_swiss_francs
assert count_change(300, [500, 5, 50, 100, 20, 200, 10]) == 1022
end
def test_no_pennies
assert count_change(301, [5, 10, 20, 50, 100, 200, 500]) == 0
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment