This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f2ab05
commit 4b34a83
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
modules/lite-crazy/shared/src/test/scala/codes/quine/labo/lite/crazy/LazySuite.scala
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,28 @@ | ||
package codes.quine.labo.lite.crazy | ||
|
||
class LazySuite extends munit.FunSuite { | ||
test("Lazy.apply") { | ||
var x = 0 | ||
val lx = Lazy { | ||
x += 1 | ||
x | ||
} | ||
assertEquals(x, 0) | ||
assertEquals(lx.value, 1) | ||
assertEquals(x, 1) | ||
assertEquals(lx.value, 1) | ||
} | ||
|
||
test("Lazy.fix") { | ||
val lxs = Lazy.fix[LazyList[Int]](lxs => LazyList.cons(1, lxs.value).scanLeft(0)(_ + _)) | ||
assertEquals(lxs.value.take(10), LazyList(0, 1, 1, 2, 3, 5, 8, 13, 21, 34)) | ||
} | ||
|
||
test("Lazy#map") { | ||
assertEquals(Lazy(1).map(_ + 2).value, 3) | ||
} | ||
|
||
test("Lazy#flatMap") { | ||
assertEquals(Lazy(1).flatMap(x => Lazy(x + 2)).value, 3) | ||
} | ||
} |
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