Skip to content

Commit

Permalink
Fixes #103, fixes #104, fixes #105
Browse files Browse the repository at this point in the history
  • Loading branch information
haf committed Feb 19, 2017
1 parent d66df67 commit 7cbad4a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .semver
@@ -1,6 +1,6 @@
---
:major: 4
:minor: 0
:patch: 2
:patch: 3
:special: ''
:metadata: ''
8 changes: 8 additions & 0 deletions Expecto.Sample/Expecto.Sample.fs
Expand Up @@ -20,6 +20,7 @@ module Utils =
open Utils
open Expecto


[<Tests>]
let tests =
testList "samples" [
Expand Down Expand Up @@ -81,6 +82,13 @@ let tests =
let actual, expected = 41.562, 41.563
Expect.floatClose Accuracy.medium actual expected "Should be close within 5 sig figs (approx)"
}

testProperty "addition is commutative" <| fun a b ->
a + b = b + a

testPropertyWithConfig FsCheckConfig.defaultConfig "Product is distributive over addition" <|
fun a b c ->
a * (b + c) = a * b + a * c
]

[<EntryPoint>]
Expand Down
5 changes: 3 additions & 2 deletions Expecto/Expecto.fs
Expand Up @@ -1349,7 +1349,8 @@ module Tests =
/// The default configuration for Expecto.
let defaultConfig = ExpectoConfig.defaultConfig

// TODO: docs
/// The CLI arguments are the parameters that are possible to send to Expecto
/// and change the runner's behaviour.
type CLIArguments =
| Sequenced
| Parallel
Expand Down Expand Up @@ -1442,7 +1443,7 @@ module Tests =
| Stress_Timeout n -> fun o -> { o with stressTimeout = TimeSpan.FromMinutes n }
| Stress_Memory_Limit n -> fun o -> { o with stressMemoryLimit = n }
| Fail_On_Focused_Tests -> fun o -> { o with failOnFocusedTests = true }
| Debug -> fun o -> { o with verbosity = LogLevel.Info }
| Debug -> fun o -> { o with verbosity = LogLevel.Debug }
| Filter hiera -> fun o -> {o with filter = Test.filter (fun s -> s.StartsWith hiera )}
| Filter_Test_List name -> fun o -> {o with filter = Test.filter (fun s -> s |> getTestList |> Array.exists(fun s -> s.Contains name )) }
| Filter_Test_Case name -> fun o -> {o with filter = Test.filter (fun s -> s |> getTastCase |> fun s -> s.Contains name )}
Expand Down
26 changes: 22 additions & 4 deletions README.md
Expand Up @@ -406,11 +406,17 @@ testList "numberology 101" (
### Property based tests

Reference [FsCheck](https://github.com/fscheck/FsCheck) and Expecto.FsCheck to
test properties:
test properties.

```fsharp
let config = { FsCheck.Config.Default with MaxTest = 100 }
let stressConfig = { FsCheck.Config.Default with MaxTest = 10000 }
module MyApp.Tests
// the ExpectoFsCheck module is auto-opened by this
// the configuration record is in the Expecto namespace in the core library
open Expecto
let config = { FsCheckConfig.defaultConfig with maxTest = 100 }
let stressConfig = { FsCheckConfig.defaultConfig with maxTest = 10000 }
let properties =
testList "FsCheck" [
Expand All @@ -435,7 +441,19 @@ let properties =
run properties
```

You can freely mix testProperty with testCase and testList.
You can freely mix testProperty with testCase and testList. The config looks
like the following.

```fsharp
type FsCheckConfig =
{ maxTest: int
startSize: int
endSize: int
replay: (int*int) option
arbitrary: Type list }
```

It will be translated to the FsCheck-specific configuration at runtime.

#### Link collection

Expand Down

0 comments on commit 7cbad4a

Please sign in to comment.