/// <summary> /// Evaluates the parameter Expressive expression, with the parameter NumericPrecision and an empty ValueSource and FunctionSource. /// </summary> public static EvaluationResult Evaluate(string expression, NumericPrecision precision) { var tokens = Lexer.Lex(expression); var parsed = Parser.Parse(tokens); return(parsed.Evaluate(precision, new ValueSource(), new FunctionSource())); }
/// <summary> /// Evaluates the parameter Expressive expression, with the parameter NumericPrecision, converting the parameter values /// and functions dictionaries in ValueSource and FunctionSource objects. /// </summary> public static EvaluationResult Evaluate(string expression, NumericPrecision precision, Dictionary <string, object> values, Dictionary <string, ExternalFunction> functions) { var valueSource = ValueSourceFromDictionary(values); var functionSource = FunctionSourceFromDictionary(functions); return(Evaluate(expression, precision, valueSource, functionSource)); }
public static void Scale_PropertyGet_EqualsCtorArgument() { const int precision = 12345; const int scale = 9876; var autoScale = new NumericPrecision(precision, scale); Assert.That(autoScale.Scale, Is.EqualTo(scale)); }
public override EvaluationResult Evaluate(NumericPrecision numericPrecision, ValueSource values, FunctionSource functions) { EvaluationResult left = Constituents[0].Evaluate(numericPrecision, values, functions); OperatorExpression op = Constituents[1] as OperatorExpression; EvaluationResult right = Constituents[2].Evaluate(numericPrecision, values, functions); return(Evaluate(left, op, right, numericPrecision)); }
public RealNumber(NumericPrecision numericPrecision, object value) { if (!(value is float) && !(value is decimal)) { throw new ArgumentException("Value must be float or decimal"); } NumericPrecision = numericPrecision; Value = value; }
public static void NotEqualsOpLeftINumericPrecision_GivenNullINumericPrecision_ReturnsTrue() { const int precision = 12345; const int scale = 9876; var a = new NumericPrecision(precision, scale); var areEqual = (FakeNumericPrecision)null != a; Assert.That(areEqual, Is.True); }
public static void EqualsOpRightINumericPrecision_GivenNullINumericPrecision_ReturnsFalse() { const int precision = 12345; const int scale = 9876; var a = new NumericPrecision(precision, scale); var areEqual = a == (FakeNumericPrecision)null; Assert.That(areEqual, Is.False); }
public static void EqualsT_GivenNullINumericPrecision_ReturnsFalse() { const int precision = 12345; const int scale = 9876; var a = new NumericPrecision(precision, scale); var areEqual = a.Equals(null); Assert.That(areEqual, Is.False); }
public static void EqualsT_GivenObjectsWithDifferentScale_ReturnsFalse() { const int precision = 12345; const int scale = 9876; var a = new NumericPrecision(precision, scale); var b = new NumericPrecision(precision, 6789); var areEqual = a.Equals(b); Assert.That(areEqual, Is.False); }
public static void Equals_GivenObjectsWithEqualInputs_ReturnsTrue() { const int precision = 12345; const int scale = 9876; var a = new NumericPrecision(precision, scale); object b = new NumericPrecision(precision, scale); var areEqual = a.Equals(b); Assert.That(areEqual, Is.True); }
public override int GetHashCode() { int result = ProviderType != null?ProviderType.GetHashCode() : 0; result = 29 * result + (DataTypeName != null ? DataTypeName.GetHashCode() : 0); result = 29 * result + NumericPrecision.GetHashCode(); result = 29 * result + NumericScale.GetHashCode(); result = 29 * result + ColumnSize.GetHashCode(); result = 29 * result + IsLong.GetHashCode(); return(result); }
public static void Equals_GivenNonNumericPrecisionObject_ReturnsFalse() { const int precision = 12345; const int scale = 9876; var a = new NumericPrecision(precision, scale); var b = new object(); var areEqual = a.Equals(b); Assert.That(areEqual, Is.False); }
public static void NotEqualsOpLeftINumericPrecision_GivenObjectsWithDifferentScale_ReturnsTrue() { const int precision = 12345; const int scale = 9876; var a = new FakeNumericPrecision(precision, scale); var b = new NumericPrecision(precision, 6789); var areEqual = a != b; Assert.That(areEqual, Is.True); }
public static void EqualsOpRightINumericPrecision_GivenObjectsWithEqualInputs_ReturnsTrue() { const int precision = 12345; const int scale = 9876; var a = new NumericPrecision(precision, scale); var b = new FakeNumericPrecision(precision, scale); var areEqual = a == b; Assert.That(areEqual, Is.True); }
public static void EqualsOpLeftINumericPrecision_GivenObjectsWithDifferentPrecision_ReturnsFalse() { const int precision = 12345; const int scale = 9876; var a = new FakeNumericPrecision(precision, scale); var b = new NumericPrecision(54321, scale); var areEqual = a == b; Assert.That(areEqual, Is.False); }
public static void NotEqualsOpLeftINumericPrecision_GivenObjectsWithEqualInputs_ReturnsFalse() { const int precision = 12345; const int scale = 9876; var a = new FakeNumericPrecision(precision, scale); var b = new NumericPrecision(precision, scale); var areEqual = a != b; Assert.That(areEqual, Is.False); }
public RealNumber AsRealNumber(NumericPrecision precision) { if (Result is float || Result is decimal) { return(new RealNumber(precision, Result)); } if (Result is int) { return(RealNumber.FromInt(AsInt().Value, precision)); } return(Result as RealNumber); }
public static void GetHashCode_GivenObjectsWithDifferentScale_AreNotEqual() { const int precision = 12345; const int scale = 9876; var a = new NumericPrecision(precision, scale); var b = new NumericPrecision(precision, 6789); var aHash = a.GetHashCode(); var bHash = b.GetHashCode(); Assert.That(aHash, Is.Not.EqualTo(bHash)); }
public static void GetHashCode_GivenObjectsWithEqualInputs_AreEqual() { const int precision = 12345; const int scale = 9876; var a = new NumericPrecision(precision, scale); var b = new NumericPrecision(precision, scale); var aHash = a.GetHashCode(); var bHash = b.GetHashCode(); Assert.That(aHash, Is.EqualTo(bHash)); }
/// <summary> /// Evaluates the parameter Expressive expression, with the parameter NumericPrecision, ValueSource and FunctionSource. /// </summary> public static EvaluationResult Evaluate(string expression, NumericPrecision precision, ValueSource values, FunctionSource functions) { values = values ?? new ValueSource(); functions = functions ?? new FunctionSource(); var tokens = Lexer.Lex(expression); var parsed = Parser.Parse(tokens); if (parsed is ErrorExpression) { throw new ParserException(((ErrorExpression)parsed).ErroneousTokens); } return(parsed.Evaluate(precision, values, functions)); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { // credit: http://stackoverflow.com/a/263416/677735 unchecked // Overflow is fine, just wrap { var hash = 41; // Suitable nullity checks etc, of course :) if (Automatic != null) { hash = hash * 57 + Automatic.GetHashCode(); } if (IndexingMode != null) { hash = hash * 57 + IndexingMode.GetHashCode(); } if (IncludePaths != null) { hash = hash * 57 + IncludePaths.GetHashCode(); } if (IndexType != null) { hash = hash * 57 + IndexType.GetHashCode(); } if (NumericPrecision != null) { hash = hash * 57 + NumericPrecision.GetHashCode(); } if (StringPrecision != null) { hash = hash * 57 + StringPrecision.GetHashCode(); } if (Path != null) { hash = hash * 57 + Path.GetHashCode(); } if (ExcludePaths != null) { hash = hash * 57 + ExcludePaths.GetHashCode(); } return(hash); } }
/// <summary> /// Returns true if IndexingPolicy instances are equal /// </summary> /// <param name="other">Instance of IndexingPolicy to be compared</param> /// <returns>Boolean</returns> public bool Equals(IndexingPolicy other) { // credit: http://stackoverflow.com/a/10454552/677735 if (other == null) { return(false); } return (( Automatic == other.Automatic || Automatic != null && Automatic.Equals(other.Automatic) ) && ( IndexingMode == other.IndexingMode || IndexingMode != null && IndexingMode.SequenceEqual(other.IndexingMode) ) && ( IncludePaths == other.IncludePaths || IncludePaths != null && IncludePaths.Equals(other.IncludePaths) ) && ( IndexType == other.IndexType || IndexType != null && IndexType.Equals(other.IndexType) ) && ( NumericPrecision == other.NumericPrecision || NumericPrecision != null && NumericPrecision.Equals(other.NumericPrecision) ) && ( StringPrecision == other.StringPrecision || StringPrecision != null && StringPrecision.Equals(other.StringPrecision) ) && ( Path == other.Path || Path != null && Path.Equals(other.Path) ) && ( ExcludePaths == other.ExcludePaths || ExcludePaths != null && ExcludePaths.Equals(other.ExcludePaths) )); }
public override EvaluationResult Evaluate(NumericPrecision numericPrecision, ValueSource values, FunctionSource functions) { var symbol = Constituents[0] as SymbolExpression; if (symbol == null) { throw new EvaluationException(this); } var matchingFunction = functions.TryGetValue(symbol.ToString()); if (matchingFunction == null) { throw new UnmatchedSymbolException(symbol.ToString()); } var parameters = Constituents[1].Evaluate(numericPrecision, values, functions); var result = matchingFunction.Invoke(parameters) ?? new EvaluationResult(EvaluationType.Null, null); if (result.Type != EvaluationType.Expression) { return(result); } return(Interpreter.Interpreter.Evaluate(result.AsString(), numericPrecision, values, functions)); }
public EvaluationResult EvaluateOperation(string expression, NumericPrecision precision) { return(Interpreter.Evaluate(expression, precision)); }
public EvaluationResult EvaluateOperation(string expression, NumericPrecision precision, ValueSource values, FunctionSource functions) { return(Interpreter.Evaluate(expression, precision, values, functions)); }
public EvaluationResult EvaluateOperation(string expression, NumericPrecision precision, Dictionary <string, object> values, Dictionary <string, ExternalFunction> functions) { return(Interpreter.Evaluate(expression, precision, values, functions)); }
public override EvaluationResult Evaluate(NumericPrecision numericPrecision, ValueSource values, FunctionSource functions) => ToString();
public abstract EvaluationResult Evaluate(NumericPrecision numericPrecision, ValueSource values, FunctionSource functions);
public override EvaluationResult Evaluate(NumericPrecision numericPrecision, ValueSource values, FunctionSource functions) => Constituents.Any() ? Constituents[0].Evaluate(numericPrecision, values, functions) : new EvaluationResult(EvaluationType.Null, null);
public override EvaluationResult Evaluate(NumericPrecision numericPrecision, ValueSource values, FunctionSource functions) => new EvaluationResult(EvaluationType.Null, null);