File tree Expand file tree Collapse file tree 5 files changed +49
-1
lines changed
Expand file tree Collapse file tree 5 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ Operators comparison across frameworks
1414| ` should ` | ✔ | ✔ | ✔ |
1515| ` equal ` | ✔ | ✔ | ✔ |
1616| ` equalSeq ` | ✔ | ✔ | ✔ |
17- | ` equivalent ` | ✔ | ❌ | ✔ |
17+ | ` equivalent ` | ✔ | ✔ | ✔ |
1818| ` equalWithin ` | ✔ | ✔ | ✔ |
1919| ` contain ` | ✔ | ✔ | ✔ |
2020| ` haveLength ` | ✔ | ✔ | ✔ |
Original file line number Diff line number Diff line change @@ -57,6 +57,9 @@ let equalSeq expected =
5757let equal expected =
5858 CustomMatchers.equal expected
5959
60+ let equivalent expected =
61+ CustomMatchers.equivalent ( fun e a -> Assert.Equivalent( e, a, true )) expected
62+
6063let equalWithin ( tolerance : obj ) ( expected : obj ) =
6164 CustomMatchers.equalWithin tolerance expected
6265
Original file line number Diff line number Diff line change @@ -11,6 +11,10 @@ module TopLevelOperators =
1111 let shouldEqual < 'a > ( expected : 'a ) ( actual : 'a ) =
1212 actual |> should equal expected
1313
14+ [<DebuggerStepThrough>]
15+ let shouldEquivalent < 'a when 'a : equality > ( expected : 'a seq ) ( actual : 'a seq ) =
16+ actual |> should equivalent expected
17+
1418 [<DebuggerStepThrough>]
1519 let shouldNotEqual < 'a > ( expected : 'a ) ( actual : 'a ) =
1620 actual |> should not' ( equal expected)
Original file line number Diff line number Diff line change 4545 <Compile Include =" typed.shouldContainTextTests.fs" />
4646 <Compile Include =" typed.shouldFailTests.fs" />
4747 <Compile Include =" typed.shouldEqualTests.fs" />
48+ <Compile Include =" equivalentTests.fs" />
4849 <None Include =" paket.references" />
4950 </ItemGroup >
5051 <ItemGroup >
Original file line number Diff line number Diff line change 1+ namespace FsUnit.Test
2+
3+ open System
4+ open Xunit
5+ open FsUnit.Xunit
6+
7+ module EquivalentTests =
8+
9+ [<Fact>]
10+ let ``two lists with same elements in different order are equivalent`` () =
11+ [ 1 ; 2 ; 3 ] |> should equivalent [ 3 ; 2 ; 1 ]
12+
13+ [<Fact>]
14+ let ``two lists with different elements are not equivalent`` () =
15+ [ 1 ; 2 ; 3 ] |> should not' ( equivalent [ 4 ; 5 ; 6 ])
16+
17+ [<Fact>]
18+ let ``two lists with different lengths are not equivalent`` () =
19+ [ 1 ; 2 ; 3 ] |> should not' ( equivalent [ 1 ; 2 ])
20+
21+ [<Fact>]
22+ let ``two arrays with same elements in different order are equivalent`` () =
23+ [| 1 ; 2 ; 3 |] |> should equivalent [| 3 ; 2 ; 1 |]
24+
25+ [<Fact>]
26+ let ``two arrays with different elements are not equivalent`` () =
27+ [| 1 ; 2 ; 3 |] |> should not' ( equivalent [| 4 ; 5 ; 6 |])
28+
29+ [<Fact>]
30+ let ``empty collections are equivalent`` () =
31+ [] |> should equivalent []
32+ [||] |> should equivalent [||]
33+
34+ [<Fact>]
35+ let ``collections with same elements and duplicates are not equivalent if counts differ`` () =
36+ [ 1 ; 1 ; 2 ] |> should not' ( equivalent [ 1 ; 2 ; 2 ])
37+
38+ [<Fact>]
39+ let ``collections with same elements and same counts are equivalent`` () =
40+ [ 1 ; 1 ; 2 ] |> should equivalent [ 2 ; 1 ; 1 ]
You can’t perform that action at this time.
0 commit comments