Image to test Ruby code
59
docker run --rm -v $(pwd):$(pwd) -w $(pwd) patriciomoreno/codeworkout-ruby:v1.0 ruby tc_simple_number.rb
class SimpleNumber
def initialize(num)
raise unless num.is_a?(Numeric)
@x = num
end
def add(y)
@x + y
end
def multiply(y)
@x * y
end
end
require_relative "simple_number"
require "test/unit"
class TestSimpleNumber < Test::Unit::TestCase
def test_simple
assert_equal(4, SimpleNumber.new(2).add(2) )
assert_equal(4, SimpleNumber.new(2).multiply(2) )
end
def test_typecheck
assert_raise( RuntimeError ) { SimpleNumber.new('a') }
end
def test_failure
assert_equal(3, SimpleNumber.new(2).add(2), "Adding doesn't work" )
end
end
Content type
Image
Digest
Size
329.2 MB
Last updated
over 8 years ago
docker pull patriciomoreno/codeworkout-ruby:v1.0