public void TestCompareTo() { VisitableList <int>[] lists = new VisitableList <int> [3]; for (int i = 0; i < 3; i++) { lists[i] = new VisitableList <int>(); for (int j = 0; j < i; j++) { lists[i].Add(j * 4); } } Assert.AreEqual(lists[0].CompareTo(lists[1]), -1); Assert.AreEqual(lists[2].CompareTo(lists[1]), 1); VisitableList <int> sameList = lists[1]; Assert.AreEqual(lists[1].CompareTo(sameList), 0); object obj = new object(); Assert.AreEqual(lists[0].CompareTo(obj), -1); VisitableHashtable <int, int> h = new VisitableHashtable <int, int>(); Assert.AreEqual(lists[0].CompareTo(h), 1); }
private VisitableHashtable <string, string> GetTestHashtable() { VisitableHashtable <string, string> h = new VisitableHashtable <string, string>(); h.Add("a", "aa"); h.Add("b", "bb"); h.Add("c", "cc"); return(h); }
public void TestIsFull() { VisitableHashtable <string, string> h = GetTestHashtable(); Assert.AreEqual(h.IsFull, false); h = new VisitableHashtable <string, string>(); Assert.AreEqual(h.IsFull, false); h.Add("ff", "fff"); Assert.AreEqual(h.IsFull, false); }
public void TestCompareTo() { VisitableHashtable <string, string> h1 = GetTestHashtable(); VisitableHashtable <string, string> h2 = GetTestHashtable(); h2.Add("d", "dd"); Assert.AreEqual(h1.CompareTo(h2), -1); Assert.AreEqual(h2.CompareTo(h1), 1); Assert.AreEqual(h1.CompareTo(h1), 0); object o = new object(); Assert.AreEqual(h1.CompareTo(o), -1); }
public void TestSuccesfulInit() { // Default constructor VisitableHashtable <string, string> h1 = new VisitableHashtable <string, string>(); Assert.AreEqual(h1.Count, 0); Assert.AreEqual(h1.IsEmpty, true); Assert.AreEqual(h1.IsFull, false); VisitableHashtable <string, string> h2 = new VisitableHashtable <string, string>(); h2.Add("aa", "bb"); h2.Add("cc", "dd"); Assert.AreEqual(h2.Count, 2); Assert.AreEqual(h2.IsEmpty, false); Assert.AreEqual(h2.IsFull, false); h1 = new VisitableHashtable <string, string>(h2); Assert.AreEqual(h1.Count, 2); Assert.AreEqual(h1.IsEmpty, false); Assert.AreEqual(h1.IsFull, false); h1 = new VisitableHashtable <string, string>(new DummyComparer()); Assert.AreEqual(h1.Count, 0); Assert.AreEqual(h1.IsEmpty, true); Assert.AreEqual(h1.IsFull, false); h1 = new VisitableHashtable <string, string>(50); Assert.AreEqual(h1.Count, 0); Assert.AreEqual(h1.IsEmpty, true); Assert.AreEqual(h1.IsFull, false); h1 = new VisitableHashtable <string, string>(h2, new DummyComparer()); Assert.AreEqual(h1.Count, 2); Assert.AreEqual(h1.IsEmpty, false); Assert.AreEqual(h1.IsFull, false); h1 = new VisitableHashtable <string, string>(300, new DummyComparer()); Assert.AreEqual(h1.Count, 0); Assert.AreEqual(h1.IsEmpty, true); Assert.AreEqual(h1.IsFull, false); }
public void TestVisitor() { TrackingVisitor <KeyValuePair <string, string> > visitor = new TrackingVisitor <KeyValuePair <string, string> >(); VisitableHashtable <string, string> h = GetTestHashtable(); h.Accept(visitor); Assert.AreEqual(visitor.TrackingList.Count, 3); bool found = false; for (int i = 0; i < visitor.TrackingList.Count; i++) { if ((visitor.TrackingList[i].Key == "a") && (visitor.TrackingList[i].Value == "aa")) { found = true; break; } } Assert.AreEqual(found, true); found = false; for (int i = 0; i < visitor.TrackingList.Count; i++) { if ((visitor.TrackingList[i].Key == "b") && (visitor.TrackingList[i].Value == "bb")) { found = true; break; } } Assert.AreEqual(found, true); found = false; for (int i = 0; i < visitor.TrackingList.Count; i++) { if ((visitor.TrackingList[i].Key == "c") && (visitor.TrackingList[i].Value == "cc")) { found = true; break; } } Assert.AreEqual(found, true); }
public void TestStoppingVisitor() { EqualityFindingVisitor <KeyValuePair <string, string> > visitor = new EqualityFindingVisitor <KeyValuePair <string, string> >(new KeyValuePair <string, string>("b", "bb"), new KeyValuePairEqualityComparer <string, string>()); VisitableHashtable <string, string> h = GetTestHashtable(); h.Accept(visitor); Assert.AreEqual(visitor.HasCompleted, true); Assert.AreEqual(visitor.Found, true); visitor = new EqualityFindingVisitor <KeyValuePair <string, string> > ( new KeyValuePair <string, string>("d", "dd"), new KeyValuePairEqualityComparer <string, string>() ); h.Accept(visitor); Assert.AreEqual(visitor.HasCompleted, false); Assert.AreEqual(visitor.Found, false); }
public void TestInvalidCompareTo() { VisitableHashtable <string, int> h = new VisitableHashtable <string, int>(); h.CompareTo(null); }
public void TestNullVisitor() { VisitableHashtable <string, string> h = new VisitableHashtable <string, string>(); h.Accept(null); }