コード例 #1
0
 public void Substract()
 {
     Assert.AreEqual(2, NumberConverter.BitsToInt(MathOperations.BitsSubstraction(NumberConverter.IntToBits(32), NumberConverter.IntToBits(30))));
     Assert.AreEqual(20, NumberConverter.BitsToInt(MathOperations.BitsSubstraction(NumberConverter.IntToBits(84), NumberConverter.IntToBits(64))));
     Assert.AreEqual(200, NumberConverter.BitsToInt(MathOperations.BitsSubstraction(NumberConverter.IntToBits(876), NumberConverter.IntToBits(676))));
     Assert.AreEqual(123, NumberConverter.BitsToInt(MathOperations.BitsSubstraction(NumberConverter.IntToBits(723), NumberConverter.IntToBits(600))));
     Assert.AreEqual(8756, NumberConverter.BitsToInt(MathOperations.BitsSubstraction(NumberConverter.IntToBits(100000), NumberConverter.IntToBits(91244))));
 }
コード例 #2
0
 public void Multiply()
 {
     Assert.AreEqual(20, NumberConverter.BitsToInt(MathOperations.BitsMultiplier(NumberConverter.IntToBits(2), NumberConverter.IntToBits(10))));
     Assert.AreEqual(200, NumberConverter.BitsToInt(MathOperations.BitsMultiplier(NumberConverter.IntToBits(2), NumberConverter.IntToBits(100))));
     Assert.AreEqual(4914, NumberConverter.BitsToInt(MathOperations.BitsMultiplier(NumberConverter.IntToBits(63), NumberConverter.IntToBits(78))));
     Assert.AreEqual(978750, NumberConverter.BitsToInt(MathOperations.BitsMultiplier(NumberConverter.IntToBits(1250), NumberConverter.IntToBits(783))));
     Assert.AreEqual(1000000, NumberConverter.BitsToInt(MathOperations.BitsMultiplier(NumberConverter.IntToBits(1000), NumberConverter.IntToBits(1000))));
     Assert.AreEqual(473859433, NumberConverter.BitsToInt(MathOperations.BitsMultiplier(NumberConverter.IntToBits(5413), NumberConverter.IntToBits(87541))));
 }
コード例 #3
0
 public void Modulo()
 {
     Assert.AreEqual(1, NumberConverter.BitsToInt(MathOperations.Modulo(NumberConverter.IntToBits(7), NumberConverter.IntToBits(2))));
     Assert.AreEqual(2, NumberConverter.BitsToInt(MathOperations.Modulo(NumberConverter.IntToBits(200), NumberConverter.IntToBits(3))));
     Assert.AreEqual(1, NumberConverter.BitsToInt(MathOperations.Modulo(NumberConverter.IntToBits(742), NumberConverter.IntToBits(13))));
     Assert.AreEqual(4, NumberConverter.BitsToInt(MathOperations.Modulo(NumberConverter.IntToBits(789), NumberConverter.IntToBits(5))));
     Assert.AreEqual(172, NumberConverter.BitsToInt(MathOperations.Modulo(NumberConverter.IntToBits(7888896), NumberConverter.IntToBits(874))));
     Assert.AreEqual(21, NumberConverter.BitsToInt(MathOperations.Modulo(NumberConverter.IntToBits(4523106), NumberConverter.IntToBits(1743))));
 }
コード例 #4
0
 public void GCD()
 {
     int[] tmp = { 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0 };
     Array.Reverse(tmp);
     Assert.AreEqual(1, NumberConverter.BitsToInt(MathOperations.GCD(NumberConverter.IntToBits(7), NumberConverter.IntToBits(5))));
     Assert.AreEqual(7, NumberConverter.BitsToInt(MathOperations.GCD(NumberConverter.IntToBits(175), NumberConverter.IntToBits(7))));
     Assert.AreEqual(7, NumberConverter.BitsToInt(MathOperations.GCD(NumberConverter.IntToBits(7), NumberConverter.IntToBits(175))));
     Assert.AreEqual(1, NumberConverter.BitsToInt(MathOperations.GCD(NumberConverter.IntToBits(1236589), NumberConverter.IntToBits(2567))));
     Assert.AreEqual(1, NumberConverter.BitsToInt(MathOperations.GCD(NumberConverter.IntToBits(6519413), NumberConverter.IntToBits(122))));
     Assert.AreEqual(1, NumberConverter.BitsToInt(MathOperations.GCD(NumberConverter.IntToBits(6519413), NumberConverter.IntToBits(12))));
     Assert.AreEqual(9, NumberConverter.BitsToInt(MathOperations.GCD(NumberConverter.IntToBits(123432534), NumberConverter.IntToBits(12123))));
 }
コード例 #5
0
        public void BigIntToBitsTest()
        {
            var s2 = NumberConverter.BigInttoBytes(new System.Numerics.BigInteger(429));

            Assert.AreEqual(429, NumberConverter.BitsToInt(s2));
        }
コード例 #6
0
 public void InversePow()
 {
     Assert.AreEqual(3, NumberConverter.BitsToInt(MathOperations.InversePow(NumberConverter.IntToBits(5), NumberConverter.IntToBits(7))));
 }
コード例 #7
0
 public void Addition()
 {
     Assert.AreEqual(20, NumberConverter.BitsToInt(MathOperations.BitsAddition(NumberConverter.IntToBits(10), NumberConverter.IntToBits(10))));
     //Assert.AreEqual(123, NumberConverter.BitsToInt(MathOperations.BitsAddition(NumberConverter.IntToBits(10), NumberConverter.IntToBits(113))));
     //Assert.AreEqual(201234, NumberConverter.BitsToInt(MathOperations.BitsAddition(NumberConverter.IntToBits(1789), NumberConverter.IntToBits(199445))));
 }