public void TestMethod1() { // ASSERT Equality eq = new Equality(); EqualityObject ea = new EqualityObject { Id = 1, Name = "David" }; EqualityObject eb = new EqualityObject { Id = 1, Name = "David" }; // ARRANGE var ec = ea.CloneMe(); var eatype = ec.GetType().ToString(); bool areEqual = eq.AreObjectsEqual(ea, eb); // ACT Assert.IsTrue(areEqual); }
/// <summary> /// Creates a new filter instance with the given property and equality criteria /// </summary> /// <param name="propertyName">The name of the Content property to test against</param> /// <param name="equalityValue">The String value to compare against</param> /// <param name="equality">The equality operator to use for comparison</param> /// <exception cref="ArgumentException">Thrown if the provided propertyName is invalid</exception> public EqualitySearchFilter(string propertyName, string equalityValue, Equality equality = Equality.Equal) { if (string.IsNullOrEmpty(propertyName)) throw new ArgumentException("Property Name must be specified"); Field = propertyName; Comparison = (equality == Equality.Equal ? SearchFilterComparer.Equal : SearchFilterComparer.NotEqual).ToString(); Value = equalityValue; }
public ProgramChunkBranch(Equality equality, ProgramChunkExpressionTerm termFirst, IProgramChunk trueChunk, ProgramChunkExpressionTerm termSecond, IProgramChunk falseChunk) { this.equality = equality; this.termFirst = termFirst; this.termSecond = termSecond; this.trueChunk = trueChunk; this.falseChunk = falseChunk; }
public static int Main() { Equality e = new Equality(); if (e.RunTest()) { Console.WriteLine(); Console.WriteLine("Test Passed"); return 100; } Console.WriteLine(); Console.WriteLine("Test Failed"); return 1; }
protected virtual String ParseEquality(Equality equality) { String parsed = ""; if (equality is Equals) { parsed = null; } else if (equality is GreaterThan) { parsed = "$gt"; } else if (equality is GreaterThanEquals) { parsed = "$gte"; } else if (equality is LessThan) { parsed = "$lt"; } else if (equality is LessThanEquals) { parsed = "$lte"; } return parsed; }
public override bool Equals(object obj) => Equality.IsStructureEqualToObject(this, obj);
public static bool operator ==(WeightUnit left, WeightUnit right) => Equality.AreEqualStructures(left, right);
public static bool operator ==(PartialEqF <T1, T2, U> a, PartialEqF <T1, T2, U> b) => Equality.Operator(a, b);
public static bool operator <=(Power left, Power right) => Equality.IsStructureLowerThanOrEqual(left, right);
public static bool operator !=(Power left, Power right) => !Equality.AreEqualStructures(left, right);
public bool Equals(IJsonMetadata other) => Equality.Combine(this.Identity, other?.Identity);
public StoredFlaggedStreamedArray(Stream stream, Func <T, int> dataSizer, Func <T, F> itemFlag, Func <F, bool> hasData, Func <Stream, F> flagReader, Action <Stream, F> flagWriter, Func <Stream, F, int, T> dataReader, Action <Stream, F, int, T> dataWriter, Equality <T> itemEquality, bool leaveOpen, bool boostAccess) : this(stream, new FlaggedCollectionParameter().With(h => { stream.Position = 0; h.Read(stream); }), dataSizer, itemFlag, hasData, flagReader, flagWriter, dataReader, dataWriter, itemEquality, leaveOpen, boostAccess) { }
public static bool operator !=(DatabaseColumnStructure dcs1, DatabaseColumnStructure dcs2) { return(Equality.IsNotEqual(dcs1, dcs2)); }
public TriangulatedSurface GetModifiedSurface(TriangulatedSurface surface, IOptions options) { var cutOptions = (TriangulatedSurfaceCutterOptions)options; List <Triangle3D> triangles = new List <Triangle3D>(); foreach (var triangle in surface.Triangles) { if (Equality.AreLessOrEqual(triangle.Points.Max(p => p.Z), cutOptions.CutDepth)) { triangles.Add(triangle); } else if (Equality.AreMoreOrEqual(triangle.Points.Min(p => p.Z), cutOptions.CutDepth)) { continue; } else { Point3D[] pointsToInclude = triangle.Points.Where(p => Equality.Less(p.Z, cutOptions.CutDepth)).ToArray(); List <IntersectionData> intersectionList = new List <IntersectionData>(); var intersect = Intersection(triangle.A, triangle.B, cutOptions.CutDepth); if (intersect != null) { intersectionList.Add(intersect.Value); } intersect = Intersection(triangle.B, triangle.C, cutOptions.CutDepth); if (intersect != null) { intersectionList.Add(intersect.Value); } intersect = Intersection(triangle.A, triangle.C, cutOptions.CutDepth); if (intersect != null) { intersectionList.Add(intersect.Value); } var firstPoint = pointsToInclude[0]; triangles.Add(new Triangle3D(firstPoint, intersectionList[0].Intersection, intersectionList[1].Intersection)); if (pointsToInclude.Length == 2) { var secondPoint = pointsToInclude[1]; if (intersectionList[0].HasPoint(secondPoint)) { triangles.Add(new Triangle3D(firstPoint, secondPoint, intersectionList[0].Intersection)); } else if (intersectionList[1].HasPoint(secondPoint)) { triangles.Add(new Triangle3D(firstPoint, secondPoint, intersectionList[1].Intersection)); } else { throw new Exception("Unexpected program behavior."); } } } } return(new TriangulatedSurface(triangles.ToArray())); }
private static void HandleInvocation(SyntaxNodeAnalysisContext context) { if (context.IsExcludedFromAnalysis()) { return; } var invocation = (InvocationExpressionSyntax)context.Node; var setter = invocation.FirstAncestorOrSelf <AccessorDeclarationSyntax>(); if (setter?.IsKind(SyntaxKind.SetAccessorDeclaration) != true) { return; } if (!IsFirstNotifyPropertyChange(invocation, context.SemanticModel, context.CancellationToken)) { return; } var propertyDeclaration = setter.FirstAncestorOrSelf <PropertyDeclarationSyntax>(); var property = context.SemanticModel.GetDeclaredSymbolSafe(propertyDeclaration, context.CancellationToken); if (!Property.TryGetBackingField(property, context.SemanticModel, context.CancellationToken, out IFieldSymbol backingField)) { return; } if (Property.TryFindValue(setter, context.SemanticModel, context.CancellationToken, out IParameterSymbol value)) { using (var pooledIfStatements = IfStatementWalker.Create(setter)) { foreach (var ifStatement in pooledIfStatements.Item.IfStatements) { if (ifStatement.SpanStart >= invocation.SpanStart) { continue; } foreach (var member in new ISymbol[] { backingField, property }) { if (Equality.IsOperatorEquals(ifStatement.Condition, context.SemanticModel, context.CancellationToken, value, member) || IsEqualsCheck(ifStatement.Condition, context.SemanticModel, context.CancellationToken, value, member)) { if (ifStatement.Statement.Span.Contains(invocation.Span)) { context.ReportDiagnostic(Diagnostic.Create(Descriptor, invocation.FirstAncestorOrSelf <StatementSyntax>()?.GetLocation() ?? invocation.GetLocation())); } return; } if (Equality.IsOperatorNotEquals(ifStatement.Condition, context.SemanticModel, context.CancellationToken, value, member) || IsNegatedEqualsCheck(ifStatement.Condition, context.SemanticModel, context.CancellationToken, value, member)) { if (!ifStatement.Statement.Span.Contains(invocation.Span)) { context.ReportDiagnostic(Diagnostic.Create(Descriptor, invocation.FirstAncestorOrSelf <StatementSyntax>()?.GetLocation() ?? invocation.GetLocation())); } return; } if (UsesValueAndMember(ifStatement, context.SemanticModel, context.CancellationToken, value, member)) { return; } } } } } context.ReportDiagnostic(Diagnostic.Create(Descriptor, invocation.FirstAncestorOrSelf <StatementSyntax>()?.GetLocation() ?? invocation.GetLocation())); }
public bool Equals(FieldIdentity other) => Equality.Combine(this, other, m => m.Metadata, m => m.Name);
public Equality CompareBinary(FileInfo fi1, FileInfo fi2, Logger log) { bool compareHigh = false; Equality equalityStatus = Equality.NotMatching; if (!CompareHighLevel(fi1, fi2)) { return(Equality.NotMatching); } else { compareHigh = true; } using (Stream stream1 = new FileStream(fi1.FullName, FileMode.Open, FileAccess.ReadWrite), stream2 = new FileStream(fi2.FullName, FileMode.Open, FileAccess.ReadWrite)) { try { long difference = 0, i = 0; for (; i < stream1.Length && i < stream2.Length; i++) { int byte1 = stream1.ReadByte(); int byte2 = stream2.ReadByte(); if (byte1 != byte2) { difference++; } } if (i == stream1.Length && i == stream2.Length) { if (difference == 0) { equalityStatus = Equality.ExactlyMatching; } else if (difference > 0) { equalityStatus = (compareHigh) ? Equality.PartialMatchHighLevelMatch : Equality.PartialMatch; } } else if ((i == stream1.Length && i != stream2.Length) || (i >= stream1.Length && i == stream2.Length)) { if (i >= (stream1.Length / 2) || (difference < i - (i / 20))) { equalityStatus = (compareHigh) ? Equality.PartialMatchHighLevelMatch : Equality.PartialMatch;; } } } catch (Exception ex) { log.OpenLog(); log.WriteLog(ex.Message); log.CloseLog(); }//catch finally { if (stream1 != null) { stream1.Close(); } if (stream2 != null) { stream2.Close(); } } //finally closed } //Usings closed return(equalityStatus); }
/// <summary> /// Idem IndexOf(object), but with a start index and a specified equality function /// </summary> /// <param name="Object">The object to locate.</param> /// <param name="Start">The index for start position.</param> /// <param name="AreEqual">Equality function to use for the search.</param> /// <returns></returns> public int IndexOf(object Object, int Start, Equality AreEqual) { if ( Start<0 || Start>=FList.Count ) throw new ArgumentException("Start index must belong to [0; Count-1]."); for (int i=Start; i<FList.Count; i++) if ( AreEqual(FList[i], Object) ) return i; return -1; }
public override bool Equals(object obj) { return(Equality.OfType(this, obj)); }
public bool Equals(IReference other) => Equality.Combine(this, other, m => m.Key, m => m.Metadata.Identity);
public CustomFlaggedStreamedCollection(Stream stream, SizeEncoding countSizing, SizeEncoding itemSizing, Func <T, int> dataSizer, Func <F, int> flagSizer, Func <T, F> itemFlag, Func <F, bool> hasData, Func <Stream, F> flagReader, Action <Stream, F> flagWriter, Func <Stream, F, int, T> dataReader, Action <Stream, F, int, T> dataWriter, Equality <T> itemEquality, ICollection <T> coll, bool leaveOpen, bool boostAccess, bool initialize) : base(stream, leaveOpen, boostAccess) { if (dataSizer == null) { throw new ArgumentNullException("dataSizer"); } if (flagSizer == null) { throw new ArgumentNullException("flagSizer"); } if (itemFlag == null) { throw new ArgumentNullException("itemFlag"); } if (hasData == null) { throw new ArgumentNullException("hasData"); } if (flagReader == null) { throw new ArgumentNullException("flagReader"); } if (flagWriter == null) { throw new ArgumentNullException("flagWriter"); } if (dataReader == null) { throw new ArgumentNullException("dataReader"); } if (dataWriter == null) { throw new ArgumentNullException("dataWriter"); } _countSizing = countSizing; _itemSizing = itemSizing; _flagSize = null; _flagSizer = flagSizer; _dataSize = null; _dataSizer = dataSizer; _compact = false; _itemFlag = itemFlag; _hasData = hasData; _flagReader = flagReader; _flagWriter = flagWriter; _dataReader = dataReader; _dataWriter = dataWriter; _dataEquality = itemEquality != null ? itemEquality : EqualityComparer <T> .Default.Equals; if (initialize) { BaseStream.Position = 0; Initialize(coll ?? default(T).Repeat(0)); } }
public static bool operator >(Power left, Power right) => Equality.IsStructureGreaterThan(left, right);
public CustomFlaggedStreamedCollection(Stream stream, SizeEncoding countSizing, SizeEncoding itemSizing, Func <T, int> dataSizer, Func <F, int> flagSizer, Func <T, F> itemFlag, Func <F, bool> hasData, Func <Stream, F> flagReader, Action <Stream, F> flagWriter, Func <Stream, F, int, T> dataReader, Action <Stream, F, int, T> dataWriter, Equality <T> itemEquality, bool leaveOpen, bool boostAccess, bool initialize) : this(stream, countSizing, itemSizing, dataSizer, flagSizer, itemFlag, hasData, flagReader, flagWriter, dataReader, dataWriter, itemEquality, null, leaveOpen, boostAccess, initialize) { }
public PartialEqF(IEqF <T1, T2, U> f, T1 arg1) { this.f = f; this.arg1 = arg1; hashCode = Equality.HashCode("PartialEqF<T1, T2, U>", f, arg1); }
protected virtual String ParseEquality(Equality equality) { String parsed = ""; if (equality is Equals) { parsed = "="; } else if (equality is GreaterThan) { parsed = ">"; } else if (equality is GreaterThanEquals) { parsed = ">="; } else if (equality is LessThan) { parsed = "<"; } else if (equality is LessThanEquals) { parsed = "<="; } return parsed; }
public bool Equals(PartialEqF <T1, T2, U> other) => Equality.Equatable <PartialEqF <T1, T2, U> >(this, other);
public CustomFlaggedStreamedRegularArray(Stream stream, SizeEncoding countSizing, SizeEncoding itemSizing, Func <T, int> dataSizer, int flagSize, Func <T, F> itemFlag, Func <F, bool> hasData, Func <Stream, F> flagReader, Action <Stream, F> flagWriter, Func <Stream, F, int, T> dataReader, Action <Stream, F, int, T> dataWriter, Equality <T> itemEquality, Array array, bool leaveOpen, bool boostAccess, bool initialize) : this(stream, countSizing, itemSizing, dataSizer, flagSize, itemFlag, hasData, flagReader, flagWriter, dataReader, dataWriter, itemEquality, array.GetRegularArrayLengths(), initialize ? array.EnumerateAsRegular <T>().Counted(array.Length) : null, leaveOpen, boostAccess, initialize) { }
public CustomFlaggedStreamedRegularArray(Stream stream, SizeEncoding countSizing, SizeEncoding itemSizing, Func <T, int> dataSizer, int flagSize, Func <T, F> itemFlag, Func <F, bool> hasData, Func <Stream, F> flagReader, Action <Stream, F> flagWriter, Func <Stream, F, int, T> dataReader, Action <Stream, F, int, T> dataWriter, Equality <T> itemEquality, int[] lengths, ICollection <T> coll, bool leaveOpen, bool boostAccess, bool initialize) : this(stream, countSizing, itemSizing, dataSizer, flagSize, itemFlag, hasData, flagReader, flagWriter, dataReader, dataWriter, itemEquality, new RegularArrayInfo(lengths), coll, leaveOpen, boostAccess, initialize) { }
public Check(string type, string value, bool invert = false, bool contains = true, Equality compare = Equality.Equals) { this.type = getType(type); this.value = value; this.invert = invert; this.contains = contains; equality = compare; this.checks = new List<Check>(); }
private Expression ParseRelationalExpression(TokenSet followers) { TokenSet followerOrRelational = followers|Parser.RelationalOperators; Expression result = this.ParseAdditiveExpression(followerOrRelational); while (Parser.RelationalOperators[this.currentToken]) { SourceLocationBuilder slb = new SourceLocationBuilder(result.SourceLocation); Token operatorToken = this.currentToken; this.GetNextToken(); Expression operand2 = this.ParseAdditiveExpression(followerOrRelational); slb.UpdateToSpan(operand2.SourceLocation); switch (operatorToken){ case Token.Equals: result = new Equality(result, operand2, slb); break; case Token.GreaterThan: result = new GreaterThan(result, operand2, slb); break; case Token.GreaterThanEqualTo: result = new GreaterThanOrEqual(result, operand2, slb); break; case Token.LessThan: result = new LessThan(result, operand2, slb); break; case Token.LessThanEqualTo: result = new LessThanOrEqual(result, operand2, slb); break; case Token.NotEqualTo: result = new NotEquality(result, operand2, slb); break; } } //^ assume followers[this.currentToken] || this.currentToken == Token.EndOfFile; return result; }
/// <summary> /// Idem IndexOf(object), but with a start index and a specified equality function /// </summary> /// <param name="obj">The object to locate.</param> /// <param name="start">The index for start position.</param> /// <param name="areEqual">Equality function to use for the search.</param> /// <returns></returns> public int IndexOf(object obj, int start, Equality areEqual) { if (start < 0 || start >= FList.Count) throw new ArgumentException("Start index must belong to [0; Count-1]."); for (int i = start; i < FList.Count; i++) if (areEqual(FList[i], obj)) return i; return -1; }
protected CustomFlaggedStreamedRegularArray(Stream stream, SizeEncoding countSizing, SizeEncoding itemSizing, int dataSize, bool compact, int flagSize, Func <T, F> itemFlag, Func <F, bool> hasData, Func <Stream, F> flagReader, Action <Stream, F> flagWriter, Func <Stream, F, int, T> dataReader, Action <Stream, F, int, T> dataWriter, Equality <T> itemEquality, RegularArrayInfo arrayInfo, ICollection <T> coll, bool leaveOpen, bool boostAccess, bool initialize) : base(stream, leaveOpen, boostAccess && !compact) { if (arrayInfo == null) { throw new ArgumentNullException("arrayInfo"); } if (dataSize < 0) { throw new ArgumentOutOfRangeException("dataSize"); } if (flagSize < 0) { throw new ArgumentOutOfRangeException("flagSize"); } if (itemFlag == null) { throw new ArgumentNullException("itemFlag"); } if (hasData == null) { throw new ArgumentNullException("hasData"); } if (flagReader == null) { throw new ArgumentNullException("flagReader"); } if (flagWriter == null) { throw new ArgumentNullException("flagWriter"); } if (dataReader == null) { throw new ArgumentNullException("dataReader"); } if (dataWriter == null) { throw new ArgumentNullException("dataWriter"); } _countSizing = countSizing; _itemSizing = itemSizing; _flagSize = flagSize; _dataSize = dataSize; _dataSizer = t => dataSize; _compact = compact; _itemFlag = itemFlag; _hasData = hasData; _flagReader = flagReader; _flagWriter = flagWriter; _dataReader = dataReader; _dataWriter = dataWriter; _dataEquality = itemEquality != null ? itemEquality : EqualityComparer <T> .Default.Equals; _arrayInfo = arrayInfo; if (initialize) { BaseStream.Position = 0; Initialize(coll ?? default(T).Repeat(ArrayInfo.Length)); } }
public void ExecuteTest2() { var eq = new Equality(new Bool(true), new Bool(false)); Assert.False((bool)eq.Execute()); }
/// <summary> /// Idem IndexOf(object), but with a specified equality function /// </summary> /// <param name="obj">The object to locate.</param> /// <param name="areEqual">Equality function to use for the search.</param> /// <returns></returns> public int IndexOf(object obj, Equality areEqual) { for (int i = 0; i < FList.Count; i++) if (areEqual(FList[i], obj)) return i; return -1; }
public static IEqualityComparer <T> CreateEqualityComparer <T, V>(this object obj, Func <T, V> keySelector) { return(Equality <T> .CreateComparer(keySelector)); }
/// <summary> /// Idem IndexOf(object), but with a specified equality function /// </summary> /// <param name="Object">The object to locate.</param> /// <param name="AreEqual">Equality function to use for the search.</param> /// <returns></returns> public int IndexOf(object Object, Equality AreEqual) { for (int i=0; i<FList.Count; i++) if ( AreEqual(FList[i], Object) ) return i; return -1; }
public bool Equals(CompositeKey <T1> other) => Equality.Combine(this.item1, other.item1);
public bool Equals(CompositeKey <T1, T2, T3> other) => Equality.Combine(this, other, m => m.item1, m => m.item2, m => m.item3);
/// <summary> /// Parses a single equality, editing the outer JObject /// </summary> /// <param name="equality"></param> /// <param name="outer"></param> /// <returns></returns> protected virtual JObject ParseEquality(Equality equality, JObject outer) { Field field = equality.FirstOrDefault(statement => statement is Field) as Field; Value value = equality.FirstOrDefault(statement => statement is Value) as Value; if (field != null && value != null) { String parsedField = this.ParseField(field); String parsedEquality = this.ParseEquality(equality); Object parsedValue = this.ParseValue(value); if (String.IsNullOrEmpty(parsedEquality) == true) { outer.Add(new JProperty(parsedField, parsedValue)); } else { if (outer[parsedField] == null) { outer[parsedField] = new JObject(); } ((JObject)outer[parsedField]).Add(new JProperty(parsedEquality, parsedValue)); } } return outer; }