Esempio n. 1
0
        private string ParsePosition(Dictionary <string, string> positions, int index, string segmentResult)
        {
            PositionParser positionParser = Factory.CreatePositionParser();

            segmentResult = positionParser.Parse(positions, index, segmentResult);
            return(segmentResult);
        }
Esempio n. 2
0
        public void B3ReturnsPosition12()
        {
            var parser   = new PositionParser();
            var input    = "B3";
            var actual   = parser.Parse(input);
            var expected = new Position(1, 2);

            actual.ShouldBeEquivalentTo(expected);
        }
Esempio n. 3
0
        public void A4ReturnsPosition03()
        {
            var parser   = new PositionParser();
            var input    = "A4";
            var actual   = parser.Parse(input);
            var expected = new Position(0, 3);

            actual.ShouldBeEquivalentTo(expected);
        }
Esempio n. 4
0
        public void EnterTypoReturnsNull()
        {
            var parser = new PositionParser();
            var input  = "";

            var actual = parser.Parse(input);

            actual.Should().Be(null);
        }
Esempio n. 5
0
        public void LetterNumLetterResturnsNull()
        {
            var parser = new PositionParser();
            var input  = "b4h";

            var actual = parser.Parse(input);

            actual.Should().Be(null);
        }
Esempio n. 6
0
        public void aaResturnsNull()
        {
            var parser = new PositionParser();
            var input  = "aa";

            var actual = parser.Parse(input);

            actual.Should().Be(null);
        }
Esempio n. 7
0
        public void Input1AResturnsThrowException()
        {
            var parser = new PositionParser();
            var input  = "1A";

            var result = parser.Parse(input);

            result.Should().Be(null);
        }
Esempio n. 8
0
        public void B4ReturnsPosition13()
        {
            var parser = new PositionParser();
            var input  = "B4";

            var actual   = parser.Parse(input);
            var expected = new Position(1, 3);

            expected.ShouldBeEquivalentTo(actual);
        }
Esempio n. 9
0
        public void a10ResturnsPosition09()
        {
            var parser = new PositionParser();
            var input  = "a10";

            var actual   = parser.Parse(input);
            var expected = new Position(0, 9);

            expected.ShouldBeEquivalentTo(actual);
        }
Esempio n. 10
0
        public void a2ReturnsPosition01()
        {
            var parser = new PositionParser();
            var input  = "a2";

            var actual   = parser.Parse(input);
            var expected = new Position(0, 1);

            expected.ShouldBeEquivalentTo(actual);
        }
Esempio n. 11
0
        public void Z3ReturnsPosition252()
        {
            var parser = new PositionParser();
            var input  = "Z3";

            var actual   = parser.Parse(input);
            var expected = new Position(25, 2);

            expected.ShouldBeEquivalentTo(actual);
        }
        public string ProcessInput(string input)
        {
            try
            {
                var inputFields = input.Split(' ');
                ValidateNumberOfInputFields(inputFields);

                _plateau  = PlateauParser.Parse(inputFields);
                _position = PositionParser.Parse(inputFields);

                var commands = ParseCommands(input);

                ExecuteCommands(commands);

                return(_position.ToString());
            }
            catch (InputParseException e)
            {
                return(e.Message);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Main method for execution of the test program.
        /// </summary>
        /// <param name="args">Command line arguments.</param>
        static void Main(string[] args)
        {
            // Read TestSettings.ini first.
            initSettings();
            try
            {
                // Make a new hand object that we will be using throughout this program.
                // This can either be an emulated one or an actual object.
                hand = emulating ? new HandEmulator(MOCK) : new Hand();
                // Make the hand poll 24 times per second.
                hand.FPS = 24;
                // Add event handlers to the position and motion events.
                hand.PositionChanged += positionChanged;
                hand.MotionDetected  += MotionDetected;
                Console.WriteLine("Initialisation went fine.");
            }
            catch (ConnectionFailedException e)
            {
                // In connection can't be made, so not much can be done.
                // Exit time!
                Console.WriteLine(e.Message);
                Console.ReadKey(true);
                return;
            }
            try
            {
                // Parse the positions file's contents and print a debugstring.
                PositionParser positionParser = new PositionParser(POSITIONS);
                positionParser.Parse();
                Console.WriteLine(positionParser.DebugString);
                // Parse the motions file.
                MotionParser motionParser = new MotionParser(MOTIONS);
                motionParser.Parse();
            }
            catch (ArgumentException e)
            {
                Console.WriteLine("ArgumentException: " + e.Message);
            }
            catch (MalformedException e)
            {
                Console.WriteLine("MalformedException in {0}: {1}", e.Path, e.Message);
            }

            // Begin the main part of the program. First create the input
            // command parser.
            initCommandParser();

            // Ask for input.
            Console.Write(">>> ");
            string input = Console.ReadLine();
            string cmd   = null;

            do
            {
                // After the first space, some parameters may follow. Separate the input
                // in the command, and the parameters.
                string[] parts = input.Split(new char[] { ' ' }, 2);
                cmd = parts[0];
                if (commandParser.ContainsKey(cmd))
                {
                    // Invoke the function represented by this command.
                    bool rv = (bool)commandParser[cmd].DynamicInvoke(parts.Length > 1 ? parts[1] : "");
                    // Based on the function's return value, give some feedback.
                    Console.WriteLine("Command exited " + (rv ? "without" : "with") + " errors.");
                }
                else
                {
                    // Give the user some feedback about the list of existing commands.
                    unknownCommand();
                }
                // Read next input command.
                Console.Write(">>> ");
                input = Console.ReadLine();
            } while (true);
        }