Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"

@Test("returns a bird count list with the corrected values", .enabled(if: RUNALL))
func testFixBirdCountLog() {
var birdCount = [3, 0, 5, 1, 0, 4, 1, 0, 3, 4, 3, 0]
let birdCount = [3, 0, 5, 1, 0, 4, 1, 0, 3, 4, 3, 0]
let expected = [4, 0, 6, 1, 1, 4, 2, 0, 4, 4, 4, 0]
#expect(fixBirdCountLog(birdCount) == expected)
}

@Test("works for a short bird count list", .enabled(if: RUNALL))
func testFixBirdCountLogShort() {
var birdCount = [4, 2]
let birdCount = [4, 2]
let expected = [5, 2]
#expect(fixBirdCountLog(birdCount) == expected)
}

@Test("works for a long bird count list", .enabled(if: RUNALL))
func testFixBirdCountLogLong() {
var birdCount = [2, 8, 4, 1, 3, 5, 0, 4, 1, 6, 0, 3, 0, 1, 5, 4, 1, 1, 2, 6]
let birdCount = [2, 8, 4, 1, 3, 5, 0, 4, 1, 6, 0, 3, 0, 1, 5, 4, 1, 1, 2, 6]
let expected = [3, 8, 5, 1, 4, 5, 1, 4, 2, 6, 1, 3, 1, 1, 6, 4, 2, 1, 3, 6]
#expect(fixBirdCountLog(birdCount) == expected)
}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/grade-school/.meta/template.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"
@Test("{{case.description}}", .enabled(if: RUNALL))
{% endif -%}
func test{{case.description |camelCase }}() {
var school = GradeSchool()
let school = GradeSchool()
{%- if case.property == "add" %}
{% for student in case.input.students -%}
{%- if case.expected[forloop.counter0] %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"

@Test("Roster is empty when no student is added")
func testRosterIsEmptyWhenNoStudentIsAdded() {
var school = GradeSchool()
let school = GradeSchool()

#expect(school.roster() == [])
}

@Test("Add a student", .enabled(if: RUNALL))
func testAddAStudent() {
var school = GradeSchool()
let school = GradeSchool()

#expect(school.addStudent("Aimee", grade: 2))
}

@Test("Student is added to the roster", .enabled(if: RUNALL))
func testStudentIsAddedToTheRoster() {
var school = GradeSchool()
let school = GradeSchool()
school.addStudent("Aimee", grade: 2)

#expect(school.roster() == ["Aimee"])
}

@Test("Adding multiple students in the same grade in the roster", .enabled(if: RUNALL))
func testAddingMultipleStudentsInTheSameGradeInTheRoster() {
var school = GradeSchool()
let school = GradeSchool()

#expect(school.addStudent("Blair", grade: 2))
#expect(school.addStudent("James", grade: 2))
Expand All @@ -40,7 +40,7 @@ let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"

@Test("Multiple students in the same grade are added to the roster", .enabled(if: RUNALL))
func testMultipleStudentsInTheSameGradeAreAddedToTheRoster() {
var school = GradeSchool()
let school = GradeSchool()
school.addStudent("Blair", grade: 2)
school.addStudent("James", grade: 2)
school.addStudent("Paul", grade: 2)
Expand All @@ -50,7 +50,7 @@ let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"

@Test("Cannot add student to same grade in the roster more than once", .enabled(if: RUNALL))
func testCannotAddStudentToSameGradeInTheRosterMoreThanOnce() {
var school = GradeSchool()
let school = GradeSchool()

#expect(school.addStudent("Blair", grade: 2))
#expect(school.addStudent("James", grade: 2))
Expand All @@ -60,7 +60,7 @@ let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"

@Test("Student not added to same grade in the roster more than once", .enabled(if: RUNALL))
func testStudentNotAddedToSameGradeInTheRosterMoreThanOnce() {
var school = GradeSchool()
let school = GradeSchool()
school.addStudent("Blair", grade: 2)
school.addStudent("James", grade: 2)
school.addStudent("James", grade: 2)
Expand All @@ -71,15 +71,15 @@ let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"

@Test("Adding students in multiple grades", .enabled(if: RUNALL))
func testAddingStudentsInMultipleGrades() {
var school = GradeSchool()
let school = GradeSchool()

#expect(school.addStudent("Chelsea", grade: 3))
#expect(school.addStudent("Logan", grade: 7))
}

@Test("Students in multiple grades are added to the roster", .enabled(if: RUNALL))
func testStudentsInMultipleGradesAreAddedToTheRoster() {
var school = GradeSchool()
let school = GradeSchool()
school.addStudent("Chelsea", grade: 3)
school.addStudent("Logan", grade: 7)

Expand All @@ -88,7 +88,7 @@ let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"

@Test("Cannot add same student to multiple grades in the roster", .enabled(if: RUNALL))
func testCannotAddSameStudentToMultipleGradesInTheRoster() {
var school = GradeSchool()
let school = GradeSchool()

#expect(school.addStudent("Blair", grade: 2))
#expect(school.addStudent("James", grade: 2))
Expand All @@ -98,7 +98,7 @@ let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"

@Test("Student not added to multiple grades in the roster", .enabled(if: RUNALL))
func testStudentNotAddedToMultipleGradesInTheRoster() {
var school = GradeSchool()
let school = GradeSchool()
school.addStudent("Blair", grade: 2)
school.addStudent("James", grade: 2)
school.addStudent("James", grade: 3)
Expand All @@ -109,7 +109,7 @@ let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"

@Test("Students are sorted by grades in the roster", .enabled(if: RUNALL))
func testStudentsAreSortedByGradesInTheRoster() {
var school = GradeSchool()
let school = GradeSchool()
school.addStudent("Jim", grade: 3)
school.addStudent("Peter", grade: 2)
school.addStudent("Anna", grade: 1)
Expand All @@ -119,7 +119,7 @@ let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"

@Test("Students are sorted by name in the roster", .enabled(if: RUNALL))
func testStudentsAreSortedByNameInTheRoster() {
var school = GradeSchool()
let school = GradeSchool()
school.addStudent("Peter", grade: 2)
school.addStudent("Zoe", grade: 2)
school.addStudent("Alex", grade: 2)
Expand All @@ -129,7 +129,7 @@ let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"

@Test("Students are sorted by grades and then by name in the roster", .enabled(if: RUNALL))
func testStudentsAreSortedByGradesAndThenByNameInTheRoster() {
var school = GradeSchool()
let school = GradeSchool()
school.addStudent("Peter", grade: 2)
school.addStudent("Anna", grade: 1)
school.addStudent("Barb", grade: 1)
Expand All @@ -143,14 +143,14 @@ let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"

@Test("Grade is empty if no students in the roster", .enabled(if: RUNALL))
func testGradeIsEmptyIfNoStudentsInTheRoster() {
var school = GradeSchool()
let school = GradeSchool()

#expect(school.studentsInGrade(1) == [])
}

@Test("Grade is empty if no students in that grade", .enabled(if: RUNALL))
func testGradeIsEmptyIfNoStudentsInThatGrade() {
var school = GradeSchool()
let school = GradeSchool()
school.addStudent("Peter", grade: 2)
school.addStudent("Zoe", grade: 2)
school.addStudent("Alex", grade: 2)
Expand All @@ -161,7 +161,7 @@ let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"

@Test("Student not added to same grade more than once", .enabled(if: RUNALL))
func testStudentNotAddedToSameGradeMoreThanOnce() {
var school = GradeSchool()
let school = GradeSchool()
school.addStudent("Blair", grade: 2)
school.addStudent("James", grade: 2)
school.addStudent("James", grade: 2)
Expand All @@ -172,7 +172,7 @@ let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"

@Test("Student not added to multiple grades", .enabled(if: RUNALL))
func testStudentNotAddedToMultipleGrades() {
var school = GradeSchool()
let school = GradeSchool()
school.addStudent("Blair", grade: 2)
school.addStudent("James", grade: 2)
school.addStudent("James", grade: 3)
Expand All @@ -183,7 +183,7 @@ let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"

@Test("Student not added to other grade for multiple grades", .enabled(if: RUNALL))
func testStudentNotAddedToOtherGradeForMultipleGrades() {
var school = GradeSchool()
let school = GradeSchool()
school.addStudent("Blair", grade: 2)
school.addStudent("James", grade: 2)
school.addStudent("James", grade: 3)
Expand All @@ -194,7 +194,7 @@ let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"

@Test("Students are sorted by name in a grade", .enabled(if: RUNALL))
func testStudentsAreSortedByNameInAGrade() {
var school = GradeSchool()
let school = GradeSchool()
school.addStudent("Franklin", grade: 5)
school.addStudent("Bradley", grade: 5)
school.addStudent("Jeff", grade: 1)
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/grains/.meta/template.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"
{%- else %}
@Test("{{subCases.description}}", .enabled(if: RUNALL))
func test{{subCases.description |camelCase }}{{ forloop.outer.counter }}() {
#expect(try! Grains.total == {{case.expected}})
#expect(Grains.total == {{case.expected}})
}
{%- endif %}
{% endfor -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"

@Test("", .enabled(if: RUNALL))
func test2() {
#expect(try! Grains.total == 18_446_744_073_709_551_615)
#expect(Grains.total == 18_446_744_073_709_551_615)
}
}
2 changes: 1 addition & 1 deletion exercises/practice/robot-simulator/.meta/template.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"
@Test("{{subCases.description}}", .enabled(if: RUNALL))
{%- endif %}
func test{{subCases.description |camelCase }}{{ forloop.outer.counter }}() {
var robot = SimulatedRobot(x: {{subCases.input.position.x}}, y: {{subCases.input.position.y}}, bearing: .{{subCases.input.direction}})
let robot = SimulatedRobot(x: {{subCases.input.position.x}}, y: {{subCases.input.position.y}}, bearing: .{{subCases.input.direction}})
robot.move(commands: "{{subCases.input.instructions}}")
let state = robot.state
#expect(state.x == {{subCases.expected.position.x}} && state.y == {{subCases.expected.position.y}} && state.bearing == .{{subCases.expected.direction}})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,143 +9,143 @@ let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"

@Test("at origin facing north")
func testAtOriginFacingNorth1() {
var robot = SimulatedRobot(x: 0, y: 0, bearing: .north)
let robot = SimulatedRobot(x: 0, y: 0, bearing: .north)
robot.move(commands: "")
let state = robot.state
#expect(state.x == 0 && state.y == 0 && state.bearing == .north)
}

@Test("at negative position facing south", .enabled(if: RUNALL))
func testAtNegativePositionFacingSouth1() {
var robot = SimulatedRobot(x: -1, y: -1, bearing: .south)
let robot = SimulatedRobot(x: -1, y: -1, bearing: .south)
robot.move(commands: "")
let state = robot.state
#expect(state.x == -1 && state.y == -1 && state.bearing == .south)
}

@Test("changes north to east", .enabled(if: RUNALL))
func testChangesNorthToEast2() {
var robot = SimulatedRobot(x: 0, y: 0, bearing: .north)
let robot = SimulatedRobot(x: 0, y: 0, bearing: .north)
robot.move(commands: "R")
let state = robot.state
#expect(state.x == 0 && state.y == 0 && state.bearing == .east)
}

@Test("changes east to south", .enabled(if: RUNALL))
func testChangesEastToSouth2() {
var robot = SimulatedRobot(x: 0, y: 0, bearing: .east)
let robot = SimulatedRobot(x: 0, y: 0, bearing: .east)
robot.move(commands: "R")
let state = robot.state
#expect(state.x == 0 && state.y == 0 && state.bearing == .south)
}

@Test("changes south to west", .enabled(if: RUNALL))
func testChangesSouthToWest2() {
var robot = SimulatedRobot(x: 0, y: 0, bearing: .south)
let robot = SimulatedRobot(x: 0, y: 0, bearing: .south)
robot.move(commands: "R")
let state = robot.state
#expect(state.x == 0 && state.y == 0 && state.bearing == .west)
}

@Test("changes west to north", .enabled(if: RUNALL))
func testChangesWestToNorth2() {
var robot = SimulatedRobot(x: 0, y: 0, bearing: .west)
let robot = SimulatedRobot(x: 0, y: 0, bearing: .west)
robot.move(commands: "R")
let state = robot.state
#expect(state.x == 0 && state.y == 0 && state.bearing == .north)
}

@Test("changes north to west", .enabled(if: RUNALL))
func testChangesNorthToWest3() {
var robot = SimulatedRobot(x: 0, y: 0, bearing: .north)
let robot = SimulatedRobot(x: 0, y: 0, bearing: .north)
robot.move(commands: "L")
let state = robot.state
#expect(state.x == 0 && state.y == 0 && state.bearing == .west)
}

@Test("changes west to south", .enabled(if: RUNALL))
func testChangesWestToSouth3() {
var robot = SimulatedRobot(x: 0, y: 0, bearing: .west)
let robot = SimulatedRobot(x: 0, y: 0, bearing: .west)
robot.move(commands: "L")
let state = robot.state
#expect(state.x == 0 && state.y == 0 && state.bearing == .south)
}

@Test("changes south to east", .enabled(if: RUNALL))
func testChangesSouthToEast3() {
var robot = SimulatedRobot(x: 0, y: 0, bearing: .south)
let robot = SimulatedRobot(x: 0, y: 0, bearing: .south)
robot.move(commands: "L")
let state = robot.state
#expect(state.x == 0 && state.y == 0 && state.bearing == .east)
}

@Test("changes east to north", .enabled(if: RUNALL))
func testChangesEastToNorth3() {
var robot = SimulatedRobot(x: 0, y: 0, bearing: .east)
let robot = SimulatedRobot(x: 0, y: 0, bearing: .east)
robot.move(commands: "L")
let state = robot.state
#expect(state.x == 0 && state.y == 0 && state.bearing == .north)
}

@Test("facing north increments Y", .enabled(if: RUNALL))
func testFacingNorthIncrementsY4() {
var robot = SimulatedRobot(x: 0, y: 0, bearing: .north)
let robot = SimulatedRobot(x: 0, y: 0, bearing: .north)
robot.move(commands: "A")
let state = robot.state
#expect(state.x == 0 && state.y == 1 && state.bearing == .north)
}

@Test("facing south decrements Y", .enabled(if: RUNALL))
func testFacingSouthDecrementsY4() {
var robot = SimulatedRobot(x: 0, y: 0, bearing: .south)
let robot = SimulatedRobot(x: 0, y: 0, bearing: .south)
robot.move(commands: "A")
let state = robot.state
#expect(state.x == 0 && state.y == -1 && state.bearing == .south)
}

@Test("facing east increments X", .enabled(if: RUNALL))
func testFacingEastIncrementsX4() {
var robot = SimulatedRobot(x: 0, y: 0, bearing: .east)
let robot = SimulatedRobot(x: 0, y: 0, bearing: .east)
robot.move(commands: "A")
let state = robot.state
#expect(state.x == 1 && state.y == 0 && state.bearing == .east)
}

@Test("facing west decrements X", .enabled(if: RUNALL))
func testFacingWestDecrementsX4() {
var robot = SimulatedRobot(x: 0, y: 0, bearing: .west)
let robot = SimulatedRobot(x: 0, y: 0, bearing: .west)
robot.move(commands: "A")
let state = robot.state
#expect(state.x == -1 && state.y == 0 && state.bearing == .west)
}

@Test("moving east and north from README", .enabled(if: RUNALL))
func testMovingEastAndNorthFromReadme5() {
var robot = SimulatedRobot(x: 7, y: 3, bearing: .north)
let robot = SimulatedRobot(x: 7, y: 3, bearing: .north)
robot.move(commands: "RAALAL")
let state = robot.state
#expect(state.x == 9 && state.y == 4 && state.bearing == .west)
}

@Test("moving west and north", .enabled(if: RUNALL))
func testMovingWestAndNorth5() {
var robot = SimulatedRobot(x: 0, y: 0, bearing: .north)
let robot = SimulatedRobot(x: 0, y: 0, bearing: .north)
robot.move(commands: "LAAARALA")
let state = robot.state
#expect(state.x == -4 && state.y == 1 && state.bearing == .west)
}

@Test("moving west and south", .enabled(if: RUNALL))
func testMovingWestAndSouth5() {
var robot = SimulatedRobot(x: 2, y: -7, bearing: .east)
let robot = SimulatedRobot(x: 2, y: -7, bearing: .east)
robot.move(commands: "RRAAAAALA")
let state = robot.state
#expect(state.x == -3 && state.y == -8 && state.bearing == .south)
}

@Test("moving east and north", .enabled(if: RUNALL))
func testMovingEastAndNorth5() {
var robot = SimulatedRobot(x: 8, y: 4, bearing: .south)
let robot = SimulatedRobot(x: 8, y: 4, bearing: .south)
robot.move(commands: "LAAARRRALLLL")
let state = robot.state
#expect(state.x == 11 && state.y == 5 && state.bearing == .north)
Expand Down