コード例 #1
0
        public void MultiplicationTest()
        {
            ComplementCode cc1 = new ComplementCode(6, "00101");
            ComplementCode cc2 = new ComplementCode(6, "00011");

            cc1 = cc1 * (-cc2);
            Assert.AreEqual("110001", cc1.ToString());
        }
コード例 #2
0
        public void CopyTest()
        {
            ComplementCode cc1 = new ComplementCode(5, "11111");
            ComplementCode cc2 = new ComplementCode(cc1);

            Assert.IsTrue(cc1 == cc2);
            Assert.IsFalse(cc1.Equals(cc2));
        }
コード例 #3
0
        public void DivideTestOne()
        {
            //8 / 4 = 2
            ComplementCode first = new ComplementCode(5, "1000");
            ComplementCode second = new ComplementCode(5, "100");

            first = first / second;

            Assert.AreEqual("00010", first.ToString());
        }
コード例 #4
0
        public void DivideTestTwo()
        {
            //-5 / -5 = 1
            ComplementCode A = new ComplementCode(5, "101");
            ComplementCode B = new ComplementCode(5, "101");

            A = -A / -B;

            Assert.AreEqual("00001", A.ToString());
        }
コード例 #5
0
        public void EqualTest()
        {
            ComplementCode cc1 = new ComplementCode(5, "110");
            ComplementCode cc2 = cc1;
            ComplementCode cc3 = new ComplementCode(5, "110");

            Assert.IsTrue(cc1.Equals(cc2));
            Assert.IsFalse(cc1.Equals(cc3));
            Assert.IsTrue(cc1 == cc3);
        }
コード例 #6
0
        public void AddTest()
        {
            ComplementCode cc1 = new ComplementCode(5, "11111");
            ComplementCode cc2 = new ComplementCode(5, "1");
            ComplementCode cc3 = new ComplementCode(5);

            cc3 = cc1 + cc2;

            Assert.AreEqual("00000", cc3.ToString());
        }
コード例 #7
0
        public void ShiftTest()
        {
            ComplementCode cc1 = new ComplementCode(5, "10110");

            cc1 >>= 1;
            Assert.AreEqual("01011", cc1.ToString());

            cc1 >>= 3;
            Assert.AreEqual("00001", cc1.ToString());
        }
コード例 #8
0
        public void AdditionTestTwo()
        {
            // 5 + (-5) = 0
            ComplementCode first = new ComplementCode(5, "101");
            ComplementCode second = new ComplementCode(5, "101");

            first = first + -second;

            Assert.AreEqual("00000", first.ToString());
        }
コード例 #9
0
        public void ShiftTest2()
        {
            ComplementCode cc1 = new ComplementCode(5, "10110");

            cc1 <<= 1;
            Assert.AreEqual("01100", cc1.ToString());

            cc1 <<= 2;
            Assert.AreEqual("10000", cc1.ToString());
        }
コード例 #10
0
        public void MultiplyTest()
        {
            //257836 * 583864 = 150541158304
            ComplementCode first = new ComplementCode(40, "111110111100101100");
            ComplementCode second = new ComplementCode(40, "10001110100010111000");

            first = first * second;

            Assert.AreEqual("0010001100001100111100111100011110100000", first.ToString());
        }
コード例 #11
0
        public void AdditionTest()
        {
            //5 + 5 = 10
            ComplementCode first = new ComplementCode(5, "101");
            ComplementCode second = new ComplementCode(5, "101");

            first = first + second;

            Assert.AreEqual("01010", first.ToString());
        }
コード例 #12
0
        public void MultiplyTestTwo()
        {
            // 5 * -2 = -10
            ComplementCode first = new ComplementCode(4, "101");
            ComplementCode second = new ComplementCode(4, "10");

            first = first * -second;
            first = -first;

            Assert.AreEqual("1010", first.ToString());
        }
コード例 #13
0
        public void MinusTest()
        {
            //5 - 7 = (-2)
            ComplementCode first = new ComplementCode(3, "101");
            ComplementCode second = new ComplementCode(3, "111");

            first = first - second;
            first = -first;

            Assert.AreEqual("010", first.ToString());
        }
コード例 #14
0
        public void CreatedTest()
        {
            ComplementCode cc = new ComplementCode(5, "110");
            Assert.AreEqual("00110", cc.ToString());

            cc = new ComplementCode("11010");
            Assert.AreEqual("11010", cc.ToString());

            cc = new ComplementCode(10, "110111");
            Assert.AreEqual("0000110111", cc.ToString());
        }
コード例 #15
0
        public Variable(string value)
        {
            string decRepresentationString = Converter.ConvertToDecNumber(new FromSTDConverter(16), value);
            BigInteger decRepresentationBigInt = BigInteger.Parse(decRepresentationString,
                System.Globalization.NumberStyles.AllowLeadingSign);

            decRepresentationBigInt = decRepresentationBigInt % cLM3BitCapacity;

            ComplementCode complRepresentation = new ComplementCode(
                Converter.Convert(new FromSTDConverter(10), new ToComplCodeConverter(56), decRepresentationBigInt.ToString()));

            mValue = complRepresentation;
        }
コード例 #16
0
        public void EqualTest()
        {
            // 5 = 5
            ComplementCode A = new ComplementCode(5, "101");
            ComplementCode B = new ComplementCode(5, "101");

            Assert.IsTrue(A == B);

            //-5 = -5
            A = new ComplementCode(5, "101");
            A = -A;
            B = new ComplementCode(5, "101");
            B = -B;

            Assert.IsTrue(A == B);
        }
コード例 #17
0
        public void GreatOrEqualTestTwo()
        {
            //3 => 3
            ComplementCode A = new ComplementCode(3, "11");
            ComplementCode B = new ComplementCode(3, "11");

            Assert.IsTrue(A >= B);
        }
コード例 #18
0
 public void GreatOrEqualTestThree()
 {
     //2 => -2
     ComplementCode A = new ComplementCode(3, "10");
     ComplementCode B = new ComplementCode(3, "10");
     B = -B;
     Assert.IsTrue(A >= B);
 }
コード例 #19
0
        public void LessOrEqualTestOne()
        {
            // 3 =< 2
            ComplementCode A = new ComplementCode(3, "11");
            ComplementCode B = new ComplementCode(3, "10");

            Assert.IsTrue(B <= A);
        }
コード例 #20
0
        public void LessOrEqualTestTwo()
        {
            //3 =< 3
            ComplementCode A = new ComplementCode(3, "11");
            ComplementCode B = new ComplementCode(3, "11");

            Assert.IsTrue(A <= B);
        }
コード例 #21
0
 public void LessOrEqualTestThree()
 {
     // 2 =< -2
     ComplementCode A = new ComplementCode(3, "10");
     ComplementCode B = new ComplementCode(3, "10");
     B = -B;
     Assert.IsTrue(B <= A);
 }
コード例 #22
0
        public void ModuleTest()
        {
            ComplementCode cc1 = new ComplementCode(8, "110100");
            ComplementCode cc2 = new ComplementCode(8, "111");

            cc1 %= cc2;
            Assert.AreEqual("00000011", cc1.ToString());
        }
コード例 #23
0
        public void DivideTestThree()
        {
            // 10 / -5 = -2
            ComplementCode A = new ComplementCode(5, "1010");
            ComplementCode B = new ComplementCode(5, "101");

            A = A / -B;

            Assert.AreEqual("11110", A.ToString());
        }
コード例 #24
0
 public void Exeption()
 {
     ComplementCode A = new ComplementCode(-3, "11");
 }
コード例 #25
0
 public void ExeptionOfBitCapacity()
 {
     ComplementCode A = new ComplementCode(3, "11111");
 }
コード例 #26
0
        public void LessTest()
        {
            //2 < 3
            ComplementCode A = new ComplementCode(3, "11");
            ComplementCode B = new ComplementCode(3, "10");

            Assert.IsTrue(B < A);
            //-2 < 2
            A = new ComplementCode(3, "10");
            A = -A;
            B = new ComplementCode(3, "10");
            Assert.IsTrue(A < B);
        }
コード例 #27
0
 public void ExeptionNotANumber()
 {
     ComplementCode A = new ComplementCode(3, "1a2");
 }
コード例 #28
0
        public void MinusTest()
        {
            ComplementCode cc1 = new ComplementCode(5, "00110");

            cc1 = -cc1;
            Assert.AreEqual("11010", cc1.ToString());
        }
コード例 #29
0
        public void LessOrEqualTest()
        {
            ComplementCode cc1 = new ComplementCode(5, "00100");
            ComplementCode cc2 = new ComplementCode(5, "00001");

            Assert.IsFalse(cc1 <= cc2);
        }
コード例 #30
0
 public void ExeptionOfBit()
 {
     ComplementCode A = new ComplementCode(3, "111");
     ComplementCode B = new ComplementCode(7, "1111111");
     ComplementCode C = A * B;
 }