Last active
October 4, 2018 02:51
-
-
Save hmhmsh/1214a7d4b2c8507acc53cbb3d1329602 to your computer and use it in GitHub Desktop.
いまさらながらSwiftでTDDをやってみた ref: https://qiita.com/hmhmsh/items/842e795d4b2a41556b5b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment