Skip to content

Nested non empty list generation fail #581

@zallesov

Description

@zallesov

Some changes in 1.14.1 and 1.14.2 make the following test to fail during value generation. With the version 1.14.0, it passes.

This makes it impossible to use generators with nested collections.

package io.moia.dispatching
package execution.impl

import org.scalacheck.Gen
class PlaygroundTest extends UnitTest {

//import org.scalactic.anyvals.PosZDouble
//  implicit override val generatorDrivenConfig =
//    PropertyCheckConfiguration(maxDiscardedFactor = PosZDouble(20.0))

  "Playground test" should {

    case class Item(list: List[Int])
    case class Wrapper(list: List[Item])
    case class NestedList(list: List[List[Int]])

    val itemGen: Gen[Item] = for {
      list <- Gen.nonEmptyListOf(Gen.posNum[Int])
    } yield Item(list)

    val wrapperGen: Gen[Wrapper] = for {
      list <- Gen.nonEmptyListOf(itemGen)
    } yield {
      Wrapper(list)
    }

    val nestedGen: Gen[NestedList] = for {
      list <- Gen.nonEmptyListOf(Gen.nonEmptyListOf(Gen.posNum[Int]))
    } yield {
      NestedList(list)
    }

    "Wrapper" in {
      forAll(wrapperGen) { wrapper =>
        wrapper.list.size should (be > 0)
      }
    }

    "Nested" in {
      forAll(nestedGen) { nested =>
        nested.list.size should (be > 0)
      }
    }
  }
}

Output

[info]  PlaygroundTest:
[info] Playground test
[info] - should Wrapper *** FAILED ***
[info]   Gave up after 6 successful property evaluations. 126 evaluations were discarded.
[info] - should Nested *** FAILED ***
[info]   Gave up after 6 successful property evaluations. 167 evaluations were discarded.

I believe the change that results in the issue was introduced here.
https://github.com/typelevel/scalacheck/blob/1.14.x/src/main/scala/org/scalacheck/Gen.scala#L866

Thank you.

PS. this looks related #568
PSS. seems like it is already being fixed in master.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions