private static bool AreValuesEqual( [NotNull] EqualFieldValuesCondition condition, [NotNull] IRow row1, int tableIndex1, [NotNull] IRow row2, int tableIndex2, [CanBeNull] out string message, [CanBeNull] HashSet <string> unequalFieldNames = null) { StringBuilder sb = null; foreach (UnequalField unequalField in condition.GetNonEqualFields( row1, tableIndex1, row2, tableIndex2)) { if (sb == null) { sb = new StringBuilder(); } sb.AppendFormat(sb.Length == 0 ? "{0}" : ";{0}", unequalField.Message); unequalFieldNames?.Add(unequalField.FieldName.ToUpper()); } if (sb != null) { message = sb.ToString(); return(false); } message = null; return(true); }
public void CanDetectEqualFieldValues() { ITable table1; ITable table2; CreateTables(out table1, out table2); DateTime now = DateTime.Now; IRow row1 = AddRow(table1, "X", 10, now); // double difference is non-significant IRow row2 = AddRow(table2, "X", 10.000000000000001, now); string fieldNames = StringUtils.Concatenate( new[] { _textFieldName, _doubleFieldName, _dateFieldName }, ","); var condition = new EqualFieldValuesCondition(fieldNames, null, new[] { table1, table2 }, caseSensitive: true); string message; var unequalFieldNames = new HashSet <string>(); bool equal = AreValuesEqual(condition, row1, 0, row2, 1, out message, unequalFieldNames); Console.WriteLine(message); Assert.True(equal); Assert.AreEqual(0, unequalFieldNames.Count); Assert.Null(message); }
GetAttributeConstraintViolations( [NotNull] IFeature feature, int classIndex, [NotNull] IFeature neighborFeature, int neighborClassIndex, [NotNull] RowPairCondition rowPairCondition, [NotNull] EqualFieldValuesCondition equalFieldValuesCondition, bool reportIndividually = false) { if (reportIndividually) { string message; IColumnNames errorColumnNames; if (!rowPairCondition.IsFulfilled(feature, classIndex, neighborFeature, neighborClassIndex, out message, out errorColumnNames)) { var affectedFields = new HashSet <string>( errorColumnNames.GetInvolvedColumnNames(), StringComparer.OrdinalIgnoreCase); yield return(new AttributeConstraintViolation( string.Format( LocalizableStrings .EdgeMatchUtils_AttributeConstraints_ConstraintNotFulfilled, message), affectedFields, message)); } IEnumerable <UnequalField> unequalFields = equalFieldValuesCondition.GetNonEqualFields(feature, classIndex, neighborFeature, neighborClassIndex); foreach (UnequalField unequalField in unequalFields) { yield return(new AttributeConstraintViolation( string.Format( LocalizableStrings.EdgeMatchUtils_AttributeConstraints_ValuesNotEqual, unequalField.Message), unequalField.FieldName, unequalField.Message)); } } else { string description; string affectedComponents; string textValue; bool areConstraintsFulfilled = AreAttributeConstraintsFulfilled( feature, classIndex, neighborFeature, neighborClassIndex, rowPairCondition, equalFieldValuesCondition, out description, out affectedComponents, out textValue); if (!areConstraintsFulfilled) { yield return(new AttributeConstraintViolation(description, affectedComponents, textValue)); } } }
public void CanAllowEquivalentValueSets() { ITable table1; ITable table2; CreateTables(out table1, out table2); DateTime now = DateTime.Now; IRow row1 = AddRow(table1, "X 1#Y 2", 10, now); // text values are equivalent IRow row2 = AddRow(table2, "Y2#X1", 10, now); string fieldNames = StringUtils.Concatenate( new[] { _textFieldName + ":#", _doubleFieldName, _dateFieldName }, ","); var condition = new EqualFieldValuesCondition(fieldNames, new[] { _textFieldName + ":ignore=[ ]" }, new[] { table1, table2 }, caseSensitive: true); string message; var unequalFieldNames = new HashSet <string>(); bool equal = AreValuesEqual(condition, row1, 0, row2, 1, out message, unequalFieldNames); Console.WriteLine(message); Assert.True(equal); Assert.AreEqual(0, unequalFieldNames.Count); Assert.IsNull(message); }
private static void CheckTextFieldDifference([NotNull] IRow row1, [NotNull] IRow row2, [NotNull] string fieldName, // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local bool expectEqual, string expectedMessage = null) { var options = new List <string> { "FLD_TEXT:ignoreCondition=_VALUE IS NULL OR Len(Trim(_VALUE)) = 0", "FLD_TEXT:allowedDifferenceCondition=G1.LAND = 'XX' AND G1._VALUE IS NOT NULL AND G2._VALUE IS NULL" }; var condition = new EqualFieldValuesCondition(fieldName, options, new[] { row1.Table, row2.Table }, caseSensitive: true); string message; bool equal = AreValuesEqual(condition, row1, 0, row2, 1, out message); Console.WriteLine(message); if (expectedMessage != null) { Assert.AreEqual(expectedMessage, message); } if (expectEqual) { Assert.True(equal); } else { Assert.False(equal); } }
public void CanDetectNonEqualFieldValues() { ITable table1; ITable table2; CreateTables(out table1, out table2); IRow row1 = AddRow(table1, "X", 10, new DateTime(2000, 12, 31)); IRow row2 = AddRow(table2, "Y", 10.0000001, new DateTime(2001, 1, 1)); string fieldNames = StringUtils.Concatenate( new[] { _textFieldName, _doubleFieldName, _dateFieldName }, ","); var condition = new EqualFieldValuesCondition(fieldNames, null, new[] { table1, table2 }, caseSensitive: true); string message; var unequalFieldNames = new HashSet <string>(); bool equal = AreValuesEqual(condition, row1, 0, row2, 1, out message, unequalFieldNames); Console.WriteLine(message); Assert.False(equal); Assert.AreEqual(3, unequalFieldNames.Count); Assert.AreEqual( "FLD_TEXT:'X','Y';FLD_DOUBLE:10,10.0000001;FLD_DATE:01/01/2001 00:00:00,12/31/2000 00:00:00", message); }
private static IList <EqualFieldValuesCondition.FieldInfo> Parse( [NotNull] string fields, [CanBeNull] IEnumerable <string> fieldOptions = null) { return(EqualFieldValuesCondition.ParseFieldInfos(fields, fieldOptions).ToList()); }
private static bool AreAttributeConstraintsFulfilled( [NotNull] IFeature feature, int classIndex, [NotNull] IFeature neighborFeature, int neighborClassIndex, [NotNull] RowPairCondition rowPairCondition, [NotNull] EqualFieldValuesCondition equalFieldValuesCondition, [NotNull] out string errorDescription, [CanBeNull] out string affectedComponents, [NotNull] out string textValue) { var affectedFields = new HashSet <string>(StringComparer.OrdinalIgnoreCase); // compare attributes that are required to match var descriptionBuilder = new StringBuilder(); var textValueBuilder = new StringBuilder(); string message; IColumnNames errorColumnNames; if (!rowPairCondition.IsFulfilled(feature, classIndex, neighborFeature, neighborClassIndex, out message, out errorColumnNames)) { descriptionBuilder.AppendFormat( LocalizableStrings.EdgeMatchUtils_AttributeConstraints_ConstraintNotFulfilled, message); foreach (string affectedColumn in errorColumnNames.GetInvolvedColumnNames()) { affectedFields.Add(affectedColumn); } textValueBuilder.Append(message); } IEnumerable <UnequalField> unequalFields = equalFieldValuesCondition.GetNonEqualFields(feature, classIndex, neighborFeature, neighborClassIndex); if (HasUnequalFields(unequalFields, out message, affectedFields)) { if (descriptionBuilder.Length > 0) { descriptionBuilder.Append(". "); } descriptionBuilder.AppendFormat( LocalizableStrings.EdgeMatchUtils_AttributeConstraints_ValuesNotEqual, message); if (textValueBuilder.Length > 0) { textValueBuilder.Append("|"); } textValueBuilder.Append(message); } errorDescription = descriptionBuilder.ToString(); affectedComponents = FormatAffectedComponents(affectedFields); textValue = textValueBuilder.ToString(); return(errorDescription.Length == 0); }