public void IdentityPathTest() { SimpleIdentity id = new SimpleIdentity(); IdentityPath pathSimple = new IdentityPath(id); Assert.AreEqual(IdentityPath.ROOT, pathSimple.Parent); Assert.AreEqual(IdentityPath.ROOT, pathSimple.GetPathTo(-1)); Assert.AreEqual(id, pathSimple.Child); Assert.AreEqual(1, pathSimple.Length); Assert.AreEqual(0, pathSimple.Depth); AssertEx.ThrowsException <IndexOutOfRangeException>(() => pathSimple.GetPathTo(-2)); AssertEx.ThrowsException <IndexOutOfRangeException>(() => pathSimple.GetPathTo(1)); IdentityPath pathRoot = new IdentityPath(new Identity[0]); Assert.AreEqual(IdentityPath.ROOT, pathRoot); Assert.AreEqual(0, pathRoot.Length); Assert.AreEqual(-1, pathRoot.Depth); AssertEx.ThrowsException <IndexOutOfRangeException>(() => pathRoot.Child); AssertEx.ThrowsException <IndexOutOfRangeException>(() => pathRoot.Parent); const int count = 5; List <Identity> listId1 = new List <Identity>(); List <Identity> listId2 = new List <Identity>(); HashSet <IdentityPath> setPaths = new HashSet <IdentityPath>(); IdentityPath last = IdentityPath.ROOT; for (int i = 0; i < count; i++) { listId1.Add(new NumericIdentity(i)); listId2.Add(new NumericIdentity(i)); IdentityPath path = new IdentityPath(listId1); Assert.AreEqual(path, new IdentityPath(listId1)); Assert.AreNotEqual(path, new IdentityPath(listId2)); Assert.AreEqual(last, path.Parent); Assert.AreSame(listId1[i], path.Child); Assert.AreEqual(path, new IdentityPath(path.Parent, path.Child)); Assert.AreEqual(i, path.Depth); Assert.AreEqual(listId1.Count, path.Length); Assert.AreSame(path.Child, path.GetIdentity(path.Depth)); Assert.AreEqual(path.Parent, path.GetPathTo(path.Depth - 1)); Assert.AreEqual("/" + listId1.ToString("/"), path.ToString()); for (int j = 0; j < i; j++) { Assert.IsTrue(setPaths.Contains(path.GetPathTo(j))); } setPaths.Add(path); last = path; } }
public void IdentityPathTest() { SimpleIdentity id = new SimpleIdentity(); IdentityPath pathSimple = new IdentityPath(id); Assert.AreEqual(IdentityPath.ROOT, pathSimple.Parent); Assert.AreEqual(IdentityPath.ROOT, pathSimple.GetPathTo(-1)); Assert.AreEqual(id, pathSimple.Child); Assert.AreEqual(1, pathSimple.Length); Assert.AreEqual(0, pathSimple.Depth); AssertEx.ThrowsException<IndexOutOfRangeException>(() => pathSimple.GetPathTo(-2)); AssertEx.ThrowsException<IndexOutOfRangeException>(() => pathSimple.GetPathTo(1)); IdentityPath pathRoot = new IdentityPath(new Identity[0]); Assert.AreEqual(IdentityPath.ROOT, pathRoot); Assert.AreEqual(0, pathRoot.Length); Assert.AreEqual(-1, pathRoot.Depth); AssertEx.ThrowsException<IndexOutOfRangeException>(() => pathRoot.Child); AssertEx.ThrowsException<IndexOutOfRangeException>(() => pathRoot.Parent); const int count = 5; List<Identity> listId1 = new List<Identity>(); List<Identity> listId2 = new List<Identity>(); HashSet<IdentityPath> setPaths = new HashSet<IdentityPath>(); IdentityPath last = IdentityPath.ROOT; for (int i = 0; i < count; i++) { listId1.Add(new NumericIdentity(i)); listId2.Add(new NumericIdentity(i)); IdentityPath path = new IdentityPath(listId1); Assert.AreEqual(path, new IdentityPath(listId1)); Assert.AreNotEqual(path, new IdentityPath(listId2)); Assert.AreEqual(last, path.Parent); Assert.AreSame(listId1[i], path.Child); Assert.AreEqual(path, new IdentityPath(path.Parent, path.Child)); Assert.AreEqual(i, path.Depth); Assert.AreEqual(listId1.Count, path.Length); Assert.AreSame(path.Child, path.GetIdentity(path.Depth)); Assert.AreEqual(path.Parent, path.GetPathTo(path.Depth - 1)); Assert.AreEqual("/" + listId1.ToString("/"), path.ToString()); for (int j = 0; j < i; j++) Assert.IsTrue(setPaths.Contains(path.GetPathTo(j))); setPaths.Add(path); last = path; } }
public bool IsPathSelected(IdentityPath selectedPath, IdentityPath identityPath) { return(selectedPath != null && identityPath != null && selectedPath.Depth <= (int)SrmDocument.Level.Molecules && identityPath.Depth <= (int)SrmDocument.Level.Molecules && (selectedPath.Depth >= identityPath.Depth && Equals(selectedPath.GetPathTo(identityPath.Depth), identityPath) || selectedPath.Depth <= identityPath.Depth && Equals(identityPath.GetPathTo(selectedPath.Depth), selectedPath))); }
private bool IsPathSelected(IdentityPath selectedPath, IdentityPath identityPath) { if (selectedPath == null || identityPath == null || selectedPath.Depth < identityPath.Depth) { return(false); } return(Equals(selectedPath.GetPathTo(identityPath.Depth), identityPath)); }
private bool IsPathSelected(IdentityPath selectedPath, IdentityPath identityPath) { if (selectedPath.Depth < identityPath.Depth) { return false; } return Equals(selectedPath.GetPathTo(identityPath.Depth), identityPath); }