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.

Version 3.x, register Arbitraries directly with ArbMap

See original GitHub issue

Feature

I love the move to ArbMap in v3, over the thread-level registry.

It’d be great if we could directly register Arbitrary instances with ArbMap instead of needing an intermediary type with static members.

For example

let customArb = //...
ArbMap.defaults |> ArbMap.with customArb

This would allow users to simply define and use an Arbitrary all in one local scope. This seems especially relevant now that ArbMap enables users to override type generation in a limited scope. It seems likely users would define an arbitrary only meant to be used in constructing some parent arbitrary.

Implementation Ideas

It seems TypeClass currently bears the responsibility for tracking the map of types to Arbitrary instances, and it tracks them as Map<InstanceKind,MethodInfo>.

In order to directly register Arbitraries, this map would need to change.

I haven’t quite grasped TypeClass yet, but here’s my idea.

  • It makes sense to me that ArbMap is responsible for tracking instances of arbitraries, maybe Map<InstanceKind,IArbitrary>.
  • TypeClass can be responsible for knowing what a match looks like / the light construction it seems to do
    • maybe arbMap |> TypeClass.getInstance type
  • Discovery then also probably moves somewhere else, and it outputs an ArbMap
    • maybe let arbMap = Discover.factoriesOnType<type> (or maybe it outputs a Map<Type, IArbitrary>)
    • If we don’t want to invoke the factories right away, then we could create some internal lazy Arbitrary derivative that invokes the matched static factory on first call

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
farlee2121commented, Jun 30, 2022

I think the work is ready for review. I’ve experimented with both the Fluent and FSharp APIs, and it seems to work as I expect. I added tests for any errors I found.

The public endpoint names may need some tweaking

//Fsharp.ArbMap
let mergeFactory (factory: unit -> Arbitrary<'b>) (existingMap: IArbMap) 
let mergeArbFactory (factory: Arbitrary<'a> -> Arbitrary<'b>) (existingMap: IArbMap)
let mergeMapFactory (factory: IArbMap -> Arbitrary<'b>) (existingMap: IArbMap) 
let mergeArb (arb: Arbitrary<'a>) (existingMap: IArbMap)  
//Fluent.ArbMap
static member MergeArb<'T>(map: IArbMap, arb:Arbitrary<'T>);
static member MergeArbFactory<'T>(map: IArbMap, factory:Func<IArbMap,Arbitrary<'T>>) ;
static member MergeArbFactory<'T, 'U>(map: IArbMap, factory:Func<Arbitrary<'T>,Arbitrary<'U>>);
static member MergeArbFactory<'T>(map: IArbMap, factory:Func<Arbitrary<'T>>);
1reaction
farlee2121commented, Jun 23, 2022

Ah. I see how I misread your earlier comment.

I think you’re correct, but I also think the category of arbitraries made from other generators and arbitraries is a pretty significant category. The library offers a pretty robust set of building blocks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Test data: generators, shrinkers and Arbitrary instances
FsCheck also allows you to register Arbitrary instances in a Type to Arbitrary ... ArbMap.generate<int> |> Gen.map Leaf Gen.map2 (fun x y ->...
Read more >
FsCheck: Override generator for a type, but only in the ...
In FsCheck 3 (prerelease) you can configure this via a new (as of yet ... in the resulting ArbMap ) and then you...
Read more >
FsCheck Release Notes.md
Removed register , registerByType , from , generate and shrink - these are replaced by functions on ArbMap , resp. mergeWith , mergeWithType...
Read more >
QuickChecking Static Analysis Properties
Compared to the conference version [3], this paper ... input, and (2) properties that should be tested on the arbitrary input. Two domain-specific...
Read more >
Changelog
Kotest now requires the runtime version of JUnit to be at least 5.8.x ... data driven tests to register in root scope #1967;...
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