示例#1
0
 /// <summary>
 /// Constructor with a moving vector
 /// and an arithmetic function
 /// </summary>
 /// <param name="m">move</param>
 /// <param name="f">function</param>
 public Line(MovingVector m, Arithmetic f)
 {
     this.move      = m;
     this.function  = f;
     this.terms     = f.UnknownTerms.Values.Cast <UnknownTerm>().ToList();
     this.nameTerms = new List <string>(Convert.ToInt32(this.move.Dimension));
     this.result    = new MovingVector(1);
 }
示例#2
0
        public void TestMethod1()
        {
            int W = 25;
            int Z = 30;
            int H = Arithmetic.Add(W, Z);

            Assert.AreEqual(30, H);
        }
示例#3
0
 public override void Animate(InGameEngine engine)
 {
     if (AnimatedObject == null)
     {
         return;
     }
     AnimatedObject.Rotation = Arithmetic.RealAngle(AnimatedObject.Rotation + Speed /* * (Aim - AnimatedObject.Rotation < 180 ? 1 : -1)*/);
 }
示例#4
0
 public OpBuilder Arithmetic(Register regA, Register regB, Arithmetic op)
 {
     _ops.Write((short)Op.Arithmetic);
     _ops.Write((byte)regA);
     _ops.Write((byte)regB);
     _ops.Write((byte)op);
     return(this);
 }
示例#5
0
        public void TestMethod1()
        {
            int a = 10;
            int b = 20;
            int c = Arithmetic.Add(a, b);

            Assert.AreEqual(30, c);
        }
        static void Main(string[] args)
        {
            List <Animal> animalList = new List <Animal>();
            List <int>    numList    = new List <int>();

            numList.Add(24);
            animalList.Add(new Animal()
            {
                Name = "Doug"
            });
            animalList.Add(new Animal()
            {
                Name = "Paul"
            });
            animalList.Add(new Animal()
            {
                Name = "Sally"
            });
            animalList.Insert(1, new Animal()
            {
                Name = "Steve"
            });
            animalList.RemoveAt(1);
            Console.WriteLine("Num of Animals : {0}", animalList.Count);
            foreach (Animal a in animalList)
            {
                Console.WriteLine(a.Name);
            }
            Stack <Animal>           stack      = new Stack <Animal>();
            Queue <Animal>           queue      = new Queue <Animal>();
            Dictionary <int, Animal> dictionary = new Dictionary <int, Animal>();

            Console.WriteLine();
            int x = 5, y = 4;

            Animal.GetSum(ref x, ref y);
            string strX = "5", strY = "4";

            Animal.GetSum(ref strX, ref strY);
            Rectangle <int> rec1 = new Rectangle <int>(20, 50);

            Console.WriteLine(rec1.GetArea());
            Rectangle <string> rec2 = new Rectangle <string>("20", "50");

            Console.WriteLine(rec2.GetArea());
            Console.WriteLine();
            Arithmetic add, sub, addSub;

            add    = new Arithmetic(Add);
            sub    = new Arithmetic(Subtract);
            addSub = add + sub;
            Console.WriteLine("Add 6 & 10");
            add(6, 10);
            Console.WriteLine("Add & Subtract 10 & 4");
            addSub(10, 4);

            Console.ReadKey();
        }
        public void Subtract_GivenTheories(decimal left, decimal right, decimal expected)
        {
            // arrange - done by theories
            // act
            decimal actual = Arithmetic.Subtract(left, right);

            // assert
            Assert.Equal(expected, actual);
        }
示例#8
0
        public Edge GetEdge(int i)
        {
            i = Arithmetic.Wrap(i, 0, _Vertices.Length - 1);
            int j = Arithmetic.Wrap(i + 1, 0, _Vertices.Length - 1);

            return(new Edge {
                Start = _TranslatedVertices[i], End = _TranslatedVertices[j]
            });
        }
示例#9
0
 public void VisitArithmetic(Arithmetic arithmetic)
 {
     arithmetic.Left.Visit(this);
     if (arithmetic.Right != null)
     {
         _builder.Append(" ").Append(ArithmeticOperators[(int)arithmetic.Operator]).Append(" ");
         arithmetic.Right.Visit(this);
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        public async Task <(int Code, byte[] Audio)> GenerateAsync(CaptchaOptions options)
        {
            await Task.FromResult(0);

            var(equation, answer) = Arithmetic.Build(options);
            var audio = Speech.Generate(equation.ToString(" "));

            return(answer, audio);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        public async Task <(int Code, Image Image)> GenerateAsync(CaptchaOptions options)
        {
            await Task.FromResult(0);

            var(equation, answer) = Arithmetic.Build(options);
            var image = Image.Generate(equation, options);

            return(answer, image);
        }
示例#12
0
        string Calc(string[] param)
        {
            //func.Calc([exp])

            string expression = param[0];
            string result     = Arithmetic.Calculation(expression);

            return(result);
        }
示例#13
0
        public void Mathematics_Arithmetic_AverageDecimal()
        {
            List <decimal> data = new List <decimal>()
            {
                1, 1, 3, 3
            };

            Assert.IsTrue(Arithmetic.AverageDecimal(data) == 2);
        }
示例#14
0
        private static double EstimateDifficulty(ProblemSpec problem)
        {
            var    ratSegments   = problem.Segments.Where(s => Arithmetic.IsSquare(s.QuadratOfLength)).ToList();
            double ratSegCount   = ratSegments.Count;
            double smallSegCount = problem.Segments.Count(s => s.IrrationalLength < 1d / 8);
            double blackPoints   = problem.Points.Count(p => !ratSegments.Any(s => s.IsEndpoint(p)));

            return(ratSegCount / 10 + smallSegCount / 3 + blackPoints);
        }
示例#15
0
        public override void Start()
        {
            Logger.Start("计算器");

            Arithmetic calc   = new Arithmetic();
            object     result = calc.Compute("2 + (23) - 2");

            Logger.Write(result);
        }
示例#16
0
        public static int Hash(DataType a, DataType b, Arithmetic arithmetic)
        {
            var hash = 0;

            hash |= (int)a;
            hash |= (int)b << 8;
            hash |= (int)arithmetic << 16;
            return(hash);
        }
示例#17
0
        static void Main(string[] args)
        {
            //ArithmeticOperations arithmeticOperations = new ArithmeticOperations();
            Console.Write("Enter Number1:");
            double num1 = Convert.ToDouble(Console.ReadLine());

            Console.Write("Enter Number2:");
            double num2 = Convert.ToDouble(Console.ReadLine());

            Console.WriteLine("1.Add");
            Console.WriteLine("2.Multiply");
            Console.WriteLine("3.Divide");
            Console.WriteLine("4.Subtract");
            Console.WriteLine("5.Max");
            Console.Write("Enter your Choice:");
            int ch = (int.Parse)(Console.ReadLine());

            switch (ch)
            {
            case 1:
            {
                Arithmetic arithmetic = new Arithmetic(ArithmeticOperations.Add);
                Console.WriteLine(arithmetic(num1, num2));
            }
            break;

            case 2:
            {
                Arithmetic arithmetic = new Arithmetic(ArithmeticOperations.Multiply);
                Console.WriteLine(arithmetic(num1, num2));
            }
            break;

            case 3:
            {
                Arithmetic arithmetic = new Arithmetic(ArithmeticOperations.Divide);
                Console.WriteLine(arithmetic(num1, num2));
            }
            break;

            case 4:
            {
                Arithmetic arithmetic = new Arithmetic(ArithmeticOperations.subtract);
                Console.WriteLine(arithmetic(num1, num2));
            }
            break;

            case 5:
            {
                Arithmetic arithmetic = new Arithmetic(ArithmeticOperations.Max);
                Console.WriteLine(arithmetic(num1, num2));
            }
            break;
            }

            Console.Read();
        }
示例#18
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));
        }
示例#19
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();
        }
示例#20
0
        static void Main(string[] args)
        {
            Arithmetic obj = new Arithmetic();

            obj.accept();
            Console.WriteLine(obj.add());
            Console.WriteLine(obj.sub());
            Console.WriteLine(obj.mul());
            Console.WriteLine(obj.div());
        }
 /// <summary>
 /// Set function(x) and rec(f)
 /// </summary>
 /// <param name="f">arithmetic function</param>
 /// <param name="inv">inverted</param>
 public void SetFunction(Arithmetic f, params Arithmetic[] inv)
 {
     this.function = f.Clone() as Arithmetic;
     this.inverted = new Arithmetic[inv.Length];
     for (int index = 0; index < inv.Length; ++index)
     {
         this.inverted[index] = inv[index].Clone() as Arithmetic;
     }
     this.points = this.bounds.GenerateMove();
 }
示例#22
0
        /// <summary>
        /// Returns the probability distribution function.
        /// </summary>
        /// <param name="k"></param>
        /// <returns></returns>
        public double ProbabilityDistributionFunction(int k)
        {
            if (k < 0)
            {
                throw new ArgumentException();
            }
            int r = this.n - k;

            return(System.Math.Exp(this.log_n - Arithmetic.LogFactorial(k) - Arithmetic.LogFactorial(r) + this.log_p * k + this.log_q * r));
        }
示例#23
0
        /// <summary>
        /// Main Thread
        /// </summary>
        static void Main()
        {
            string solution = "0";

            for (int i = 1; i <= 1000; i++)
            {
                solution = Arithmetic.AddNumbers(solution, Arithmetic.ModPow(i.ToString(), i, 10000000000));
            }

            Console.WriteLine("Solution: {0} ", solution[^ 10..]);
示例#24
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"));
 }
示例#25
0
        private Arithmetic.Fraction<int> getFractionNearestToNWithDenominatorM(Arithmetic.Fraction<int> n, int m)
        {
            int q = (m * n.Numerator) / n.Denominator;

            while (NumberTheory.GCD(q, m) != 1)
            {
                q--;
            }

            return new Arithmetic.Fraction<int>(q, m);
        }
示例#26
0
        public void GivenTwoIntegers_WhenSubtractIsCall_ThenIntegerIsReturned()
        {
            // var mockArithmetic = new Mock<Arithmetic>();
            var target = new Arithmetic();

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

            // Assert
            Assert.AreEqual(actual, 1);
        }
示例#27
0
        public void GivenTwoIntegers_WhenMultiplyIsCall_ThenIntegerIsReturned()
        {
            // var mockArithmetic = new Mock<Arithmetic>();
            var target = new Arithmetic();

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

            // Assert
            Assert.AreEqual(actual, 2);
        }
示例#28
0
        public static void Sample(string[] args)
        {
            Arithmetic add    = new Arithmetic(Add);//the name of the function will be passed as param
            Arithmetic sub    = new Arithmetic(Sub);
            Arithmetic addSub = add + sub;
            Arithmetic sub2   = addSub - sub;

            add(5, 4);
            addSub(10, 4);
            sub2(6, 5);
        }
示例#29
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);
        }
示例#30
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) { }
 }
示例#31
0
    /// <summary>
    /// Converts a color to HSI (hue-saturation-intensity).
    /// </summary>
    /// <param name="value">The color to get HSI values.</param>
    /// <returns>The HSI tuple: hue [0°..360°], saturation [0..1] and value [0..1].</returns>
    public static (double h, double s, double i) ToHSI(Color value)
    {
        if (value.R == 0 && value.G == 0 && value.B == 0)
        {
            return(0d, 0d, 0d);
        }
        var intensity = (value.R / 255d + value.G / 255d + value.B / 255d) / 3d;
        var min       = Arithmetic.Min(value.R, value.G, value.B) / 255d;

        return(value.GetHue(), 1d - (min / intensity), intensity);
    }
示例#32
0
    public void Initialize()
    {
        objects = new Dictionary<string, GameObject>();
        //the keyword THIS should be a GameObject refering to the Root GameObject
        objects.Add("xbuild", Root.gameObject);

        variables = new Dictionary<string, XBGameObject>();
        numbers = new Dictionary<string, double>();
        structures = new Dictionary<string, XBStructure>();
        sensors = new List<string>();

        logic = new Logic(this);
        arithmetic = new Arithmetic(this);

        StateStack = new Stack<XBInterpreterState>();
        loopStates = new Stack<LoopState>();
        BlockStates = new Stack<BlockType>();

        GameObject[] allObjs = GameObject.FindObjectsOfType(typeof(GameObject)) as GameObject[];
        foreach (GameObject go in allObjs)
        {
            //Debug.Log("Object name: " + go.name);
            if (go.activeInHierarchy)
            {
                if (go.name == null) continue;
                bool valid = false;
                foreach(string tag in VALID_TAGS)
                {
                    if(go.CompareTag(tag))
                    {
                        valid = true;
                        break;
                    }
                }
                if(valid)
                    objects.Add(go.name.ToLower(), go);
            }
        }

        functions = new Dictionary<string, XBFunction>();
        StartSensorUpdate = true;
    }