public void UpdateSettings(Variable resultVariable, ArithmeticOp operation, Variable variable, int value) { this.resultVariable = resultVariable; this.operation = operation; this.variable = variable; this.value = value; }
public void ArithmeticOpTests_Divide_SmallThanTolerance_ShouldThrow() { var op = new ArithmeticOp(Operator.Division); var denominator = AppConstants.Tolerance - 1e-5; Assert.Throws <DivideByZeroException>(() => op.Divide(1, denominator)); }
public void ArithmeticOpTests_Divide_BiggerThanTolerance_Pass() { var op = new ArithmeticOp(Operator.Division); var denominator = AppConstants.Tolerance + 1e-5; var result = op.Divide(1, denominator); Assert.Equal(1 / denominator, result); }
public MathAction(string key, Variable resultVariable, ArithmeticOp operation, Variable variable, int value) { this.key = key; this.operation = operation; this.resultVariable = resultVariable; this.variable = variable; this.value = value; }
public ArithmeticNode(ArithmeticNode opHolder, ArithmeticOp unaryOp, ArithmeticNode applyTo) { this.op = unaryOp.op; this.ops.Add(unaryOp); this.children.Add(applyTo); applyTo.parent = this; applyTo.merged = true; opHolder.parent = this; opHolder.merged = true; this.arithemeticType = ArithmeticType.MergedUnaryOperator; }
public void TestCreateArithmeticOp03() { ArithmeticOp arithmeticOp = CreateArithmeticOp03(); Assert.IsNotNull(arithmeticOp); #region Record State ValueRecorder recorder = new ValueRecorder(); recorder.Record((OperatorPriority)arithmeticOp.Priority); recorder.FinishRecording(); #endregion }
private static Word ArithmeticOperation( ArithmeticOp op, Word word1, Word word2, out Boolean overflow) { Int16 i16Val1 = word1.GetAsSigned(); Int16 i16Val2 = word2.GetAsSigned(); Int32 i32Val = op(i16Val1, i16Val2); Int16 i16Result = NumberUtils.ToInt16(i32Val); overflow = NumberUtils.CheckInt16Overflow(i32Val); return(new Word(i16Result)); }
public ArithExpr(INumberTerm t1, ArithmeticOp oper, INumberTerm t2) : base(oper.ToString(), 2) { AddTerm(t1); AddTerm(t2); op = oper; if (t1.GetSrcInfo() != null) { srcInfo = t1.GetSrcInfo(); } else { srcInfo = t2.GetSrcInfo(); } }
public ArithmeticNode(ArithmeticNode opHolder, ArithmeticOp binaryOp, ArithmeticNode applyToA, ArithmeticNode applyToB) { this.op = binaryOp.op; this.ops.Add(binaryOp); this.children.Add(applyToA); applyToA.parent = this; applyToA.merged = true; applyToB.parent = this; applyToB.merged = true; opHolder.parent = this; opHolder.merged = true; this.children.Add(applyToB); this.arithemeticType = ArithmeticType.MergedBinaryOperator; }
protected override void SaveSettings() { Variable resultVariable = GraphManager.GetVariable(this.cbResult.SelectedItem.ToString()); ArithmeticOp operation = (ArithmeticOp)Enum.ToObject(typeof(ArithmeticOp), this.cbOperator.SelectedIndex); Variable variable = null; int value = 0; if (this.cbOperand.SelectedIndex != 0) { variable = GraphManager.GetVariable(this.cbOperand.SelectedItem.ToString()); } else { value = (int)this.nudOperandValue.Value; } this.action.UpdateSettings(resultVariable, operation, variable, value); }
public MathAction(string key, XmlElement properties, System.Collections.Generic.SortedList <string, Variable> variables) { this.key = key; if (properties.Name != "properties") { throw new ActionException("Can't create the action"); } foreach (XmlElement property in properties.ChildNodes) { switch (property.Name) { case "version": break; case "resultVariable": if (property.InnerText != "none") { this.resultVariable = variables[property.InnerText]; } break; case "variable": if (property.InnerText != "none") { this.variable = variables[property.InnerText]; } break; case "operation": this.operation = (ArithmeticOp)Enum.Parse(typeof(ArithmeticOp), property.InnerText); break; case "value": this.value = System.Convert.ToInt32(property.InnerText); break; default: throw new ProjectException("Error el crear la acción"); } } }
public override void Visit(ArithmeticOp op, Node n) { VisitScalarOpDefault(op, n); switch (op.OpType) { case OpType.Plus: case OpType.Minus: case OpType.Multiply: case OpType.Divide: case OpType.Modulo: AssertEqualTypes(n.Child0.Op.Type, n.Child1.Op.Type); AssertEqualTypes(n.Op.Type, n.Child0.Op.Type); AssertArity(n, 2); break; case OpType.UnaryMinus: AssertArity(n, 1); break; default: AssertUnexpectedOp(op); break; } }
public void Subtraction() { var subop = new ArithmeticOp("-", op1, op2, 0); var assignment = new Assignment(resultdecl, subop, 0); program.Add(assignment); interpreter.Run(new Program(program)); Assert.That(interpreter.Valuetable[symboltable.resolve("result")], Is.EqualTo(3)); }
public void ArithmeticOperationTest() { var integer = new IntegerLiteral("9", 0); var plus = new ArithmeticOp("+", integer, integer, 0); var times = new ArithmeticOp("*", plus, integer, 0); var div = new ArithmeticOp("/", integer, integer, 0); var minus = new ArithmeticOp("-", times, div, 0); var variable = new VariableDeclaration("foo", "int", 0); var assignment = new Assignment(variable, minus, 0); statementlist.Add(assignment); var parsetree = new Program(statementlist); Assert.DoesNotThrow(() => symbolTableBuilder.BuildSymbolTableAndTypeCheck(parsetree)); }
/// <summary> /// Visitor pattern method for ArithmeticOp /// </summary> /// <param name="op"> The ArithmeticOp being visited </param> /// <param name="n"> The Node that references the Op </param> public virtual void Visit(ArithmeticOp op, Node n) { VisitScalarOpDefault(op, n); }
/// <summary> /// Copies an ArithmeticOp /// </summary> /// <param name="op">The Op to Copy</param> /// <param name="n">The Node that references the Op</param> /// <returns>A copy of the original Node that references a copy of the original Op</returns> public override Node Visit(ArithmeticOp op, Node n) { return(CopyDefault(m_destCmd.CreateArithmeticOp(op.OpType, op.Type), n)); }
public void DivisionByZero() { var divop = new ArithmeticOp("/", op1, new IntegerLiteral("0", 0), 0); var assignment = new Assignment(resultdecl, divop, 0); program.Add(assignment); Assert.Throws<MiniPLDivisionByZero>(() => interpreter.Run(new Program(program))); }
public void FaultyArithmetic() { var variable = new VariableDeclaration("foo", "int", 0); var integer = new IntegerLiteral("42", 0); var stringlit = new StringLiteral("\"foobar\"", 0); var plus = new ArithmeticOp("+", integer, integer, 0); var times = new ArithmeticOp("*", stringlit, plus, 0); var assignment = new Assignment(variable, times, 0); statementlist.Add(assignment); var parsetree = new Program(statementlist); Assert.Throws<SemanticError>(() => symbolTableBuilder.BuildSymbolTableAndTypeCheck(parsetree)); }
public void Multiplication() { var multop = new ArithmeticOp("*", op1, op2, 0); var assignment = new Assignment(resultdecl, multop, 0); program.Add(assignment); interpreter.Run(new Program(program)); Assert.That(interpreter.Valuetable[symboltable.resolve("result")], Is.EqualTo(10)); }
public void visit(ArithmeticOp node) { string optype1 = operandtypes.Pop(); string optype2 = operandtypes.Pop(); if (optype1 == "int" && optype2 == "int") operandtypes.Push("int"); else throw new SemanticError("Non-integer arguments to arithmetic operator on row " + node.Row + "."); }
private ArithExpr(ArithExpr ae) : base(ae) { op = ae.op; }
public ArithExpr(ArithmeticOp oper, INumberTerm t1) : base(oper.ToString(), 1) { AddTerm(t1); op = oper; srcInfo = t1.GetSrcInfo(); }
private void btnSave_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.OK; expression.QuestionTitle = tbQuestionTitle.Text; expression.Hint = tbSuggestions.Text; expression.SkipEvaluation = chkBxSkipEval.Checked; expression.FallbackAction = null; if (cbxFallbackActionNode.SelectedItem != null) { var id = (cbxFallbackActionNode.SelectedItem as ILinkInfo)._id; var type = (LinkType)((KeyValuePair <string, int>)cbxFallbackActionType.SelectedItem).Value; expression.FallbackAction = new ActionLink { LinkId = id, Type = type }; } expression.ForwardAction = null; if (cbxForwardActionNode.SelectedItem != null) { var id = (cbxForwardActionNode.SelectedItem as ILinkInfo)._id; var type = (LinkType)((KeyValuePair <string, int>)cbxForwardActionType.SelectedItem).Value; expression.ForwardAction = new ActionLink { LinkId = id, Type = type }; } expression.ExpressionTree = new ExpressionTree { Nodes = new List <IExpEval>() }; var dt = ((KeyValuePair <string, Type>)cbxDataType.SelectedItem).Value; //Data type foreach (DataGridViewRow row in dataGridViewActionItems.Rows) { var op = row.Cells[0].Value; //Operation var rVal = row.Cells[1].Value as string; //String data var with = row.Cells[2].Value; //Logical with if (!string.IsNullOrWhiteSpace(rVal) && op != null && with != null) { IExpEval curRes = null; object parsedRVal = Convert((Type)dt, rVal); if (parsedRVal != null) { if (op is RelationalOpType) { curRes = new RelationalOp { With = (LogicalOpType)with, RVal = parsedRVal, ROp = (RelationalOpType)op }; } else if (op is ArithmeticOpType) { curRes = new ArithmeticOp { With = (LogicalOpType)with, RVal = parsedRVal, AOp = (ArithmeticOpType)op }; } } if (curRes != null) { expression.ExpressionTree.Nodes.Add(curRes); } } } }
// <summary> // Copies an ArithmeticOp // </summary> // <param name="op"> The Op to Copy </param> // <param name="n"> The Node that references the Op </param> // <returns> A copy of the original Node that references a copy of the original Op </returns> public override Node Visit(ArithmeticOp op, Node n) { return CopyDefault(m_destCmd.CreateArithmeticOp(op.OpType, op.Type), n); }
/// <summary> /// <code> /// <list type="table"> /// <item><see cref="Expression.AddAssign(Expression, Expression)"/></item> /// <item><see cref="Expression.AddAssignChecked(Expression, Expression)"/></item> /// <item><see cref="Expression.DivideAssign(Expression, Expression)"/></item> /// <item><see cref="Expression.ModuloAssign(Expression, Expression)"/></item> /// <item><see cref="Expression.MultiplyAssign(Expression, Expression)"/></item> /// <item><see cref="Expression.MultiplyAssignChecked(Expression, Expression)"/></item> /// <item><see cref="Expression.PowerAssign(Expression, Expression)"/></item> /// <item><see cref="Expression.SubtractAssign(Expression, Expression)"/></item> /// <item><see cref="Expression.SubtractAssignChecked(Expression, Expression)"/></item> /// </list> /// </code> /// </summary> /// <remarks>Throws <see cref="NotSupportedException"/>.</remarks> public static BinaryExpression Assign(this Expression @this, ArithmeticOp operation, Expression operand) => operation switch {
public static void Arith(LuaStatePtr l, ArithmeticOp op) { LuaDelegates.lua_arith(l, (int)op); }
public void StringArithmetic() { var stringlit = new StringLiteral("\"foobar\"", 0); var plus = new ArithmeticOp("+", stringlit, stringlit, 0); var print = new ExpressionStatement("print", plus, 0); statementlist.Add(print); var parsetree = new Program(statementlist); Assert.Throws<SemanticError>(() => symbolTableBuilder.BuildSymbolTableAndTypeCheck(parsetree)); }