예제 #1
0
파일: MemoryTest.cs 프로젝트: fossabot/Silo
        public void SRFlipFlopTest()
        {
            var a      = new Switch();
            var b      = new Switch();
            var button = new Button();
            var reset  = new Switch();
            var mem    = new SRFlipFlop();

            a.AttachTo(mem, 0);
            b.AttachTo(mem, 1);
            button.AttachTo(mem, 2);
            reset.AttachTo(mem, 3);

            a.State = true;
            button.Click();

            Assert.IsTrue(mem.OutState());

            b.State = true;
            button.Click();
            Assert.IsTrue(mem.OutState());

            a.State = false;
            button.Click();
            Assert.IsFalse(mem.OutState());

            reset.State = true;
            Assert.IsFalse(mem.OutState());
        }
예제 #2
0
파일: MemoryTest.cs 프로젝트: fossabot/Silo
        public void ShiftRegister4Test()
        {
            var serial = new Switch();
            var button = new Button();
            var shift  = new ShiftRegister4();

            var bools = new List <bool>();

            var trap = new Trap(b1 =>
            {
                bools.Add(b1);
            });

            serial.AttachTo(shift, 0);
            button.AttachTo(shift, 1);
            shift.AttachTo(trap, 0);

            serial.State = true;
            button.Click();

            serial.State = false;
            button.Click();

            serial.State = true;
            button.Click();

            serial.State = false;
            button.Click();
            Assert.IsTrue(shift.OutState());

            button.Click();
            button.Click();
            Assert.IsTrue(shift.OutState());

            serial.State = true;
            button.Click();

            serial.State = false;
            button.Click();

            serial.State = true;
            button.Click();

            var rst = new Button();

            rst.AttachTo(shift, 2);
            rst.Click();

            button.Click();
            Assert.IsFalse(shift.OutState());
            button.Click();
            Assert.IsFalse(shift.OutState());
            button.Click();
            Assert.IsFalse(shift.OutState());
            button.Click();
            Assert.IsFalse(shift.OutState());
        }
예제 #3
0
파일: MemoryTest.cs 프로젝트: fossabot/Silo
        public void CounterTest()
        {
            var reset       = new Switch();
            var loadOrCount = new Switch();
            var upOrDown    = new Switch();
            var countToggle = new Switch();
            var input       = new EightBitInput();
            var clock       = new Button();
            var counter     = new Counter();
            var display     = new EightBitDisplay();

            reset.AttachTo(counter, 0);
            loadOrCount.AttachTo(counter, 1);
            upOrDown.AttachTo(counter, 2);
            countToggle.AttachTo(counter, 3);
            clock.AttachTo(counter, 4);
            input.AttachTo(counter, 5);

            counter.AttachRange(display, 1, 8);

            loadOrCount.State = true;
            input.State       = 50;
            clock.Click();

            Assert.AreEqual(50, display.Value);

            loadOrCount.State = false;
            upOrDown.State    = true;
            countToggle.State = true;
            clock.Click();

            Assert.AreEqual(51, display.Value);

            upOrDown.State = false;
            clock.Click();

            Assert.AreEqual(50, display.Value);

            reset.State = true;
            Assert.AreEqual(0, display.Value);

            reset.State       = false;
            loadOrCount.State = true;
            input.State       = 254;
            clock.Click();

            Assert.IsFalse(counter.OutState());

            loadOrCount.State = false;
            countToggle.State = true;
            upOrDown.State    = true;
            clock.Click();
            clock.Click();

            Assert.IsTrue(counter.OutState());
        }
예제 #4
0
        public void InverterTest()
        {
            var a   = new Switch();
            var inv = new Inverter();

            a.AttachTo(inv, 0);
            Assert.IsTrue(inv.OutState());

            a.State = true;
            Assert.IsFalse(inv.OutState());
        }
예제 #5
0
파일: GateTests.cs 프로젝트: fossabot/Silo
        private void GateTest(Component gate, IReadOnlyList <bool> results)
        {
            var a = new Switch();
            var b = new Switch();

            a.AttachTo(gate, 0);
            b.AttachTo(gate, 1);

            for (var i = 0; i < _truthTable.Length; i++)
            {
                a.State = _truthTable[i][0];
                b.State = _truthTable[i][1];

                Assert.AreEqual(gate.OutState(), results[i]);
            }
        }
예제 #6
0
파일: MemoryTest.cs 프로젝트: fossabot/Silo
        public void DFlipFlopTest()
        {
            var a      = new Switch();
            var button = new Button();
            var mem    = new DFlipFlop();

            a.AttachTo(mem, 0);
            button.AttachTo(mem, 1);

            Assert.IsFalse(mem.OutState());
            Assert.IsTrue(mem.GetPortState(1));

            a.State = true;
            button.Click();

            Assert.IsTrue(mem.OutState());
            Assert.IsFalse(mem.GetPortState(1));

            a.State = false;
            button.Click();

            Assert.IsFalse(mem.OutState());
            Assert.IsTrue(mem.GetPortState(1));
        }
예제 #7
0
파일: Program.cs 프로젝트: fossabot/Silo
        private static void Main()
        {
            var a = new Switch();
            var b = new Switch();
            var c = new Switch();

            #region AndGate

            Console.WriteLine("AND Gate Test");
            Console.WriteLine("------------------------");

            var inv = new Inverter();

            b.AttachTo(inv, 0);

            var andGate = new AndGate();

            a.AttachTo(andGate, 0);
            inv.AttachTo(andGate, 1);

            a.State = true;
            b.State = true;

            Console.WriteLine(andGate);

            b.State = false;
            Console.WriteLine(andGate);

            #endregion

            #region 8 bit input

            Console.WriteLine("\n8 bit input");
            Console.WriteLine("------------------------");

            var inp = new EightBitInput {
                State = 200
            };

            Console.WriteLine(inp);

            #endregion

            #region FullAdder

            Console.WriteLine("\nFull Adder");
            Console.WriteLine("------------------------");

            a.State = false;
            b.State = false;

            var add = new FullAdder();

            a.AttachTo(add, 0);
            b.AttachTo(add, 1);
            c.AttachTo(add, 2);

            a.State = true;

            Console.WriteLine(add);

            b.State = true;

            Console.WriteLine(add);

            b.State = false;
            c.State = true;

            Console.WriteLine(add);

            #endregion

            #region 8 bit Adder

            Console.WriteLine("\n8 bit Adder");
            Console.WriteLine("------------------------");

            var in1 = new EightBitInput();
            var in2 = new EightBitInput();

            var add1 = new EightBitAdder();

            in1.AttachTo(add1);
            in2.AttachTo(add1, 8);

            in1.State = 10;
            in2.State = 5;

            Console.WriteLine(add1);

            var display = new EightBitDisplay();
            add1.AttachToAll(display);
            Console.WriteLine(display);

            #endregion

            #region Dual 8 bit adder

            Console.WriteLine("\nDual 8 bit Adder");
            Console.WriteLine("------------------------");

            var in3 = new EightBitInput();
            var in4 = new EightBitInput();

            var add2 = new EightBitAdder();

            in3.AttachTo(add2);
            in4.AttachTo(add2, 8);

            in3.State = 4;
            in4.State = 11;

            var add3 = new EightBitAdder();

            add1.AttachToAll(add3);
            add2.AttachToAll(add3, 8);

            var display2 = new EightBitDisplay();
            add3.AttachToAll(display2);
            Console.WriteLine(display2);

            #endregion

            #region D FlipFlop with pseudo clock

            Console.WriteLine("\nD FlipFlop with pseudo clock");
            Console.WriteLine("------------------------");

            var d   = new DFlipFlop();
            var val = new Switch();
            var clk = new Switch();

            val.AttachTo(d, 0);
            clk.AttachTo(d, 1);

            val.State = true;
            clk.State = true;
            Console.WriteLine(d);

            val.State = false;
            clk.State = false;
            clk.State = true;
            Console.WriteLine(d);

            #endregion

            #region D Flip Flop with real clock

            Console.WriteLine("\nD Flip Flop with real clock");
            Console.WriteLine("------------------------");

            var clk1 = new Clock(1.Hz());
            clk1.AttachTo(d, 1);
            val.State = true;
            Console.WriteLine(d);
            Thread.Sleep(2000);
            Console.WriteLine(d);

            val.State = false;
            Console.WriteLine(d);
            Thread.Sleep(2000);
            Console.WriteLine(d);

            #endregion

            #region SR Flip Flop with pseudo clock

            Console.WriteLine("\nSR Flip Flop with pseudo clock");
            Console.WriteLine("------------------------");

            var sr  = new SRFlipFlop();
            var sr1 = new Switch();
            var sr2 = new Switch();
            var sr3 = new Switch();

            sr1.AttachTo(sr, 0);
            sr2.AttachTo(sr, 1);
            sr3.AttachTo(sr, 2);

            sr1.State = true;

            sr3.State = true;
            sr3.State = false;

            Console.WriteLine(sr);

            sr2.State = true;

            sr3.State = true;
            sr3.State = false;

            Console.WriteLine(sr);

            sr1.State = false;

            sr3.State = true;
            sr3.State = false;

            Console.WriteLine(sr);

            #endregion
        }