// -------------------------------------------------------------------------------------------------------------------------- public Tuple <bool, string> CompareArrays <TValue>(Array src, Array comp, Func <TValue, TValue, bool> compareFunc = null) { int srcRank = src.Rank; int compRank = comp.Rank; if (srcRank != compRank) { string errMsg = "Array ranks don't match! --> src={0} : comp={1}"; return(new Tuple <bool, string>(false, string.Format(errMsg, srcRank, compRank))); } int[] srcDims = ArrayHelpers.GetDims(src); int[] compDims = ArrayHelpers.GetDims(comp); for (int i = 0; i < srcDims.Length; i++) { if (srcDims[i] != compDims[i]) { string errMsg = "Array dimensions at index {0} don't match! --> {1} : {2}"; return(new Tuple <bool, string>(false, string.Format(errMsg, i, srcDims[i], compDims[i]))); } } int[] sizes = ArrayHelpers.GetSizes(srcDims); int len = ArrayHelpers.GetTotalElements(srcDims); for (int i = 0; i < len; i++) { int[] addr = ArrayHelpers.ComputeIndicies(srcDims, sizes, i); TValue srcVal = (TValue)src.GetValue(addr); TValue compVal = (TValue)comp.GetValue(addr); // TODO: This is basically the same thing as the list comparison function, so let's see about some // consolidation.... bool match = false; if (CachedReports.ContainsKey(srcVal, compVal)) { // TODO: This may need some closer inspection. We are just skipping items that haven't completed their inspection. // They may or may not actually come out OK, but I'm not 100% sure at this point. Of course, I think that if // anything fails, then the whole process will fail....... // TODO: I think that the list comparison code may need some similar concessions made...... var report = CachedReports[srcVal, compVal]; if (report.InspectionComplete) { match = report.ObjectsMatch.HasValue && report.ObjectsMatch.Value; } else { continue; } } else { match = CompareValues(srcVal, compVal, "List Item " + i, compareFunc); } if (!match) { string errMsg = "Array items do not match at location {0} --> src={0} : comp={1}"; return(new Tuple <bool, string>(false, string.Format(errMsg, string.Join(",", addr), srcVal, compVal))); } } // Everything was OK! return(new Tuple <bool, string>(true, null)); }