Skip to content

Instantly share code, notes, and snippets.

@Gab-km
Forked from yukitos/gist:4db499ede35c8ad82863
Last active August 29, 2015 14:05
Show Gist options
  • Save Gab-km/afc2db9d6503004f6ed1 to your computer and use it in GitHub Desktop.
Save Gab-km/afc2db9d6503004f6ed1 to your computer and use it in GitHub Desktop.
namespace FsCheck.Ext
module Test =
open System
open FsCheck
open FsCheck.Arb
type JapaneseChar = char
let japaneseChar (s: string) =
let jc: JapaneseChar = char s
jc
type MyGenerators =
static member JapaneseChar() =
{ new Arbitrary<JapaneseChar>() with
override x.Generator = Gen.oneof [
Gen.choose(0x3000, 0x303f) |> Gen.map (Char.ConvertFromUtf32 >> japaneseChar)
Gen.choose(0x3040, 0x309f) |> Gen.map (Char.ConvertFromUtf32 >> japaneseChar)
Gen.choose(0x30a0, 0x30ff) |> Gen.map (Char.ConvertFromUtf32 >> japaneseChar)
Gen.choose(0xff00, 0xffef) |> Gen.map (Char.ConvertFromUtf32 >> japaneseChar)
Gen.choose(0x4e00, 0x9faf) |> Gen.map (Char.ConvertFromUtf32 >> japaneseChar)
Gen.choose(0x3400, 0x4dbf) |> Gen.map (Char.ConvertFromUtf32 >> japaneseChar)
]
override x.Shrinker c =
seq { for c' in ['a';'b';'c'] do if c' < c || not (Char.IsLower c) then yield c' }
}
Arb.register<MyGenerators>() |> ignore
let sample n = Gen.sample 1000 n
type Target() =
static member JapaneseChar (value:JapaneseChar) =
(generate<JapaneseChar> |> sample 10 |> List.forall (fun _ -> true)
, shrink<JapaneseChar> value |> Seq.forall (fun shrunkv -> int shrunkv <= abs (int value)))
Check.QuickAll<Target>()
--- Checking Target ---
Target.JapaneseChar-Ok, passed 100 tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment