File tree Expand file tree Collapse file tree 2 files changed +10
-7
lines changed
Tests/NimbleTests/Matchers Expand file tree Collapse file tree 2 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -19,17 +19,13 @@ internal func isCloseTo(_ actualValue: NMBDoubleConvertible?,
1919/// point values which can have imprecise results when doing arithmetic on them.
2020///
2121/// @see equal
22- public func beCloseTo( _ expectedValue: Double , within delta: Double = DefaultDelta) -> Predicate < Double > {
22+ public func beCloseTo< Value : NMBDoubleConvertible > ( _ expectedValue: Value , within delta: Double = DefaultDelta) -> Predicate < Value > {
2323 return Predicate . define { actualExpression in
2424 return isCloseTo ( try actualExpression. evaluate ( ) , expectedValue: expectedValue, delta: delta)
2525 }
2626}
2727
28- /// A Nimble matcher that succeeds when a value is close to another. This is used for floating
29- /// point values which can have imprecise results when doing arithmetic on them.
30- ///
31- /// @see equal
32- public func beCloseTo( _ expectedValue: NMBDoubleConvertible , within delta: Double = DefaultDelta) -> Predicate < NMBDoubleConvertible > {
28+ private func beCloseTo( _ expectedValue: NMBDoubleConvertible , within delta: Double = DefaultDelta) -> Predicate < NMBDoubleConvertible > {
3329 return Predicate . define { actualExpression in
3430 return isCloseTo ( try actualExpression. evaluate ( ) , expectedValue: expectedValue, delta: delta)
3531 }
Original file line number Diff line number Diff line change @@ -53,7 +53,8 @@ final class BeCloseToTest: XCTestCase {
5353 expect ( NSDate ( dateTimeString: " 2015-08-26 11:43:00 " ) ) . to ( beCloseTo ( NSDate ( dateTimeString: " 2015-08-26 11:43:05 " ) , within: 10 ) )
5454
5555 failsWithErrorMessage ( " expected to not be close to <2015-08-26 11:43:00.0050> (within 0.006), got <2015-08-26 11:43:00.0000> " ) {
56- let expectedDate = NSDate ( dateTimeString: " 2015-08-26 11:43:00 " ) . addingTimeInterval ( 0.005 )
56+ // Cast to NSDate is needed for Linux (swift-corelibs-foundation) compatibility.
57+ let expectedDate = NSDate ( dateTimeString: " 2015-08-26 11:43:00 " ) . addingTimeInterval ( 0.005 ) as NSDate
5758 expect ( NSDate ( dateTimeString: " 2015-08-26 11:43:00 " ) ) . toNot ( beCloseTo ( expectedDate, within: 0.006 ) )
5859 }
5960 }
@@ -139,4 +140,10 @@ final class BeCloseToTest: XCTestCase {
139140 expect ( [ 0.1 , 1.2 ] ) . to ( beCloseTo ( [ 0.3 , 1.3 ] , within: 0.1 ) )
140141 }
141142 }
143+
144+ // https://github.com/Quick/Nimble/issues/831
145+ func testCombinationWithAllPass( ) {
146+ let values : [ NSNumber ] = [ 0 ]
147+ expect ( values) . to ( allPass ( beCloseTo ( 0 ) ) )
148+ }
142149}
You can’t perform that action at this time.
0 commit comments