public void ShouldNotErrorNonEmptyString() { CustomSort customSort = new CustomSort(); SortResult result = customSort.Sort(INPUT); Assert.IsNotNull(result); Assert.IsTrue(result.Success); }
public void ShouldMatchExpectedResult() { CustomSort customSort = new CustomSort(); SortResult result = customSort.Sort(INPUT); Assert.IsNotNull(result); Assert.IsTrue(result.Success); Assert.AreEqual(result.SortedString, EXPECTED_RESULT); }
public void ShouldNotContainAnyPunctuation() { CustomSort customSort = new CustomSort(); SortResult result = customSort.Sort(INPUT); Assert.IsNotNull(result); Assert.IsTrue(result.Success); Assert.IsTrue(Regex.IsMatch(result.SortedString, @"^[a-z]+$")); }
public void ShouldBeLowerCase() { CustomSort customSort = new CustomSort(); SortResult result = customSort.Sort(INPUT); Assert.IsNotNull(result); Assert.IsTrue(result.Success); Assert.IsFalse(result.SortedString.Any(char.IsUpper)); }
public void ShouldNotReturnEmptyResult() { CustomSort customSort = new CustomSort(); SortResult result = customSort.Sort(INPUT); Assert.IsNotNull(result); Assert.IsTrue(result.Success); Assert.IsFalse(string.IsNullOrEmpty(result.SortedString)); }
public void ShouldErrorEmptyString() { CustomSort customSort = new CustomSort(); SortResult result = customSort.Sort(string.Empty); Assert.IsNotNull(result); Assert.IsFalse(result.Success); Assert.IsNotNull(result.ErrorMessage); }
public static void Main(string[] args) { string[] arr = null; arr = StringHelper.Init(arr); var func = new Func <string, string, bool>(StringHelper.Compare); CustomSort.Sort(ref arr, func); Console.WriteLine(); Console.WriteLine("Sorted array:"); arr.Show(); }
static void Main(string[] args) { string[] words = { "Hello", "World", "It's", "2017", "Year", "ddasdasdsa5555", "2", "555555", "6666dd" }; CustomSort.Sort(words, SortConditional); foreach (var item in words) { Console.WriteLine(item); } Console.ReadKey(); }
static void Main(string[] args) { Question1.Test(); EvaluateReversePolishNotation.Test(); MedianTwoSortedArrays.Test(); StringSum.Test(); LongestSubstringWithoutRepeatingChar.Test(); CustomSort.Test(); MergeIntervals.Test(); RegexMatch.Test(); StringToInt.Test(); }
public static void TestSortString() { var arrayToSort = new string[] { "abc", "a", "dsfs", "mnsw", "acb", "rcs", "saldkas" }; var sortedArrayAsc = new string[] { "a", "abc", "acb", "rcs", "dsfs", "mnsw", "saldkas" }; var sortedArrayDesc = new string[] { "saldkas", "mnsw", "dsfs", "rcs", "acb", "abc", "a" }; // function for sorting strings by lengths by ascending order, // then by alphabetical order Func <string, string, bool> comparator = new Func <string, string, bool>((a, b) => { if (a.Length != b.Length) { return(a.Length < b.Length); } for (int i = 0; i < a.Length; i++) { if (a[i] != b[i]) { return(a[i] < b[i]); } } return(true); }); // function for sorting strings by lengths by descending order, // then by reversed alphabetical order Func <string, string, bool> antiComparator = new Func <string, string, bool>((a, b) => { return(!comparator.Invoke(a, b)); }); CustomSort sortingUnit = new CustomSort(); sortingUnit.SortArray(arrayToSort, comparator); Assert.AreEqual(sortedArrayAsc, arrayToSort); sortingUnit.SortArray(arrayToSort, antiComparator); Assert.AreEqual(sortedArrayDesc, arrayToSort); }
private static void Sort(Action endSort) { if (endSort == null) { throw new ArgumentNullException(nameof(endSort)); } int[] arr = { 5, 6, 8, 90, 150, 30, 123, 1230, 165, 0, 351, 651, 615, 6158 }; CustomSort.Sort(arr, SortCondition); foreach (var item in arr) { Console.WriteLine(item); } endSort(); }
public static void TestSortDouble() { var rand = new Random(); var numOfItems = 1000; double[] arrayToSort = new double[numOfItems]; for (int i = 0; i < arrayToSort.Length; i++) { arrayToSort[i] = rand.NextDouble() * numOfItems * 10 - numOfItems * 20; } // Reference array, sorted using LINQ double[] sortedArray = (double[])arrayToSort.Clone(); CustomSort sortingUnit = new CustomSort(); sortingUnit.SortArray(arrayToSort, (x, y) => x < y); Assert.AreEqual(arrayToSort, sortedArray.OrderBy(a => a)); sortingUnit.SortArray(arrayToSort, (x, y) => x > y); Assert.AreEqual(arrayToSort, sortedArray.OrderByDescending(a => a)); }