scala检查中生成的实体数量

amount of generated entity in scala check

我有一个带有 case class Payment Seq 的 scalacheck 测试,我想检查并生成包含 10,000 个元素的 Seq。你能告诉我如何在测试中控制 Seq 中的元素数量吗?

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,
)

您可以使用 containerOfN:

import org.scalacheck.Gen.containerOfN

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