Skip to content

Instantly share code, notes, and snippets.

@harsh183
Created January 25, 2020 23:42
Show Gist options
  • Save harsh183/10e879a31a4008aa4f741d34ecd36b9e to your computer and use it in GitHub Desktop.
Save harsh183/10e879a31a4008aa4f741d34ecd36b9e to your computer and use it in GitHub Desktop.
A very hacky quick test thingy I wrote because I did not want to deal with libraries and imports but show people basic exercises. I'm pretty sure it'll fall apart on basic security.
fun main() {
println("Running stuff")
case("5 + 10", weight=5) {
var x = 15;
x = x + 10
add(5, 10) == x
}
case("10 + 15") {
add(10, 15) == 25
}
case("Negative") {
add(10, -15) == -5
}
case("Zero", 10) {
add(10, 0) == 10
}
}
fun case(name: String, weight: Int = 1, code: () -> Boolean): Boolean {
val result = code()
val resultDisplay = if (result) "PASSED" else "FAILED"
println("TEST $name -> $resultDisplay")
return result
}
fun add(a: Int, b: Int): Int {
return a + b
}
@harsh183
Copy link
Author

Running stuff
TEST 5 + 10 -> FAILED
TEST 10 + 15 -> PASSED
TEST Negative -> PASSED
TEST Zero -> PASSED

@harsh183
Copy link
Author

MIT License

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