Пример #1
0
        static void Main(string[] args)
        {
            IntegerList listOfIntegers = new IntegerList();

            listOfIntegers.Add(1);                         // [1]
            listOfIntegers.Add(2);                         // [1 ,2]
            listOfIntegers.Add(3);                         // [1 ,2 ,3]
            listOfIntegers.Add(4);                         // [1 ,2 ,3 ,4]
            listOfIntegers.Add(5);                         // [1 ,2 ,3 ,4 ,5]
            listOfIntegers.RemoveAt(0);                    // [2 ,3 ,4 ,5]
            listOfIntegers.Remove(5);                      // [2 ,3 ,4]
            Console.WriteLine(listOfIntegers.Count);       // 3
            Console.WriteLine(listOfIntegers.Remove(100)); // false
            Console.WriteLine(listOfIntegers.RemoveAt(5)); // false
            listOfIntegers.Clear();                        // []
            Console.WriteLine(listOfIntegers.Count);       // 0

            GenericList <string> stringList = new GenericList <string>();

            stringList.Add(" Hello ");
            stringList.Add(" World ");
            stringList.Add("!");
            foreach (string value in stringList)
            {
                Console.WriteLine(value);
            }
        }
Пример #2
0
        public static void Main()
        {
            IntegerList listOfIntegers = new IntegerList(5);
            Console.WriteLine(listOfIntegers.Count);
            listOfIntegers.Add(3);
            listOfIntegers.Add(4);
            listOfIntegers.Add(5);
            listOfIntegers.Add(1);
            Console.WriteLine("Count: " + listOfIntegers.Count);
            Console.WriteLine("Contains 2? " + listOfIntegers.Contains(2));
            Console.WriteLine("Contains 4? " + listOfIntegers.Contains(4));
            Console.WriteLine("Element at 2: " + listOfIntegers.GetElement(2));
            Console.WriteLine("Element at 3: " + listOfIntegers.GetElement(3));
            Console.WriteLine("Index of 7: " + listOfIntegers.IndexOf(7));
            Console.WriteLine("Index of 5: " + listOfIntegers.IndexOf(5));
            Console.WriteLine("Remove 5: " + listOfIntegers.Remove(5));
            Console.WriteLine("Index of 5: " + listOfIntegers.IndexOf(7));
            Console.WriteLine("Contains 5: " + listOfIntegers.Contains(5));
            Console.WriteLine("Count: " + listOfIntegers.Count);
            Console.WriteLine("Element at 2: " + listOfIntegers.GetElement(2));
            Console.WriteLine("Remove at 2: " + listOfIntegers.RemoveAt(2));
            Console.WriteLine("Element at 1: " + listOfIntegers.GetElement(1));
            Console.WriteLine("Count: " + listOfIntegers.Count);
            Console.WriteLine("Remove 5: " + listOfIntegers.Remove(5));

            listOfIntegers.Clear();
            Console.WriteLine(listOfIntegers.Count);

            //GenericList
            IGenericList<string> stringList = new GenericList<string>();
            stringList.Add("Hello");
            stringList.Add("World");
            stringList.Add("!");
            /*
            Console.WriteLine(stringList.Count);   
            Console.WriteLine(stringList.Contains("Hello"));    
            Console.WriteLine(stringList.IndexOf("Hello"));     
            Console.WriteLine(stringList.GetElement(1));
            */

            foreach (string value in stringList)
            {
                Console.WriteLine(value);
            }

            /*
            IGenericList<double> doubleList = new GenericList<double>(2);
            doubleList.Add(0.2);     
            doubleList.Add(0.7);
            Console.WriteLine(doubleList.Count);
            Console.WriteLine(doubleList.Contains(0.2));
            Console.WriteLine(doubleList.IndexOf(0.7));
            doubleList.Add(0.3);
            Console.WriteLine(doubleList.GetElement(2));
            doubleList.Add(0.9);
            Console.WriteLine(doubleList.Count);
        */

        }
Пример #3
0
        public void IndexOf_1Point()
        {
            IIntegerList list = new IntegerList();

            list.Add(1);
            list.Add(2);
            list.Add(3);

            Assert.AreEqual(0, list.IndexOf(1));
            Assert.AreEqual(1, list.IndexOf(2));
            Assert.AreEqual(-1, list.IndexOf(100));
        }
Пример #4
0
        public void Clear_1Point()
        {
            IIntegerList list = new IntegerList();

            list.Add(1);
            list.Add(2);
            list.Add(3);
            Assert.AreEqual(3, list.Count);

            list.Clear();
            Assert.AreEqual(0, list.Count);
        }
Пример #5
0
        public void Count_1Point()
        {
            IIntegerList list = new IntegerList();

            Assert.AreEqual(0, list.Count);

            list.Add(1);
            list.Add(2);
            list.Add(3);
            Assert.AreEqual(3, list.Count);

            list.Remove(3);
            list.Remove(2);
            Assert.AreEqual(1, list.Count);
        }
Пример #6
0
        public void Contains_1Point()
        {
            IIntegerList list = new IntegerList();

            list.Add(11);
            list.Add(22);
            list.Add(33);
            Assert.IsTrue(list.Contains(33));
            Assert.IsTrue(list.Contains(22));
            Assert.IsTrue(list.Contains(11));
            Assert.IsFalse(list.Contains(44));

            list.Clear();
            Assert.IsFalse(list.Contains(33));
        }
Пример #7
0
        public void AddToList_1Point()
        {
            IIntegerList list = new IntegerList();

            list.Add(10);

            Assert.AreEqual(10, list.GetElement(0));
            Assert.AreEqual(1, list.Count);

            list.Add(11);
            Assert.AreEqual(10, list.GetElement(0));
            Assert.AreEqual(11, list.GetElement(1));

            Assert.AreEqual(2, list.Count);
        }
Пример #8
0
        public void RemoveFromList_1Point()
        {
            IIntegerList list = new IntegerList();

            list.Add(11);
            list.Add(2);
            list.Add(11);

            Assert.AreEqual(false, list.Remove(10));
            Assert.AreEqual(3, list.Count);

            // will remove only first occurence
            Assert.AreEqual(true, list.Remove(11));
            Assert.AreEqual(11, list.GetElement(1));
            Assert.AreEqual(2, list.GetElement(0));
        }
Пример #9
0
        public void RemoveAtIndex_ThrowsIndexOutOfRangeException_1Point()
        {
            IIntegerList list = new IntegerList();

            list.Add(11);

            list.RemoveAt(100);
        }
Пример #10
0
        public void RemoveAtIndex_1Point()
        {
            IIntegerList list = new IntegerList();

            list.Add(11);

            Assert.AreEqual(true, list.RemoveAt(0));
            Assert.AreEqual(0, list.Count);

            list.Add(11);
            list.Add(12);
            list.Add(13);

            Assert.AreEqual(true, list.RemoveAt(1));
            Assert.AreEqual(2, list.Count);
            Assert.AreEqual(11, list.GetElement(0));
            Assert.AreEqual(13, list.GetElement(1));
        }
Пример #11
0
        public static void Main()
        {
            IntegerList listOfIntegers = new IntegerList();

            listOfIntegers.Add(1);                         // [1]
            listOfIntegers.Add(2);                         // [1 ,2]
            listOfIntegers.Add(3);                         // [1 ,2 ,3]
            listOfIntegers.Add(4);                         // [1 ,2 ,3 ,4]
            listOfIntegers.Add(5);                         // [1 ,2 ,3 ,4 ,5]
            listOfIntegers.RemoveAt(0);                    // [2 ,3 ,4 ,5]
            listOfIntegers.Remove(5);                      //[2 ,3 ,4]
            Console.WriteLine(listOfIntegers.Count);       // 3
            Console.WriteLine(listOfIntegers.Remove(100)); // false
            Console.WriteLine(listOfIntegers.RemoveAt(5)); // false
            listOfIntegers.Clear();                        // []
            Console.WriteLine(listOfIntegers.Count);       // 0
            Console.ReadLine();
        }
Пример #12
0
        static void Main(string[] args)
        {
            IntegerList a = new IntegerList();

            a.Add(1);
            a.Add(5);
            a.Add(-2);
            a.Add(3);
            a.Add(10);

            a.RemoveAt(2);
            a.Remove(5);
            int  b   = a.Count;
            bool boo = a.Contains(69);
            bool bo  = a.Remove(24);

            a.Clear();
            b = a.Count;
        }
Пример #13
0
        static void Main(string[] args)
        {
            IntegerList l = new IntegerList();
            l.Add(1);
            l.Add(2);
            l.Add(3);
            Console.WriteLine( l.Remove(5));
            Console.WriteLine(l.RemoveAt(3));
            Console.WriteLine(l.Remove(3));
            Console.WriteLine(l.IndexOf(2));
            try {
                Console.WriteLine(l.GetElement(2));
                Console.WriteLine(l.GetElement(3));
            }
            catch (IndexOutOfRangeException)
            {
                Console.WriteLine("Please enter index between 0 and {0}", l.Count);
            }
            Console.WriteLine(l.Count);


        }
Пример #14
0
        static void Main(string[] args)
        {
            IntegerList intList = new IntegerList();

            Console.WriteLine("{0, 9} {1, 9}", "Elements", "Capacity");
            Console.WriteLine("{0}", new string('-', 19));
            Console.WriteLine("{0, 9} {1, 9}", intList.Count, intList.Capacity);

            for (int count = 0; count < 50; count++)
            {
                intList.Add(count);
                Console.WriteLine("{0, 9} {1, 9}", intList.Count, intList.Capacity);
            }
        }
Пример #15
0
        public void ListRebuildTest_1Point()
        {
            IIntegerList list = new IntegerList(100);

            for (int i = 0; i < 100000; i++)
            {
                list.Add(i);
            }

            Assert.AreEqual(100000, list.Count);

            for (int i = 0; i < 100000; i++)
            {
                Assert.AreEqual(i, list.GetElement(i));
            }
        }
Пример #16
0
        public RuleRecord(Record record)
        {
            if (record.Entries.Count < 4)
            {
                throw new ContentException("Numero invalido de reglas");
            }
            byte header = record.Entries[0].ToByteValue();

            if (header != 82) //'R'
            {
                throw new ContentException("Numero invalido de reglas");
            }
            this.index       = record.Entries[1].ToIntValue();
            this.nonterminal = record.Entries[2].ToIntValue();
            this.symbols     = new IntegerList();
            for (int i = 4; i < record.Entries.Count; i++)
            {
                int symbol = record.Entries[i].ToIntValue();
                symbols.Add(symbol);
            }
        }
        public RuleRecord(Record record)
        {
            if (record.Entries.Count < 4)
            {
                throw new CGTContentException("Invalid number of entries for rule");
            }
            byte header = record.Entries[0].ToByteValue();

            if (header != 82)             //'R'
            {
                throw new CGTContentException("Invalid rule header");
            }
            this.index       = record.Entries[1].ToIntValue();
            this.nonterminal = record.Entries[2].ToIntValue();
            //skip reserved empty entry
            this.symbols = new IntegerList();
            for (int i = 4; i < record.Entries.Count; i++)
            {
                int symbol = record.Entries[i].ToIntValue();
                symbols.Add(symbol);
            }
        }