-
-
Notifications
You must be signed in to change notification settings - Fork 158
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 testing files
- Loading branch information
1 parent
30f8e4c
commit bb82bde
Showing
9 changed files
with
138 additions
and
173 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
13 changes: 10 additions & 3 deletions
13
exercises/concept/freelancer-rates/Sources/FreelancerRates/FreelancerRates.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,11 +1,18 @@ | ||
let hoursPerDay = 8 | ||
let daysPerMonth = 22 | ||
|
||
func dailyRateFrom(hourlyRate: Int) -> Double { | ||
fatalError("Please implement the dailyRateFrom(hourlyRate:) function") | ||
return Double(hourlyRate * hoursPerDay) | ||
} | ||
|
||
func monthlyRateFrom(hourlyRate: Int, withDiscount discount: Double) -> Double { | ||
fatalError("Please implement the monthlyRateFrom(hourlyRate:withDiscount:) function") | ||
let monthly = Double(hourlyRate * hoursPerDay * daysPerMonth) * (1.0 - (discount / 100)) | ||
return monthly.rounded() | ||
} | ||
|
||
func workdaysIn(budget: Double, hourlyRate: Int, withDiscount discount: Double) -> Double { | ||
fatalError("Please implement the workdaysIn(budget:hourlyRate:withDiscount:) function") | ||
let fullMonthlyRate = budget / (1.0 - (discount / 100)) | ||
let hours = fullMonthlyRate / Double(hourlyRate) | ||
let days = hours / Double(hoursPerDay) | ||
return days.rounded(.down) | ||
} |
83 changes: 39 additions & 44 deletions
83
exercises/concept/freelancer-rates/Tests/FreelancerRatesTests/FreelancerRatesTests.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,70 +1,65 @@ | ||
import XCTest | ||
import Testing | ||
import Foundation | ||
import Numerics | ||
|
||
@testable import FreelancerRates | ||
|
||
let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false | ||
let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false | ||
|
||
class TaskDailyRateFrom: XCTestCase { | ||
func testdailyRateFromFor60() { | ||
XCTAssertEqual(dailyRateFrom(hourlyRate: 60), 480.0, accuracy: 0.001) | ||
@Suite struct FreelancerRatesTests { | ||
@Test("Daily rate from hourly rate") | ||
func testTaskDailyRateFrom() { | ||
#expect(dailyRateFrom(hourlyRate: 60).isApproximatelyEqual(to: 480.0, relativeTolerance: 0.002)) | ||
} | ||
|
||
func testdailyRateFromFor16() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(dailyRateFrom(hourlyRate: 16), 128.0, accuracy: 0.001) | ||
@Test("Daily rate from hourly rate with 16 as rate", .enabled(if: RUNALL)) | ||
func testTaskDailyRateFromFor16() { | ||
#expect(dailyRateFrom(hourlyRate: 16).isApproximatelyEqual(to: 128.0, relativeTolerance: 0.002)) | ||
} | ||
|
||
func testdailyRateFromFor25() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(dailyRateFrom(hourlyRate: 25), 200.0, accuracy: 0.001) | ||
@Test("Daily rate from hourly rate with 25 as rate", .enabled(if: RUNALL)) | ||
func testTaskDailyRateFromFor25() { | ||
#expect(dailyRateFrom(hourlyRate: 25).isApproximatelyEqual(to: 200.0, relativeTolerance: 0.002)) | ||
} | ||
} | ||
|
||
class TaskMonthlyRateFrom: XCTestCase { | ||
func testmonthlyWithWholeResult() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(monthlyRateFrom(hourlyRate: 80, withDiscount: 50), 7040, accuracy: 0.001) | ||
@Test("Montly rate with whole result", .enabled(if: RUNALL)) | ||
func testmonthlyWithWholeResult() { | ||
#expect(monthlyRateFrom(hourlyRate: 80, withDiscount: 50).isApproximatelyEqual(to: 7040, relativeTolerance: 0.001)) | ||
} | ||
|
||
func testmonthlyRoundDown() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(monthlyRateFrom(hourlyRate: 77, withDiscount: 10.5), 12129, accuracy: 0.001) | ||
@Test("Montly rate round down", .enabled(if: RUNALL)) | ||
func testmonthlyRoundDown() { | ||
#expect(monthlyRateFrom(hourlyRate: 77, withDiscount: 10.5).isApproximatelyEqual(to: 12129, relativeTolerance: 0.001)) | ||
} | ||
|
||
func testmonthlyRoundUp() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(monthlyRateFrom(hourlyRate: 80, withDiscount: 10.5), 12602, accuracy: 0.001) | ||
@Test("Montly rate round up", .enabled(if: RUNALL)) | ||
func testmonthlyRoundUp() { | ||
#expect(monthlyRateFrom(hourlyRate: 80, withDiscount: 10.5).isApproximatelyEqual(to: 12602, relativeTolerance: 0.001)) | ||
} | ||
} | ||
|
||
class TaskWorkdaysIn: XCTestCase { | ||
func testworkdaysInSmallBudget() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual( | ||
workdaysIn(budget: 1000, hourlyRate: 50, withDiscount: 10), 2.0, accuracy: 0.001) | ||
|
||
@Test("Workdays in small budget", .enabled(if: RUNALL)) | ||
func testworkdaysInSmallBudget() { | ||
#expect(workdaysIn(budget: 1000, hourlyRate: 50, withDiscount: 10).isApproximatelyEqual(to: 2.0, relativeTolerance: 0.001)) | ||
} | ||
|
||
func testworkdaysInMediumBudget() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual( | ||
workdaysIn(budget: 5000, hourlyRate: 60, withDiscount: 10), 11.0, accuracy: 0.001) | ||
@Test("Workdays in medium budget", .enabled(if: RUNALL)) | ||
func testworkdaysInMediumBudget() { | ||
#expect(workdaysIn(budget: 5000, hourlyRate: 60, withDiscount: 10).isApproximatelyEqual(to: 11.0, relativeTolerance: 0.001)) | ||
} | ||
|
||
func testworkdaysLargebudget() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual( | ||
workdaysIn(budget: 25_000, hourlyRate: 80, withDiscount: 10), 43.0, accuracy: 0.001) | ||
@Test("Workdays large budget", .enabled(if: RUNALL)) | ||
func testworkdaysLargebudget() { | ||
#expect(workdaysIn(budget: 25_000, hourlyRate: 80, withDiscount: 10).isApproximatelyEqual(to: 43.0, relativeTolerance: 0.001)) | ||
} | ||
|
||
func testworkdaysShouldRound() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual( | ||
workdaysIn(budget: 20000, hourlyRate: 80, withDiscount: 11), 35.0, accuracy: 0.001) | ||
@Test("Workdays should round", .enabled(if: RUNALL)) | ||
func testworkdaysShouldRound() { | ||
#expect(workdaysIn(budget: 20000, hourlyRate: 80, withDiscount: 11).isApproximatelyEqual(to: 35.0, relativeTolerance: 0.001)) | ||
} | ||
|
||
func testworkdaysShouldNotRoundToNearstInteger() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual( | ||
workdaysIn(budget: 25_000, hourlyRate: 80, withDiscount: 11), 43.0, accuracy: 0.001) | ||
@Test("Workdays should not round to nearst integer", .enabled(if: RUNALL)) | ||
func testworkdaysShouldNotRoundToNearstInteger() { | ||
#expect(workdaysIn(budget: 25_000, hourlyRate: 80, withDiscount: 11).isApproximatelyEqual(to: 43.0, relativeTolerance: 0.001)) | ||
} | ||
} |
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
70 changes: 33 additions & 37 deletions
70
exercises/concept/lasagna/Tests/LasagnaTests/LasagnaTests.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,62 +1,58 @@ | ||
import XCTest | ||
import Testing | ||
import Foundation | ||
|
||
@testable import Lasagna | ||
|
||
let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false | ||
let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false | ||
|
||
class TaskExpectedMinutesInOvenTests: XCTestCase { | ||
@Suite struct LasagnaTests { | ||
@Test("Expected minutes in oven") | ||
func testExpectedMinutes() { | ||
XCTAssertEqual(expectedMinutesInOven, 40) | ||
#expect(expectedMinutesInOven == 40) | ||
} | ||
} | ||
|
||
class TaskRemainingMinutesInOven: XCTestCase { | ||
func testRemainingMinutes() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(remainingMinutesInOven(elapsedMinutes: 13), 27) | ||
@Test("Remaining minutes in oven", .enabled(if: RUNALL)) | ||
func testRemainingMinutes() { | ||
#expect(remainingMinutesInOven(elapsedMinutes: 13) == 27) | ||
} | ||
|
||
func testRemainingMinutesWhenDone() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(remainingMinutesInOven(elapsedMinutes: 40), 0) | ||
@Test("Remaining minutes in oven when done", .enabled(if: RUNALL)) | ||
func testRemainingMinutesWhenDone() { | ||
#expect(remainingMinutesInOven(elapsedMinutes: 40) == 0) | ||
} | ||
|
||
func testRemainingMinutesWhenLessThanOne() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(remainingMinutesInOven(elapsedMinutes: 39), 1) | ||
@Test("Remaining minutes in oven when less than one", .enabled(if: RUNALL)) | ||
func testRemainingMinutesWhenLessThanOne() { | ||
#expect(remainingMinutesInOven(elapsedMinutes: 39) == 1) | ||
} | ||
} | ||
|
||
class TaskPreparationTimeInMinutes: XCTestCase { | ||
func testPreparationMinutes() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(preparationTimeInMinutes(layers: 6), 12) | ||
@Test("Preparation time in minutes", .enabled(if: RUNALL)) | ||
func testPreparationMinutes() { | ||
#expect(preparationTimeInMinutes(layers: 6) == 12) | ||
} | ||
|
||
func testPreparationMinutesForOneLayer() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(preparationTimeInMinutes(layers: 1), 2) | ||
@Test("Preparation time in minutes for one layer", .enabled(if: RUNALL)) | ||
func testPreparationMinutesForOneLayer() { | ||
#expect(preparationTimeInMinutes(layers: 1) == 2) | ||
} | ||
|
||
func testPreparationMinutesForZeroLayers() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(preparationTimeInMinutes(layers: 0), 0) | ||
@Test("Preparation time in minutes for zero layers", .enabled(if: RUNALL)) | ||
func testPreparationMinutesForZeroLayers() { | ||
#expect(preparationTimeInMinutes(layers: 0) == 0) | ||
} | ||
} | ||
|
||
class TaskTotalTimeInMinutes: XCTestCase { | ||
func testTotalMinutes() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(totalTimeInMinutes(layers: 1, elapsedMinutes: 30), 32) | ||
@Test("Total time in minutes", .enabled(if: RUNALL)) | ||
func testTotalMinutes() { | ||
#expect(totalTimeInMinutes(layers: 1, elapsedMinutes: 30) == 32) | ||
} | ||
|
||
func testTotalMinutesWhenDone() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(totalTimeInMinutes(layers: 2, elapsedMinutes: 25), 29) | ||
@Test("Total time in minutes when done", .enabled(if: RUNALL)) | ||
func testTotalMinutesWhenDone() { | ||
#expect(totalTimeInMinutes(layers: 2, elapsedMinutes: 25) == 29) | ||
} | ||
|
||
func testTotalMinutesWhenLessThanOne() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(totalTimeInMinutes(layers: 4, elapsedMinutes: 8), 16) | ||
@Test("Total time in minutes when less than one", .enabled(if: RUNALL)) | ||
func testTotalMinutesWhenLessThanOne() { | ||
#expect(totalTimeInMinutes(layers: 4, elapsedMinutes: 8) == 16) | ||
} | ||
} |
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
Oops, something went wrong.