Skip to content

Commit 730e6d8

Browse files
committed
test for lazy evaluation
1 parent 396947e commit 730e6d8

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

compat/src/test/scala/test/scala/collection/LazyZipTest.scala

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package test.scala.collection
22

33
import org.junit.Assert.assertEquals
4+
import org.junit.Assert.assertTrue
5+
import org.junit.Assert.assertFalse
46
import org.junit.Test
57

68
import scala.collection.compat._
@@ -18,15 +20,26 @@ class LazyZipTest {
1820

1921
@Test
2022
def lazyZipTest(): Unit = {
21-
2223
val res: List[(Int, Int)] = zipped2.map((a, b) => (a, b))
2324
assertEquals(List((1, 1), (2, 2), (3, 3)), res)
2425
}
2526

2627
@Test
2728
def lazyZip3_map(): Unit = {
2829
val res: List[(Int, Int, String)] = zipped3.map((a: Int, b: Int, c: String) => (a, b, c))
29-
3030
assertEquals(List((1, 1, "a"), (2, 2, "b"), (3, 3, "c")), res)
3131
}
32+
33+
@Test
34+
def collectionValueIsNotEvaluated(): Unit = {
35+
val st = Stream.cons(1, throw new AssertionError("should not be evaluated"))
36+
ws.lazyZip(st)
37+
}
38+
39+
@Test
40+
def zip3collectionValueIsNotEvaluated(): Unit = {
41+
val st = Stream.cons(1, throw new AssertionError("should not be evaluated"))
42+
ws.lazyZip(st).lazyZip(st)
43+
}
44+
3245
}

0 commit comments

Comments
 (0)