public void Execute_02_NoCart( BaseCartItemSubtotalAmountOffAction action, IBinaryOperator <decimal, decimal> subtotalOperator, IRuleValue <decimal> subtotal, IRuleValue <decimal> amountOff, CartTotals cartTotals, CommerceContext commerceContext, IRuleExecutionContext context) { /********************************************** * Arrange **********************************************/ context.Fact <CommerceContext>().ReturnsForAnyArgs(commerceContext); commerceContext.AddObject(cartTotals); action.SubtotalOperator = subtotalOperator; action.Subtotal = subtotal; action.AmountOff = amountOff; /********************************************** * Act **********************************************/ Action executeAction = () => action.Execute(context); /********************************************** * Assert **********************************************/ executeAction.Should().NotThrow <Exception>(); }
public bool Match(string value, Type type) { if (_missingOperatorTable.Contains(type)) { return(false); } if (!IsSyntaxMatch(value)) { return(false); } if (_foundOperatorTable.ContainsKey(type)) { return(true); } IBinaryOperator operatorData = GetOperatorData(type); if (operatorData != null) { _foundOperatorTable.Add(type, operatorData); return(true); } _missingOperatorTable.Add(type); return(false); }
public void Execute_08_NoAmount( BaseCartItemSubtotalAmountOffAction action, IBinaryOperator <decimal, decimal> subtotalOperator, IRuleValue <decimal> subtotal, Cart cart, CartTotals cartTotals, CommerceContext commerceContext, IRuleExecutionContext context) { /********************************************** * Arrange **********************************************/ cart.Adjustments.Clear(); cart.Lines.ForEach(l => l.Adjustments.Clear()); context.Fact <CommerceContext>().ReturnsForAnyArgs(commerceContext); commerceContext.AddObject(cartTotals); commerceContext.AddObject(cart); action.MatchingLines(context).ReturnsForAnyArgs(cart.Lines); action.SubtotalOperator = subtotalOperator; action.Subtotal = subtotal; action.AmountOff = null; /********************************************** * Act **********************************************/ Action executeAction = () => action.Execute(context); /********************************************** * Assert **********************************************/ executeAction.Should().NotThrow <Exception>(); cart.Lines.SelectMany(l => l.Adjustments).Should().BeEmpty(); cart.Adjustments.Should().BeEmpty(); }
public void binaryOperatorClick(object sender, TextView textView, EventArgs e, IBinaryOperator operator_passed) { if (!operatorClicked) { History_list.Add(textView.Text); } //else { History_list.Add(Convert.ToString(0)); } pendingOperator = sender.ToString (); opCount++; if (!digitEntered) { int size = History_list.Count; History_list.RemoveAt(size-1); } History_list.Add (pendingOperator); //History_list.Add (pendingOperator); pendingValue = Convert.ToDouble(textView.Text); operatorClicked = true; op_Pressed = true; //pendingValue = Convert.ToDouble(digit); if(digitEntered) { pendingResult = calculator.AcceptNumber(Convert.ToDouble(textView.Text), operator_passed); digitEntered = false; textView.Text = Convert.ToString(pendingResult); } else calculator.AcceptOperator(operator_passed); }
private static string ExpressionToStringWithParentheses(IBinaryOperator parent, IAstTreeNode childNode, bool isLeftChild) { string text = childNode.ToString(); var child = childNode.Value as IBinaryOperator; if (child == null || parent.Precedence < child.Precedence) { return(text); } if (parent.Precedence == child.Precedence) { if (!(parent.Associativity == OperatorAssociativity.RightAssociative || child.Associativity == OperatorAssociativity.RightAssociative)) { if (isLeftChild) { return(text); } if (parent.Associativity == OperatorAssociativity.NonAssociative && child.Associativity == OperatorAssociativity.NonAssociative) { return(text); } } } return(string.Format("({0})", text)); }
public GraphTraversalSource WithSack(object initialValue, IBinaryOperator mergeOperator) { var source = new GraphTraversalSource(new List <ITraversalStrategy>(TraversalStrategies), new Bytecode(Bytecode)); source.Bytecode.AddSource("withSack", initialValue, mergeOperator); return(source); }
public GraphTraversalSource WithSideEffect(string key, object initialValue, IBinaryOperator reducer) { var source = new GraphTraversalSource(new List <ITraversalStrategy>(TraversalStrategies), new Bytecode(Bytecode)); source.Bytecode.AddSource("withSideEffect", key, initialValue, reducer); return(source); }
public void Symmetrize(IBinaryOperator <T> bin_op) { SparseMatrix <T> tr_mat = GetTransposedCopy(); tr_mat.RemoveDiagonal(); tr_mat.Merge(this, bin_op); // throws ArgumentNullException m_rows = tr_mat.m_rows; }
/// <summary> /// Adds a binary operator. /// </summary> /// <param name="name">The name of the operator.</param> /// <param name="binaryOperator">The binary operator.</param> /// <returns>This <see cref="MathContextBuilder"/> instance.</returns> /// <exception cref="ArgumentException">If the binary operator already exists.</exception> public MathContextBuilder AddBinaryOperator(string name, IBinaryOperator binaryOperator) { if (_binaryOperators.TryAdd(name, binaryOperator) is false) { throw new ArgumentException($"A binary operator named '{name}' already exists."); } return(this); }
/// <summary> /// Updates the active binary operator. /// </summary> /// <param name="op">The new operator.</param> internal void SetBinaryOperator(IBinaryOperator op) { if (BinaryOperator != null) { throw new QueryConstructionException("Cannot set operator - Another binary operator is already active"); } BinaryOperator = op; }
public WhereFilteredStatement And(string key, IBinaryOperator comparisonOperator, IConvertible value) { if (_where == null) { throw new InvalidOperationException("La commande AND ne peut être appelée qu'après un WHERE"); } _where.And(key, comparisonOperator, value); return(this); }
public WhereFilteredStatement Where(string key, IBinaryOperator comparisonOperator, IConvertible value) { if (_where != null) { throw new InvalidOperationException("La commande WHERE ne peut être appelée qu'une fois"); } _where = new WhereSequence(key, comparisonOperator, value, Params); return(this); }
public static T Sum <T>(T[] items, IBinaryOperator <T> op) { var sum = op.Zero; foreach (var item in items) { sum = op.Operate(sum, item); } return(sum); }
//public Tuple<double,string> AcceptNumber(double d, IBinaryOperator operation) public string AcceptNumber(double d, IBinaryOperator operation) { acceptNumberCount++; if (operation == null) { an = false; ct++; secondNumber = d; return Convert.ToString(secondNumber); } else { //if ( lhsNumberAvailability==LHSNumber.AVAILABLE) //if (isLHSNumberAvailable) if (acceptNumberCount == 1 && acceptOperatorCount >= 1) //when AN is called after multiple operators { firstNumber = pendingOperation.perform(0, d); pendingOperation = operation; return Convert.ToString(firstNumber); //return new Tuple<double, string> (firstNumber, null); } else if ((acceptNumberCount > 1 && equalsCount == 0)) //An is called and needs to saves result and perofrms operation { acceptNumber_LHS_perform (d, operation); return Convert.ToString (firstNumber); } else if ((an) && acceptNumberCount > 1 && equalsCount >= 1) { acceptNumber_LHS_perform (d, operation); return Convert.ToString (firstNumber); } else if (acceptNumberCount > 1 && equalsCount >= 1) //when AN is called after an equals is called { an = true; accept_number_save_LHS (d, operation); return Convert.ToString (firstNumber); } else if (acceptNumberCount > 1 && equalsCount >= 1 && acceptOperatorCount >= 1) //when AN is called after an equals is called { acceptNumber_LHS_perform (d, operation); return Convert.ToString(firstNumber); } else // An is called in normal cases accept_number_save_LHS (d, operation); return Convert.ToString (firstNumber); } }
public void Merge(SparseMatrix <T> .ReadOnly other_matrix, IBinaryOperator <T> binary_operator) { Utils.ThrowException(binary_operator == null ? new ArgumentNullException("binary_operator") : null); int other_matrix_num_rows = other_matrix.GetLastNonEmptyRowIdx() + 1; if (m_rows.Count < other_matrix_num_rows) { SetRowListSize(other_matrix_num_rows); } for (int row_idx = 0; row_idx < other_matrix_num_rows; row_idx++) { m_rows[row_idx].Merge(other_matrix.Inner.m_rows[row_idx], binary_operator); } }
public void Merge(SparseVector <T> .ReadOnly other_vec, IBinaryOperator <T> binary_operator) { Utils.ThrowException(other_vec == null ? new ArgumentNullException("other_vec") : null); Utils.ThrowException(binary_operator == null ? new ArgumentNullException("binary_operator") : null); ArrayList <int> other_idx = other_vec.Inner.InnerIdx; ArrayList <T> other_dat = other_vec.Inner.InnerDat; ArrayList <int> new_idx = new ArrayList <int>(m_idx.Count + other_idx.Count); ArrayList <T> new_dat = new ArrayList <T>(m_dat.Count + other_dat.Count); int i = 0, j = 0; while (i < m_idx.Count && j < other_idx.Count) { int a_idx = m_idx[i]; int b_idx = other_idx[j]; if (a_idx == b_idx) { T value = binary_operator.PerformOperation(m_dat[i], other_dat[j]); if (value != null) { new_idx.Add(a_idx); new_dat.Add(value); } i++; j++; } else if (a_idx < b_idx) { new_idx.Add(a_idx); new_dat.Add(m_dat[i]); i++; } else { new_idx.Add(b_idx); new_dat.Add(other_dat[j]); j++; } } for (; i < m_idx.Count; i++) { new_idx.Add(m_idx[i]); new_dat.Add(m_dat[i]); } for (; j < other_idx.Count; j++) { new_idx.Add(other_idx[j]); new_dat.Add(other_dat[j]); } m_idx = new_idx; m_dat = new_dat; }
private void binaryOperatorClick(object sender, EventArgs e) { TextView textView = FindViewById<TextView> (Resource.Id.textView); if (!operatorClicked) { iList.Add(textView.Text); } else { iList.Add(Convert.ToString(0)); } pendingOperator = sender.ToString (); opCount++; iList.Add(pendingOperator); pendingValue = Convert.ToDouble(textView.Text); switch (pendingOperator) { case "+": po = new AdditionOperator(); break; case "-": po = new SubtractionOperator(); break; case "*": po = new MultiplicationOperator(); break; case "/": po = new DivisionOperator(); break; } operatorClicked = true; //pendingValue = Convert.ToDouble(digit); if(digitEntered) { pendingResult = calculator.AcceptNumber(Convert.ToDouble(textView.Text), po); digitEntered = false; textView.Text = Convert.ToString(pendingResult); } else { calculator.AcceptOperator(po); } }
public object Parse(string value, Type type, Func <string, Type, object> recursiveParser) { IBinaryOperator operatorData = _foundOperatorTable[type]; int splitIndex = GetOperatorPosition(value); string left = value.Substring(0, splitIndex); string right = value.Substring(splitIndex + 1); object leftVal = recursiveParser(left, operatorData.LArg); object rightVal = recursiveParser(right, operatorData.RArg); try { return(operatorData.Invoke(leftVal, rightVal)); } catch (TargetInvocationException e) { throw e.InnerException ?? e; } }
//----------------------------------------------------------------------------------------------------------------------------------------------------- public BinaryExpressionOperand( IBinaryOperator <TLeft, TRight> @operator, IOperand <TLeft> left, IOperand <TRight> right) { m_Left = left; m_Right = right; m_Operator = @operator; if (StatementScope.Exists) { var scope = StatementScope.Current; scope.Consume(left as IExpressionOperand); scope.Consume(right as IExpressionOperand); // since the unregister method only checks the last statement, the following line is // required to remove dependency on the order of left and right registration: scope.Consume(left as IExpressionOperand); scope.RegisterExpressionStatement(this); } }
private Bitmap GetResultImage(int index) { Bitmap a = srcA.TryGetImage(index); Bitmap b = srcB.TryGetImage(index); Bitmap c = srcC.TryGetImage(index); IBinaryOperator operAB = mergeAB.TryGetOperator(); IBinaryOperator operBC = mergeBC.TryGetOperator(); Bitmap ret = null; if (a == null) { return(ret); } ret = a; if (b == null) { return(ret); } if (operAB == null) { return(ret); } ret = operAB.Merge(ret, b); if (c == null) { return(ret); } if (operBC == null) { return(ret); } ret = operBC.Merge(ret, c); return(ret); }
/// <summary> /// /// Initializes a new instance of the <see cref="BinaryOperatorTerm"/> class. /// </summary> /// <param name="op">Binary operation</param> public BinaryOperatorTerm(IBinaryOperator op) { Operator = op; }
public static IBinaryOperator <T, bool> Wrap(IBinaryOperator binaryOperator) { return(new BinaryOperator <T, bool>(binaryOperator)); }
private BinaryOperator(IBinaryOperator binaryOperator) { _method = binaryOperator; }
/// <summary> /// Updates the active binary operator. /// </summary> /// <param name="op">The new operator.</param> internal void SetBinaryOperator(IBinaryOperator op) { if (BinaryOperator != null) throw new QueryConstructionException("Cannot set operator - Another binary operator is already active"); BinaryOperator = op; }
public static IRightValue Parse(ISyntaxNode parent, ref string Input) { string temp = Input; System.Text.RegularExpressions.Regex endRegEx = new System.Text.RegularExpressions.Regex("^\\s*$"); System.Text.RegularExpressions.Regex bracketsRegEx = new System.Text.RegularExpressions.Regex("^\\s*\\)\\s*"); System.Text.RegularExpressions.Regex commaRegEx = new System.Text.RegularExpressions.Regex("^\\s*,\\s*"); IRightValue highestNode = null; while ((!endRegEx.IsMatch(Input)) && (!bracketsRegEx.IsMatch(Input)) && (!commaRegEx.IsMatch(Input))) { IntegerConstant iconst = TryParse <IntegerConstant>(parent, ref Input); if (iconst != null) { if (highestNode != null) // Function calls can only be the first one. { throw new SyntaxException("Syntax error: Invalid rvalue before integer constant."); } highestNode = iconst; continue; } FloatingConstant fconst = TryParse <FloatingConstant>(parent, ref Input); if (fconst != null) { if (highestNode != null) // Function calls can only be the first one. { throw new SyntaxException("Syntax error: Invalid rvalue before floating constant."); } highestNode = fconst; continue; } FunctionCall fcall = TryParse <FunctionCall>(parent, ref Input); if (fcall != null) { if (highestNode != null) // Function calls can only be the first one. { throw new SyntaxException("Syntax error: Invalid rvalue before function call."); } highestNode = fcall; continue; } //string tmp = Input; IBinaryOperator binop = IBinaryOperator.Parse(parent, ref Input, highestNode); if (binop != null) { // Input = tmp; if (highestNode == null) // Function calls can only be the first one. { throw new SyntaxException("Syntax error: Missing first operand for binary operator."); } highestNode = binop; continue; } IUnaryOperator unop = IUnaryOperator.Parse(parent, ref Input, highestNode); if (unop != null) { if ((unop.Position == OperatorPosition.Postfix) && (highestNode == null)) // Function calls can only be the first one. { throw new SyntaxException("Syntax error: Missing first operand for unary operator."); } highestNode = unop; continue; } Brackets backets = TryParse <Brackets>(parent, ref Input); if (backets != null) { if (highestNode != null) // Function calls can only be the first one. { throw new SyntaxException("Syntax error: Invalid rvalue before brackets."); } highestNode = backets; continue; } // InfixOperator iopp = TryParse<InfixOperator>(ref Input, delegate(ref string i) { return new InfixOperator(parent, ref i, highestNode); }); // if (iopp != null) // highestNode = fcall; // Well, if nothing got parsed, then it's a invalid expression throw new SyntaxException("Syntax error: Invalid token \"" + Input + "\""); } if ((highestNode is IOperator) && ((highestNode as IOperator).SecondaryOperand is IOperator) && (highestNode.Priority < (highestNode as IOperator).SecondaryOperand.Priority)) { IOperator higher = (highestNode as IOperator); IOperator lower = (IOperator)higher.SecondaryOperand; higher.SecondaryOperand = lower.PrimaryOperand; lower.PrimaryOperand = higher; higher = lower; highestNode = higher; } return(highestNode); }
public string AcceptOperator(IBinaryOperator operation) { ao = true; acceptOperatorCount++; if (equalsCount >= 1 || acceptOperatorCount >= 1) { secondNumber = firstNumber; } pendingOperation = operation; return Convert.ToString(firstNumber); }
public WhereSequence Where(string key, IBinaryOperator binOperator, IConvertible value) { _sequence = new WhereSequence(key, binOperator, value, _parentCollection); return(_sequence); }
public IWhereFilterable <ITableUpdate, int> Or(string key, IBinaryOperator comparisonOperator, IConvertible value) { Statement.Or(key, comparisonOperator, value); return(this); }
public WhereSequence(string key, IBinaryOperator binOperator, IConvertible value, ParamsCollection parentCollection) { _parentCollection = parentCollection; _sequence = binOperator.ToString(key, parentCollection.GetIdentifier(value)); }
void acceptNumber_LHS_perform(double d, IBinaryOperator operation) { double res = pendingOperation.perform (firstNumber, d); firstNumber = res; pendingOperation = operation; }
public WhereSequence Or(string key, IBinaryOperator binOperator, IConvertible value) { _sequence += " OR " + binOperator.ToString(key, _parentCollection.GetIdentifier(value)); return(this); }
public IWhereFilterable <ITableSelect <TResultType>, TResultType> And(string key, IBinaryOperator comparisonOperator, IConvertible value) { Statement.And(key, comparisonOperator, value); return(this); }
public BinaryOperation(IBinaryOperator @operator, IAst lhs, IAst rhs) { Operator = @operator; Lhs = lhs; Rhs = rhs; }
public MergeSource(IBinaryOperator binaryOperator) { this.Operator = binaryOperator; }
public IWhereFilterable <TableDelete, int> And(string key, IBinaryOperator comparisonOperator, IConvertible value) { Statement.And(key, comparisonOperator, value); return(this); }
void accept_number_save_LHS(double d, IBinaryOperator operation) { pendingOperation = operation; firstNumber = d; }
public IWhereFilterable <ITableOperation <bool>, bool> And(string key, IBinaryOperator comparisonOperator, IConvertible value) { Statement.And(key, comparisonOperator, value); return(this); }
public BinaryOperatorRule(IBinaryOperator binaryOperator) { this.binaryOperator = binaryOperator; }
internal Token(IBinaryOperator expr) { Type = TokenType.BinaryOperator; _expr = expr; }
public Token(IBinaryOperator binaryOperator) { value = binaryOperator; Type = TokenType.BinaryOperator; }
private void AddBinaryOperator(OperatorType Type, IBinaryOperator Operator) { binaryOperators.Add(Type, Operator); }
public bool Equals(IBinaryOperator other) { return base.Equals(other); }
private static string ExpressionToStringWithParentheses(IBinaryOperator parent, IAstTreeNode childNode, bool isLeftChild) { string text = childNode.ToString(); var child = childNode.Value as IBinaryOperator; if (child == null || parent.Precedence < child.Precedence) return text; if (parent.Precedence == child.Precedence) { if (!(parent.Associativity == OperatorAssociativity.RightAssociative || child.Associativity == OperatorAssociativity.RightAssociative)) { if (isLeftChild) return text; if (parent.Associativity == OperatorAssociativity.NonAssociative && child.Associativity == OperatorAssociativity.NonAssociative) return text; } } return string.Format("({0})", text); }