tracks/kotlin/exercises/react/src/test/kotlin/ReactTest.kt in trackler-2.0.8.20 vs tracks/kotlin/exercises/react/src/test/kotlin/ReactTest.kt in trackler-2.0.8.21

- old
+ new

@@ -34,11 +34,11 @@ @Test fun computeCellsTakeInputsInTheRightOrder() { val reactor = Reactor<Int>() val one = reactor.InputCell(1) val two = reactor.InputCell(2) - val output = reactor.ComputeCell(one, two) { it[0] + it[1] * 10 } + val output = reactor.ComputeCell(one, two) { (x, y) -> x + y * 10 } assertEquals(21, output.value) } @Ignore @Test @@ -55,11 +55,11 @@ fun computeCellsCanDependOnOtherComputeCells() { val reactor = Reactor<Int>() val input = reactor.InputCell(1) val timesTwo = reactor.ComputeCell(input) { it[0] * 2 } val timesThirty = reactor.ComputeCell(input) { it[0] * 30 } - val output = reactor.ComputeCell(timesTwo, timesThirty) { it[0] + it[1] } + val output = reactor.ComputeCell(timesTwo, timesThirty) { (x, y) -> x + y } assertEquals(32, output.value) input.value = 3 assertEquals(96, output.value) } @@ -147,11 +147,11 @@ val reactor = Reactor<Int>() val input = reactor.InputCell(1) val plusOne = reactor.ComputeCell(input) { it[0] + 1 } val minusOne1 = reactor.ComputeCell(input) { it[0] - 1 } val minusOne2 = reactor.ComputeCell(minusOne1) { it[0] - 1 } - val output = reactor.ComputeCell(plusOne, minusOne2) { it[0] * it[1] } + val output = reactor.ComputeCell(plusOne, minusOne2) { (x, y) -> x * y } val vals = mutableListOf<Int>() output.addCallback { vals.add(it) } input.value = 4 @@ -163,11 +163,11 @@ fun callbacksShouldNotBeCalledIfDependenciesChangeButOutputValueDoesntChange() { val reactor = Reactor<Int>() val input = reactor.InputCell(1) val plusOne = reactor.ComputeCell(input) { it[0] + 1 } val minusOne = reactor.ComputeCell(input) { it[0] - 1 } - val alwaysTwo = reactor.ComputeCell(plusOne, minusOne) { it[0] - it[1] } + val alwaysTwo = reactor.ComputeCell(plusOne, minusOne) { (x, y) -> x - y } val vals = mutableListOf<Int>() alwaysTwo.addCallback { vals.add(it) } for (i in 1..10) { @@ -207,15 +207,15 @@ val reactor = Reactor<Boolean>() val a = reactor.InputCell(input.a) val b = reactor.InputCell(input.b) val carryIn = reactor.InputCell(input.carryIn) - val aXorB = reactor.ComputeCell(a, b) { it[0].xor(it[1]) } - val sum = reactor.ComputeCell(aXorB, carryIn) { it[0].xor(it[1]) } + val aXorB = reactor.ComputeCell(a, b) { (x, y) -> x.xor(y) } + val sum = reactor.ComputeCell(aXorB, carryIn) { (x, y) -> x.xor(y) } - val aXorBAndCin = reactor.ComputeCell(aXorB, carryIn) { it[0] && it[1] } - val aAndB = reactor.ComputeCell(a, b) { it[0] && it[1] } - val carryOut = reactor.ComputeCell(aXorBAndCin, aAndB) { it[0] || it[1] } + val aXorBAndCin = reactor.ComputeCell(aXorB, carryIn) { (x, y) -> x && y } + 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)) } }