Exemple #1
0
        public void ShouldNotErrorNonEmptyString()
        {
            CustomSort customSort = new CustomSort();
            SortResult result     = customSort.Sort(INPUT);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Success);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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]+$"));
        }
Exemple #4
0
        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));
        }
Exemple #5
0
        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));
        }
Exemple #6
0
        public void ShouldErrorEmptyString()
        {
            CustomSort customSort = new CustomSort();
            SortResult result     = customSort.Sort(string.Empty);

            Assert.IsNotNull(result);
            Assert.IsFalse(result.Success);
            Assert.IsNotNull(result.ErrorMessage);
        }
Exemple #7
0
        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();
        }
Exemple #8
0
        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();
        }
Exemple #9
0
 static void Main(string[] args)
 {
     Question1.Test();
     EvaluateReversePolishNotation.Test();
     MedianTwoSortedArrays.Test();
     StringSum.Test();
     LongestSubstringWithoutRepeatingChar.Test();
     CustomSort.Test();
     MergeIntervals.Test();
     RegexMatch.Test();
     StringToInt.Test();
 }
Exemple #10
0
        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);
        }
Exemple #11
0
 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();
 }
Exemple #12
0
        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));
        }