Fixed nand and nor gate to work with more than two inputs
[Mograsim.git] / net.mograsim.logic.core / src / net / mograsim / logic / core / tests / ComponentTest.java
index 5fb7d9c..38d1b7c 100644 (file)
@@ -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()
        {