Skip to content

Instantly share code, notes, and snippets.

@edipofederle
Created September 23, 2012 17:54
Show Gist options
  • Select an option

  • Save edipofederle/3772500 to your computer and use it in GitHub Desktop.

Select an option

Save edipofederle/3772500 to your computer and use it in GitHub Desktop.
square2.rb
require "rubygems"
require "test/unit"
class Array
def square
self.each do |i|
raise ArgumentError unless i.class == Float
end
self.collect {|num| num * num}
end
end
class TestLibraryFileName < Test::Unit::TestCase
def test_case_name
array = [1.0,2.0,3.0]
assert_equal([1.0,4.0,9.0], array.square)
end
def test_type
array = ["a","b","c"]
assert_raise(ArgumentError) {
array.square
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment