public void TestEquals() { ShortList list = new ShortList(); //Assert.AreEqual(list, list); Assert.IsTrue(list.Equals(list)); Assert.IsTrue(!list.Equals(null)); ShortList list2 = new ShortList(200); //Assert.AreEqual(list, list2); Assert.IsTrue(list.Equals(list2)); //Assert.AreEqual(list2, list); Assert.IsTrue(list2.Equals(list)); Assert.AreEqual(list.GetHashCode(), list2.GetHashCode()); list.Add((short)0); list.Add((short)1); list2.Add((short)1); list2.Add((short)0); Assert.IsTrue(!list.Equals(list2)); list2.RemoveValue((short)1); list2.Add((short)1); //Assert.AreEqual(list, list2); Assert.IsTrue(list.Equals(list2)); //Assert.AreEqual(list2, list); Assert.IsTrue(list2.Equals(list)); list2.Add((short)2); Assert.IsTrue(!list.Equals(list2)); Assert.IsTrue(!list2.Equals(list)); }
public void TestRetainAll() { ShortList list = new ShortList(); for (short j = 0; j < 1000; j++) { list.Add(j); } ShortList listCopy = new ShortList(list); ShortList listOdd = new ShortList(); ShortList listEven = new ShortList(); for (short j = 0; j < 1000; j++) { if (j % 2 == 0) { listEven.Add(j); } else { listOdd.Add(j); } } list.RetainAll(listOdd); Assert.IsTrue(list.Equals(listOdd));// Assert.AreEqual(list, listOdd); list.RetainAll(listEven); Assert.IsTrue(list.IsEmpty()); listCopy.RetainAll(listEven); //Assert.AreEqual(listCopy, listEven); Assert.IsTrue(listCopy.Equals(listEven)); listCopy.RetainAll(listOdd); Assert.IsTrue(listCopy.IsEmpty()); }
public void TestConstructors() { ShortList list = new ShortList(); Assert.IsTrue(list.IsEmpty()); list.Add((short)0); list.Add((short)1); ShortList list2 = new ShortList(list); //Assert.AreEqual(list, list2); Assert.IsTrue(list.Equals(list2)); ShortList list3 = new ShortList(2); Assert.IsTrue(list3.IsEmpty()); }
public void TestAddAll() { ShortList list = new ShortList(); for (short j = 0; j < 5; j++) { list.Add(j); } ShortList list2 = new ShortList(0); list2.AddAll(list); list2.AddAll(list); Assert.AreEqual(2 * list.Count, list2.Count); for (short j = 0; j < 5; j++) { Assert.AreEqual(list2.Get(j), j); Assert.AreEqual(list2.Get(j + list.Count), j); } ShortList empty = new ShortList(); int limit = list.Count; for (int j = 0; j < limit; j++) { Assert.IsTrue(list.AddAll(j, empty)); Assert.AreEqual(limit, list.Count); } try { list.AddAll(limit + 1, empty); Assert.Fail("should have thrown an exception"); } catch (IndexOutOfRangeException) { // as expected } // try add at beginning empty.AddAll(0, list); //Assert.AreEqual(empty, list); Assert.IsTrue(empty.Equals(list)); // try in the middle empty.AddAll(1, list); Assert.AreEqual(2 * list.Count, empty.Count); Assert.AreEqual(list.Get(0), empty.Get(0)); Assert.AreEqual(list.Get(0), empty.Get(1)); Assert.AreEqual(list.Get(1), empty.Get(2)); Assert.AreEqual(list.Get(1), empty.Get(6)); Assert.AreEqual(list.Get(2), empty.Get(3)); Assert.AreEqual(list.Get(2), empty.Get(7)); Assert.AreEqual(list.Get(3), empty.Get(4)); Assert.AreEqual(list.Get(3), empty.Get(8)); Assert.AreEqual(list.Get(4), empty.Get(5)); Assert.AreEqual(list.Get(4), empty.Get(9)); // try at the end empty.AddAll(empty.Count, list); Assert.AreEqual(3 * list.Count, empty.Count); Assert.AreEqual(list.Get(0), empty.Get(0)); Assert.AreEqual(list.Get(0), empty.Get(1)); Assert.AreEqual(list.Get(0), empty.Get(10)); Assert.AreEqual(list.Get(1), empty.Get(2)); Assert.AreEqual(list.Get(1), empty.Get(6)); Assert.AreEqual(list.Get(1), empty.Get(11)); Assert.AreEqual(list.Get(2), empty.Get(3)); Assert.AreEqual(list.Get(2), empty.Get(7)); Assert.AreEqual(list.Get(2), empty.Get(12)); Assert.AreEqual(list.Get(3), empty.Get(4)); Assert.AreEqual(list.Get(3), empty.Get(8)); Assert.AreEqual(list.Get(3), empty.Get(13)); Assert.AreEqual(list.Get(4), empty.Get(5)); Assert.AreEqual(list.Get(4), empty.Get(9)); Assert.AreEqual(list.Get(4), empty.Get(14)); }