-
-
Save Gab-km/afc2db9d6503004f6ed1 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 | |
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>() |
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