X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Ftests%2FComponentTest.java;h=b80b2f30e467f08b35351162910e1fa7aeb00c0e;hb=e6d8e1a6099a1bc26af3851860bfd849543278c3;hp=b015d21aaae62341aa742024807a376775bdb3b5;hpb=cc4a905123efa6afb61c95cca21f22b78b194734;p=Mograsim.git diff --git a/net.mograsim.logic.core/src/net/mograsim/logic/core/tests/ComponentTest.java b/net.mograsim.logic.core/src/net/mograsim/logic/core/tests/ComponentTest.java index b015d21a..b80b2f30 100644 --- a/net.mograsim.logic.core/src/net/mograsim/logic/core/tests/ComponentTest.java +++ b/net.mograsim.logic.core/src/net/mograsim/logic/core/tests/ComponentTest.java @@ -15,6 +15,8 @@ import net.mograsim.logic.core.components.Mux; import net.mograsim.logic.core.components.Splitter; import net.mograsim.logic.core.components.TriStateBuffer; import net.mograsim.logic.core.components.gates.AndGate; +import net.mograsim.logic.core.components.gates.NandGate; +import net.mograsim.logic.core.components.gates.NorGate; import net.mograsim.logic.core.components.gates.NotGate; import net.mograsim.logic.core.components.gates.OrGate; import net.mograsim.logic.core.components.gates.XorGate; @@ -85,6 +87,47 @@ class ComponentTest assertBitArrayEquals(out.getValues(), Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE); } + @Test + void fusionTest1() + { + t.reset(); + Wire a = new Wire(t, 3, 1), b = new Wire(t, 2, 1), c = new Wire(t, 3, 1), out = new Wire(t, 8, 1); + Wire.fuse(a, out, 0, 0, a.length); + Wire.fuse(b, out, 0, a.length, b.length); + Wire.fuse(c, out, 0, a.length + b.length, c.length); + ReadWriteEnd rA = a.createReadWriteEnd(); + rA.feedSignals(Bit.ZERO, Bit.ONE, Bit.ZERO); + ReadWriteEnd rB = b.createReadWriteEnd(); + rB.feedSignals(Bit.ONE, Bit.ZERO); + ReadWriteEnd rC = c.createReadWriteEnd(); + rC.feedSignals(Bit.ONE, Bit.ZERO, Bit.ONE); + t.executeAll(); + assertBitArrayEquals(out.getValues(), Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE); + out.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ZERO); + t.executeAll(); + assertBitArrayEquals(rA.getValues(), Bit.X, Bit.X, Bit.X); + assertBitArrayEquals(rB.getValues(), Bit.X, Bit.X); + assertBitArrayEquals(rC.getValues(), Bit.X, Bit.X, Bit.X); + rA.clearSignals(); + rB.clearSignals(); + rC.clearSignals(); + t.executeAll(); + assertBitArrayEquals(rA.getValues(), Bit.ONE, Bit.ZERO, Bit.ONE); + assertBitArrayEquals(rB.getValues(), Bit.ZERO, Bit.ONE); + assertBitArrayEquals(rC.getValues(), Bit.ZERO, Bit.ONE, Bit.ZERO); + } + + @Test + void fusionTest2() + { + t.reset(); + Wire a = new Wire(t, 3, 1), b = new Wire(t, 3, 1); + Wire.fuse(a, b); + a.createReadWriteEnd().feedSignals(Bit.ONE, Bit.U, Bit.Z); + t.executeAll(); + assertBitArrayEquals(b.getValues(), Bit.ONE, Bit.U, Bit.Z); + } + @Test void triStateBufferTest() { @@ -207,6 +250,36 @@ class ComponentTest assertBitArrayEquals(c.getValues(), Bit.ONE, Bit.ONE, Bit.ZERO, Bit.ONE); } + @Test + void nandTest() + { + t.reset(); + Wire a = new Wire(t, 4, 1), b = new Wire(t, 4, 3), c = new Wire(t, 4, 1), d = new Wire(t, 4, 1); + new NandGate(t, 1, d.createReadWriteEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd(), c.createReadOnlyEnd()); + a.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ONE, Bit.ZERO, Bit.ZERO); + b.createReadWriteEnd().feedSignals(Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE); + c.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ONE, Bit.ZERO, Bit.ZERO); + + t.executeAll(); + + assertBitArrayEquals(d.getValues(), Bit.ONE, Bit.ZERO, Bit.ONE, Bit.ONE); + } + + @Test + void norTest() + { + t.reset(); + Wire a = new Wire(t, 4, 1), b = new Wire(t, 4, 3), c = new Wire(t, 4, 1), d = new Wire(t, 4, 1); + new NorGate(t, 1, d.createReadWriteEnd(), a.createReadOnlyEnd(), b.createReadOnlyEnd(), c.createReadOnlyEnd()); + a.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ONE, Bit.ZERO, Bit.ZERO); + b.createReadWriteEnd().feedSignals(Bit.ZERO, Bit.ONE, Bit.ZERO, Bit.ONE); + c.createReadWriteEnd().feedSignals(Bit.ONE, Bit.ONE, Bit.ZERO, Bit.ZERO); + + t.executeAll(); + + assertBitArrayEquals(d.getValues(), Bit.ZERO, Bit.ZERO, Bit.ONE, Bit.ZERO); + } + @Test void xorTest() { @@ -368,7 +441,7 @@ class ComponentTest TestBitDisplay test = new TestBitDisplay(t, c.createReadOnlyEnd()); TestBitDisplay test2 = new TestBitDisplay(t, a.createReadOnlyEnd()); - LongConsumer print = time -> System.out.format("Time %2d\n a: %s\n b: %s\n c: %s\n", time, a, b, c); + LongConsumer print = time -> System.out.format("Time %2d\n a: %s\n b: %s\n c: %s\n", time, a, b, c); cI.feedSignals(Bit.ONE); test.assertAfterSimulationIs(print, Bit.ONE);