Example #1
0
    public void Interpret(string input)
    {
        string[] cmdArgs = input.Split();
        if (cmdArgs[0] == "Create")
        {
            items = new ListyIterator <string>(cmdArgs.Skip(1).ToArray());
        }
        switch (cmdArgs[0])
        {
        case "Move":
            Console.WriteLine(items.MoveIndex());
            break;

        case "Print":
            items.Print();
            break;

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

        case "PrintAll":
            items.PrintAll();
            break;
        }
    }
Example #2
0
    private static void ExecuteCommand(string command, ListyIterator <string> listyIterator)
    {
        switch (command)
        {
        case "Move":
            Console.WriteLine(listyIterator.Move());
            break;

        case "Print":
            try
            {
                listyIterator.Print();
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine(e.Message);
            }
            break;

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

        case "PrintAll":
            listyIterator.PrintAll();
            break;
        }
    }
    public static void Main()
    {
        var inputElements = Console.ReadLine().Split().Skip(1).ToList();
        var elements      = new ListyIterator <string>(inputElements);

        var isContinue = true;

        while (isContinue)
        {
            var command = Console.ReadLine();

            switch (command)
            {
            case "Move":
                Console.WriteLine(elements.Move());
                break;

            case "Print":
                Console.WriteLine(elements.Print());
                break;

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

            case "PrintAll":
                Console.WriteLine(elements.PrintAll());
                break;

            case "END":
                isContinue = false;
                break;
            }
        }
    }
Example #4
0
    public static void Main(string[] args)
    {
        var create = Console.ReadLine().Split(' ');

        var list = create.Skip(1).ToArray();

        var iterator = new ListyIterator <string>(list);

        var command = Console.ReadLine();

        while (command != "END")
        {
            switch (command)
            {
            case "Move":
                Console.WriteLine($"{iterator.Move()}");
                break;

            case "Print":
                iterator.Print();
                break;

            case "HasNext":
                Console.WriteLine($"{iterator.HasNext()}");
                break;

            case "PrintAll":
                Console.WriteLine(string.Join(" ", iterator));
                break;
            }

            command = Console.ReadLine();
        }
    }
Example #5
0
    static void Main(string[] args)
    {
        ListyIterator <string> listyIterator = new ListyIterator <string>(new List <string>());

        string input = string.Empty;

        while ((input = Console.ReadLine()) != "END")
        {
            List <string> commandArgs = input.Split().ToList();
            string        command     = commandArgs[0];

            switch (command)
            {
            case "Create":
                listyIterator.Create(commandArgs.Skip(1).ToList());
                break;

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

            case "Print":
                Console.WriteLine(listyIterator.Print());
                break;

            case "HasNext":
                Console.WriteLine(listyIterator.HasNext());
                break;
            }
        }
    }
Example #6
0
    static void Main(string[] args)
    {
        string inputLine;
        ListyIterator <string> list = new ListyIterator <string>();

        while ((inputLine = Console.ReadLine()) != "END")
        {
            var tokens = inputLine.Split(' ').ToList();
            switch (tokens[0])
            {
            case "Create":
                tokens.RemoveAt(0);
                list = new ListyIterator <string>(tokens);
                break;

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

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

            case "Print":
                list.Print();
                break;
            }
        }
    }
Example #7
0
    public static void Main()
    {
        List <string>          createCommand = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
        ListyIterator <string> list          = new ListyIterator <string>(createCommand.GetRange(1, createCommand.Count - 1));

        string input = Console.ReadLine();

        while (input != "END")
        {
            switch (input)
            {
            case "Move":
                Console.WriteLine(list.Move());
                break;

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

            case "Print":
                list.Print();
                break;

            case "PrintAll":
                list.PrintAll();
                break;

            default:
                break;
            }
            input = Console.ReadLine();
        }
    }
        public void TestMethodPrintInvalid()
        {
            ListyIterator listy = new ListyIterator();

            Assert.That(() => listy.Print(),
                        Throws.InvalidOperationException.With.Message.EqualTo("Invalid Operation!"));
        }
Example #9
0
    static void Main(string[] args)
    {
        string[] initialCommand = Console.ReadLine().Split(' ');

        ListyIterator <string> listyIterator = new ListyIterator <string>(initialCommand.Skip(1).ToArray());

        string command;

        while ((command = Console.ReadLine()) != "END")
        {
            if (command == "Move")
            {
                Console.WriteLine(listyIterator.Move());
            }
            else if (command == "HasNext")
            {
                Console.WriteLine(listyIterator.HasNext());
            }
            else if (command == "Print")
            {
                try
                {
                    listyIterator.Print();
                }
                catch (InvalidOperationException e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
    }
Example #10
0
    public void PrintReturnsExceptionIfCollectionIsEmpty()
    {
        _listyIterator = new ListyIterator <string>(EmptyCollection);

        Assert.That(() => _listyIterator.Print(),
                    Throws.InvalidOperationException.With.Message.EqualTo("Invalid Operation!"));
    }
Example #11
0
    public static void Main()
    {
        var initialInput            = Console.ReadLine().Split();
        ListyIterator <string> list = new ListyIterator <string>(initialInput.Skip(1).ToArray());

        string input;

        while ((input = Console.ReadLine()) != "END")
        {
            try
            {
                if (input == "Move")
                {
                    Console.WriteLine(list.Move());
                }
                else if (input == "Print")
                {
                    Console.WriteLine(list.Print());
                }
                else if (input == "PrintAll")
                {
                    Console.WriteLine(list);
                }
                else if (input == "HasNext")
                {
                    Console.WriteLine(list.HasNext());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
Example #12
0
    static void Main()
    {
        string[] createList = Console.ReadLine()
                              .Split(' ');
        ListyIterator <string> listyIterator = new ListyIterator <string>(createList.Skip(1).ToArray());

        try
        {
            string command = string.Empty;
            while ((command = Console.ReadLine()) != "END")
            {
                string result = string.Empty;
                switch (command)
                {
                case "Move":
                    result = listyIterator.Move().ToString();
                    break;

                case "HasNext":
                    result = listyIterator.HasNext().ToString();
                    break;

                case "Print":
                    result = listyIterator.Print();
                    break;
                }
                Console.WriteLine(result);
            }
        }
        catch (ArgumentException argEx)
        {
            Console.WriteLine(argEx.Message);
        }
    }
    static void Main()
    {
        string[] command = Console.ReadLine().Split(' ').Skip(1).ToArray();
        ListyIterator <string> listyIterator = new ListyIterator <string>(command);

        command = Console.ReadLine().Split(' ').ToArray();

        while (command[0] != "END")
        {
            switch (command[0])
            {
            case "Move":
                Console.WriteLine(listyIterator.Move());

                break;

            case "Print":
                listyIterator.Print();
                break;

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

            case "PrintAll":
                Console.WriteLine(string.Join(" ", listyIterator));
                break;
            }
            command = Console.ReadLine().Split(' ').ToArray();
        }
    }
Example #14
0
    public static void Main()
    {
        ListyIterator <string> listyIterator = new ListyIterator <string>();

        string[] parts = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        listyIterator.Create(parts.Skip(1).ToArray());

        string command = Console.ReadLine();

        while (command != "END")
        {
            switch (command)
            {
            case "Move":
                Console.WriteLine(listyIterator.Move());
                break;

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

            case "Print":
                listyIterator.Print();
                break;
            }
            command = Console.ReadLine();
        }
    }
    public static void Main()
    {
        var input      = Console.ReadLine();
        var listParams = input.Split().Skip(1).ToList();

        myList = new ListyIterator <string>(listParams);

        while ((input = Console.ReadLine()) != "END")
        {
            switch (input)
            {
            case "Move":
                Console.WriteLine(myList.Move());
                break;

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

            case "Print":
                try
                {
                    Console.WriteLine(myList.Print());
                }
                catch (IndexOutOfRangeException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                break;
            }
        }
    }
Example #16
0
    static void Main(string[] args)
    {
        var input      = Console.ReadLine();
        var listItems  = input.Split().Skip(1).ToArray();
        var collection = new ListyIterator <string>(listItems);

        while ((input = Console.ReadLine()) != "END")
        {
            try
            {
                switch (input)
                {
                case "HasNext":
                    Console.WriteLine(collection.HasNext());
                    break;

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

                case "Print":
                    collection.Print();
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
            catch (InvalidOperationException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
Example #17
0
    public static void Main()
    {
        var listIterator = new ListyIterator <string>();

        string input;

        while ((input = Console.ReadLine()) != "END")
        {
            var commands       = input.Split();
            var currentCommand = commands[0];

            switch (currentCommand)
            {
            case "Create":
                listIterator.Create(commands.Skip(1).ToArray());
                break;

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

            case "Print":
                listIterator.Print();
                break;

            case "HasNext":
                Console.WriteLine(listIterator.HasNext());
                break;
            }
        }
    }
Example #18
0
 private static void DispatchCommands(string[] tokens)
 {
     if (tokens[0] == "Create")
     {
         List.Create(tokens);
     }
     else if (tokens[0] == "Move")
     {
         Console.WriteLine(List.MoveNext());
     }
     else if (tokens[0] == "Print")
     {
         try
         {
             Console.WriteLine(List.Print());
         }
         catch (Exception exception)
         {
             Console.WriteLine(exception.Message);
         }
     }
     else if (tokens[0] == "HasNext")
     {
         Console.WriteLine(List.HasNext());
     }
     else if (tokens[0] == "PrintAll")
     {
         Console.WriteLine(List.PrintAll());
     }
 }
Example #19
0
    static void Main(string[] args)
    {
        string[] create     = Console.ReadLine().Split();
        string[] parameters = create.Skip(1).ToArray();

        var list = new ListyIterator <string>(parameters);

        string command;

        while ((command = Console.ReadLine()) != "END")
        {
            switch (command)
            {
            case "Move":
                Console.WriteLine(list.Move());
                break;

            case "Print":
                try
                {
                    list.Print();
                }
                catch (ArgumentException argEx)
                {
                    Console.WriteLine(argEx.Message);
                }
                break;

            case "HasNext":
                Console.WriteLine(list.HasNext());
                break;
            }
        }
    }
Example #20
0
    static void Main()
    {
        ListyIterator listyIterator = new ListyIterator();

        string input;

        while ((input = Console.ReadLine()) != "END")
        {
            var args = input.Split();
            var cmd  = args[0];

            switch (cmd)
            {
            case "Create":
                listyIterator.Create(args.Skip(1).ToArray());
                break;

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

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

            case "Print":
                listyIterator.Print();
                break;

            default:
                break;
            }
        }
    }
        public void IteratorPrintingThrowsIfEmpty()
        {
            List <string> emptyCollection = new List <string>();

            listIterator = new ListyIterator(emptyCollection);

            Assert.Throws <InvalidOperationException>(() => listIterator.Print());
        }
    public void PrintEmptyListThrows()

    {
        list = new ListyIterator <string>();



        Assert.That(() => list.Print(), Throws.InvalidOperationException);
    }
        public void TestMethodPrintValid()
        {
            string[]      testData = InitTestData();
            ListyIterator listy    = new ListyIterator(testData);

            listy.Print();

            Assert.Pass();
        }
Example #24
0
        public void PrintMethodPrintsTheElementOfTheCurrentIndex()
        {
            string         input         = "Gosho Stamat Petsata";
            IListyIterator listyIterator = new ListyIterator <string>("create", input);

            this.SetCurrentIndex(listyIterator);

            Assert.That(() => listyIterator.Print(), Is.EqualTo("Petsata"));
        }
    static void Main()
    {
        var tokens = Console.ReadLine().Split();
        ListyIterator <string> iterator = new ListyIterator <string>(tokens.Skip(1).ToArray());

        string input;

        while ((input = Console.ReadLine()) != "END")
        {
            switch (input)
            {
            case "Move":
                bool isMoved = iterator.Move();
                iterator.Print(isMoved);
                break;

            case "HasNext":
                bool next = iterator.HasNext();
                iterator.Print(next);
                break;

            case "Print":
                try
                {
                    iterator.Print();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                break;

            case "PrintAll":
            {
                foreach (var element in iterator)
                {
                    Console.Write(element + " ");
                }
                Console.WriteLine();
            }
            break;
            }
        }
    }
Example #26
0
    static void Main(string[] args)
    {
        ListyIterator <string> listyIterator = new ListyIterator <string>(new List <string>());

        while (true)
        {
            var tokens = Console.ReadLine().Split().ToList();

            try
            {
                switch (tokens[0])
                {
                case "Create":
                    List <string> names = new List <string>();

                    for (int i = 1; i < tokens.Count; i++)
                    {
                        names.Add(tokens[i]);
                    }

                    listyIterator = new ListyIterator <string>(names);
                    break;

                case "Move":

                    Console.WriteLine(listyIterator.Move());
                    break;

                case "HasNext":

                    Console.WriteLine(listyIterator.HasNext());
                    break;

                case "Print":
                    listyIterator.Print();
                    break;

                case "PrintAll":
                    listyIterator.PrintAll();
                    break;

                case "END":
                    Environment.Exit(0);
                    break;

                default:
                    throw new ArgumentException("Invalid Command !");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
Example #27
0
 private static void TryPrint <T>(ListyIterator <T> listyIterator)
 {
     try
     {
         listyIterator.Print();
     }
     catch (InvalidOperationException iopex)
     {
         Console.WriteLine(iopex.Message);
     }
 }
    public void Start()
    {
        string input = Console.ReadLine();

        while (input != "END")
        {
            var inputLine = input.Split(' ').ToArray();

            string command  = inputLine[0];
            var    commands = inputLine.Skip(1).ToArray();

            switch (command)
            {
            case "Create":
                listyIterator = new ListyIterator <string>(commands);
                break;

            case "Move":
                listyIterator.Move();
                break;

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

            case "HasNext":
                listyIterator.HasNext();
                break;

            case "PrintAll":
                try
                {
                    listyIterator.PrintAll();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                break;

            default:
                break;
            }

            input = Console.ReadLine();
        }
    }
Example #29
0
        public void PrintMethodThrowsExeptionIfListyIteratorIsEmpty()
        {
            string input = "Petsata";
            ListyIterator <string> listyIterator = new ListyIterator <string>("create", input);

            IList <string> iteratorsElements = GetIteratorElements(listyIterator);

            iteratorsElements.Clear();

            Assert.Throws <InvalidOperationException>
                (() => listyIterator.Print(), "Invalid Operation!");
        }
Example #30
0
    public void Print_PrintCurrentElement_CurrentElementAsString()
    {
        var listToUseToInitilize = new List <int>()
        {
            1, 2, 3, 4, 5, 6, 7, 8
        };
        var listy    = new ListyIterator <int>(listToUseToInitilize);
        var expected = "1";
        var actual   = listy.Print();

        Assert.That(actual, Is.EqualTo(expected));
    }