Skip to content

Commit

Permalink
Merge pull request #70 from sergey-tihon/master
Browse files Browse the repository at this point in the history
Added support of `unique` operator for xUnit, MsTest and MbUnit
  • Loading branch information
sergey-tihon committed Aug 2, 2015
2 parents 4068aa2 + f1e865e commit 5f0f292
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 2 deletions.
3 changes: 2 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
* Added support of `instanceOfType` operator for xUnit, MsTest and MbUnit - https://github.com/fsprojects/FsUnit/pull/65
* Added support of `Empty` operator for xUnit, MsTest and MbUnit - https://github.com/fsprojects/FsUnit/pull/66
* Added support of `NaN` operator for xUnit, MsTest and MbUnit - https://github.com/fsprojects/FsUnit/pull/67
* Added support of `haveLength` and `haveCount` operators for xUnit, MsTest and MbUnit -
* Added support of `haveLength` and `haveCount` operators for xUnit, MsTest and MbUnit - https://github.com/fsprojects/FsUnit/pull/68
* Added support of `unique` operator for xUnit, MsTest and MbUnit -

### 1.3.1.0 - 26 July 2015
* Bump NUnit version up to 2.6.4
Expand Down
2 changes: 1 addition & 1 deletion docs/content/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Operators comparison across frameworks
| `True` | + | + | + | + |
| `False` | + | + | + | + |
| `NaN` | + | + | + | + |
| `unique` | + | | | |
| `unique` | + | + | + | + |
| `should` | + | + | + | + |
| `equal` | + | + | + | + |
| `equalWithin` | + | + | + | + |
Expand Down
2 changes: 2 additions & 0 deletions src/FsUnit.MbUnit/FsUnit.fs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ let False = CustomMatchers.False

let NaN = CustomMatchers.NaN

let unique = CustomMatchers.unique

let sameAs expected = CustomMatchers.sameAs expected

let greaterThan (expected:obj) = CustomMatchers.greaterThan expected
Expand Down
2 changes: 2 additions & 0 deletions src/FsUnit.MsTestUnit/FsUnit.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ let False = CustomMatchers.False

let NaN = CustomMatchers.NaN

let unique = CustomMatchers.unique

let sameAs expected = CustomMatchers.sameAs expected

let greaterThan (expected:obj) = CustomMatchers.greaterThan expected
Expand Down
11 changes: 11 additions & 0 deletions src/FsUnit.Xunit/CustomMatchers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ let NaN = CustomMatcher<obj>("NaN", fun x ->
| :? double as d -> System.Double.IsNaN(d)
| _ -> false)

let unique = CustomMatcher<obj>("All items unique", fun (x:obj) ->
let isAllItemsUnique x =
let y = Seq.distinct x
Seq.length x = Seq.length y
match x with
| :? list<_> as l -> l |> isAllItemsUnique
| :? array<_> as a -> a |> isAllItemsUnique
| :? seq<_> as s -> s |> isAllItemsUnique
| :? System.Collections.IEnumerable as e -> e |> Seq.cast |> isAllItemsUnique
| _ -> false)

let sameAs x = Is.SameAs<obj>(x)

let greaterThan (x:obj) = CustomMatcher<obj>(string x,
Expand Down
2 changes: 2 additions & 0 deletions src/FsUnit.Xunit/FsUnit.fs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ let False = CustomMatchers.False

let NaN = CustomMatchers.NaN

let unique = CustomMatchers.unique

let sameAs expected = CustomMatchers.sameAs expected

let greaterThan (expected:obj) = CustomMatchers.greaterThan expected
Expand Down
1 change: 1 addition & 0 deletions tests/FsUnit.MbUnit.Test/FsUnit.MbUnit.Test.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<Compile Include="equalWithinTests.fs" />
<Compile Include="instanceOfTests.fs" />
<Compile Include="NaNTests.fs" />
<Compile Include="beUniqueTests.fs" />
<None Include="paket.references" />
</ItemGroup>
<ItemGroup>
Expand Down
54 changes: 54 additions & 0 deletions tests/FsUnit.MbUnit.Test/beUniqueTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
namespace FsUnit.Test
open MbUnit.Framework
open FsUnit.MbUnit
open System

[<TestFixture>]
type ``have unique items list tests`` ()=
[<Test>] member test.
``empty list should be considered as unique`` ()=
[] |> should be unique

[<Test>] member test.
``empty list should fail to be considered as not unique`` ()=
shouldFail(fun () -> [] |> should not' (be unique))

[<Test>] member test.
``one-item list should be considered as unique`` ()=
[1] |> should be unique

[<Test>] member test.
``one-item list should not fail to be considered as unique`` ()=
shouldFail(fun () -> [1] |> should not' (be unique))

[<Test>] member test.
``unique list should be considered as unique`` ()=
[1;2;3] |> should be unique

[<Test>] member test.
``unique list should fail to be considered unique`` ()=
shouldFail(fun () -> [1;2;3] |> should not' (be unique))

[<Test>] member test.
``non-unique list should not be considered unique`` ()=
[1;1;1] |> should not' (be unique)

[<Test>] member test.
``non-unique list should fail to be considered unique`` ()=
shouldFail(fun () -> [1;1;1] |> should be unique)

[<Test>] member test.
``non-unique sequence should not be considered unique`` ()=
[1;1] |> List.toSeq |> should not' (be unique)

[<Test>] member test.
``unique sequence should be considered unique`` ()=
[1;2] |> List.toSeq |> should be unique

[<Test>] member test.
``non-unique array should not be considered as unique`` ()=
[|1;1|] |> should not' (be unique)

[<Test>] member test.
``unique array should be considered unique`` ()=
[|1;2|] |> should be unique
1 change: 1 addition & 0 deletions tests/FsUnit.MsTest.Test/Fs30Unit.MsTest.Test.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<Compile Include="shouldHaveSubstringTests.fs" />
<Compile Include="instanceOfTests.fs" />
<Compile Include="NaNTests.fs" />
<Compile Include="beUniqueTests.fs" />
<None Include="App.config" />
<None Include="paket.references" />
<None Include="MSTest.runsettings" />
Expand Down
54 changes: 54 additions & 0 deletions tests/FsUnit.MsTest.Test/beUniqueTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
namespace FsUnit.Test
open Microsoft.VisualStudio.TestTools.UnitTesting
open FsUnit.MsTest
open NHamcrest.Core

[<TestClass>]
type ``have unique items list tests`` ()=
[<TestMethod>] member test.
``empty list should be considered as unique`` ()=
[] |> should be unique

[<TestMethod>] member test.
``empty list should fail to be considered as not unique`` ()=
shouldFail(fun () -> [] |> should not' (be unique))

[<TestMethod>] member test.
``one-item list should be considered as unique`` ()=
[1] |> should be unique

[<TestMethod>] member test.
``one-item list should not fail to be considered as unique`` ()=
shouldFail(fun () -> [1] |> should not' (be unique))

[<TestMethod>] member test.
``unique list should be considered as unique`` ()=
[1;2;3] |> should be unique

[<TestMethod>] member test.
``unique list should fail to be considered unique`` ()=
shouldFail(fun () -> [1;2;3] |> should not' (be unique))

[<TestMethod>] member test.
``non-unique list should not be considered unique`` ()=
[1;1;1] |> should not' (be unique)

[<TestMethod>] member test.
``non-unique list should fail to be considered unique`` ()=
shouldFail(fun () -> [1;1;1] |> should be unique)

[<TestMethod>] member test.
``non-unique sequence should not be considered unique`` ()=
[1;1] |> List.toSeq |> should not' (be unique)

[<TestMethod>] member test.
``unique sequence should be considered unique`` ()=
[1;2] |> List.toSeq |> should be unique

[<TestMethod>] member test.
``non-unique array should not be considered as unique`` ()=
[|1;1|] |> should not' (be unique)

[<TestMethod>] member test.
``unique array should be considered unique`` ()=
[|1;2|] |> should be unique
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 @@ -80,6 +80,7 @@
<Compile Include="equalWithinTests.fs" />
<Compile Include="instanceOfTests.fs" />
<Compile Include="NaNTests.fs" />
<Compile Include="beUniqueTests.fs" />
<None Include="paket.references" />
</ItemGroup>
<ItemGroup>
Expand Down
52 changes: 52 additions & 0 deletions tests/FsUnit.Xunit.Test/beUniqueTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace FsUnit.Test
open Xunit
open FsUnit.Xunit

type ``have unique items list tests`` ()=
[<Fact>] member test.
``empty list should be considered as unique`` ()=
[] |> should be unique

[<Fact>] member test.
``empty list should fail to be considered as not unique`` ()=
shouldFail(fun () -> [] |> should not' (be unique))

[<Fact>] member test.
``one-item list should be considered as unique`` ()=
[1] |> should be unique

[<Fact>] member test.
``one-item list should not fail to be considered as unique`` ()=
shouldFail(fun () -> [1] |> should not' (be unique))

[<Fact>] member test.
``unique list should be considered as unique`` ()=
[1;2;3] |> should be unique

[<Fact>] member test.
``unique list should fail to be considered unique`` ()=
shouldFail(fun () -> [1;2;3] |> should not' (be unique))

[<Fact>] member test.
``non-unique list should not be considered unique`` ()=
[1;1;1] |> should not' (be unique)

[<Fact>] member test.
``non-unique list should fail to be considered unique`` ()=
shouldFail(fun () -> [1;1;1] |> should be unique)

[<Fact>] member test.
``non-unique sequence should not be considered unique`` ()=
[1;1] |> List.toSeq |> should not' (be unique)

[<Fact>] member test.
``unique sequence should be considered unique`` ()=
[1;2] |> List.toSeq |> should be unique

[<Fact>] member test.
``non-unique array should not be considered as unique`` ()=
[|1;1|] |> should not' (be unique)

[<Fact>] member test.
``unique array should be considered unique`` ()=
[|1;2|] |> should be unique

0 comments on commit 5f0f292

Please sign in to comment.