private string ParsePosition(Dictionary <string, string> positions, int index, string segmentResult) { PositionParser positionParser = Factory.CreatePositionParser(); segmentResult = positionParser.Parse(positions, index, segmentResult); return(segmentResult); }
public void B3ReturnsPosition12() { var parser = new PositionParser(); var input = "B3"; var actual = parser.Parse(input); var expected = new Position(1, 2); actual.ShouldBeEquivalentTo(expected); }
public void A4ReturnsPosition03() { var parser = new PositionParser(); var input = "A4"; var actual = parser.Parse(input); var expected = new Position(0, 3); actual.ShouldBeEquivalentTo(expected); }
public void EnterTypoReturnsNull() { var parser = new PositionParser(); var input = ""; var actual = parser.Parse(input); actual.Should().Be(null); }
public void LetterNumLetterResturnsNull() { var parser = new PositionParser(); var input = "b4h"; var actual = parser.Parse(input); actual.Should().Be(null); }
public void aaResturnsNull() { var parser = new PositionParser(); var input = "aa"; var actual = parser.Parse(input); actual.Should().Be(null); }
public void Input1AResturnsThrowException() { var parser = new PositionParser(); var input = "1A"; var result = parser.Parse(input); result.Should().Be(null); }
public void B4ReturnsPosition13() { var parser = new PositionParser(); var input = "B4"; var actual = parser.Parse(input); var expected = new Position(1, 3); expected.ShouldBeEquivalentTo(actual); }
public void a10ResturnsPosition09() { var parser = new PositionParser(); var input = "a10"; var actual = parser.Parse(input); var expected = new Position(0, 9); expected.ShouldBeEquivalentTo(actual); }
public void a2ReturnsPosition01() { var parser = new PositionParser(); var input = "a2"; var actual = parser.Parse(input); var expected = new Position(0, 1); expected.ShouldBeEquivalentTo(actual); }
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); } }
/// <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); }