-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Swift tools version to 6.0 and refactor test cases to use new …
…testing framework
- Loading branch information
1 parent
30f8e4c
commit 95c5e5b
Showing
13 changed files
with
271 additions
and
243 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
import XCTest | ||
import Testing | ||
import Foundation | ||
@testable import {{exercise|camelCase}} | ||
class {{exercise|camelCase}}Tests: XCTestCase { | ||
let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false | ||
|
||
let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false | ||
|
||
@Suite struct {{exercise|camelCase}}Tests { | ||
{% for case in cases %} | ||
{% if forloop.first -%} | ||
func test{{case.description |camelCase }}() { | ||
@Test("{{case.description}}") | ||
{% else -%} | ||
func test{{case.description |camelCase }}() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("{{case.description}}", .enabled(if: RUNALL)) | ||
{% endif -%} | ||
XCTAssertEqual(pascalsTriangle(rows: {{case.input | extractCountKey}}), {{case.expected}}) | ||
func test{{case.description |camelCase }}() { | ||
#expect(pascalsTriangle(rows: {{case.input | extractCountKey}}) == {{case.expected}}) | ||
} | ||
{% endfor -%} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// swift-tools-version:5.3 | ||
// swift-tools-version:6.0 | ||
|
||
import PackageDescription | ||
|
||
|
63 changes: 33 additions & 30 deletions
63
exercises/practice/pascals-triangle/Tests/PascalsTriangleTests/PascalsTriangleTests.swift
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// swift-tools-version:5.3 | ||
// swift-tools-version:6.0 | ||
|
||
import PackageDescription | ||
|
||
|
87 changes: 45 additions & 42 deletions
87
exercises/practice/perfect-numbers/Tests/PerfectNumbersTests/PerfectNumbersTests.swift
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 |
---|---|---|
@@ -1,75 +1,78 @@ | ||
import XCTest | ||
import Foundation | ||
import Testing | ||
|
||
@testable import PerfectNumbers | ||
|
||
class PerfectNumbersTests: XCTestCase { | ||
let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false | ||
let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false | ||
|
||
@Suite struct PerfectNumbersTests { | ||
|
||
@Test("Smallest perfect number is classified correctly") | ||
func testSmallestPerfectNumberIsClassifiedCorrectly() { | ||
XCTAssertEqual(try! classify(number: 6), .perfect) | ||
#expect(try! classify(number: 6) == .perfect) | ||
} | ||
|
||
func testMediumPerfectNumberIsClassifiedCorrectly() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(try! classify(number: 28), .perfect) | ||
@Test("Medium perfect number is classified correctly", .enabled(if: RUNALL)) | ||
func testMediumPerfectNumberIsClassifiedCorrectly() { | ||
#expect(try! classify(number: 28) == .perfect) | ||
} | ||
|
||
func testLargePerfectNumberIsClassifiedCorrectly() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(try! classify(number: 33_550_336), .perfect) | ||
@Test("Large perfect number is classified correctly", .enabled(if: RUNALL)) | ||
func testLargePerfectNumberIsClassifiedCorrectly() { | ||
#expect(try! classify(number: 33_550_336) == .perfect) | ||
} | ||
|
||
func testSmallestAbundantNumberIsClassifiedCorrectly() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(try! classify(number: 12), .abundant) | ||
@Test("Smallest abundant number is classified correctly", .enabled(if: RUNALL)) | ||
func testSmallestAbundantNumberIsClassifiedCorrectly() { | ||
#expect(try! classify(number: 12) == .abundant) | ||
} | ||
|
||
func testMediumAbundantNumberIsClassifiedCorrectly() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(try! classify(number: 30), .abundant) | ||
@Test("Medium abundant number is classified correctly", .enabled(if: RUNALL)) | ||
func testMediumAbundantNumberIsClassifiedCorrectly() { | ||
#expect(try! classify(number: 30) == .abundant) | ||
} | ||
|
||
func testLargeAbundantNumberIsClassifiedCorrectly() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(try! classify(number: 33_550_335), .abundant) | ||
@Test("Large abundant number is classified correctly", .enabled(if: RUNALL)) | ||
func testLargeAbundantNumberIsClassifiedCorrectly() { | ||
#expect(try! classify(number: 33_550_335) == .abundant) | ||
} | ||
|
||
func testSmallestPrimeDeficientNumberIsClassifiedCorrectly() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(try! classify(number: 2), .deficient) | ||
@Test("Smallest prime deficient number is classified correctly", .enabled(if: RUNALL)) | ||
func testSmallestPrimeDeficientNumberIsClassifiedCorrectly() { | ||
#expect(try! classify(number: 2) == .deficient) | ||
} | ||
|
||
func testSmallestNonPrimeDeficientNumberIsClassifiedCorrectly() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(try! classify(number: 4), .deficient) | ||
@Test("Smallest non-prime deficient number is classified correctly", .enabled(if: RUNALL)) | ||
func testSmallestNonPrimeDeficientNumberIsClassifiedCorrectly() { | ||
#expect(try! classify(number: 4) == .deficient) | ||
} | ||
|
||
func testMediumDeficientNumberIsClassifiedCorrectly() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(try! classify(number: 32), .deficient) | ||
@Test("Medium deficient number is classified correctly", .enabled(if: RUNALL)) | ||
func testMediumDeficientNumberIsClassifiedCorrectly() { | ||
#expect(try! classify(number: 32) == .deficient) | ||
} | ||
|
||
func testLargeDeficientNumberIsClassifiedCorrectly() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(try! classify(number: 33_550_337), .deficient) | ||
@Test("Large deficient number is classified correctly", .enabled(if: RUNALL)) | ||
func testLargeDeficientNumberIsClassifiedCorrectly() { | ||
#expect(try! classify(number: 33_550_337) == .deficient) | ||
} | ||
|
||
func testEdgeCaseNoFactorsOtherThanItselfIsClassifiedCorrectly() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(try! classify(number: 1), .deficient) | ||
@Test("Edge case (no factors other than itself) is classified correctly", .enabled(if: RUNALL)) | ||
func testEdgeCaseNoFactorsOtherThanItselfIsClassifiedCorrectly() { | ||
#expect(try! classify(number: 1) == .deficient) | ||
} | ||
|
||
func testZeroIsRejectedAsItIsNotAPositiveInteger() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertThrowsError(try classify(number: 0)) { error in | ||
XCTAssertEqual(error as? ClassificationError, .invalidInput) | ||
@Test("Zero is rejected (as it is not a positive integer)", .enabled(if: RUNALL)) | ||
func testZeroIsRejectedAsItIsNotAPositiveInteger() { | ||
#expect(throws: ClassificationError.invalidInput) { | ||
try classify(number: 0) | ||
} | ||
} | ||
|
||
func testNegativeIntegerIsRejectedAsItIsNotAPositiveInteger() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertThrowsError(try classify(number: -1)) { error in | ||
XCTAssertEqual(error as? ClassificationError, .invalidInput) | ||
@Test("Negative integer is rejected (as it is not a positive integer)", .enabled(if: RUNALL)) | ||
func testNegativeIntegerIsRejectedAsItIsNotAPositiveInteger() { | ||
#expect(throws: ClassificationError.invalidInput) { | ||
try classify(number: -1) | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// swift-tools-version:5.3 | ||
// swift-tools-version:6.0 | ||
|
||
import PackageDescription | ||
|
||
|
Oops, something went wrong.