Skip to content

Instantly share code, notes, and snippets.

@kenmazaika
Created December 7, 2020 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenmazaika/dc9b384a488218a8721adcb02e19947b to your computer and use it in GitHub Desktop.
Save kenmazaika/dc9b384a488218a8721adcb02e19947b to your computer and use it in GitHub Desktop.
// String Functions
func substr(input: String, start: Int, count: Int) {
var substr = ""
for i in range(0, input.length) {
if(i >= start && i <= start + count - 1 ) {
substr = substr + input[i]
}
}
substr
}
// Assertion Library
func assert(message: String, expected: String, actual: String, verbose: Bool) {
if(expected != actual) {
println("FAILED: " + message)
println("> Expected: " + expected)
println("> Actual: " + actual)
false
}
else if(verbose) {
println("PASS: " + message)
println("> Expected: " + expected)
println("> Actual: " + actual)
true
}
true
}
// Unit Tests
// substr("hello world", 4, 4) == "o wo"
assert("substr - hello world - 4, 4",
"o wo",
substr("hello world", 4, 4),
true
)
@kenmazaika
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment