public override bool TestGate() { Input1.SetValue(7); Input2.SetValue(7); if (Output.Get2sComplement() != 14) { return(false); } Input1.Set2sComplement(6); Input2.Set2sComplement(-6); if (Output.Get2sComplement() != 0) { return(false); } Input1.Set2sComplement(6); Input2.Set2sComplement(-1); if (Output.Get2sComplement() != 5) { return(false); } return(true); }
public override bool TestGate() { int bits = Size - 1; for (int i = 0; i < 10; i++) { Random rand = new Random(); int num1 = rand.Next((-(int)Math.Pow(2, bits - 1)), ((int)Math.Pow(2, bits - 1) - 1) + 1); int num2 = rand.Next((-(int)Math.Pow(2, bits - 1)), ((int)Math.Pow(2, bits - 1) - 1) + 1); WireSet sum = new WireSet(Size); sum.Set2sComplement(num1 + num2); Input1.Set2sComplement(num1); Input2.Set2sComplement(num2); if (Output.Get2sComplement() != sum.Get2sComplement()) { return(false); } } return(true); }