Created
January 21, 2020 13:16
-
-
Save konrad1977/3b2fe55302ad6a3f9a60bbf562dae828 to your computer and use it in GitHub Desktop.
Unit test support in Swift Playgrounds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XCTest | |
// MARK: Comparable --- | |
@discardableResult | |
public func assertGreaterThan<A: Comparable>(_ lhs: A, _ rhs: A) -> String { | |
return lhs > rhs ? "✅" : "❌" | |
} | |
@discardableResult | |
public func assertGreaterThanOrEqual<A: Comparable>(_ lhs: A, _ rhs: A) -> String { | |
return lhs >= rhs ? "✅" : "❌" | |
} | |
@discardableResult | |
public func assertLesserThan<A: Comparable>(_ lhs: A, _ rhs: A) -> String { | |
return lhs < rhs ? "✅" : "❌" | |
} | |
@discardableResult | |
public func assertLesserThanOrEqual<A: Comparable>(_ lhs: A, _ rhs: A) -> String { | |
return lhs <= rhs ? "✅" : "❌" | |
} | |
// MARK: Equatable --- | |
@discardableResult | |
public func assertEqual<A: Equatable>(_ lhs: A, _ rhs: A) -> String { | |
return lhs == rhs ? "✅" : "❌" | |
} | |
// MARK: Optional --- | |
@discardableResult | |
public func assertNotNil<A>(_ lhs: A?) -> String { | |
return lhs == nil ? "❌" : "✅" | |
} | |
@discardableResult | |
public func assertNil<A>(_ lhs: A?) -> String { | |
return lhs != nil ? "❌" : "✅" | |
} | |
// MARK: Boolean --- | |
@discardableResult | |
public func assertTrue(_ lhs: Bool) -> String { | |
return lhs == true ? "✅" : "❌" | |
} | |
@discardableResult | |
public func assertFalse(_ lhs: Bool) -> String { | |
return assertTrue(lhs == false) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment