Created
December 7, 2020 18:22
-
-
Save kenmazaika/dc9b384a488218a8721adcb02e19947b to your computer and use it in GitHub Desktop.
This file contains 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
// 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 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
kengorab/abra-lang@333c9b4