From a7b2072821e06e1b24f4af9c8974b2b83c321081 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Tue, 16 Jun 2015 20:12:49 +0200 Subject: [PATCH] Refactor property tests --- .../CollectionModulesConsistency.fs | 116 ++++++++---------- 1 file changed, 51 insertions(+), 65 deletions(-) diff --git a/src/fsharp/FSharp.Core.PropertyTests/CollectionModulesConsistency.fs b/src/fsharp/FSharp.Core.PropertyTests/CollectionModulesConsistency.fs index 0904a1a92c9..4b1ffb3622f 100644 --- a/src/fsharp/FSharp.Core.PropertyTests/CollectionModulesConsistency.fs +++ b/src/fsharp/FSharp.Core.PropertyTests/CollectionModulesConsistency.fs @@ -9,100 +9,86 @@ open NUnit.Framework open FsCheck let append<'a when 'a : equality> (xs : list<'a>) (xs2 : list<'a>) = - let s = xs |> Seq.append xs2 - let l = xs |> List.append xs2 - let a = xs |> Seq.toArray |> Array.append (Seq.toArray xs2) - s |> Seq.toArray = a && - l |> List.toArray = a + let s = xs |> Seq.append xs2 + let l = xs |> List.append xs2 + let a = xs |> Seq.toArray |> Array.append (Seq.toArray xs2) + Seq.toArray s = a && List.toArray l = a + +[] +let ``append is consistent`` () = + Check.QuickThrowOnFailure append + Check.QuickThrowOnFailure append + Check.QuickThrowOnFailure append let contains<'a when 'a : equality> (xs : 'a []) x = let s = xs |> Seq.contains x let l = xs |> List.ofArray |> List.contains x let a = xs |> Array.contains x - s = a && - l = a + s = a && l = a + +[] +let ``contains is consistent`` () = + Check.QuickThrowOnFailure contains + Check.QuickThrowOnFailure contains + Check.QuickThrowOnFailure contains let choose<'a when 'a : equality> (xs : 'a []) f = let s = xs |> Seq.choose f let l = xs |> List.ofArray |> List.choose f let a = xs |> Array.choose f - s |> Seq.toArray = a && - l |> List.toArray = a + Seq.toArray s = a && List.toArray l = a + +[] +let ``choose is consistent`` () = + Check.QuickThrowOnFailure contains + Check.QuickThrowOnFailure contains + Check.QuickThrowOnFailure contains let collect<'a> (xs : 'a []) f = let s = xs |> Seq.collect f let l = xs |> List.ofArray |> List.collect (fun x -> f x |> List.ofArray) let a = xs |> Array.collect f - s |> Seq.toArray = a && - l |> List.toArray = a + Seq.toArray s = a && List.toArray l = a + +[] +let ``collect is consistent`` () = + Check.QuickThrowOnFailure collect + Check.QuickThrowOnFailure collect + Check.QuickThrowOnFailure collect let compareWith<'a>(xs : 'a []) (xs2 : 'a []) f = let s = (xs, xs2) ||> Seq.compareWith f let l = (List.ofArray xs, List.ofArray xs2) ||> List.compareWith f let a = (xs, xs2) ||> Array.compareWith f - s = a && - l = a + s = a && l = a + +[] +let ``compareWith is consistent`` () = + Check.QuickThrowOnFailure compareWith + Check.QuickThrowOnFailure compareWith + Check.QuickThrowOnFailure compareWith let concat<'a when 'a : equality> (xs : 'a [][]) = let s = xs |> Seq.concat let l = xs |> List.ofArray |> List.map List.ofArray |> List.concat let a = xs |> Array.concat - s |> Seq.toArray = a && - l |> List.toArray = a + Seq.toArray s = a && List.toArray l = a + +[] +let ``concat is consistent`` () = + Check.QuickThrowOnFailure concat + Check.QuickThrowOnFailure concat + Check.QuickThrowOnFailure concat let countBy<'a> (xs : 'a []) f = let s = xs |> Seq.countBy f let l = xs |> List.ofArray |> List.countBy f let a = xs |> Array.countBy f - s |> Seq.toArray = a && - l |> List.toArray = a - -type Properties = - - static member appendInt xs xs2 = append xs xs2 - static member appendFloat xs xs2 = append xs xs2 - static member appendString xs xs2 = append xs xs2 - - static member average (xs : NonEmptyArray) = - let xs = xs.Get |> Array.map (fun x -> x.Get) - let s = xs |> Seq.average - let l = xs |> List.ofArray |> List.average - let a = xs |> Array.average - s = a && - l = a - - static member averageBy (xs : NonEmptyArray) = - let xs = xs.Get |> Array.map (fun x -> x.Get) - let s = xs |> Seq.averageBy id - let l = xs |> List.ofArray |> List.averageBy id - let a = xs |> Array.averageBy id - s = a && - l = a - - static member containsInt xs x = contains xs x - static member containsString xs x = contains xs x - static member containsFloat xs x = contains xs x - - static member chooseInt xs f = choose xs f - static member chooseString xs f = choose xs f - static member chooseFloat xs f = choose xs f - - static member collectInt xs f = collect xs f - static member collectString xs f = collect xs f - static member collectFloat xs f = collect xs f - - static member compareWithInt xs f = compareWith xs f - static member compareWithString xs f = compareWith xs f - static member compareWithFloat xs f = compareWith xs f - - static member concatInt xs = concat xs - static member concatString xs = concat xs - static member concatFloat xs = concat xs - - static member countByInt xs f = countBy xs f - static member countByString xs f = countBy xs f - static member countByFloat xs f = countBy xs f + Seq.toArray s = a && List.toArray l = a [] -let ``modules consistency`` () = - Check.QuickThrowOnFailureAll() \ No newline at end of file +let ``countBy is consistent`` () = + Check.QuickThrowOnFailure countBy + Check.QuickThrowOnFailure countBy + Check.QuickThrowOnFailure countBy + \ No newline at end of file