Example #1
0
 public void LoadCalculatorAsset()
 {
     InputBuffer       = new InputBuffer();
     Operators         = new OperatorLookup();
     UnitConverter     = new AngleConverter();
     OperatorConverter = new OperatorConverter(Operators.Operators, Operators.Unary);
     Parenthesizer     = new Parenthesizer(Operators.Precedence);
     ExpressionBuilder = new ExpressionBuilder(Parenthesizer);
     ExpressionParser  = new ExpressionParser(OperatorConverter);
     Evaluator         = new Evaluator(UnitConverter, OperatorConverter, Operators);
     MemoryStorage     = new MemoryStorage();
 }
        public void CheckTrigonometricKey()
        {
            var lookup = new OperatorLookup();

            Assert.AreEqual(lookup.SineDEG, calculator.CheckTrigonometricKey("sin"));

            calculator.ChangeAngularUnit();

            Assert.AreEqual(lookup.SineRAD, calculator.CheckTrigonometricKey("sin"));

            calculator.ChangeAngularUnit();

            Assert.AreEqual(lookup.SineGRAD, calculator.CheckTrigonometricKey("sin"));

            calculator.ChangeAngularUnit();

            Assert.AreEqual(lookup.SineDEG, calculator.CheckTrigonometricKey("sin"));
        }
Example #3
0
 /// <summary>
 /// Gets unary operator of the same result type as its operand.
 /// </summary>
 /// <param name="op">Unary operator type.</param>
 /// <param name="lookup">Operator resolution strategy.</param>
 /// <returns>Unary operator.</returns>
 /// <exception cref="MissingOperatorException">Operator doesn't exist.</exception>
 public static UnaryOperator <T, T> Require(UnaryOperator op, OperatorLookup lookup = OperatorLookup.Any) => Require <T>(op, lookup);
Example #4
0
 /// <summary>
 /// Gets unary operator.
 /// </summary>
 /// <param name="op">Unary operator type.</param>
 /// <param name="lookup">Operator resolution strategy.</param>
 /// <typeparam name="TResult">Result of unary operator.</typeparam>
 /// <returns>Unary operator.</returns>
 /// <exception cref="MissingOperatorException">Operator doesn't exist.</exception>
 public static UnaryOperator <T, TResult> Require <TResult>(UnaryOperator op, OperatorLookup lookup = OperatorLookup.Any) => Get <TResult>(op, lookup) ?? throw MissingOperatorException.Create <T>(op);
Example #5
0
 /// <summary>
 /// Gets unary operator of the same result type as its operand.
 /// </summary>
 /// <param name="op">Unary operator type.</param>
 /// <param name="lookup">Operator resolution strategy.</param>
 /// <returns>Unary operator; or <see langword="null"/>, if it doesn't exist.</returns>
 public static UnaryOperator <T, T>?Get(UnaryOperator op, OperatorLookup lookup = OperatorLookup.Any) => Get <T>(op, lookup);
Example #6
0
 /// <summary>
 /// Gets unary operator.
 /// </summary>
 /// <param name="op">Unary operator type.</param>
 /// <param name="lookup">Operator resolution strategy.</param>
 /// <typeparam name="TResult">Result of unary operator.</typeparam>
 /// <returns>Unary operator; or <see langword="null"/>, if it doesn't exist.</returns>
 public static UnaryOperator <T, TResult>?Get <TResult>(UnaryOperator op, OperatorLookup lookup = OperatorLookup.Any) => UnaryOperator <T, TResult> .GetOrCreate(op, lookup);
Example #7
0
 /// <summary>
 /// Gets unary operator.
 /// </summary>
 /// <param name="op">Unary operator type.</param>
 /// <param name="lookup">Operator resolution strategy.</param>
 /// <typeparam name="R">Result of unary operator.</typeparam>
 /// <returns>Unary operator; or <see langword="null"/>, if it doesn't exist.</returns>
 public static UnaryOperator <T, R>?Get <R>(UnaryOperator op, OperatorLookup lookup = OperatorLookup.Any) => UnaryOperator <T, R> .GetOrCreate(op, lookup);
Example #8
0
 public void Setup()
 {
     lookup = new OperatorLookup();
 }