Skip to content

Instantly share code, notes, and snippets.

@asiansteev
Forked from xtoddx/competition.rb
Created September 10, 2010 18:58
Show Gist options
  • Save asiansteev/574157 to your computer and use it in GitHub Desktop.
Save asiansteev/574157 to your computer and use it in GitHub Desktop.
require 'test/unit'
#
# The goal for this exercise is to get the tests to pass while not using
# the expected functionality. The 'multiply' method shouldn't actually
# multiply, but it should get the tests to pass _somehow_.
#
# CompTest may be renamed, as may CompEntry, so don't rely on names.
#
class CompEntry
def length string
# string.length
end
def multiply term_a, term_b
# term_a * term_b
end
end
class CompTest < Test::Unit::TestCase
def test_length
assert_equal 10, CompEntry.new.length('abcdefghij')
assert_equal 12, CompEntry.new.length('Test String.')
assert_equal 0, CompEntry.new.length('')
assert_equal 1, CompEntry.new.length("\n")
assert_equal 1, CompEntry.new.length("\t")
end
def test_multiply
assert_equal 100, CompEntry.new.multiply(50, 2)
assert_equal 0, CompEntry.new.multiply(50, 0)
assert_equal 0, CompEntry.new.multiply(0, 0)
assert_equal 50, CompEntry.new.multiply(50, 1)
assert_equal 22.5, CompEntry.new.multiply(2.5, 9)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment