Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
guizmaii committed Nov 13, 2024
1 parent b54a7c4 commit cd4bb94
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,15 @@ import zio.test._
import zio.test.laws._

object CommutativeBothSpec extends ZIOBaseSpec {

val optional: GenF[Any, Optional] =
new GenF[Any, Optional] {
def apply[R1, A](gen: Gen[R1, A])(implicit trace: Trace): Gen[R1, Optional[A]] =
Gen.option(gen)
}
import Fixtures._

def spec: Spec[Environment, Any] =
suite("CommutativeBothSpec")(
suite("laws")(
test("chunk")(checkAllLaws(CommutativeBothLaws)(GenF.chunk, Gen.chunkOf(Gen.int))),
test("list")(checkAllLaws(CommutativeBothLaws)(GenF.list, Gen.int)),
test("option")(checkAllLaws(CommutativeBothLaws)(GenF.option, Gen.int)),
test("optional")(checkAllLaws(CommutativeBothLaws)(optional, Gen.int)),
test("optional")(checkAllLaws(CommutativeBothLaws)(optionalGenF, Gen.int)),
test("vector")(checkAllLaws(CommutativeBothLaws)(GenF.vector, Gen.vectorOf(Gen.int)))
)
)
Expand Down
7 changes: 7 additions & 0 deletions core-tests/shared/src/test/scala/zio/prelude/Fixtures.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package zio.prelude

import zio.prelude.data.Optional
import zio.test.laws.GenF
import zio.test.{Gen, Sized}
import zio.{Chunk, Trace}
Expand All @@ -22,4 +23,10 @@ object Fixtures {

implicit val chunkOptionInvariant: Invariant[ChunkOption] =
Invariant[Chunk].compose[Option]

val optionalGenF: GenF[Any, Optional] =
new GenF[Any, Optional] {
def apply[R1, A](gen: Gen[R1, A])(implicit trace: Trace): Gen[R1, Optional[A]] =
Gen.option(gen)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ object ForEachSpec extends ZIOBaseSpec {
test("list")(checkAllLaws(ForEachLaws)(GenF.list, Gen.int)),
test("map")(checkAllLaws(ForEachLaws)(GenFs.map(Gen.int), Gen.int)),
test("option")(checkAllLaws(ForEachLaws)(GenF.option, Gen.int)),
test("optional")(checkAllLaws(ForEachLaws)(optionalGenF, Gen.int)),
test("vector")(checkAllLaws(ForEachLaws)(GenF.vector, Gen.int))
),
suite("combinators")(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
package zio.prelude

import zio.Trace
import zio.prelude.laws._
import zio.prelude.data.Optional
import zio.test._
import zio.test.laws._

object IdentityBothSpec extends ZIOBaseSpec {

val optional: GenF[Any, Optional] =
new GenF[Any, Optional] {
def apply[R1, A](gen: Gen[R1, A])(implicit trace: Trace): Gen[R1, Optional[A]] =
Gen.option(gen)
}
import Fixtures._

def spec: Spec[Environment, Any] =
suite("IdentityBothSpec")(
suite("laws")(
test("either")(checkAllLaws(IdentityBothLaws)(GenF.either(Gen.int), Gen.int)),
test("list")(checkAllLaws(IdentityBothLaws)(GenF.list, Gen.int)),
test("option")(checkAllLaws(IdentityBothLaws)(GenF.option, Gen.int)),
test("optional")(checkAllLaws(IdentityBothLaws)(optional, Gen.int)),
test("optional")(checkAllLaws(IdentityBothLaws)(optionalGenF, Gen.int)),
test("try")(checkAllLaws(IdentityBothLaws)(GenFs.tryScala, Gen.int))
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
package zio.prelude

import zio.Trace
import zio.prelude.laws.IdentityEitherlaws
import zio.prelude.data.Optional
import zio.test._
import zio.test.laws._

object IdentityEitherSpec extends ZIOBaseSpec {

val optional: GenF[Any, Optional] =
new GenF[Any, Optional] {
def apply[R1, A](gen: Gen[R1, A])(implicit trace: Trace): Gen[R1, Optional[A]] =
Gen.option(gen)
}
import Fixtures._

def spec: Spec[Environment, Any] =
suite("IdentityEitherSpec")(
suite("laws")(
test("chunk")(checkAllLaws(IdentityEitherlaws)(GenF.chunk, Gen.int)),
test("list")(checkAllLaws(IdentityEitherlaws)(GenF.list, Gen.int)),
test("option")(checkAllLaws(IdentityEitherlaws)(GenF.option, Gen.int)),
test("optional")(checkAllLaws(IdentityEitherlaws)(optional, Gen.int)),
test("optional")(checkAllLaws(IdentityEitherlaws)(optionalGenF, Gen.int)),
test("set")(checkAllLaws(IdentityEitherlaws)(GenF.set, Gen.int)),
test("vector")(checkAllLaws(IdentityEitherlaws)(GenF.vector, Gen.int))
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
package zio.prelude

import zio.Trace
import zio.prelude.laws._
import zio.prelude.data.Optional
import zio.test._
import zio.test.laws._

object IdentityFlattenSpec extends ZIOBaseSpec {

val optional: GenF[Any, Optional] =
new GenF[Any, Optional] {
def apply[R1, A](gen: Gen[R1, A])(implicit trace: Trace): Gen[R1, Optional[A]] =
Gen.option(gen)
}
import zio.prelude.Fixtures._

def spec: Spec[Environment, Any] =
suite("IdentityFlattenSpec")(
Expand All @@ -21,7 +14,7 @@ object IdentityFlattenSpec extends ZIOBaseSpec {
test("either")(checkAllLaws(IdentityFlattenLaws)(GenFs.either(Gen.int), Gen.int)),
test("list")(checkAllLaws(IdentityFlattenLaws)(GenF.list, Gen.int)),
test("option")(checkAllLaws(IdentityFlattenLaws)(GenF.option, Gen.int)),
test("optional")(checkAllLaws(IdentityFlattenLaws)(optional, Gen.int)),
test("optional")(checkAllLaws(IdentityFlattenLaws)(optionalGenF, Gen.int)),
test("vector")(checkAllLaws(IdentityFlattenLaws)(GenF.vector, Gen.int))
)
)
Expand Down

0 comments on commit cd4bb94

Please sign in to comment.