Skip to content

Commit 4c0c1be

Browse files
author
Henrik Kirk
committed
Updated with correct code example
1 parent 7a67c70 commit 4c0c1be

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

slides/05/property-based-testing.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,17 @@ So the properties of FizzBuzz is:
171171
### Custom types
172172

173173
```fsharp
174-
type MultipleOfOnly3 =
175-
[<Property>]
174+
type MultiplyOfOnly3 = MultiplyOfOnly3 of int with
175+
static member op_Explicit(MultiplyOfOnly3 i) = i
176+
177+
type MultiplyOfOnly3Modifier =
178+
static member MultiplyOfOnly3() =
179+
ArbMap.defaults
180+
|> ArbMap.generate<int32>
181+
|> Gen.filter (fun i -> i > 0 && i % 3 = 0 && not (i % 5 = 0))
182+
|> Arb.fromGen
183+
184+
[<Property(Arbitrary = [| typeof<MultiplyOfOnly3Modifier> |])>]
176185
let ```test multiply of three``` (x: MultiplyOfOnly3) =
177186
test <@ FizzBuzz.fizzBuzz x = "Fizz" @>
178187
```
@@ -184,12 +193,14 @@ let ```test multiply of three``` (x: MultiplyOfOnly3) =
184193

185194
```fsharp
186195
[<Property>]
187-
let ``Only divisible by three`` () =
188-
Arb.generate<int32>
189-
|> Gen.filter (fun i -> i % 3 = 0 && not (i % 5 = 0))
190-
|> Arb.fromGen
191-
|> Prop.forAll <| fun i ->
192-
FizzBuzz.fizzBuzz i = "Fizz"
196+
let ``test multiply of three`` () =
197+
let gen = ArbMap.defaults
198+
|> ArbMap.generate<int32>
199+
|> Gen.filter (fun i -> i % 3 = 0 && not (i % 5 = 0))
200+
|> Arb.fromGen
201+
Prop.forAll gen (fun x ->
202+
test <@ FizzBuzz.fizzBuzz x = "Fizz" @>
203+
)
193204
```
194205

195206
---

0 commit comments

Comments
 (0)