Last active
August 29, 2015 14:24
-
-
Save siosio/9744e11f6b30dc8549e8 to your computer and use it in GitHub Desktop.
to :q!
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
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