public static bool HasMatchingIDs(this PushPullObjectComparison a, PushPullObjectComparison b) { if (a == null || b == null) { return(false); } return(a.PropertyID == b.PropertyID); }
public static ComparisonDifference NewResultAfterCrashFix(this PushPullObjectComparison result) { if (result == null) { return(null); } return(new ComparisonDifference { Message = "Difference now showing after previous crash.", ReferenceValue = result.ReturnedItem, Property = result.PropertyID, Status = oM.Test.TestStatus.Warning }); }
public static ComparisonDifference OnlyReferenceFound(this PushPullObjectComparison refResult) { if (refResult == null) { return(null); } return(new ComparisonDifference { Message = "Difference only found in reference.", ReferenceValue = refResult.ReturnedItem, Property = refResult.PropertyID, Status = oM.Test.TestStatus.Warning, }); }
public static ComparisonDifference NoReferenceFound(this PushPullObjectComparison result) { if (result == null) { return(null); } //No avilable reference return(new ComparisonDifference { Message = "A difference has been introduced.", Status = oM.Test.TestStatus.Error, Property = result.PropertyID, RunValue = result.ReturnedItem }); }
/***************************************************/ private static bool KeepResult(PushPullObjectComparison diffrences, List <string> propertiesToIgnore) { if (propertiesToIgnore == null || propertiesToIgnore.Count == 0) { return(true); } foreach (string prop in propertiesToIgnore) { if (diffrences.PropertyID.Contains(prop)) { return(false); } } return(true); }
/***************************************************/ /**** Private Methods ****/ /***************************************************/ private static double PushPullValueDifference(PushPullObjectComparison diffObj) { double input, output; if (!double.TryParse(diffObj.PushedItem.ToString(), out input) || !double.TryParse(diffObj.ReturnedItem.ToString(), out output)) { return(0); } if (input == 0 && output == 0) { return(0); } if (input == 0) { return(Math.Abs(input - output) / output); } return(Math.Abs(input - output) / input); }
/***************************************************/ private static oM.Test.ITestInformation GetSameIDInformation(this IEnumerable <oM.Test.ITestInformation> infoList, PushPullObjectComparison toFind) { //Find exact match oM.Test.ITestInformation found = infoList.FirstOrDefault(x => x.IHasMatchingIDs(toFind)); //If no exact match found, look for partial match if (found == null) { found = infoList.OfType <PushPullObjectComparison>().FirstOrDefault(x => x.PropertyID.Contains(toFind.PropertyID) || toFind.PropertyID.Contains(x.PropertyID)); } return(found); }
public static ComparisonDifference Compare(PushPullObjectComparison result, PushPullObjectComparison reference) { if (result == null) { return(null); } if (reference == null) { //No available reference return(result.NoReferenceFound()); } else if (result.PropertyID != reference.PropertyID) { if (result.PropertyID.Contains(reference.PropertyID)) { //Results property ID is a subpart of the reference. This mean the new result is closer to the original pushed object return(new ComparisonDifference { Message = "Run item is showing a difference of an inner property of an object that was previously showing difference on a higher level object. This is likely an improvement, but needs to be validated!", Status = oM.Test.TestStatus.Warning, Property = result.PropertyID, RunValue = result.ReturnedItem, ReferenceValue = reference.PropertyID }); } else if (reference.PropertyID.Contains(result.PropertyID)) { //Opposite of the above. The reference is showing a difference on a inner more property than the just run data. //This generally should mean a worsening of the convert situation. return(new ComparisonDifference { Message = "Run item is showing a difference on an outermore property compared to the reference. This possibly means a convert has been made worse.", Status = oM.Test.TestStatus.Error, Property = result.PropertyID, RunValue = result.ReturnedItem, ReferenceValue = reference.PropertyID }); } else { return(new ComparisonDifference { Message = "Unable to compare results as properties are different.", Status = oM.Test.TestStatus.Error, Property = result.PropertyID, RunValue = result.ReturnedItem, ReferenceValue = reference.PropertyID }); } } else if (result.PushedItem != reference.PushedItem) { //Different data has been pushed return(new ComparisonDifference { Message = "The input data has changed", Status = oM.Test.TestStatus.Error, Property = result.PropertyID, RunValue = result.PushedItem, ReferenceValue = reference.PushedItem }); } else if (result.ReturnedItem == reference.ReturnedItem) { //Identical return as the reference return(new ComparisonDifference { Message = "Difference is unchanged", Status = oM.Test.TestStatus.Pass, Property = result.PropertyID, RunValue = result.ReturnedItem, ReferenceValue = reference.ReturnedItem }); } else { //Something is different than before //Try extract numerical information to try to deduce if it is an improvement or not double d, d1, d2; if (double.TryParse(result.PushedItem, out d) && double.TryParse(result.ReturnedItem, out d1) && double.TryParse(reference.ReturnedItem, out d2)) { double diffVal1 = Math.Abs(d - d1); double diffVal2 = Math.Abs(d - d2); if (diffVal1 == diffVal2) { //Equal //Identical return as the reference return(new ComparisonDifference { Message = "Difference is unchanged", Status = oM.Test.TestStatus.Pass, Property = result.PropertyID, RunValue = result.ReturnedItem, ReferenceValue = reference.ReturnedItem }); } else if (diffVal1 < diffVal2) { //Improvement return(new ComparisonDifference { Message = "Return data is different from the reference, but is a probable improvement.", Status = oM.Test.TestStatus.Warning, Property = result.PropertyID, RunValue = result.ReturnedItem, ReferenceValue = reference.ReturnedItem }); } else { //Worsened return(new ComparisonDifference { Message = "Data is different from the reference, worse than reference.", Status = oM.Test.TestStatus.Error, Property = result.PropertyID, RunValue = result.ReturnedItem, ReferenceValue = reference.ReturnedItem }); } } else { //Can not extract numerical information, report back that there is a difference return(new ComparisonDifference { Message = "Data is different from the reference", Status = oM.Test.TestStatus.Error, Property = result.PropertyID, RunValue = result.ReturnedItem, ReferenceValue = reference.ReturnedItem }); } } }