Created
May 20, 2010 03:32
-
-
Save aarongough/407156 to your computer and use it in GitHub Desktop.
This file contains 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 'test/unit' | |
class ShallowTest < Test::Unit::TestCase | |
def test_standard_copy_should_be_by_reference_and_changes_should_back_propagate | |
simple_array = [1,"hello", 3.000] | |
copied_array = simple_array | |
copied_array[0] = nil | |
copied_array[1] = nil | |
copied_array[2] = nil | |
assert_equal copied_array, simple_array | |
end | |
def test_clone_should_be_by_value_and_changes_should_not_back_propogate | |
simple_array = [1,"hello", 3.000] | |
copied_array = simple_array.clone | |
copied_array[0] = nil | |
copied_array[1] = nil | |
copied_array[2] = nil | |
assert_not_equal copied_array, simple_array | |
end | |
end | |
# 2 tests, 2 assertions, 0 failures, 0 errors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment