Skip to content

Instantly share code, notes, and snippets.

@up1
Last active October 8, 2015 09:28
Show Gist options
  • Save up1/645ee7e2b94d17c0fd68 to your computer and use it in GitHub Desktop.
Save up1/645ee7e2b94d17c0fd68 to your computer and use it in GitHub Desktop.
TDD Swift
class Employee {
private let id: Int
private let firstname: String
init(id: Int, firstname: String) {
self.id = id
self.firstname = firstname
}
}
class Employee {
private let id: Int
private let firstname: String
init(id: Int, firstname: String) {
self.id = id
self.firstname = firstname
}
func asDictionary() -> [String: AnyObject] {
return [String : AnyObject]()
}
}
public class Employee {
private let id: Int
private let firstname: String
init(id: Int, firstname: String) {
self.id = id
self.firstname = firstname
}
func asDictionary() -> [String: AnyObject] {
return [
"id": 1,
"firstname": "Somkiat"
]
}
}
public class Employee {
private let id: Int
private let firstname: String
init(id: Int, firstname: String) {
self.id = id
self.firstname = firstname
}
func asDictionary() -> [String: AnyObject] {
return [
"id": self.id,
"firstname": self.firstname
]
}
}
class EmployeeTest: XCTestCase {
func testCreateNewEmployee() {
let employee = Employee(id: 1, firstname: "Somkiat")
}
}
class EmployeeTest: XCTestCase {
func testCreateNewEmployee() {
let employee = Employee(id: 1, firstname: "Somkiat")
let dictionary = employee.asDictionary()
}
}
class EmployeeTest: XCTestCase {
func testCreateNewEmployee() {
let employee = Employee(id: 1, firstname: "Somkiat")
let dictionary = employee.asDictionary()
XCTAssertEqual(dictionary["id"] as? Int, 1)
XCTAssertEqual(dictionary["firstname"] as? String, "Somkiat")
}
}
class EmployeeTest: XCTestCase {
func testCreateNewEmployee() {
let employee = Employee(id: 1, firstname: "Somkiat")
let dictionary = employee.asDictionary()
XCTAssertEqual(dictionary["id"] as? Int, 1)
XCTAssertEqual(dictionary["firstname"] as? String, "Somkiat")
}
func testCreateNewEmployeeWithId2() {
let employee = Employee(id: 2, firstname: "Up1")
let dictionary = employee.asDictionary()
XCTAssertEqual(dictionary["id"] as? Int, 2)
XCTAssertEqual(dictionary["firstname"] as? String, "Up1")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment