public void SortedMatches(string value, string candidates, string expectedOutput)
 {
     Assert.Equal(expectedOutput,
                  string.Join(",",
                              StringDistance.GetBestMatchesSorted(
                                  StringDistance.DamareuLevenshteinDistance,
                                  value,
                                  candidates.Split(','),
                                  0.33d
                                  )
                              )
                  );
 }
 public void MatchesBelowThresholdAreNotReturned(string value, string candidates, string expectedOutput, double treshold)
 {
     Assert.Equal(expectedOutput,
                  string.Join(",",
                              StringDistance.GetBestMatchesSorted(
                                  StringDistance.DamareuLevenshteinDistance,
                                  value,
                                  candidates.Split(','),
                                  treshold
                                  )
                              )
                  );
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets a list of suggestions from sub commands and options of <paramref name="command"/> that are likely to
        /// fix the invalid argument <paramref name="input"/>
        /// </summary>
        /// <param name="command"></param>
        /// <param name="input"></param>
        /// <returns>A list of string with suggestions or null if no suggestions were found</returns>
        public static List <string> GetTopSuggestions(CommandLineApplication command, string input)
        {
            var candidates = GetCandidates(command).ToList();

            if (candidates.Count == 0)
            {
                return(null);
            }

            return(StringDistance.GetBestMatchesSorted(StringDistance.DamareuLevenshteinDistance,
                                                       input,
                                                       candidates.Select(c => c.CompareValue),
                                                       0.33d)
                   .ToList());
        }
 public void MatchingWithNullReturnsNull()
 {
     Assert.Empty(StringDistance.GetBestMatchesSorted(null, "", new[] { "" }, 0));
     Assert.Empty(StringDistance.GetBestMatchesSorted((s, s1) => 1, null, new[] { "" }, 0));
     Assert.Empty(StringDistance.GetBestMatchesSorted((s, s1) => 1, "", null, 0));
 }