Skip to content

Commit 8d763b8

Browse files
xperiandriclaude
andcommitted
fixup! test: shared contracts of the map modules, run for HashMap and IMap
The assertion helpers of `main` are static classes since the foundation was merged, so the call sites of the map tests use them: `ExceptionAssert.Same (paramName, oracle, actual, message)` in `MapContract` and `OverrideAssert.OptionMatches (expected, actual, message)` in the `Option` tests of `HashMap` and `IMap`. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 1fef81d commit 8d763b8

3 files changed

Lines changed: 35 additions & 29 deletions

File tree

‎tests/FSharp.Collections.Immutable.Tests/Contracts/MapContract.fs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type BindingPredicate =
3939
/// <para>
4040
/// Every map module mirrors the FSharp.Core <c>Map</c> module (ADR 0001, D6), so the map contracts take no
4141
/// <see cref="T:FSharp.Collections.Immutable.Tests.Mirror"/>: they compare the exceptions with the <c>Map</c> oracle through
42-
/// <c>ExceptionAssert.same</c>, and <c>Mirror</c> stays about the sequence-like modules.
42+
/// <c>ExceptionAssert.Same</c>, and <c>Mirror</c> stays about the sequence-like modules.
4343
/// </para>
4444
/// <para>
4545
/// A hash map enumerates its bindings in an unspecified order. The contracts compare whole maps as bindings sorted by key,
@@ -72,7 +72,7 @@ type MapContractBase<'M>
7272

7373
/// Asserts that a function of the module throws what the same function of the FSharp.Core Map module throws.
7474
member _.ThrowsLikeMap (oracle : unit -> 'A, actual : unit -> 'R, message : string) =
75-
ExceptionAssert.same paramName (oracle >> ignore) (actual >> ignore) $"%s{name}: %s{message}"
75+
ExceptionAssert.Same (paramName, oracle >> ignore, actual >> ignore, $"%s{name}: %s{message}")
7676

7777
/// <summary>
7878
/// The contract of the reading functions that every map module provides: <c>HashMap</c>, <c>SortedMap</c>, <c>IMap</c>

‎tests/FSharp.Collections.Immutable.Tests/HashMap/HashMapOptionTests.fs‎

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,21 @@ type HashMapOptionTests () =
3030
member _.``tryFind returns an option`` (key : int) =
3131
let found : string option = HashMap.tryFind key table
3232

33-
OverrideAssert.optionMatches
34-
(FSharp.Collections.Immutable.HashMap.tryFind key table)
35-
found
33+
OverrideAssert.OptionMatches (
34+
FSharp.Collections.Immutable.HashMap.tryFind key table,
35+
found,
3636
"Option.HashMap.tryFind must match the default"
37+
)
3738

3839
[<TestMethod; DataRow 5; DataRow 1>]
3940
member _.``tryGetKey returns an option`` (key : int) =
4041
let found : int option = HashMap.tryGetKey key table
4142

42-
OverrideAssert.optionMatches
43-
(FSharp.Collections.Immutable.HashMap.tryGetKey key table)
44-
found
43+
OverrideAssert.OptionMatches (
44+
FSharp.Collections.Immutable.HashMap.tryGetKey key table,
45+
found,
4546
"Option.HashMap.tryGetKey must match the default"
47+
)
4648

4749
[<TestMethod>]
4850
member _.``pick takes a chooser of options`` () =
@@ -58,21 +60,23 @@ type HashMapOptionTests () =
5860
member _.``tryFindKey returns an option`` (predicate : BindingPredicate) =
5961
let found : int option = HashMap.tryFindKey predicate.Matches table
6062

61-
OverrideAssert.optionMatches
62-
(FSharp.Collections.Immutable.HashMap.tryFindKey predicate.Matches table)
63-
found
63+
OverrideAssert.OptionMatches (
64+
FSharp.Collections.Immutable.HashMap.tryFindKey predicate.Matches table,
65+
found,
6466
"Option.HashMap.tryFindKey must match the default"
67+
)
6568

6669
[<TestMethod>]
6770
member _.``tryPick takes a chooser of options and returns an option`` () =
6871
let found : int option = HashMap.tryPick negatedIfNegative table
6972

70-
OverrideAssert.optionMatches
71-
(FSharp.Collections.Immutable.HashMap.tryPick
73+
OverrideAssert.OptionMatches (
74+
FSharp.Collections.Immutable.HashMap.tryPick
7275
(fun key value -> negatedIfNegative key value |> ValueOption.ofOption)
73-
table)
74-
found
76+
table,
77+
found,
7578
"Option.HashMap.tryPick must match the default"
79+
)
7680

7781
let nothing : int option = HashMap.tryPick (fun _ _ -> None) table
7882
Assert.AreEqual<int option>(None, nothing, "Option.HashMap.tryPick must return None when the chooser returns nothing")

‎tests/FSharp.Collections.Immutable.Tests/HashMap/IMapOptionTests.fs‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,21 @@ type IMapOptionTests () =
3030
member _.``tryFind returns an option`` (key : int) =
3131
let found : string option = IMap.tryFind key table
3232

33-
OverrideAssert.optionMatches
34-
(FSharp.Collections.Immutable.IMap.tryFind key table)
35-
found
33+
OverrideAssert.OptionMatches (
34+
FSharp.Collections.Immutable.IMap.tryFind key table,
35+
found,
3636
"Option.IMap.tryFind must match the default"
37+
)
3738

3839
[<TestMethod; DataRow 5; DataRow 1>]
3940
member _.``tryGetKey returns an option`` (key : int) =
4041
let found : int option = IMap.tryGetKey key table
4142

42-
OverrideAssert.optionMatches
43-
(FSharp.Collections.Immutable.IMap.tryGetKey key table)
44-
found
43+
OverrideAssert.OptionMatches (
44+
FSharp.Collections.Immutable.IMap.tryGetKey key table,
45+
found,
4546
"Option.IMap.tryGetKey must match the default"
47+
)
4648

4749
[<TestMethod>]
4850
member _.``pick takes a chooser of options`` () =
@@ -58,21 +60,21 @@ type IMapOptionTests () =
5860
member _.``tryFindKey returns an option`` (predicate : BindingPredicate) =
5961
let found : int option = IMap.tryFindKey predicate.Matches table
6062

61-
OverrideAssert.optionMatches
62-
(FSharp.Collections.Immutable.IMap.tryFindKey predicate.Matches table)
63-
found
63+
OverrideAssert.OptionMatches (
64+
FSharp.Collections.Immutable.IMap.tryFindKey predicate.Matches table,
65+
found,
6466
"Option.IMap.tryFindKey must match the default"
67+
)
6568

6669
[<TestMethod>]
6770
member _.``tryPick takes a chooser of options and returns an option`` () =
6871
let found : int option = IMap.tryPick negatedIfNegative table
6972

70-
OverrideAssert.optionMatches
71-
(FSharp.Collections.Immutable.IMap.tryPick
72-
(fun key value -> negatedIfNegative key value |> ValueOption.ofOption)
73-
table)
74-
found
73+
OverrideAssert.OptionMatches (
74+
FSharp.Collections.Immutable.IMap.tryPick (fun key value -> negatedIfNegative key value |> ValueOption.ofOption) table,
75+
found,
7576
"Option.IMap.tryPick must match the default"
77+
)
7678

7779
[<TestMethod; DataRow 5; DataRow 1>]
7880
member _.``change takes a function of options as Map.change does`` (key : int) =

0 commit comments

Comments
 (0)