Ejemplo n.º 1
0
        /// <summary>
        /// A test for testing sorting an int collection from start to end 
        /// </summary>
        /// <param name="isAsc">Is ascending</param>
        private void TestSortWithoutRange(bool isAsc)
        {
            BubbleSortV4 target = new BubbleSortV4();
            List<int> list = new List<int>();
            target.Init(list, 20);
            List<int> actual;
            target.IsAsc = isAsc;
            actual = target.Sort(list);

            // Verify if the list is ascending from low position to high position
            for (int i = 0; i < list.Count - 1; i++)
            {
                if (target.IsAsc)
                {
                    Assert.IsTrue(actual[i] <= actual[i + 1]);
                }
                else
                {
                    Assert.IsTrue(actual[i] >= actual[i + 1]);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// A test for testing sorting an int collection between a specific range 
        /// </summary>
        /// <param name="isAsc">Is ascending</param>
        private void TestSortWithRange(bool isAsc)
        {
            BubbleSortV4 target = new BubbleSortV4();
            List<int> list = new List<int>();
            target.Init(list, 20);
            int low = 10;
            int high = 15;
            List<int> actual;
            target.IsAsc = isAsc;
            actual = target.Sort(list, low, high);

            // Verify if the list is sorted from low position to high position
            for (int i = low; i < (high - 1); i++)
            {
                if (target.IsAsc)
                {
                    Assert.IsTrue(actual[i] <= actual[i + 1]);
                }
                else
                {
                    Assert.IsTrue(actual[i] >= actual[i + 1]);
                }
            }
        }