Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Merge two streams.
- Loading branch information
1 parent
651cf1b
commit dca32dc8d3708d2c9738c1698aadf24dd5c20595
Showing
4 changed files
with
38 additions
and
8 deletions.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| 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 = Frappuccino::Stream.merge(stream_one, stream_two) | ||
| counter = merged_stream | ||
| .map {|event| event == :pushed ? 1 : 0 } | ||
| .inject(0) {|sum, n| sum + n } | ||
|
|
||
| button_one.push | ||
| button_two.push | ||
|
|
||
| assert_equal 2, counter.to_i | ||
| end | ||
| end |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,8 @@ | ||
| require 'minitest/autorun' | ||
|
|
||
| class Button | ||
| def push | ||
| emit(:pushed) | ||
| end | ||
| end | ||
|
|