Sha256: e6a769bdb1e3f74a83c20160e2247603bff6e0ef84537809a6127a975a0b14f7

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

require 'helper'
include Stages

class TestPipeline < MiniTest::Unit::TestCase
  
  test 'simple basic pipeline' do
    evens = Evens.new
    mx3 = MultiplesOf.new(3)
    mx7 = MultiplesOf.new(7) 
    mx3.source = evens 
    mx7.source = mx3
    
    result = (0..2).map{ mx7.run }
    assert_equal([0, 42, 84], result)
  end
  
  test 'pipeline pipe syntax works' do
    pipeline = Evens.new | MultiplesOf.new(3) | MultiplesOf.new(7)
    result = (0..2).map{ pipeline.run }
    assert_equal([0, 42, 84], result)
  end
  
  test 'block stages work' do
    pipeline = Evens.new | Map.new{ |x| x * 3} | Select.new{ |x| x % 7 == 0}
    result = (0..2).map{ pipeline.run }
    assert_equal([0, 42, 84], result)
  end
  
  test 'exceptions do what you expect' do
    begin
      pipeline = Evens.new | Map.new{ |val| throw Exception.new "exception!" } | Select.new{ |v| v > 2}
      pipeline.run
      assert false
    rescue Exception => e
    end
  end   
       
  test 'nil kills it' do
    pipeline = EachElement.new([1, 2, nil, 3])
    result = []
    while v = pipeline.run
      result << v
    end
    assert_equal([1, 2], result)    
  end  

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stages-0.1.1 test/test_pipeline.rb
stages-0.1.0 test/test_pipeline.rb