示例#1
0
        public static void Run()
        {
            IMyCollection myCollection = new MyCollection();

            myCollection.Add("Bonjour");
            myCollection.Add("tout");
            myCollection.Add("le");
            myCollection.Add("monde");

            foreach (var item in myCollection.Values)
            {
                Console.Write($"{item}\t");
            }
            Console.WriteLine();

            IMyCollection mySecondCollection = new MyCollection();

            mySecondCollection.Add("10");
            mySecondCollection.Add("20");
            mySecondCollection.Add("30");
            mySecondCollection.Add("40");
            mySecondCollection.InsertAt(2, "25");
            mySecondCollection.InsertAt(0, "5");

            foreach (var item in mySecondCollection.Values)
            {
                Console.Write($"{item}\t");
            }
            Console.WriteLine();
        }
示例#2
0
        public static void Run()
        {
            IMyCollection myCollection = new MyCollection();

            /*myCollection.Add("Bonjour");
             * myCollection.Add("tout");
             * myCollection.Add("le");
             * myCollection.Add("monde");
             * foreach (var item in myCollection.Values)
             * {
             *  Console.Write(item);
             * }
             * Console.WriteLine();*/

            myCollection.Add("10");
            myCollection.Add("20");
            myCollection.Add("30");
            myCollection.Add("40");
            myCollection.InsertAt(2, "25");
            myCollection.InsertAt(0, "5");
            myCollection.InsertAt(6, "45");
            foreach (var item in myCollection.Values)
            {
                Console.Write(item);
                Console.WriteLine();
            }
            Console.WriteLine();
        }
        static void Main(string[] args)
        {
            /*Notifier notifier = new Notifier();
             * var col = new MyCollection<IDisplay>
             * {
             *  new ConsoleDisplay(),
             *  new FileDisplay()
             * };
             * foreach (IDisplay disp in col)
             * {
             *  notifier.TimerEvent += disp.Display;
             * }
             *
             * notifier.Update(5);*/

            TimeNotifier time = new TimeNotifier(5);
            var          col  = new MyCollection <IDisplay>();

            col.Add(new ConsoleDisplay());
            col.Add(new FileDisplay());

            foreach (IDisplay disp in col)
            {
                time.Timers.Elapsed += disp.Display;
            }
            time.Update();

            Console.ReadLine();
        }
        public void CopyToTest(){
            var list = new MyCollection<char>();
            list.Add('A');
            list.Add('B');
            list.Add('C');

            var biggerArray = new char[] {'1', '2', 'a', 'b', 'c', 'd'};
            var biggerExpected = new char[] {'1', '2', 'A', 'B', 'C', 'd'};
            list.CopyTo(biggerArray, 2);
            Assert.Equal(biggerArray, biggerExpected);

            var equalArray = new char[]{'1', '2', '3', '4'};
            var equalExpected = new char[]{'1', 'A', 'B', 'C'};
            list.CopyTo(equalArray, 1);
            Assert.Equal(equalArray, equalExpected);
            

            var smallArray = new char[]{'1', '2', '3'};
            try
            {
                list.CopyTo(smallArray, 2);
            }
            catch(Exception e)
            {
                Assert.True(e is ArgumentException);
            }
        }
 private void BtnTrunIn_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(TxtName.Text))
     {
         return;
     }
     _submittedTests.Add(new Test(TxtName.Text, int.Parse(TxtNumber.Text)));
     Flush();
 }
        public void CountTest()
        {
            var list = new MyCollection <string>();

            list.Add("A");
            list.Add("B");
            list.Add("C");
            Assert.True(list.Count == 3);
        }
        public void RemoveAtTest()
        {
            var list = new MyCollection <char>();

            list.Add('A');
            list.Add('B');
            list.Add('C');
            list.Add('D');

            list.RemoveAt(0);
            Assert.True(list.Count == 3);
            Assert.True(list[0] == 'B');
            Assert.True(list[1] == 'C');
            Assert.True(list[2] == 'D');

            list.RemoveAt(1);
            Assert.True(list.Count == 2);
            Assert.True(list[0] == 'B');
            Assert.True(list[1] == 'D');

            list.RemoveAt(1);
            Assert.True(list.Count == 1);
            Assert.True(list[0] == 'B');

            list.RemoveAt(0);
            Assert.True(list.Count == 0);

            try
            {
                list.RemoveAt(0);
            }
            catch (Exception e)
            {
                Assert.True(
                    e is IndexOutOfRangeException);
            }

            try
            {
                list.RemoveAt(1);
            }
            catch (Exception e)
            {
                Assert.True(
                    e is IndexOutOfRangeException);
            }

            try
            {
                list.RemoveAt(-1);
            }
            catch (Exception e)
            {
                Assert.True(
                    e is IndexOutOfRangeException);
            }
        }
 public void AddTest()
 {
     var list = new MyCollection<char>();
     list.Add('A');
     list.Add('B');
     list.Add('C');
     var targetArray = new char[] {'A', 'B', 'C'};
     Assert.Equal(targetArray, list.Values);
 }
示例#9
0
        public void RemoveAtTest()
        {
            var list = new MyCollection <string>();

            list.Add("A");
            list.Add("B");
            list.Add("C");
            list.Add("D");

            list.RemoveAt(0);
            Assert.True(list.Count == 3);
            Assert.True(list[0] == "B");
            Assert.True(list[1] == "C");
            Assert.True(list[2] == "D");

            list.RemoveAt(1);
            Assert.True(list.Count == 2);
            Assert.True(list[0] == "B");
            Assert.True(list[1] == "D");

            list.RemoveAt(1);
            Assert.True(list.Count == 1);
            Assert.True(list[0] == "B");

            list.RemoveAt(0);
            Assert.True(list.Count == 0);

            try
            {
                list.RemoveAt(0);
            }
            catch (Exception e)
            {
                Assert.True(
                    e is IndexOutOfRangeException);
            }

            try
            {
                list.RemoveAt(1);
            }
            catch (Exception e)
            {
                Assert.True(
                    e is IndexOutOfRangeException);
            }

            try
            {
                list.RemoveAt(-1);
            }
            catch (Exception e)
            {
                Assert.True(
                    e is IndexOutOfRangeException);
            }
        }
        public void CountTest()
        {
            var list = new MyCollection <char>();

            list.Add('A');
            list.Add('B');
            list.Add('C');
            Assert.True(list.Count == 3);
        }
示例#11
0
        public void AddTest()
        {
            var list = new MyCollection <string>();

            list.Add("A");
            list.Add("B");
            list.Add("C");
            var targetArray = new string[] { "A", "B", "C" };

            Assert.Equal(targetArray, list);
        }
 public void RemoveTest(){
     var list = new MyCollection<char>();
     list.Add('A');
     list.Add('B');
     list.Add('B');
     list.Add('C');
     Assert.True(list.Remove('B'));
     Assert.True(list.Count == 3);
     Assert.True(list[2] == 'C');
     Assert.False(list.Remove('Z'));
 }
示例#13
0
文件: Program.cs 项目: CAHbl4/csharp
        static void Main(string[] args)
        {
            MyCollection<int> intCollection = new MyCollection<int>(2, 6);
            intCollection.Add(3);
            for(int i=0;i<intCollection.Count();i++)
                Console.WriteLine(intCollection[i]);
            intCollection.Sort();
            Console.WriteLine("После сортировки:");
            for (int i = 0; i < intCollection.Count(); i++)
                Console.WriteLine(intCollection[i]);
            int newInt = intCollection.CreateEntity();
            Console.WriteLine("создали число "+newInt);

            //коллекция котов
            MyCollection<Cat> catCollection = new MyCollection<Cat>();
            catCollection.Add(new Cat { Name = "Мурка", Weight = 8 });
            catCollection.Add(new Cat { Name = "Мурзик", Weight = 15 });
            catCollection.Add(new Cat { Name = "Барсик", Weight = 10 });
            for (int i = 0; i < catCollection.Count(); i++)
                Console.WriteLine(catCollection[i]);

            catCollection.Sort();
            Console.WriteLine("После сортировки:");
            for (int i = 0; i < catCollection.Count(); i++)
                Console.WriteLine(catCollection[i]);

            foreach (Cat cat in catCollection)
                Console.WriteLine(cat);

            Cat newCat = catCollection.CreateEntity();
            Console.WriteLine("Создали кота "+newCat);

            DateTime time1 = DateTime.Now;
            ArrayList arrList = new ArrayList();
            for (int i = 0; i < 1000000;i++ )
            {
                arrList.Add(i);//упаковка
                int x =(int) arrList[i];//распаковка
            }
            Console.WriteLine((DateTime.Now-time1).TotalSeconds);
            arrList.Add("Вася");

            DateTime time2 = DateTime.Now;
            List<int> list = new List<int>();
            for (int i = 0; i < 1000000; i++)
            {
                list.Add(i);
                int x = list[i];
            }
            //list.Add("Вася");
            Console.WriteLine((DateTime.Now - time2).TotalSeconds);
                Console.ReadKey();
        }
示例#14
0
        static void Main(string[] args)
        {
            MyCollection myCollection = new MyCollection();

            myCollection.Add(2);
            myCollection.Add(3);
            myCollection.Add(4);
            foreach (var i in myCollection)
            {
                Console.WriteLine(i);
            }
            Console.ReadLine();
        }
        public void IndexTest()
        {
            var list = new MyCollection<char>();
            list.Add('A');
            list.Add('B');
            list.Add('C');
            Assert.True(list[0] == 'A');
            Assert.True(list[1] == 'B');
            Assert.True(list[2] == 'C');

            list[0] = '2';
            Assert.True(list[0] == '2');
        }
        public void ClearTest()
        {
            var list = new MyCollection<char>();
            list.Add('A');
            list.Add('B');
            list.Add('C');
            list.Add('D');

            Assert.True(list.Count == 4);
            list.Clear();
            Assert.True(list.Count == 0);
            
        }
示例#17
0
        public void RemoveTest()
        {
            var list = new MyCollection <string>();

            list.Add("A");
            list.Add("B");
            list.Add("B");
            list.Add("C");
            Assert.True(list.Remove("B"));
            Assert.True(list.Count == 3);
            Assert.True(list[2] == "C");
            Assert.False(list.Remove("Z"));
        }
示例#18
0
        public void WorkCollectionInheritedClasses()
        {
            //throw new NotImplementedException();
            Student student1 = new Student("Имя", "Фамилия", 11, new DateTime(1967, 1, 1), 1);
            Student student2 = new Student("Имя", "Фамилия", 22, new DateTime(1967, 1, 1), 2);
            Student student3 = new Student("Имя", "Фамилия", 33, new DateTime(1967, 1, 1), 3);
            Student student4 = new Student("Имя", "Фамилия", 44, new DateTime(1967, 1, 1), 4);

            MyDictionary groupForDictionary = new MyDictionary();
            groupForDictionary.Add(student1);
            groupForDictionary.Add(student2);
            groupForDictionary.Add(student3);
            groupForDictionary.Add(student4);

            Tuple<string, string, int, DateTime> workKey = Tuple.Create<string, string, int, DateTime>("Имя", "Фамилия", 22, new DateTime(1967, 1, 1));
            if (!groupForDictionary.Contains(workKey))
            {
                Console.WriteLine("Нет такого студента");
            }

            MyCollection<Student> groupForCollection = new MyCollection<Student>();
            groupForCollection.Add(student1);
            groupForCollection.Add(student3);

            Console.WriteLine("Студент 1,3");
            foreach (Student workStudent in groupForCollection)
            {
                Console.WriteLine("{0} {1} : {2}, {3}, {4} ", workStudent.firstName,
                                                              workStudent.secondName,
                                                              workStudent.birthDate,
                                                              workStudent.rating,
                                                              workStudent.personalCode);
            }

            groupForCollection.Insert(1, student2);
            groupForCollection.Remove(student1);
            groupForCollection.Add(student4);

            Console.WriteLine("+ Студент2, -Студент1,+ Студент4");
            foreach (Student workStudent in groupForCollection)
            {
                Console.WriteLine("{0} {1} : {2}, {3}, {4} ", workStudent.firstName,
                                                                  workStudent.secondName,
                                                                  workStudent.birthDate,
                                                                  workStudent.rating,
                                                                  workStudent.personalCode);
            }

            Console.ReadKey();
        }
        public void EnumeratorTest()
        {
            var list = new MyCollection<char>();
            list.Add('A');
            list.Add('B');
            list.Add('C');
            list.Add('D');

            var targetArray = new char[] {'A', 'B', 'C', 'D'};
            foreach(var item in list)
            {
                Assert.True(true);
            }
        }
示例#20
0
    static void Main()
    {
        MyCollection c = new MyCollection();

        c.Add("aaa");
        c.Add("bbb");
        c.Add("ccc");
        foreach (object o in c)
        {
            Console.WriteLine(o);
        }
        Print(c);
        Console.WriteLine("<%END%>");
    }
示例#21
0
        public void SetValueAtProvidedIndex()
        {
            var mc = new MyCollection <int>();

            mc.Add(10);
            mc.Add(5);
            mc.Add(3);

            Assert.Equal(3, mc[2]);

            mc[2] = 100;

            Assert.Equal(100, mc[2]);
        }
示例#22
0
        public void IndexTest()
        {
            var list = new MyCollection <string>();

            list.Add("A");
            list.Add("B");
            list.Add("C");
            Assert.True(list[0] == "A");
            Assert.True(list[1] == "B");
            Assert.True(list[2] == "C");

            list[0] = "Z";
            Assert.True(list[0] == "Z");
        }
示例#23
0
    public static void Main()
    {
        // Creates and initializes a new MyCollection that is read-only.
        IDictionary d = new ListDictionary();

        d.Add("red", "apple");
        d.Add("yellow", "banana");
        d.Add("green", "pear");
        MyCollection myROCol = new MyCollection(d, true);

        // Tries to add a new item.
        try  {
            myROCol.Add("blue", "sky");
        }
        catch (NotSupportedException e)  {
            Console.WriteLine(e.ToString());
        }

        // Displays the keys and values of the MyCollection.
        Console.WriteLine("Read-Only Collection:");
        PrintKeysAndValues(myROCol);


        // Creates and initializes an empty MyCollection that is writable.
        MyCollection myRWCol = new MyCollection();

        // Adds new items to the collection.
        myRWCol.Add("purple", "grape");
        myRWCol.Add("orange", "tangerine");
        myRWCol.Add("black", "berries");
        Console.WriteLine("Writable Collection (after adding values):");
        PrintKeysAndValues(myRWCol);

        // Changes the value of one element.
        myRWCol["orange"] = "grapefruit";
        Console.WriteLine("Writable Collection (after changing one value):");
        PrintKeysAndValues(myRWCol);

        // Removes one item from the collection.
        myRWCol.Remove("black");
        Console.WriteLine("Writable Collection (after removing one value):");
        PrintKeysAndValues(myRWCol);

        // Removes all elements from the collection.
        myRWCol.Clear();
        Console.WriteLine("Writable Collection (after clearing the collection):");
        PrintKeysAndValues(myRWCol);
    }
示例#24
0
    public bool PosTest4()
    {
        bool         retVal      = true;
        const string c_TEST_DESC = "PosTest4: Using customer class which implemented the Clear method in ICollection<T> and Type is int...";
        const string c_TEST_ID   = "P004";

        MyCollection <int> myC = new MyCollection <int>();

        for (int i = 0; i < 10; i++)
        {
            myC.Add(TestLibrary.Generator.GetInt32(-55));
        }

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            ((ICollection <int>)myC).Clear();
            if (myC.Count != 0)
            {
                string errorDesc = "ICollection.Count is not 0 as expected: Actual(" + myC.Count.ToString() + ")";
                TestLibrary.TestFramework.LogError("007" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("008", "Unecpected exception occurs :" + e);
            retVal = false;
        }

        return(retVal);
    }
示例#25
0
    public bool NegTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("NegTest1: Using custome class which implemented the Remove method in ICollection<T> and  is readonly");

        MyCollection <int> myC = new MyCollection <int>();
        int item1 = TestLibrary.Generator.GetInt32(-55);

        myC.Add(item1);
        myC.isReadOnly = true;

        try
        {
            ((ICollection <int>)myC).Remove(item1);
            TestLibrary.TestFramework.LogError("013", "The NotSupportedException was not thrown as expected");
            retVal = false;
        }
        catch (NotSupportedException)
        {
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("014", "Unexpected exception: " + e);
            retVal = false;
        }

        return(retVal);
    }
示例#26
0
        public void EnumeratorTest()
        {
            var list = new MyCollection <string>();

            list.Add("A");
            list.Add("B");
            list.Add("C");
            list.Add("D");

            var targetArray = new string[] { "A", "B", "C", "D" };

            foreach (var item in list)
            {
                Assert.True(true);
            }
        }
示例#27
0
        public void AddTest()
        {
            var col = new MyCollection(10);

            col.Add((Food) new Food().CreateRandom());
            Assert.AreEqual(11, col.Count);
        }
示例#28
0
        public void AddFirearm()
        {
            bool value = false;

            try
            {
                VerifyDoesNotExists();

                value = MyCollection.Add(_databasePath, false, 2, _manufacturesId,
                                         _fullName, "G26", _modelId, "RIA2323423", "Pistol: Semi-Auto - SA/DA", "9mm Luger", "black",
                                         "New", " ", _nationalityId, _gripId, "16oz", "4", "plastic", "5 in", " ", " ", "single", "10 round mag",
                                         "iron", "400.00", "billy bob", "500.00", " ", "MSRP", "500.00", "Safe", " ", " ", "1990", " ",
                                         DateTime.Now.ToString(CultureInfo.InvariantCulture), false, " ", "11/09/2021 14:20:45", " ", " ", true, "1-8", "2 lbs", " ", "Modern", "11/09/2021 14:20:45", false, " ", false, false, out _errOut);
                if (_errOut.Length > 0)
                {
                    throw new Exception(_errOut);
                }
                bool exists = MyCollection.Exists(_databasePath, _fullName, out _errOut);
                if (_errOut.Length > 0)
                {
                    throw new Exception(_errOut);
                }
                value = exists;
            }
            catch (Exception e)
            {
                _errOut = e.Message;
            }

            General.HasTrueValue(value, _errOut);
        }
示例#29
0
    public bool PosTest6()
    {
        bool         retVal      = true;
        const string c_TEST_DESC = "PosTest6: Using customer class which implemented the Contanins method in ICollection<T> and Type is int...";
        const string c_TEST_ID   = "P006";

        int value = TestLibrary.Generator.GetInt32(-55);
        MyCollection <int> myC = new MyCollection <int>();

        for (int i = 0; i < 10; i++)
        {
            value = TestLibrary.Generator.GetInt32(-55);
            myC.Add(value);
        }

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            bool contains = ((ICollection <int>)myC).Contains(value);
            if (!contains)
            {
                string errorDesc = "Value is not false as expected: Actual is true";
                TestLibrary.TestFramework.LogError("011" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("012", "Unecpected exception occurs :" + e);
            retVal = false;
        }

        return(retVal);
    }
示例#30
0
    public bool PosTest4()
    {
        bool         retVal      = true;
        const string c_TEST_DESC = "PosTest4: Using custome class which implemented the Count property in ICollection<T>...";
        const string c_TEST_ID   = "P004";

        MyCollection <int> myC = new MyCollection <int>();
        int count = 10;

        for (int i = 0; i < count; i++)
        {
            myC.Add(TestLibrary.Generator.GetInt32(-55));
        }

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            if (((ICollection <int>)myC).Count != 10)
            {
                string errorDesc = "Count is not 10 as expected: Actual is " + myC.Count;
                TestLibrary.TestFramework.LogError("007" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("008", "Unecpected exception occurs :" + e);
            retVal = false;
        }

        return(retVal);
    }
示例#31
0
        public void Add_ThirtyItems_AllItemsMustbeEquaWithCreatedArray()
        {
            // Arrange
            var random       = new Random();
            var arrayLength  = 30;
            var collection   = new MyCollection <int>();
            var createdArray = new int[arrayLength];

            for (var i = 0; i < arrayLength; i++)
            {
                createdArray[i] = random.Next(10000);
            }

            // Act
            for (var i = 0; i < arrayLength; i++)
            {
                collection.Add(createdArray[i]);
            }

            // Assert
            for (var i = 0; i < arrayLength; i++)
            {
                Assert.Equal(createdArray[i], collection[i]);
            }
        }
示例#32
0
        public void CopyTo_CorrectArguments_DestinationArrayShouldContainsFullCollection(int index)
        {
            // Arrange
            var random           = new Random();
            var arrayLength      = 30;
            var collection       = new MyCollection <string>();
            var destinationArray = new string[100];

            for (var i = 0; i < arrayLength; i++)
            {
                collection.Add(random.Next(10000).ToString());
            }
            for (var i = 0; i < index; i++)
            {
                destinationArray[i] = random.Next(10000).ToString();
            }

            // Act
            collection.CopyTo(destinationArray, index);

            // Assert
            for (int i = 0; i < arrayLength; i++)
            {
                Assert.Equal(collection[i], destinationArray[i + index]);
            }
        }
 private static MyCollection CreateCollection(int count)
 {
     var collBase = new MyCollection();
     for (int i = 0; i < 100; i++)
     {
         collBase.Add(CreateValue(i));
     }
     return collBase;
 }
示例#34
0
        static void Main(string[] args)
        {
            using (new Watcher("Adding to my collection"))
            {
                MyCollection<int> test = new MyCollection<int>();
                test.Add(3);
                test.Add(4);
                test.Add(5);
                test.Add(363);
                test.Add(8);
                test.Add(45);
            }
            using (new Watcher("Adding to List<int>"))
            {
                List<int> test = new List<int>();
                test.Add(3);
                test.Add(4);
                test.Add(5);
                test.Add(363);
                test.Add(8);
                test.Add(45);
            }
            using (new Watcher("Adding to SortedList<int,int>"))
            {
                SortedList<int,int> test = new SortedList<int, int>();
                test.Add(3,3);
                test.Add(4,4);
                test.Add(5,5);
                test.Add(363,363);
                test.Add(8,8);
                test.Add(45,45);
            }

            Console.ReadLine();
        }
 public static void TestAdd()
 {
     MyCollection collBase = new MyCollection();
     for (int i = 0; i < 100; i++)
     {
         Foo value = CreateValue(i);
         collBase.Add(value);
         Assert.True(collBase.Contains(value));
     }
     Assert.Equal(100, collBase.Count);
     for (int i = 0; i < collBase.Count; i++)
     {
         Foo value = CreateValue(i);
         Assert.Equal(value, collBase[i]);               
     }
 }
    public bool Capacity_1_With2Elements()
    {
        bool retValue = true;
        MyCollection mc = new MyCollection();
        Random rndGen = new Random(-55);

        mc.Add(rndGen.Next());
        mc.Add(rndGen.Next());

        retValue &= SetCapacityAndVerify(mc, 1, mc.Capacity, typeof(ArgumentOutOfRangeException));

        if (!retValue)
        {
            Console.WriteLine("Err_012!!! Verifying setting capacity to 1 with 2 elements in the collection FAILED");
        }

        return retValue;
    }
示例#37
0
        public void WorkCollectionInheritedClasses()
        {
            Student firstStudent = new Student("Alina", "Kylish", 123456789, new DateTime(1988, 4, 3));
            Student secondStudent = new Student("Elena", "Kylish", 987654321, new DateTime(1987, 8, 15));
            Student thirdStudent = new Student("Oleg", "Ivanov", 975312468, new DateTime(1992, 11, 20));
            MyDictionary students = new MyDictionary();
            Tuple<string, string, int> key = new Tuple<string,string,int>("Alina", "Kylish", 123456789);
            students.Add(firstStudent);
            if (!students.Contains(key))
            {
                Console.WriteLine("This key is not found");
            }
            else
            {
                Console.WriteLine("This key is found");
            }

            MyCollection students1 = new MyCollection();
            students1.Add(firstStudent);
            students1.Add(secondStudent);
            students1.Insert(0, thirdStudent);
            students1.Add(firstStudent);
            students1.Remove(firstStudent);
            students1.Clear();
            Console.ReadKey();
        }
    public bool Capacity_EqualNumElements()
    {
        bool retValue = true;
        MyCollection mc = new MyCollection(4);
        int initialCapacity = mc.Capacity;
        Random rndGen = new Random(-55);

        for (int i = 0; i < initialCapacity; i++)
        {
            mc.Add(rndGen.Next());
        }

        retValue &= VerifyCapacity(mc, 4);

        if (!retValue)
        {
            Console.WriteLine("Err_017!!! Verifying adding the same number of elements to the collection as the Capacity then remoiving one FAILED");
        }

        return retValue;
    }
    public bool Capacity_GrowRemove()
    {
        bool retValue = true;
        MyCollection mc = new MyCollection(4);
        int initialCapacity = mc.Capacity;
        Random rndGen = new Random(-55);

        for (int i = 0; i < initialCapacity + 1; i++)
        {
            mc.Add(rndGen.Next());
        }
        mc.RemoveAt(initialCapacity);

        retValue &= SetCapacityAndVerify(mc, initialCapacity, initialCapacity, null);

        if (!retValue)
        {
            Console.WriteLine("Err_016!!! Verifying growing the capacity by adding elements tot he collection then removing one FAILED");
        }

        return retValue;
    }
    public bool Capacity_Remove()
    {
        bool retValue = true;
        MyCollection mc = new MyCollection(4);
        int initialCapacity = mc.Capacity;
        Random rndGen = new Random(-55);

        for (int i = 0; i < initialCapacity; i++)
        {
            mc.Add(rndGen.Next());
        }

        mc.RemoveAt(initialCapacity - 1);

        retValue &= SetCapacityAndVerify(mc, initialCapacity - 1, initialCapacity - 1, null);

        if (!retValue)
        {
            Console.WriteLine("Err_015!!! Verifying adding the same number of elements to the collection as the Capacity then remoiving one FAILED");
        }

        return retValue;
    }
    public bool Capacity_Grow()
    {
        bool retValue = true;
        MyCollection mc = new MyCollection(4);
        int initialCapacity = mc.Capacity;
        Random rndGen = new Random(-55);

        for (int i = 0; i < initialCapacity + 1; i++)
        {
            mc.Add(rndGen.Next());
        }

        retValue &= VerifyCapacity(mc, initialCapacity * 2);

        if (!retValue)
        {
            Console.WriteLine("Err_014!!! Verifying growing the capacity by adding elements tot he collection FAILED");
        }

        return retValue;
    }
    public bool Capacity_64_With2Elements()
    {
        bool retValue = true;
        MyCollection mc = new MyCollection();
        Random rndGen = new Random(-55);

        mc.Add(rndGen.Next());
        mc.Add(rndGen.Next());

        retValue &= SetCapacityAndVerify(mc, 64, 64, null);

        if (!retValue)
        {
            Console.WriteLine("Err_013!!! Verifying setting capacity to 64 with 2 elements in the collection FAILED");
        }

        return retValue;
    }
示例#43
0
        public static void Main(string[] args)
        {
            //1* Implement double LinkedList for a Person class (which contains Id, Name , Location properties) and use enumerator to
            // iterate through each item and print the values on console. Note: Dont not use any default classes, only use either IEnumerable/IEnumerator.
            Myenumarable enumarableObj = new Myenumarable ();
            var enumarator =  enumarableObj.GetEnumerator ();
            while (enumarator.MoveNext ()) {
                Person person = (Person)enumarator.Current;
                Console.WriteLine ("Person ID: {0}, Name: {1}, Location: {2}",person.ID, person.Name, person.Location);

            }

            //2. Implement IList<T> interface and perform operations to add, remove, contains, clear all.
            MyCollection<int> myCollection = new MyCollection<int>();
            myCollection.Add (1);
            myCollection.Add (2);
            myCollection.Add (3);
            var enumarator1 = myCollection.GetEnumerator();
            while (enumarator1.MoveNext ()) {
                Console.WriteLine (enumarator1.Current);
            }

            //4. Using .Net provided List<T> and Dictionary<Tkey,TValue>, perform operations for Add,AddRange, Remove, Contains, InsertAt, Clear.
            MyCollection<string> myCollection4 = new MyCollection<string>();
            myCollection4.Add ("John");
            myCollection4.Add ("Lessy");
            myCollection4.Add ("Clair");
            var enumarator4 = myCollection4.GetEnumerator();
            while (enumarator4.MoveNext ()) {
                Console.WriteLine (enumarator4.Current);
            }
            myCollection4.Remove ("Lessy");
            var enumarator41 = myCollection4.GetEnumerator();
            while (enumarator41.MoveNext ()) {
                Console.WriteLine (enumarator41.Current);
            }

            //3* Implement stack and Queue using array as backing field in the class.
            stack st = new stack();
            while (true)
            {
                Console.Clear();
                Console.WriteLine("\nStack MENU(size -- 10)");
                Console.WriteLine("1. Add an element");
                Console.WriteLine("2. See the Top element.");
                Console.WriteLine("3. Remove top element.");
                Console.WriteLine("4. Display stack elements.");
                Console.WriteLine("5. Exit");
                Console.Write("Select your choice: ");
                int choice = Convert.ToInt32(Console.ReadLine());
                switch (choice)
                {
                case 1:
                    Console.WriteLine("Enter an Element : ");
                    st.Push(Console.ReadLine());
                    break;

                case 2: Console.WriteLine("Top element is: {0}", st.Peek());
                    break;

                case 3: Console.WriteLine("Element removed: {0}", st.Pop());
                    break;

                case 4: st.Display();
                    break;

                case 5: System.Environment.Exit(1);
                    break;
                }
                Console.ReadKey();
            }
        }