-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from masters3d/SR1187AddTests
Added tests and lowercased enums
- Loading branch information
Showing
8 changed files
with
178 additions
and
17 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
This source file is part of the Swift.org open source project | ||
|
||
Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors | ||
Licensed under Apache License v2.0 with Runtime Library Exception | ||
|
||
See http://swift.org/LICENSE.txt for license information | ||
See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
*/ | ||
|
||
@testable import PlayingCardTestSuite | ||
|
||
import XCTest | ||
|
||
XCTMain([testCase(CardTest.allTest), | ||
testCase(RankTest.allTest), | ||
testCase(SuitTest.allTest) | ||
]) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
This source file is part of the Swift.org open source project | ||
|
||
Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors | ||
Licensed under Apache License v2.0 with Runtime Library Exception | ||
|
||
See http://swift.org/LICENSE.txt for license information | ||
See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
*/ | ||
|
||
@testable import PlayingCard | ||
import XCTest | ||
|
||
class CardTests: XCTestCase { | ||
|
||
func testCardSingle() { | ||
let card1 = PlayingCard(rank: .queen, suit: .diamonds) | ||
let card2 = PlayingCard(rank: .king, suit: .diamonds) | ||
let card3 = PlayingCard(rank: .ace, suit: .clubs) | ||
let card4 = PlayingCard(rank: .queen, suit: .diamonds) | ||
let card5 = PlayingCard(rank: .queen, suit: .clubs) | ||
|
||
XCTAssertGreaterThan(card2, card1) | ||
XCTAssertGreaterThan(card3, card2) | ||
XCTAssertEqual(card1, card4) | ||
XCTAssertGreaterThan(card4, card5) | ||
} | ||
|
||
func testCardStringEquality() { | ||
let card1 = PlayingCard(rank: .jack, suit: .clubs) | ||
let card2 = PlayingCard(rank: .two, suit: .hearts) | ||
let card3 = PlayingCard(rank: .queen, suit: .diamonds) | ||
|
||
XCTAssertEqual(String(card1), "♣︎J") | ||
XCTAssertEqual(String(card2), "♡2") | ||
XCTAssertEqual(String(card3), "♢Q") | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
This source file is part of the Swift.org open source project | ||
|
||
Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors | ||
Licensed under Apache License v2.0 with Runtime Library Exception | ||
|
||
See http://swift.org/LICENSE.txt for license information | ||
See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
*/ | ||
|
||
@testable import PlayingCard | ||
import XCTest | ||
|
||
class RankTests: XCTestCase { | ||
|
||
func testRankStringEquality() { | ||
let numbers = [2,3,4,5,6,7,8,9,10] | ||
let suits = numbers.map{Rank(rawValue:$0)}.flatMap{$0}.map{Int(String($0)) ?? 0} | ||
|
||
XCTAssertEqual(String(Rank.ace), "A") | ||
XCTAssertEqual(String(Rank.jack), "J") | ||
XCTAssertEqual(String(Rank.queen), "Q") | ||
XCTAssertEqual(String(Rank.king), "K") | ||
XCTAssertEqual(numbers, suits) | ||
} | ||
|
||
func testRankComparable() { | ||
XCTAssertGreaterThan(Rank.ace, Rank.two) | ||
XCTAssertGreaterThan(Rank.ace, Rank.king) | ||
XCTAssertGreaterThan(Rank.king, Rank.queen) | ||
XCTAssertGreaterThan(Rank.queen, Rank.jack) | ||
XCTAssertGreaterThan(Rank.jack, Rank.ten) | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
This source file is part of the Swift.org open source project | ||
|
||
Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors | ||
Licensed under Apache License v2.0 with Runtime Library Exception | ||
|
||
See http://swift.org/LICENSE.txt for license information | ||
See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
*/ | ||
|
||
@testable import PlayingCard | ||
import XCTest | ||
|
||
class SuitTests: XCTestCase { | ||
|
||
func testSuitStringEquality() { | ||
XCTAssertEqual(String(Suit.spades), "♠︎") | ||
XCTAssertEqual(String(Suit.hearts), "♡") | ||
XCTAssertEqual(String(Suit.diamonds), "♢") | ||
XCTAssertEqual(String(Suit.clubs), "♣︎") | ||
} | ||
|
||
func testSuitComparable() { | ||
XCTAssertGreaterThan(Suit.spades, Suit.diamonds) | ||
XCTAssertGreaterThan(Suit.hearts, Suit.diamonds ) | ||
XCTAssertGreaterThan(Suit.hearts, Suit.clubs) | ||
XCTAssertGreaterThan(Suit.diamonds, Suit.clubs) | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
This source file is part of the Swift.org open source project | ||
|
||
Copyright 2015 - 2016 Apple Inc. and the Swift project authors | ||
Licensed under Apache License v2.0 with Runtime Library Exception | ||
|
||
See http://swift.org/LICENSE.txt for license information | ||
See http://swift.org/CONTRIBUTORS.txt for Swift project authors | ||
*/ | ||
|
||
extension CardTests { | ||
|
||
static var allTests : [(String, CardTests -> () throws -> Void)] { | ||
return [ | ||
("testCardSingle", testCardSingle), | ||
("testCardStringEquality",testCardStringEquality) | ||
] | ||
} | ||
} | ||
|
||
extension RankTests { | ||
|
||
static var allTests : [(String, RankTests -> () throws -> Void)] { | ||
return [ | ||
("testRankStringEquality",testRankStringEquality), | ||
("testRankComparable", testRankComparable) | ||
] | ||
} | ||
} | ||
|
||
extension SuitTests { | ||
|
||
static var allTests : [(String, SuitTests -> () throws -> Void)] { | ||
return [ | ||
("testSuitStringEquality",testSuitStringEquality), | ||
("testSuitComparable",testSuitComparable ) | ||
] | ||
} | ||
} |