X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2Ftests%2FComponentTest.java;fp=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2Ftests%2FComponentTest.java;h=722c52a2a466044bccb16b2a3a92567aa07ff430;hb=d31f9734d6aa233682ef80d7e9322dd500123bfd;hp=0638cf8a22a8c5c9cd363f7bb61b2eec805cd6ff;hpb=33d4533c5e48fbb5d1d0057f2b08d3d6f8e29a87;p=Mograsim.git diff --git a/era.mi/src/era/mi/logic/tests/ComponentTest.java b/era.mi/src/era/mi/logic/tests/ComponentTest.java index 0638cf8a..722c52a2 100644 --- a/era.mi/src/era/mi/logic/tests/ComponentTest.java +++ b/era.mi/src/era/mi/logic/tests/ComponentTest.java @@ -3,15 +3,13 @@ package era.mi.logic.tests; import static org.junit.jupiter.api.Assertions.*; import java.util.Arrays; +import java.util.function.LongConsumer; import org.junit.jupiter.api.Test; import era.mi.logic.Bit; import era.mi.logic.Simulation; -import era.mi.logic.components.Merger2; -import era.mi.logic.components.Mux; import era.mi.logic.components.Mux2; -import era.mi.logic.components.Splitter; import era.mi.logic.components.gates.AndGate; import era.mi.logic.components.gates.NotGate; import era.mi.logic.components.gates.OrGate; @@ -245,4 +243,49 @@ class ComponentTest } assertTrue(Arrays.equals(w.getValues(), new Bit[] { Bit.ONE, Bit.Z })); } + + @Test + void wireConnections() + { + // Nur ein Experiment, was über mehrere 'passive' Bausteine hinweg passieren würde + + Simulation.TIMELINE.reset(); + + WireArray a = new WireArray(1, 2); + WireArray b = new WireArray(1, 2); + WireArray c = new WireArray(1, 2); + WireArrayInput aI = a.createInput(); + WireArrayInput bI = b.createInput(); + WireArrayInput cI = c.createInput(); + + TestBitDisplay test = new TestBitDisplay(c); + LongConsumer print = time -> System.out.format("Time %2d\n %s\n %s\n %s\n", time, a, b, c); + + cI.feedSignals(Bit.ONE); + test.assertAfterSimulationIs(print, Bit.ONE); + + cI.feedSignals(Bit.X); + test.assertAfterSimulationIs(print, Bit.X); + + cI.feedSignals(Bit.X); + cI.feedSignals(Bit.Z); + test.assertAfterSimulationIs(print, Bit.Z); + + Connector c1 = new Connector(b, c); + test.assertAfterSimulationIs(print, Bit.Z); + System.out.println("ONE"); + bI.feedSignals(Bit.ONE); + test.assertAfterSimulationIs(print, Bit.ONE); + System.out.println("ZERO"); + bI.feedSignals(Bit.ZERO); + test.assertAfterSimulationIs(print, Bit.ZERO); + System.out.println("Z"); + bI.feedSignals(Bit.Z); + test.assertAfterSimulationIs(Bit.Z); + } + + private static void assertBitArrayEquals(Bit[] actual, Bit... expected) + { + assertArrayEquals(expected, actual); + } }