Skip to content

Instantly share code, notes, and snippets.

@bannzai
Created January 15, 2020 09:24
Show Gist options
  • Save bannzai/c5d62f927fa521a7fae076eac1156418 to your computer and use it in GitHub Desktop.
Save bannzai/c5d62f927fa521a7fae076eac1156418 to your computer and use it in GitHub Desktop.
ロマンが無い書き方
typealias InputAndExpected = [String: String]
let x: InputAndExpected = [
"11": "11.0",
"11.0": "11.0",
"11.01": "11.01",
"11.1": "11.1",
"11.10": "11.10",
"11.11": "11.11"
]
func convert(input: String) -> String {
input.contains(".") ? input : input + ".0"
}
func isValid(input: String) -> Bool {
Float(input) != nil
}
for (key, value) in x {
let v = convert(input: key)
if value != v {
fatalError("failure \(key), value: \(value), v: \(v)")
}
if !isValid(input: v) {
fatalError("failure \(key), value: \(value), v: \(v)")
}
}
print("Finish")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment