Guest User

Untitled

a guest
May 26th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. require 'test/unit'
  2.  
  3. class ShallowTest < Test::Unit::TestCase
  4. def test_standard_copy_should_be_by_reference_and_changes_should_back_propagate
  5. simple_array = [1,"hello", 3.000]
  6. copied_array = simple_array
  7. copied_array[0] = nil
  8. copied_array[1] = nil
  9. copied_array[2] = nil
  10.  
  11. assert_equal copied_array, simple_array
  12. end
  13.  
  14. def test_clone_should_be_by_value_and_changes_should_not_back_propogate
  15. simple_array = [1,"hello", 3.000]
  16. copied_array = simple_array.clone
  17. copied_array[0] = nil
  18. copied_array[1] = nil
  19. copied_array[2] = nil
  20.  
  21. assert_not_equal copied_array, simple_array
  22. end
  23. end
  24.  
  25. # 2 tests, 2 assertions, 0 failures, 0 errors
Add Comment
Please, Sign In to add comment