public TextStatistics GenerateStatistics(string textInput) { var result = new TextStatistics(); if (string.IsNullOrEmpty(textInput)) { return(result); } var characterSorter = _sorterFactory.GetSorter(SortOptions.Character); var wordsSorter = _sorterFactory.GetSorter(SortOptions.Word); try { var characters = characterSorter.Partition(textInput); var words = wordsSorter.Partition(textInput); result.Hyphens = characters.Count(c => c.Equals("-")); result.Spaces = characters.Count(c => c.Equals(" ")); result.Words = words.Count; } catch (Exception ex) { throw new TextServiceException(TextServiceException.Error.SortingError, ex, textInput); } return(result); }
public static void TestFixtureSetup(TestContext context) { var sorterFactory = new SorterFactory(); _lineSorter = sorterFactory.GetSorter(SortOptions.Line); _characterSorter = sorterFactory.GetSorter(SortOptions.Character); _wordSorter = sorterFactory.GetSorter(SortOptions.Word); }
private int TestSortings(SortingAlgorithm algorithm, int[] array) { var sorter = SorterFactory.GetSorter(); var swapped = sorter.Sort(algorithm, array); return(swapped); }
public string GetExchangeResults() { var result = new StringBuilder(); var sorter = SorterFactory.GetSorter(); var items = GetItemResults(); var sortedItems = sorter.OrderList(items); foreach (var item in sortedItems) { result.Append($"{item.Currency} {item.Rate:N4}\n"); } return(result.ToString()); }
public SorterContext(int sorterType) { SorterAlgorithm = SorterFactory.GetSorter(sorterType); }