示例#1
0
        public void Calculate_Addition_Test_30()
        {
            double a = 10, b = 20;

            A.CallTo(() => m.Add(a, b)).Returns(30);
            Assert.AreEqual(30, m.Add(a, b));
        }
示例#2
0
        /// <summary>
        /// Updates the position, rotation and associated momentum using RK4 integration.
        /// </summary>
        /// <param name="rigidbody">The object to be updated.</param>
        /// <param name="deltaTime">The length of the normal time-step.</param>
        public static void Integrate(Rigidbody rigidbody, float deltaTime)
        {
            // Cache anything calculated multiple times.
            var halfDelta = deltaTime / 2f;
            var sixth     = 1f / 6f;

            // RK4 uses four evaulations to create values to weight.
            var first  = Evaluation.Evaluate(rigidbody);
            var second = Evaluation.Evaluate(rigidbody, first, halfDelta);
            var third  = Evaluation.Evaluate(rigidbody, second, halfDelta);
            var fourth = Evaluation.Evaluate(rigidbody, third, deltaTime);

            // Now we use Taylor Series expansion to weight the values: 1/6 * (dxdt1 + 2 * (dxdt2 + dxdt3) + dxdt4).
            var velocity = sixth * (first.velocity + 2f * (second.velocity + third.velocity) + fourth.velocity);
            var force    = sixth * (first.force + 2f * (second.force + third.force) + fourth.force);
            var torque   = sixth * (first.torque + 2f * (second.torque + third.torque) + fourth.torque);

            // Since Unity doesn't support scaling and adding Quaternions the spin is going to be ugly....
            var spin = Maths.Scale(sixth, Maths.Add(Maths.Add(first.spin, Maths.Scale(2f, Maths.Add(second.spin, third.spin))), fourth.spin));

            // Finally set the correct position and momentum.
            rigidbody.position        += velocity * deltaTime;
            rigidbody.rotation         = Maths.Add(rigidbody.rotation, Maths.Scale(spin, deltaTime));
            rigidbody.momentum        += force * deltaTime;
            rigidbody.angularMomentum += torque * deltaTime;
        }
示例#3
0
文件: TestUtil.cs 项目: vkiktev/NxBRE
        public void MathOperators()
        {
            Assert.AreEqual(3, Maths.Multiply(3), "3 * = 3");
            Assert.AreEqual(10, Maths.Multiply(2, 5), "2 * 5 = 10");
            Assert.AreEqual(-210, Maths.Multiply(2, 5, -3, 7), "2 * 5 * -3 * 7 = -210");

            Assert.AreEqual(2.5, Maths.Multiply(2.5), "2.5 * = 2.5");
            Assert.AreEqual(-8.75, Maths.Multiply(2.5, -3.5), "2.5 * (-3.5) = -8.75");
            Assert.AreEqual(37.625, Maths.Multiply(2.5, 3.5, 4.3), "2.5 * 3.5 * 4.3 = 37.625");

            Assert.AreEqual(3, Maths.Add(3), "3 + = 3");
            Assert.AreEqual(7, Maths.Add(2, 5), "2 + 5 = 7");
            Assert.AreEqual(-3, Maths.Add(2, 5, -3, -7), "2 + 5 + (-3) + (-7) = -3");

            Assert.AreEqual(2.5, Maths.Add(2.5), "2.5 + = 2.5");
            Assert.AreEqual(-1.0, Maths.Add(2.5, -3.5), "2.5 + (-3.5) = -1.0");
            Assert.AreEqual(1.7, Maths.Add(2.5, 3.5, -4.3), "2.5 + 3.5 + (-4.3) = 1.7");

            Assert.AreEqual(3, Maths.Subtract(3), "3 - = 3");
            Assert.AreEqual(-3, Maths.Subtract(2, 5), "2 - 5 = -3");
            Assert.AreEqual(7, Maths.Subtract(2, 5, -3, -7), "2 - 5 - (-3) - (-7) = 7");

            Assert.AreEqual(2.5, Maths.Subtract(2.5), "2.5 - = 2.5");
            Assert.AreEqual(6.0, Maths.Subtract(2.5, -3.5), "2.5 - (-3.5) = 6.0");
            Assert.AreEqual(3.3, Maths.Subtract(2.5, 3.5, -4.3), "2.5 - 3.5 - (-4.3) = 3.3");

            Assert.AreEqual(3, Maths.Divide(3), "3 / = 3");
            Assert.AreEqual(4, Maths.Divide(20, 5), "20 / 5 = 4");
            Assert.AreEqual(1, Maths.Divide(100, 5, -4, -5), "100 / 5 / (-4) / (-5) = 1");

            Assert.AreEqual(2.5d, Maths.Divide(2.5d), "2.5 / = 2.5");
            Assert.AreEqual(.4d, Maths.Divide(2d, 5d), "2 / 5 = .4");
            Assert.AreEqual(.1d, Maths.Divide(2d, 5d, -.4d, -10d), "2 / 5 / (-.4) / (-10) = .1");
        }
        public virtual dynamic CalculateInterest(double _princamt, double _rate, double _year, int denominator)
        {
            Maths m = new Maths();

            if (_princamt < 0 || _rate < 0 || _year < 0)
            {
                return("error");
            }

            try
            {
                _interest = m.Divide(m.Multiply(_princamt, m.Multiply(_rate, _year)), denominator);

                if (denominator == 0)
                {
                    tot_amt = 0;
                }
                else
                {
                    tot_amt = m.Add(_princamt, _interest);
                }
            }
            catch
            {
                tot_amt = 0;
            }



            return(tot_amt);
        }
示例#5
0
 public IActionResult Add([FromQuery] int?num1, int?num2)
 {
     if (!num1.HasValue || !num2.HasValue)
     {
         return(BadRequest());
     }
     return(Ok(Maths.Add(num1.Value, num2.Value)));
 }
示例#6
0
        public void TestAdd()
        {
            float one = 2.0f, two = 3.0f, expected = 5.0f;
            float actual;

            actual = Maths.Add(one, two);
            Assert.AreEqual(expected, actual);
        }
示例#7
0
//        [Ignore("Because I love it")]
        public void Add_WhenCalled_ReturnTheSumOfArguments()
        {
            //  var math = new Maths();

            var result = _math.Add(1, 2);

            Assert.AreEqual(result, 3);
        }
示例#8
0
        static void Main(string[] args)
        {
            Console.WriteLine("Program TestNUnit");
            Maths add = new Maths();

            Console.WriteLine(add.Add(1, 2));

            Console.ReadLine();
        }
示例#9
0
        static void Main(string[] args)
        {
            Maths obj = new Maths();

            while (true)
            {
                Console.WriteLine("Enter Value of X");
                string data1 = Console.ReadLine();
                int    i     = Convert.ToInt32(data1);

                Console.WriteLine("Enter Value of Y");
                string data2 = Console.ReadLine();
                int    j     = Convert.ToInt32(data2);

                Console.WriteLine("Enter Your Operation Choice");
                Console.WriteLine("1: Add, 2: Sub, 3: Mult, 4: Div");
                string choice = Console.ReadLine();
                int    ch     = Convert.ToInt32(choice);

                switch (ch)
                {
                case 1:

                    int sum = obj.Add(i, j);
                    Console.WriteLine("Sum is " + sum.ToString());
                    break;

                case 2:
                    int sub = obj.Sub(i, j);
                    Console.WriteLine("Sub is " + sub.ToString());
                    break;

                case 3:
                    int mult = obj.Mult(i, j);
                    Console.WriteLine("Mult is " + mult.ToString());
                    break;


                case 4:
                    int div = obj.Div(i, j);
                    Console.WriteLine("Div is " + div.ToString());
                    break;

                default:
                    Console.WriteLine("Invalid Choice!!");
                    break;
                }

                Console.WriteLine("Hit Enter to Continue Doing Operations...");
                Console.ReadLine();
            }
        }
示例#10
0
        public IActionResult Add(OperationsParameters parameters)
        {
            double a = parameters.a;
            double b = parameters.b;

            if (a == 0 || b == 0)
            {
                return(NoContent());
            }

            var result = new ApiResponse
            {
                status = "success",
                result = _maths.Add(a, b)
            };

            return(Ok(result));
        }
 public void WhenTheTwoNumbersAreAdded()
 {
     _result = _maths.Add(_num1, _num2);
 }
示例#12
0
 public void Calculate_Addition_Test_30(double a, double b)
 {
     A.CallTo(() => m.Add(a, b)).Returns(30);
     Assert.AreEqual(30, m.Add(a, b));
 }
示例#13
0
        public IActionResult AddNumbers(int num1, int num2)
        {
            string sum = Maths.Add(num1, num2);

            return(View("Results", sum));
        }
示例#14
0
 public void Should_get_sum(int sum, int x, int y)
 {
     Assert.Equal(sum, Maths.Add(x, y));
 }
示例#15
0
        public void Return5(long lhs, long rhs)
        {
            var result = Maths.Add(lhs, rhs);

            Assert.Equal(5, result);
        }
 public double Add(double x, double y)
 {
     return(maths.Add(x, y));
 }
 public void WhenIPressAdd()
 {
     output = app.Add(input1, input2);
 }