Last active
August 30, 2018 10:01
-
-
Save isaacabraham/882236bc83a35a02fdd9f7984ad0ccf8 to your computer and use it in GitHub Desktop.
Test if the behaviour of two functions are the same.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Some dummy data types | |
type Thing = Red | Yellow | Blue | |
type Foo = { Number : PositiveInt; Other : Thing } | |
/// First way | |
let groupByThenSortAndHead data = | |
data | |
|> Array.groupBy(fun x -> x.Other) | |
|> Array.map ( | |
snd | |
>> Seq.sortByDescending(fun x -> x.Number) | |
>> Seq.head) | |
/// Second way | |
let sortThenDistinct data = | |
data | |
|> Array.sortByDescending(fun x -> x.Number) | |
|> Array.distinctBy(fun x -> x.Other) | |
/// Create a "test" function which returns true or false if some property holds. | |
let bothMethodsAreTheSame data = | |
groupByThenSortAndHead data = sortThenDistinct data | |
/// FsCheck tests the compareThem function with random data | |
Check.Quick bothMethodsAreTheSame |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment