Exemplo n.º 1
0
        public void Add()
        {
            Arithmetic a   = new Arithmetic();
            int        res = a.Add(1, 2);

            Assert.Equal(3, res);
        }
Exemplo n.º 2
0
        public void AddMultiple(int parmaA, int parmaB)
        {
            Arithmetic a   = new Arithmetic();
            int        res = a.Add(parmaA, parmaB);

            Assert.Equal(parmaA + parmaB, res);
        }
Exemplo n.º 3
0
        public void Add_Ok()
        {
            Arithmetic arithmetic = new Arithmetic();
            var        sum        = arithmetic.Add(1, 2);

            Assert.True(sum == 3);
        }
Exemplo n.º 4
0
 //tests if display isnt empty, tests for which sign was pressed to calculate accordingly
 // or displays an error for missing number
 private void Equals()
 {
     if (!String.IsNullOrEmpty(txtboxDisplay.Text))
     {
         if (plusClick == true)
         {
             calcNumTwo = Arithmetic.Add(calcNumOne, DoubleParse(txtboxDisplay.Text));
         }
         else if (minusClick == true)
         {
             calcNumTwo = Arithmetic.Sub(calcNumOne, DoubleParse(txtboxDisplay.Text));
         }
         else if (divideClick == true)
         {
             calcNumTwo = Arithmetic.Div(calcNumOne, DoubleParse(txtboxDisplay.Text));
         }
         else if (multiplyClick == true)
         {
             calcNumTwo = Arithmetic.Mult(calcNumOne, DoubleParse(txtboxDisplay.Text));
         }
     }
     else
     {
         MessageBox.Show("Missing number", "Error Message");
     }
 }
Exemplo n.º 5
0
        public void Add_No(int nb1, int nb2, int result)
        {
            Arithmetic arithmetic = new Arithmetic();
            var        sum        = arithmetic.Add(nb1, nb2);

            Assert.False(sum == result);
        }
Exemplo n.º 6
0
        public void Add_Ok_Two(int num1, int num2, int result)
        {
            Arithmetic arithmetic = new Arithmetic();
            var        sum        = arithmetic.Add(num1, num2);

            Assert.True(sum == result);
        }
Exemplo n.º 7
0
        public void AddTest()
        {
            Arithmetic a = new Arithmetic();
            int        c = a.Add(-10, -20);

            Assert.AreEqual(c, 30);
        }
Exemplo n.º 8
0
        public void TestMethod1()
        {
            int H = 10;
            int F = 20;
            int K = Arithmetic.Add(H, F);

            Assert.AreEqual(30, K);
        }
Exemplo n.º 9
0
        public void TestMethod1()
        {
            int a = 10;
            int b = 20;
            int c = Arithmetic.Add(a, b);

            Assert.AreEqual(30, c);
        }
Exemplo n.º 10
0
        public void TestMethod1()
        {
            int W = 25;
            int Z = 30;
            int H = Arithmetic.Add(W, Z);

            Assert.AreEqual(30, H);
        }
Exemplo n.º 11
0
        public void TestAddIntMaxValue()
        {
            var maxint    = int.MaxValue;
            var increment = 1;
            var result    = Arithmetic.Add(int.MaxValue, increment);

            Assert.AreEqual(increment + maxint, result);
        }
        public void Add_GivenTheories(decimal left, decimal right, decimal expected)
        {
            // arrange - done by theories
            // act
            decimal actual = Arithmetic.Add(left, right);

            // assert
            Assert.Equal(expected, actual);
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            int a = 10, b = 6;

            Console.WriteLine(Arithmetic.Add(a, b));
            Console.WriteLine(Arithmetic.Subtract(a, b));
            Console.WriteLine(Arithmetic.Multiply(a, b));
            Console.WriteLine(Arithmetic.Divide(a, b));
        }
Exemplo n.º 14
0
        private void btnEquals_Click(object sender, EventArgs e)
        {
            input = Parser(txtboxInputOutput.Text);

            if (btnPlusClicked == true)
            {
                output = Arithmetic.Add(temp, input);
            }

            else if (btnMinusClicked == true)
            {
                output = Arithmetic.Subtract(temp, input);
            }

            else if (btnDivideClicked == true)
            {
                output = Arithmetic.Divide(temp, input);
            }

            else if (btnMultiplyClicked == true)
            {
                output = Arithmetic.Multiply(temp, input);
            }

            else if (btnInverseClicked == true)
            {
                output = Algebraic.Inverse(input);
            }

            else if (btnSquareRootClicked == true)
            {
                output = Algebraic.SquareRoot(input);
            }

            else if (btnCubeRootClicked == true)
            {
                output = Algebraic.CubeRoot(input);
            }

            else if (btnTanClicked == true)
            {
                output = Trigonometric.Tan(input);
            }

            else if (btnSinClicked == true)
            {
                output = Trigonometric.Sine(input);
            }

            else if (btnCosClicked == true)
            {
                output = Trigonometric.Cosine(input);
            }

            txtboxInputOutput.Text = output.ToString();
        }
Exemplo n.º 15
0
 public static void CompiledOperationsTest()
 {
     Assert.Equal(3, Arithmetic.Add(1, 2));
     Assert.Equal(1, Arithmetic.Subtract(2, 1));
     Assert.Equal(8, Arithmetic.Multiply(2, 4));
     Assert.Equal(4, Arithmetic.Divide(8, 2));
     Assert.Equal(2, Arithmetic.Increment(1));
     Assert.Equal(1UL, Arithmetic.Decrement(2UL));
     Assert.Throws <NotSupportedException>(() => Arithmetic <string> .Subtract("1", "2"));
 }
Exemplo n.º 16
0
 public void TestAdd()
 {
     Assert.AreEqual(-97, Arithmetic.Add(-49, -48));
     Assert.AreEqual(-3, Arithmetic.Add(-1, -2));
     Assert.AreEqual(0, Arithmetic.Add(-1, 1));
     Assert.AreEqual(97, Arithmetic.Add(49, 48));
     try {
         Arithmetic.Add(-49, -50);
         Assert.Fail("Add should have thrown an exceptin");
     } catch (Exception) { }
 }
Exemplo n.º 17
0
        public void Add_2_Plus_2_Equals_4()
        {
            //Arrange
            //Nothing to arrange

            //Act
            int result = Arithmetic.Add(2, 2);

            //Assert
            Assert.Equal(4, result);
        }
Exemplo n.º 18
0
        public void GivenTwoIntegers_WhenAddIsCall_ThenIntegerIsReturned()
        {
            // var mockArithmetic = new Mock<Arithmetic>();
            var target = new Arithmetic();

            // Act
            var actual = target.Add(1, 2);

            // Assert
            Assert.AreEqual(actual, 3);
        }
        public void Add_GivenData(decimal left, decimal right, decimal expected)
        {
            // arrange - done by data rows

            // act
            decimal actual = Arithmetic.Add(left, right);

            // assert
            Assert.AreEqual(expected, actual);

            // CollectionAssert.
            // StringAssert.
        }
Exemplo n.º 20
0
        static void Main(string[] args)
        {
            Arithmetic proxy = new Arithmetic();

            proxy.Url = "http://localhost/server/arithmetic.asmx";
            Add add = new Add();

            add.n1 = 10;
            add.n2 = 20;
            AddResponse resp = proxy.Add(add);

            Console.WriteLine("10 + 20 = " + resp.sum);
        }
Exemplo n.º 21
0
        public void TestValidAdd()
        {
            var actual = Arithmetic.Add(-50, -50);

            Assert.AreEqual(-50 + -50, actual, "n50 fail");
            actual = Arithmetic.Add(-49, -49);
            Assert.AreEqual(-49 + -49, actual, "n49 fail");
            actual = Arithmetic.Add(0, 0);
            Assert.AreEqual(0 + 0, actual, "0 fail");
            actual = Arithmetic.Add(49, 49);
            Assert.AreEqual(49 + 49, actual, "49 fail");
            actual = Arithmetic.Add(50, 50);
            Assert.AreEqual(50 + 50, actual, "50 fail");
        }
Exemplo n.º 22
0
        public static void Run()
        {
            var    arith = new Arithmetic();
            double a     = 5;
            double b     = 15;
            double sum   = arith.Add(a, b);
            double sub   = arith.Substract(a, b);
            double diff  = arith.Difference(a, b);

            Console.WriteLine("Numbers: {0} and {1}\r\n", a, b);
            Console.WriteLine("Sum: " + sum);
            Console.WriteLine("Substraction: " + sub);
            Console.WriteLine("Difference: " + diff);
            Console.WriteLine("Absolute value of -3: " + Arithmetic.MathAbs(-3));
        }
Exemplo n.º 23
0
        private void PerfTestInternal <T>(int count)
        {
            // Random random = RandomManager.CreateRandom(SeedVariatorType.CallingMethod);
            IInstanceGenerator <T> generator = InstanceGeneratorProvider.Default.GetInstanceGenerator <T>();
            T instance1 = generator.GetInstance(random);
            T instance2 = generator.GetInstance(random);
            Arithmetic <T> arithmetic = Arithmetic <T> .Default;

            using (new Measurement(typeof(T).Name, count)) {
                for (int i = 0; i < count; i++)
                {
                    arithmetic.Add(instance1, instance2);
                }
            }
        }
Exemplo n.º 24
0
        public void AddRegistersWithCarry(byte a, byte b)
        {
            var registerFile = InitialRegisterFile.WithRegister(0, a).WithRegister(1, b).WithStatusRegister(sr => sr.WithCarry(true));

            byte c = (byte)(a + b + 1);

            registerFile = Arithmetic.Add(registerFile, 0, 1, new object[] { true });

            Assert.AreEqual(a + b + 1 > 255, registerFile.StatusRegister.C, "Carry");
            Assert.AreEqual(c == 0, registerFile.StatusRegister.Z, "Zero");
            Assert.AreEqual((a & 0xf) + (b & 0xf) > 0xf, registerFile.StatusRegister.H, "Half carry");
            Assert.AreEqual((a >= 128 && b >= 128 && c < 128) || (a < 128 && b < 128 && c >= 128), registerFile.StatusRegister.V, "Two's complement overflow");
            Assert.AreEqual(registerFile.StatusRegister.N ^ registerFile.StatusRegister.V, registerFile.StatusRegister.S, "Sign");
            Assert.AreEqual(c >= 128, registerFile.StatusRegister.N, "Negative");
            Assert.AreEqual(c, registerFile[0], "Result");
        }
Exemplo n.º 25
0
        public void Add()
        {
            void Test(int x, int y) => Assert.AreEqual(x + y, Arithmetic.Add(x, y));

            foreach (var i in ExtremeValues)
            {
                foreach (var j in ExtremeValues)
                {
                    Test(i, j);
                }
            }

            for (int i = 0; i < 1000; i++)
            {
                Test(NextInt32(), NextInt32());
            }
        }
Exemplo n.º 26
0
        public void Test()
        {
            const int count = 100;

            Assert.IsNull(Arithmetic <string> .Default);
            Arithmetic <long>   longArithmetic   = Arithmetic <long> .Default;
            Arithmetic <double> doubleArithmetic = Arithmetic <double> .Default;
            Arithmetic <int>    intArithmetic    = Arithmetic <int> .Default;

            Assert.IsNotNull(longArithmetic);
            Assert.IsNotNull(doubleArithmetic);
            Assert.IsNotNull(intArithmetic);
            Assert.AreEqual(longArithmetic.Implementation.GetType().Name, "Int64Arithmetic");
            Assert.AreEqual(intArithmetic.Implementation.GetType().Name, "Int32Arithmetic");
            Assert.AreEqual(doubleArithmetic.Implementation.GetType().Name, "DoubleArithmetic");
            checked {
                IEnumerable <long> longValues = InstanceGeneratorProvider.Default.GetInstanceGenerator <long>().GetInstances(random, count);
                foreach (long longValue in longValues)
                {
                    AssertEx.ResultsAreEqual <long>(() => (long)(longValue / 12.34d), () => longArithmetic.Divide(longValue, 12.34d));
                    AssertEx.ResultsAreEqual <long>(() => (long)(longValue * 12.34d), () => longArithmetic.Multiply(longValue, 12.34d));
                    AssertEx.ResultsAreEqual <long>(() => longValue + longValue, () => longArithmetic.Add(longValue, longValue));
                    AssertEx.ResultsAreEqual <long>(() => longValue - longValue, () => longArithmetic.Subtract(longValue, longValue));
                    AssertEx.ResultsAreEqual <long>(() => - longValue, () => longArithmetic.Negation(longValue));
                }
                IEnumerable <int> intValues = InstanceGeneratorProvider.Default.GetInstanceGenerator <int>().GetInstances(random, count);
                foreach (int intValue in intValues)
                {
                    AssertEx.ResultsAreEqual <int>(() => (int)(intValue / 12.34d), () => intArithmetic.Divide(intValue, 12.34d));
                    AssertEx.ResultsAreEqual <int>(() => (int)(intValue * 12.34d), () => intArithmetic.Multiply(intValue, 12.34d));
                    AssertEx.ResultsAreEqual <int>(() => intValue + intValue, () => intArithmetic.Add(intValue, intValue));
                    AssertEx.ResultsAreEqual <int>(() => intValue - intValue, () => intArithmetic.Subtract(intValue, intValue));
                    AssertEx.ResultsAreEqual <int>(() => - intValue, () => intArithmetic.Negation(intValue));
                }
                IEnumerable <double> doubleValues = InstanceGeneratorProvider.Default.GetInstanceGenerator <double>().GetInstances(random, count);
                foreach (double doubleValue in doubleValues)
                {
                    AssertEx.ResultsAreEqual <double>(() => doubleValue / 12.34d, () => doubleArithmetic.Divide(doubleValue, 12.34d));
                    AssertEx.ResultsAreEqual <double>(() => doubleValue * 12.34d, () => doubleArithmetic.Multiply(doubleValue, 12.34d));
                    AssertEx.ResultsAreEqual <double>(() => doubleValue + doubleValue, () => doubleArithmetic.Add(doubleValue, doubleValue));
                    AssertEx.ResultsAreEqual <double>(() => doubleValue - doubleValue, () => doubleArithmetic.Subtract(doubleValue, doubleValue));
                    AssertEx.ResultsAreEqual <double>(() => - doubleValue, () => doubleArithmetic.Negation(doubleValue));
                }
            }
        }
Exemplo n.º 27
0
 public LinkFrequency <TLink> IncrementFrequency(ref Doublet <TLink> doublet)
 {
     if (_doubletsCache.TryGetValue(doublet, out LinkFrequency <TLink> data))
     {
         data.IncrementFrequency();
     }
     else
     {
         var link = _links.SearchOrDefault(doublet.Source, doublet.Target);
         data = new LinkFrequency <TLink>(_one, link);
         if (!_equalityComparer.Equals(link, default))
         {
             data.Frequency = Arithmetic.Add(data.Frequency, _frequencyCounter.Count(link));
         }
         _doubletsCache.Add(doublet, data);
     }
     return(data);
 }
Exemplo n.º 28
0
        static void Main(string[] args)
        {
            Arithmetic Art = new Arithmetic();

            Console.WriteLine("Enter First Number :-");
            double first = double.Parse(Console.ReadLine());

            Console.WriteLine("Enter Second Number :-");
            double second = double.Parse(Console.ReadLine());

            Console.WriteLine("-----------------");
            Console.WriteLine(" Enter 1 for ADDITION \n Enter 2 for SUBTRACTION \n Enter 3 for MULTIPLICATION \n ENTER 4 for DIVISION \n ENTER 5 for MODULUS \n ENTER 6 for exit");
            Console.WriteLine("-----------------");
            int no = int.Parse(Console.ReadLine());

            switch (no)
            {
            case 1:
                Console.WriteLine("Addition is :-", Art.Add(first, second));
                break;

            case 2:
                Console.WriteLine("Subtraction is :-" Art.Sub(first, second));
                break;

            case 3:
                Console.WriteLine("Multiplication is :-" Art.Multi(first, second));
                break;

            case 4:
                Console.WriteLine("Division is :-" Art.Divd(first, second));
                break;

            case 5:
                Console.WriteLine("Modulus is :-" Art.Mod(first, second));
                break;

            case 6:
                Console.WriteLine("You selected exit");
                break;
            }
            Console.ReadKey();
        }
Exemplo n.º 29
0
        public static TLink CountUsages <TLink>(this ILinks <TLink> links, TLink link)
        {
            var   constants        = links.Constants;
            var   values           = links.GetLink(link);
            TLink usagesAsSource   = links.Count(new Link <TLink>(constants.Any, link, constants.Any));
            var   equalityComparer = EqualityComparer <TLink> .Default;

            if (equalityComparer.Equals(values[constants.SourcePart], link))
            {
                usagesAsSource = Arithmetic <TLink> .Decrement(usagesAsSource);
            }
            TLink usagesAsTarget = links.Count(new Link <TLink>(constants.Any, constants.Any, link));

            if (equalityComparer.Equals(values[constants.TargetPart], link))
            {
                usagesAsTarget = Arithmetic <TLink> .Decrement(usagesAsTarget);
            }
            return(Arithmetic <TLink> .Add(usagesAsSource, usagesAsTarget));
        }
        public AtomicActionRendererTest()
        {
            _record         = new RecordingActionRenderer <Arithmetic>();
            _renderer       = new AtomicActionRenderer <Arithmetic>(_record);
            _fx             = new IntegerSet(new BigInteger?[] { 0 }, null, new[] { _renderer });
            (_successTx, _) = _fx.Sign(
                0,
                Arithmetic.Add(1),
                Arithmetic.Mul(2),
                Arithmetic.Add(3)
                );

            // failing transaction; should not be rendered:
            _fx.Sign(
                0,
                Arithmetic.Add(1),
                new Arithmetic(),
                Arithmetic.Add(3)
                );
            _record.ResetRecords();
        }