Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType}
import ReleaseTransformations._

val catsVersion = "2.6.1"
val catsTestkitScalatestVersion = "2.1.5"
val munitDisciplineVersion = "1.0.9"
val scalacheckVersion = "1.15.4"
val algebraVersion = "2.2.3"
val Scala212 = "2.12.14"
Expand Down Expand Up @@ -72,7 +72,19 @@ lazy val `cats-collections` = project.in(file("."))
releaseStepCommand("sonatypeReleaseAll"),
setNextVersion,
commitNextVersion,
pushChanges))
pushChanges)
)

lazy val commonJsSettings = Seq(
Global / scalaJSStage := FullOptStage,
Test / scalaJSStage := FastOptStage,
parallelExecution := false,
jsEnv := new org.scalajs.jsenv.nodejs.NodeJSEnv(),
// batch mode decreases the amount of memory needed to compile Scala.js code
scalaJSLinkerConfig := scalaJSLinkerConfig.value.withBatchMode(githubIsWorkflowBuild.value),
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule)),
coverageEnabled := false
)

lazy val core = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Pure)
Expand All @@ -95,7 +107,7 @@ lazy val core = crossProject(JSPlatform, JVMPlatform)
}
}
)
.jsSettings(coverageEnabled := false)
.jsSettings(commonJsSettings)

lazy val coreJVM = core.jvm
lazy val coreJS = core.js
Expand All @@ -109,7 +121,7 @@ lazy val scalacheck = crossProject(JSPlatform, JVMPlatform)
.settings(
libraryDependencies += "org.scalacheck" %%% "scalacheck" % scalacheckVersion
)
.jsSettings(coverageEnabled := false)
.jsSettings(commonJsSettings)

lazy val scalacheckJVM = scalacheck.jvm
lazy val scalacheckJS = scalacheck.js
Expand All @@ -123,7 +135,7 @@ lazy val laws = crossProject(JSPlatform, JVMPlatform)
.settings(
libraryDependencies += "org.typelevel" %%% "cats-laws" % catsVersion
)
.jsSettings(coverageEnabled := false)
.jsSettings(commonJsSettings)

lazy val lawsJVM = laws.jvm
lazy val lawsJS = laws.js
Expand All @@ -135,17 +147,19 @@ lazy val tests = crossProject(JSPlatform, JVMPlatform)
.settings(moduleName := "cats-collections-tests")
.settings(dogsSettings:_*)
.settings(noPublishSettings)
.settings(coverageEnabled := false,
Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-oDF"),
.settings(
coverageEnabled := false,
Test / testOptions += Tests.Argument(TestFrameworks.MUnit),
Test / testOptions += Tests.Argument(TestFrameworks.ScalaCheck, "-minSuccessfulTests", "1000"), // "-verbosity", "2"), // increase for stress tests
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-laws" % catsVersion % "test",
"org.typelevel" %%% "algebra-laws" % algebraVersion % "test",
"org.typelevel" %%% "cats-testkit-scalatest" % catsTestkitScalatestVersion % "test"
"org.typelevel" %%% "discipline-munit" % munitDisciplineVersion % "test"
),
buildInfoPackage := "cats.collections",
buildInfoKeys := Seq("isJvm" -> (crossProjectPlatform.value == JVMPlatform))
)
.jsSettings(commonJsSettings)

lazy val testsJVM = tests.jvm
lazy val testsJS = tests.js
Expand Down
48 changes: 48 additions & 0 deletions tests/src/test/scala/cats/collections/AnotherDietSuite.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package cats.collections

import cats.Eval
import munit.DisciplineSuite
import org.scalacheck._
import org.scalacheck.Prop._

class AnotherDietSuite extends DisciplineSuite {
import DietSuite._

override def scalaCheckTestParameters: Test.Parameters =
DefaultScalaCheckPropertyCheckConfig.default
.withMinSuccessfulTests(if (BuildInfo.isJvm) 300 else 30)

property("foldLeft")(forAll { (rs: Ranges, start: Int, f: (Int, Int) => Int) =>
assertEquals(rs.toDiet.foldLeft(start)(f), rs.toSet.toList.sorted.foldLeft(start)(f))
})

property("foldLeft/toList")(forAll { rs: Ranges =>
assertEquals(rs.toDiet.foldLeft(List.empty[Int])(_ :+ _), rs.toDiet.toList)
})

property("foldRight")(forAll { (rs: Ranges, start: Int, f: (Int, Int) => Int) =>
assertEquals(
rs.toDiet.foldRight(Eval.now(start))((v, acc) => acc.map(f(v, _))).value,
rs.toSet.toList.sorted.foldRight(start)(f))
})

property("foldRight/toList")(forAll { rs: Ranges =>
assertEquals(
rs.toDiet.foldRight(Eval.now(List.empty[Int]))((v, acc) => acc.map(v :: _)).value,
rs.toDiet.toList
)
})

property("not be modified when inserting existing item")(forAll { d: Diet[Int] =>
d.toList.forall(elem =>
// there may be structural changes, so fall back to list comparison
d.add(elem).toList == d.toList
)
})

property("--")(forAll { (d1: Diet[Int], d2: Diet[Int]) =>
val d = d1 -- d2
d2.toList.foreach(elem => assert(!d.contains(elem)))
d1.toList.foreach(elem => assert(d2.contains(elem) || d.contains(elem)))
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package cats.collections

import org.scalacheck.Test.Parameters

object DefaultScalaCheckPropertyCheckConfig {
final val default: Parameters = Parameters.default
.withMinSuccessfulTests(if (BuildInfo.isJvm) 50 else 5)
.withMaxDiscardRatio(if (BuildInfo.isJvm) 5 else 50)
.withMinSize(0)
.withWorkers(if (BuildInfo.isJvm) 2 else 1)
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package cats.collections
package tests

import cats.collections.arbitrary.cogen._
import org.scalacheck._
import org.scalacheck.Arbitrary.{arbitrary=>getArbitrary,_}
import cats._
import cats.collections.arbitrary.cogen._
import cats.laws.discipline._
import cats.tests.CatsSuite
import munit.DisciplineSuite
import org.scalacheck._
import org.scalacheck.Arbitrary.{arbitrary => getArbitrary, _}
import org.scalacheck.Prop._

class DequeueSpec extends CatsSuite {
class DequeueSuite extends DisciplineSuite {
import Dequeue._

override def scalaCheckTestParameters: Test.Parameters =
DefaultScalaCheckPropertyCheckConfig.default

checkAll("Dequeue[Int]", CoflatMapTests[Dequeue].coflatMap[Int, Int, Int])
checkAll("CoflatMap[Dequeue]", SerializableTests.serializable(CoflatMap[Dequeue]))

Expand Down Expand Up @@ -45,36 +48,36 @@ class DequeueSpec extends CatsSuite {
val x = "xyzzy"
val q = Dequeue.empty cons x

q.uncons should be(Some((x,EmptyDequeue())))
q.unsnoc should be(Some((x,EmptyDequeue())))
assertEquals(q.uncons, Some((x,EmptyDequeue())))
assertEquals(q.unsnoc, Some((x,EmptyDequeue())))
}

test("cons and then uncons")(forAll { (xs: List[Int]) =>
property("cons and then uncons")(forAll { xs: List[Int] =>
val q = consL(xs, Dequeue.empty)
val l = unconsL(q, List.empty)

xs should be (l)
assertEquals(xs, l)
})

test("snoc and then unsnoc")(forAll { (xs: List[Int]) =>
property("snoc and then unsnoc")(forAll { xs: List[Int] =>
val q = snocL(xs, Dequeue.empty)
val l = unsnocL(q, List.empty)

xs should be(l)
assertEquals(xs, l)
})

test("cons and then unsnoc")(forAll { (xs: List[Int]) =>
property("cons and then unsnoc")(forAll { xs: List[Int] =>
val q = consL(xs, Dequeue.empty)
val l = unsnocL(q, List.empty)

xs should be(l.reverse)
assertEquals(xs, l.reverse)
})

test("snoc and then uncons")(forAll { (xs: List[Int]) =>
property("snoc and then uncons")(forAll { xs: List[Int] =>
val q = snocL(xs, Dequeue.empty)
val l = unconsL(q, List.empty)

xs should be(l.reverse)
assertEquals(xs, l.reverse)
})

implicit def genQ[A: Arbitrary]: Arbitrary[Dequeue[A]] = Arbitrary(
Expand All @@ -83,45 +86,45 @@ class DequeueSpec extends CatsSuite {
r <- getArbitrary[List[A]]
} yield consL(l, snocL(r, Dequeue.empty)))

test("foldLeft")(forAll{ (q: Dequeue[Int]) =>
q.foldLeft[List[Int]](List.empty)((xs,x) => x :: xs) should be (q.reverse.toList)
property("foldLeft")(forAll{ q: Dequeue[Int] =>
assertEquals(q.foldLeft[List[Int]](List.empty)((xs,x) => x :: xs), q.reverse.toList)
})

test("foldRight")(forAll { (q: Dequeue[Int]) =>
q.foldRight[List[Int]](Eval.now(List.empty))((x,xs) => xs.map(xs => x ::xs)).value should be (q.toList)
property("foldRight")(forAll { q: Dequeue[Int] =>
assertEquals(q.foldRight[List[Int]](Eval.now(List.empty))((x,xs) => xs.map(xs => x ::xs)).value, q.toList)
})

test("toList")(forAll { (q: Dequeue[Int]) =>
q.toList should be (q.toIterator.toList)
property("toList")(forAll { q: Dequeue[Int] =>
assertEquals(q.toList, q.toIterator.toList)
})

test("toList/reverse")(forAll { (q: Dequeue[Int]) =>
q.reverse.toList should be (q.toIterator.toList.reverse)
property("toList/reverse")(forAll { q: Dequeue[Int] =>
assertEquals(q.reverse.toList, q.toIterator.toList.reverse)
})

test("toList/append")(forAll { (q1: Dequeue[Int], q2: Dequeue[Int]) =>
(q1 ++ q2).toList should be (q1.toList ::: q2.toList)
property("toList/append")(forAll { (q1: Dequeue[Int], q2: Dequeue[Int]) =>
assertEquals((q1 ++ q2).toList, q1.toList ::: q2.toList)
})

test("toList/Foldable consistency")(forAll { (q: Dequeue[Int]) =>
q.toList should be (Foldable[Dequeue].toList(q))
property("toList/Foldable consistency")(forAll { q: Dequeue[Int] =>
assertEquals(q.toList, Foldable[Dequeue].toList(q))
})

test("toList/toStream consistency")(forAll { (q: Dequeue[Int]) =>
q.toList should be (q.to[Stream, Int].toList)
property("toList/toStream consistency")(forAll { q: Dequeue[Int] =>
assertEquals(q.toList, q.to[Stream, Int].toList)
})

test("equality")(forAll { (xs: List[Int]) =>
property("equality")(forAll { xs: List[Int] =>
val q1 = consL(xs, Dequeue.empty)
val q2 = snocL(xs.reverse, Dequeue.empty)
Eq[Dequeue[Int]].eqv(q1, q2) should be (true)
assert(Eq[Dequeue[Int]].eqv(q1, q2), true)
})

test("inequality")(forAll { (xs: List[Int], ys: List[Int]) =>
property("inequality")(forAll { (xs: List[Int], ys: List[Int]) =>
val q1 = consL(xs, Dequeue.empty)
val q2 = consL(ys, Dequeue.empty)
whenever(xs != ys) {
Eq[Dequeue[Int]].eqv(q1, q2) should be (false)
if (xs != ys) {
assertEquals(Eq[Dequeue[Int]].eqv(q1, q2), false)
}
})

Expand Down
Loading