Example #1
0
        public override bool TestGate()
        {
            Random  rand       = new Random();
            WireSet randInWire = new WireSet(WordSize);

            for (int i = 0; i < m_rMultiBit.Length; i++)
            {
                randInWire.Set2sComplement((int)rand.Next(-(int)Math.Pow(2, WordSize - 1), ((int)Math.Pow(2, WordSize - 1) - 1))); //generate random valid input
                Input.Set2sComplement(randInWire.Get2sComplement());                                                               // connect input to randomized wire
                Address.Set2sComplement((int)rand.Next(0, (int)Math.Pow(2, AddressSize) + 1));                                     //generate random valid address
                Load.Value = 1;

                Clock.ClockDown();
                Clock.ClockUp();

                Load.Value = 0;
                int tempChange = randInWire.Get2sComplement();
                if (tempChange < 0)
                {
                    tempChange++;
                }
                else
                {
                    tempChange--;
                }
                Input.Set2sComplement(tempChange);
                if (Output.Get2sComplement() != randInWire.Get2sComplement())
                {
                    return(false);
                }

                Clock.ClockDown();
                Clock.ClockUp();
                if (Output.Get2sComplement() != randInWire.Get2sComplement())
                {
                    return(false);
                }

                Load.Value = 1;
                Clock.ClockDown();
                Clock.ClockUp();
                if (Output.Get2sComplement() != Input.Get2sComplement())
                {
                    return(false);
                }

                tempChange = Address.Get2sComplement();
                if (tempChange != 0)
                {
                    tempChange--;
                }
                else
                {
                    tempChange++;
                }
                Address.Set2sComplement(tempChange);
                Clock.ClockDown();
                Clock.ClockUp();
                if (Output.Get2sComplement() != Input.Get2sComplement())
                {
                    return(false);
                }
            }

            return(true);
        }