Пример #1
0
        public override bool TestGate()
        {
            try
            {
                var ws1 = new WireSet(Size);
                for (int i = 0; i < Math.Pow(2, Size) - 1; i++)
                {
                    ws1.SetValue(i);
                    for (int j = 0; j < Math.Pow(2, Size) - 1; j++)
                    {
                        var mgOr = new BitwiseOrGate(Size);
                        var ws2  = new WireSet(Size);
                        ws2.SetValue(j);
                        mgOr.ConnectInput1(ws1);
                        mgOr.ConnectInput2(ws2);

                        for (int k = 0; k < ws1.Size; k++)
                        {
                            if (mgOr.Output[j].Value != (ws1[j].Value | ws2[j].Value))
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message + " " + e.HelpLink);
            }
            return(true);
        }
Пример #2
0
        public override bool TestGate()
        {
            ALU al;

            WireSet[] inputs   = new WireSet[2];
            WireSet[] solution = new WireSet[18];
            WireSet[] all      = new WireSet[6];

            for (int i = 0; i < all.Length; i++)
            {
                all[i] = new WireSet(18);
            }


            WireSet wsTemp  = new WireSet(18);
            WireSet wsTemp2 = new WireSet(Size);

            wsTemp.SetValue(240288);
            all[0].ConnectInput(wsTemp);
            wsTemp = new WireSet(18);
            wsTemp.SetValue(109481);
            all[1].ConnectInput(wsTemp);
            wsTemp = new WireSet(18);
            wsTemp.SetValue(251200);
            all[2].ConnectInput(wsTemp);
            wsTemp = new WireSet(18);
            wsTemp.SetValue(87493);
            all[3].ConnectInput(wsTemp);
            wsTemp = new WireSet(18);
            wsTemp.SetValue(231420);
            all[4].ConnectInput(wsTemp);
            wsTemp = new WireSet(18);
            wsTemp.SetValue(73613);
            all[5].ConnectInput(wsTemp);

            for (int i = 0; i < Size; i++)
            {
                for (int j = 0; j < Size; j++)
                {
                    for (int f = 0; f < solution.Length; f++)
                    {
                        solution[f] = new WireSet(Size);
                    }

                    inputs[0] = new WireSet(Size);
                    inputs[1] = new WireSet(Size);
                    inputs[0].SetValue(i);
                    inputs[1].SetValue(j);

                    wsTemp2 = new WireSet(Size);
                    wsTemp2.SetValue(0);
                    solution[0].ConnectInput(wsTemp2);
                    wsTemp2 = new WireSet(Size);
                    wsTemp2.SetValue(1);
                    solution[1].ConnectInput(wsTemp2);
                    wsTemp2 = new WireSet(Size);
                    wsTemp2.Set2sComplement(-1);
                    solution[2].ConnectInput(wsTemp2);
                    solution[3].ConnectInput(inputs[0]);
                    solution[4].ConnectInput(inputs[1]);

                    BitwiseNotGate bwng = new BitwiseNotGate(Size);
                    bwng.ConnectInput(inputs[0]);

                    solution[5].ConnectInput(bwng.Output);
                    bwng = new BitwiseNotGate(Size);
                    bwng.ConnectInput(inputs[1]);
                    solution[6].ConnectInput(bwng.Output);
                    wsTemp2 = new WireSet(Size);

                    wsTemp2.SetValue(inputs[0].GetValue() * -1);
                    solution[7].ConnectInput(wsTemp2);
                    wsTemp2 = new WireSet(Size);
                    wsTemp2.SetValue(inputs[1].GetValue() * -1);
                    solution[8].ConnectInput(wsTemp2);
                    wsTemp2 = new WireSet(Size);
                    wsTemp2.SetValue(inputs[0].GetValue() + 1);
                    solution[9].ConnectInput(wsTemp2);
                    wsTemp2 = new WireSet(Size);
                    wsTemp2.SetValue(inputs[1].GetValue() + 1);
                    solution[10].ConnectInput(wsTemp2);
                    wsTemp2 = new WireSet(Size);
                    wsTemp2.SetValue(inputs[0].GetValue() - 1);
                    solution[11].ConnectInput(wsTemp2);
                    wsTemp2 = new WireSet(Size);
                    wsTemp2.SetValue(inputs[1].GetValue() - 1);
                    solution[12].ConnectInput(wsTemp2);
                    wsTemp2 = new WireSet(Size);
                    wsTemp2.SetValue(inputs[0].GetValue() + inputs[1].GetValue());
                    solution[13].ConnectInput(wsTemp2);
                    wsTemp2 = new WireSet(Size);
                    wsTemp2.SetValue(inputs[0].GetValue() - inputs[1].GetValue());
                    solution[14].ConnectInput(wsTemp2);
                    wsTemp2 = new WireSet(Size);
                    wsTemp2.SetValue(inputs[1].GetValue() - inputs[0].GetValue());
                    solution[15].ConnectInput(wsTemp2);

                    BitwiseOrGate  bwog = new BitwiseOrGate(Size);
                    BitwiseAndGate bwag = new BitwiseAndGate(Size);
                    bwog.ConnectInput1(inputs[0]);
                    bwog.ConnectInput2(inputs[1]);
                    bwag.ConnectInput1(inputs[0]);
                    bwag.ConnectInput2(inputs[1]);
                    solution[16].ConnectInput(bwag.Output);
                    solution[17].ConnectInput(bwog.Output);

                    for (int k = 0; k < 18; k++)
                    {
                        al = new ALU(Size);
                        al.InputX.ConnectInput(inputs[0]);
                        al.InputY.ConnectInput(inputs[1]);
                        al.ZeroX.Value     = all[0][17 - k].Value;
                        al.NotX.Value      = all[1][17 - k].Value;
                        al.ZeroY.Value     = all[2][17 - k].Value;
                        al.NotY.Value      = all[3][17 - k].Value;
                        al.F.Value         = all[4][17 - k].Value;
                        al.NotOutput.Value = all[5][17 - k].Value;

                        if (al.Output.ToString() != solution[k].ToString())
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }