Exemple #1
0
        public void IteratorShouldPrintTheCorrectElement()
        {
            ListIterator iterator         = new ListIterator("a", "b");
            FieldInfo    lastPrintedField = iterator.GetType().GetField("lastPrinted", BindingFlags.NonPublic | BindingFlags.Instance);

            iterator.Print();
            string comparator = (string)lastPrintedField.GetValue(iterator);

            Assert.That("a".Equals(comparator));
            iterator.Move();
            iterator.Print();
            comparator = (string)lastPrintedField.GetValue(iterator);
            Assert.That("b".Equals(comparator));
        }
Exemple #2
0
        public void CallingPrintOnEmptyCollectionShouldThrowException()
        {
            ListIterator iterator = new ListIterator();
            Exception    ex       = Assert.Throws <InvalidOperationException>(() => iterator.Print());

            Assert.That(ex.Message == "Invalid Operation!");
        }
        public static void Main()
        {
            IListIterator list = null;

            var input = string.Empty;

            while ((input = Console.ReadLine()) != "END")
            {
                try
                {
                    var tokens = input.Split();

                    switch (tokens[0])
                    {
                    case "Create":
                        var collection = new List <string>(tokens.Skip(1));
                        list = new ListIterator(collection);
                        break;

                    case "Move":
                        Console.WriteLine(list.Move());
                        break;

                    case "HasNext":
                        Console.WriteLine(list.HasNext());
                        break;

                    case "Print":
                        Console.WriteLine(list.Print());
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }