Skip to content

Instantly share code, notes, and snippets.

@jgn
Last active August 29, 2015 13:57
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 jgn/9379462 to your computer and use it in GitHub Desktop.
Save jgn/9379462 to your computer and use it in GitHub Desktop.
def assert_equality(example, actual, expected)
print "example #{example}: "
if actual == expected
puts 'Pass'
else
puts "Fail: got #{actual.inspect}; expected #{expected.inspect}"
end
end
examples = [
[0, 0, 0, 0],
[1, 0, 0, 1],
[0, 1, 0, 1],
[1, 1, 1, 0]
]
examples.each do |example|
a, b, c, s = example
half_adder = HalfAdder.new(a, b) # setup
half_adder.compute # exercise
assert_equality(example, half_adder.carry, c) # verify
assert_equality(example, half_adder.sum, s) # verify
adder = nil # teardown
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment