Esempio n. 1
0
        public void AndNotBigInteger()
        {
            foreach (BigInteger[] element in booleanPairs)
            {
                BigInteger i1 = element[0], i2 = element[1];
                BigInteger res = i1.AndNot(i2);
                int        len = System.Math.Max(i1.BitLength, i2.BitLength) + 66;

                for (int i = 0; i < len; i++)
                {
                    IsTrue((i1.TestBit(i) && !i2.TestBit(i)) == res.TestBit(i), "andNot");
                }

                // asymmetrical
                i1  = element[1];
                i2  = element[0];
                res = i1.AndNot(i2);

                for (int i = 0; i < len; i++)
                {
                    IsTrue((i1.TestBit(i) && !i2.TestBit(i)) == res.TestBit(i), "andNot reversed");
                }
            }

            Throw(() => BigInteger.Zero.AndNot(null), "BigInteger: AndNot null test");
            BigInteger bi = new BigInteger(0, new byte[] { });
            //AreEqual(BigInteger.Zero, bi.AndNot(BigInteger.Zero));
        }
Esempio n. 2
0
        public void TestClearBit()
        {
            Assert.AreEqual(zero, zero.ClearBit(0));
            Assert.AreEqual(zero, one.ClearBit(0));
            Assert.AreEqual(two, two.ClearBit(0));

            Assert.AreEqual(zero, zero.ClearBit(1));
            Assert.AreEqual(one, one.ClearBit(1));
            Assert.AreEqual(zero, two.ClearBit(1));

            // TODO Tests for clearing bits in negative numbers

            // TODO Tests for clearing extended bits

            for (int i = 0; i < 10; ++i)
            {
                BigInteger n = new BigInteger(128, random);

                for (int j = 0; j < 10; ++j)
                {
                    int        pos  = random.Next(128);
                    BigInteger m    = n.ClearBit(pos);
                    bool       test = m.ShiftRight(pos).Remainder(two).Equals(one);

                    Assert.IsFalse(test);
                }
            }

            for (int i = 0; i < 100; ++i)
            {
                BigInteger pow2      = one.ShiftLeft(i);
                BigInteger minusPow2 = pow2.Negate();

                Assert.AreEqual(zero, pow2.ClearBit(i));
                Assert.AreEqual(minusPow2.ShiftLeft(1), minusPow2.ClearBit(i));

                BigInteger bigI = BigInteger.ValueOf(i);
                BigInteger negI = bigI.Negate();

                for (int j = 0; j < 10; ++j)
                {
                    string data = "i=" + i + ", j=" + j;
                    Assert.AreEqual(bigI.AndNot(one.ShiftLeft(j)), bigI.ClearBit(j), data);
                    Assert.AreEqual(negI.AndNot(one.ShiftLeft(j)), negI.ClearBit(j), data);
                }
            }
        }
Esempio n. 3
0
        public void AndNotBigInteger()
        {
            foreach (BigInteger[] element in booleanPairs) {
                BigInteger i1 = element[0], i2 = element[1];
                BigInteger res = i1.AndNot(i2);
                int len = System.Math.Max(i1.BitLength, i2.BitLength) + 66;
                for (int i = 0; i < len; i++) {
                    Assert.IsTrue((i1.TestBit(i) && !i2.TestBit(i)) == res.TestBit(i), "andNot");
                }

                // asymmetrical
                i1 = element[1];
                i2 = element[0];
                res = i1.AndNot(i2);
                for (int i = 0; i < len; i++) {
                    Assert.IsTrue((i1.TestBit(i) && !i2.TestBit(i)) == res.TestBit(i), "andNot reversed");
                }
            }

            Assert.Throws<NullReferenceException>(() => BigInteger.Zero.AndNot(null));

            BigInteger bi = new BigInteger(0, new byte[] { });
            Assert.AreEqual(BigInteger.Zero, bi.AndNot(BigInteger.Zero));
        }