@@ -32,7 +32,7 @@ import org.scalatest.junit.JUnitSuite
32
32
import rx .lang .scala ._
33
33
import rx .lang .scala .schedulers ._
34
34
35
- @ Ignore // Since this doesn't do automatic testing, don't increase build time unnecessarily
35
+ // @Ignore // Since this doesn't do automatic testing, don't increase build time unnecessarily
36
36
class RxScalaDemo extends JUnitSuite {
37
37
38
38
@ Test def intervalExample () {
@@ -78,13 +78,9 @@ class RxScalaDemo extends JUnitSuite {
78
78
val first = Observable .from(List (10 , 11 , 12 ))
79
79
val second = Observable .from(List (10 , 11 , 12 ))
80
80
81
- val b1 = (first zip second) map (p => p._1 == p._2) forall (b => b)
81
+ val b = (first zip second) forall { case (a, b) => a == b }
82
82
83
- val equality = (a : Any , b : Any ) => a == b
84
- val b2 = (first zip second) map (p => equality(p._1, p._2)) forall (b => b)
85
-
86
- assertTrue(b1.toBlockingObservable.single)
87
- assertTrue(b2.toBlockingObservable.single)
83
+ assertTrue(b.toBlockingObservable.single)
88
84
}
89
85
90
86
@ Test def testObservableComparisonWithForComprehension () {
@@ -93,7 +89,7 @@ class RxScalaDemo extends JUnitSuite {
93
89
94
90
val booleans = for ((n1, n2) <- (first zip second)) yield (n1 == n2)
95
91
96
- val b1 = booleans.forall(_ == true ) // without `== true`, b1 is assigned the forall function
92
+ val b1 = booleans.forall(identity)
97
93
98
94
assertTrue(b1.toBlockingObservable.single)
99
95
}
@@ -216,18 +212,21 @@ class RxScalaDemo extends JUnitSuite {
216
212
}).flatten.toBlockingObservable.foreach(println(_))
217
213
}
218
214
219
- @ Ignore // TODO something's bad here
220
215
@ Test def timingTest1 () {
221
216
val numbersByModulo3 = Observable .interval(1000 millis).take(9 ).groupBy(_ % 3 )
222
217
223
218
val t0 = System .currentTimeMillis
224
219
225
220
(for ((modulo, numbers) <- numbersByModulo3) yield {
226
221
println(" Observable for modulo" + modulo + " started at t = " + (System .currentTimeMillis - t0))
227
- numbers.take(1 ) // <- TODO very unexpected
228
- // numbers
222
+ numbers.map(n => s " ${n} is in the modulo- $modulo group " )
229
223
}).flatten.toBlockingObservable.foreach(println(_))
230
224
}
225
+
226
+ @ Test def testOlympicYearTicks () {
227
+ Olympics .yearTicks.subscribe(println(_))
228
+ waitFor(Olympics .yearTicks)
229
+ }
231
230
232
231
@ Test def groupByExample () {
233
232
val medalsByCountry = Olympics .mountainBikeMedals.groupBy(medal => medal.country)
@@ -238,8 +237,10 @@ class RxScalaDemo extends JUnitSuite {
238
237
firstMedalOfEachCountry.subscribe(medal => {
239
238
println(s " ${medal.country} wins its first medal in ${medal.year}" )
240
239
})
240
+
241
+ Olympics .yearTicks.subscribe(year => println(s " \n Year $year starts. " ))
241
242
242
- waitFor(firstMedalOfEachCountry )
243
+ waitFor(Olympics .yearTicks )
243
244
}
244
245
245
246
@ Test def groupByUntilExample () {
@@ -469,7 +470,10 @@ class RxScalaDemo extends JUnitSuite {
469
470
470
471
def output (s : String ): Unit = println(s)
471
472
472
- // blocks until obs has completed
473
+ /** Subscribes to obs and waits until obs has completed. Note that if you subscribe to
474
+ * obs yourself and also call waitFor(obs), all side-effects of subscribing to obs
475
+ * will happen twice.
476
+ */
473
477
def waitFor [T ](obs : Observable [T ]): Unit = {
474
478
obs.toBlockingObservable.toIterable.last
475
479
}
0 commit comments