File tree Expand file tree Collapse file tree 1 file changed +51
-1
lines changed
src/test/scala/com/github/yruslan/channel Expand file tree Collapse file tree 1 file changed +51
-1
lines changed Original file line number Diff line number Diff line change @@ -899,7 +899,7 @@ class ChannelSuite extends AnyWordSpec with BeforeAndAfterAll {
899
899
assert(lst == List (2 , 6 ))
900
900
}
901
901
902
- " test for comprehension" in {
902
+ " test for comprehension with yield " in {
903
903
val ch1 = Channel .make[Int ](3 )
904
904
905
905
val ch2 = ch1
@@ -918,6 +918,56 @@ class ChannelSuite extends AnyWordSpec with BeforeAndAfterAll {
918
918
919
919
assert(outputChannel.recv() == 6 )
920
920
}
921
+
922
+ " test for comprehension with foreach" in {
923
+ val ch1 = Channel .make[Int ](3 )
924
+
925
+ val ch2 = ch1
926
+ .map(v => v * 2 )
927
+ .filter(v => v != 4 )
928
+
929
+ ch1.send(1 )
930
+ ch1.send(2 )
931
+ ch1.send(3 )
932
+ ch1.close()
933
+
934
+ var out = 0
935
+ for {
936
+ a <- ch2
937
+ if a > 5
938
+ } out = a
939
+
940
+ assert(out == 6 )
941
+ }
942
+
943
+ " test for comprehension with 2 channels" in {
944
+ val ch1 = Channel .make[Int ](3 )
945
+ val ch2 = Channel .make[Int ](3 )
946
+
947
+ val ch3 = ch1
948
+ .map(v => v * 2 )
949
+ .filter(v => v != 4 )
950
+
951
+ ch1.send(1 )
952
+ ch1.send(2 )
953
+ ch1.send(3 )
954
+ ch1.close()
955
+
956
+ ch2.send(100 )
957
+ ch2.send(200 )
958
+ ch2.send(300 )
959
+ ch2.close()
960
+
961
+ var out = 0
962
+ for {
963
+ a <- ch2
964
+ b <- ch3
965
+ if a > 5
966
+ if b > 5
967
+ } out = a + b
968
+
969
+ assert(out == 106 )
970
+ }
921
971
}
922
972
923
973
" master/worker model" should {
You can’t perform that action at this time.
0 commit comments