public void GreaterThanEqualToOperation_ShouldBeFalse_ForTwoValueTypes_WithGreaterSecondOperand() { var op = new NumericOperator(NumericOperation.GreaterThanEqualTo); RunTest(op, 2, 3, false); RunTest(op, 2.0m, 3, false); RunTest(op, 2.0f, 3, false); RunTest(op, 2L, 3, false); RunTest(op, 2ul, 3, false); RunTest(op, 2u, 3, false); }
public void GreaterThanEqualToOperation_ShouldBeTrue_ForFirstValueType_AndTypeConversion() { var op = new NumericOperator(NumericOperation.GreaterThanEqualTo); RunTest(op, 2, "2", true); RunTest(op, 2.0m, "2", true); RunTest(op, 2.0f, "2", true); RunTest(op, 2L, "2", true); RunTest(op, 2ul, "2", true); RunTest(op, 2u, "2", true); }
public void GreaterThanOperation_ShouldBeTrue_ForTwoValueTypes() { var op = new NumericOperator(NumericOperation.GreaterThan); RunTest(op, 2, 1, true); RunTest(op, 2.0m, 1, true); RunTest(op, 2.0f, 1, true); RunTest(op, 2L, 1, true); RunTest(op, 2ul, 1, true); RunTest(op, 2u, 1, true); }
public void Enumerate() { // Retrieves enum members in increasing value order foreach (EnumMember <NumericOperator> member in Enums.GetMembers <NumericOperator>()) { NumericOperator value = member.Value; string name = member.Name; // Do stuff } Assert.AreEqual(8, Enums.GetMembers <NumericOperator>().Count()); Assert.AreEqual(6, Enums.GetMembers <NumericOperator>(EnumMemberSelection.Distinct).Count()); }
public void Enumerate() { // Retrieves enum members in increasing value order foreach (EnumMember <NumericOperator> member in Enums.GetEnumMembers <NumericOperator>()) { NumericOperator value = member.Value; string name = member.Name; // Do stuff } Assert.AreEqual(8, Enums.GetEnumMembers <NumericOperator>().Count()); Assert.AreEqual(6, Enums.GetEnumMembers <NumericOperator>(excludeDuplicates: true).Count()); }
private void GetHQLStatement(NumericOperator op, decimal val, decimal min, decimal max, out string sqlStr, out Dictionary <string, object> sqlParams) { sqlParams = new Dictionary <string, object>(); sqlStr = "SELECT rr.ContentItemRecord.Id FROM Contrib.Voting.Models.ResultRecord AS rr WHERE rr.FunctionName = :functionname AND "; sqlParams.Add("functionname", functionName); switch (op) { case NumericOperator.Between: sqlStr += "rr.Value BETWEEN :min AND :max"; sqlParams.Add("min", min); sqlParams.Add("max", max); break; case NumericOperator.Equals: sqlStr += "rr.Value = :value"; sqlParams.Add("value", val); break; case NumericOperator.GreaterThan: sqlStr += "rr.Value > :value"; sqlParams.Add("value", val); break; case NumericOperator.GreaterThanEquals: sqlStr += "rr.Value >= :value"; sqlParams.Add("value", val); break; case NumericOperator.LessThan: sqlStr += "rr.Value < :value"; sqlParams.Add("value", val); break; case NumericOperator.LessThanEquals: sqlStr += "rr.Value <= :value"; sqlParams.Add("value", val); break; case NumericOperator.NotBetween: sqlStr += "rr.Value NOT BETWEEN :min AND :max"; sqlParams.Add("min", min); sqlParams.Add("max", max); break; case NumericOperator.NotEquals: sqlStr += "rr.Value <> :value"; sqlParams.Add("value", val); break; } }
private void searchfield_Loaded(object sender, RoutedEventArgs e) { defaultOperator = Operator; isSetDefaultOperator = true; DisplayName = GetDisplayName(); Binding binding = new Binding("IsFocused") { Source = this, Mode = BindingMode.OneWay }; SetBinding(IsGetFocusProperty, binding); }
public void Enumerate() { // Retrieves all enum members in increasing value order foreach (var member in Enums.GetMembers <NumericOperator>()) { NumericOperator value = member.Value; string name = member.Name; AttributeCollection attributes = member.Attributes; // Do stuff } // Retrieves distinct values in increasing value order foreach (var value in Enums.GetValues <NumericOperator>(EnumMemberSelection.Distinct)) { // Do stuff } }
public static void Main() { NumericOperator <int> nn1 = new NumericOperator <int>(Add); NumericOperator <int> nn2 = new NumericOperator <int>(Subtract); nn1(25, 25); Console.WriteLine($"{num}"); nn2(25, 100); Console.WriteLine($"{num}"); //多播 NumericOperator <int> nn3; nn3 = nn1; nn3 += nn2; nn3(100, 20); Console.WriteLine($"{num}"); Console.ReadKey(); }
public static bool Evaluate <T>(this NumericOperator @operator, T value, T comparisonValue) { @operator.Validate(nameof(@operator)); var isOdd = ((int)@operator) % 2 == 1; return(EvaluateInternal(isOdd ? @operator + 1 : @operator) ^ isOdd); bool EvaluateInternal(NumericOperator effectiveOperator) { return(effectiveOperator switch { NumericOperator.Equals => Number.Equals(value, comparisonValue), NumericOperator.LessThan => Number.LessThan(value, comparisonValue), NumericOperator.GreaterThan => Number.GreaterThan(value, comparisonValue), _ => throw new NotSupportedException($"NumericOperator of {@operator} is not supported"), }); }
public void Enumerate() { var count = 0; // Retrieves all enum members in increasing value order foreach (var member in Enums.GetMembers <NumericOperator>()) { NumericOperator value = member.Value; string name = member.Name; AttributeCollection attributes = member.Attributes; ++count; } Assert.AreEqual(8, count); count = 0; // Retrieves distinct values in increasing value order foreach (var value in Enums.GetValues <NumericOperator>(EnumMemberSelection.Distinct)) { string name = value.GetName(); AttributeCollection attributes = value.GetAttributes(); ++count; } Assert.AreEqual(6, count); }
public void LessThanEqualToOperation_ShouldBeFalse_ForNonComparableTypes() { var op = new NumericOperator(NumericOperation.LessThanEqualTo); RunTest(op, "hello", new { one = 1 }, false); }
internal NumericCondition(object pLeft, NumericOperator dbOperator, object pRight) { this.mLeft = pLeft; this.mOperator = dbOperator; this.mRight = pRight; }
public static NumericOperator Invert(this NumericOperator @operator) { @operator.Validate(nameof(@operator)); return(@operator + (((int)@operator) % 2 == 0 ? 1 : -1)); }
public static NumericCondition <T> Create <T>(NumericOperator @operator, T value) => new NumericCondition <T>(@operator, value);
public void GreaterThanOperation_ShouldBeTrue_ForComparableTypes_WithGreaterFirstOperand() { var op = new NumericOperator(NumericOperation.GreaterThan); RunTest(op, "b", "a", true); }
public void GreaterThanOperation_ShouldBeFalse_ForNonComparableTypes() { var op = new NumericOperator(NumericOperation.GreaterThan); RunTest(op, "hello", new { one = 1 }, false); }
/// <summary> /// Initializes the operator resolver. /// </summary> /// <returns>The operator resolver.</returns> private static OperatorResolver InitOperatorResolver() { Mock <OperatorResolver> opResolverMock = new Mock <OperatorResolver>(); IExpressionFactory exprFactory = new ExpressionFactory( ModelResolvers.ExprResolver, ModelResolvers.RuleExprResolver, ModelResolvers.JoinExprResolver, opResolverMock.Object); JoinApplyMeasuresOperator joinApplyMeasuresOp = new JoinApplyMeasuresOperator( exprFactory, ModelResolvers.DsResolver); opResolverMock.Setup(o => o(It.IsAny <string>())) .Returns((string key) => { IOperatorDefinition op; if (key.In("count", "min", "max", "median", "sum", "avg", "stddev_pop", "stddev_samp", "var_pop", "var_samp")) { op = new AggrFunctionOperator(joinApplyMeasuresOp, ModelResolvers.DsResolver); } else if (key == "aggr") { op = new AggrOperator(); } else if (key.In("first_value", "last_value", "lag", "rank", "ratio_to_report", "lead")) { op = new AnalyticFunctionOperator(joinApplyMeasuresOp, ModelResolvers.DsResolver); } else if (key.In("+", "-", "*", "/")) { op = new ArithmeticOperator(joinApplyMeasuresOp); } else if (key == "between") { op = new BetweenOperator(joinApplyMeasuresOp, ModelResolvers.DsResolver); } else if (key.In("and", "or", "xor", "not")) { op = new BooleanOperator(joinApplyMeasuresOp, ModelResolvers.DsResolver); } else if (key == "calc") { op = new CalcOperator(ModelResolvers.DsResolver); } else if (key == "check_datapoint") { op = new CheckDatapointOperator(ModelResolvers.DsResolver, exprFactory); } else if (key.In("=", "<>", "<", "<=", ">", ">=")) { op = new ComparisonOperator(joinApplyMeasuresOp, ModelResolvers.DsResolver); } else if (key == "comp") { op = new ComponentOperator(ModelResolvers.DsResolver, new ComponentTypeInference(ModelResolvers.DsResolver)); } else if (key == "const") { op = new ConstantOperator(ModelResolvers.DsResolver); } else if (key == "current_date") { op = new CurrentDateOperator(ModelResolvers.DsResolver); } else if (key == "exists_in") { op = new ExistsInOperator(ModelResolvers.DsResolver); } else if (key == "get") { op = new GetOperator(new Mock <IDataModelProvider>().Object); // operator tests should mock IDataModel implementation } else if (key == "if") { op = new IfThenElseOperator(joinApplyMeasuresOp, ModelResolvers.DsResolver); } else if (key.In("in", "not_in")) { op = new InOperator(joinApplyMeasuresOp, ModelResolvers.DsResolver); } else if (key == "isnull") { op = new IsNullOperator(joinApplyMeasuresOp, ModelResolvers.DsResolver); } else if (key == "join") { op = new JoinOperator(ModelResolvers.DsResolver); } else if (key.In("keep", "drop")) { op = new KeepDropOperator(ModelResolvers.DsResolver); } else if (key == "match_characters") { op = new MatchCharactersOperator(joinApplyMeasuresOp, ModelResolvers.DsResolver); } else if (key == "#") { op = new MembershipOperator(); } else if (key.In("ceil", "floor", "abs", "exp", "ln", "sqrt", "mod", "round", "power", "log", "trunc")) { op = new NumericOperator(joinApplyMeasuresOp, ModelResolvers.DsResolver); } else if (key == "nvl") { op = new NvlOperator(joinApplyMeasuresOp); } else if (key == "opt") { op = new OptionalOperator(ModelResolvers.DsResolver); } else if (key == "period_indicator") { op = new PeriodIndicatorOperator(joinApplyMeasuresOp, ModelResolvers.DsResolver, exprFactory); } else if (key == "pivot") { op = new PivotOperator(ModelResolvers.DsResolver); } else if (key == "ref") { op = new ReferenceOperator(); } else if (key == "rename") { op = new RenameOperator(ModelResolvers.DsResolver); } else if (key.In("union", "intersect", "setdiff", "symdiff")) { op = new SetOperator(); } else if (key.In("||", "trim", "rtrim", "ltrim", "upper", "lower", "substr", "replace", "instr", "length")) { op = new StringOperator(joinApplyMeasuresOp, ModelResolvers.DsResolver); } else if (key == "sub") { op = new SubspaceOperator(ModelResolvers.DsResolver); } else if (key.In("fill_time_series", "flow_to_stock", "stock_to_flow", "timeshift", "time_agg")) { op = new TimeOperator(); } else if (key.In("plus", "minus")) { op = new UnaryArithmeticOperator(joinApplyMeasuresOp); } else if (key == "unpivot") { op = new UnpivotOperator(ModelResolvers.DsResolver); } // --- else if (key == "calcExpr") { op = new CalcExprOperator(ModelResolvers.DsResolver); } else if (key == "collection") { op = new CollectionOperator(ModelResolvers.DsResolver); } else if (key == "datasetClause") { op = new DatasetClauseOperator(); } else if (key == "group") { op = new GroupOperator(ModelResolvers.DsResolver); } else if (key == "order") { op = new OrderOperator(ModelResolvers.DsResolver); } else if (key == "partition") { op = new PartitionOperator(ModelResolvers.DsResolver); } else if (key == "renameExpr") { op = new RenameExprOperator(ModelResolvers.DsResolver); } else if (key == "subExpr") { op = new SubspaceExprOperator(); } else if (key == "when") { op = new WhenOperator(); } else { throw new InvalidOperationException("Operator not found"); } op.Symbol = key; return(op); }); return(opResolverMock.Object); }