PageRenderTime 23ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/gems/facets-2.4.5/test/core/enumerable/test_mash.rb

https://bitbucket.org/mediashelf/fedora-migrator
Ruby | 38 lines | 29 code | 9 blank | 0 comment | 0 complexity | 634adae03d37af949ee1469513c5a0cf MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, IPL-1.0, AGPL-1.0, LGPL-3.0
  1. require 'facets/enumerable/mash'
  2. require 'test/unit'
  3. class TC_Enumerable_Mash < Test::Unit::TestCase
  4. def test_mash_hash_return
  5. a = { :a => 1, :b => 2, :c => 3 }
  6. e = { :a => 2, :b => 3, :c => 4 }
  7. assert_equal( e, a.mash{ |k,v| {k => v+1} } )
  8. end
  9. def test_mash_hash_of_array
  10. a = { :a => [1,2], :b => [2,3], :c => [3,4] }
  11. e = { :a => 2, :b => 6, :c => 12 }
  12. assert_equal( e, a.mash{ |k,v| [k, v[0]*v[1] ] } )
  13. end
  14. def test_mash_array_of_array
  15. a = [ [1,2], [2,3], [3,4] ]
  16. e = { [1,2] => 2, [2,3] => 6, [3,4] => 12 }
  17. assert_equal( e, a.mash{ |a| [a, a[0]*a[1] ] } )
  18. end
  19. def test_mash_squares
  20. numbers = (1..3)
  21. squares = numbers.mash{ |n| [n, n*n] }
  22. assert_equal( {1=>1, 2=>4, 3=>9}, squares )
  23. end
  24. def test_mash_roots
  25. numbers = (1..3)
  26. sq_roots = numbers.mash{ |n| [n*n, n] }
  27. assert_equal( {1=>1, 4=>2, 9=>3}, sq_roots )
  28. end
  29. end