public void EqualBoolean_Element_CheckParametersPassedDown()
        {
            var lhs = Utilities.GetBoolLitExpression();
            var rhs = Utilities.GetBoolLitExpression();

            List <object> parameters     = Utilities.GetParameterList(4);
            List <object> expectedParams = parameters;
            var           expression     = new EqualExpression(lhs, rhs, 0, 0);

            expression.Type = TypeEnum.Element;
            IInterpreterBoolean parent      = Substitute.For <IInterpreterBoolean>();
            List <object>       lhsParams   = new List <object>();
            List <object>       rhsParams   = new List <object>();
            Element             testElement = new Element(17);

            parent.DispatchElement(lhs, Arg.Do <List <object> >(x => lhsParams = x)).Returns(testElement);
            parent.DispatchElement(rhs, Arg.Do <List <object> >(x => rhsParams = x)).Returns(testElement);

            BooleanHelper booleanHelper = Utilities.GetBooleanHelper(parent);

            booleanHelper.EqualBoolean(expression, parameters);

            Assert.AreEqual(expectedParams, lhsParams);
            Assert.AreEqual(expectedParams, rhsParams);
        }
        private bool IsEqual(ExpressionNode lhs, ExpressionNode rhs, TypeEnum type, List <object> parameters)
        {
            bool res = false;

            if (type == TypeEnum.Boolean)
            {
                bool lhsValue = _interpreter.DispatchBoolean(lhs, parameters);
                bool rhsValue = _interpreter.DispatchBoolean(rhs, parameters);
                res = lhsValue == rhsValue;
            }
            else if (type == TypeEnum.Real)
            {
                double lhsValue = _interpreter.DispatchReal(lhs, parameters);
                double rhsValue = _interpreter.DispatchReal(rhs, parameters);
                res = lhsValue == rhsValue;
            }
            else if (type == TypeEnum.Integer)
            {
                int lhsValue = _interpreter.DispatchInt(lhs, parameters);
                int rhsValue = _interpreter.DispatchInt(rhs, parameters);
                res = lhsValue == rhsValue;
            }
            else if (type == TypeEnum.Function)
            {
                Function lhsValue = _interpreter.DispatchFunction(lhs, parameters);
                Function rhsValue = _interpreter.DispatchFunction(rhs, parameters);
                res = lhsValue.Reference == rhsValue.Reference;
            }
            else if (type == TypeEnum.Set)
            {
                Set lhsValue = _interpreter.DispatchSet(lhs, parameters);
                Set rhsValue = _interpreter.DispatchSet(rhs, parameters);

                res = EquivalentSets(lhsValue, rhsValue);
            }
            else if (type == TypeEnum.Element)
            {
                Element lhsValue = _interpreter.DispatchElement(lhs, parameters);
                Element rhsValue = _interpreter.DispatchElement(rhs, parameters);

                res = lhsValue.Equals(rhsValue);
            }
            else
            {
                throw new Exception($"The type '{type}' cannot be used for equivalence");
            }
            return(res);
        }
        public void EqualBoolean_Element_CorrectValuesReturned(int[] a, int[] b, bool expected)
        {
            Element lhsValue = new Element(a.ToList());
            Element rhsValue = new Element(b.ToList());

            var lhs = Utilities.GetRealLitExpression();
            var rhs = Utilities.GetRealLitExpression();

            EqualExpression expression = new EqualExpression(lhs, rhs, 0, 0);

            expression.Type = TypeEnum.Element;
            IInterpreterBoolean parent = Substitute.For <IInterpreterBoolean>();

            parent.DispatchElement(lhs, Arg.Any <List <object> >()).Returns(lhsValue);
            parent.DispatchElement(rhs, Arg.Any <List <object> >()).Returns(rhsValue);

            BooleanHelper booleanHelper = Utilities.GetBooleanHelper(parent);

            bool res = booleanHelper.EqualBoolean(expression, new List <object>());

            Assert.AreEqual(expected, res);
        }
 private static void DispatchElementForParent(Element elementValue, ElementExpression elementExpression, IInterpreterBoolean parent)
 {
     parent.DispatchElement(elementExpression, Arg.Any <List <object> >()).Returns(elementValue);
 }