public void TestMethod1()
        {
            MyQueue <int> intQueue = new MyQueue <int>();

            for (int i = 1; i <= 5; i++)
            {
                intQueue.Enqueue(i);
            }

            if (intQueue.Peek() != 1)
            {
                throw new Exception();
            }
            intQueue.Dequeue();
            if (intQueue.Peek() != 2)
            {
                throw new Exception();
            }
            if (intQueue.Count() != 4)
            {
                throw new Exception();
            }
            intQueue.Clear();
            if (intQueue.Count() != 0)
            {
                throw new Exception();
            }
            if (intQueue.Contains(1))
            {
                throw new Exception();
            }
        }
Beispiel #2
0
        public void ContainsExceptionTest(string source, Type expectedEx)
        {
            var queue = new MyQueue <string>();

            void Result() => queue.Contains(source);

            Assert.Throws(expectedEx, Result);
        }
Beispiel #3
0
 static void Main(string[] args)
 {
     MyQueue<int> queue = new MyQueue<int>();
     queue.Enqueue(1);
     queue.Enqueue(2);
     queue.Dequeue();
     Console.WriteLine(queue.Contains(1));
 }
        public void Queue_EqualityComaparer_PositiveTests()
        {
            MyQueue <Book> qb = new MyQueue <Book>(new ComparerByPrice());

            qb.Enqueue(new Book("Palanik", 120));
            qb.Enqueue(new Book("King", 140));

            Assert.AreEqual(!default(bool), qb.Contains(new Book("Pushkin", 140)));
        }
        public void Queue_EqualityDefault_PositiveTests()
        {
            MyQueue <Book> qb = new MyQueue <Book>();

            qb.Enqueue(new Book("Palanik", 120));
            qb.Enqueue(new Book("King", 140));

            Assert.AreEqual(default(bool), qb.Contains(new Book("Pushkin", 140)));
        }
Beispiel #6
0
        public void ContainsTest()
        {
            MyQueue<int> actualInts = new MyQueue<int>();
            actualInts.Enqueue(5);

            bool actual = actualInts.Contains(5);

            Assert.AreEqual(true, actual);
        }
Beispiel #7
0
        public void DequeueElemContainsTest()
        {
            //Arange
            MyQueue <string> queue = new MyQueue <string>(new[] { "1day", "2day", "3day", "4day", "5day" });

            //Act
            queue.Dequeue();
            //Assert
            Assert.IsFalse(queue.Contains("6day"));
        }
Beispiel #8
0
        public void EnqueueElemContainsTest()
        {
            //Arange
            MyQueue <string> queue = new MyQueue <string>(new[] { "1day", "2day", "3day", "4day", "5day", "6day" });

            //Act
            queue.Enqueue("7day");
            //Assert
            Assert.IsTrue(queue.Contains("7day"));
        }
Beispiel #9
0
        public void ContainsTest()
        {
            MyQueue <int> actualInts = new MyQueue <int>();

            actualInts.Enqueue(5);

            bool actual = actualInts.Contains(5);

            Assert.AreEqual(true, actual);
        }
Beispiel #10
0
        public void ContainsTest()
        {
            object objectItem = new object();

            intQueue.Enqueue(5);
            stringQueue.Enqueue("test");
            objectQueue.Enqueue(objectItem);

            Assert.IsTrue(intQueue.Contains(5));
            Assert.IsTrue(stringQueue.Contains("test"));
            Assert.IsTrue(objectQueue.Contains(objectItem));
            Assert.IsFalse(intQueue.Contains(6));
            Assert.IsFalse(stringQueue.Contains("test1"));
            Assert.IsFalse(objectQueue.Contains(new object()));

            intQueue.Clear();
            stringQueue.Clear();
            objectQueue.Clear();
        }
Beispiel #11
0
        public void Contains_QueueContains6_FalseReturned()
        {
            var queue = new MyQueue <int>();

            queue.Enqueue(-3);
            queue.Enqueue(-6);

            var flag = queue.Contains(6);

            Assert.IsFalse(flag);
        }
Beispiel #12
0
        public void Removes_First_Item()
        {
            var queue = new MyQueue <int> {
                1, 2, 3, 4, 5
            };
            int expectedLength = 4;

            int item         = queue.GetAndRemove();
            int actualLength = queue.Count;

            Assert.IsFalse(queue.Contains(item));
            Assert.AreEqual(expectedLength, actualLength);
        }
Beispiel #13
0
        public void ContainsTest(List <int> source, List <int> contains, List <bool> expectedResult)
        {
            var queue = new MyQueue <int>();

            foreach (var item in source)
            {
                queue.Enqueue(item);
            }

            var result = contains.Select(item => queue.Contains(item));

            Assert.That(result, Is.EqualTo(expectedResult));
        }
        public void TestMethod2()
        {
            MyQueue <Computer> computers = new MyQueue <Computer>();

            computers.Enqueue(new Computer(10234, "HP-Pavilion"));
            computers.Enqueue(new Computer(0, "Test"));
            computers.Enqueue(new Computer(228, "ASUS"));

            if (!computers.Contains(new Computer(0, "Test")))
            {
                throw new Exception();
            }
            if (!computers.Peek().Equals(new Computer(10234, "HP-Pavilion")))
            {
                throw new Exception();
            }
            computers.Clear();
            computers.Enqueue(new Computer(228, "ASUS"));
            if (!computers.Contains(new Computer(228, "ASUS")))
            {
                throw new Exception();
            }
        }
Beispiel #15
0
        static void Queue()
        {
            System.Console.WriteLine("\n=====   Queue   =====\n");

            //IMyQueue<int> queue = new MyArrayQueue<int>();
            IMyQueue <int> queue = new MyQueue <int>();

            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);

            Console.WriteLine(queue.ToString());

            Console.WriteLine(queue.Contains(10));

            Console.WriteLine(queue.Count());

            queue.Dequeue();

            Console.WriteLine(queue.Count());
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            MyQueue <int>    numbers = new MyQueue <int>();
            MyQueue <string> strings = new MyQueue <string>(8);

            char[]         charArray = { 'H', 'i', ',', 'g', 'u', 'y', 's', '!' };
            MyQueue <char> chars     = new MyQueue <char>(charArray);

            Console.WriteLine("String count: ");
            Console.WriteLine(strings.Count);
            strings.Enqueue("one");
            strings.Enqueue("two");
            strings.Enqueue("three");
            strings.Enqueue("fore");
            strings.Enqueue("five");
            strings.Enqueue("six");
            strings.Enqueue("seven");
            strings.Enqueue("eight");
            Console.WriteLine("String queue after adding 8 string: ");
            foreach (var elem in strings)
            {
                Console.Write(elem + " ");
            }
            Console.WriteLine("\nIs 'three' contain in string queue:\n" + strings.Contains("three"));
            Console.WriteLine(strings.Peek());
            strings.Enqueue("nine");
            Console.WriteLine("Queue + 'nine':");
            foreach (var elem in strings)
            {
                Console.Write(elem + " ");
            }
            Console.WriteLine("Remove and return firs element:");
            Console.WriteLine("\n" + strings.Dequeue() + "\n");

            foreach (var elem in strings)
            {
                Console.Write(elem + " ");
            }
            Console.WriteLine("Count of queue:\n" + strings.Count);

            strings.Enqueue("ten");
            strings.Enqueue("eleven");
            Console.WriteLine("Queue + 'ten' and 'eleven':");
            foreach (var elem in strings)
            {
                Console.Write(elem + " ");
            }
            Console.WriteLine("\nChar array: ");
            foreach (var elem in chars)
            {
                Console.Write(elem);
            }

            chars.Clear();
            Console.WriteLine("Char count after Clearing: \n" + chars.Count);
            numbers.Enqueue(1);
            numbers.Enqueue(2);
            numbers.Enqueue(3);
            numbers.Enqueue(4);
            numbers.Enqueue(5);
            numbers.Enqueue(6);
            numbers.Enqueue(7);
            numbers.Enqueue(8);
            numbers.Enqueue(9);
            numbers.Enqueue(10);
            numbers.Enqueue(11);
            Console.WriteLine("Adding 11 elements in queue numbers: \n");
            foreach (var elem in numbers)
            {
                Console.Write(elem);
            }
            //Array array1 = numbers.ToArray();
            //Array array2 = strings.ToArray();
            //Console.WriteLine("\n" + array1.GetType());
            //Console.WriteLine("\n" + array2.GetType());
            Console.ReadKey();
        }
 public void Queue_Contains_PositiveTests()
 {
     Initial();
     Assert.AreEqual(!default(bool), q.Contains("4"));
 }
Beispiel #18
0
        static void Main(string[] args)
        {
            MyQueue <int> newQueue = new MyQueue <int>();

            newQueue.DoClear   += (obj, arg) => Console.WriteLine("Queue cleared.");
            newQueue.DoDequeue += (obj, arg) => Console.WriteLine("Dequeue elem : {0}", arg.data);
            newQueue.DoEnqueue += (obj, arg) => Console.WriteLine("Enqueue elem : {0}", arg.data);

            newQueue.Enqueue(1);
            newQueue.Enqueue(2);
            newQueue.Enqueue(3);
            newQueue.Enqueue(4);

            Console.WriteLine(newQueue.Contains(2));
            Console.WriteLine(newQueue.Contains(10));

            Console.WriteLine(newQueue.ToString());

            newQueue.Dequeue();
            Console.WriteLine(newQueue.ToString());

            int[] newArray = newQueue.ToArray();

            Console.WriteLine("\nQueue:");
            foreach (int elem in newQueue)
            {
                Console.Write(elem + " ");
            }

            Console.WriteLine();
            Console.WriteLine("\nArray:");
            foreach (int elem in newArray)
            {
                Console.Write(elem + " ");
            }
            Console.WriteLine();

            try
            {
                newQueue.CopyTo(null, 0);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }

            try
            {
                int[] newArray1 = new int[1];
                newQueue.CopyTo(newArray1, -1);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }

            try
            {
                int[] newArray1 = new int[1];
                newQueue.CopyTo(newArray1, 0);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }

            newQueue.Clear();

            try
            {
                newQueue.Dequeue();
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Beispiel #19
0
        public bool Contains(string[] arr, string elem)
        {
            MyQueue <string> queue = new MyQueue <string>(arr);

            return(queue.Contains(elem));
        }
Beispiel #20
0
 public void Item_Exists()
 {
     Assert.IsTrue(queue.Contains(3));
 }