@@ -142,26 +142,24 @@ private func fail(
142
142
XCTFail ( message, file: file, line: line)
143
143
}
144
144
145
- /// Allows comparing:
145
+ /// Asserts that two values are equal within a certain accuracy.
146
146
///
147
- /// ```
148
- /// T where
149
- /// T: Collection,
150
- /// T.Element == U,
151
- /// U: FloatingPoint
152
- /// ```
153
- ///
154
- /// Useful for comparing:
155
- /// - `[Float]`
156
- /// - `[Double]`
157
- func XCTAssertEqual< T, U> (
147
+ /// - Parameters:
148
+ /// - expression1: An expression of type `T: Collection`, where `T.Element` conforms `FloatingPoint`.
149
+ /// - expression2: An expression of type `T: Collection`, where `T.Element` conforms `FloatingPoint`.
150
+ /// - accuracy: An expression of type `T.Element`, where `T.Element` conforms to `FloatingPoint`.
151
+ /// Describes the maximum difference between `expression1` and `expression2` for these values to be considered equal.
152
+ /// - message: An optional description of the failure.
153
+ /// - file: The file in which failure occurred. Defaults to the file name of the test case in which this function was called.
154
+ /// - line: The line number on which failure occurred. Defaults to the line number on which this function was called.
155
+ func XCTAssertEqual< T> (
158
156
_ expression1: @autoclosure ( ) throws -> T ,
159
157
_ expression2: @autoclosure ( ) throws -> T ,
160
- accuracy: U ? = nil ,
158
+ accuracy: T . Element ? = nil ,
161
159
_ message: @autoclosure ( ) -> String = " " ,
162
160
file: StaticString = #file,
163
161
line: UInt = #line
164
- ) where T: Collection , T. Element == U , U : FloatingPoint & ExpressibleByFloatLiteral {
162
+ ) where T: Collection , T. Element: FloatingPoint & ExpressibleByFloatLiteral {
165
163
XCTAssertEqual1D (
166
164
try expression1 ( ) ,
167
165
try expression2 ( ) ,
@@ -172,14 +170,27 @@ func XCTAssertEqual<T, U>(
172
170
)
173
171
}
174
172
175
- func XCTAssertEqual1D< T, U> (
173
+ /// Asserts that two values are equal within a certain accuracy.
174
+ ///
175
+ /// Semantically the same as its `XCTAssertEqual<T>(_:_:accuracy:_:file:line:)` counterpart
176
+ /// (i.e. without the `…1D` suffix), but with improved error messages.
177
+ ///
178
+ /// - Parameters:
179
+ /// - expression1: An expression of type `T: Collection`, where `T.Element` conforms `FloatingPoint`.
180
+ /// - expression2: An expression of type `T: Collection`, where `T.Element` conforms `FloatingPoint`.
181
+ /// - accuracy: An expression of type `T.Element`, where `T.Element` conforms to `FloatingPoint`.
182
+ /// Describes the maximum difference between `expression1` and `expression2` for these values to be considered equal.
183
+ /// - message: An optional description of the failure.
184
+ /// - file: The file in which failure occurred. Defaults to the file name of the test case in which this function was called.
185
+ /// - line: The line number on which failure occurred. Defaults to the line number on which this function was called.
186
+ func XCTAssertEqual1D< T> (
176
187
_ expression1: @autoclosure ( ) throws -> T ,
177
188
_ expression2: @autoclosure ( ) throws -> T ,
178
- accuracy: U ? = nil ,
189
+ accuracy: T . Element ? = nil ,
179
190
_ message: @autoclosure ( ) -> String = " " ,
180
191
file: StaticString = #file,
181
192
line: UInt = #line
182
- ) where T: Collection , T. Element == U , U : FloatingPoint & ExpressibleByFloatLiteral {
193
+ ) where T: Collection , T. Element: FloatingPoint & ExpressibleByFloatLiteral {
183
194
let prefix : Prefix = ( accuracy == nil ) ? . assertEqual : . assertEqualWithAccuracy
184
195
185
196
let ( actual, expected) : ( T , T )
@@ -200,30 +211,24 @@ func XCTAssertEqual1D<T, U>(
200
211
return fail ( prefix: prefix, failureMessage: error. description, file: file, line: line)
201
212
}
202
213
203
- /// Allows comparing:
214
+ /// Asserts that two values are equal within a certain accuracy.
204
215
///
205
- /// ```
206
- /// T where
207
- /// T: Collection,
208
- /// U: Collection,
209
- /// T.Element == U,
210
- /// U.Element == V,
211
- /// V: FloatingPoint
212
- /// ```
213
- ///
214
- /// Useful for comparing:
215
- /// - `[[Float]]`
216
- /// - `[[Double]]`
217
- /// - `Matrix<Float>`
218
- /// - `Matrix<Double>`
219
- func XCTAssertEqual< T, U, V> (
216
+ /// - Parameters:
217
+ /// - expression1: An expression of type `T: Collection`, `T.Element == U`, where `U` is `FloatingPoint`.
218
+ /// - expression2: An expression of type `T: Collection`, `T.Element == U`, where `U` is `FloatingPoint`.
219
+ /// - accuracy: An expression of type `U.Element`, where `U.Element` conforms to `FloatingPoint`.
220
+ /// Describes the maximum difference between `expression1` and `expression2` for these values to be considered equal.
221
+ /// - message: An optional description of the failure.
222
+ /// - file: The file in which failure occurred. Defaults to the file name of the test case in which this function was called.
223
+ /// - line: The line number on which failure occurred. Defaults to the line number on which this function was called.
224
+ func XCTAssertEqual< T, U> (
220
225
_ expression1: @autoclosure ( ) throws -> T ,
221
226
_ expression2: @autoclosure ( ) throws -> T ,
222
- accuracy: V ? = nil ,
227
+ accuracy: U . Element ? = nil ,
223
228
_ message: @autoclosure ( ) -> String = " " ,
224
229
file: StaticString = #file,
225
230
line: UInt = #line
226
- ) where T: Collection , U: Collection , T. Element == U , U. Element == V , V : FloatingPoint & ExpressibleByFloatLiteral {
231
+ ) where T: Collection , U: Collection , T. Element == U , U. Element: FloatingPoint & ExpressibleByFloatLiteral {
227
232
XCTAssertEqual2D (
228
233
try expression1 ( ) ,
229
234
try expression2 ( ) ,
@@ -234,14 +239,27 @@ func XCTAssertEqual<T, U, V>(
234
239
)
235
240
}
236
241
237
- func XCTAssertEqual2D< T, U, V> (
242
+ /// Asserts that two values are equal within a certain accuracy.
243
+ ///
244
+ /// Semantically the same as its `XCTAssertEqual<T>(_:_:accuracy:_:file:line:)` counterpart
245
+ /// (i.e. without the `…2D` suffix), but with improved error messages.
246
+ ///
247
+ /// - Parameters:
248
+ /// - expression1: An expression of type `T: Collection`, `T.Element == U`, where `U` is `FloatingPoint`.
249
+ /// - expression2: An expression of type `T: Collection`, `T.Element == U`, where `U` is `FloatingPoint`.
250
+ /// - accuracy: An expression of type `U.Element`, where `U.Element` conforms to `FloatingPoint`.
251
+ /// Describes the maximum difference between `expression1` and `expression2` for these values to be considered equal.
252
+ /// - message: An optional description of the failure.
253
+ /// - file: The file in which failure occurred. Defaults to the file name of the test case in which this function was called.
254
+ /// - line: The line number on which failure occurred. Defaults to the line number on which this function was called.
255
+ func XCTAssertEqual2D< T, U> (
238
256
_ expression1: @autoclosure ( ) throws -> T ,
239
257
_ expression2: @autoclosure ( ) throws -> T ,
240
- accuracy: V ? = nil ,
258
+ accuracy: U . Element ? = nil ,
241
259
_ message: @autoclosure ( ) -> String = " " ,
242
260
file: StaticString = #file,
243
261
line: UInt = #line
244
- ) where T: Collection , U: Collection , T. Element == U , U. Element == V , V : FloatingPoint & ExpressibleByFloatLiteral {
262
+ ) where T: Collection , U: Collection , T. Element == U , U. Element: FloatingPoint & ExpressibleByFloatLiteral {
245
263
let prefix : Prefix = ( accuracy == nil ) ? . assertEqual : . assertEqualWithAccuracy
246
264
247
265
let ( actual, expected) : ( T , T )
0 commit comments