@@ -331,14 +331,84 @@ module Generators =
331331 |> genericSparseGenerator false Arb.generate< bool>
332332 |> Arb.fromGen
333333
334- // type ArrayOfDistinctKeys() =
335- // // Stack overflow.
336- // static member ArrayOfDistinctKeysArb() =
337- // gen {
338- // let! array = Arb.generate<(uint64 * int)[]>
339- // return Array.distinctBy (fun (key, _) -> key) array
340- // }
341- // |> Arb.fromGen
334+ type ArrayOfDistinctKeys () =
335+ static let arrayOfDistinctKeysGenerator ( keysGenerator : Gen < 'n >) ( valuesGenerator : Gen < 'a >) =
336+ let tuplesGenerator =
337+ Gen.map3
338+ <| fun a b c -> a, b, c
339+ <| keysGenerator
340+ <| keysGenerator
341+ <| valuesGenerator
342+
343+ gen {
344+ let! length =
345+ Gen.sized
346+ <| fun size -> Gen.choose ( 1 , size)
347+
348+ let! array =
349+ Gen.arrayOfLength
350+ <| length
351+ <| tuplesGenerator
352+
353+ return Array.distinctBy ( fun ( r , c , _ ) -> r, c) array
354+ }
355+
356+ static member IntType () =
357+ arrayOfDistinctKeysGenerator
358+ <| Arb.generate< int>
359+ <| Arb.generate< int>
360+ |> Arb.fromGen
361+
362+ static member FloatType () =
363+ arrayOfDistinctKeysGenerator
364+ <| Arb.generate< int>
365+ <| ( Arb.Default.NormalFloat()
366+ |> Arb.toGen
367+ |> Gen.map float)
368+ |> Arb.fromGen
369+
370+ static member SByteType () =
371+ arrayOfDistinctKeysGenerator
372+ <| Arb.generate< int>
373+ <| Arb.generate< sbyte>
374+ |> Arb.fromGen
375+
376+ static member ByteType () =
377+ arrayOfDistinctKeysGenerator
378+ <| Arb.generate< int>
379+ <| Arb.generate< byte>
380+ |> Arb.fromGen
381+
382+ static member Int16Type () =
383+ arrayOfDistinctKeysGenerator
384+ <| Arb.generate< int>
385+ <| Arb.generate< int16>
386+ |> Arb.fromGen
387+
388+ static member UInt16Type () =
389+ arrayOfDistinctKeysGenerator
390+ <| Arb.generate< int>
391+ <| Arb.generate< uint16>
392+ |> Arb.fromGen
393+
394+ static member Int32Type () =
395+ arrayOfDistinctKeysGenerator
396+ <| Arb.generate< int>
397+ <| Arb.generate< int32>
398+ |> Arb.fromGen
399+
400+ static member UInt32Type () =
401+ arrayOfDistinctKeysGenerator
402+ <| Arb.generate< int>
403+ <| Arb.generate< uint32>
404+ |> Arb.fromGen
405+
406+ static member BoolType () =
407+ arrayOfDistinctKeysGenerator
408+ <| Arb.generate< int>
409+ <| Arb.generate< bool>
410+ |> Arb.fromGen
411+
342412
343413module Utils =
344414 type TestContext =
@@ -356,7 +426,7 @@ module Utils =
356426 typeof< Generators.PairOfMatricesOfCompatibleSize>
357427 typeof< Generators.PairOfSparseMatrixOAndVectorfCompatibleSize>
358428 typeof< Generators.PairOfSparseVectorAndMatrixOfCompatibleSize>
359- // typeof<Generators.ArrayOfDistinctKeys>
429+ typeof< Generators.ArrayOfDistinctKeys>
360430 ] }
361431
362432 let rec cartesian listOfLists =
0 commit comments