Skip to content

Instantly share code, notes, and snippets.

@konrad1977
Created January 21, 2020 13:16
Show Gist options
  • Save konrad1977/3b2fe55302ad6a3f9a60bbf562dae828 to your computer and use it in GitHub Desktop.
Save konrad1977/3b2fe55302ad6a3f9a60bbf562dae828 to your computer and use it in GitHub Desktop.
Unit test support in Swift Playgrounds
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