Giter VIP home page Giter VIP logo

Comments (16)

cmeeren avatar cmeeren commented on June 11, 2024 1

Nearly finished with an implementation of what I described above. Seems to work brilliantly. Will create a PR when I'm done, need to test it thoroughly.

from fsharp-hedgehog-experimental.

moodmosaic avatar moodmosaic commented on June 11, 2024 1

So in this case the user would pass the generator for that type through the dictionary.

from fsharp-hedgehog-experimental.

cmeeren avatar cmeeren commented on June 11, 2024

Any thoughts on this?

from fsharp-hedgehog-experimental.

moodmosaic avatar moodmosaic commented on June 11, 2024

I apologize for the delay, I've been busy. I'll get back to this soon. /cc @jystic

from fsharp-hedgehog-experimental.

moodmosaic avatar moodmosaic commented on June 11, 2024

There should be quite a few ways of doing this, and I think I'm not convinced with any of them:

from fsharp-hedgehog-experimental.

moodmosaic avatar moodmosaic commented on June 11, 2024

I'd start looking for the most type safe approach which immediately excludes the emulation of Haskell typeclasses and the dictionary lookup.

from fsharp-hedgehog-experimental.

cmeeren avatar cmeeren commented on June 11, 2024

I haven't thought too hard on this, but recursively auto-generating custom types seems inherently un-typesafe to me. How could it be made type-safe? Could you share an example?

from fsharp-hedgehog-experimental.

cmeeren avatar cmeeren commented on June 11, 2024

Hmm, I just thought of another way to solve the specific problem of stack overflow when auto-generating recursive types (which is the main reason I wanted this override functionality in the first place).

We can add a recursionDepth: int parameter to the config. An inner auto function can get passed a Map<System.Type, int> that describes how many times the given type has recursed. When it reaches the recursion depth, it will as far as possible stop generating these (e.g. None if it's an option of that type, or empty list if it's a list of that type).

For example, say we have a Customer with a list of child customers also of the type Customer. We generate this with a recursion depth of 1. For each sub-type it generates, it checks the map to see how many times it has recursed. Initially of course, the map won't contain the Customer type key (i.e., recursed zero times). So now it adds Customer to the map with the value 1, and generates a list of sub-customers, passing along the modified map. When this auto call gets to the same Customer list generation, it'll see that Customer has recursed once, and the recursion limit (from the config) is 1, so it'll generate an empty list.

What do you think?

from fsharp-hedgehog-experimental.

moodmosaic avatar moodmosaic commented on June 11, 2024

On mobile right now, but looking forward to your PR.

from fsharp-hedgehog-experimental.

dharmaturtle avatar dharmaturtle commented on June 11, 2024

I'm interested in this feature. In my case, attempting to auto NodaTime's Instant yields "System.Exception: Class NodaTime.Instant lacking an appropriate ctor". Since my application uses Instant liberally (it's analogous to System.DateTime or System.DateTimeOffset), creating handcrafted generators for each type is annoying.

Of the 5 options given, I feel like I only understand the dictionary approach. I'd pass a list of Generators as a new field on AutoGenConfig, then use reflection to create an internal dictionary.

@moodmosaic have your thoughts evolved on this issue?

from fsharp-hedgehog-experimental.

cmeeren avatar cmeeren commented on June 11, 2024

I'd pass a list of Generators as a new field on AutoGenConfig, then use reflection to create an internal dictionary.

How does reflection enter into the picture? Are you talking about using reflection to obtain a list of the defined generators in the test library, and fill a dictionary with those?


@moodmosaic I don't see any important downsides to the dictionary approach. Could you elaborate, if you still hold this position? The only "downside" I can see is that the user, when using auto, has no guarantees about the contents of the config (specifically the custom generator map), and therefore isn't guaranteed that their custom configs are actually used. But I don't see how that can be guaranteed no matter which solution is used.

from fsharp-hedgehog-experimental.

moodmosaic avatar moodmosaic commented on June 11, 2024

I can't remember (it's been ~3 years) but it seems strange to me right now why I excluded the dictionary approach.

(I could understand that excluding the typeclass emulation sounds reasonable.)

I'd just go with the dictionary approach now.

from fsharp-hedgehog-experimental.

TysonMN avatar TysonMN commented on June 11, 2024

I think this functionality would provide a workaround for hedgehogqa/fsharp-hedgehog#249.

from fsharp-hedgehog-experimental.

moodmosaic avatar moodmosaic commented on June 11, 2024

Yep. (Though I think we ought to provide out-of-the-box primitive generators.)

from fsharp-hedgehog-experimental.

TysonMN avatar TysonMN commented on June 11, 2024

Agree. I just think it is interesting to see the connection.

from fsharp-hedgehog-experimental.

cmeeren avatar cmeeren commented on June 11, 2024

I hope to have implemented this feature during the weekend. I will make a PR so you can have a look at it.

Also I think I'll wait with releasing a new version until hedgehogqa/fsharp-hedgehog#249 is fixed, so I can include changes that depend on that, too (specifically, adding support for single and decimal to the auto-generator).

from fsharp-hedgehog-experimental.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.