PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/gems/facets-2.4.5/test/more/test_functor.rb

https://bitbucket.org/mediashelf/fedora-migrator
Ruby | 26 lines | 20 code | 5 blank | 1 comment | 0 complexity | 712bff9659841dda2e36ffab103a6ae8 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, IPL-1.0, AGPL-1.0, LGPL-3.0
  1. # Test lib/facets/functor.rb
  2. require 'facets/functor.rb'
  3. require 'test/unit'
  4. class TC_Functor < Test::Unit::TestCase
  5. def test_function
  6. f = Functor.new { |op, x| x.send(op, x) }
  7. assert_equal( 2, f + 1 ) #=> 2
  8. assert_equal( 4, f + 2 ) #=> 4
  9. assert_equal( 6, f + 3 ) #=> 6
  10. assert_equal( 1, f * 1 ) #=> 1
  11. assert_equal( 4, f * 2 ) #=> 4
  12. assert_equal( 9, f * 3 ) #=> 9
  13. end
  14. def test_decoration
  15. a = 'A'
  16. f = Functor.new{ |op, x| x.send(op, a + x) }
  17. assert_equal( 'BAB', f + 'B' )
  18. assert_equal( 'CAC', f + 'C' )
  19. assert_equal( 'DAD', f + 'D' )
  20. end
  21. end