diff --git a/docs/content/index.fsx b/docs/content/index.fsx index 0df15d40..11444f3e 100644 --- a/docs/content/index.fsx +++ b/docs/content/index.fsx @@ -139,6 +139,9 @@ anObj |> should not' (be sameAs otherObj) [1..10] |> should be (supersetOf [3;6;9]) [1..10] |> should not' (be supersetOf [5;11;21]) +[3;6;9] |> should be (supersetOf [1..10]) +[5;11;21] |> should not' (be supersetOf [1..10]) + (** The ofCase operator allows you to check the case of a union. Supplying an expression that will result in a non-union type as well as supplying a non-union type as value argument will result in an exception detailing which parameter is wrong. Note that the actual value of the case is NOT checked, e.g. using `<@ MyCase 5 @>` as expression and `(MyCase 10)` as parameter will succeed. It is possible to check for more than one case by using a tuple of union cases. diff --git a/docs/content/operators.md b/docs/content/operators.md index 8bd989fa..4e024d71 100644 --- a/docs/content/operators.md +++ b/docs/content/operators.md @@ -39,3 +39,4 @@ Operators comparison across frameworks | `inRange` | + | + | + | | `ofCase` | + | + | + | | `supersetOf` | + | + | + | +| `subsetOf` | + | + | + | \ No newline at end of file diff --git a/src/FsUnit.MsTestUnit/FsUnit.fs b/src/FsUnit.MsTestUnit/FsUnit.fs index 551c9bf8..d48bbc7c 100644 --- a/src/FsUnit.MsTestUnit/FsUnit.fs +++ b/src/FsUnit.MsTestUnit/FsUnit.fs @@ -112,4 +112,6 @@ let inRange min max = CustomMatchers.inRange min max let ofCase case = CustomMatchers.ofCase case -let supersetOf expected = CustomMatchers.supersetOf expected \ No newline at end of file +let supersetOf expected = CustomMatchers.supersetOf expected + +let subsetOf expected = CustomMatchers.subsetOf expected \ No newline at end of file diff --git a/src/FsUnit.NUnit/FsUnit.fs b/src/FsUnit.NUnit/FsUnit.fs index 8180f75e..9f911bed 100644 --- a/src/FsUnit.NUnit/FsUnit.fs +++ b/src/FsUnit.NUnit/FsUnit.fs @@ -95,4 +95,6 @@ module TopLevelOperators = let ofCase case = OfSameCaseConstraint(case) - let supersetOf x = CollectionSupersetConstraint(x) \ No newline at end of file + let supersetOf x = CollectionSupersetConstraint(x) + + let subsetOf x = CollectionSubsetConstraint(x) \ No newline at end of file diff --git a/src/FsUnit.Xunit/CustomMatchers.fs b/src/FsUnit.Xunit/CustomMatchers.fs index dfa095b7..5547446e 100644 --- a/src/FsUnit.Xunit/CustomMatchers.fs +++ b/src/FsUnit.Xunit/CustomMatchers.fs @@ -135,6 +135,9 @@ let containf f = CustomMatcher(sprintf "Contains %s" (f.ToString()), let supersetOf x = CustomMatcher(sprintf "Is superset of %A" x, fun c -> Set.isSuperset (Set (unbox c)) (Set x)) +let subsetOf x = CustomMatcher(sprintf "Is subset of %A" x, + fun c -> Set.isSubset (Set (unbox c)) (Set x)) + let matchList xs = CustomMatcher(sprintf "All elements from list %s" (xs.ToString()), fun ys -> match ys with | :? list<_> as ys' -> List.sort xs = List.sort ys' diff --git a/src/FsUnit.Xunit/FsUnit.fs b/src/FsUnit.Xunit/FsUnit.fs index 732494b9..d5f97c3a 100644 --- a/src/FsUnit.Xunit/FsUnit.fs +++ b/src/FsUnit.Xunit/FsUnit.fs @@ -104,4 +104,6 @@ let descending = CustomMatchers.descending let inRange min max = CustomMatchers.inRange min max -let supersetOf expected = CustomMatchers.supersetOf expected \ No newline at end of file +let supersetOf expected = CustomMatchers.supersetOf expected + +let subsetOf expected = CustomMatchers.subsetOf expected \ No newline at end of file diff --git a/tests/FsUnit.MsTest.Test/Fs30Unit.MsTest.Test.fsproj b/tests/FsUnit.MsTest.Test/Fs30Unit.MsTest.Test.fsproj index e086c21e..8345515a 100644 --- a/tests/FsUnit.MsTest.Test/Fs30Unit.MsTest.Test.fsproj +++ b/tests/FsUnit.MsTest.Test/Fs30Unit.MsTest.Test.fsproj @@ -21,7 +21,8 @@ - + + diff --git a/tests/FsUnit.MsTest.Test/beSubsetOfTests.fs b/tests/FsUnit.MsTest.Test/beSubsetOfTests.fs new file mode 100644 index 00000000..28d6df53 --- /dev/null +++ b/tests/FsUnit.MsTest.Test/beSubsetOfTests.fs @@ -0,0 +1,39 @@ +namespace FsUnit.Test +open Microsoft.VisualStudio.TestTools.UnitTesting +open FsUnit.MsTest + +[] +type ``be subsetOf tests`` ()= + + [] member test. + ``5, 3 and 8 should be subset of 1 to 10`` ()= + [5;3;8] |> should be (subsetOf [1..10]) + + [] member test. + ``5 should be subset of 1 to 10`` ()= + [5] |> should be (subsetOf [1..10]) + + [] member test. + ``4 to 8 should be subset of 1 to 10`` ()= + {4..8} |> should be (subsetOf {1..10}) + + [] member test. + ``1 to 10 should be subset of 4. 1 and 7`` ()= + [|1..10|] |> should be (supersetOf [|4;1;7|]) + + [] member test. + ``5, 1 and 11 should not be subset of 1 to 10`` ()= + [5;1;11] |> should not' (be subsetOf [|1..10|]) + + [] member test. + ``1 to 10 should not be subset of 5`` ()= + [1..10] |> should not' (be subsetOf [5]) + + [] member test. + ``1 to 10 should be subset of 1 to 10`` ()= + [1..10] |> should be (subsetOf [1..10]) + + [] member test. + ``should fail on '1 to 10 should not be subset of 1 to 10'`` ()= + shouldFail (fun () -> + [1..10] |> should not' (be subsetOf [1..10])) diff --git a/tests/FsUnit.MsTest.Test/beSupersetOf.fs b/tests/FsUnit.MsTest.Test/beSupersetOfTests.fs similarity index 100% rename from tests/FsUnit.MsTest.Test/beSupersetOf.fs rename to tests/FsUnit.MsTest.Test/beSupersetOfTests.fs diff --git a/tests/FsUnit.NUnit.Test/FsUnit.NUnit.Test.fsproj b/tests/FsUnit.NUnit.Test/FsUnit.NUnit.Test.fsproj index 3cba3337..005ab162 100644 --- a/tests/FsUnit.NUnit.Test/FsUnit.NUnit.Test.fsproj +++ b/tests/FsUnit.NUnit.Test/FsUnit.NUnit.Test.fsproj @@ -13,7 +13,8 @@ - + + diff --git a/tests/FsUnit.NUnit.Test/beSubsetOfTests.fs b/tests/FsUnit.NUnit.Test/beSubsetOfTests.fs new file mode 100644 index 00000000..98bbecdd --- /dev/null +++ b/tests/FsUnit.NUnit.Test/beSubsetOfTests.fs @@ -0,0 +1,39 @@ +namespace FsUnit.Test +open NUnit.Framework +open FsUnit + +[] +type ``be subsetOf tests`` ()= + + [] member test. + ``5, 3 and 8 should be subset of 1 to 10`` ()= + [5;3;8] |> should be (subsetOf [1..10]) + + [] member test. + ``5 should be subset of 1 to 10`` ()= + [5] |> should be (subsetOf [1..10]) + + [] member test. + ``4 to 8 should be subset of 1 to 10`` ()= + {4..8} |> should be (subsetOf {1..10}) + + [] member test. + ``1 to 10 should be subset of 4. 1 and 7`` ()= + [|1..10|] |> should be (supersetOf [|4;1;7|]) + + [] member test. + ``5, 1 and 11 should not be subset of 1 to 10`` ()= + [5;1;11] |> should not' (be subsetOf [|1..10|]) + + [] member test. + ``1 to 10 should not be subset of 5`` ()= + [1..10] |> should not' (be subsetOf [5]) + + [] member test. + ``1 to 10 should be subset of 1 to 10`` ()= + [1..10] |> should be (subsetOf [1..10]) + + [] member test. + ``should fail on '1 to 10 should not be subset of 1 to 10'`` ()= + shouldFail (fun () -> + [1..10] |> should not' (be subsetOf [1..10])) \ No newline at end of file diff --git a/tests/FsUnit.NUnit.Test/beSupersetOf.fs b/tests/FsUnit.NUnit.Test/beSupersetOfTests.fs similarity index 100% rename from tests/FsUnit.NUnit.Test/beSupersetOf.fs rename to tests/FsUnit.NUnit.Test/beSupersetOfTests.fs diff --git a/tests/FsUnit.Xunit.Test/FsUnit.Xunit.Test.fsproj b/tests/FsUnit.Xunit.Test/FsUnit.Xunit.Test.fsproj index 39378dc6..06b88d86 100644 --- a/tests/FsUnit.Xunit.Test/FsUnit.Xunit.Test.fsproj +++ b/tests/FsUnit.Xunit.Test/FsUnit.Xunit.Test.fsproj @@ -20,7 +20,8 @@ - + + diff --git a/tests/FsUnit.Xunit.Test/beSubsetOfTests.fs b/tests/FsUnit.Xunit.Test/beSubsetOfTests.fs new file mode 100644 index 00000000..ea30fb84 --- /dev/null +++ b/tests/FsUnit.Xunit.Test/beSubsetOfTests.fs @@ -0,0 +1,38 @@ +namespace FsUnit.Test +open Xunit +open FsUnit.Xunit + +type ``be subsetOf tests`` ()= + + [] member test. + ``5, 3 and 8 should be subset of 1 to 10`` ()= + [5;3;8] |> should be (subsetOf [1..10]) + + [] member test. + ``5 should be subset of 1 to 10`` ()= + [5] |> should be (subsetOf [1..10]) + + [] member test. + ``4 to 8 should be subset of 1 to 10`` ()= + {4..8} |> should be (subsetOf {1..10}) + + [] member test. + ``1 to 10 should be subset of 4. 1 and 7`` ()= + [|1..10|] |> should be (supersetOf [|4;1;7|]) + + [] member test. + ``5, 1 and 11 should not be subset of 1 to 10`` ()= + [5;1;11] |> should not' (be subsetOf [|1..10|]) + + [] member test. + ``1 to 10 should not be subset of 5`` ()= + [1..10] |> should not' (be subsetOf [5]) + + [] member test. + ``1 to 10 should be subset of 1 to 10`` ()= + [1..10] |> should be (subsetOf [1..10]) + + [] member test. + ``should fail on '1 to 10 should not be subset of 1 to 10'`` ()= + shouldFail (fun () -> + [1..10] |> should not' (be subsetOf [1..10])) diff --git a/tests/FsUnit.Xunit.Test/beSupersetOf.fs b/tests/FsUnit.Xunit.Test/beSupersetOfTests.fs similarity index 100% rename from tests/FsUnit.Xunit.Test/beSupersetOf.fs rename to tests/FsUnit.Xunit.Test/beSupersetOfTests.fs