Created
September 29, 2015 14:01
-
-
Save bjartwolf/f67dc5c3dce624c93a21 to your computer and use it in GitHub Desktop.
generators.fs
This file contains hidden or 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
module ProgramSpillerGenerators | |
open System | |
open FsCheck | |
type ProgramId = string | |
type ConstrainedDate = DateTime | |
type Tolker = None | Tolk | Syns | |
type ProgramSpillerGenerators = | |
static member DateTimeInRange() = | |
let genDate : Gen<ConstrainedDate> = gen { let! y = Gen.choose(2013,2037) | |
let! m = Gen.choose(1, 12) | |
let! d = Gen.choose(1, DateTime.DaysInMonth(y, m)) | |
let! h = Gen.choose(0,23) | |
let! min = Gen.choose(0,59) | |
let! sec = Gen.choose(0,59) | |
return DateTime(y, m, d, h, min, sec) } | |
let shrinkDate (d:ConstrainedDate) = | |
if d.Second <> 0 then | |
seq { yield DateTime(d.Year,d.Month,d.Day,d.Hour,d.Minute,0) } | |
elif d.Minute <> 0 then | |
seq { yield DateTime(d.Year,d.Month,d.Day,d.Hour,0,0) } | |
elif d.Hour <> 0 then | |
seq { yield DateTime(d.Year,d.Month,d.Day) } | |
else | |
Seq.empty | |
Arb.fromGenShrink (genDate,shrinkDate) | |
static member ProgramIdArb () = | |
let legalChars = ["A";"B";"C";"D";"E";"F";"G";"H";"I";"J";"K";"L";"M";"N";"O";"P";"Q";"R";"S";"T";"U";"V";"X";"Y";"Z"] //;"Æ";"Ø";"Å" + tolk etc | |
let convertToString = List.map (sprintf "%i") >> String.concat "" | |
let genId : Gen<ProgramId> = gen { let! a = Gen.elements legalChars |> Gen.listOfLength 4 | |
let! b = Gen.elements [1;2;3] |> Gen.listOfLength 8 | |
return (a |> String.Concat) + (b |> convertToString) } | |
let shrinkId (d:ProgramId) = | |
if (d = "ABCD12345678") then Seq.empty | |
else seq { yield "ABCD12345678" } | |
Arb.fromGenShrink (genId , shrinkId) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment