public void TestReversedUniqueIdSet()
        {
            UniqueId[] uids =
            {
                new UniqueId(20), new UniqueId(19), new UniqueId(15),
                new UniqueId(12), new UniqueId(11), new UniqueId(10),
                new UniqueId(9),  new UniqueId(6),  new UniqueId(5),
                new UniqueId(3),  new UniqueId(2),  new UniqueId(1)
            };
            var list   = new UniqueIdSet(uids);
            var actual = list.ToString();

            Assert.AreEqual("20:19,15,12:9,6:5,3:1", actual, "Unexpected result for unsorted set.");

            list   = new UniqueIdSet(uids, SortOrder.Ascending);
            actual = list.ToString();

            Assert.AreEqual("1:3,5:6,9:12,15,19:20", actual, "Unexpected result for ascending set.");
            Assert.AreEqual(0, list.IndexOf(new UniqueId(1)), "Unexpected index for descending set.");

            list   = new UniqueIdSet(uids, SortOrder.Descending);
            actual = list.ToString();

            Assert.AreEqual("20:19,15,12:9,6:5,3:1", actual, "Unexpected result for descending set.");
            Assert.AreEqual(11, list.IndexOf(new UniqueId(1)), "Unexpected index for descending set.");
        }
        public void TestAscendingUniqueIdSet()
        {
            UniqueId[] uids =
            {
                new UniqueId(1), new UniqueId(2), new UniqueId(3),
                new UniqueId(4), new UniqueId(5), new UniqueId(6),
                new UniqueId(7), new UniqueId(8), new UniqueId(9)
            };
            var list   = new UniqueIdSet(uids, SortOrder.Ascending);
            var actual = list.ToString();

            Assert.AreEqual("1:9", actual, "Incorrect initial value.");
            Assert.AreEqual(9, list.Count, "Incorrect initial count.");
            Assert.AreEqual(-1, list.IndexOf(new UniqueId(500)));
            Assert.IsFalse(list.Contains(new UniqueId(500)));
            Assert.IsFalse(list.Remove(new UniqueId(500)));

            // Test Remove()

            list.Remove(uids[0]);
            actual = list.ToString();

            Assert.AreEqual("2:9", actual, "Incorrect results after Remove() #1.");
            Assert.AreEqual(8, list.Count, "Incorrect count after Remove() #1.");

            list.Remove(uids[uids.Length - 1]);
            actual = list.ToString();

            Assert.AreEqual("2:8", actual, "Incorrect results after Remove() #2.");
            Assert.AreEqual(7, list.Count, "Incorrect count after Remove() #2.");

            list.Remove(uids[4]);
            actual = list.ToString();

            Assert.AreEqual("2:4,6:8", actual, "Incorrect results after Remove() #3.");
            Assert.AreEqual(6, list.Count, "Incorrect count after Remove() #3.");

            // Test Add()

            list.Add(new UniqueId(5));
            actual = list.ToString();

            Assert.AreEqual("2:8", actual, "Incorrect results after Add() #1.");
            Assert.AreEqual(7, list.Count, "Incorrect count after Add() #1.");

            list.Add(new UniqueId(1));
            actual = list.ToString();

            Assert.AreEqual("1:8", actual, "Incorrect results after Add() #2.");
            Assert.AreEqual(8, list.Count, "Incorrect count after Add() #2.");

            list.Add(new UniqueId(9));
            actual = list.ToString();

            Assert.AreEqual("1:9", actual, "Incorrect results after Add() #3.");
            Assert.AreEqual(9, list.Count, "Incorrect count after Add() #3.");

            // Test RemoveAt()

            list.RemoveAt(0);
            actual = list.ToString();

            Assert.AreEqual("2:9", actual, "Incorrect results after RemoveAt() #1.");
            Assert.AreEqual(8, list.Count, "Incorrect count after RemoveAt() #1.");

            list.RemoveAt(7);
            actual = list.ToString();

            Assert.AreEqual("2:8", actual, "Incorrect results after RemoveAt() #2.");
            Assert.AreEqual(7, list.Count, "Incorrect count after RemoveAt() #2.");

            list.RemoveAt(3);
            actual = list.ToString();

            Assert.AreEqual("2:4,6:8", actual, "Incorrect results after RemoveAt() #3.");
            Assert.AreEqual(6, list.Count, "Incorrect count after RemoveAt() #3.");

            // Test adding a range of items

            list.AddRange(uids);
            actual = list.ToString();

            Assert.AreEqual("1:9", actual, "Incorrect results after AddRange().");
            Assert.AreEqual(9, list.Count, "Incorrect count after AddRange().");

            // Test clearing the list
            list.Clear();
            Assert.AreEqual(0, list.Count, "Incorrect count after Clear().");
        }
Beispiel #3
0
		public void TestAscendingUniqueIdSet ()
		{
			UniqueId[] uids = {
				new UniqueId (1), new UniqueId (2), new UniqueId (3),
				new UniqueId (4), new UniqueId (5), new UniqueId (6),
				new UniqueId (7), new UniqueId (8), new UniqueId (9)
			};
			var list = new UniqueIdSet (uids, SortOrder.Ascending);
			var actual = list.ToString ();

			Assert.AreEqual ("1:9", actual, "Incorrect initial value.");
			Assert.AreEqual (9, list.Count, "Incorrect initial count.");
			Assert.AreEqual (-1, list.IndexOf (new UniqueId (500)));
			Assert.IsFalse (list.Contains (new UniqueId (500)));
			Assert.IsFalse (list.Remove (new UniqueId (500)));

			// Test Remove()

			list.Remove (uids[0]);
			actual = list.ToString ();

			Assert.AreEqual ("2:9", actual, "Incorrect results after Remove() #1.");
			Assert.AreEqual (8, list.Count, "Incorrect count after Remove() #1.");

			list.Remove (uids[uids.Length - 1]);
			actual = list.ToString ();

			Assert.AreEqual ("2:8", actual, "Incorrect results after Remove() #2.");
			Assert.AreEqual (7, list.Count, "Incorrect count after Remove() #2.");

			list.Remove (uids[4]);
			actual = list.ToString ();

			Assert.AreEqual ("2:4,6:8", actual, "Incorrect results after Remove() #3.");
			Assert.AreEqual (6, list.Count, "Incorrect count after Remove() #3.");

			// Test Add()

			list.Add (new UniqueId (5));
			actual = list.ToString ();

			Assert.AreEqual ("2:8", actual, "Incorrect results after Add() #1.");
			Assert.AreEqual (7, list.Count, "Incorrect count after Add() #1.");

			list.Add (new UniqueId (1));
			actual = list.ToString ();

			Assert.AreEqual ("1:8", actual, "Incorrect results after Add() #2.");
			Assert.AreEqual (8, list.Count, "Incorrect count after Add() #2.");

			list.Add (new UniqueId (9));
			actual = list.ToString ();

			Assert.AreEqual ("1:9", actual, "Incorrect results after Add() #3.");
			Assert.AreEqual (9, list.Count, "Incorrect count after Add() #3.");

			// Test RemoveAt()

			list.RemoveAt (0);
			actual = list.ToString ();

			Assert.AreEqual ("2:9", actual, "Incorrect results after RemoveAt() #1.");
			Assert.AreEqual (8, list.Count, "Incorrect count after RemoveAt() #1.");

			list.RemoveAt (7);
			actual = list.ToString ();

			Assert.AreEqual ("2:8", actual, "Incorrect results after RemoveAt() #2.");
			Assert.AreEqual (7, list.Count, "Incorrect count after RemoveAt() #2.");

			list.RemoveAt (3);
			actual = list.ToString ();

			Assert.AreEqual ("2:4,6:8", actual, "Incorrect results after RemoveAt() #3.");
			Assert.AreEqual (6, list.Count, "Incorrect count after RemoveAt() #3.");

			// Test adding a range of items

			list.AddRange (uids);
			actual = list.ToString ();

			Assert.AreEqual ("1:9", actual, "Incorrect results after AddRange().");
			Assert.AreEqual (9, list.Count, "Incorrect count after AddRange().");

			// Test clearing the list
			list.Clear ();
			Assert.AreEqual (0, list.Count, "Incorrect count after Clear().");
		}
Beispiel #4
0
		public void TestReversedUniqueIdSet ()
		{
			UniqueId[] uids = {
				new UniqueId (20), new UniqueId (19), new UniqueId (15),
				new UniqueId (12), new UniqueId (11), new UniqueId (10),
				new UniqueId (9), new UniqueId (6), new UniqueId (5),
				new UniqueId (3), new UniqueId (2), new UniqueId (1)
			};
			var list = new UniqueIdSet (uids);
			var actual = list.ToString ();

			Assert.AreEqual ("20:19,15,12:9,6:5,3:1", actual, "Unexpected result for unsorted set.");

			list = new UniqueIdSet (uids, SortOrder.Ascending);
			actual = list.ToString ();

			Assert.AreEqual ("1:3,5:6,9:12,15,19:20", actual, "Unexpected result for ascending set.");
			Assert.AreEqual (0, list.IndexOf (new UniqueId (1)), "Unexpected index for descending set.");

			list = new UniqueIdSet (uids, SortOrder.Descending);
			actual = list.ToString ();

			Assert.AreEqual ("20:19,15,12:9,6:5,3:1", actual, "Unexpected result for descending set.");
			Assert.AreEqual (11, list.IndexOf (new UniqueId (1)), "Unexpected index for descending set.");
		}