Skip to content

Instantly share code, notes, and snippets.

@pocketberserker
Forked from yukitos/gist:4db499ede35c8ad82863
Last active August 29, 2015 14:05
Show Gist options
  • Save pocketberserker/d30f6ef797e44901522a to your computer and use it in GitHub Desktop.
Save pocketberserker/d30f6ef797e44901522a to your computer and use it in GitHub Desktop.
namespace FsCheck.Ext
module Test =
open System
open FsCheck
open FsCheck.Arb
type JapaneseChar = char
type MyGenerators =
static member JapaneseChar() =
// The following characters range definitions are based on:
// http://www.rikai.com/library/kanjitables/kanji_codes.unicode.shtml
{ new Arbitrary<JapaneseChar>() with
override x.Generator = Gen.oneof [
Gen.choose(0x3000, 0x303f) |> Gen.map (Char.ConvertFromUtf32 >> char)
Gen.choose(0x3040, 0x309f) |> Gen.map (Char.ConvertFromUtf32 >> char)
Gen.choose(0x30a0, 0x30ff) |> Gen.map (Char.ConvertFromUtf32 >> char)
Gen.choose(0xff00, 0xffef) |> Gen.map (Char.ConvertFromUtf32 >> char)
Gen.choose(0x4e00, 0x9faf) |> Gen.map (Char.ConvertFromUtf32 >> char)
Gen.choose(0x3400, 0x4dbf) |> Gen.map (Char.ConvertFromUtf32 >> char)
]
override x.Shrinker c =
// TODO: need more appropriate implementation
seq { for c' in ['a';'b';'c'] do if c' < c || not (Char.IsLower c) then yield c' }
}
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.All<Target>({ Config.Default with Arbitrary = [typeof<MyGenerators>] })
--- 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