Skip to content

Instantly share code, notes, and snippets.

@harsh183
Last active May 29, 2026 04:08
Show Gist options
  • Select an option

  • Save harsh183/fb32427bb283b5b546bab7974859060b to your computer and use it in GitHub Desktop.

Select an option

Save harsh183/fb32427bb283b5b546bab7974859060b to your computer and use it in GitHub Desktop.
A very, very budget cut test running framework that also works with grade weights. Expanded from hackyTest.kt. It eventually got used in https://github.com/daviskeene/KTeach
data class TestResult(var score: Double, var maxScore: Double);
fun main() {
println("Running stuff")
val results = listOf(
case("5 + 10", 2.0) {
var x = 15;
x = x + 10
add(5, 10) == x
},
case("10 + 15", weight=0.25) {
add(10, 15) == 25
},
case("Negative") {
add(10, -15) == -5
},
case("Zero", 10.0) {
add(10, 0) == 10
}
)
val (score, totalScore) = sumScore(results)
println("Got $score / $totalScore")
}
fun sumScore(results: List<TestResult>): Pair<Double, Double> {
var score: Double = 0.0
var totalScore: Double = 0.0
for ((pointsScored, possiblePoints) in results) {
score += pointsScored
totalScore += possiblePoints
}
return Pair(score, totalScore)
}
fun case(name: String, weight: Double = 1.0, code: () -> Boolean): TestResult {
val result = code()
val resultDisplay = if (result) "PASSED" else "FAILED"
println("TEST " + name + " -> " + resultDisplay)
val score = if (result) weight else 0.0
return TestResult(score, weight)
}
// User code from here
fun add(a: Int, b: Int): Int {
return a + b
}
@harsh183

harsh183 commented Apr 18, 2020

Copy link
Copy Markdown
Author

MIT License

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