mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-20 01:07:18 +03:00
Fix test for groupContiguous (#5432)
* Fix test for groupContiguous Automatic generation of test values was prone to cause flakiness, removed in favor of a simpler test case. changelog_begin changelog_end * Relax order sensitivity * Update ledger/sandbox/src/test/suite/scala/com/digitalasset/platform/store/dao/events/GroupContiguousSpec.scala Co-Authored-By: Remy <remy.haemmerle@daml.com> * Fix compilation issue Co-authored-by: Remy <remy.haemmerle@daml.com>
This commit is contained in:
parent
e4ec7ab405
commit
a7474f4c50
@ -5,7 +5,6 @@ package com.digitalasset.platform.store.dao.events
|
||||
|
||||
import akka.stream.scaladsl.{Sink, Source}
|
||||
import com.digitalasset.ledger.api.testing.utils.AkkaBeforeAndAfterAll
|
||||
import org.scalacheck.Gen
|
||||
import org.scalatest.concurrent.ScalaFutures
|
||||
import org.scalatest.prop.PropertyChecks
|
||||
import org.scalatest.{AsyncFlatSpec, Matchers}
|
||||
@ -18,7 +17,6 @@ final class GroupContiguousSpec
|
||||
with AkkaBeforeAndAfterAll {
|
||||
|
||||
behavior of "groupContiguous"
|
||||
import GroupContiguousSpec.contiguous
|
||||
|
||||
it should "be equivalent to grouping on inputs with an ordered key" in forAll {
|
||||
pairs: List[(Int, String)] =>
|
||||
@ -29,36 +27,26 @@ final class GroupContiguousSpec
|
||||
}
|
||||
}
|
||||
|
||||
it should "be equivalent to grouping on inputs with a contiguous key" in forAll(contiguous) {
|
||||
pairsWithContiguousKeys =>
|
||||
val grouped = groupContiguous(Source(pairsWithContiguousKeys))(by = _._1)
|
||||
whenReady(grouped.runWith(Sink.seq[Vector[(Int, String)]])) {
|
||||
_ should contain theSameElementsAs pairsWithContiguousKeys.groupBy(_._1).values
|
||||
}
|
||||
it should "be equivalent to grouping on inputs with a contiguous key" in {
|
||||
val pairsWithContiguousKeys = List(1 -> "baz", 0 -> "foo", 0 -> "bar", 0 -> "quux")
|
||||
val grouped = groupContiguous(Source(pairsWithContiguousKeys))(by = _._1)
|
||||
whenReady(grouped.runWith(Sink.seq[Vector[(Int, String)]])) {
|
||||
_.map(_.toSet) should contain theSameElementsAs pairsWithContiguousKeys
|
||||
.groupBy(_._1)
|
||||
.map(_._2.toSet)
|
||||
}
|
||||
}
|
||||
|
||||
it should "behave as expected when grouping inputs without a contiguous key" in {
|
||||
val pairs = List(0 -> "foo", 0 -> "bar", 1 -> "baz", 0 -> "quux")
|
||||
val grouped = groupContiguous(Source(pairs))(by = _._1)
|
||||
whenReady(grouped.runWith(Sink.seq[Vector[(Int, String)]])) {
|
||||
_ should contain theSameElementsAs Vector(
|
||||
Vector(0 -> "foo", 0 -> "bar"),
|
||||
Vector(1 -> "baz"),
|
||||
Vector(0 -> "quux"),
|
||||
_.map(_.toSet) should contain theSameElementsAs Vector(
|
||||
Set(0 -> "foo", 0 -> "bar"),
|
||||
Set(1 -> "baz"),
|
||||
Set(0 -> "quux"),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
object GroupContiguousSpec {
|
||||
|
||||
private val contiguous =
|
||||
for {
|
||||
n <- Gen.oneOf(Gen.const(0), Gen.posNum[Int], Gen.negNum[Int])
|
||||
l <- Gen.size
|
||||
s <- Gen.asciiPrintableStr
|
||||
ss <- Gen.listOfN(l, s)
|
||||
} yield List.fill(l)(n).zip(ss)
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user