-
-
Save pocketberserker/d30f6ef797e44901522a to your computer and use it in GitHub Desktop.
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
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>] }) |
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
--- 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