Sha256: bb2230dadf34a6e0003b29c5c7f74fc1aa61668988f823b781b85677938f511e

Contents?: true

Size: 602 Bytes

Versions: 20

Compression:

Stored size: 602 Bytes

Contents

# Test lib/facets/functor.rb

require 'facets/functor.rb'
require 'test/unit'

class TC_Functor < Test::Unit::TestCase

  def test_function
    f = Functor.new { |op, x| x.send(op, x) }
    assert_equal( 2, f + 1 ) #=> 2
    assert_equal( 4, f + 2 ) #=> 4
    assert_equal( 6, f + 3 ) #=> 6
    assert_equal( 1, f * 1 ) #=> 1
    assert_equal( 4, f * 2 ) #=> 4
    assert_equal( 9, f * 3 ) #=> 9
  end

  def test_decoration
    a = 'A'
    f = Functor.new{ |op, x| x.send(op, a + x) }
    assert_equal( 'BAB', f + 'B' )
    assert_equal( 'CAC', f + 'C' )
    assert_equal( 'DAD', f + 'D' )
  end

end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
facets-2.8.4 test/core/test_functor.rb
facets-2.8.3 test/core/test_functor.rb
facets-2.8.2 test/core/test_functor.rb
facets-2.8.1 test/core/test_functor.rb
facets-2.8.0 test/core/test_functor.rb
facets-2.7.0 test/core/test_functor.rb
facets-2.6.0 test/more/test_functor.rb
facets-2.1.3 test/unit/test_functor.rb
facets-2.2.1 test/unit/test_functor.rb
facets-2.3.0 test/core/test_functor.rb
facets-2.4.0 test/test_functor.rb
facets-2.2.0 test/unit/test_functor.rb
facets-2.4.1 test/test_functor.rb
facets-2.4.2 test/more/test_functor.rb
facets-2.4.4 test/more/test_functor.rb
facets-2.4.3 test/more/test_functor.rb
facets-2.4.5 test/more/test_functor.rb
facets-2.5.1 test/more/test_functor.rb
facets-2.5.0 test/more/test_functor.rb
facets-2.5.2 test/more/test_functor.rb