tracks/kotlin/exercises/react/src/test/kotlin/ReactTest.kt in trackler-2.2.1.52 vs tracks/kotlin/exercises/react/src/test/kotlin/ReactTest.kt in trackler-2.2.1.53
- old
+ new
@@ -3,10 +3,11 @@
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import kotlin.test.assertEquals
class ReactTest {
+
@Test
fun inputCellsHaveValue() {
val reactor = Reactor<Int>()
val input = reactor.InputCell(10)
assertEquals(10, input.value)
@@ -130,11 +131,11 @@
val vals1 = mutableListOf<Int>()
val sub1 = output.addCallback { vals1.add(it) }
val vals2 = mutableListOf<Int>()
output.addCallback { vals2.add(it) }
- for (i in 1..10) {
+ for (i in 1..3) {
sub1.cancel()
}
input.value = 2
assertEquals(listOf<Int>(), vals1)
@@ -168,21 +169,26 @@
val alwaysTwo = reactor.ComputeCell(plusOne, minusOne) { (x, y) -> x - y }
val vals = mutableListOf<Int>()
alwaysTwo.addCallback { vals.add(it) }
- for (i in 1..10) {
+ for (i in 2..5) {
input.value = i
}
assertEquals(listOf<Int>(), vals)
}
+
}
+/*
+ * Extension
+ *
+ * This is a digital logic circuit called an adder:
+ * https://en.wikipedia.org/wiki/Adder_(electronics)
+ */
@RunWith(Parameterized::class)
-// This is a digital logic circuit called an adder:
-// https://en.wikipedia.org/wiki/Adder_(electronics)
class ReactAdderTest(val input: Input, val expected: Expected) {
companion object {
data class Input(val a: Boolean, val b: Boolean, val carryIn: Boolean)
data class Expected(val carryOut: Boolean, val sum: Boolean)
@@ -216,6 +222,7 @@
val aAndB = reactor.ComputeCell(a, b) { (x, y) -> x && y }
val carryOut = reactor.ComputeCell(aXorBAndCin, aAndB) { (x, y) -> x || y }
assertEquals(expected, Expected(sum=sum.value, carryOut=carryOut.value))
}
+
}