Exemplo n.º 1
0
 public void UnaryConstructorTest()
 {
     UnaryOperators op = new UnaryOperators(); // TODO: Initialize to an appropriate value
     float expression = 0F; // TODO: Initialize to an appropriate value
     Unary target = new Unary(op, expression);
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
Exemplo n.º 2
0
 public UnaryOperatorExpression(
     UnaryOperators @operator,
     ExpressionBase <T> operand
     )
 {
     Operator = @operator;
     Operand  = operand;
 }
Exemplo n.º 3
0
 public Predicate(string operand, UnaryOperators unaryOperator)
 {
     if (unaryOperator == UnaryOperators.Not)
     {
         ExpressionValue = "NOT (" + operand + ")";
     }
     else if (unaryOperator == UnaryOperators.IsNull)
     {
         ExpressionValue = operand + " IS NULL";
     }
     else if (unaryOperator == UnaryOperators.IsNotNull)
     {
         ExpressionValue = operand + " IS NOT NULL";
     }
     else
     {
         throw new NotImplementedException();
     }
 }
Exemplo n.º 4
0
 public Glossary()
 {
     ReservedWords = OtherReservedWords.Union(Types)
                     .Union(Conditions).Union(Cycles).ToList();
     UnaryOperators = IncDecOperators.Union(UnaryBinary).Union(new List <string> {
         "!", "~"
     }).ToList();
     Operators =
         BinaryOperatorsByPriority.Union(UnaryOperators).Union(AssignationOperators).ToList();
     Operators.Remove("?");
     Operators.Remove(".");
     ConsiderAsUnary    = UnaryOperators.Union(Types).ToList();
     Brackets           = OpeningBrackets.Select(b => b + ClosingBrackets[OpeningBrackets.IndexOf(b)]).ToList();
     LexemesOfTokenType = new Dictionary <TokenType, List <string> >
     {
         { TokenType.OpeningBracket, OpeningBrackets },
         { TokenType.ClosingBracket, ClosingBrackets },
         { TokenType.Punctuation, Punctuation },
         { TokenType.ReservedWord, ReservedWords },
         { TokenType.Operator, Operators },
         { TokenType.Quote, Quotes }
     };
 }
Exemplo n.º 5
0
 public static string AsString(this UnaryOperators @operator) =>
 @operator switch
 {
Exemplo n.º 6
0
 public Unary(UnaryOperators op, bool expression)
     : this(op, new ConstantTypes.Bit(expression))
 {
     //
 }
Exemplo n.º 7
0
 public Unary(UnaryOperators op, int expression)
     : this(op, new ConstantTypes.Integer(expression))
 {
     //
 }
Exemplo n.º 8
0
 public Unary(UnaryOperators op, float expression)
     : this(op, new ConstantTypes.Float(expression))
 {
     //
 }
Exemplo n.º 9
0
 public Unary(UnaryOperators op, decimal expression)
     : this(op, new ConstantTypes.Decimal(expression))
 {
     //
 }
Exemplo n.º 10
0
 public Unary(UnaryOperators op, System.DateTime expression)
     : this(op, new ConstantTypes.DateTime(expression))
 {
     //
 }
Exemplo n.º 11
0
 public Unary(UnaryOperators op, Expression expression)
 {
     Expression = expression;
     Operator = op;
 }
        protected override void MetaOperate(List <MutableObject> entryList, UnaryOperators operation)
        {
            switch (operation)
            {
            case UnaryOperators.Value:
                foreach (var subEntry in Operand.GetEntries(entryList))
                {
                    OutputValue.SetValue(Operand.GetValue(subEntry), subEntry);
                }
                break;

            case UnaryOperators.Abs:
                foreach (var subEntry in Operand.GetEntries(entryList))
                {
                    OutputValue.SetValue(Mathf.Abs(Operand.GetValue(subEntry)), subEntry);
                }
                break;

            case UnaryOperators.Sum:
                float total = 0;
                foreach (var subEntry in Operand.GetEntries(entryList))
                {
                    total += Operand.GetValue(subEntry);
                }
                foreach (var subEntry in OutputValue.GetEntries(entryList))
                {
                    OutputValue.SetValue(total, subEntry);
                }
                break;

            case UnaryOperators.Average:
                total = 0;
                int count = 0;
                foreach (var subEntry in Operand.GetEntries(entryList))
                {
                    total += Operand.GetValue(subEntry);
                    count++;
                }
                total /= count;
                foreach (var subEntry in OutputValue.GetEntries(entryList))
                {
                    OutputValue.SetValue(total, subEntry);
                }
                break;

            case UnaryOperators.Max:
                float max = float.MinValue;
                foreach (var subEntry in Operand.GetEntries(entryList))
                {
                    var foundVal = Operand.GetValue(subEntry);
                    if (max < foundVal)
                    {
                        max = foundVal;
                    }
                }
                foreach (var subEntry in OutputValue.GetEntries(entryList))
                {
                    OutputValue.SetValue(max, subEntry);
                }
                break;

            case UnaryOperators.Min:
                float min = float.MaxValue;
                foreach (var subEntry in Operand.GetEntries(entryList))
                {
                    var foundVal = Operand.GetValue(subEntry);
                    if (min > foundVal)
                    {
                        min = foundVal;
                    }
                }
                foreach (var subEntry in OutputValue.GetEntries(entryList))
                {
                    OutputValue.SetValue(min, subEntry);
                }
                break;

            case UnaryOperators.Accumulate:
                total = 0f;
                foreach (var subEntry in Operand.GetEntries(entryList))
                {
                    total += Operand.GetValue(subEntry);

                    OutputValue.SetValue(total, subEntry);
                }
                break;

            case UnaryOperators.Diff:
                bool first = true;
                var  prior = 0f;
                foreach (var subEntry in Operand.GetEntries(entryList))
                {
                    var foundEntry = Operand.GetValue(subEntry);
                    prior = foundEntry - prior;

                    if (first)
                    {
                        first = false;
                        OutputValue.SetValue(0f, subEntry);
                        prior = foundEntry;
                        continue;
                    }

                    OutputValue.SetValue(prior, subEntry);
                    prior = foundEntry;
                }
                break;

            case UnaryOperators.Sign:
                foreach (var subEntry in Operand.GetEntries(entryList))
                {
                    OutputValue.SetValue((Operand.GetValue(subEntry) >= 0?1f:-1f), subEntry);
                }
                break;

            case UnaryOperators.Sin:
                foreach (var subEntry in Operand.GetEntries(entryList))
                {
                    OutputValue.SetValue(Mathf.Sin(Operand.GetValue(subEntry)), subEntry);
                }
                break;

            case UnaryOperators.Cos:
                foreach (var subEntry in Operand.GetEntries(entryList))
                {
                    OutputValue.SetValue(Mathf.Cos(Operand.GetValue(subEntry)), subEntry);
                }
                break;

            case UnaryOperators.Tan:
                foreach (var subEntry in Operand.GetEntries(entryList))
                {
                    OutputValue.SetValue(Mathf.Tan(Operand.GetValue(subEntry)), subEntry);
                }
                break;

            default:
                throw new Exception("Unknown operation type!");
            }
        }
Exemplo n.º 13
0
 public UnaryExpression(SourceLocation location, UnaryOperators @operator, Expression argument) : base(location)
 {
     this.Operator = @operator;
     this.Argument = argument;
 }
Exemplo n.º 14
0
        public void Test()
        {
            BinaryOperators o1 = new BinaryOperators()
            {
                X = 20, Y = 12
            };
            BinaryOperators o2 = new BinaryOperators()
            {
                X = 30, Y = 38
            };
            BinaryOperators o3 = o1 + o2;

            o3 += 2;
            Console.WriteLine("o3.X {0}, o3.Y {1}", o3.X, o3.Y);

            UnaryOperators uOp1 = new UnaryOperators()
            {
                X = 100, Y = 200
            };

            Console.WriteLine("uOp1.X {0}, uOp1.Y {1}", uOp1.X, uOp1.Y);
            uOp1++;
            ++uOp1;
            Console.WriteLine("uOp1.X {0}, uOp1.Y {1}", uOp1.X, uOp1.Y);

            EqualityOperator eo1 = new EqualityOperator()
            {
                X = 100, Y = 200
            };
            EqualityOperator eo2 = new EqualityOperator()
            {
                X = 100, Y = 200
            };

            Console.WriteLine("eo1 == eo2 {0}   eo1.Equals(eo2) {1} ", eo1 == eo2, eo1.Equals(eo2));
            ComparisonOperator co1 = new ComparisonOperator()
            {
                X = 2, Y = 2
            };
            ComparisonOperator co3 = new ComparisonOperator()
            {
                X = 6, Y = 6
            };
            ComparisonOperator co2 = new ComparisonOperator()
            {
                X = 4, Y = 4
            };

            Console.WriteLine(" co1 < co2  {0}", co1 < co2);
            Console.WriteLine(" co1 < co2  {0}", co1 > co2);
            Console.WriteLine(" co3 < co2  {0}", co3 > co2);


            CustomConversionA customA = new CustomConversionA()
            {
                Description = "My Description"
            };
            CustomConversionC customC = new CustomConversionC()
            {
                Description = "My Description"
            };

            CustomConversionB customBfromA    = (CustomConversionB)customA;
            CustomConversionB customBfromCex  = (CustomConversionB)customC;
            CustomConversionB customBfromCimp = customC;

            Console.WriteLine("CustomBfromA : {0}", customBfromA.ReverseDescription);
            Console.WriteLine("CustomBfromC(explicit) :  {0}", customBfromCex.ReverseDescription);
            Console.WriteLine("CustomBfromC(implpicit) : {0}", customBfromCimp.ReverseDescription);
        }
Exemplo n.º 15
0
 protected abstract void MetaOperate(List <MutableObject> entryList, UnaryOperators operation);
        protected override void MetaOperate(List <MutableObject> entryList, UnaryOperators operation)
        {
            switch (operation)
            {
            case UnaryOperators.Value:
                foreach (var subEntry in Operand.GetEntries(entryList))
                {
                    OutputValue.SetValue(Operand.GetValue(subEntry), subEntry);
                }
                break;

            case UnaryOperators.Accumulate:
                var total = Vector3.zero;
                foreach (var subEntry in Operand.GetEntries(entryList))
                {
                    total += Operand.GetValue(subEntry);

                    OutputValue.SetValue(total, subEntry);
                }
                break;

            case UnaryOperators.Diff:
                bool first = true;
                var  prior = Vector3.zero;
                foreach (var subEntry in Operand.GetEntries(entryList))
                {
                    var foundEntry = Operand.GetValue(subEntry);
                    prior = foundEntry - prior;

                    if (first)
                    {
                        first = false;
                        OutputValue.SetValue(0, subEntry);
                        prior = foundEntry;
                        continue;
                    }

                    OutputValue.SetValue(prior, subEntry);
                    prior = foundEntry;
                }
                break;

            case UnaryOperators.Sign:
                foreach (var subEntry in Operand.GetEntries(entryList))
                {
                    OutputValue.SetValue(Vector3.Normalize(Operand.GetValue(subEntry)), subEntry);
                }
                break;

            case UnaryOperators.Sin:
                foreach (var subEntry in Operand.GetEntries(entryList))
                {
                    var result = Operand.GetValue(subEntry);
                    OutputValue.SetValue(
                        new Vector3(
                            Mathf.Sin(result.x),
                            Mathf.Sin(result.y),
                            Mathf.Sin(result.z)), subEntry);
                }
                break;

            case UnaryOperators.Cos:
                foreach (var subEntry in Operand.GetEntries(entryList))
                {
                    var result = Operand.GetValue(subEntry);
                    OutputValue.SetValue(
                        new Vector3(
                            Mathf.Cos(result.x),
                            Mathf.Cos(result.y),
                            Mathf.Cos(result.z)), subEntry);
                }
                break;

            case UnaryOperators.Tan:
                foreach (var subEntry in Operand.GetEntries(entryList))
                {
                    var result = Operand.GetValue(subEntry);
                    OutputValue.SetValue(
                        new Vector3(
                            Mathf.Tan(result.x),
                            Mathf.Tan(result.y),
                            Mathf.Tan(result.z)), subEntry);
                }
                break;

            default:
                throw new Exception("Unhandled operation type!");
            }
        }