diff options
author | Kota Mizushima <mizukota@gmail.com> | 2012-01-23 18:53:05 +0900 |
---|---|---|
committer | Kota Mizushima <mizukota@gmail.com> | 2012-01-23 18:53:05 +0900 |
commit | 39a837c8357e78c949613db881bd060d176f3279 (patch) | |
tree | 3649df1dac15b8ece7d829b068e30d560a140cbf /test/files/run/t4835.scala | |
parent | eadc8db056ee5165cefbf221c0d8e2e67ba147cf (diff) | |
download | scala-39a837c8357e78c949613db881bd060d176f3279.tar.gz scala-39a837c8357e78c949613db881bd060d176f3279.tar.bz2 scala-39a837c8357e78c949613db881bd060d176f3279.zip |
Add test case for SI-4835 (https://issues.scala-lang.org/browse/SI-4835)
This test case only confirm that StreamIterator's lazyiness is not broken.
Test case about memory consumption could be created. However, such a
test cause a greatly increased time of test.
Diffstat (limited to 'test/files/run/t4835.scala')
-rw-r--r-- | test/files/run/t4835.scala | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/files/run/t4835.scala b/test/files/run/t4835.scala new file mode 100644 index 0000000000..50d161be40 --- /dev/null +++ b/test/files/run/t4835.scala @@ -0,0 +1,38 @@ +/*
+ * Test case for SI-4835. This tests confirm that the fix
+ * doesn't break laziness. To test memory consumption,
+ * I need to confirm that OutOfMemoryError doesn't occur.
+ * I could create such tests. However, such tests consume
+ * too much time and memory.
+ */
+object Test {
+ private final val INFINITE = -1
+ def testStreamIterator(num: Int, stream: Stream[Int]): Unit = {
+ val iter = stream.iterator
+ print(num)
+ // if num == -1, then steram is infinite sequence
+ if (num == INFINITE) {
+ for(i <- 0 until 10) {
+ print(" " + iter.next())
+ }
+ } else {
+ while(iter.hasNext) {
+ print(" " + iter.next())
+ }
+ }
+ println()
+ }
+
+ def main(args: Array[String]): Unit = {
+ import Stream.{from, cons, empty}
+ testStreamIterator(INFINITE, from(0))
+ testStreamIterator(INFINITE, from(0).filter(_ % 2 == 1))
+ testStreamIterator(1, Stream(1))
+ testStreamIterator(2, Stream(1, 2))
+ //Stream with side effect
+ testStreamIterator(2, cons(1, cons({ print(" A"); 2}, empty)))
+ testStreamIterator(3, Stream(1, 2, 3))
+ //Stream with side effect
+ testStreamIterator(3, cons(1, cons({ print(" A"); 2}, cons({ print(" B"); 3}, Stream.empty))))
+ }
+}
|