Exemple #1
0
        public void DefaultTTGenerator()
        {
            Gates.TruthTable.TruthTable tt  = CreateLines();
            Gates.TruthTable.TruthTable tt2 = Gates.TruthTable.TruthTable.DefaultTruthTable(tt);
            TestLines(tt2);

            Gates.BasicGates.Xor        xor  = new Gates.BasicGates.Xor();
            Gates.TruthTable.TruthTable txor = Gates.TruthTable.TruthTable.DefaultTruthTable(xor);
            Assert.AreEqual(2, txor.NumberOfInputs);
            Assert.AreEqual(1, txor.Output.Length);
            Assert.AreEqual(4, txor.Table.GetLength(0));
            Assert.AreEqual(1, txor.Table[0].GetLength(0));

            txor[0] = false;
            txor[1] = false;
            Assert.AreEqual(false, txor.Output[0]);

            txor[0] = true;
            txor[1] = false;
            Assert.AreEqual(true, txor.Output[0]);

            txor[0] = true;
            txor[1] = true;
            Assert.AreEqual(false, txor.Output[0]);

            txor[0] = false;
            txor[1] = true;
            Assert.AreEqual(true, txor.Output[0]);
        }
Exemple #2
0
        private Gates.TruthTable.TruthTable CreateLines()
        {
            Gates.TruthTable.TruthTable tt = new Gates.TruthTable.TruthTable(3, 2);
            Assert.AreEqual(8, tt.Table.GetLength(0));
            Assert.AreEqual(2, tt.Table[0].GetLength(0));

            // output 0 is xor
            // output 1 is not first bit
            tt[new bool[] { false, false, false }, 0] = false;
            tt[new bool[] { false, false, false }, 1] = true;

            tt[new bool[] { false, false, true }, 0] = true;
            tt[new bool[] { false, false, true }, 1] = true;

            tt[new bool[] { false, true, false }, 0] = true;
            tt[new bool[] { false, true, false }, 1] = true;

            tt[new bool[] { true, false, false }, 0] = true;
            tt[new bool[] { true, false, false }, 1] = false;

            tt[new bool[] { false, true, true }, 0] = false;
            tt[new bool[] { false, true, true }, 1] = true;

            tt[new bool[] { true, true, false }, 0] = false;
            tt[new bool[] { true, true, false }, 1] = false;

            tt[new bool[] { true, true, true }, 0] = true;
            tt[new bool[] { true, true, true }, 1] = false;


            return(tt);
        }
Exemple #3
0
        public void CloneTT()
        {
            Gates.TruthTable.TruthTable tt  = CreateLines();
            Gates.TruthTable.TruthTable tt2 = (Gates.TruthTable.TruthTable)tt.Clone();
            TestLines(tt2);

            Gates.TruthTable.StatefulTruthTable stt  = CreateSimpleState();
            Gates.TruthTable.StatefulTruthTable stt2 = (Gates.TruthTable.StatefulTruthTable)stt.Clone();
            TestSimpleState(stt2);
        }
Exemple #4
0
        private void TestLines(Gates.TruthTable.TruthTable tt)
        {
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    for (int k = 0; k < 2; k++)
                    {
                        tt[0] = i == 1;
                        tt[1] = j == 1;
                        tt[2] = k == 1;

                        Assert.AreEqual((i + j + k) % 2 == 1, tt.Output[0], i.ToString() + j.ToString() + k.ToString());
                        Assert.AreEqual(i == 0, tt.Output[1], i.ToString() + j.ToString() + k.ToString());
                    }
                }
            }
        }
Exemple #5
0
        private void TestBasic(Gates.TruthTable.TruthTable tt)
        {
            tt[0] = false;
            tt[1] = false;
            Assert.AreEqual(false, tt.Output[0], "00 case");
            Assert.AreEqual(false, tt.Output[1], "00 case");

            tt[0] = true;
            tt[1] = false;
            Assert.AreEqual(true, tt.Output[0], "10 case");
            Assert.AreEqual(false, tt.Output[1], "10 case");

            tt[0] = false;
            tt[1] = true;
            Assert.AreEqual(true, tt.Output[0], "01 case");
            Assert.AreEqual(false, tt.Output[1], "01 case");

            tt[0] = true;
            tt[1] = true;
            Assert.AreEqual(true, tt.Output[0], "11 case");
            Assert.AreEqual(true, tt.Output[1], "11 case");
        }
Exemple #6
0
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        private Gates.TruthTable.TruthTable CreateBasic()
        {
            Gates.TruthTable.TruthTable tt = new Gates.TruthTable.TruthTable(2, 2);
            Assert.AreEqual(4, tt.Table.GetLength(0));
            Assert.AreEqual(2, tt.Table[0].GetLength(0));

            // output 0 is or
            // output 1 is and
            tt[0, 0] = false;
            tt[0, 1] = false;

            tt[1, 0] = true;
            tt[1, 1] = false;

            tt[2, 0] = true;
            tt[2, 1] = false;

            tt[3, 0] = true;
            tt[3, 1] = true;

            return(tt);
        }
Exemple #7
0
 public void BoolLinesTTTest()
 {
     Gates.TruthTable.TruthTable tt = CreateLines();
     TestLines(tt);
 }
Exemple #8
0
 public void BasicTTTest()
 {
     Gates.TruthTable.TruthTable tt = CreateBasic();
     TestBasic(tt);
 }