public void EqualBoolean_Set_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.Set;
            IInterpreterBoolean parent    = Substitute.For <IInterpreterBoolean>();
            List <object>       lhsParams = new List <object>();
            List <object>       rhsParams = new List <object>();
            Set testSet = new Set(new Element(17));

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

            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_Set_CorrectValuesReturned(int leftDataRow, int rightDataRow, bool expected)
        {
            Set lhsValue = GetSet(leftDataRow);
            Set rhsValue = GetSet(rightDataRow);

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

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

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

            parent.DispatchSet(lhs, Arg.Any <List <object> >()).Returns(lhsValue);
            parent.DispatchSet(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 DispatchSetForParent(Set setValue, SetExpression setExpression, IInterpreterBoolean parent)
 {
     parent.DispatchSet(setExpression, Arg.Any <List <object> >()).Returns(setValue);
 }