Example #1
0
        public static void Test()
        {
            var  list = new ElemList();
            Elem el1  = new Elem()
            {
                ID = 1, Value = "1"
            };

            list.Add(el1);
            Elem el2 = new Elem()
            {
                ID = 2, Value = "2"
            };

            list.Add(el2);
            Elem el3 = new Elem()
            {
                ID = 3, Value = "3"
            };

            list.Add(el3);
            Elem el4 = new Elem()
            {
                ID = 4, Value = "4"
            };

            list.Add(el4);
            NUnit.Framework.Assert.AreEqual(4, list.Count);
            //list.Add(el1);
            //NUnit.Framework.Assert.AreEqual(4, list.Count);

            Elem el5 = new Elem()
            {
                ID = 5, Value = "5"
            };

            //    NUnit.Framework.Assert.IsTrue(list.GetByID(1) == el1);
            //    NUnit.Framework.Assert.IsTrue(list.GetByID(2) == el2);
            //    NUnit.Framework.Assert.IsTrue(list.GetByID(3) == el3);
            //    NUnit.Framework.Assert.IsTrue(list.GetByID(4) == el4);
            //    NUnit.Framework.Assert.IsTrue(list.GetByID(5) == null);

            //    NUnit.Framework.Assert.IsTrue(list[1] == el1);
            //    NUnit.Framework.Assert.IsTrue(list[2] == el2);
            //    NUnit.Framework.Assert.IsTrue(list[3] == el3);
            //    NUnit.Framework.Assert.IsTrue(list[4] == el4);
            //    NUnit.Framework.Assert.IsTrue(list[5] == null);

            //    NUnit.Framework.Assert.IsTrue(list.GetByIndex(0) == el1);
            //    NUnit.Framework.Assert.IsTrue(list.GetByIndex(1) == el2);
            //    NUnit.Framework.Assert.IsTrue(list.GetByIndex(2) == el3);
            //    NUnit.Framework.Assert.IsTrue(list.GetByIndex(3) == el4);
            //    NUnit.Framework.Assert.IsTrue(list.GetByIndex(4) == null);

            //    NUnit.Framework.Assert.IsTrue(list.ContainsID(1));
            //    NUnit.Framework.Assert.IsTrue(list.ContainsID(2));
            //    NUnit.Framework.Assert.IsTrue(list.ContainsID(3));
            //    NUnit.Framework.Assert.IsTrue(list.ContainsID(4));
            //    NUnit.Framework.Assert.IsFalse(list.ContainsID(5));

            //    NUnit.Framework.Assert.IsTrue(list.Contains(el1));
            //    NUnit.Framework.Assert.IsTrue(list.Contains(el2));
            //    NUnit.Framework.Assert.IsTrue(list.Contains(el3));
            //    NUnit.Framework.Assert.IsTrue(list.Contains(el4));
            //    NUnit.Framework.Assert.IsFalse(list.Contains(el5));

            //    NUnit.Framework.Assert.IsTrue(list.Remove(el2));
            //    NUnit.Framework.Assert.AreEqual(3, list.Count);
            //    NUnit.Framework.Assert.IsFalse(list.ContainsID(2));
            //    NUnit.Framework.Assert.IsFalse(list.Contains(el2));

            //    NUnit.Framework.Assert.IsFalse(list.Remove(el2));
            //    NUnit.Framework.Assert.IsFalse(list.Remove(null));

            //    list.Add(el2.ID, el2);

            //    NUnit.Framework.Assert.IsTrue(list.GetByID(1) == el1);
            //    NUnit.Framework.Assert.IsTrue(list.GetByID(2) == el2);
            //    NUnit.Framework.Assert.IsTrue(list.GetByID(3) == el3);
            //    NUnit.Framework.Assert.IsTrue(list.GetByID(4) == el4);
            //    NUnit.Framework.Assert.IsTrue(list.GetByID(5) == null);

            //    NUnit.Framework.Assert.IsTrue(list[1] == el1);
            //    NUnit.Framework.Assert.IsTrue(list[2] == el2);
            //    NUnit.Framework.Assert.IsTrue(list[3] == el3);
            //    NUnit.Framework.Assert.IsTrue(list[4] == el4);
            //    NUnit.Framework.Assert.IsTrue(list[5] == null);

            //    NUnit.Framework.Assert.IsTrue(list.GetByIndex(0) == el1);
            //    NUnit.Framework.Assert.IsTrue(list.GetByIndex(3) == el2);
            //    NUnit.Framework.Assert.IsTrue(list.GetByIndex(1) == el3);
            //    NUnit.Framework.Assert.IsTrue(list.GetByIndex(2) == el4);
            //    NUnit.Framework.Assert.IsTrue(list.GetByIndex(4) == null);

            list.Sort(delegate(Elem a, Elem b) { return(0 - a.Value.CompareTo(b.Value)); });

            NUnit.Framework.Assert.IsTrue(list[3] == el1);
            NUnit.Framework.Assert.IsTrue(list[2] == el2);
            NUnit.Framework.Assert.IsTrue(list[1] == el3);
            NUnit.Framework.Assert.IsTrue(list[0] == el4);
        }
Example #2
0
        public static void Test()
        {
            var list = new ElemList();

            NUnit.Framework.Assert.AreEqual(0, list.Count);

            Elem el1 = new Elem()
            {
                ID = 1, Value = "1", Value2 = 11
            };

            list.Add(el1);
            NUnit.Framework.Assert.AreEqual(1, list.Count);
            Elem el2 = new Elem()
            {
                ID = 2, Value = "2", Value2 = 22
            };

            list.Add(el2);
            Elem el3 = new Elem()
            {
                ID = 3, Value = "3", Value2 = 33
            };

            list.Add(el3);
            Elem el4 = new Elem()
            {
                ID = 4, Value = "4", Value2 = 44
            };

            list.Add(el4);
            NUnit.Framework.Assert.AreEqual(4, list.Count);
            list.Add(el1);
            NUnit.Framework.Assert.AreEqual(4, list.Count);

            Elem el5 = new Elem()
            {
                ID = 5, Value = "5", Value2 = 55
            };

            NUnit.Framework.Assert.IsTrue(list.GetByID(1) == el1);
            NUnit.Framework.Assert.IsTrue(list.GetByID(2) == el2);
            NUnit.Framework.Assert.IsTrue(list.GetByID(3) == el3);
            NUnit.Framework.Assert.IsTrue(list.GetByID(4) == el4);
            NUnit.Framework.Assert.IsTrue(list.GetByID(5) == null);

            NUnit.Framework.Assert.IsTrue(list[1] == el1);
            NUnit.Framework.Assert.IsTrue(list[2] == el2);
            NUnit.Framework.Assert.IsTrue(list[3] == el3);
            NUnit.Framework.Assert.IsTrue(list[4] == el4);
            NUnit.Framework.Assert.IsTrue(list[5] == null);

            NUnit.Framework.Assert.IsTrue(list.GetByIndex(0) == el1);
            NUnit.Framework.Assert.IsTrue(list.GetByIndex(1) == el2);
            NUnit.Framework.Assert.IsTrue(list.GetByIndex(2) == el3);
            NUnit.Framework.Assert.IsTrue(list.GetByIndex(3) == el4);
            NUnit.Framework.Assert.IsTrue(list.GetByIndex(4) == null);

            NUnit.Framework.Assert.IsTrue(list.ContainsID(1));
            NUnit.Framework.Assert.IsTrue(list.ContainsID(2));
            NUnit.Framework.Assert.IsTrue(list.ContainsID(3));
            NUnit.Framework.Assert.IsTrue(list.ContainsID(4));
            NUnit.Framework.Assert.IsFalse(list.ContainsID(5));

            NUnit.Framework.Assert.IsTrue(list.Contains(el1));
            NUnit.Framework.Assert.IsTrue(list.Contains(el2));
            NUnit.Framework.Assert.IsTrue(list.Contains(el3));
            NUnit.Framework.Assert.IsTrue(list.Contains(el4));
            NUnit.Framework.Assert.IsFalse(list.Contains(el5));

            NUnit.Framework.Assert.IsTrue(list.Remove(el2));
            NUnit.Framework.Assert.AreEqual(3, list.Count);
            NUnit.Framework.Assert.IsFalse(list.ContainsID(2));
            NUnit.Framework.Assert.IsFalse(list.Contains(el2));

            NUnit.Framework.Assert.IsFalse(list.Remove(el2));
            NUnit.Framework.Assert.IsFalse(list.Remove(null));

            list.Add(el2);

            NUnit.Framework.Assert.IsTrue(list.GetByID(1) == el1);
            NUnit.Framework.Assert.IsTrue(list.GetByID(2) == el2);
            NUnit.Framework.Assert.IsTrue(list.GetByID(3) == el3);
            NUnit.Framework.Assert.IsTrue(list.GetByID(4) == el4);
            NUnit.Framework.Assert.IsTrue(list.GetByID(5) == null);

            NUnit.Framework.Assert.IsTrue(list[1] == el1);
            NUnit.Framework.Assert.IsTrue(list[2] == el2);
            NUnit.Framework.Assert.IsTrue(list[3] == el3);
            NUnit.Framework.Assert.IsTrue(list[4] == el4);
            NUnit.Framework.Assert.IsTrue(list[5] == null);

            NUnit.Framework.Assert.IsTrue(list.GetByIndex(0) == el1);
            NUnit.Framework.Assert.IsTrue(list.GetByIndex(3) == el2);
            NUnit.Framework.Assert.IsTrue(list.GetByIndex(1) == el3);
            NUnit.Framework.Assert.IsTrue(list.GetByIndex(2) == el4);
            NUnit.Framework.Assert.IsTrue(list.GetByIndex(4) == null);

            list.Sort(delegate(Elem a, Elem b) { return(a.Value.CompareTo(b.Value)); });
            list.Sort((a, b) => a.Value.CompareTo(b.Value));

            NUnit.Framework.Assert.IsTrue(list.GetByIndex(0) == el1);
            NUnit.Framework.Assert.IsTrue(list.GetByIndex(1) == el2);
            NUnit.Framework.Assert.IsTrue(list.GetByIndex(2) == el3);
            NUnit.Framework.Assert.IsTrue(list.GetByIndex(3) == el4);

            list.Sort(delegate(Elem a, Elem b) { return(0 - a.Value.CompareTo(b.Value)); });

            NUnit.Framework.Assert.IsTrue(list.GetByIndex(3) == el1);
            NUnit.Framework.Assert.IsTrue(list.GetByIndex(2) == el2);
            NUnit.Framework.Assert.IsTrue(list.GetByIndex(1) == el3);
            NUnit.Framework.Assert.IsTrue(list.GetByIndex(0) == el4);

            //list.Sort(delegate(Elem a, Elem b) { return 0 - a.Value2.CompareTo(b.Value2); });

            /*list.Sort(delegate(Elem a, Elem b) { return  CompareHelper.CompareTo(a.Value2, b.Value2); });
             *
             * NUnit.Framework.Assert.IsTrue(list.GetByIndex(0) == el1);
             * NUnit.Framework.Assert.IsTrue(list.GetByIndex(1) == el2);
             * NUnit.Framework.Assert.IsTrue(list.GetByIndex(2) == el3);
             * NUnit.Framework.Assert.IsTrue(list.GetByIndex(3) == el4);*/
        }