Пример #1
0
        public void Test001_DoubleEndedUniqueCollectionBehavesLikeLinkedList()
        {
            var lklist = new LinkedList <int>();

            lklist.AddLast(456);
            lklist.AddLast(123);
            lklist.AddLast(789);
            lklist.AddLast(567);
            lklist.Remove(123);

            var delist = new DoubleEndedUniqueCollection <int>();

            delist.Add(456);
            delist.Add(123);
            delist.Add(789);
            delist.Add(567);
            delist.Remove(123);

            var expectedArray = new int[] { 456, 789, 567 };
            var lklistArray   = lklist.ToArray();
            var delistArray   = delist.ToArray();

            Assert.AreEqual(expectedArray, lklistArray);
            Assert.AreEqual(expectedArray, delistArray);
        }
Пример #2
0
        public void Test001_DoubleEndedUniqueCollectionDoesntAcceptKeyDuplicates()
        {
            Assert.Throws <ArgumentException>(() =>
            {
                var delist = new DoubleEndedUniqueCollection <int>();
                delist.Add(123);
                Console.WriteLine("Added " + 123);
                delist.Add(789);
                Console.WriteLine("Added " + 789);
                delist.Add(456);
                Console.WriteLine("Added " + 456);

                var error = null as Exception;
                try
                {
                    Console.WriteLine("Trying to add " + 789 + " again");
                    delist.Add(789);
                    Console.WriteLine("Added " + 789);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Couldn't add " + 789 + " again... removing it...");
                    delist.Remove(789);
                    error = ex;
                }
                Assert.AreEqual(delist.Contains(789), false);

                Console.WriteLine("Re-adding " + 789);
                delist.Add(789);
                Console.WriteLine("Added " + 789);
                Assert.AreEqual(delist.Contains(789), true);

                if (error != null)
                {
                    Console.WriteLine("Re-throwing the exception we caught...");
                    throw error;
                }
            });
        }
        public void Test001_DoubleEndedUniqueCollectionBehavesLikeLinkedList()
        {
            var lklist = new LinkedList<int>();
            lklist.AddLast(456);
            lklist.AddLast(123);
            lklist.AddLast(789);
            lklist.AddLast(567);
            lklist.Remove(123);

            var delist = new DoubleEndedUniqueCollection<int>();
            delist.Add(456);
            delist.Add(123);
            delist.Add(789);
            delist.Add(567);
            delist.Remove(123);

            var expectedArray = new int[] { 456, 789, 567 };
            var lklistArray = lklist.ToArray();
            var delistArray = delist.ToArray();

            Assert.AreEqual(expectedArray, lklistArray);
            Assert.AreEqual(expectedArray, delistArray);
        }
        public void Test001_DoubleEndedUniqueCollectionDoesntAcceptKeyDuplicates()
        {
            var delist = new DoubleEndedUniqueCollection<int>();
            delist.Add(123);
            Console.WriteLine("Added " + 123);
            delist.Add(789);
            Console.WriteLine("Added " + 789);
            delist.Add(456);
            Console.WriteLine("Added " + 456);

            var error = null as Exception;
            try
            {
                Console.WriteLine("Trying to add " + 789 + " again");
                delist.Add(789);
                Console.WriteLine("Added " + 789);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Couldn't add " + 789 + " again... removing it...");
                delist.Remove(789);
                error = ex;
            }
            Assert.AreEqual(delist.Contains(789), false);

            Console.WriteLine("Re-adding " + 789);
            delist.Add(789);
            Console.WriteLine("Added " + 789);
            Assert.AreEqual(delist.Contains(789), true);

            if (error != null)
            {
                Console.WriteLine("Re-throwing the exception we caught...");
                throw error;
            }
        }