Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment