Sha256: cbb08fb43eb3952a3f63d1a18b4a6dc98a2add67501c02800c9fe416dc1d7290

Contents?: true

Size: 1.85 KB

Versions: 1

Compression:

Stored size: 1.85 KB

Contents

require 'test_helper'

describe "zip" do
  it "returns a stream where the events are tuples of corresponding events" do
    button1 = CounterButton.new(0)
    stream1 = Frappuccino::Stream.new(button1)
    button2 = CounterButton.new(10)
    stream2 = Frappuccino::Stream.new(button2)


    zipped_stream = to_array(stream1.zip(stream2))

    button1.push
    button2.push
    assert_equal [[0, 10]], zipped_stream, "zipped stream did not propagate events correctly"

    button2.push
    button1.push
    assert_equal [[0, 10], [1, 11]], zipped_stream, "zipped stream did not propagate events correctly"
  end

  it "returns a stream that buffers the left input stream" do
    button1 = CounterButton.new(0)
    stream1 = Frappuccino::Stream.new(button1)
    button2 = CounterButton.new(10)
    stream2 = Frappuccino::Stream.new(button2)

    zipped_stream = to_array(stream1.zip(stream2))

    2.times do
      button1.push
      assert_equal [], zipped_stream, "zipped stream occurred too early"
    end

    2.times do |i|
      button2.push
      assert_equal zipped_stream.length, i + 1, "zipped stream did not occur"
      assert_equal [i, 10 + i], zipped_stream.last, "zipped stream did not occur with correct value"
    end

    zipped_stream.clear
  end

  it "returns a stream that buffers the right input stream" do
    button1 = CounterButton.new(0)
    stream1 = Frappuccino::Stream.new(button1)
    button2 = CounterButton.new(10)
    stream2 = Frappuccino::Stream.new(button2)

    zipped_stream = to_array(stream1.zip(stream2))

    2.times do
      button2.push
      assert_equal [], zipped_stream, "zipped stream occurred too early"
    end

    2.times do |i|
      button1.push
      assert_equal zipped_stream.length, i + 1, "zipped stream did not occur"
      assert_equal [i, 10 + i], zipped_stream.last, "zipped stream did not occur with correct value"
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
frappuccino-0.3.0 test/zip_test.rb