private long SortChunks() { var splittedFilePaths = Directory.GetFiles(parameters.SplittedFilesDirectoryName, "split*.dat"); var stringSorter = new StringSorter(); long totalRecordsCount = 0; //var parallelOptions = new ParallelOptions() //{ // MaxDegreeOfParallelism = (int)(parameters.MaxMemoryUsageInBytes / parameters.SplittedFileSizeInBytes / 10) //}; // Parallel.ForEach(splittedFilePaths, (splitFilePath) => foreach (var splitFilePath in splittedFilePaths) { var dataStrings = File.ReadAllLines(splitFilePath); totalRecordsCount += dataStrings.Length; parameters.ProgressInformer.Inform($"Start sort spliited file '{splitFilePath}'"); Array.Sort(dataStrings, stringSorter); parameters.ProgressInformer.Inform($"Finish sort spliited file '{splitFilePath}'"); var sortedFilePath = splitFilePath.Replace("split", "sorted"); File.WriteAllLines(sortedFilePath, dataStrings); File.Delete(splitFilePath); GC.Collect(); } return(totalRecordsCount); }
private static void tv1_NodeExpanded(object sender, TreeviewNode node) { if (node.Nodes[0].Tag != null) { return; } string[] sDirs = new StringSorter(Directory.GetDirectories((string)node.Tag)).InsensitiveSort(); var nodes = new TreeviewNode[sDirs.Length]; for (int i = 0; i < nodes.Length; i++) { nodes[i] = new TreeviewNode(sDirs[i].Substring(sDirs[i].LastIndexOf('\\') + 1)) { Tag = sDirs[i] }; if (Directory.GetDirectories(sDirs[i]).Length > 0) { var ni = new TreeviewNode(string.Empty) { Tag = null }; nodes[i].AddNode(ni); } } node.Nodes = nodes; }
public void SortCommaSeparatedStringsTest() { StringSorter stringSorterObj = new StringSorter(); /// only strings made of alphabets and integers List <string> expectedOrderedList = new List <String>() { "0", "25", "50", "100", "a", "A", "c", "C", "e", "E", "z", "Z" }; List <string> actualList = stringSorterObj.SortCommaSeparatedStrings(new string[] { "C", "A", "a", "e", "50", "Z", "z", "c", "0", "E", "25", "100" }); for (int i = 0; i < expectedOrderedList.Count; i++) { Assert.AreEqual(expectedOrderedList[i], actualList[i]); } StringSorter stringSorterObj1 = new StringSorter(); /// Strings mixed with both chars and numbers List <string> expectedOrderedList1 = new List <String>() { "0Zab", "a100DE", "A50DE", "G001A99", "G001A101", "G10A99" }; List <string> actualList1 = stringSorterObj1.SortCommaSeparatedStrings(new string[] { "G001A99", "G10A99", "0Zab", "a100DE", "A50DE", "G001A101" }); for (int i = 0; i < expectedOrderedList1.Count; i++) { Assert.AreEqual(expectedOrderedList1[i], actualList1[i]); } }
public void SortAndChageCase_WorksWell_WithNull() { string[] nullArray = null; var res = new StringSorter().SortAndChangeCase(nullArray); res.Should().BeNull(); }
public void SortAndChageCase_Sorts_OnOneElementArray() { var nullArray = new[] { "" }; var res = new StringSorter().SortAndChangeCase(nullArray); res.Should().HaveCount(1); res[0].Should().BeEmpty(); }
internal void CategorizePropEntries() { if (this.Children.Count > 0) { GridEntry[] dest = new GridEntry[this.Children.Count]; this.Children.CopyTo(dest, 0); if ((base.PropertySort & PropertySort.Categorized) != PropertySort.NoSort) { Hashtable hashtable = new Hashtable(); for (int i = 0; i < dest.Length; i++) { GridEntry entry = dest[i]; if (entry != null) { string propertyCategory = entry.PropertyCategory; ArrayList list = (ArrayList)hashtable[propertyCategory]; if (list == null) { list = new ArrayList(); hashtable[propertyCategory] = list; } list.Add(entry); } } ArrayList list2 = new ArrayList(); IDictionaryEnumerator enumerator = hashtable.GetEnumerator(); while (enumerator.MoveNext()) { ArrayList list3 = (ArrayList)enumerator.Value; if (list3 != null) { string key = (string)enumerator.Key; if (list3.Count > 0) { GridEntry[] array = new GridEntry[list3.Count]; list3.CopyTo(array, 0); try { list2.Add(new CategoryGridEntry(base.ownerGrid, this, key, array)); continue; } catch { continue; } } } } dest = new GridEntry[list2.Count]; list2.CopyTo(dest, 0); StringSorter.Sort(dest); base.ChildCollection.Clear(); base.ChildCollection.AddRange(dest); } } }
public void SortAndChageCase_MakesUpperCase_OnOneElementArray() { var str = "UpperMyCase"; var nullArray = new[] { str }; var res = new StringSorter().SortAndChangeCase(nullArray, toLower: false); res.Should().HaveCount(1); res[0].Should().Be(str.ToUpper()); }
public void SortStrings3() { StringSorter sorter = new StringSorter(); sorter.AddString(s1); sorter.AddString(s2); sorter.AddString(s3); AssertStringOrder(sorter.GetOrderedArray()); }
public void LinqSort_ListWithInvalidString_IndexOutOfRangeException() { List <string> expected = new List <string>() { "qweqweab", "a", "dfsffdda" }; Assert.Throws <IndexOutOfRangeException>(() => StringSorter.LinqSort(expected)); }
public void SortAndChageCase_SortsTwoElementArrayDescending() { var str = "UpperMyCase"; var str2 = "UpeerMyCase2"; var array = new[] { str, str2 }; var res = new StringSorter().SortAndChangeCase(array, @ascending: false); res.Should().HaveCount(2); res[1].Length.Should().BeLessOrEqualTo(res[0].Length); }
public void Test_AlphabeticalSort_CorrectlySortsString_WhenCalled() { // Arrange StringSorter sorter = new StringSorter(); string message = "ecfbad"; string expected = "abcdef"; // Act string result = sorter.AlphabeticalSort(message); // Assert Assert.AreEqual(expected, result); }
public void SortAndChangeCase_SortsAndChangesCase_OnTwoElementArray() { var str = "UpperMyCase"; var str2 = "UpeerMyCase2"; var array = new[] { str2, str }; var res = new StringSorter().SortAndChangeCase(array); res.Should().HaveCount(2); res[0].Length.Should().BeLessOrEqualTo(res[1].Length); res[0].Should().Be(str.ToLower()); res[1].Should().Be(str2.ToLower()); }
public void Test_DistinctAlphabeticalSort_CorrectlySortsStringOfUniqueCharacters_WhenCalled() { // Arrange // Arrange StringSorter sorter = new StringSorter(); string message = "eeecccfbbffabaddde"; string expected = "abcdef"; // Act string result = sorter.DistinctAlphabeticalSort(message); // Assert Assert.AreEqual(expected, result); }
public void Sort_a_empty_Resulted_empty_a() { List <string> list = new List <string> { "a", "" }; List <string> sortedList = new List <string> { "", "a" }; StringSorter stringSorter = new StringSorter(list); list = stringSorter.Sort().ToList(); CollectionAssert.AreEqual(list, sortedList); }
public void LinqSort_SomeStrings_SortedStrings() { List <string> strings = new List <string>() { "asdasdcb", "qweqweab", "dfsffdda" }; List <string> expected = new List <string>() { "qweqweab", "asdasdcb", "dfsffdda" }; CollectionAssert.AreEqual(expected, StringSorter.LinqSort(strings)); }
public void Sort_ba_aa_bb_ab_Resulted_aa_ab_ba_bb() { List <string> list = new List <string> { "ba", "aa", "bb", "ab" }; List <string> sortedList = new List <string> { "aa", "ab", "ba", "bb" }; StringSorter stringSorter = new StringSorter(list); list = stringSorter.Sort().ToList(); CollectionAssert.AreEqual(list, sortedList); }
public void Sort_c_b_a_d_Resulted_a_b_c_d() { List <string> list = new List <string> { "c", "b", "a", "d" }; List <string> sortedList = new List <string> { "a", "b", "c", "d" }; StringSorter stringSorter = new StringSorter(list); list = stringSorter.Sort().ToList(); CollectionAssert.AreEqual(list, sortedList); }
static void SortRun() { List <string> list = new List <string> { "Zebra", //a 1 "Lion", // i 7 "Tiger", //e i 3 "Tiger", //4 "", //0 "Elephent", //e (e)h 2 "Mouse", //e m 6 "Monkey" //e k 5 }; StringSorter sorter = new StringSorter(list); List <string> sortedList = sorter.Sort().ToList(); foreach (var item in sortedList) { Console.WriteLine(item); } }
/// <summary> /// Gets all directories and files from <see cref="FilePath"/> and sets them as items in a sorted order /// </summary> public void UpdateItems() { if (_path == null || !Directory.Exists(_path)) { RequiredHeight = 0; _items = null; return; } try { int i; int c = 0; string[] s = new StringSorter(Directory.GetDirectories(_path)).InsensitiveSort(); _items = new ItemData[s.Length + Directory.GetFiles(_path).Length]; for (i = 0; i < s.Length; i++) { _items[c++] = new ItemData(s[i].Substring(s[i].LastIndexOf('\\') + 1), "", new DirectoryInfo(s[i]).LastWriteTime.ToString(), s[i], FileType.Folder); } s = new StringSorter(Directory.GetFiles(_path)).InsensitiveSort(); for (i = 0; i < s.Length; i++) { _items[c++] = new ItemData(Path.GetFileName(s[i]), Filelen(new FileInfo(s[i]).Length), new FileInfo(s[i]).LastWriteTime.ToString(), s[i], FileType.File); } } // ReSharper disable once EmptyGeneralCatchClause catch { } if (_items != null) { RequiredHeight = ((_items.Length + 1) * (_font.Height + 9)) + 2; } }
public void Test_CountCharOccurences_CorrectlyCountsOccurencesOfEachCharacterInAString_WhenCalled() { // Arrange // Arrange StringSorter sorter = new StringSorter(); string message = "ddfffabb"; int dExpected = 2, fExpected = 3, aExpected = 1, bExpected = 2; // Act Dictionary <char, int> dictionaryResult = sorter.CountCharOccurences(message); int aResult, bResult, dResult, fResult; dictionaryResult.TryGetValue('a', out aResult); dictionaryResult.TryGetValue('b', out bResult); dictionaryResult.TryGetValue('d', out dResult); dictionaryResult.TryGetValue('f', out fResult); // Assert Assert.AreEqual(aExpected, aResult); Assert.AreEqual(bExpected, bResult); Assert.AreEqual(dExpected, dResult); Assert.AreEqual(fExpected, fResult); }
internal void CategorizePropEntries() { if (Children.Count > 0) { GridEntry[] childEntries = new GridEntry[this.Children.Count]; this.Children.CopyTo(childEntries, 0); if ((this.PropertySort & PropertySort.Categorized) != 0) { // first, walk through all the entires and // group them by their category by adding // them to a hashtable of arraylists. // Hashtable bins = new Hashtable(); for (int i = 0; i < childEntries.Length; i++) { GridEntry pe = childEntries[i]; Debug.Assert(pe != null); if (pe != null) { string category = pe.PropertyCategory; ArrayList bin = (ArrayList)bins[category]; if (bin == null) { bin = new ArrayList(); bins[category] = bin; } bin.Add(pe); } } // now walk through the hashtable // and create a categorygridentry for each // category that holds all the properties // of that category. // ArrayList propList = new ArrayList(); IDictionaryEnumerator enumBins = (IDictionaryEnumerator)bins.GetEnumerator(); while (enumBins.MoveNext()) { ArrayList bin = (ArrayList)enumBins.Value; if (bin != null) { string category = (string)enumBins.Key; if (bin.Count > 0) { GridEntry[] rgpes = new GridEntry[bin.Count]; bin.CopyTo(rgpes, 0); try { propList.Add(new CategoryGridEntry(this.ownerGrid, this, category, rgpes)); } catch { } } } } childEntries = new GridEntry[propList.Count]; propList.CopyTo(childEntries, 0); StringSorter.Sort(childEntries); ChildCollection.Clear(); ChildCollection.AddRange(childEntries); } } }
static void Main(string[] args) { string[] sorted = StringSorter.Sort(args); System.Console.WriteLine(string.Join(",", sorted)); }
// Start is called before the first frame update void Start() { mergeSorter = new MergeSorter(); quickSorter = new QuickSorter(); bubbleSorter = new StringSorter(); }
private void button1_Click(object sender, EventArgs e) { label1.Text = Convert.ToString(StringSorter.MonoCounter(StringSorter.StrToArray(textBox1.Text))); }
public void QSort_NullList_ArgumentNullException() { Assert.Throws <ArgumentNullException>(() => StringSorter.QSort(null)); }