public void ShouldReportGeneralDiffWhenDiffAfterMultipleSpace() { var stringDifference = StringDifference.Analyze("toto t", "toto ", false); Check.That(stringDifference).HasSize(1); Check.That(stringDifference[0].Kind).IsEqualTo(DifferenceMode.Longer); }
/// <summary> /// Compare two <see cref="IChemObject"/> classes and return the difference as an <see cref="IDifference"/>. /// </summary> /// <param name="first">the first of the two classes to compare</param> /// <param name="second">the second of the two classes to compare</param> /// <returns>an <see cref="IDifference"/> representation of the difference between the first and second <see cref="IChemObject"/>.</returns> public static IDifference Difference(IChemObject first, IChemObject second) { if (!(first is IAtomType && second is IAtomType)) { return(null); } var firstElem = (IAtomType)first; var secondElem = (IAtomType)second; var totalDiff = new ChemObjectDifference("AtomTypeDiff"); totalDiff.AddChild(StringDifference.Construct("N", firstElem.AtomTypeName, secondElem.AtomTypeName)); totalDiff.AddChild(BondOrderDifference.Construct("MBO", firstElem.MaxBondOrder, secondElem.MaxBondOrder)); totalDiff .AddChild(DoubleDifference.Construct("BOS", firstElem.BondOrderSum, secondElem.BondOrderSum)); totalDiff .AddChild(IntegerDifference.Construct("FC", firstElem.FormalCharge, secondElem.FormalCharge)); totalDiff.AddChild(AtomTypeHybridizationDifference.Construct("H", firstElem.Hybridization, secondElem.Hybridization)); totalDiff.AddChild(IntegerDifference.Construct("NC", firstElem.FormalNeighbourCount, secondElem.FormalNeighbourCount)); totalDiff.AddChild(DoubleDifference.Construct("CR", firstElem.CovalentRadius, secondElem.CovalentRadius)); totalDiff.AddChild(IntegerDifference.Construct("V", firstElem.Valency, secondElem.Valency)); totalDiff.AddChild(IsotopeDiff.Difference(first, second)); if (totalDiff.ChildCount() > 0) { return(totalDiff); } else { return(null); } }
public void ShouldReportDifferenceInSpacesAtEnd() { var stringDifference = StringDifference.Analyze("toto ", "toto ", false); Check.That(stringDifference).HasSize(1); Check.That(stringDifference[0].Kind).IsEqualTo(DifferenceMode.Spaces); }
public void ShouldReportDifferenceForGeneralEvenIfFirstDiffIsCase() { var stringDifferences = StringDifference.Analyze("food", "FoOGd", false); Check.That(stringDifferences).HasSize(1); Check.That(stringDifferences[0].Kind).IsEqualTo(DifferenceMode.General); Check.That(stringDifferences[0].Position).IsEqualTo(3); }
public void ShouldReportDifferenceForLongerTextOnMultiline() { var stringDifferences = StringDifference.Analyze("foo bar\ntest", "foo\ntest", false); Check.That(stringDifferences).HasSize(1); Check.That(stringDifferences[0].Kind).IsEqualTo(DifferenceMode.LongerLine); Check.That(stringDifferences[0].Position).IsEqualTo(3); }
public void ShouldReportDifferentLineWhenOneLine() { var stringDifferences = StringDifference.Analyze("foo", "far", false); Check.That(stringDifferences).HasSize(1); Check.That(stringDifferences[0].Kind).IsEqualTo(DifferenceMode.GeneralSameLength); Check.That(stringDifferences[0].Position).IsEqualTo(1); }
public void ShouldReportDifferenceForShorterTextOnMultiline() { var stringDifferences = StringDifference.Analyze("toto\ntest", "toto et tata\ntest", false); Check.That(stringDifferences).HasSize(1); Check.That(stringDifferences[0].Kind).IsEqualTo(DifferenceMode.ShorterLine); Check.That(stringDifferences[0].Position).IsEqualTo(4); }
public void ShouldReportDifferenceForGeneralSameLength() { var stringDifferences = StringDifference.Analyze("food", "FoOG", false); Check.That(stringDifferences).HasSize(1); Check.That(stringDifferences[0].Kind).IsEqualTo(DifferenceMode.GeneralSameLength); Check.That(stringDifferences[0].Position).IsEqualTo(3); }
public void ShouldReportDifferenceForCaseSensitive() { var stringDifferences = StringDifference.Analyze("foo", "foO", false); Check.That(stringDifferences).HasSize(1); Check.That(stringDifferences[0].Kind).IsEqualTo(DifferenceMode.CaseDifference); Check.That(stringDifferences[0].Position).IsEqualTo(2); }
public void ShouldReportDifferenceOfEoL() { var stringDifferences = StringDifference.Analyze("toto\ntiti", "toto\r\ntiti", false); Check.That(stringDifferences).HasSize(1); Check.That(stringDifferences[0].Kind).IsEqualTo(DifferenceMode.EndOfLine); Check.That(stringDifferences[0].Position).IsEqualTo(4); Check.That(stringDifferences[0].Line).IsEqualTo(0); }
public void ShouldProvideSyntheticView() { var stringDifferences = StringDifference.Analyze("toto\ntiti", "toto\nTiTi", false); Check.That(StringDifference.Summarize(stringDifferences)).IsEqualTo(DifferenceMode.CaseDifference); stringDifferences = StringDifference.Analyze("Toto\ntiti", "toto\ntata", false); Check.That(StringDifference.Summarize(stringDifferences)).IsEqualTo(DifferenceMode.General); }
public void ShouldReportDifferenceOfNumberOfLinesL() { var stringDifferences = StringDifference.Analyze("toto\ntiti", "toto", false); Check.That(stringDifferences).HasSize(1); Check.That(stringDifferences[0].Kind).IsEqualTo(DifferenceMode.ExtraLines); Check.That(stringDifferences[0].Position).IsEqualTo(0); Check.That(stringDifferences[0].Line).IsEqualTo(1); stringDifferences = StringDifference.Analyze("toto", "toto\n", false); Check.That(stringDifferences).HasSize(1); Check.That(stringDifferences[0].Kind).IsEqualTo(DifferenceMode.MissingLines); Check.That(stringDifferences[0].Position).IsEqualTo(0); Check.That(stringDifferences[0].Line).IsEqualTo(1); }
private static void PerformEqualCheck(object expected, ICheckLogic <string> test, bool ignoreCase = false) { test.DefineExpectedValue(expected) .OnNegate("The {0} is equal to the {1} whereas it must not.", MessageOption.NoCheckedBlock) .FailWhen((sut) => expected == null && sut != null, "The {0} is not null whereas it must.") .FailWhen((sut) => expected != null && sut == null, "The {0} is null whereas it must not.") .Analyze((sut, runner) => { var details = StringDifference.Analyze(sut, (string)expected, ignoreCase); if (details != null && details.Count > 0) { runner.Fail(StringDifference.SummaryMessage(details)); } }) .EndCheck(); }
public void ShouldReportDifferenceForMultipleLines() { var stringDifferences = StringDifference.Analyze("toto\ntiti", "toto\ntata", false); Check.That(stringDifferences).HasSize(1); Check.That(stringDifferences[0].Kind).IsEqualTo(DifferenceMode.GeneralSameLength); Check.That(stringDifferences[0].Position).IsEqualTo(1); Check.That(stringDifferences[0].Line).IsEqualTo(1); stringDifferences = StringDifference.Analyze("maybe\ntiti", "toto\ntatata", false); Check.That(stringDifferences).HasSize(2); Check.That(stringDifferences[0].Kind).IsEqualTo(DifferenceMode.General); Check.That(stringDifferences[0].Position).IsEqualTo(0); Check.That(stringDifferences[0].Line).IsEqualTo(0); Check.That(stringDifferences[1].Kind).IsEqualTo(DifferenceMode.General); Check.That(stringDifferences[1].Position).IsEqualTo(1); Check.That(stringDifferences[1].Line).IsEqualTo(1); }
bool AreEqual(TypedValue actualValue, TypedValue expectedValue, Cell expectedCell) { if (expectedValue.Type == typeof(DateTime) && actualValue.Type == typeof(DateTime)) { return(expectedValue.ValueString == actualValue.ValueString); } if (expectedValue.IsNull) { return(actualValue.IsNull); } if (actualValue.IsNull) { return(false); } if (expectedValue.GetValueAs <Array>() != null && actualValue.GetValueAs <Array>() != null) { return(ArraysAreEqual(expectedValue.GetValueAs <Array>(), actualValue.GetValueAs <Array>())); } if (expectedValue.Type == typeof(string)) { if (expectedValue.ValueString == actualValue.ValueString) { return(true); } if (expectedCell != null) { var difference = new StringDifference(expectedValue.ValueString, actualValue.ValueString).ToString(); if (difference.Length > 0) { expectedCell.SetAttribute(CellAttribute.Difference, difference); } } return(false); } return(expectedValue.Value.Equals(actualValue.Value)); }
/// <summary> /// Compare two <see cref="IChemObject"/> classes and return the difference as an <see cref="IDifference"/>. /// /// <param name="first">the first of the two classes to compare</param> /// <param name="second">the second of the two classes to compare</param> /// <returns>an <see cref="IDifference"/> representation of the difference between the first and second <see cref="IChemObject"/>.</returns> /// </summary> public static IDifference Difference(IChemObject first, IChemObject second) { if (!(first is IElement && second is IElement)) { return(null); } var firstElem = (IElement)first; var secondElem = (IElement)second; var coDiff = new ChemObjectDifference("ElementDiff"); coDiff.AddChild(StringDifference.Construct("S", firstElem.Symbol, secondElem.Symbol)); coDiff.AddChild(StringDifference.Construct("ID", firstElem.Id, secondElem.Id)); coDiff.AddChild(IntegerDifference.Construct("AN", firstElem.AtomicNumber, secondElem.AtomicNumber)); coDiff.AddChild(ChemObjectDiff.Difference(first, second)); if (coDiff.ChildCount() > 0) { return(coDiff); } else { return(null); } }
public void ShouldHandleNullString() { Check.That(StringDifference.Analyze(null, "foo", false)).HasSize(1); }
} // CompanyIsDissolved private void IsDirector() { if (!Trail.MyInputData.MetaData.IsLimitedCompanyType) { StepDone <CustomerIsDirector>().Init(Trail.MyInputData.MetaData.IsLimitedCompanyType); return; } // if bool bIsDirector = false; if (Trail.MyInputData.DirectorNames.Count < 1) { StepFailed <CustomerIsDirector>().Init(Trail.MyInputData.CustomerName.ToString()); return; } // if foreach (Name name in Trail.MyInputData.DirectorNames) { if (Trail.MyInputData.CustomerName.Equals(name)) { bIsDirector = true; break; } // if } // for each name if (!bIsDirector) { var nc = new NameComparer( Trail.MyInputData.CustomerName, Trail.MyInputData.DirectorNames, this.agent.DB ); foreach (Name name in Trail.MyInputData.DirectorNames) { StringDifference firstNameDiff = nc[Trail.MyInputData.CustomerName.FirstName, name.FirstName]; if ((int)firstNameDiff >= (int)StringDifference.SoundVerySimilar) { StringDifference lastNameDiff = nc[Trail.MyInputData.CustomerName.LastName, name.LastName]; if ((int)lastNameDiff >= (int)StringDifference.SoundVerySimilar) { bIsDirector = true; break; } // if } // if } // for each name } // if if (bIsDirector) { StepDone <CustomerIsDirector>().Init( Trail.MyInputData.CustomerName.ToString(), Trail.MyInputData.DirectorNames.Select(n => n.ToString()).ToList() ); } else { StepFailed <CustomerIsDirector>().Init( Trail.MyInputData.CustomerName.ToString(), Trail.MyInputData.DirectorNames.Select(n => n.ToString()).ToList() ); } // if } // IsDirector
} // indexer private void Load(Name customerName, List <Name> directorNames, AConnection db) { var firstNames = new SortedSet <string>(); var lastNames = new SortedSet <string>(); foreach (Name name in directorNames) { string s = Normalize(name.FirstName); if (s != string.Empty) { firstNames.Add(s); } s = Normalize(name.LastName); if (s != string.Empty) { lastNames.Add(s); } } // for each diffMap.Clear(); if ((firstNames.Count == 0) && (lastNames.Count == 0)) { return; } db.ForEachRowSafe( sr => { NormalStringPair tpl = Normalize(sr["Alice"], sr["Boob"]); if (tpl.AreEqual) { return; } int mark = sr["Mark"]; StringDifference diff = Enum.IsDefined(typeof(StringDifference), mark) ? (StringDifference)mark : StringDifference.NotEqual; SortedDictionary <string, StringDifference> nameMap = this.diffMap.ContainsKey(tpl.Alice) ? this.diffMap[tpl.Alice] : null; if (nameMap == null) { this.diffMap[tpl.Alice] = new SortedDictionary <string, StringDifference> { { tpl.Boob, diff } } } ; else { nameMap[tpl.Boob] = diff; } }, "GetNameDifference", CommandSpecies.StoredProcedure, new QueryParameter("FirstName", Normalize(customerName.FirstName)), new QueryParameter("LastName", Normalize(customerName.LastName)), db.CreateTableParameter <string>("FirstNames", firstNames), db.CreateTableParameter <string>("LastNames", lastNames) ); } // Load
public IList <IQuickStartEntry> Sort(IList <IQuickStartEntry> list) { return(list.OrderBy(entry => StringDifference.CompareWordsIgnoreCase(CompareValue, entry.Name)).ToList()); }
public void ShouldNotHandleNullString() { Check.ThatCode(() => Check.That(StringDifference.Analyze(null, "foo", false)).HasSize(1)).Throws <NullReferenceException>(); }
public void ShouldNotReportWhenNoDifference() { Check.That(StringDifference.Analyze("foo", "foo", false)).IsNull(); }
} // CheckIsBroker private void CheckIsDirector() { if (!this.trail.MyInputData.MetaData.IsLimitedCompanyType) { StepDone <CustomerIsDirector>().Init(this.trail.MyInputData.MetaData.IsLimitedCompanyType); return; } // if bool isDirector = false; if (this.trail.MyInputData.DirectorNames.Count < 1) { StepFailed <CustomerIsDirector>().Init(this.trail.MyInputData.CustomerName.ToString()); return; } // if foreach (Name directorName in this.trail.MyInputData.DirectorNames) { if (directorName.Equals(this.trail.MyInputData.CustomerName)) { isDirector = true; break; } // if } // for if (!isDirector) { var nc = new NameComparer( this.trail.MyInputData.CustomerName, this.trail.MyInputData.DirectorNames, this.db ); foreach (Name name in this.trail.MyInputData.DirectorNames) { StringDifference firstNameDiff = nc[this.trail.MyInputData.CustomerName.FirstName, name.FirstName]; if ((int)firstNameDiff >= (int)StringDifference.SoundVerySimilar) { StringDifference lastNameDiff = nc[this.trail.MyInputData.CustomerName.LastName, name.LastName]; if ((int)lastNameDiff >= (int)StringDifference.SoundVerySimilar) { isDirector = true; break; } // if } // if } // for each name } // if if (!isDirector) { StepFailed <CustomerIsDirector>().Init( this.trail.MyInputData.CustomerName.ToString(), this.trail.MyInputData.DirectorNames.Select(x => x.ToString()).ToList() ); } else { StepDone <CustomerIsDirector>().Init( this.trail.MyInputData.CustomerName.ToString(), this.trail.MyInputData.DirectorNames.Select(x => x.ToString()).ToList() ); } // if } // CheckIsDirector
public void ShouldNotReportDifferenceForCaseSensitiveWhenDisabled() { var stringDifferences = StringDifference.Analyze("foo", "foO", true); Check.That(stringDifferences).HasSize(0); }