Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Operators comparison across frameworks
| `should` | ✔ | ✔ | ✔ |
| `equal` | ✔ | ✔ | ✔ |
| `equalSeq` | ✔ | ✔ | ✔ |
| `equivalent` | ✔ | | ✔ |
| `equivalent` | ✔ | | ✔ |
| `equalWithin` | ✔ | ✔ | ✔ |
| `contain` | ✔ | ✔ | ✔ |
| `haveLength` | ✔ | ✔ | ✔ |
Expand Down
3 changes: 3 additions & 0 deletions src/FsUnit.Xunit/FsUnit.fs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ let equalSeq expected =
let equal expected =
CustomMatchers.equal expected

let equivalent expected =
CustomMatchers.equivalent (fun e a -> Assert.Equivalent(e, a, true)) expected

let equalWithin (tolerance: obj) (expected: obj) =
CustomMatchers.equalWithin tolerance expected

Expand Down
4 changes: 4 additions & 0 deletions src/FsUnit.Xunit/FsUnitTyped.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ module TopLevelOperators =
let shouldEqual<'a> (expected: 'a) (actual: 'a) =
actual |> should equal expected

[<DebuggerStepThrough>]
let shouldEquivalent<'a when 'a: equality> (expected: 'a seq) (actual: 'a seq) =
actual |> should equivalent expected

[<DebuggerStepThrough>]
let shouldNotEqual<'a> (expected: 'a) (actual: 'a) =
actual |> should not' (equal expected)
Expand Down
1 change: 1 addition & 0 deletions tests/FsUnit.Xunit.Test/FsUnit.Xunit.Test.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<Compile Include="typed.shouldContainTextTests.fs" />
<Compile Include="typed.shouldFailTests.fs" />
<Compile Include="typed.shouldEqualTests.fs" />
<Compile Include="equivalentTests.fs" />
<None Include="paket.references" />
</ItemGroup>
<ItemGroup>
Expand Down
40 changes: 40 additions & 0 deletions tests/FsUnit.Xunit.Test/equivalentTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace FsUnit.Test

open System
open Xunit
open FsUnit.Xunit

module EquivalentTests =

[<Fact>]
let ``two lists with same elements in different order are equivalent``() =
[ 1; 2; 3 ] |> should equivalent [ 3; 2; 1 ]

[<Fact>]
let ``two lists with different elements are not equivalent``() =
[ 1; 2; 3 ] |> should not' (equivalent [ 4; 5; 6 ])

[<Fact>]
let ``two lists with different lengths are not equivalent``() =
[ 1; 2; 3 ] |> should not' (equivalent [ 1; 2 ])

[<Fact>]
let ``two arrays with same elements in different order are equivalent``() =
[| 1; 2; 3 |] |> should equivalent [| 3; 2; 1 |]

[<Fact>]
let ``two arrays with different elements are not equivalent``() =
[| 1; 2; 3 |] |> should not' (equivalent [| 4; 5; 6 |])

[<Fact>]
let ``empty collections are equivalent``() =
[] |> should equivalent []
[||] |> should equivalent [||]

[<Fact>]
let ``collections with same elements and duplicates are not equivalent if counts differ``() =
[ 1; 1; 2 ] |> should not' (equivalent [ 1; 2; 2 ])

[<Fact>]
let ``collections with same elements and same counts are equivalent``() =
[ 1; 1; 2 ] |> should equivalent [ 2; 1; 1 ]