Created
September 23, 2012 17:54
-
-
Save edipofederle/3772500 to your computer and use it in GitHub Desktop.
square2.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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