Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
makenowjust committed Aug 1, 2021
1 parent 5f2ab05 commit 4b34a83
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ class TardisSuite extends munit.FunSuite {
Mov
)

val (lb, lf, lis) = assemble(0, input).run(Map.empty[String, Int], Map.empty[String, Int])
assertEquals(lb.value, Map("my_label" -> 5, "second_label" -> 5))
assertEquals(lf.value, Map("my_label" -> 5, "second_label" -> 5))
assertEquals(
assemble(0, input).run(Map.empty[String, Int], Map.empty[String, Int])._3.value,
lis.value,
List(
(0, Add),
(1, Add),
Expand All @@ -73,4 +76,28 @@ class TardisSuite extends munit.FunSuite {
)
)
}

test("Tardis.putBackward") {
val program: Tardis[Int, Int, (Int, Int, Int)] = for {
s1 <- Tardis.getBackward[Int, Int]
_ <- Tardis.putBackward[Int, Int](Lazy(1))
s2 <- Tardis.getBackward[Int, Int]
_ <- Tardis.putBackward[Int, Int](Lazy(2))
s3 <- Tardis.getBackward[Int, Int]
} yield Lazy((s1.value, s2.value, s3.value))
val (_, _, ls123) = program.run(Lazy(3), Lazy(0))
assertEquals(ls123.value, (1, 2, 3))
}

test("Tardis.putForward") {
val program: Tardis[Int, Int, (Int, Int, Int)] = for {
s1 <- Tardis.getForward[Int, Int]
_ <- Tardis.putForward[Int, Int](Lazy(2))
s2 <- Tardis.getForward[Int, Int]
_ <- Tardis.putForward[Int, Int](Lazy(3))
s3 <- Tardis.getForward[Int, Int]
} yield Lazy((s1.value, s2.value, s3.value))
val (_, _, ls123) = program.run(Lazy(0), Lazy(1))
assertEquals(ls123.value, (1, 2, 3))
}
}

0 comments on commit 4b34a83

Please sign in to comment.