public void CreateDiffResult() { _result = new DiffResult(); _diff = new XmlDiff("<a/>", "<b/>"); _majorDifference = new Difference(DifferenceType.ElementTagName, XmlNodeType.Element, XmlNodeType.Element); _minorDifference = new Difference(DifferenceType.AttributeSequence, XmlNodeType.Comment, XmlNodeType.Comment); }
public override void Visit(Difference difference) { _differences.Add(difference); // For now use this to set the ExitCode to 2 if there are any differences DifferenceWriter.ExitCode = 2; }
private bool ListsHaveDifferentCounts(CompareParms parms) { IList ilist1 = parms.Object1 as IList; IList ilist2 = parms.Object2 as IList; if (ilist1 == null) throw new ArgumentException("parms.Object1"); if (ilist2 == null) throw new ArgumentException("parms.Object2"); //Objects must be the same length if (ilist1.Count != ilist2.Count) { Difference difference = new Difference { ParentObject1 = new WeakReference(parms.ParentObject1), ParentObject2 = new WeakReference(parms.ParentObject2), PropertyName = parms.BreadCrumb, Object1Value = ilist1.Count.ToString(CultureInfo.InvariantCulture), Object2Value = ilist2.Count.ToString(CultureInfo.InvariantCulture), ChildPropertyName = "Count", Object1 = new WeakReference(ilist1), Object2 = new WeakReference(ilist2) }; AddDifference(parms.Result, difference); if (parms.Result.ExceededDifferences) return true; } return false; }
protected bool Equals(Difference other) { return string.Equals(Breadcrumb, other.Breadcrumb) && string.Equals(ChildProperty, other.ChildProperty) && Equals(Value1, other.Value1) && Equals(Value2, other.Value2); }
public override string Format(Difference difference) { var setDifference = (SetDifference) difference; var sb = new StringBuilder(); sb.AppendFormat("Actual{0} != Expected{0}", setDifference.Breadcrumb); if (setDifference.Extra.Count != 0) { sb.AppendLine(); sb.AppendFormat("Actual{0} contains the following unmatched elements:", setDifference.Breadcrumb); foreach (var o in setDifference.Extra) { sb.AppendLine(); sb.AppendFormat("\t{0}", Prettify(o)); } } if (setDifference.Expected.Count != 0) { sb.AppendLine(); sb.AppendFormat("Expected{0} contains the following unmatched elements:", setDifference.Breadcrumb); foreach (var o in setDifference.Expected) { sb.AppendLine(); sb.AppendFormat("\t{0}", Prettify(o)); } } return sb.ToString(); }
public void Clone() { IScrTxtPara[] paras = DiffTestHelper.CreateDummyParas(2, Cache); Difference diff = new Difference( new ScrReference(1, 1, 1, ScrVers.English), new ScrReference(1, 1, 30, ScrVers.English), paras[0], 1, 99, paras[1], 11, 88, DifferenceType.PictureDifference, null, null, "Whatever", "Whateverelse", "Esperanto", "Latvian", null, null); //diff.SectionsCurr = new int[] {6, 7, 8}; Difference clonedDiff = diff.Clone(); Assert.AreEqual(1001001, clonedDiff.RefStart); Assert.AreEqual(1001030, clonedDiff.RefEnd); Assert.AreSame(paras[0], clonedDiff.ParaCurr); Assert.AreEqual(1, clonedDiff.IchMinCurr); Assert.AreEqual(99, clonedDiff.IchLimCurr); Assert.AreSame(paras[1], clonedDiff.ParaRev); Assert.AreEqual(11, clonedDiff.IchMinRev); Assert.AreEqual(88, clonedDiff.IchLimRev); //Assert.AreEqual(987654321, clonedDiff.hvoAddedSection); Assert.AreEqual(DifferenceType.PictureDifference, clonedDiff.DiffType); Assert.IsNull(clonedDiff.SubDiffsForParas); Assert.IsNull(clonedDiff.SubDiffsForORCs); Assert.AreEqual("Whatever", clonedDiff.StyleNameCurr); Assert.AreEqual("Whateverelse", clonedDiff.StyleNameRev); Assert.AreEqual("Esperanto", clonedDiff.WsNameCurr); Assert.AreEqual("Latvian", clonedDiff.WsNameRev); }
/// <summary> /// Compare two URIs /// </summary> public override void CompareType(CompareParms parms) { Uri uri1 = parms.Object1 as Uri; Uri uri2 = parms.Object2 as Uri; //This should never happen, null check happens one level up if (uri1 == null || uri2 == null) return; if (uri1.OriginalString != uri2.OriginalString) { Difference difference = new Difference { ParentObject1 = new WeakReference(parms.ParentObject1), ParentObject2 = new WeakReference(parms.ParentObject2), PropertyName = parms.BreadCrumb, Object1Value = NiceString(uri1.OriginalString), Object2Value = NiceString(uri2.OriginalString), ChildPropertyName = "OriginalString", Object1 = new WeakReference(parms.Object1), Object2 = new WeakReference(parms.Object2) }; AddDifference(parms.Result, difference); } }
public void Clone() { Difference diff = new Difference( new ScrReference(1, 1, 1, Paratext.ScrVers.English), new ScrReference(1, 1, 30, Paratext.ScrVers.English), 4711, 1, 99, 4712, 11, 88, DifferenceType.PictureDifference, null, null, "Whatever", "Whateverelse", "Esperanto", "Latvian", null, null); //diff.HvosSectionsCurr = new int[] {6, 7, 8}; Difference clonedDiff = diff.Clone(); Assert.AreEqual(1001001, clonedDiff.RefStart); Assert.AreEqual(1001030, clonedDiff.RefEnd); Assert.AreEqual(4711, clonedDiff.HvoCurr); Assert.AreEqual(1, clonedDiff.IchMinCurr); Assert.AreEqual(99, clonedDiff.IchLimCurr); Assert.AreEqual(4712, clonedDiff.HvoRev); Assert.AreEqual(11, clonedDiff.IchMinRev); Assert.AreEqual(88, clonedDiff.IchLimRev); //Assert.AreEqual(987654321, clonedDiff.hvoAddedSection); Assert.AreEqual(DifferenceType.PictureDifference, clonedDiff.DiffType); Assert.IsNull(clonedDiff.SubDiffsForParas); Assert.IsNull(clonedDiff.SubDiffsForORCs); Assert.AreEqual("Whatever", clonedDiff.StyleNameCurr); Assert.AreEqual("Whateverelse", clonedDiff.StyleNameRev); Assert.AreEqual("Esperanto", clonedDiff.WsNameCurr); Assert.AreEqual("Latvian", clonedDiff.WsNameRev); }
public DiffResultTests() { _result = new DiffResult(); _diff = new XmlDiff("<a/>", "<b/>"); _majorDifference = new Difference(DifferenceType.ELEMENT_TAG_NAME_ID, XmlNodeType.Element, XmlNodeType.Element); _minorDifference = new Difference(DifferenceType.ATTR_SEQUENCE_ID, XmlNodeType.Comment, XmlNodeType.Comment); }
public OperationTypeConflict( Difference differenceInSourceBranch, Difference differenceInDestinationBranch) : base(differenceInSourceBranch.Identifier) { r_differenceInSourceBranch = differenceInSourceBranch; r_differenceInDestinationBranch = differenceInDestinationBranch; }
public void ThrowsExceptionCgpNull() { var instance = new Difference(); var ex = Assert.Throws<ArgumentNullException>(() => instance.Generate(null)); Assert.Equal("cgp", ex.ParamName); }
/// <summary>overload for same end ref</summary> public static void VerifyParaDiff(Difference diff, BCVRef startAndEnd, DifferenceType type, StTxtPara paraCurr, int ichMinCurr, int ichLimCurr, StTxtPara paraRev, int ichMinRev, int ichLimRev) { VerifyParaDiff(diff, startAndEnd, startAndEnd, type, paraCurr, ichMinCurr, ichLimCurr, paraRev, ichMinRev, ichLimRev); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// <param name="differenceList"></param> /// <param name="reviewedList"></param> /// <param name="fRevert"><code>true</code> if we are reverting the difference (as /// opposed to keeping the current). If <c>true</c> a revert action is being created</param> /// ------------------------------------------------------------------------------------ public UndoDifferenceAction(DifferenceList differenceList, DifferenceList reviewedList, bool fRevert) { m_differenceList = differenceList; m_reviewedList = reviewedList; m_differenceRef = m_differenceList.CurrentDifference; m_differenceClone = m_differenceList.CurrentDifference.Clone(); m_index = m_differenceList.CurrentDifferenceIndex; m_fReverted = fRevert; }
private void m_buttonAccept_Click(object sender, EventArgs e) { if (m_radioKeepSource.Checked) { m_result = (Difference)m_radioKeepSource.Tag; } else { m_result = (Difference)m_radioKeepDestination.Tag; } }
public bool Include(Difference difference) { // Is the entire rule ignored? if (_ignoreDifferences.Contains(difference.Id)) return false; // Is the specific violation of the rule ignored? if (_ignoreDifferences.Contains(difference.ToString())) return false; return _filter.Include(difference); }
static void Main(string[] args) { int.Parse(Console.ReadLine()); int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); Difference d = new Difference(a); d.computeDifference(); Console.Write(d.maximumDifference); }
private static bool IsIncludeObject(Difference difference) { if (difference.DatabaseObjectType != ObjectType.User && difference.DatabaseObjectType != ObjectType.Role && difference.DatabaseObjectType != ObjectType.Queue && difference.DatabaseObjectType != ObjectType.Service && MeetExcludeSpecialCase(difference) == false) { return true; } return false; }
public override string Format(Difference diff) { var difference = (MissingEntryDifference) diff; var format = difference.Side == MissingSide.Expected ? "Expected{0}[{1}] not found (Actual{0}[{1}] = {2})" : "Actual{0}[{1}] not found (Expected{0}[{1}] = {2})"; return string.Format(format, difference.Breadcrumb, Prettify(difference.Key), Prettify(difference.Value)); }
public void FilterShouldReturnNullIfNoMatchingChildDiffs() { var difference = new Difference("prop", 1, 2) { ChildDiffs = new List<Difference> { new Difference("a", 1337, 0), } }; var filtered = difference.Filter(d => false); Assert.IsNull(filtered); }
public IDifferenceFormatter GetFormatter(Difference difference) { if (difference is MissingEntryDifference) { return new MissingEntryDifferenceFormatter(); } if (difference is SetDifference) { return new SetDifferenceFormatter(); } return new BasicDifferenceFormatter(); }
private string FormatProperty(Difference difference) { string shortItem = difference.GetShortItem(); StringBuilder sb = new StringBuilder(shortItem.Length); string[] words = shortItem.Split(new [] {'.'}, StringSplitOptions.RemoveEmptyEntries); foreach (var word in words) { sb.Append(StringHelper.InsertSpaces(word)); sb.Append(" "); } return sb.ToString().Trim(); }
private void FillDifferenceNode(TreeNode node, Difference difference) { node.Tag = difference; NodeDifference nodeDifference = difference as NodeDifference; if (nodeDifference != null) { foreach (Difference subdifference in nodeDifference.Subdifferences) { TreeNode subnode = node.Nodes.Add(subdifference.ToString()); FillDifferenceNode(subnode, subdifference); } } }
public void IndexerShouldReturnNullIfNoChildDiffExists() { var difference = new Difference("prop", 1, 2) { ChildDiffs = new List<Difference> { new Difference("b", "still nope", "nope") } }; var child = difference["a"]; Assert.IsNull(child); }
private static bool MeetExcludeSpecialCase(Difference difference) { if ((difference.DatabaseObjectType == ObjectType.Table && difference.Name.ToLower().StartsWith("[dbo].[aspnet_sql")) || (difference.DatabaseObjectType == ObjectType.StoredProcedure && difference.Name.ToLower().StartsWith("[dbo].[aspnet_sql")) || (difference.DatabaseObjectType == ObjectType.StoredProcedure && difference.Name.ToLower().StartsWith("[dbo].[sqlquery"))) { return true; } return false; }
public void DifferenceFound(XmlDiff inDiff, Difference difference) { _identical = false; if (difference.MajorDifference) { _equal = false; } _difference = difference; if (_stringBuilder.Length == 0) { _stringBuilder.Append(inDiff.OptionalDescription); } _stringBuilder.Append(Environment.NewLine).Append(difference); }
public void IndexerShouldReturnCorrectChildDiffIfExists() { var expected = new Difference("a", 1337, 0); var difference = new Difference("prop", 1, 2) { ChildDiffs = new List<Difference> { expected, new Difference("b", "still nope", "nope") } }; var child = difference["a"]; Assert.AreSame(expected, child); }
public OperationTypeConflictResolverForm( ConflictContext context, Difference differenceTypeInSourceBranch, Difference differenceTypeInDestinationBranch) { InitializeComponent(); FormPosition.LoadFromRegistry(this); m_result = null; m_conflictcontextcontrol.Data = context; m_radioKeepSource.Tag = differenceTypeInSourceBranch; m_textboxChangeDescriptionFromSourceBranch.Text = differenceTypeInSourceBranch.ToString(); m_radioKeepDestination.Tag = differenceTypeInDestinationBranch; m_textboxChangeDescriptionFromDestinationBranch.Text = differenceTypeInDestinationBranch.ToString(); m_buttonAccept.Enabled = false; }
public Difference PerformDiff(object newObj, object oldObj, string propName, Type type, Func<object, object, string, Type, Difference> diffChildCallback) { var newArray = newObj == null ? new List<object>() : (newObj as IEnumerable).Cast<object>().ToList(); var oldArray = oldObj == null ? new List<object>() : (oldObj as IEnumerable).Cast<object>().ToList(); var parentDifference = new Difference(propName, newObj, oldObj) { ChildDiffs = GroupEqualObjects(newArray, oldArray) .Select( change => diffChildCallback(change.Item1, change.Item2, "Item", GetEnumerableElementType(type))) .Where(d => d != null) .ToList() }; // assume arrays are the same if there are no child differences return parentDifference.ChildDiffs.Any() ? parentDifference : null; }
/// <summary> /// Compare two pointers /// </summary> public override void CompareType(CompareParms parms) { if ((parms.Object1 is IntPtr && parms.Object2 is IntPtr && ((IntPtr)parms.Object1) != ((IntPtr)parms.Object2)) || (parms.Object1 is UIntPtr && parms.Object2 is UIntPtr && ((UIntPtr)parms.Object1) != ((UIntPtr)parms.Object2))) { Difference difference = new Difference { ParentObject1 = new WeakReference(parms.ParentObject1), ParentObject2 = new WeakReference(parms.ParentObject2), PropertyName = parms.BreadCrumb, Object1 = new WeakReference(parms.Object1), Object2 = new WeakReference(parms.Object2) }; AddDifference(parms.Result, difference); } }
public Difference PerformDiff(object newObj, object oldObj, string propName, Type type, Func<object, object, string, Type, Difference> diffChildCallback) { var parentDifference = new Difference(propName, newObj, oldObj) { ChildDiffs = type.GetProperties(BindingFlags.Public | BindingFlags.Instance).Select( p => { var newValue = newObj == null ? null : p.GetValue(newObj, null); var oldValue = oldObj == null ? null : p.GetValue(oldObj, null); return diffChildCallback(newValue, oldValue, p.Name, p.PropertyType); }) .Where(d => d != null) .ToList() }; // assume objects are the same if there are no child differences return parentDifference.ChildDiffs.Any() ? parentDifference : null; }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { IGH_Goo goo = null; Image image = new Image(); if (!DA.GetData(0, ref goo)) { return; } if (!goo.TryGetImage(ref image)) { return; } int mode = 0; DA.GetData(1, ref mode); double numValA = 1.0; DA.GetData(2, ref numValA); int numValB = 1; DA.GetData(3, ref numValB); int numValC = 1; DA.GetData(4, ref numValC); int numValD = 1; DA.GetData(5, ref numValD); Filter filter = new Filter(); int[] indices = new int[] { 2, 3, 4, 5 }; switch ((FilterModes)mode) { case FilterModes.Canny: SetParameter(2, "X", "Sigma", "Gaussian sigma"); SetParameter(3, "S", "Size", "Gaussian size"); SetParameter(4, "L", "Low Threshold", "High threshold value used for hysteresis"); SetParameter(5, "H", "High Threshold", "Low threshold value used for hysteresis"); filter = new Canny(numValA, numValB, numValC, numValD); image.Filters.Add(new Canny()); break; case FilterModes.Difference: ClearParameter(indices); filter = new Difference(); image.Filters.Add(new Difference()); break; case FilterModes.Homogeneity: ClearParameter(indices); filter = new Homogeneity(); image.Filters.Add(new Homogeneity()); break; case FilterModes.Kirsch: ClearParameter(indices); filter = new Kirsch(); image.Filters.Add(new Kirsch()); break; case FilterModes.Robinson: ClearParameter(indices); filter = new Robinson(); image.Filters.Add(new Robinson()); break; case FilterModes.Sobel: ClearParameter(indices); filter = new Sobel(); image.Filters.Add(new Sobel()); break; } message = ((FilterModes)mode).ToString(); UpdateMessage(); DA.SetData(0, image); DA.SetData(1, filter); }
public string Format(Difference difference) { var customDifference = (CustomDifference)difference; return($"{difference.Breadcrumb} ==!{customDifference.Foo}!=="); }
protected SchemaDifference(Difference difference) => Difference = difference;
public FunctionSchemaDifference(Difference difference, IKustoSchema value) : base(difference) => Value = value;
public void ShowModifiedFiles(Workspace workspace, string path) { char[] charsToTrim = { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }; string itemPath = path.TrimEnd(charsToTrim); workspace.RefreshMappings(); string serverPath = workspace.GetServerItemForLocalItem(itemPath); // pull item list based on WorkspaceVersion. otherwise might get // new items on server that haven't been pulled yet in the list returned WorkspaceVersionSpec version = new WorkspaceVersionSpec(workspace); // get item list from TFS server ItemSpec itemSpec = new ItemSpec(itemPath, RecursionType.Full); ItemSet itemSet = VersionControlServer.GetItems(itemSpec, version, DeletedState.NonDeleted, ItemType.Any, true); Item[] items = itemSet.Items; foreach (Item item in items) { if (item.ItemType != ItemType.File) { continue; } if (item.ServerItem.Length == serverPath.Length) { continue; } string serverItem = item.ServerItem.Remove(0, serverPath.Length + 1); // server item paths are separated with '/', but on windows the file list below has '\' separated paths if (Path.DirectorySeparatorChar != '/') { serverItem = serverItem.Replace('/', Path.DirectorySeparatorChar); } // only looking for modifications, not deletes or adds string fname = Path.Combine(itemPath, serverItem); if (!File.Exists(fname)) { continue; } if (FileAttributes.ReadOnly == (File.GetAttributes(fname) & FileAttributes.ReadOnly)) { continue; } using (FileStream fileStream = new FileStream(fname, FileMode.Open, FileAccess.Read)) { string localHash = Convert.ToBase64String(md5.ComputeHash(fileStream)); string itemHash = Convert.ToBase64String(item.HashValue); if (itemHash == localHash) { continue; } } string p = fname.Substring(path.Length + 1); if (OptionBrief) { Driver.WriteLine(CanonicalPath(p)); continue; } string tnameA = Path.GetTempFileName(); item.DownloadFile(tnameA); IDiffItem a = new DiffItemLocalFile(tnameA, item.Encoding, DateTime.Now, false); IDiffItem b = new DiffItemLocalFile(fname, item.Encoding, DateTime.Now, false); Difference.DiffFiles(VersionControlServer, a, b, GetDiffOptions(), p, true); if (!String.IsNullOrEmpty(tnameA)) { File.Delete(tnameA); } } }
public void TwoSpecialFormatNumbers() { mulExp = new MultiplicationExp(new Number(14e21), new Number(3e-15)); dif = new Difference(4.2e7, mulExp.Evaluate()); Assert.IsTrue(dif.IsAlmostSame()); }
private void CompareOutOfOrder(CompareParms parms, bool reverseCompare) { IEnumerator enumerator1; List <string> matchingSpec = null; if (!reverseCompare) { enumerator1 = ((IEnumerable)parms.Object1).GetEnumerator(); } else { enumerator1 = ((IEnumerable)parms.Object2).GetEnumerator(); } while (enumerator1.MoveNext()) { if (enumerator1.Current == null) { continue; } if (matchingSpec == null) { matchingSpec = GetMatchingSpec(parms.Result, enumerator1.Current.GetType()); } string matchIndex1 = GetMatchIndex(parms.Result, matchingSpec, enumerator1.Current); if (_alreadyCompared.Contains(matchIndex1)) { continue; } string currentBreadCrumb = string.Format("{0}[{1}]", parms.BreadCrumb, matchIndex1); IEnumerator enumerator2; if (!reverseCompare) { enumerator2 = ((IEnumerable)parms.Object2).GetEnumerator(); } else { enumerator2 = ((IEnumerable)parms.Object1).GetEnumerator(); } bool found = false; while (enumerator2.MoveNext()) { if (enumerator2.Current == null) { continue; } string matchIndex2 = GetMatchIndex(parms.Result, matchingSpec, enumerator2.Current); if (matchIndex1 == matchIndex2) { CompareParms childParms = new CompareParms { Result = parms.Result, Config = parms.Config, ParentObject1 = parms.Object1, ParentObject2 = parms.Object2, Object1 = enumerator1.Current, Object2 = enumerator2.Current, BreadCrumb = currentBreadCrumb }; _rootComparer.Compare(childParms); _alreadyCompared.Add(matchIndex1); found = true; break; } } if (!found) { Difference difference = new Difference { ParentObject1 = new WeakReference(parms.ParentObject1), ParentObject2 = new WeakReference(parms.ParentObject2), PropertyName = currentBreadCrumb, Object1Value = reverseCompare ? "(null)" : NiceString(enumerator1.Current), Object2Value = reverseCompare ? NiceString(enumerator1.Current) : "(null)", ChildPropertyName = "Item", Object1 = reverseCompare ? null : new WeakReference(enumerator1), Object2 = reverseCompare ? new WeakReference(enumerator1) : null }; AddDifference(parms.Result, difference); } if (parms.Result.ExceededDifferences) { return; } } }
public override void CompareType(CompareParms parms) { string[] included = { "Name", "SocialSecurityNumber", "DateOfBirth" }; string[] excluded = { "FinalResult", "InitialResult", "FinalResultDate", "InitialResultDate" }; var db = (Employee)parms.Object1; var er = (Employee)parms.Object2; var properties = typeof(Employee).GetProperties().Where(prop => prop.CanRead && prop.CanWrite).ToArray(); for (int x = 0; x < properties.Count(); x++) { Type t2 = properties[x].GetValue(db, null).GetType(); Type s2 = properties[x].GetValue(er, null).GetType(); var childTargetProperties = t2.GetProperties().Where(p => p.CanRead && p.CanWrite).ToArray(); var childSourceProperties = s2.GetProperties().Where(p => p.CanRead && p.CanWrite).ToArray(); for (int y = 0; y < childTargetProperties.Count(); y++) { var dbValue = childSourceProperties[y].GetValue(properties[x].GetValue(db, null), null); var erValue = childTargetProperties[y].GetValue(properties[x].GetValue(er, null), null); if (included.Any(q => q == childSourceProperties[y].Name)) { string t; if (erValue != null) { t = erValue.GetType().ToString(); } else { t = null; } switch (t) { case "System.String": { string targetObj = dbValue as string; string sourceObj = erValue as string; targetObj = targetObj == null ? "" : targetObj; sourceObj = sourceObj == null ? "" : sourceObj; if ((targetObj.ToLower().Trim().Equals(sourceObj.ToLower().Trim())) && !string.IsNullOrWhiteSpace(sourceObj)) { Difference match = new Difference { PropertyName = childSourceProperties[y].Name, Object1Value = dbValue == null ? "" : dbValue.ToString(), Object2Value = erValue == null ? "" : erValue.ToString() }; parms.Result.Differences.Add(match); } } break; case "System.DateTime": { var targetObj = dbValue as DateTime?; var sourceObj = erValue as DateTime?; if (targetObj == sourceObj && (sourceObj != null || sourceObj != DateTime.MinValue)) { Difference match = new Difference { PropertyName = childSourceProperties[y].Name, Object1Value = dbValue == null ? "" : dbValue.ToString(), Object2Value = erValue == null ? "" : erValue.ToString() }; parms.Result.Differences.Add(match); } } break; case "System.Boolean": { var targetObj = dbValue as bool?; var sourceObj = erValue as bool?; if (targetObj == sourceObj) { Difference match = new Difference { PropertyName = childSourceProperties[y].Name, Object1Value = dbValue == null ? "" : dbValue.ToString(), Object2Value = erValue == null ? "" : erValue.ToString() }; parms.Result.Differences.Add(match); } } break; case "System.Int64": { var targetObj = dbValue as Int64?; var sourceObj = erValue as Int64?; if (targetObj == sourceObj && (sourceObj != 0)) { Difference match = new Difference { PropertyName = childSourceProperties[y].Name, Object1Value = dbValue == null ? "" : dbValue.ToString(), Object2Value = erValue == null ? "" : erValue.ToString() }; parms.Result.Differences.Add(match); } } break; case null: //nothing break; default: { Difference match = new Difference { PropertyName = childSourceProperties[y].Name, Object1Value = dbValue == null ? "" : dbValue.ToString(), Object2Value = erValue == null ? "" : erValue.ToString() }; parms.Result.Differences.Add(match); } break; } } else { if (!excluded.Any(z => z == childSourceProperties[y].Name)) { } } } } }
public void TestChangedMovedWithMeta() { MountPointWithPath rootMountPointWithPath = BuildRootMountPointWithPath(); Difference changed = Build.ChangedDifference("/foo/var.c"); Difference changedMeta = Build.ChangedDifference("/foo/var.c.meta"); Difference moved = Build.MovedDifference( "/foo/bar.c", "/foo/var.c"); Difference movedMeta = Build.MovedDifference( "/foo/bar.c.meta", "/foo/var.c.meta"); OutOfDateItemsByMount outOfDateItems = new OutOfDateItemsByMount() { Mount = rootMountPointWithPath }; outOfDateItems.Changed.Add(changed); outOfDateItems.Changed.Add(changedMeta); outOfDateItems.Moved.Add(moved); outOfDateItems.Moved.Add(movedMeta); CheckedStateManager checkedStateManager = new CheckedStateManager(); List <OutOfDateItemsByMount> outOfDateItemsByMount = new List <OutOfDateItemsByMount>(); List <GluonFileConflict> fileConflicts = new List <GluonFileConflict>(); outOfDateItemsByMount.Add(outOfDateItems); IncomingChangesTree innerTree = IncomingChangesTree.BuildIncomingChangeCategories( checkedStateManager, outOfDateItemsByMount, fileConflicts); UnityIncomingChangesTree tree = UnityIncomingChangesTree.BuildIncomingChangeCategories(innerTree); IncomingChangeInfo changeInfo = FindChangeInfo.FromDifference( changed, tree); IncomingChangeInfo movedChangeInfo = FindChangeInfo.FromDifference( moved, tree); Assert.IsNotNull( changeInfo, "ChangedInfo not found"); Assert.IsNotNull( movedChangeInfo, "MovedChangedInfo not found"); Assert.IsNotNull( tree.GetMetaChange(changeInfo), "Meta change for changed not should be null"); Assert.IsNotNull( tree.GetMetaChange(movedChangeInfo), "Meta change for moved should not be null"); }
public void TwoDifferentNumbers() { mulExp = new MultiplicationExp(new Number(13553.2992), new Number(-2884.2155431)); dif = new Difference(-39090636.21292479552, mulExp.Evaluate()); Assert.IsTrue(dif.IsAlmostSame()); }
public void TwoOppositeNumbers() { mulExp = new MultiplicationExp(new Number(125235.1265436), new Number(0.00000798498015372)); dif = new Difference(1.0, mulExp.Evaluate()); Assert.IsTrue(dif.IsAlmostSame()); }
public void TwoSameNumbers() { mulExp = new MultiplicationExp(new Number(124.126665435654356543), new Number(124.126665435654356543)); dif = new Difference(15407.4290721748699306017565, mulExp.Evaluate()); Assert.IsTrue(dif.IsAlmostSame()); }
public IAnnotatedFile Annotate(string path, VersionSpec version) { var options = new DiffOptions { Flags = DiffOptionFlags.EnablePreambleHandling | DiffOptionFlags.IgnoreLeadingAndTrailingWhiteSpace | DiffOptionFlags.IgnoreEndOfLineDifference }; PendingChange[] pendingChanges = server.GetWorkspace(path).GetPendingChanges(path); if (pendingChanges.Length >= 2) { throw new InvalidOperationException("Expected at most 1 pending change, but got " + pendingChanges.Length); } Changeset currentChangeset = null; AnnotatedFile annotatedFile; string currentPath; int currentEncoding; if (pendingChanges.Length == 1 && (pendingChanges[0].ChangeType & ChangeType.Edit) != 0) { annotatedFile = new AnnotatedFile(path, pendingChanges[0].Encoding); if (annotatedFile.IsBinary()) { return(annotatedFile); } currentPath = path; currentEncoding = pendingChanges[0].Encoding; } else { annotatedFile = null; currentPath = null; currentEncoding = 0; } using (var historyProvider = new HistoryProvider(server, path, version)) { bool done = false; while (!done && historyProvider.Next()) { Changeset previousChangeset = historyProvider.Changeset(); string previousPath = historyProvider.Filename(); int previousEncoding = previousChangeset.Changes[0].Item.Encoding; if (annotatedFile == null) { annotatedFile = new AnnotatedFile(previousPath, previousEncoding); if (annotatedFile.IsBinary()) { return(annotatedFile); } } else if (previousEncoding == -1) { annotatedFile.Apply(currentChangeset); done = true; } else { var diff = Diff(Difference.DiffFiles(currentPath, currentEncoding, previousPath, previousEncoding, options)); done = annotatedFile.ApplyDiff(currentChangeset, diff); } currentChangeset = previousChangeset; currentEncoding = previousEncoding; currentPath = previousPath; } if (annotatedFile != null) { annotatedFile.Apply(currentChangeset); } } return(annotatedFile); }
private bool ColumnsDifferent(CompareParms parms) { DataTable dataTable1 = parms.Object1 as DataTable; DataTable dataTable2 = parms.Object2 as DataTable; if (dataTable1 == null) { throw new ArgumentException("parms.Object1"); } if (dataTable2 == null) { throw new ArgumentException("parms.Object2"); } if (dataTable1.Columns.Count != dataTable2.Columns.Count) { Difference difference = new Difference { ParentObject1 = parms.ParentObject1, ParentObject2 = parms.ParentObject2, PropertyName = parms.BreadCrumb, Object1Value = dataTable1.Columns.Count.ToString(CultureInfo.InvariantCulture), Object2Value = dataTable2.Columns.Count.ToString(CultureInfo.InvariantCulture), ChildPropertyName = "Columns.Count", Object1 = parms.Object1, Object2 = parms.Object2 }; AddDifference(parms.Result, difference); if (parms.Result.ExceededDifferences) { return(true); } } foreach (var i in Enumerable.Range(0, dataTable1.Columns.Count)) { string currentBreadCrumb = AddBreadCrumb(parms.Config, parms.BreadCrumb, "Columns", string.Empty, i); CompareParms childParms = new CompareParms { Result = parms.Result, Config = parms.Config, ParentObject1 = parms.Object1, ParentObject2 = parms.Object2, Object1 = dataTable1.Columns[i], Object2 = dataTable2.Columns[i], BreadCrumb = currentBreadCrumb }; RootComparer.Compare(childParms); if (parms.Result.ExceededDifferences) { return(true); } } return(false); }
public void DifferenceTestsForBox() { SolidMaterial redMaterial = new SolidMaterial(RGBA_Floats.Red, 0, 0, 0); SolidMaterial blueMaterial = new SolidMaterial(RGBA_Floats.Blue, 0, 0, 0); Ray castRay = new Ray(new Vector3(0, -1, 0), Vector3.UnitY); BoxShape box1X1 = new BoxShape(new Vector3(-.5, -.5, -.5), new Vector3(.5, .5, .5), blueMaterial); // just a box all by itself { IntersectInfo testInfo = box1X1.GetClosestIntersection(castRay); Assert.IsTrue(testInfo.hitType == IntersectionType.FrontFace, "Found Hit : Box No CSG"); Assert.IsTrue(testInfo.closestHitObject == box1X1, "Found Hit : Box No CSG"); Assert.IsTrue(testInfo.hitPosition == new Vector3(0, -.5, 0), "Hit position y = -.5 : Box No CSG"); Assert.IsTrue(testInfo.distanceToHit == .5, "Hit length = .5 : Box No CSG"); Assert.IsTrue(testInfo.normalAtHit == -Vector3.UnitY, "Normal Correct : Box No CSG"); } // one subtract from the front of a box, the front faces are aligned { BoxShape subtractBox = new BoxShape(new Vector3(-.5, -.5, -.5), new Vector3(.5, 0, .5), redMaterial); Difference merge = new Difference(box1X1, subtractBox); IntersectInfo testInfo = merge.GetClosestIntersection(castRay); Assert.IsTrue(testInfo.hitType == IntersectionType.FrontFace, "Found Hit : One Subtract"); Assert.IsTrue(testInfo.closestHitObject == subtractBox, "Found Hit : One Subtract"); Assert.IsTrue(testInfo.hitPosition == new Vector3(0, 0, 0), "Hit position y = 0 : One Subtract"); Assert.IsTrue(testInfo.distanceToHit == 1, "Hit length = 1 : One Subtract"); Assert.IsTrue(testInfo.normalAtHit == -Vector3.UnitY, "Normal Correct : One Subtract"); } #if false // An internal primary object that needs to be skipped over { List <IPrimitive> primaryShapes = new List <IPrimitive>(); BoxShape insideBox = new BoxShape(new Vector3(-.1, -.1, -.1), new Vector3(.1, .1, .1), blueMaterial); primaryShapes.Add(box1X1); primaryShapes.Add(insideBox); IPrimitive primamryGroup = BoundingVolumeHierarchy.CreateNewHierachy(primaryShapes); List <IPrimitive> subtractShapes = new List <IPrimitive>(); subtractShapes.Add(new BoxShape(new Vector3(-.5, -.5, -.5), new Vector3(.5, .4, .5), redMaterial)); IPrimitive subtractGroup = BoundingVolumeHierarchy.CreateNewHierachy(subtractShapes); Difference merge = new Difference(primamryGroup, subtractGroup); IntersectInfo testInfo = merge.GetClosestIntersection(castRay); Assert.IsTrue(testInfo.isHit == true, "Found Hit : 5 Subtracts"); //Assert.IsTrue(testInfo.closestHitObject == subtractBox, "Found Hit : 5 Subtracts"); Assert.IsTrue(testInfo.hitPosition == new Vector3(0, 0, 0), "Hit position y = 0 : 5 Subtracts"); Assert.IsTrue(testInfo.distanceToHit == 1, "Hit length = 1 : 5 Subtracts"); Assert.IsTrue(testInfo.normalAtHit == -Vector3.UnitY, "Normal Correct : 5 Subtracts"); } // Go through 5 subtract boxes to get to 1/2 way through the main box. { List <IPrimitive> subtractShapes = new List <IPrimitive>(); for (int i = 0; i < 5; i++) { subtractShapes.Add(new BoxShape(new Vector3(-.5, -.5 + i * .1, -.5), new Vector3(.5, -.4 + i * .1, .5), redMaterial)); } IPrimitive subtractGroup = BoundingVolumeHierarchy.CreateNewHierachy(subtractShapes); Difference merge = new Difference(box1X1, subtractGroup); IntersectInfo testInfo = merge.GetClosestIntersection(castRay); Assert.IsTrue(testInfo.isHit == true, "Found Hit : 5 Subtracts"); //Assert.IsTrue(testInfo.closestHitObject == subtractBox, "Found Hit : 5 Subtracts"); Assert.IsTrue(testInfo.hitPosition == new Vector3(0, 0, 0), "Hit position y = 0 : 5 Subtracts"); Assert.IsTrue(testInfo.distanceToHit == 1, "Hit length = 1 : 5 Subtracts"); Assert.IsTrue(testInfo.normalAtHit == -Vector3.UnitY, "Normal Correct : 5 Subtracts"); } #endif }
private void ParseImage(int imageId) { DateTime startTime = DateTime.Now; labelDetection.Text = ""; string difImagePath = ""; if (imageId >= 0) { difImagePath = DifBoardImages[imageId]; } Bitmap orig; Bitmap dif; try { orig = (Bitmap)Bitmap.FromFile(OriginalBoardImage); if (imageId >= 0) { dif = (Bitmap)Bitmap.FromFile(difImagePath); } else { dif = (Bitmap)pictureBoxGenerated.Image; } } catch { // kill any exception due to missing files return; } pictureBoxOrig.Image = dif; Difference filter = new Difference(orig); dif = filter.Apply(dif); BlobCounter blobCounter = new BlobCounter(); blobCounter.ProcessImage(dif); Blob[] blobs = blobCounter.GetObjectsInformation(); // create Graphics object to draw on the image and a pen Graphics g = Graphics.FromImage(dif); Pen redPen = new Pen(Color.Red, 3); Pen bluePen = new Pen(Color.Blue, 1); SimpleShapeChecker shapeChecker = new SimpleShapeChecker(); // check each object and draw circle around objects, which // are recognized as circles for (int i = 0, n = blobs.Length; i < n; i++) { List <IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]); labelDetection.Text = string.Format("{0} points", edgePoints.Count); if (edgePoints.Count <= 1) { continue; } List <IntPoint> points = new List <IntPoint>(); if (shapeChecker.IsQuadrilateral(edgePoints)) { labelDetection.Text += ", quadrilateral"; } else if (shapeChecker.IsConvexPolygon(edgePoints, out points)) { labelDetection.Text += ", convex poligon"; } else if (shapeChecker.IsTriangle(edgePoints, out points)) { labelDetection.Text += ", triangle"; } Pen usePen = shapeChecker.IsQuadrilateral(edgePoints) ? redPen : bluePen; int centerX = edgePoints[0].X; int centerY = edgePoints[0].Y; int minX = centerX; int minY = centerY; int maxX = centerX; int maxY = centerY; for (int j = 0; j < edgePoints.Count - 1; j++) { centerX += edgePoints[j + 1].X; centerY += edgePoints[j + 1].Y; if (edgePoints[j + 1].X < minX) { minX = edgePoints[j + 1].X; } if (edgePoints[j + 1].Y < minY) { minY = edgePoints[j + 1].Y; } if (edgePoints[j + 1].X > maxX) { maxX = edgePoints[j + 1].X; } if (edgePoints[j + 1].Y > maxX) { maxX = edgePoints[j + 1].Y; } g.DrawLine(usePen, edgePoints[j].X, edgePoints[j].Y, edgePoints[j + 1].X, edgePoints[j + 1].Y); } g.DrawLine(usePen , edgePoints[0].X, edgePoints[0].Y , edgePoints[edgePoints.Count - 1].X, edgePoints[edgePoints.Count - 1].Y); labelDetectedPosition.Text = string.Format("{0}, {1}" , new object[] { (centerX / edgePoints.Count), (centerY / edgePoints.Count) //, maxX - minX, maxY - minY }); labelDetectionOffset.Text = string.Format("{0}, {1}" , Grigore.Position.X - (centerX / edgePoints.Count) , Grigore.Position.Y - (centerY / edgePoints.Count) ); } redPen.Dispose(); bluePen.Dispose(); g.Dispose(); pictureBoxRoboBoard.Image = dif; labelDetection.Text = string.Format("{1}, {0} sec", (DateTime.Now - startTime), labelDetection.Text); }
public override void CompareType(CompareParms parms) { if (TypeHelper.IsIList(parms.Object1?.GetType()) || TypeHelper.IsIList(parms.Object2?.GetType()) || CustomListComparer.IsIReadOnlyList(parms.Object1?.GetType()) || CustomListComparer.IsIReadOnlyList(parms.Object2?.GetType())) { listComparer.CompareType(parms); } if (typeof(ExpandoObject).IsAssignableFrom(parms.Object1?.GetType()) || typeof(ExpandoObject).IsAssignableFrom(parms.Object2?.GetType())) { customExpandoObjectComparer.CompareType(parms); } if (typeof(string).Equals(parms.Object1?.GetType()) || typeof(string).Equals(parms.Object2?.GetType())) { } if (parms.Object1 != null && parms.Object1.GetType().IsClass || parms.Object1 != null && parms.Object1.GetType().IsStruct() || parms.Object2 != null && parms.Object2.GetType().IsClass || parms.Object2 != null && parms.Object2.GetType().IsStruct()) { var properties = parms.Object1 == null?parms.Object2.GetType().GetProperties() : parms.Object1.GetType().GetProperties(); foreach (var property in properties) { if (ignoreProperties.Contains(property.Name)) { continue; } CompareParms childParms = new CompareParms { Result = parms.Result, Config = parms.Config, ParentObject1 = parms.Object1, ParentObject2 = parms.Object2, Object1 = parms.Object1 != null?property.GetValue(parms.Object1) : null, Object2 = parms.Object2 != null?property.GetValue(parms.Object2) : null, BreadCrumb = AddBreadCrumb(parms.Config, parms.BreadCrumb, property.Name) }; RootComparer.Compare(childParms); } } //var propertiesInfo = parms.Object1 == null ? parms.Object2.GetType().GetProperties() : parms.Object1.GetType().GetProperties(); if (parms.Object1 != null && parms.Object1.GetType().IsPrimitive || parms.Object2 != null && parms.Object2.GetType().IsPrimitive) { Difference difference = new Difference { ParentObject1 = parms.Object1, ParentObject2 = parms.Object2, PropertyName = parms.BreadCrumb, Object1Value = NiceString(parms.Object1), Object2Value = NiceString(parms.Object2), Object1 = parms.Object1, Object2 = parms.Object2 }; AddDifference(parms.Result, difference); } //foreach (var propertyInfo in propertiesInfo) //{ // Difference difference = new Difference // { // ParentObject1 = parms.Object1, // ParentObject2 = parms.Object2, // PropertyName = propertyInfo.Name, // Object1Value = NiceString(parms.Object1 == null ? null : propertyInfo.GetValue(parms.Object1)), // Object2Value = NiceString(parms.Object2 == null ? null : propertyInfo.GetValue(parms.Object2)), // Object1 = parms.Object1 == null ? null : propertyInfo.GetValue(parms.Object1), // Object2 = parms.Object2 == null ? null : propertyInfo.GetValue(parms.Object2) // }; //} }
// Start is called before the first frame update void Start() { Diff = FindObjectOfType <Difference>(); }
private static string GetAssert(this Difference difference, string fieldName) { try { if (difference.Object1 != null && !difference.Object1.GetType().Supported()) { return(null); } if (difference.Object2 != null && !difference.Object2.GetType().Supported()) { return(null); } if (difference.ParentObject2 != null) { var propertyInfo = difference.ParentObject2.GetType().GetProperty(difference.PropertyName); propertyInfo?.GetValue(difference.ParentObject2); } } catch (Exception) { return(null); } if (difference.ParentObject2 != null && difference.ParentObject2.GetType().Name.StartsWith("Tuple`")) { var output = new StringBuilder("Tuple.Create("); var fields = difference.ParentObject2.GetType().GetFields(BindingFlags); for (var index = 0; index < fields.Length; index++) { var field = fields[index]; output.Append(GetTupleValue(field.FieldType.Name, field.GetValue(difference.ParentObject2))); if (index < fields.Length - 1) { output.Append(", "); } } output = output.Append(")"); return($"() => {fieldName}.ShouldBe({output}),-Tuple"); } if (difference.ParentObject2 != null) { var propertyInfo = difference.ParentObject2.GetType().GetProperty(difference.PropertyName); if (propertyInfo != null && propertyInfo.PropertyType.IsNullable()) { _nullableType = true; } else { _nullableType = false; } } var type = difference.Object2TypeName != Null ? difference.Object2TypeName : difference.Object1TypeName; var propertyName = string.IsNullOrWhiteSpace(difference.PropertyName) ? string.Empty : $"{difference.PropertyName}."; var childProperty = difference.ChildPropertyName; if (childProperty == "GetType()") { difference.ChildPropertyName = null; } if (!string.IsNullOrWhiteSpace(difference.ChildPropertyName)) { propertyName = string.IsNullOrWhiteSpace(propertyName) ? $"{difference.ChildPropertyName}." : $"{propertyName}{difference.ChildPropertyName}."; } propertyName = propertyName.Replace(TypeMethod, string.Empty); fieldName = fieldName.Replace(TypeMethod, string.Empty); var unBoxType = type.UnBoxType(); if ((difference.Object2 == null || string.IsNullOrWhiteSpace(difference.Object2Value)) && unBoxType == StringType) { var nested = string.IsNullOrWhiteSpace(difference.PropertyName) ? string.Empty : $"{difference.PropertyName}."; return($"() => {fieldName}.{nested}ShouldBeNullOrWhiteSpace(),-{unBoxType}"); } if (difference.Object2 == null) { var nested = string.IsNullOrWhiteSpace(difference.PropertyName) ? string.Empty : $"{difference.PropertyName}."; return($"() => {fieldName}.{nested}ShouldBeNull(),-{unBoxType}"); } if (childProperty == "GetType()") { unBoxType = difference.Object2.GetType().Name.UnBoxType(); difference.Object2Value = difference.Object2.ToString(); } if (unBoxType != StringType && unBoxType != UnsignedInt && unBoxType != ShortType && unBoxType != UnsignedShort && unBoxType != ByteType && unBoxType != ShortByte && unBoxType != UnsignedLong && unBoxType != CharType) { unBoxType = difference.Object2Value.IsNumeric() ? difference.Object2Value.IsInteger() ? IntegerType : DoubleType : unBoxType; } var enumType = CheckEnum(difference, fieldName, propertyName); if (!string.IsNullOrWhiteSpace(enumType)) { return(enumType); } if (difference.Object2.GetType().IsACollection()) { var collectionProperty = propertyName .Replace(".Count", string.Empty) .Replace(".Length", string.Empty) .Replace(TypeMethod, string.Empty); _objTypeCollection = false; var generateAssertsForCollection = GenerateAssertsForCollection(difference.Object2, $"{fieldName}.{collectionProperty}".Trim('.')); var builder = new StringBuilder(); for (var index = 0; index < generateAssertsForCollection.Count; index++) { var assert = generateAssertsForCollection[index]; if (index != generateAssertsForCollection.Count - 1) { builder.AppendLine(assert); } else { builder.Append(assert); } } return(builder.ToString()); } var nullableType = _nullableType ? "GetValueOrDefault()." : string.Empty; switch (unBoxType) { case IntegerType: case DoubleType: case DecimalType: case FloatType: case Long: return($"() => {fieldName}.{propertyName}{nullableType}ShouldBe({difference.Object2Value}),-{unBoxType}"); case UnsignedInt: case ShortType: case UnsignedShort: case ByteType: case ShortByte: case UnsignedLong: return($"() => {fieldName}.{propertyName}{nullableType}ShouldBe(({unBoxType}){difference.Object2Value}),-{unBoxType}"); case BoolType: return(difference.Object2Value.Equals("false", StringComparison.InvariantCultureIgnoreCase) ? $"() => {fieldName}.{propertyName}{nullableType}ShouldBeFalse(),-{unBoxType}" : $"() => {fieldName}.{propertyName}{nullableType}ShouldBeTrue(),-{unBoxType}"); case CharType: return($"() => {fieldName}.{propertyName}{nullableType}ShouldBe('{difference.Object2Value}'),-{unBoxType}"); case StringType: var replace = difference.Object2Value.FormatMultiLines(); return($"() => {fieldName}.{propertyName}ShouldBe(\"{replace}\"),-{unBoxType}"); case GuidType: return(difference.Object2Value.Equals(EmptyGuid) ? $"() => {fieldName}.{propertyName}{nullableType}ShouldBe(Guid.Empty),-{unBoxType}" : $"() => {fieldName}.{propertyName}{nullableType}ShouldBe(new Guid(\"{difference.Object2Value}\")),-{unBoxType}"); case "DateTime": var dateTime = (DateTime)difference.Object2; return($"() => {fieldName}.{propertyName}{nullableType}ToString(CultureInfo.InvariantCulture).ShouldBe(\"{dateTime.ToString(CultureInfo.InvariantCulture)}\"),-{unBoxType}"); default: if (difference.Object2 != null && difference.Object2.GetType().FullName == "System.Drawing.Color") { var colorName = difference.Object2.GetType().GetProperty("Name").GetValue(difference.Object2); return ($"() => {fieldName}.{propertyName.Replace(TypeMethod, string.Empty)}Name.ShouldBe(\"{colorName}\"),-{unBoxType}"); } if (!string.IsNullOrWhiteSpace(unBoxType)) { var unknownBuilder = new StringBuilder() .AppendLine($"() => {fieldName}.{propertyName.Replace(TypeMethod, string.Empty)}ShouldNotBeNull(),-{unBoxType}") .Append($"() => {fieldName}.{propertyName.Replace(TypeMethod, string.Empty)}ShouldBeOfType<{unBoxType}>(),-{unBoxType}"); return(unknownBuilder.ToString()); } return(null); } }
/// <summary> /// Cun along the diagonal of a give edge to the opposite edge. The edge is chosen by saying /// which 2 faces are to be kept solid, and or-ing them together. /// </summary> /// <param name="facesThatShareEdge">The two faces to maintain after the cut, or-ed together with '|'.</param> public void CutAlongDiagonal(Face facesToKeepWhole) { switch (facesToKeepWhole) { case (Face.Left | Face.Back): { Vector3 size = root.Size; CsgObject boxToCutOut = new Box(Math.Sqrt(2), 1, 1.1, createCentered: false); boxToCutOut = new Rotate(boxToCutOut, new Vector3(0, 0, MathHelper.Tau / 8)); boxToCutOut = new Translate(boxToCutOut, x: Math.Sqrt(2) / 2, y: -Math.Sqrt(2) / 2, z: -.05); boxToCutOut = new Scale(boxToCutOut, size, name: "boxToCutOut"); root = new Difference(root, boxToCutOut); } break; case (Face.Left | Face.Front): { Vector3 size = root.Size; CsgObject boxToCutOut = new Box(Math.Sqrt(2), 1, 1.1, createCentered: false); boxToCutOut = new Rotate(boxToCutOut, new Vector3(0, 0, -MathHelper.Tau / 8)); boxToCutOut = new Translate(boxToCutOut, y: 1, z: -.05); boxToCutOut = new Scale(boxToCutOut, size, name: "boxToCutOutLeftFront"); root = new Difference(root, boxToCutOut); } break; case (Face.Left | Face.Bottom): { Vector3 size = root.Size; CsgObject boxToCutOut = new Box(Math.Sqrt(2), 1.1, 1, createCentered: false); boxToCutOut = new Rotate(boxToCutOut, new Vector3(0, MathHelper.Tau / 8, 0)); boxToCutOut = new Translate(boxToCutOut, y: -.05, z: 1); boxToCutOut = new Scale(boxToCutOut, size, name: "boxToCutOut"); root = new Difference(root, boxToCutOut); } break; case (Face.Right | Face.Front): { Vector3 size = root.Size; CsgObject boxToCutOut = new Box(Math.Sqrt(2), 1, 1.1, createCentered: false, name: "boxtToCutOut"); boxToCutOut = new Rotate(boxToCutOut, new Vector3(0, 0, MathHelper.Tau / 8)); boxToCutOut = new Translate(boxToCutOut, z: -.05); boxToCutOut = new Scale(boxToCutOut, size, name: "boxToCutOutRightFront"); root = new Difference(root, boxToCutOut); } break; case (Face.Right | Face.Bottom): { Vector3 size = root.Size; CsgObject boxToCutOut = new Box(Math.Sqrt(2), 1.1, 1, createCentered: false, name: "boxToCutOut"); boxToCutOut = new Rotate(boxToCutOut, new Vector3(0, -MathHelper.Tau / 8, 0)); boxToCutOut = new Translate(boxToCutOut, 0, -.05, 0); //boxToCutOut = new Translate(boxToCutOut, Math.Sqrt(2) / 2, 0, -Math.Sqrt(2) / 2); boxToCutOut = new Scale(boxToCutOut, size, name: "boxToCutOut"); root = new Difference(root, boxToCutOut); } break; case (Face.Right | Face.Top): { Vector3 size = root.Size; CsgObject boxToCutOut = new Box(Math.Sqrt(2), 1.1, 1, createCentered: false, name: "boxToCutOut"); boxToCutOut = new Rotate(boxToCutOut, new Vector3(0, MathHelper.Tau / 8, 0)); boxToCutOut = new Translate(boxToCutOut, -Math.Sqrt(2) / 2, 0, 1 - Math.Sqrt(2) / 2); boxToCutOut = new Scale(boxToCutOut, size, name: "botToCutOut"); root = new Difference(root, boxToCutOut); } break; case (Face.Front | Face.Top): { Vector3 size = root.Size; CsgObject boxToCutOut = new Box(1.1, Math.Sqrt(2), 1, createCentered: false, name: "boxToCutOut"); boxToCutOut = new Rotate(boxToCutOut, new Vector3(MathHelper.Tau / 8, 0, 0)); boxToCutOut = new Translate(boxToCutOut, -.05, Math.Sqrt(2) / 2, -Math.Sqrt(2) / 2); boxToCutOut = new Scale(boxToCutOut, size); root = new Difference(root, boxToCutOut); } break; case (Face.Front | Face.Bottom): { Vector3 size = root.Size; CsgObject boxToCutOut = new Box(1.1, Math.Sqrt(2), 1, createCentered: false, name: "boxToCutOut"); boxToCutOut = new Rotate(boxToCutOut, new Vector3(-MathHelper.Tau / 8, 0, 0)); boxToCutOut = new Translate(boxToCutOut, -.05, 0, 1); boxToCutOut = new Scale(boxToCutOut, size, name: "boxtToCutOutFrontBottom"); root = new Difference(root, boxToCutOut); } break; case (Face.Bottom | Face.Back): { Vector3 size = root.Size; CsgObject boxToCutOut = new Box(1.1, Math.Sqrt(2), 1, createCentered: false); boxToCutOut = new Rotate(boxToCutOut, new Vector3(MathHelper.Tau / 8, 0, 0)); boxToCutOut = new Translate(boxToCutOut, x: -.05); boxToCutOut = new Scale(boxToCutOut, size, name: "boxToCutOut"); root = new Difference(root, boxToCutOut); } break; case (Face.Back | Face.Top): { Vector3 size = root.Size; CsgObject boxToCutOut = new Box(1.1, Math.Sqrt(2), 1, createCentered: false, name: "boxToCutOut"); boxToCutOut = new Rotate(boxToCutOut, new Vector3(-MathHelper.Tau / 8, 0, 0)); boxToCutOut = new Translate(boxToCutOut, x: -.05, y: -Math.Sqrt(2) / 2, z: .28); // TODO: do the right math. .28 is hacky boxToCutOut = new Scale(boxToCutOut, size, name: "boxToCutOut"); root = new Difference(root, boxToCutOut); } break; default: throw new NotImplementedException("Just write it for this case."); } }
public async Task ShouldUpdateTheDifferenceData(string left, string right) { // Arrange var leftInput = Convert.FromBase64String(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("LF data"))); var rightInput = Convert.FromBase64String(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("RT data"))); Guid id = Guid.NewGuid(); using (var scope = this.testHostCollectionFixture.Host.Services.CreateScope()) { var context = scope.ServiceProvider.GetRequiredService <DifferenceContext>(); Difference diff = new Difference { Id = id, Left = leftInput, Right = rightInput }; context.Differences.Add(diff); context.SaveChanges(); } // Act var newLeftInput = left == null ? null : Convert.FromBase64String( Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(left))); var newRightInput = right == null ? null : Convert.FromBase64String( Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(right))); var diffToUpdate = new DifferenceForUpdateDto { Left = newLeftInput, Right = newRightInput }; var requestContent = new ObjectContent <DifferenceForUpdateDto>(diffToUpdate, new JsonMediaTypeFormatter()); var response = await this.testHostCollectionFixture.Client.PutAsync($"{BaseUrl}/{id}", requestContent); // Assert Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); Difference updatedDiff; using (var scope = this.testHostCollectionFixture.Host.Services.CreateScope()) { var context = scope.ServiceProvider.GetRequiredService <DifferenceContext>(); updatedDiff = context.Differences.Find(id); } var updatedLeftDiffData = Convert.ToBase64String(updatedDiff.Left); var updatedRightDiffData = Convert.ToBase64String(updatedDiff.Right); Assert.NotNull(updatedDiff); Assert.NotEqual(Convert.ToBase64String(leftInput), updatedLeftDiffData); Assert.Equal( newLeftInput != null ? Convert.ToBase64String(newLeftInput) : string.Empty, updatedLeftDiffData); Assert.NotEqual(Convert.ToBase64String(rightInput), updatedRightDiffData); Assert.Equal( newRightInput != null ? Convert.ToBase64String(newRightInput) : string.Empty, updatedRightDiffData); }
public void InputZero() { tanExp = new TangentExp(new Number(Constants.Zero)); dif = new Difference(Constants.Zero, tanExp.Evaluate()); Assert.IsTrue(dif.IsAlmostSame()); }
public void InputThreePiDivFour() { tanExp = new TangentExp(new Number(Constants.ThreePiDivFour)); dif = new Difference(-Constants.One, tanExp.Evaluate()); Assert.IsTrue(dif.IsAlmostSame()); }
public void InputEightPiDivSix() { tanExp = new TangentExp(new Number(Constants.EightPiDivSix)); dif = new Difference(Constants.SqrtThree, tanExp.Evaluate()); Assert.IsTrue(dif.IsAlmostSame()); }
public ConflictInfo(Difference mineToBase, Difference serverToBase) { this.MineToBase = mineToBase; this.ServerToBase = serverToBase; }