3 people like it.

A quick NodaTime.Instant generator for FsCheck

A quick NodaTime.Instant generator for FsCheck

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
open NodaTime
open FsCheck

type NodaGen =
    static member Instant () =
        Arb.generate<System.DateTime>
        |> Gen.map (fun dt -> dt.ToUniversalTime())
        |> Gen.map (fun dt -> Instant.FromDateTimeUtc dt)
        |> Arb.fromGen

// If using NUnit...
// [<SetUp>]
let setup () =
    do Arb.register<NodaGen>() |> ignore        
     
namespace NodaTime
namespace FsCheck
type NodaGen =
  static member Instant : unit -> 'a

Full name: Script.NodaGen
Multiple items
static member NodaGen.Instant : unit -> 'a

Full name: Script.NodaGen.Instant

--------------------
type Instant =
  struct
    new : ticks:int64 -> Instant
    member CompareTo : other:Instant -> int
    member Equals : obj:obj -> bool + 1 overload
    member GetHashCode : unit -> int
    member InUtc : unit -> ZonedDateTime
    member InZone : zone:DateTimeZone -> ZonedDateTime + 1 overload
    member Minus : other:Instant -> Duration + 1 overload
    member Plus : duration:Duration -> Instant
    member PlusTicks : ticksToAdd:int64 -> Instant
    member Ticks : int64
    ...
  end

Full name: NodaTime.Instant

--------------------
Instant()
Instant(ticks: int64) : unit
namespace System
Multiple items
type DateTime =
  struct
    new : ticks:int64 -> DateTime + 10 overloads
    member Add : value:TimeSpan -> DateTime
    member AddDays : value:float -> DateTime
    member AddHours : value:float -> DateTime
    member AddMilliseconds : value:float -> DateTime
    member AddMinutes : value:float -> DateTime
    member AddMonths : months:int -> DateTime
    member AddSeconds : value:float -> DateTime
    member AddTicks : value:int64 -> DateTime
    member AddYears : value:int -> DateTime
    ...
  end

Full name: System.DateTime

--------------------
System.DateTime()
   (+0 other overloads)
System.DateTime(ticks: int64) : unit
   (+0 other overloads)
System.DateTime(ticks: int64, kind: System.DateTimeKind) : unit
   (+0 other overloads)
System.DateTime(year: int, month: int, day: int) : unit
   (+0 other overloads)
System.DateTime(year: int, month: int, day: int, calendar: System.Globalization.Calendar) : unit
   (+0 other overloads)
System.DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int) : unit
   (+0 other overloads)
System.DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, kind: System.DateTimeKind) : unit
   (+0 other overloads)
System.DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, calendar: System.Globalization.Calendar) : unit
   (+0 other overloads)
System.DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int) : unit
   (+0 other overloads)
System.DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int, kind: System.DateTimeKind) : unit
   (+0 other overloads)
Multiple items
type Instant =
  struct
    new : ticks:int64 -> Instant
    member CompareTo : other:Instant -> int
    member Equals : obj:obj -> bool + 1 overload
    member GetHashCode : unit -> int
    member InUtc : unit -> ZonedDateTime
    member InZone : zone:DateTimeZone -> ZonedDateTime + 1 overload
    member Minus : other:Instant -> Duration + 1 overload
    member Plus : duration:Duration -> Instant
    member PlusTicks : ticksToAdd:int64 -> Instant
    member Ticks : int64
    ...
  end

Full name: NodaTime.Instant

--------------------
Instant()
Instant(ticks: int64) : unit
Instant.FromDateTimeUtc(dateTime: System.DateTime) : Instant
val setup : unit -> unit

Full name: Script.setup
val ignore : value:'T -> unit

Full name: Microsoft.FSharp.Core.Operators.ignore
Raw view Test code New version

More information

Link:http://fssnip.net/nK
Posted:9 years ago
Author:mavnn
Tags: fscheck , nodatime