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

ex2 Clarification #7

Open
wants to merge 1 commit into
base: ex02
Choose a base branch
from
Open
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
20 changes: 11 additions & 9 deletions Tests/MKTKoansTests/ex02/Ex2Task.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,32 @@ import MKTCore
* Initialize an mutable property.
*/
func shouldInitializeMutableProperty() throws -> Int {
/* Create a variable equal to 2 and modify it to 3 */
return try Todo()
/* Create a variable 'a' equal to 2 and modify it to 3 */
return try Todo() // Return value of 'a'
}

/**
* Initialize an immutable property.
*/
func shouldInitializeImmutableProperty() throws -> Int {
/* Try to create a constant equal to 2 and modify it to 3 */
return try Todo()
/* Try to create a constant 'a' equal to 2 and modify it to 3 */
return try Todo() // Return value of 'a'
}

/**
* Read about Getters and Setters
*
* Add a custom setter for posX to expose posX as an Integer >=0 if _posX >=0 or -1
* Add a custom getter for posY to expose posY as an Integer >=0 if _posY >=0 or -1
* Read about https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Properties.html
*/
struct Position : Equatable {
private var _posX : Int
private var _posY : Int

var posX : Int = 0
// TODO Add a custom setter for posX to update _posX as an Integer >=0 (use -1 is setter value < 0)
// the getter should return the _posX
var posX : Int = 0

// TODO Add a custom getter for posY to expose posY as an Integer >=0 (use -1 is _poxY < 0)
// the setter should set the _posY
var posY : Int = 0

init(_ x: Int, _ y: Int) {
Expand Down Expand Up @@ -62,6 +64,6 @@ struct Pair<L,R> {
/**
* Add a specific method returning a pair
*/
func shouldReturnPairOfIdAndName(_ position: Position) throws -> Pair<Int, Int> {
func shouldReturnPairOfPosXAndPosY(_ position: Position) throws -> Pair<Int, Int> {
return try Todo()
}
2 changes: 1 addition & 1 deletion Tests/MKTKoansTests/ex02/Ex2Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Ex02Tests: XCTestCase {
}

func test03ShouldReturnAPair() throws {
let pair = try shouldReturnPairOfIdAndName(Position(1, 2))
let pair = try shouldReturnPairOfPosXAndPosY(Position(1, 2))
XCTAssertEqual(pair._0, 1)
XCTAssertEqual(pair._1, 2)
}
Expand Down