-
Notifications
You must be signed in to change notification settings - Fork 30
/
GenTests.fs
99 lines (83 loc) · 2.94 KB
/
GenTests.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
module Hedgehog.Tests.GenTests
open System
open Hedgehog
open Hedgehog.Gen.Operators
open TestDsl
let genTests = testList "Gen tests" [
yield! testCases "dateTime creates DateTime instances"
[ 8; 16; 32; 64; 128; 256; 512 ] <| fun count->
let actual =
(Range.constant
DateTime.MinValue
DateTime.MaxValue)
|> Gen.dateTime
|> Gen.sample 0 count
actual
|> List.distinct
|> List.length
=! actual.Length
testCase "unicode doesn't return any surrogate" <| fun _ ->
let actual =
Gen.sample 100 100000 Gen.unicode
[] =! List.filter Char.IsSurrogate actual
yield! testCases "unicode doesn't return any noncharacter"
[ 65534; 65535 ] <| fun nonchar ->
let actual =
Gen.sample 100 100000 Gen.unicode
[] =! List.filter (fun ch -> ch = char nonchar) actual
testCase "dateTime randomly generates value between max and min ticks" <| fun _ ->
let seed0 = Seed.random ()
let (seed1, _) = Seed.split seed0
let range =
Range.constant
DateTime.MinValue.Ticks
DateTime.MaxValue.Ticks
let ticks =
Random.integral range
|> Random.run seed1 0
let actual =
Range.constant DateTime.MinValue DateTime.MaxValue
|> Gen.dateTime
|> Gen.toRandom
|> Random.run seed0 0
|> Tree.outcome
let expected =
DateTime ticks
expected =! actual
testCase "dateTime shrinks to correct mid-value" <| fun _ ->
let actual =
property {
let! actual =
(Range.constantFrom
(DateTime (2000, 1, 1))
DateTime.MinValue
DateTime.MaxValue)
|> Gen.dateTime
DateTime.Now =! actual
}
|> Property.report
|> Report.render
|> (fun x -> x.Split ([|Environment.NewLine|], StringSplitOptions.None))
|> Array.item 1
|> DateTime.Parse
DateTime (2000, 1, 1) =! actual
fableIgnore "int64 can create exponentially bounded integer" <| fun _ ->
Property.check (property {
let! _ = Gen.int64 (Range.exponentialBounded ())
return true
})
fableIgnore "uint64 can create exponentially bounded integer" <| fun _ ->
Property.check (property {
let! _ = Gen.uint64 (Range.exponentialBounded ())
return true
})
testCase "apply is chainable" <| fun _ ->
let _ : Gen<int> =
Gen.constant (+)
|> Gen.apply (Gen.constant 1)
|> Gen.apply (Gen.constant 1)
()
testCase "apply operator works as expected" <| fun _ ->
let _ : Gen<int> = (+) <!> (Gen.constant 1) <*> (Gen.constant 1)
()
]