いまさらながらSwiftでTDDをやってみた ref: https://qiita.com/hmhmsh/items/842e795d4b2a41556b5b
class TodoList {
var list = Array<String>()
func isEmpty() -> Bool {
return list.count == 0
}
func append(_ todo: String) {
list.append(todo)
}
func getTop() throws -> String {
do {
try emptyCheck()
}
return list[0]
}
func size() -> Int {
return list.count
}
func removeTop() throws {
do {
try emptyCheck()
}
list.remove(at: 0)
}
func emptyCheck() throws {
if isEmpty() {
throw NSError(domain: "error", code: -1, userInfo: nil)
}
}
}
class TodoList {
var list = Array<String>()
func isEmpty() -> Bool {
return list.count == 0
}
func append(_ todo: String) {
list.append(todo)
}
func getTop() throws -> String {
do {
try emptyCheck()
}
return list[0]
}
func size() -> Int {
return list.count
}
func removeTop() throws {
do {
try emptyCheck()
}
list.remove(at: 0)
}
func emptyCheck() throws {
if isEmpty() {
throw NSError(domain: "error", code: -1, userInfo: nil)
}
}
}