Skip to content

Instantly share code, notes, and snippets.

@aarongough
Created May 20, 2010 03:32
Show Gist options
  • Save aarongough/407156 to your computer and use it in GitHub Desktop.
Save aarongough/407156 to your computer and use it in GitHub Desktop.
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