Skip to content

Instantly share code, notes, and snippets.

@siosio
Last active August 29, 2015 14:24
Show Gist options
  • Save siosio/9744e11f6b30dc8549e8 to your computer and use it in GitHub Desktop.
Save siosio/9744e11f6b30dc8549e8 to your computer and use it in GitHub Desktop.
to :q!
import TestContext
import org.junit.Test
import setup
import sum
import kotlin.test.assertEquals
fun sum(a: IntArray) = a.sum()
class TestContext<P, OUT> {
var sut: Function1<P, OUT>? = null
var params: Array<P>? = null
fun verify(verifier: () -> Array<OUT>) {
params!!.zip(verifier()).forEach {
assertEquals(sut!!(it.first), it.second)
}
}
}
fun <P, OUT> setup(setup: TestContext<P, OUT>.() -> Unit): TestContext<P, OUT> {
val testContext = TestContext<P, OUT>()
testContext.setup()
return testContext
}
public class Tests {
@Test
fun testSum() {
setup<IntArray, Int> {
sut = ::sum
params = arrayOf(
intArrayOf(1, 2, 3),
intArrayOf(1, 2, 3, 4)
)
}.verify {
arrayOf(
6,
10
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment