-
-
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.
Merge branch 'update-exercise-batch-17' into main
- Loading branch information
Showing
14 changed files
with
249 additions
and
210 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,17 +1,20 @@ | ||
import XCTest | ||
import Testing | ||
import Foundation | ||
import Numerics | ||
@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 -%} | ||
func test{{case.description |camelCase }}() { | ||
let age = SpaceAge({{case.input.seconds}}) | ||
XCTAssertEqual(age.on{{case.input.planet |camelCase}}, {{case.expected | round:2 }}, accuracy: 0.02) | ||
#expect(age.on{{case.input.planet |camelCase}}.isApproximatelyEqual(to: {{case.expected | round:2 }}, relativeTolerance: 0.03)) | ||
} | ||
{% 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
15 changes: 14 additions & 1 deletion
15
exercises/practice/space-age/Sources/SpaceAge/SpaceAge.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,3 +1,16 @@ | ||
class SpaceAge { | ||
// Write your code for the 'SpaceAge' exercise in this file. | ||
var seconds: Float = 0 | ||
|
||
var onMercury: Float { return ((seconds / 7_600_530.24) * 100).rounded() / 100 } | ||
var onVenus: Float { return ((seconds / 19_413_907.2) * 100).rounded() / 100 } | ||
var onEarth: Float { return ((seconds / 31_558_149.76) * 100).rounded() / 100 } | ||
var onMars: Float { return ((seconds / 59_354_294.4) * 100).rounded() / 100 } | ||
var onJupiter: Float { return ((seconds / 374_335_776.0) * 100).rounded() / 100 } | ||
var onSaturn: Float { return ((seconds / 929_596_608.0) * 100).rounded() / 100 } | ||
var onUranus: Float { return ((seconds / 2_661_041_808.0) * 100).rounded() / 100 } | ||
var onNeptune: Float { return ((seconds / 5_200_418_592.0) * 100).rounded() / 100 } | ||
|
||
init(_ input: Float) { | ||
self.seconds = input | ||
} | ||
} |
54 changes: 29 additions & 25 deletions
54
exercises/practice/space-age/Tests/SpaceAgeTests/SpaceAgeTests.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,54 +1,58 @@ | ||
import XCTest | ||
import Foundation | ||
import Numerics | ||
import Testing | ||
|
||
@testable import SpaceAge | ||
|
||
class SpaceAgeTests: XCTestCase { | ||
let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false | ||
let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false | ||
|
||
@Suite struct SpaceAgeTests { | ||
|
||
@Test("age on Earth") | ||
func testAgeOnEarth() { | ||
let age = SpaceAge(1_000_000_000) | ||
XCTAssertEqual(age.onEarth, 31.69, accuracy: 0.02) | ||
#expect(age.onEarth.isApproximatelyEqual(to: 31.69, relativeTolerance: 0.03)) | ||
} | ||
|
||
func testAgeOnMercury() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("age on Mercury", .enabled(if: RUNALL)) | ||
func testAgeOnMercury() { | ||
let age = SpaceAge(2_134_835_688) | ||
XCTAssertEqual(age.onMercury, 280.88, accuracy: 0.02) | ||
#expect(age.onMercury.isApproximatelyEqual(to: 280.88, relativeTolerance: 0.03)) | ||
} | ||
|
||
func testAgeOnVenus() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("age on Venus", .enabled(if: RUNALL)) | ||
func testAgeOnVenus() { | ||
let age = SpaceAge(189_839_836) | ||
XCTAssertEqual(age.onVenus, 9.78, accuracy: 0.02) | ||
#expect(age.onVenus.isApproximatelyEqual(to: 9.78, relativeTolerance: 0.03)) | ||
} | ||
|
||
func testAgeOnMars() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("age on Mars", .enabled(if: RUNALL)) | ||
func testAgeOnMars() { | ||
let age = SpaceAge(2_129_871_239) | ||
XCTAssertEqual(age.onMars, 35.88, accuracy: 0.02) | ||
#expect(age.onMars.isApproximatelyEqual(to: 35.88, relativeTolerance: 0.03)) | ||
} | ||
|
||
func testAgeOnJupiter() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("age on Jupiter", .enabled(if: RUNALL)) | ||
func testAgeOnJupiter() { | ||
let age = SpaceAge(901_876_382) | ||
XCTAssertEqual(age.onJupiter, 2.41, accuracy: 0.02) | ||
#expect(age.onJupiter.isApproximatelyEqual(to: 2.41, relativeTolerance: 0.03)) | ||
} | ||
|
||
func testAgeOnSaturn() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("age on Saturn", .enabled(if: RUNALL)) | ||
func testAgeOnSaturn() { | ||
let age = SpaceAge(2_000_000_000) | ||
XCTAssertEqual(age.onSaturn, 2.15, accuracy: 0.02) | ||
#expect(age.onSaturn.isApproximatelyEqual(to: 2.15, relativeTolerance: 0.03)) | ||
} | ||
|
||
func testAgeOnUranus() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("age on Uranus", .enabled(if: RUNALL)) | ||
func testAgeOnUranus() { | ||
let age = SpaceAge(1_210_123_456) | ||
XCTAssertEqual(age.onUranus, 0.46, accuracy: 0.02) | ||
#expect(age.onUranus.isApproximatelyEqual(to: 0.46, relativeTolerance: 0.03)) | ||
} | ||
|
||
func testAgeOnNeptune() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("age on Neptune", .enabled(if: RUNALL)) | ||
func testAgeOnNeptune() { | ||
let age = SpaceAge(1_821_023_456) | ||
XCTAssertEqual(age.onNeptune, 0.35, accuracy: 0.02) | ||
#expect(age.onNeptune.isApproximatelyEqual(to: 0.35, relativeTolerance: 0.03)) | ||
} | ||
} |
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 | ||
|
||
|
89 changes: 46 additions & 43 deletions
89
exercises/practice/strain/Tests/StrainTests/StrainTests.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,108 +1,111 @@ | ||
import XCTest | ||
import Foundation | ||
import Testing | ||
|
||
@testable import Strain | ||
|
||
class StrainTests: XCTestCase { | ||
let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false | ||
let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false | ||
|
||
@Suite struct StrainTests { | ||
|
||
@Test("keep on empty list returns empty list") | ||
func testKeepOnEmptyListReturnsEmptyList() { | ||
let input: [Int] = [] | ||
let expected: [Int] = [] | ||
XCTAssertEqual(input.keep { x in true }, expected) | ||
#expect(input.keep { x in true } == expected) | ||
} | ||
|
||
func testKeepsEverything() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("keeps everything", .enabled(if: RUNALL)) | ||
func testKeepsEverything() { | ||
let input = [1, 3, 5] | ||
let expected = [1, 3, 5] | ||
XCTAssertEqual(input.keep { x in true }, expected) | ||
#expect(input.keep { x in true } == expected) | ||
} | ||
|
||
func testKeepsNothing() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("keeps nothing", .enabled(if: RUNALL)) | ||
func testKeepsNothing() { | ||
let input = [1, 3, 5] | ||
let expected: [Int] = [] | ||
XCTAssertEqual(input.keep { x in false }, expected) | ||
#expect(input.keep { x in false } == expected) | ||
} | ||
|
||
func testKeepsFirstAndLast() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("keeps first and last", .enabled(if: RUNALL)) | ||
func testKeepsFirstAndLast() { | ||
let input = [1, 2, 3] | ||
let expected = [1, 3] | ||
XCTAssertEqual(input.keep { x in x % 2 == 1 }, expected) | ||
#expect(input.keep { x in x % 2 == 1 } == expected) | ||
} | ||
|
||
func testKeepsNeitherFirstNorLast() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("keeps neither first nor last", .enabled(if: RUNALL)) | ||
func testKeepsNeitherFirstNorLast() { | ||
let input = [1, 2, 3] | ||
let expected = [2] | ||
XCTAssertEqual(input.keep { x in x % 2 == 0 }, expected) | ||
#expect(input.keep { x in x % 2 == 0 } == expected) | ||
} | ||
|
||
func testKeepsStrings() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("keeps strings", .enabled(if: RUNALL)) | ||
func testKeepsStrings() { | ||
let input = ["apple", "zebra", "banana", "zombies", "cherimoya", "zealot"] | ||
let expected = ["zebra", "zombies", "zealot"] | ||
XCTAssertEqual(input.keep { x in x.starts(with: "z") }, expected) | ||
#expect(input.keep { x in x.starts(with: "z") } == expected) | ||
} | ||
|
||
func testKeepsLists() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("keeps lists", .enabled(if: RUNALL)) | ||
func testKeepsLists() { | ||
let input = [ | ||
[1, 2, 3], [5, 5, 5], [5, 1, 2], [2, 1, 2], [1, 5, 2], [2, 2, 1], [1, 2, 5], | ||
] | ||
let expected = [[5, 5, 5], [5, 1, 2], [1, 5, 2], [1, 2, 5]] | ||
XCTAssertEqual(input.keep { x in x.contains(5) }, expected) | ||
#expect(input.keep { x in x.contains(5) } == expected) | ||
} | ||
|
||
func testDiscardOnEmptyListReturnsEmptyList() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("discard on empty list returns empty list", .enabled(if: RUNALL)) | ||
func testDiscardOnEmptyListReturnsEmptyList() { | ||
let input: [Int] = [] | ||
let expected: [Int] = [] | ||
XCTAssertEqual(input.discard { x in true }, expected) | ||
#expect(input.discard { x in true } == expected) | ||
} | ||
|
||
func testDiscardsEverything() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("discards everything", .enabled(if: RUNALL)) | ||
func testDiscardsEverything() { | ||
let input = [1, 3, 5] | ||
let expected: [Int] = [] | ||
XCTAssertEqual(input.discard { x in true }, expected) | ||
#expect(input.discard { x in true } == expected) | ||
} | ||
|
||
func testDiscardsNothing() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("discards nothing", .enabled(if: RUNALL)) | ||
func testDiscardsNothing() { | ||
let input = [1, 3, 5] | ||
let expected = [1, 3, 5] | ||
XCTAssertEqual(input.discard { x in false }, expected) | ||
#expect(input.discard { x in false } == expected) | ||
} | ||
|
||
func testDiscardsFirstAndLast() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("discards first and last", .enabled(if: RUNALL)) | ||
func testDiscardsFirstAndLast() { | ||
let input = [1, 2, 3] | ||
let expected = [2] | ||
XCTAssertEqual(input.discard { x in x % 2 == 1 }, expected) | ||
#expect(input.discard { x in x % 2 == 1 } == expected) | ||
} | ||
|
||
func testDiscardsNeitherFirstNorLast() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("discards neither first nor last", .enabled(if: RUNALL)) | ||
func testDiscardsNeitherFirstNorLast() { | ||
let input = [1, 2, 3] | ||
let expected = [1, 3] | ||
XCTAssertEqual(input.discard { x in x % 2 == 0 }, expected) | ||
#expect(input.discard { x in x % 2 == 0 } == expected) | ||
} | ||
|
||
func testDiscardsStrings() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("discards strings", .enabled(if: RUNALL)) | ||
func testDiscardsStrings() { | ||
let input = ["apple", "zebra", "banana", "zombies", "cherimoya", "zealot"] | ||
let expected = ["apple", "banana", "cherimoya"] | ||
XCTAssertEqual(input.discard { x in x.starts(with: "z") }, expected) | ||
#expect(input.discard { x in x.starts(with: "z") } == expected) | ||
} | ||
|
||
func testDiscardsLists() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
@Test("discards lists", .enabled(if: RUNALL)) | ||
func testDiscardsLists() { | ||
let input = [ | ||
[1, 2, 3], [5, 5, 5], [5, 1, 2], [2, 1, 2], [1, 5, 2], [2, 2, 1], [1, 2, 5], | ||
] | ||
let expected = [[1, 2, 3], [2, 1, 2], [2, 2, 1]] | ||
XCTAssertEqual(input.discard { x in x.contains(5) }, expected) | ||
#expect(input.discard { x in x.contains(5) } == expected) | ||
} | ||
} |
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,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(.{{case.expected}}, classifier(listOne: {{case.input.listOne}}, listTwo: {{case.input.listTwo}})) | ||
func test{{case.description |camelCase }}() { | ||
#expect(.{{case.expected}} == classifier(listOne: {{case.input.listOne}}, listTwo: {{case.input.listTwo}})) | ||
} | ||
{% 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 | ||
|
||
|
Oops, something went wrong.