<commit_before>﻿#light

namespace FsCheck

//module public Fluent //don't add a module - otherwise every class needs to be qualified

open System
open System.Linq
open System.ComponentModel
open System.Collections.Generic
open Common

//TODO:
//Within -> rely on testing frameworks?
//Throws -> rely on testing frameworks?
//"And" and "Or" should start a new property, with own classifies and labels etc (see prop_Label)
//label: maybe add some overloads, should be able to nest (see propMul)
//registering default generators per type

type WeightAndValue<'a>(weight:int,value:'a) =
    member x.Weight = weight
    member x.Value = value
    
type Any = 
    static member private OneOfSeqGen gs = 
        gs |> Seq.to_list |> oneof
    static member private OneOfSeqValue vs = 
        vs |> Seq.to_list |> elements
    static member private SequenceSeq<'a> gs = 
        gs |> Seq.to_list |> sequence |> fmapGen (fun list -> new List<'a>(list))
    static member OfType<'a>() = 
        arbitrary<'a>
    static member Value (value) = 
        constant value
    [<OverloadIDAttribute("0")>]
    static member ValueIn (values : seq<_>) = 
        values |> Any.OneOfSeqValue
    [<OverloadIDAttribute("1")>]
    static member ValueIn ([<ParamArrayAttribute>] values : array<_>) = 
        values |> Any.OneOfSeqValue
    static member IntBetween (l,h) = 
        choose (l,h)
    [<OverloadIDAttribute("0")>]
    static member WeighedValueIn ( weighedValues : seq<WeightAndValue<'a>> ) =
        weighedValues |> Any.OneOfWeighedSeqValue
    [<OverloadIDAttribute("1")>]
    static member WeighedValueIn ( [<ParamArrayAttribute>] weighedValues : array<WeightAndValue<'a>> ) =
        weighedValues |> Any.OneOfWeighedSeqValue
    static member private OneOfWeighedSeqValue ws = 
        ws |> Seq.map (fun wv -> (wv.Weight, constant wv.Value)) |> Seq.to_list |> frequency
    [<OverloadIDAttribute("0")>]
    static member GeneratorIn (generators : seq<Gen<_>>) = 
        generators |> Any.OneOfSeqGen
    [<OverloadIDAttribute("1")>]
    static member GeneratorIn ([<ParamArrayAttribute>]  generators : array<Gen<_>>) = 
        generators |> Any.OneOfSeqGen
    [<OverloadIDAttribute("0")>]
    static member WeighedGeneratorIn ( weighedValues : seq<WeightAndValue<Gen<'a>>> ) =
        weighedValues |> Any.OneOfWeighedSeq
    [<OverloadIDAttribute("1")>]
    static member WeighedGeneratorIn ( [<ParamArrayAttribute>] weighedValues : array<WeightAndValue<Gen<'a>>> ) =
        weighedValues |> Any.OneOfWeighedSeq
    static member private OneOfWeighedSeq ws = 
        ws |> Seq.map (fun wv -> (wv.Weight, wv.Value)) |> Seq.to_list |> frequency
    [<OverloadIDAttribute("0")>]
    static member SequenceOf<'a> (generators:seq<Gen<'a>>) = 
        generators |> Any.SequenceSeq
    [<OverloadIDAttribute("1")>]
    static member SequenceOf<'a> ([<ParamArrayAttribute>]generators:array<Gen<'a>>) = 
        generators |> Any.SequenceSeq
    static member OfSize (sizedGen : Func<int,Gen<_>>) =
        sized <| fun s -> (sizedGen.Invoke(s))


type Shrink =
    static member Type<'a>() = shrink<'a>

//mutable counterpart of the Config type
type Configuration() =
    let mutable maxTest = Runner.quick.MaxTest
    let mutable maxFail = Runner.quick.MaxFail
    let mutable name = Runner.quick.Name
    let mutable every = Runner.quick.Every
    let mutable everyShrink = Runner.quick.EveryShrink
    let mutable size = Runner.quick.Size
    let mutable runner = Runner.quick.Runner
    member x.MaxNbOfTest with get() = maxTest and set(v) = maxTest <- v
    member x.MaxNbOfFailedTests with get() = maxFail and set(v) = maxFail <- v
    member x.Name with get() = name and set(v) = name <- v
    member x.Every with get() = every and set(v:Func<int,obj array,string>) = every <- fun i os -> v.Invoke(i,List.to_array os)
    member x.EveryShrink with get() = everyShrink and set(v:Func<obj array,string>) = everyShrink <- fun os -> v.Invoke(List.to_array os)
    member x.Size with get() = size and set(v:Func<double,double>) = size <- v.Invoke
    member x.Runner with get() = runner and set(v) = runner <- v
    member internal x.ToConfig() =
        { MaxTest = maxTest
        ; MaxFail = maxFail 
        ; Name = name
        ; Every = every
        ; EveryShrink = everyShrink
        ; Size= size
        ; Runner = runner
        }

[<AbstractClass>]
type UnbrowsableObject() =
    inherit obj()
    [<EditorBrowsable(EditorBrowsableState.Never)>]
    override x.Equals(other) = base.Equals(other)
    [<EditorBrowsable(EditorBrowsableState.Never)>]
    override x.GetHashCode() = base.GetHashCode()
//    [<EditorBrowsable(EditorBrowsableState.Never)>]
//    override x.GetType() = base.GetType() //GetType cannot be overridden
    [<EditorBrowsable(EditorBrowsableState.Never)>]
    override x.ToString() = base.ToString()
    [<EditorBrowsable(EditorBrowsableState.Never)>]
    abstract Build : unit -> Property
    member x.QuickCheck() = quickCheck <| x.Build()
    member x.VerboseCheck() = verboseCheck <| x.Build()
    member x.QuickCheck(name:string) = quickCheckN name <| x.Build()
    member x.VerboseCheck(name:string) = verboseCheckN name <| x.Build()
    member x.Check(configuration:Configuration) = check (configuration.ToConfig()) <| x.Build()

and SpecBuilder<'a>( generator0:'a Gen
                   , shrinker0: 'a -> 'a seq
                   , assertion0:'a -> Property
                   , conditions:('a -> bool) list
                   , collects:('a -> string) list<commit_msg>Updated fluent interface to take replay into account.<commit_after>﻿#light

namespace FsCheck

//module public Fluent //don't add a module - otherwise every class needs to be qualified

open System
open System.Linq
open System.ComponentModel
open System.Collections.Generic
open Common

//TODO:
//Within -> rely on testing frameworks?
//Throws -> rely on testing frameworks?
//"And" and "Or" should start a new property, with own classifies and labels etc (see prop_Label)
//label: maybe add some overloads, should be able to nest (see propMul)
//registering default generators per type

type WeightAndValue<'a>(weight:int,value:'a) =
    member x.Weight = weight
    member x.Value = value
    
type Any = 
    static member private OneOfSeqGen gs = 
        gs |> Seq.to_list |> oneof
    static member private OneOfSeqValue vs = 
        vs |> Seq.to_list |> elements
    static member private SequenceSeq<'a> gs = 
        gs |> Seq.to_list |> sequence |> fmapGen (fun list -> new List<'a>(list))
    static member OfType<'a>() = 
        arbitrary<'a>
    static member Value (value) = 
        constant value
    [<OverloadIDAttribute("0")>]
    static member ValueIn (values : seq<_>) = 
        values |> Any.OneOfSeqValue
    [<OverloadIDAttribute("1")>]
    static member ValueIn ([<ParamArrayAttribute>] values : array<_>) = 
        values |> Any.OneOfSeqValue
    static member IntBetween (l,h) = 
        choose (l,h)
    [<OverloadIDAttribute("0")>]
    static member WeighedValueIn ( weighedValues : seq<WeightAndValue<'a>> ) =
        weighedValues |> Any.OneOfWeighedSeqValue
    [<OverloadIDAttribute("1")>]
    static member WeighedValueIn ( [<ParamArrayAttribute>] weighedValues : array<WeightAndValue<'a>> ) =
        weighedValues |> Any.OneOfWeighedSeqValue
    static member private OneOfWeighedSeqValue ws = 
        ws |> Seq.map (fun wv -> (wv.Weight, constant wv.Value)) |> Seq.to_list |> frequency
    [<OverloadIDAttribute("0")>]
    static member GeneratorIn (generators : seq<Gen<_>>) = 
        generators |> Any.OneOfSeqGen
    [<OverloadIDAttribute("1")>]
    static member GeneratorIn ([<ParamArrayAttribute>]  generators : array<Gen<_>>) = 
        generators |> Any.OneOfSeqGen
    [<OverloadIDAttribute("0")>]
    static member WeighedGeneratorIn ( weighedValues : seq<WeightAndValue<Gen<'a>>> ) =
        weighedValues |> Any.OneOfWeighedSeq
    [<OverloadIDAttribute("1")>]
    static member WeighedGeneratorIn ( [<ParamArrayAttribute>] weighedValues : array<WeightAndValue<Gen<'a>>> ) =
        weighedValues |> Any.OneOfWeighedSeq
    static member private OneOfWeighedSeq ws = 
        ws |> Seq.map (fun wv -> (wv.Weight, wv.Value)) |> Seq.to_list |> frequency
    [<OverloadIDAttribute("0")>]
    static member SequenceOf<'a> (generators:seq<Gen<'a>>) = 
        generators |> Any.SequenceSeq
    [<OverloadIDAttribute("1")>]
    static member SequenceOf<'a> ([<ParamArrayAttribute>]generators:array<Gen<'a>>) = 
        generators |> Any.SequenceSeq
    static member OfSize (sizedGen : Func<int,Gen<_>>) =
        sized <| fun s -> (sizedGen.Invoke(s))


type Shrink =
    static member Type<'a>() = shrink<'a>

//mutable counterpart of the Config type
type Configuration() =
    let mutable maxTest = Runner.quick.MaxTest
    let mutable maxFail = Runner.quick.MaxFail
    let mutable name = Runner.quick.Name
    let mutable every = Runner.quick.Every
    let mutable everyShrink = Runner.quick.EveryShrink
    let mutable size = Runner.quick.Size
    let mutable runner = Runner.quick.Runner
    let mutable replay = Runner.quick.Replay
    member x.MaxNbOfTest with get() = maxTest and set(v) = maxTest <- v
    member x.MaxNbOfFailedTests with get() = maxFail and set(v) = maxFail <- v
    member x.Name with get() = name and set(v) = name <- v
    member x.Every with get() = every and set(v:Func<int,obj array,string>) = every <- fun i os -> v.Invoke(i,List.to_array os)
    member x.EveryShrink with get() = everyShrink and set(v:Func<obj array,string>) = everyShrink <- fun os -> v.Invoke(List.to_array os)
    member x.Size with get() = size and set(v:Func<double,double>) = size <- v.Invoke
    member x.Runner with get() = runner and set(v) = runner <- v
    //TODO: figure out how to deal with null values
    //member x.Replay with get() = (match replay with None -> null | Some s -> s) and set(v) = replay = Some v
    member internal x.ToConfig() =
        { MaxTest = maxTest
        ; MaxFail = maxFail 
        ; Name = name
        ; Every = every
        ; EveryShrink = everyShrink
        ; Size= size
        ; Runner = runner
        ; Replay = None
        }

[<AbstractClass>]
type UnbrowsableObject() =
    inherit obj()
    [<EditorBrowsable(EditorBrowsableState.Never)>]
    override x.Equals(other) = base.Equals(other)
    [<EditorBrowsable(EditorBrowsableState.Never)>]
    override x.GetHashCode() = base.GetHashCode()
//    [<EditorBrowsable(EditorBrowsableState.Never)>]
//    override x.GetType() = base.GetType() //GetType cannot be overridden
    [<EditorBrowsable(EditorBrowsableState.Never)>]
    override x.ToString() = base.ToString()
    [<EditorBrowsable(EditorBrowsableState.Never)>]
    abstract Build : unit -> Property
    member x.QuickCheck() = quickCheck <| x.Build()
    member x.VerboseCheck() = verboseCheck <| x.Build()
    member x.QuickCheck(name:string) = quickCheckN name <| x.Build()
    member x.VerboseCheck(name:string) = verboseCheckN name <| x.Build()
    member x.Check(configuration:Configuration) = check (configuration.ToConfig()) <| x.Build()

and SpecBuilder<'a>( generator0:'a Gen
                   , shrinker0: 'a -> 'a seq
                   , assertion0:'a -> Property
                   , conditions:('a -> bool) list
                   , collects:('a -> string) list
{'fraction_non_alphanumeric': 0.12548603746907033, 'fraction_numerical': 0.002297631671968894, 'mean_word_length': 3.2657369016208064, 'pattern_counts': {'":': 0, '<': 141, '<?xml version=': 0, '>': 189, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6913095', 'n_tokens_mistral': 3631, 'n_tokens_neox': 3514, 'n_words': 928}