Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Swift 6]: Update concept exercises batch 1 #807

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion exercises/concept/freelancer-rates/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
".meta/Sources/FreelancerRates/FreelancerRatesExemplar.swift"
]
},
"language_versions": ">=5.0",
"language_versions": ">=6.0",
"forked_from": [
"javascript/freelancer-rates"
],
Expand Down
5 changes: 3 additions & 2 deletions exercises/concept/freelancer-rates/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.3
// swift-tools-version:6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -14,6 +14,7 @@ let package = Package(
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/apple/swift-numerics", from: "1.0.2"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand All @@ -23,6 +24,6 @@ let package = Package(
dependencies: []),
.testTarget(
name: "FreelancerRatesTests",
dependencies: ["FreelancerRates"]),
dependencies: ["FreelancerRates", .product(name: "Numerics", package: "swift-numerics"),]),
]
)
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)
}
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))
}
}
2 changes: 1 addition & 1 deletion exercises/concept/lasagna/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
".meta/Sources/Lasagna/LasagnaExemplar.swift"
]
},
"language_versions": ">=5.0",
"language_versions": ">=6.0",
"forked_from": [
"fsharp/lucians-luscious-lasagna"
],
Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/lasagna/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.3
// swift-tools-version:6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down
70 changes: 33 additions & 37 deletions exercises/concept/lasagna/Tests/LasagnaTests/LasagnaTests.swift
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)
}
}
2 changes: 1 addition & 1 deletion exercises/concept/wings-quest/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.3
// swift-tools-version:6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down
Loading
Loading