Skip to content

Commit 0f1976d

Browse files
xperiandriclaude
andcommitted
fixup! test: contracts of Stack and IStack
The tests call the assertion helpers of the foundation on `main`, which are static classes with tupled arguments and the message last: `ExceptionAssert.Same` (10 call sites) and `OverrideAssert.OptionMatches` (14 call sites) replace the curried functions `ExceptionAssert.same` and `OverrideAssert.optionMatches`. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent fab5b77 commit 0f1976d

6 files changed

Lines changed: 106 additions & 82 deletions

File tree

‎tests/FSharp.Collections.Immutable.Tests/Stack/IStackOptionTests.fs‎

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,29 @@ type IStackOptionTests () =
2424
let single : IImmutableStack<int> = Stack.singleton 5
2525
let found : int option = IStack.tryExactlyOne single
2626

27-
OverrideAssert.optionMatches
28-
(FSharp.Collections.Immutable.IStack.tryExactlyOne single)
29-
found
27+
OverrideAssert.OptionMatches (
28+
FSharp.Collections.Immutable.IStack.tryExactlyOne single,
29+
found,
3030
"Option.IStack.tryExactlyOne must match the default after conversion"
31+
)
3132

3233
[<TestMethod>]
3334
member _.``tryHead returns an option`` () =
3435
let found : int option = IStack.tryHead several
35-
OverrideAssert.optionMatches
36-
(FSharp.Collections.Immutable.IStack.tryHead several)
37-
found
36+
OverrideAssert.OptionMatches (
37+
FSharp.Collections.Immutable.IStack.tryHead several,
38+
found,
3839
"Option.IStack.tryHead must match the default"
40+
)
3941

4042
[<TestMethod>]
4143
member _.``tryLast returns an option`` () =
4244
let found : int option = IStack.tryLast several
43-
OverrideAssert.optionMatches
44-
(FSharp.Collections.Immutable.IStack.tryLast several)
45-
found
45+
OverrideAssert.OptionMatches (
46+
FSharp.Collections.Immutable.IStack.tryLast several,
47+
found,
4648
"Option.IStack.tryLast must match the default"
49+
)
4750

4851
[<TestMethod>]
4952
member _.``tryTail returns an option`` () =
@@ -105,37 +108,41 @@ type IStackOptionTests () =
105108
member _.``tryFind returns an option`` () =
106109
let found : int option = IStack.tryFind (fun item -> item > 6) several
107110

108-
OverrideAssert.optionMatches
109-
(FSharp.Collections.Immutable.IStack.tryFind (fun item -> item > 6) several)
110-
found
111+
OverrideAssert.OptionMatches (
112+
FSharp.Collections.Immutable.IStack.tryFind (fun item -> item > 6) several,
113+
found,
111114
"Option.IStack.tryFind must match the default"
115+
)
112116

113117
[<TestMethod>]
114118
member _.``tryFindBack returns an option`` () =
115119
let found : int option = IStack.tryFindBack (fun item -> item > 6) several
116120

117-
OverrideAssert.optionMatches
118-
(FSharp.Collections.Immutable.IStack.tryFindBack (fun item -> item > 6) several)
119-
found
121+
OverrideAssert.OptionMatches (
122+
FSharp.Collections.Immutable.IStack.tryFindBack (fun item -> item > 6) several,
123+
found,
120124
"Option.IStack.tryFindBack must match the default"
125+
)
121126

122127
[<TestMethod>]
123128
member _.``tryFindIndex returns an option`` () =
124129
let found : int option = IStack.tryFindIndex (fun item -> item > 6) several
125130

126-
OverrideAssert.optionMatches
127-
(FSharp.Collections.Immutable.IStack.tryFindIndex (fun item -> item > 6) several)
128-
found
131+
OverrideAssert.OptionMatches (
132+
FSharp.Collections.Immutable.IStack.tryFindIndex (fun item -> item > 6) several,
133+
found,
129134
"Option.IStack.tryFindIndex must match the default"
135+
)
130136

131137
[<TestMethod>]
132138
member _.``tryFindIndexBack returns an option`` () =
133139
let found : int option = IStack.tryFindIndexBack (fun item -> item > 6) several
134140

135-
OverrideAssert.optionMatches
136-
(FSharp.Collections.Immutable.IStack.tryFindIndexBack (fun item -> item > 6) several)
137-
found
141+
OverrideAssert.OptionMatches (
142+
FSharp.Collections.Immutable.IStack.tryFindIndexBack (fun item -> item > 6) several,
143+
found,
138144
"Option.IStack.tryFindIndexBack must match the default"
145+
)
139146

140147
[<TestMethod>]
141148
member _.``tryPick takes a chooser of options and returns an option`` () =

‎tests/FSharp.Collections.Immutable.Tests/Stack/IStackTests.fs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,11 +404,12 @@ type IStackTests () =
404404

405405
[<TestMethod>]
406406
member _.``uncons throws for an empty stack as List.head does`` () =
407-
ExceptionAssert.same
408-
StackOps.paramName
409-
(fun () -> List.head List.empty<int> |> ignore)
410-
(fun () -> IStack.uncons (IStack.clear (tagged ())) |> ignore)
407+
ExceptionAssert.Same (
408+
StackOps.paramName,
409+
(fun () -> List.head List.empty<int> |> ignore),
410+
(fun () -> IStack.uncons (IStack.clear (tagged ())) |> ignore),
411411
"IStack.uncons of an empty stack must throw as List.head does"
412+
)
412413

413414
[<TestMethod>]
414415
member _.``cons and consMany push the values on top`` () =

‎tests/FSharp.Collections.Immutable.Tests/Stack/IStackTupleTests.fs‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,23 +118,25 @@ type IStackTupleTests () =
118118
member _.``zip and zip3 throw for different lengths as the defaults do`` () =
119119
let short : IImmutableStack<int> = Stack.singleton 1
120120

121-
ExceptionAssert.same
122-
id
121+
ExceptionAssert.Same (
122+
id,
123123
(fun () ->
124124
FSharp.Collections.Immutable.IStack.zip several short
125125
|> ignore
126-
)
127-
(fun () -> IStack.zip several short |> ignore)
126+
),
127+
(fun () -> IStack.zip several short |> ignore),
128128
"Tuple.IStack.zip must throw as the default zip does"
129+
)
129130

130-
ExceptionAssert.same
131-
id
131+
ExceptionAssert.Same (
132+
id,
132133
(fun () ->
133134
FSharp.Collections.Immutable.IStack.zip3 several short other
134135
|> ignore
135-
)
136-
(fun () -> IStack.zip3 several short other |> ignore)
136+
),
137+
(fun () -> IStack.zip3 several short other |> ignore),
137138
"Tuple.IStack.zip3 must throw as the default zip3 does"
139+
)
138140

139141
[<TestMethod>]
140142
member _.``zip3 returns reference tuples`` () =

‎tests/FSharp.Collections.Immutable.Tests/Stack/StackOptionTests.fs‎

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,31 @@ type StackOptionTests () =
3131
member _.``tryExactlyOne returns an option`` () =
3232
let found : int option = Stack.tryExactlyOne (Stack.singleton 5)
3333

34-
OverrideAssert.optionMatches
35-
(FSharp.Collections.Immutable.Stack.tryExactlyOne (Stack.singleton 5))
36-
found
34+
OverrideAssert.OptionMatches (
35+
FSharp.Collections.Immutable.Stack.tryExactlyOne (Stack.singleton 5),
36+
found,
3737
"Option.Stack.tryExactlyOne must match the default after conversion"
38+
)
3839

3940
[<TestMethod>]
4041
member _.``tryHead returns an option`` () =
4142
let found : int option = Stack.tryHead several
4243

43-
OverrideAssert.optionMatches
44-
(FSharp.Collections.Immutable.Stack.tryHead several)
45-
found
44+
OverrideAssert.OptionMatches (
45+
FSharp.Collections.Immutable.Stack.tryHead several,
46+
found,
4647
"Option.Stack.tryHead must match the default"
48+
)
4749

4850
[<TestMethod>]
4951
member _.``tryLast returns an option`` () =
5052
let found : int option = Stack.tryLast several
5153

52-
OverrideAssert.optionMatches
53-
(FSharp.Collections.Immutable.Stack.tryLast several)
54-
found
54+
OverrideAssert.OptionMatches (
55+
FSharp.Collections.Immutable.Stack.tryLast several,
56+
found,
5557
"Option.Stack.tryLast must match the default"
58+
)
5659

5760
[<TestMethod>]
5861
member _.``tryTail returns an option`` () =
@@ -108,50 +111,55 @@ type StackOptionTests () =
108111

109112
[<TestMethod>]
110113
member _.``pick throws as List.pick does`` () =
111-
ExceptionAssert.same
112-
StackOps.paramName
114+
ExceptionAssert.Same (
115+
StackOps.paramName,
113116
(fun () ->
114117
List.pick (fun _ -> None) (List.ofArray Inputs.Several)
115118
|> ignore
116-
)
117-
(fun () -> Stack.pick (fun _ -> None) several |> ignore)
119+
),
120+
(fun () -> Stack.pick (fun _ -> None) several |> ignore),
118121
"Option.Stack.pick without a choice must throw as List.pick does"
122+
)
119123

120124
[<TestMethod>]
121125
member _.``tryFind returns an option`` () =
122126
let found : int option = Stack.tryFind (fun item -> item > 6) several
123127

124-
OverrideAssert.optionMatches
125-
(FSharp.Collections.Immutable.Stack.tryFind (fun item -> item > 6) several)
126-
found
128+
OverrideAssert.OptionMatches (
129+
FSharp.Collections.Immutable.Stack.tryFind (fun item -> item > 6) several,
130+
found,
127131
"Option.Stack.tryFind must match the default"
132+
)
128133

129134
[<TestMethod>]
130135
member _.``tryFindBack returns an option`` () =
131136
let found : int option = Stack.tryFindBack (fun item -> item > 6) several
132137

133-
OverrideAssert.optionMatches
134-
(FSharp.Collections.Immutable.Stack.tryFindBack (fun item -> item > 6) several)
135-
found
138+
OverrideAssert.OptionMatches (
139+
FSharp.Collections.Immutable.Stack.tryFindBack (fun item -> item > 6) several,
140+
found,
136141
"Option.Stack.tryFindBack must match the default"
142+
)
137143

138144
[<TestMethod>]
139145
member _.``tryFindIndex returns an option`` () =
140146
let found : int option = Stack.tryFindIndex (fun item -> item > 6) several
141147

142-
OverrideAssert.optionMatches
143-
(FSharp.Collections.Immutable.Stack.tryFindIndex (fun item -> item > 6) several)
144-
found
148+
OverrideAssert.OptionMatches (
149+
FSharp.Collections.Immutable.Stack.tryFindIndex (fun item -> item > 6) several,
150+
found,
145151
"Option.Stack.tryFindIndex must match the default"
152+
)
146153

147154
[<TestMethod>]
148155
member _.``tryFindIndexBack returns an option`` () =
149156
let found : int option = Stack.tryFindIndexBack (fun item -> item > 6) several
150157

151-
OverrideAssert.optionMatches
152-
(FSharp.Collections.Immutable.Stack.tryFindIndexBack (fun item -> item > 6) several)
153-
found
158+
OverrideAssert.OptionMatches (
159+
FSharp.Collections.Immutable.Stack.tryFindIndexBack (fun item -> item > 6) several,
160+
found,
154161
"Option.Stack.tryFindIndexBack must match the default"
162+
)
155163

156164
[<TestMethod>]
157165
member _.``tryPick takes a chooser of options and returns an option`` () =

‎tests/FSharp.Collections.Immutable.Tests/Stack/StackTests.fs‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -567,11 +567,12 @@ type StackTests () =
567567

568568
[<TestMethod>]
569569
member _.``uncons throws for an empty stack as List.head does`` () =
570-
ExceptionAssert.same
571-
StackOps.paramName
572-
(fun () -> List.head List.empty<int> |> ignore)
573-
(fun () -> Stack.uncons Stack.empty<int> |> ignore)
570+
ExceptionAssert.Same (
571+
StackOps.paramName,
572+
(fun () -> List.head List.empty<int> |> ignore),
573+
(fun () -> Stack.uncons Stack.empty<int> |> ignore),
574574
"Stack.uncons of an empty stack must throw as List.head does"
575+
)
575576

576577
[<TestMethod>]
577578
member _.``tryUncons returns the top and the stack below it or nothing`` () =
@@ -777,22 +778,24 @@ type StackTests () =
777778

778779
[<TestMethod>]
779780
member _.``transpose names the stack that ends first as List does`` () =
780-
ExceptionAssert.same
781-
StackOps.paramName
782-
(fun () -> List.transpose [| [ 1 ]; [ 1; 2 ] |] |> ignore)
781+
ExceptionAssert.Same (
782+
StackOps.paramName,
783+
(fun () -> List.transpose [| [ 1 ]; [ 1; 2 ] |] |> ignore),
783784
(fun () ->
784785
Stack.transpose [| Stack.ofArray [| 1 |]; Stack.ofArray [| 1; 2 |] |]
785786
|> ignore
786-
)
787+
),
787788
"Stack.transpose of a shorter first stack must throw as List.transpose does"
789+
)
788790

789791
[<TestMethod>]
790792
member _.``splitAt of an empty stack throws as List.splitAt does`` () =
791-
ExceptionAssert.same
792-
StackOps.paramName
793-
(fun () -> List.splitAt 1 List.empty<int> |> ignore)
794-
(fun () -> Stack.splitAt 1 Stack.empty<int> |> ignore)
793+
ExceptionAssert.Same (
794+
StackOps.paramName,
795+
(fun () -> List.splitAt 1 List.empty<int> |> ignore),
796+
(fun () -> Stack.splitAt 1 Stack.empty<int> |> ignore),
795797
"Stack.splitAt 1 of an empty stack must throw as List.splitAt does"
798+
)
796799

797800
[<TestMethod; DynamicData(nameof StackTests.CompleteMessages)>]
798801
member _.``the exceptions have the complete messages of List with the names of the stacks`` (name : string) =

‎tests/FSharp.Collections.Immutable.Tests/Stack/StackTupleTests.fs‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,15 @@ type StackTupleTests () =
5959

6060
[<TestMethod>]
6161
member _.``uncons throws as the default does`` () =
62-
ExceptionAssert.same
63-
id
62+
ExceptionAssert.Same (
63+
id,
6464
(fun () ->
6565
FSharp.Collections.Immutable.Stack.uncons Stack.empty<int>
6666
|> ignore
67-
)
68-
(fun () -> Stack.uncons Stack.empty<int> |> ignore)
67+
),
68+
(fun () -> Stack.uncons Stack.empty<int> |> ignore),
6969
"Tuple.Stack.uncons must throw as the default uncons does"
70+
)
7071

7172
[<TestMethod>]
7273
member _.``Cons is a struct partial pattern of reference tuples`` () =
@@ -143,23 +144,25 @@ type StackTupleTests () =
143144
member _.``zip and zip3 throw for different lengths as the defaults do`` () =
144145
let short = Stack.singleton 1
145146

146-
ExceptionAssert.same
147-
id
147+
ExceptionAssert.Same (
148+
id,
148149
(fun () ->
149150
FSharp.Collections.Immutable.Stack.zip several short
150151
|> ignore
151-
)
152-
(fun () -> Stack.zip several short |> ignore)
152+
),
153+
(fun () -> Stack.zip several short |> ignore),
153154
"Tuple.Stack.zip must throw as the default zip does"
155+
)
154156

155-
ExceptionAssert.same
156-
id
157+
ExceptionAssert.Same (
158+
id,
157159
(fun () ->
158160
FSharp.Collections.Immutable.Stack.zip3 several short other
159161
|> ignore
160-
)
161-
(fun () -> Stack.zip3 several short other |> ignore)
162+
),
163+
(fun () -> Stack.zip3 several short other |> ignore),
162164
"Tuple.Stack.zip3 must throw as the default zip3 does"
165+
)
163166

164167
[<TestMethod>]
165168
member _.``zip3 returns reference tuples`` () =

0 commit comments

Comments
 (0)