private RealHelper SetUpHelper(IInterpreterReal parent)
        {
            RealHelper realHelper = new RealHelper();

            realHelper.SetInterpreter(parent);
            return(realHelper);
        }
        public void ExportReal_Real_ReturnsCorrectResult(double input, double expected)
        {
            RealLiteralExpression realLit    = new RealLiteralExpression(input, 1, 1);
            ExportNode            exportNode = new ExportNode(realLit, 1, 1);
            IInterpreterReal      parent     = Substitute.For <IInterpreterReal>();

            parent.DispatchReal(realLit, Arg.Any <List <object> >()).Returns(input);
            RealHelper realHelper = SetUpHelper(parent);

            double res = realHelper.ExportReal(exportNode, new List <object>());

            Assert.AreEqual(expected, res);
        }
        public void CastIntegerToReal_Int_ReturnsCorrectResult(int input, double expected)
        {
            RealLiteralExpression     realLit  = new RealLiteralExpression(input, 1, 1);
            CastFromIntegerExpression castExpr = new CastFromIntegerExpression(realLit, 1, 1);
            IInterpreterReal          parent   = Substitute.For <IInterpreterReal>();

            parent.DispatchInt(realLit, Arg.Any <List <object> >()).Returns(input);
            RealHelper realHelper = SetUpHelper(parent);

            double res = realHelper.CastIntegerToReal(castExpr, new List <object>());

            Assert.AreEqual(expected, res);
        }
        public void ModuloReal_DivisorIsZero_ThrowsException(double input1, double input2)
        {
            RealLiteralExpression realLit1   = new RealLiteralExpression(input1, 1, 1);
            RealLiteralExpression realLit2   = new RealLiteralExpression(input2, 2, 2);
            ModuloExpression      moduloExpr = new ModuloExpression(realLit1, realLit2, 1, 1);
            IInterpreterReal      parent     = Substitute.For <IInterpreterReal>();

            parent.DispatchReal(realLit1, Arg.Any <List <object> >()).Returns(input1);
            parent.DispatchReal(realLit2, Arg.Any <List <object> >()).Returns(input2);
            RealHelper realHelper = SetUpHelper(parent);

            Assert.ThrowsException <DivisionByZeroException>(() => realHelper.ModuloReal(moduloExpr, new List <object>()));
        }
        public void SubtractionReal_TwoReals_ReturnsCorrectResult(double input1, double input2, double expected)
        {
            RealLiteralExpression realLit1        = new RealLiteralExpression(input1, 1, 1);
            RealLiteralExpression realLit2        = new RealLiteralExpression(input2, 2, 2);
            SubtractionExpression subtractionExpr = new SubtractionExpression(realLit1, realLit2, 1, 1);
            IInterpreterReal      parent          = Substitute.For <IInterpreterReal>();

            parent.DispatchReal(realLit1, Arg.Any <List <object> >()).Returns(input1);
            parent.DispatchReal(realLit2, Arg.Any <List <object> >()).Returns(input2);
            RealHelper realHelper = SetUpHelper(parent);

            double res = realHelper.SubtractionReal(subtractionExpr, new List <object>());

            Assert.AreEqual(expected, res);
        }
        public void NegativeReal_Real_CorrectNegativeValue(double input, double expected)
        {
            RealLiteralExpression realLitExpr = new RealLiteralExpression(input, 0, 0);

            NegativeExpression negExpr = new NegativeExpression(new List <ExpressionNode>()
            {
                realLitExpr
            }, 0, 0);

            IInterpreterReal parent = Substitute.For <IInterpreterReal>();

            parent.DispatchReal(realLitExpr, Arg.Any <List <object> >()).Returns(input);
            RealHelper realHelper = SetUpHelper(parent);

            double res = realHelper.NegativeReal(negExpr, new List <object>());

            Assert.AreEqual(expected, res);
        }
Exemplo n.º 7
0
 public void SetInterpreter(IInterpreterReal interpreter)
 {
     _interpreter = interpreter;
 }