Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Data generation#

Sumit Rawal answered on May 23, 2023 Popularity 6/10 Helpfulness 1/10

Contents


More Related Answers

  • generatedata

  • Data generation#

    0

    We will start by writing some data generators using the ScalaCheck library.

    ScalaCheck already provides several generators for primitives, but for the data models, we have to do some more plumbing.

    ScalaCheck generate LanguageCode

    Let’s start by generating a language code.

    1

    val genLanguageCode: Gen[LanguageCode] = Gen.oneOf(LanguageCodes.all)

    Generate LanguageCode

    Using the Gen.oneOf helper from the library makes the code extremely simple.

    ScalaCheck generate UUID

    Generating a UUID is nothing special, either.

    12

    val genUuid: Gen[UUID] = Gen.delay(UUID.randomUUID)

    )

    Generate UUID

    We might be tempted to use Gen.const here, but we don’t because it will then become immutable.

    Another option is using a list of randomly generated UUID values from which we then chose one. That would be sufficient for generators that only generate a single product, but if we want to generate lists of products, we would have duplicate IDs sooner or later. 

    Popularity 6/10 Helpfulness 1/10 Language scala
    Source: Grepper
    Tags: scala
    Link to this answer
    Share Copy Link
    Contributed on May 23 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.