Skip to content

Commit

Permalink
Update tests for Swift 4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
xwu committed Jan 24, 2018
1 parent c962760 commit c5816a9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Tests/NumericAnnexTests/FactoringTests.swift
Expand Up @@ -41,6 +41,7 @@ class FactoringTests : XCTestCase {
XCTAssertEqual(UInt.lcm(42, 0), 0)
XCTAssertEqual(UInt.lcm(0, 0), 0)

#if !swift(>=4.1)
XCTAssertEqual(Int8.lcmFullWidth(0, 42).high, 0)
XCTAssertEqual(Int8.lcmFullWidth(0, 42).low, 0)
XCTAssertEqual(Int8.lcmReportingOverflow(0, 42).partialValue, 0)
Expand All @@ -55,6 +56,7 @@ class FactoringTests : XCTestCase {
XCTAssertEqual(Int8.lcmFullWidth(0, 0).low, 0)
XCTAssertEqual(Int8.lcmReportingOverflow(0, 0).partialValue, 0)
XCTAssertFalse(Int8.lcmReportingOverflow(0, 0).overflow)
#endif

XCTAssertEqual(UInt8.lcmFullWidth(0, 42).high, 0)
XCTAssertEqual(UInt8.lcmFullWidth(0, 42).low, 0)
Expand Down
12 changes: 12 additions & 0 deletions Tests/NumericAnnexTests/RationalTests.swift
Expand Up @@ -97,15 +97,19 @@ class RationalTests : XCTestCase {
XCTAssertEqual(pi.description, "inf")
XCTAssertTrue(pi.isCanonical)

#if !swift(>=4.1)
XCTAssertTrue(Ratio(numerator: 2, denominator: 0).isInfinite)
XCTAssertFalse(Ratio(numerator: 2, denominator: 0).isCanonical)
#endif

let ni = -Ratio.infinity
XCTAssertEqual(ni.description, "-inf")
XCTAssertTrue(ni.isCanonical)

#if !swift(>=4.1)
XCTAssertTrue(Ratio(numerator: -2, denominator: 0).isInfinite)
XCTAssertFalse(Ratio(numerator: -2, denominator: 0).isCanonical)
#endif

let zero = 0 as Ratio
XCTAssertEqual(zero.description, "0")
Expand All @@ -119,14 +123,18 @@ class RationalTests : XCTestCase {

XCTAssertEqual(pi + pi, .infinity)
XCTAssertEqual(ni + ni, -.infinity)
#if !swift(>=4.1)
XCTAssertEqual(pi + 0, .infinity)
XCTAssertEqual(ni + 0, -.infinity)
#endif
XCTAssertEqual(pi + 42, .infinity)
XCTAssertEqual(pi - 42, .infinity)
XCTAssertEqual(ni + 42, -.infinity)
XCTAssertEqual(ni - 42, -.infinity)
#if !swift(>=4.1)
XCTAssertEqual(0 + pi, .infinity)
XCTAssertEqual(0 + ni, -.infinity)
#endif
XCTAssertEqual(42 + pi, .infinity)
XCTAssertEqual(42 - pi, -.infinity)
XCTAssertEqual(42 + ni, -.infinity)
Expand All @@ -137,6 +145,7 @@ class RationalTests : XCTestCase {
XCTAssertTrue((pi - pi).isNaN)
XCTAssertTrue((-pi + pi).isNaN)

#if !swift(>=4.1)
XCTAssertTrue((0 / 0 as Ratio).isNaN)
XCTAssert((0 / 0 as Ratio) != .nan) // NaN compares unequal to everything.
XCTAssertTrue((42 / 0 as Ratio).isInfinite)
Expand All @@ -145,16 +154,19 @@ class RationalTests : XCTestCase {
XCTAssert(-42 / 0 as Ratio == -.infinity)
XCTAssertEqual((42 / 0 as Ratio).description, "inf")
XCTAssertEqual((-42 / 0 as Ratio).description, "-inf")
#endif

XCTAssertEqual(pi * pi, .infinity)
XCTAssertEqual(pi * ni, -.infinity)
XCTAssertEqual(ni * pi, -.infinity)
XCTAssertEqual(ni * ni, .infinity)

#if !swift(>=4.1)
XCTAssertTrue((pi * 0).isNaN)
XCTAssertTrue((ni * 0).isNaN)
XCTAssertTrue((0 * pi).isNaN)
XCTAssertTrue((0 * ni).isNaN)
#endif
XCTAssertTrue((pn * pi).isNaN)
XCTAssertTrue((pi * pn).isNaN)
XCTAssertTrue((pn * ni).isNaN)
Expand Down
12 changes: 11 additions & 1 deletion Tests/NumericAnnexTests/RealTests.swift
Expand Up @@ -23,7 +23,7 @@ extension MockReal : Hashable {
}
}

extension MockReal : Strideable, _Strideable {
extension MockReal : Strideable {
func distance(to other: MockReal) -> MockReal {
return MockReal(_value.distance(to: other._value))
}
Expand All @@ -33,6 +33,10 @@ extension MockReal : Strideable, _Strideable {
}
}

#if !swift(>=4.1)
extension MockReal : _Strideable { }
#endif

extension MockReal : Numeric {
var magnitude: MockReal {
return MockReal(_value.magnitude)
Expand Down Expand Up @@ -69,6 +73,12 @@ extension MockReal : Numeric {
}

extension MockReal : FloatingPoint {
#if swift(>=4.1)
init<T : BinaryInteger>(_ value: T) {
self = MockReal(Double(value))
}
#endif

init(_ value: Int) {
self = MockReal(Double(value))
}
Expand Down

0 comments on commit c5816a9

Please sign in to comment.