question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

using list(MockUnitInt) doesn't generate a new random value each time.

See original GitHub issue

I am trying to generate lists of data with random size. I started with

MockUnit<T> things;
MockUnit<List<T>> listsOfThings = things.list(ints().range(0, 10));

my expectation from looking at the API was that each time I called listOfThings.val() I’d get a new list with a random size. in practice, the random size is evaluated once, and I get lists of the same size each time.

i’ve worked around this by doing

MockUnit<List<T>> listsOfThings = ints().range(0, 10).map( size -> things.list(size).val());

but that feels awkward.

what’s the intention of MockUnit.list(MockUnitInt) ? would you be open to a PR that evaluates the random size each time a new val is requested?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
nomemorycommented, Jan 11, 2020

Thank you for your interest. I enjoy when people actually raise those kinds of issues.

Regarding the PRs, there are many ideas hanging, but one of the things I was interested in building were:

  • implementing mockneat in other languages, e.g.: JavaScript . The fakers in the js world aren’t very smart;
  • building a mockneat server that can be used to mock rest APIs easier (descriptive approach)
  • adding mockneat @Annotations so you can decorate the model classes with hints about the data the fields are holding
  • improve the https://www.mockneat.com/docs/#reflect method so objects can be automatically populated in a recursive manner.
  • etc.
0reactions
osicommented, Jan 14, 2020

Good to hear your ideas! I’ve been primarily using the project to populate tables in a relational DB. I borrowed some from the existing SQLInsert but had made my own abstraction a bit more tailored to how I’m using it. I’ll keep your goals in mind as I continue to use the library and help enhance it appropriately.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Random number generator only generating one random number
Every time you do new Random() it is initialized using the clock. This means that in a tight loop you get the same...
Read more >
Tutorial - mockneat
Generates a integer value from the given array int[] array = new int[] {1,10 ... a new MockUnit<List<String>> , where each element from...
Read more >
Rand and RandBetween functions in Power Apps
Text = Slider1.Value + Rand() then a new random number is generated each time the Slider control's value changes and the label's text...
Read more >
Generate Random Numbers That Are Different - MathWorks
One way to get different random numbers is to initialize the generator using a different seed every time. Doing so ensures that you...
Read more >
Random Number Generation
The functions RandomChoice and RandomSample sample from a list of values with or ... Generating 10 7 numbers one at a time takes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found