Beispiel #1
0
        public void NumberEqualTest()
        {
            var equal  = new Equal(new Number(10), new Number(10));
            var result = (bool)equal.Execute();

            Assert.True(result);
        }
        public static void TestSymbolism()
        {
            // Create some constants.
            ComputerAlgebra.Expression A = 2;
            ComputerAlgebra.Constant   B = ComputerAlgebra.Constant.New(3);

            // Create some variables.
            ComputerAlgebra.Expression x = "x";
            Variable y = Variable.New("y");

            // Create basic expression with operator overloads.
            ComputerAlgebra.Expression f = A * x + B * y + 4;

            // This expression uses the implicit conversion from string to
            // Expression, which parses the string.
            ComputerAlgebra.Expression g = "5*x + C*y + 8";

            // Create a system of equations from the above expressions.
            var system = new List <Equal>()
            {
                Equal.New(f, 0),
                Equal.New(g, 0),
            };

            // We can now solve the system of equations for x and y. Since the
            // equations have a variable 'C', the solutions will not be
            // constants.
            List <Arrow> solutions = system.Solve(x, y);

            Debug.WriteLine("The solutions are:");
            foreach (Arrow i in solutions)
            {
                Debug.WriteLine(i.ToString());
            }
        }
        public IType Visit(Equal node)
        {
            var leftHandSideValue  = Visit((dynamic)node.Lhs);
            var rightHandSideValue = Visit((dynamic)node.Rhs);

            return(leftHandSideValue.EqualTo(rightHandSideValue));
        }
Beispiel #4
0
        public override Value Visit(Equal node)
        {
            Value left  = node.Left().Accept(this);
            Value right = node.Right().Accept(this);

            return(left.BoolEqual((dynamic)right));
        }
Beispiel #5
0
        private void Operation_Perf(object sender, EventArgs e)
        {
            if (!_infinityCheck)
            {
                Button output = (Button)sender;

                if (_resultValue != 0)
                {
                    Equal.PerformClick();
                    _operatorPerf    = output.Text;
                    Label_Show.Text  = $"{_firstValue} {_operatorPerf}";
                    _boloperatorPerf = true;
                }
                else if (TxtBox.Text.Length <= 0)
                {
                    TxtBox.Text  = Constants.ZeroValue;
                    _resultValue = 0;
                }
                else
                {
                    _operatorPerf    = output.Text;
                    _firstValue      = double.Parse(TxtBox.Text);
                    Label_Show.Text  = $"{_firstValue} {_operatorPerf}";
                    _boloperatorPerf = true;
                }
            }
            else
            {
                Global_Clr.PerformClick();
            }
        }
Beispiel #6
0
        public void CloneTest()
        {
            var exp   = new Equal(new Number(2), new Number(3));
            var clone = exp.Clone();

            Assert.Equal(exp, clone);
        }
Beispiel #7
0
        public void Visit(Equal op)
        {
            var left  = VisitChild(op.Variable);
            var right = VisitChild(op.Literal);

            _codeStack.Peek().Expression = new CodeBinaryOperatorExpression(left.Expression, CodeBinaryOperatorType.IdentityEquality, right.Expression);
        }
Beispiel #8
0
        /**
         * Check if element is exist in heap
         *
         * First: the element which is comparing to
         *
         * Second: the element which will be compared
         **/
        public bool Contain(T element, Equal equal)
        {
            if (equal == null)
            {
                Debug.LogAssertion("Binary Heap must have equal delegate method");
                return(false);
            }

            if (element == null)
            {
                return(false);
            }

            IEnumerator ie = _heap.GetEnumerator();

            while (ie.MoveNext())
            {
                if (equal(element, (T)ie.Current))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #9
0
 public void ArgsEqualWithArrayReferenceEqual()
 {
     object[] arr = new object[3] {
         "1", 2, 4.5f
     };
     Assert.True(Equal.CollectionsAreEqual(new object[] { 1, arr }, new object[] { 1, arr }));
 }
Beispiel #10
0
 public static void Syncronize <TSrc, TTrg>(
     NotifyCollectionChangedAction action,
     IList <TTrg> collection,
     Equal <TTrg, object> eq,
     Converter <TSrc, TTrg> converter,
     IEnumerable items,
     int startAt)
 //where TTrg : ISourceReference<TSrc>
 {
     if (action == NotifyCollectionChangedAction.Add)
     {
         FillCollection(collection, converter, items, startAt);
     }
     else if (action == NotifyCollectionChangedAction.Remove)
     {
         RemoveItems(collection, eq, items);
     }
     else if (action == NotifyCollectionChangedAction.Move)
     {
         foreach (var item in items)
         {
             var found = FindElement(collection, t => eq(t, item));
             collection.Remove(found);
             collection.Insert(startAt++, found);
         }
     }
     else if (action == NotifyCollectionChangedAction.Replace)
     {
     }
     else if (action == NotifyCollectionChangedAction.Reset)
     {
         collection.Clear();
         FillCollection(collection, converter, items, 0);
     }
 }
Beispiel #11
0
        /// <summary>
        /// End analysis of the current context.
        /// </summary>
        public void PopContext()
        {
            // Evaluate the definitions from the context for the equations and add the results to the analysis.
            foreach (Equal i in context.Equations)
            {
                Equal ei = (Equal)Evaluate(i, context.Definitions);
                if (!equations.Contains(ei))
                {
                    equations.Add(ei);
                }
            }
            // And the KCL equations.
            foreach (KeyValuePair <Expression, Expression> i in context.Kcl)
            {
                AddKcl(kcl, i.Key, Evaluate(i.Value, context.Definitions));
            }
            // And the initial conditions.
            initialConditions.AddRange(context.InitialConditions.Evaluate(context.Definitions).OfType <Arrow>());

            foreach (Node i in context.Nodes)
            {
                i.EndAnalysis();
            }

            context = context.Parent;
        }
Beispiel #12
0
        public Value Visit(Equal node)
        {
            Value left  = node.Left().Accept(this);
            Value right = node.Right().Accept(this);

            return(left.Equal(right));
        }
Beispiel #13
0
        private void OP_click(object sender, EventArgs e)
        {
            if (Op_press == false)
            {
                op_cnt = op_cnt + 1;
                if (op_cnt > 1)
                {
                    Equal.PerformClick();
                    op_cnt = 1;
                    Num    = res;
                }
                else
                {
                    Num = Double.Parse(result.Text);
                }


                Button B = (Button)sender;


                Operation = B.Text;

                Op_press      = true;
                equation.Text = equation.Text + " " + result.Text + " " + Operation;
            }
        }
        private ComparisonOperator ComparisonOperator()
        {
            if (this.lexer.Token == null || !this.lexer.Token.Is(TokenType.Name))
            {
                this.SyntaxError("comparision operator");
            }

            ComparisonOperator comparisonOperator = null;

            switch (this.lexer.Token.Value)
            {
            case "pr":
                comparisonOperator = new Present();
                break;

            case "eq":
                comparisonOperator = new Equal();
                break;

            case "ne":
                comparisonOperator = new NotEqual();
                break;

            case "co":
                comparisonOperator = new Contains();
                break;

            case "sw":
                comparisonOperator = new StartsWith();
                break;

            case "ew":
                comparisonOperator = new EndsWith();
                break;

            case "gt":
                comparisonOperator = new GreaterThan();
                break;

            case "lt":
                comparisonOperator = new LessThan();
                break;

            case "ge":
                comparisonOperator = new GreaterThanOrEqual();
                break;

            case "le":
                comparisonOperator = new LessThanOrEqual();
                break;

            default:
                this.SyntaxError("comparision operator");
                break;
            }

            this.Match(this.lexer.Token.Name);
            return(comparisonOperator);
        }
Beispiel #15
0
 public override bool Visit(Equal node)
 {
     traverse(node.left);
     outputCode(" = ", false, false);
     traverse(node.right);
     //Visit((LogicalBinaryExpression) node);
     return(true);
 }
Beispiel #16
0
 public void Visit(Equal n)
 {
     Helpers.Write("(");
     n.LeftExpression.Accept(this);
     Helpers.Write(" == ");
     n.RightExpression.Accept(this);
     Helpers.Write(")");
 }
Beispiel #17
0
 public bool CanAppendEqual(Equal equal)
 {
     if (hasEqual)
     {
         return(false);
     }
     return((lhsOperands.Count - lhsOperators.Count) == 1);
 }
        public void IEnumerable_GetListAndConvertToList()
        {
            var actual   = _mapper.EnumerableMap <DummyA, DummyB>(_listDummyA);
            var expected = _listDummyB;

            Assert.AreEqual(actual.Count(), expected.Count());
            Assert.IsTrue(Equal.IsEqual(actual, expected));
        }
        public void MapFromSmallObjectToBig()
        {
            _dummyA.Age = 0;
            var expeted = _dummyA;
            var actual  = _mapper.Map <DummyC, DummyA>(_dummyC);

            Assert.IsTrue(Equal.IsEqualObject(actual, expeted));
        }
Beispiel #20
0
 public static void RemoveItems <T>(IList <T> collection, Equal <T, object> eq, IEnumerable items)
 {
     foreach (var item in items)
     {
         collection.Remove(
             FindElement(collection, t => eq(t, item)));
     }
 }
        public void MapBetweenToObjectPartialCommonVariable()
        {
            var actual   = _mapper.Map <DummyA, DummyC>(_dummyA);
            var expected = _dummyC;

            Assert.AreEqual(expected.GetType(), actual.GetType());
            Assert.IsTrue(Equal.IsEqualObject(actual, expected));
        }
Beispiel #22
0
        protected Equal <T> CreateEqual(Constant <T> value)
        {
            Equal <T> eq = new Equal <T>()
            {
                Field = this, FieldValue = value
            };

            return(eq);
        }
Beispiel #23
0
        protected Equal <T> CreateEqual(Parameter <T> param)
        {
            Equal <T> eq = new Equal <T>()
            {
                Field = this, FieldValue = param
            };

            return(eq);
        }
Beispiel #24
0
 private void Num9_Click(object sender, EventArgs e)
 {
     Equal.Focus();
     if (Equasion.Text == "0")
     {
         Equasion.Text = "";
     }
     Equasion.Text = Equasion.Text.Insert(Equasion.Text.Length, "9");
 }
Beispiel #25
0
 public bool AppendEqual(Equal equal)
 {
     if (!CanAppendEqual(equal))
     {
         return(false);
     }
     hasEqual = true;
     return(true);
 }
Beispiel #26
0
 /// <summary>
 /// Initializes the <see cref="Ops" /> class.
 /// </summary>
 static Ops()
 {
     Equal              = new Equal();
     GreaterThan        = new GreaterThan();
     GreaterThanOrEqual = new GreaterThanOrEqual();
     LessThan           = new LessThan();
     LessThanOrEqual    = new LessThanOrEqual();
     NotEqual           = new NotEqual();
 }
Beispiel #27
0
        public void Construction()
        {
            var t = (0, "hello");

            Equal(t.Item1, 0);
            Equal(t.Item2, "hello");
            var(x, y) = t;
            Equal(x, 0);
            Equal(y, "hello");
            var(x2, _) = t;
            Equal(x2, 0);

            var ct  = new Tuple <int, int>(2, 3);
            var cvt = new ValueTuple <int, int>(2, 3);

            Equal(ct, (2, 3).ToTuple());
            Equal(cvt, (2, 3));
        }
Beispiel #28
0
 private void Div_Click(object sender, EventArgs e)
 {
     Equal.Focus();
     if (Equasion.Text.EndsWith("+") || Equasion.Text.EndsWith("-") || Equasion.Text.EndsWith("*") || Equasion.Text.EndsWith("/") || Equasion.Text.EndsWith(","))
     {
         Equasion.Text = Equasion.Text.Remove(Equasion.Text.Length - 1);
     }
     Equasion.Text = Equasion.Text.Insert(Equasion.Text.Length, "/");
 }
 /// <summary>
 /// Write instruction operands into bytecode stream.
 /// </summary>
 /// <param name="writer">Bytecode writer.</param>
 public override void WriteOperands(WordWriter writer)
 {
     Pointer.Write(writer);
     Memory.Write(writer);
     Equal.Write(writer);
     Unequal.Write(writer);
     Value.Write(writer);
     Comparator.Write(writer);
 }
Beispiel #30
0
        /// <summary>
        /// Analyzes the specified expression.
        /// </summary>
        /// <param name="exp">The expression.</param>
        /// <returns>The result of analysis.</returns>
        public string Analyze(Equal exp)
        {
            if (exp.Parent is BinaryExpression && !(exp.Parent is While))
            {
                return(ToString(exp, "({0} == {1})"));
            }

            return(ToString(exp, "{0} == {1}"));
        }
 public void EvaluateTest()
 {
     IExpression leftExpr = new Variable("whatever",typeof(decimal),Convert.ToDecimal(11.34)); // TODO: Initialize to an appropriate value
     IExpression rightExpr = new StrategyAnalyzer.DataClass.TradingRuleDefinitions.Decimal(Convert.ToDecimal(11.34)); // TODO: Initialize to an appropriate value
     Equal target = new Equal(leftExpr, rightExpr); // TODO: Initialize to an appropriate value
     bool expected = true; // TODO: Initialize to an appropriate value
     bool actual;
     actual = target.Evaluate(new DateTime());
     Assert.AreEqual(expected, actual);
    // Assert.Inconclusive("Verify the correctness of this test method.");
 }
 public void EqualCorrectlyConvertsToJson()
 {
     var eq = new Equal<string>("basho");
     eq.ToString().ShouldEqual(EqualJson);
 }
Beispiel #33
0
 public void Visit(Equal eq)
 {
     eq.Left.Accept(this);
     _sb.Append(" == ");
     Debug.Assert(eq.Left.Type.Equals(eq.Right.Type));
     eq.Right.Accept(this);
 }
        /**
         * Parses the sublist of tokens.  In most cases this will equate to
         * the full list
         *
         * @param len the length of the subexpression to parse
         * @exception FormulaException
         */
        private void parseSubExpression(int len)
        {
            int tokenVal = 0;
            Token t = null;

            // Indicates that we are parsing the incredibly complicated and
            // hacky if construct that MS saw fit to include, the gits
            Stack<ParseItem> ifStack = new Stack<ParseItem>();

            // The end position of the sub-expression
            int endpos = pos + len;

            while (pos < endpos)
                {
                tokenVal = tokenData[pos];
                pos++;

                t = Token.getToken(tokenVal);

                if (t == Token.UNKNOWN)
                    {
                    throw new FormulaException
                      (FormulaException.UNRECOGNIZED_TOKEN,tokenVal);
                    }

                Assert.verify(t != Token.UNKNOWN);

                // Operands
                if (t == Token.REF)
                    {
                    CellReference cr = new CellReference(relativeTo);
                    pos += cr.read(tokenData,pos);
                    tokenStack.Push(cr);
                    }
                else if (t == Token.REFERR)
                    {
                    CellReferenceError cr = new CellReferenceError();
                    pos += cr.read(tokenData,pos);
                    tokenStack.Push(cr);
                    }
                else if (t == Token.ERR)
                    {
                    ErrorConstant ec = new ErrorConstant();
                    pos += ec.read(tokenData,pos);
                    tokenStack.Push(ec);
                    }
                else if (t == Token.REFV)
                    {
                    SharedFormulaCellReference cr =
                      new SharedFormulaCellReference(relativeTo);
                    pos += cr.read(tokenData,pos);
                    tokenStack.Push(cr);
                    }
                else if (t == Token.REF3D)
                    {
                    CellReference3d cr = new CellReference3d(relativeTo,workbook);
                    pos += cr.read(tokenData,pos);
                    tokenStack.Push(cr);
                    }
                else if (t == Token.AREA)
                    {
                    Area a = new Area();
                    pos += a.read(tokenData,pos);
                    tokenStack.Push(a);
                    }
                else if (t == Token.AREAV)
                    {
                    SharedFormulaArea a = new SharedFormulaArea(relativeTo);
                    pos += a.read(tokenData,pos);
                    tokenStack.Push(a);
                    }
                else if (t == Token.AREA3D)
                    {
                    Area3d a = new Area3d(workbook);
                    pos += a.read(tokenData,pos);
                    tokenStack.Push(a);
                    }
                else if (t == Token.NAME)
                    {
                    Name n = new Name();
                    pos += n.read(tokenData,pos);
                    n.setParseContext(parseContext);
                    tokenStack.Push(n);
                    }
                else if (t == Token.NAMED_RANGE)
                    {
                    NameRange nr = new NameRange(nameTable);
                    pos += nr.read(tokenData,pos);
                    nr.setParseContext(parseContext);
                    tokenStack.Push(nr);
                    }
                else if (t == Token.INTEGER)
                    {
                    IntegerValue i = new IntegerValue();
                    pos += i.read(tokenData,pos);
                    tokenStack.Push(i);
                    }
                else if (t == Token.DOUBLE)
                    {
                    DoubleValue d = new DoubleValue();
                    pos += d.read(tokenData,pos);
                    tokenStack.Push(d);
                    }
                else if (t == Token.BOOL)
                    {
                    BooleanValue bv = new BooleanValue();
                    pos += bv.read(tokenData,pos);
                    tokenStack.Push(bv);
                    }
                else if (t == Token.STRING)
                    {
                    StringValue sv = new StringValue(settings);
                    pos += sv.read(tokenData,pos);
                    tokenStack.Push(sv);
                    }
                else if (t == Token.MISSING_ARG)
                    {
                    MissingArg ma = new MissingArg();
                    pos += ma.read(tokenData,pos);
                    tokenStack.Push(ma);
                    }

                  // Unary Operators
                else if (t == Token.UNARY_PLUS)
                    {
                    UnaryPlus up = new UnaryPlus();
                    pos += up.read(tokenData,pos);
                    addOperator(up);
                    }
                else if (t == Token.UNARY_MINUS)
                    {
                    UnaryMinus um = new UnaryMinus();
                    pos += um.read(tokenData,pos);
                    addOperator(um);
                    }
                else if (t == Token.PERCENT)
                    {
                    Percent p = new Percent();
                    pos += p.read(tokenData,pos);
                    addOperator(p);
                    }

                  // Binary Operators
                else if (t == Token.SUBTRACT)
                    {
                    Subtract s = new Subtract();
                    pos += s.read(tokenData,pos);
                    addOperator(s);
                    }
                else if (t == Token.ADD)
                    {
                    Add s = new Add();
                    pos += s.read(tokenData,pos);
                    addOperator(s);
                    }
                else if (t == Token.MULTIPLY)
                    {
                    Multiply s = new Multiply();
                    pos += s.read(tokenData,pos);
                    addOperator(s);
                    }
                else if (t == Token.DIVIDE)
                    {
                    Divide s = new Divide();
                    pos += s.read(tokenData,pos);
                    addOperator(s);
                    }
                else if (t == Token.CONCAT)
                    {
                    Concatenate c = new Concatenate();
                    pos += c.read(tokenData,pos);
                    addOperator(c);
                    }
                else if (t == Token.POWER)
                    {
                    Power p = new Power();
                    pos += p.read(tokenData,pos);
                    addOperator(p);
                    }
                else if (t == Token.LESS_THAN)
                    {
                    LessThan lt = new LessThan();
                    pos += lt.read(tokenData,pos);
                    addOperator(lt);
                    }
                else if (t == Token.LESS_EQUAL)
                    {
                    LessEqual lte = new LessEqual();
                    pos += lte.read(tokenData,pos);
                    addOperator(lte);
                    }
                else if (t == Token.GREATER_THAN)
                    {
                    GreaterThan gt = new GreaterThan();
                    pos += gt.read(tokenData,pos);
                    addOperator(gt);
                    }
                else if (t == Token.GREATER_EQUAL)
                    {
                    GreaterEqual gte = new GreaterEqual();
                    pos += gte.read(tokenData,pos);
                    addOperator(gte);
                    }
                else if (t == Token.NOT_EQUAL)
                    {
                    NotEqual ne = new NotEqual();
                    pos += ne.read(tokenData,pos);
                    addOperator(ne);
                    }
                else if (t == Token.EQUAL)
                    {
                    Equal e = new Equal();
                    pos += e.read(tokenData,pos);
                    addOperator(e);
                    }
                else if (t == Token.PARENTHESIS)
                    {
                    Parenthesis p = new Parenthesis();
                    pos += p.read(tokenData,pos);
                    addOperator(p);
                    }

                  // Functions
                else if (t == Token.ATTRIBUTE)
                    {
                    Attribute a = new Attribute(settings);
                    pos += a.read(tokenData,pos);

                    if (a.isSum())
                        addOperator(a);
                    else if (a.isIf())
                        {
                        // Add it to a special stack for ifs
                        ifStack.Push(a);
                        }
                    }
                else if (t == Token.FUNCTION)
                    {
                    BuiltInFunction bif = new BuiltInFunction(settings);
                    pos += bif.read(tokenData,pos);

                    addOperator(bif);
                    }
                else if (t == Token.FUNCTIONVARARG)
                    {
                    VariableArgFunction vaf = new VariableArgFunction(settings);
                    pos += vaf.read(tokenData,pos);

                    if (vaf.getFunction() != Function.ATTRIBUTE)
                        addOperator(vaf);
                    else
                        {
                        // This is part of an IF function.  Get the operands, but then
                        // add it to the top of the if stack
                        vaf.getOperands(tokenStack);

                        Attribute ifattr = null;
                        if (ifStack.Count == 0)
                            ifattr = new Attribute(settings);
                        else
                            ifattr = (Attribute)ifStack.Pop();

                        ifattr.setIfConditions(vaf);
                        tokenStack.Push(ifattr);
                        }
                    }

                    // Other things
                else if (t == Token.MEM_FUNC)
                    {
                    MemFunc memFunc = new MemFunc();
                    handleMemoryFunction(memFunc);
                    }
                else if (t == Token.MEM_AREA)
                    {
                    MemArea memArea = new MemArea();
                    handleMemoryFunction(memArea);
                    }
                }
        }
Beispiel #35
0
 public virtual void Visit(Equal node)
 {
 }
 public virtual void VisitEqual(Equal n)
 {
 }
Beispiel #37
0
 public void Visit(Equal eq)
 {
     var leftType = eq.Left.Type as StructType;
     if (leftType != null) {
         eq.Left.Accept(this);
         eq.Right.Accept(this);
         _instructions.Add(Instruction.Create(OpCodes.Callvirt, leftType.TypeEquals));
     } else {
         Visit(eq, OpCodes.Ceq);
     }
 }
 public void Visit(Equal eq)
 {
     eq.Left.Accept(this);
     eq.Right.Accept(this);
     if (!eq.Left.Type.Equals(eq.Right.Type)) {
         throw new TypeCheckException("Both operands of == must have the same type");
     }
     eq.Type = _result = _boolType;
 }
Beispiel #39
0
 public bool CompareShouldBeAffectedIgnoreCase(string left, string right, bool ignoreCase)
 {
     var expression = Expression.Constant("");
     var result = new Equal<CustomEntity>("=", ignoreCase).Compare(expression, OperandBuilder.BuildUp(left), OperandBuilder.BuildUp(right));
     return (bool)Expression.Lambda(result.Expression).Compile().DynamicInvoke();
 }
 public void Visit(Equal eq)
 {
     // Nothing to do here...
 }
        void Comparison(out Expression exp)
        {
            Expression second;
            BitOr(out exp);
            if (StartOf(3)) {
            switch (la.kind) {
            case 29: {
                Get();
                break;
            }
            case 30: {
                Get();
                break;
            }
            case 31: {
                Get();
                break;
            }
            case 32: {
                Get();
                break;
            }
            case 33: {
                Get();
                break;
            }
            case 34: {
                Get();
                break;
            }
            }
            Token tok = t;
            Comparison(out second);
            if (!ExpectInt(exp, tok, false)) { return; };
            if (!ExpectInt(second, tok, true)) { return; };
            if (tok.val == "<") {
                exp = new LessThan((TypedExpression<int>)exp, (TypedExpression<int>)second);
            } else if (tok.val == ">") {
                exp = new GreaterThan((TypedExpression<int>)exp, (TypedExpression<int>)second);
            } else if (tok.val == "<=") {
                exp = new LessThanOrEqual((TypedExpression<int>)exp, (TypedExpression<int>)second);
            } else if (tok.val == ">=") {
                exp = new GreaterThanOrEqual((TypedExpression<int>)exp, (TypedExpression<int>)second);
            } else if (tok.val == "==") {
                exp = new Equal((TypedExpression<int>)exp, (TypedExpression<int>)second);
            } else if (tok.val == "!=") {
                exp = new NotEqual((TypedExpression<int>)exp, (TypedExpression<int>)second);
            }

            }
        }
Beispiel #42
0
 public void SetUp()
 {
     testee = new Equal<CustomEntity>("=");
 }