scalascalacheck

amount of generated entity in scala check


I have a scalacheck test with case class Payment Seq and I want to check and generate Seq with 10,000 elements. Could you tell me please how to control the amount of elements in Seq in test?

import org.scalacheck.{Arbitrary, Gen}

  test("payment test") {
    implicit val arbitraryEntityType: Arbitrary[Payment] = Arbitrary(genPayment)

    forAll { (payment: Seq[Payment]) =>


implicit val genUserId: Gen[Int] = Gen.oneOf(10010 to 30000)

implicit val genVisaType: Gen[String] = Gen.oneOf("VISA", "MASTER")

case class Payment(
    user_id: Int,
    pay_doc_type: String,
    .... )


implicit val genPayment: Gen[Payment] = for {
  user_id      <- genUserId
  pay_doc_type <- genVisaType
} yield Payment(
  user_id,
  pay_doc_type,
)

Solution

  • You can use containerOfN:

    import org.scalacheck.Gen.containerOfN
    
    implicit val limitedPayments: Gen[Seq[Payment]] = containerOfN[Seq, Payment](10000, genPayment)