private string ParsePosition(Dictionary <string, string> positions, int index, string segmentResult) { PositionParser positionParser = Factory.CreatePositionParser(); segmentResult = positionParser.Parse(positions, index, segmentResult); return(segmentResult); }
/// <summary> /// Polls for updated data. Because this is an emulator, the next line in the /// record will be used. /// </summary> protected override void pollJointData() { // Clone the current item into this hand, and increase the index Populate(sequence[currentPos++]); // Update the position. PositionRecord pr = PositionParser.GetMatch(this); // Huge ugly if test... // Call the event if this position is recognized, and it's not the same // as the last recognized function. if (pr != null && pr != CurrentPosition && pr != LastPosition) { LastPosition = pr; PositionHasChanged(this, pr); // Check whether any motions have been detected... // There can be multiple matches. List <MotionRecord> matches = MotionParser.GetMatches(pr); foreach (MotionRecord mr in matches) { MotionHasDetected(this, mr); } } CurrentPosition = pr; DataHasUpdated(this); // Check whether we need to stop polling now. checkIfEnded(); }
/// <summary> /// Requests renewed data from the CyberGlove and populates the finger objects with this /// new data. /// </summary> protected virtual void pollJointData() { // Calculate the size of the array. int max = NR_FINGERS * NR_JOINTS + 2; // Create an array of doubles, that will later be filled with joint data. double[] arr = new double[max]; // Poll() fills arr with data and returns the size of the new array. // If that size is not 22, something weird is going on. int size = Poll(this.vhtHand, arr, max); // Fill the hand with data. populate(arr); // Update the position. PositionRecord pr = PositionParser.GetMatch(this); // Huge ugly if test... // Call the event if this position is recognized, and it's not the same // as the last recognized function. if (pr != null && pr != CurrentPosition && pr != LastPosition) { LastPosition = pr; PositionHasChanged(this, pr); // Check whether any motions have been detected... // There can be multiple matches. List <MotionRecord> matches = MotionParser.GetMatches(pr); foreach (MotionRecord mr in matches) { MotionHasDetected(this, mr); } } CurrentPosition = pr; DataHasUpdated(this); }
private Country ParseCountry(IReadOnlyList <string> tokens) { var regex = new Regex(@"^\d{4}[NS] \d{5}[EW]$"); var countryId = tokens[1]; var posToken = tokens.FirstOrDefault(regex.IsMatch); var lat = PositionParser.ParseLatitude(posToken); var lng = PositionParser.ParseLongitude(posToken); if (countryId.Length != 2) { EmitWarn($"Country with invalid UN/LOCODE found: {countryId}"); } var country = new Country { Id = countryId, Name = tokens[3].Trim('.') }; if (lat != null && lng != null) { var position = new Position { Lat = lat.Value, Lng = lng.Value }; country.Position = position; } return(country); }
public void Can_parse_two_numbers_separated_by_space() { PositionParser.TryParse("1234 4321", out Point point).Should().BeTrue(); point.X.Should().Be(1234); point.Y.Should().Be(4321); }
public void LetterNumLetterResturnsNull() { var parser = new PositionParser(); var input = "b4h"; var actual = parser.Parse(input); actual.Should().Be(null); }
public void ValidInputTest() { Direction direction; var point = PositionParser.ParsePosition("7 8 S", out direction); Assert.AreEqual(point.X, 7); Assert.AreEqual(point.Y, 8); Assert.AreEqual(direction, Direction.South); }
public void EnterTypoReturnsNull() { var parser = new PositionParser(); var input = ""; 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); }
/// <summary> /// Lets the user edit the record in command line. /// </summary> /// <param name="record">The PositionRecord that has been recorded.</param> private static void editRecord(PositionRecord record) { string input = ""; do { Console.WriteLine(record.Name); Console.WriteLine(record.CSV); Console.WriteLine("Anything you still want to do?"); Console.WriteLine(" s : Save record"); Console.WriteLine(" q!: Discard record"); Console.WriteLine(" w: Ignore wrist."); Console.WriteLine(" a: Ignore abductions."); Console.WriteLine(" t: Ignore thumb."); Console.WriteLine(" Enter any number from 0 to 21 to"); Console.WriteLine(" add a joint to the ignore list."); Console.Write(">>> "); input = Console.ReadLine().Trim(); int joint = -1; if (input == "q!") { break; } else if (input == "w") { record.IgnoreWrist(); } else if (input == "t") { record.IgnoreThumb(); } else if (input == "a") { record.IgnoreAbductions(); } else if (input == "s") { PositionParser p = new PositionParser("positions.txt"); Console.WriteLine("Saving record!"); for (int i = 0; i < 22; i++) { Console.WriteLine("[{0,2}]: {1,5} : {2,5}", i, record[i].Value, hand[i].Value); } p.Save(record); break; } else if (Int32.TryParse(input, out joint)) { record.Ignored[joint] = true; } else { Console.WriteLine("Unrecognized command!!"); } } while (true); }
public void Input1AResturnsThrowException() { var parser = new PositionParser(); var input = "1A"; var result = parser.Parse(input); result.Should().Be(null); }
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 B3ReturnsPosition12() { var parser = new PositionParser(); var input = "B3"; var actual = parser.Parse(input); var expected = new Position(1, 2); actual.ShouldBeEquivalentTo(expected); }
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 void Position99ReturnsJ10() { PositionParser positionParser = new PositionParser(); Position thePosition = new Position(9, 9); string output = positionParser.BackParser(thePosition); output.Should().Be("J10"); }
public void Position46ReturnsE7() { PositionParser positionParser = new PositionParser(); Position thePosition = new Position(4, 6); string output = positionParser.BackParser(thePosition); output.Should().Be("E7"); }
public Location Parse(string source, out string message) { message = null; var tokens = ExtractTokens(source); if (string.IsNullOrWhiteSpace(tokens[2]) && string.IsNullOrWhiteSpace(tokens[6])) { return(null); // This is a country. } var regex = new Regex(@"^\d{4}[NS] \d{5}[EW]$"); var countryId = tokens[1]; var locationId = countryId + tokens[2]; var functions = ParseFunction(tokens[6]); var changeReason = ParseChangeReason(tokens[0], out message); var changeDetails = ParseChangeDetails(tokens[11], out var remarks); var posToken = tokens.FirstOrDefault(regex.IsMatch); var lat = PositionParser.ParseLatitude(posToken); var lng = PositionParser.ParseLongitude(posToken); if (locationId.Length != 5) { message = $"Location with invalid UN/LOCODE found: {locationId}"; } var location = new Location { UNLOC = locationId, CountryId = countryId, Name = tokens[3], SpellingName = tokens[4], Functions = functions, ChangeReason = changeReason, ChangeDetails = changeDetails, Remarks = remarks }; if (lat != null && lng != null) { var position = new Position { Lat = lat.Value, Lng = lng.Value }; location.Position = position; } return(location); }
public void ReturnX() { PositionParser positionParser = new PositionParser(); Position thePosition = new Position(0, 0); string output = positionParser.BackParser(thePosition); string i = output[0].ToString(); i.Should().Be("A"); }
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); } }
public void ReturnNotNull() { PositionParser positionParser = new PositionParser(); Position thePosition = new Position(0, 0); var output = positionParser.BackParser(thePosition); bool result; if (output != null) { result = true; } else { result = false; } result.Should().Be(true); }
/// <summary> /// Configures the Transition modifier for this item. /// </summary> /// <param name="next">The next position; required to have an end point for the transition.</param> public void InitTransition(HandData next) { if (!HasTransitionModifier) { throw new Exception("Trying to init transition, but the SequenceItem is not specified to allow a transition."); } if (transition == null) { transition = new HashSet <PositionRecord>(); } else { transition.Clear(); } double[] diffs = new double[22]; double iterations = 10.0; HandData needle = new HandData(); for (int i = 0; i < diffs.Length; i++) { diffs[i] = (next[i].Radians - Position[i].Radians) / iterations; needle[i].Value = Position[i].Radians; } for (int i = 0; i < iterations; i++) { // Prepare the needle by making its values approach two's some more. needle.Add(diffs); // Check if this matches a position. List <PositionRecord> list = PositionParser.GetAllMatches(needle, 1.5); foreach (PositionRecord pr in list) { if (transition.Add(pr)) { Console.WriteLine("Found a transitional item: {0}", pr.Name); } } } }
/// <summary> /// Configures the Leniency modifier for this item. /// </summary> public void InitLeniency() { if (!HasLeniencyModifier) { throw new Exception("Trying to init leniency, but the SequenceItem is not specified to be lenient."); } if (leniency == null) { leniency = new HashSet <PositionRecord>(); } else { leniency.Clear(); } List <PositionRecord> list = PositionParser.GetAllMatches(Position); foreach (PositionRecord pr in list) { leniency.Add(pr); } }
/// <summary> /// Creates a new SequenceItem from an input file token. /// </summary> /// <param name="token">The token, containing a positionrecord's name and some modifiers.</param> /// <returns>A SequenceItem created from this token.</returns> public static SequenceItem FromToken(string token) { // List of modifiers that specify details about how the item can be matched. List <char> modifiers = new List <char>(); // Strip the end of the token from its modifiers, and // store those modifiers in the list. while (isModifier(token[token.Length - 1])) { modifiers.Add(token[token.Length - 1]); token = token.Substring(0, token.Length - 1); } // If the name still contains any characters that are not alphanumeric, // throw an exception. if (!isAlphanumeric(token)) { throw new MalformedException(string.Format("Name must be alphanumeric, and all modifiers should appear at the end of the name. This token is invalid: {0}", token)); } SequenceItem rv = new SequenceItem(token); rv.Position = PositionParser.GetByName(token); rv.parseModifiers(modifiers); return(rv); }
public void InVailidDirectionTest() { Direction direction; PositionParser.ParsePosition("7 7 @", out direction); }
public void InVailidXTest() { Direction direction; PositionParser.ParsePosition("A 7 N", out direction); }
public void EmptyInvalidTextTest() { Direction direction; PositionParser.ParsePosition("AB C", out direction); }
public void EmptyInputTest() { Direction direction; PositionParser.ParsePosition(" ", out direction); }