Ejemplo n.º 1
0
        public void TestArgumentExceptions()
        {
            var      uids = new UniqueIdSet(SortOrder.Ascending);
            UniqueId uid;

            Assert.IsFalse(uids.IsReadOnly);

            uids.Add(UniqueId.MinValue);

            Assert.Throws <ArgumentOutOfRangeException> (() => new UniqueIdSet((SortOrder)500));
            Assert.Throws <ArgumentException> (() => uids.Add(UniqueId.Invalid));
            Assert.Throws <ArgumentNullException> (() => uids.AddRange(null));
            Assert.Throws <ArgumentNullException> (() => uids.CopyTo(null, 0));
            Assert.Throws <ArgumentOutOfRangeException> (() => uids.CopyTo(new UniqueId[1], -1));
            Assert.Throws <ArgumentOutOfRangeException> (() => uids.RemoveAt(-1));
            Assert.Throws <ArgumentOutOfRangeException> (() => uid = uids[-1]);
            Assert.Throws <NotSupportedException> (() => uids[0]   = UniqueId.MinValue);
            Assert.Throws <NotSupportedException> (() => uids.Insert(0, UniqueId.MinValue));

            var list = new List <UniqueId> {
                UniqueId.Invalid
            };

            Assert.Throws <ArgumentNullException> (() => UniqueIdSet.ToString(null));
            Assert.Throws <ArgumentException> (() => UniqueIdSet.ToString(list));

            Assert.Throws <ArgumentNullException> (() => UniqueIdSet.TryParse(null, out uids));
        }
Ejemplo n.º 2
0
		public void TestArgumentExceptions ()
		{
			var uids = new UniqueIdSet (SortOrder.Ascending);
			UniqueId uid;

			uids.Add (UniqueId.MinValue);

			Assert.Throws<ArgumentException> (() => uids.Add (UniqueId.Invalid));
			Assert.Throws<ArgumentNullException> (() => uids.AddRange (null));
			Assert.Throws<ArgumentNullException> (() => uids.CopyTo (null, 0));
			Assert.Throws<ArgumentOutOfRangeException> (() => uids.CopyTo (new UniqueId[1], -1));
			Assert.Throws<ArgumentOutOfRangeException> (() => uids.RemoveAt (-1));
			Assert.Throws<ArgumentOutOfRangeException> (() => uid = uids[-1]);
			Assert.Throws<NotSupportedException> (() => uids[0] = UniqueId.MinValue);
			Assert.Throws<NotSupportedException> (() => uids.Insert (0, UniqueId.MinValue));

			var list = new List<UniqueId> { UniqueId.Invalid };
			Assert.Throws<ArgumentNullException> (() => UniqueIdSet.ToString (null));
			Assert.Throws<ArgumentException> (() => UniqueIdSet.ToString (list));

			Assert.Throws<ArgumentNullException> (() => UniqueIdSet.TryParse (null, out uids));
		}
Ejemplo n.º 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().");
        }
Ejemplo n.º 4
0
        public void TestUnsortedUniqueIdSet()
        {
            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);
            var actual = list.ToString();

            Assert.AreEqual("1:9", actual, "Incorrect initial value.");
            Assert.AreEqual(9, list.Count, "Incorrect initial count.");

            // 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:4,6:8,5", 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("2:4,6:8,5,1", 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("2:4,6:8,5,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("3:4,6:8,5,1,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("3:4,6:8,5,1", actual, "Incorrect results after RemoveAt() #2.");
            Assert.AreEqual(7, list.Count, "Incorrect count after RemoveAt() #2.");

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

            Assert.AreEqual("3:4,6,8,5,1", 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("3:4,6,8,5,1:2,7,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().");
        }
Ejemplo n.º 5
0
		public void TestSortedUniqueIdSet ()
		{
			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, true);
			var actual = list.ToString ();

			Assert.AreEqual ("1:9", actual, "Incorrect initial value.");
			Assert.AreEqual (9, list.Count, "Incorrect initial count.");

			// 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().");
		}