X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Ftests%2FComponentTest.java;h=38d1b7c67717022a575a2a5c9b0c0acd4d2bb421;hb=15aff307cbd5ae828801f5ee078e7a086b5b3973;hp=a47f7921e2ade2497f02d4baaa1b53cac19f1464;hpb=07faf07e3acb8b2afdc2bf65a46bc868faaed0f8;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 a47f7921..38d1b7c6 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 @@ -1,6 +1,5 @@ package net.mograsim.logic.core.tests; -import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; @@ -16,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; @@ -26,6 +27,7 @@ import net.mograsim.logic.core.wires.Wire; import net.mograsim.logic.core.wires.Wire.ReadEnd; import net.mograsim.logic.core.wires.Wire.ReadWriteEnd; +@SuppressWarnings("unused") class ComponentTest { private Timeline t = new Timeline(11); @@ -207,6 +209,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() { @@ -295,19 +327,19 @@ class ComponentTest t.addEvent((e) -> { if (!flag) - fail(); + fail("Events executed out of order!"); flag = false; }, 15); t.addEvent((e) -> { if (flag) - fail(); + fail("Events executed out of order!"); flag = true; }, 10); t.addEvent((e) -> { if (flag) - fail(); + fail("Events executed out of order!"); flag = true; }, 20); t.addEvent((e) -> @@ -318,7 +350,7 @@ class ComponentTest t.executeUntil(t.laterThan(20), 100); if (!flag) - fail(); + fail("Not all events were executed in order!"); } @Test @@ -342,12 +374,12 @@ class ComponentTest wI2.feedSignals(Bit.ONE, Bit.Z); ReadEnd rE = w.createReadOnlyEnd(); - rE.addObserver((i, oldValues) -> fail("WireEnd notified observer, although value did not change.")); + rE.registerObserver((i) -> fail("WireEnd notified observer, although value did not change.")); t.executeAll(); rE.close(); wI1.feedSignals(Bit.X, Bit.X); t.executeAll(); - wI1.addObserver((i, oldValues) -> fail("WireEnd notified observer, although it was closed.")); + wI1.registerObserver((i) -> fail("WireEnd notified observer, although it was closed.")); wI1.close(); assertBitArrayEquals(w.getValues(), Bit.ONE, Bit.Z); }