Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
frappuccino/test/merge_test.rb /
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
81 lines (62 sloc)
2.04 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'test_helper' | |
| describe "merging steams" do | |
| it "produces one stream with both sets of events" do | |
| button_one = Button.new | |
| button_two = Button.new | |
| stream_one = Frappuccino::Stream.new(button_one) | |
| stream_two = Frappuccino::Stream.new(button_two) | |
| merged_stream = to_array(stream_one.merge(stream_two)) | |
| button_one.push | |
| button_two.push | |
| assert_equal 2, merged_stream.length | |
| end | |
| it "+1/-1" do | |
| plus_button = PlusOneButton.new | |
| minus_button = MinusOneButton.new | |
| stream_one = Frappuccino::Stream.new(plus_button) | |
| stream_two = Frappuccino::Stream.new(minus_button) | |
| merged_stream = stream_one.merge(stream_two) | |
| counter = merged_stream | |
| .map do |event| | |
| case event | |
| when :+ | |
| 1 | |
| when :- | |
| -1 | |
| else | |
| 0 | |
| end | |
| end | |
| .inject(0) {|sum, n| sum + n } | |
| assert_equal 0, counter.now | |
| plus_button.push | |
| assert_equal 1, counter.now | |
| minus_button.push | |
| assert_equal 0, counter.now | |
| 2.times { minus_button.push } | |
| assert_equal(-2, counter.now) | |
| 4.times { plus_button.push } | |
| assert_equal 2, counter.now | |
| end | |
| it "works if the callee has a different constructor from Stream" do | |
| button_one = Button.new | |
| button_two = Button.new | |
| stream_one = Frappuccino::Stream.new(button_one).map { 0 } | |
| stream_two = Frappuccino::Stream.new(button_two) | |
| # This would explode if the merge was calling | |
| # self.class.new rather than Stream.new | |
| stream_one.merge(stream_two) | |
| end | |
| end | |
| describe "merging stream with Frappuccino::Stream#merge" do | |
| it "produces one stream with both sets of events" do | |
| button_one = Button.new | |
| button_two = Button.new | |
| stream_one = Frappuccino::Stream.new(button_one) | |
| stream_two = Frappuccino::Stream.new(button_two) | |
| merged_stream = to_array(Frappuccino::Stream.merge(stream_one, stream_two)) | |
| button_one.push | |
| button_two.push | |
| assert_equal 2, merged_stream.length | |
| end | |
| end |