Esempio n. 1
0
        public void RunTestbench_NoAlgorithms_DoesntReturnError()
        {
            ArrayCompare.ClearAlgorithmQueue();

            ArrayCompare.RunTestbench();

            //If there is no error, this test is a success
        }
Esempio n. 2
0
        public void QueueListLengthsAreEqual_InEqualLengths_ReturnsFalse()
        {
            ArrayCompare.ClearAlgorithmQueue();

            ArrayCompare.algorithmNames.Add("Test");

            Assert.IsFalse(ArrayCompare.QueueListLengthsAreEqual());
        }
Esempio n. 3
0
        public void FormatTime_5000000ns_Returns5ms()
        {
            double ns             = 5000000;
            string expectedResult = "5 ms";

            string result = ArrayCompare.FormatTimeFromNanoseconds(ns);

            Assert.AreEqual(expectedResult, result);
        }
Esempio n. 4
0
        public void CreateArray_InOrder_CreatesArrayOfRightSize()
        {
            int[] testArray;
            int   expectedResult = ArrayCompare.arraySize;

            testArray = ArrayCompare.CreateArray_InOrder();

            Assert.AreEqual(expectedResult, testArray.Length);
        }
Esempio n. 5
0
        public void QueueListLengthsAreEqual_EqualLengths_ReturnsTrue()
        {
            ArrayCompare.ClearAlgorithmQueue();

            ArrayCompare.AddAlgorithmToQueue("Selection Sort", ArraySortingAlgorithms.SelectionSort);
            ArrayCompare.AddAlgorithmToQueue("Bubble Sort", ArraySortingAlgorithms.BubbleSort);

            Assert.IsTrue(ArrayCompare.QueueListLengthsAreEqual());
        }
Esempio n. 6
0
        public void RunTestbench_NoParams_DoesOneRun()
        {
            int expectedResult = 1;

            ArrayCompare.Init();

            ArrayCompare.RunTestbench();
            int measurements = ArrayCompare.algorithmPerformances.Count;

            Assert.AreEqual(expectedResult, measurements);
        }
Esempio n. 7
0
        public void CreateArray_InOrder_CreatesOrderedArray()
        {
            int[] testArray;

            testArray = ArrayCompare.CreateArray_InOrder();

            for (int i = 0; i < testArray.Length - 1; i++)
            {
                Assert.IsTrue(testArray[i] <= testArray[i + 1]);
            }
        }
Esempio n. 8
0
        public void ClearArrayQueue_ClearsQueue()
        {
            ArrayCompare.ClearArrayQueue();
            int[] testArray = ArrayCompare.CreateArray_InOrder();
            ArrayCompare.AddToBaseArrays(testArray);

            ArrayCompare.ClearArrayQueue();

            Assert.AreEqual(0, ArrayCompare.baseArrays.Count);
            Assert.AreEqual(ArrayCompare.sortedArrays.Count, ArrayCompare.baseArrays.Count);
        }
Esempio n. 9
0
        public void GetAlgorithmIndex_ValidIndex_ReturnsRightIndexOne()
        {
            int expectedResult = 1;

            ArrayCompare.ClearAlgorithmQueue();

            ArrayCompare.AddAlgorithmToQueue("Selection Sort", ArraySortingAlgorithms.SelectionSort);
            ArrayCompare.AddAlgorithmToQueue("Bubble Sort", ArraySortingAlgorithms.BubbleSort);
            int result = ArrayCompare.GetAlgorithmIndex("Bubble Sort");

            Assert.AreEqual(expectedResult, result);
        }
Esempio n. 10
0
        public void AddAlgorithmToQueue_NewAlgorithm_DoesAddToQueue()
        {
            int expectedResult = 1;

            ArrayCompare.ClearAlgorithmQueue();

            ArrayCompare.AddAlgorithmToQueue("Bubble Sort", ArraySortingAlgorithms.BubbleSort);

            Assert.IsTrue(ArrayCompare.algorithmNames.Contains("Bubble Sort"));
            Assert.AreEqual(expectedResult, ArrayCompare.algorithmNames.Count);
            Assert.IsTrue(ArrayCompare.QueueListLengthsAreEqual());
        }
Esempio n. 11
0
        public void ClearAlgorithmQueue_ClearsQueue()
        {
            int expectedResult = 0;

            ArrayCompare.ClearAlgorithmQueue();

            ArrayCompare.AddAlgorithmToQueue("Selection Sort", ArraySortingAlgorithms.SelectionSort);
            ArrayCompare.AddAlgorithmToQueue("Bubble Sort", ArraySortingAlgorithms.BubbleSort);
            ArrayCompare.ClearAlgorithmQueue();

            Assert.AreEqual(expectedResult, ArrayCompare.algorithmNames.Count);
            Assert.IsTrue(ArrayCompare.QueueListLengthsAreEqual());
        }
Esempio n. 12
0
        public void AddToBaseArrays_InvalidArrayLength_DoesNotAddToBaseArray()
        {
            int expectedResult = 0;
            int a = 10;

            if (a == ArrayCompare.arraySize)
            {
                a++;
            }
            int[] testArray = new int[a];
            ArrayCompare.ClearArrayQueue();

            ArrayCompare.AddToBaseArrays(testArray);
            Assert.AreEqual(expectedResult, ArrayCompare.baseArrays.Count);
        }
Esempio n. 13
0
        public void CalculateAlgorithmAveragePerformances_AfterRunTestbench_CalculatesRightAverage()
        {
            ArrayCompare.Init();
            ArrayCompare.RunTestbench();

            long expectedResult = 0;
            int  measurements   = ArrayCompare.algorithmPerformances.Count;

            for (int i = 0; i < measurements; i++)
            {
                expectedResult += ArrayCompare.algorithmPerformances[i][0].ticksElapsed[0];
            }
            expectedResult /= measurements;

            Assert.AreEqual(expectedResult, ArrayCompare.algorithmPerformancesAverage[0].ticksElapsed[0]);
        }
Esempio n. 14
0
        public void AddToBaseArrays_ValidArrayLength_DoesAddToBaseArray()
        {
            int expectedResult;

            ArrayCompare.ClearArrayQueue();
            int[] testArray = ArrayCompare.CreateArray_InOrder();

            ArrayCompare.AddToBaseArrays(testArray);

            Assert.IsNotNull(ArrayCompare.baseArrays[0]);
            Assert.AreEqual(ArrayCompare.baseArrays.Count, 1);
            for (int i = 0; i < testArray.Length; i++)
            {
                expectedResult = testArray[i];
                Assert.AreEqual(expectedResult, ArrayCompare.baseArrays[0][i]);
            }
        }
Esempio n. 15
0
        public void ResetSortedArrays_ResetsSortedToBaseValues()
        {
            int[] testArray;
            int   expectedResult;

            ArrayCompare.ClearArrayQueue();
            testArray = ArrayCompare.CreateArray_InOrder();

            ArrayCompare.AddToBaseArrays(testArray);
            ArrayCompare.ResetSortedArrays();

            Assert.AreEqual(ArrayCompare.baseArrays[0].Length, ArrayCompare.sortedArrays[0].Length);

            for (int i = 0; i < ArrayCompare.baseArrays[0].Length; i++)
            {
                expectedResult = ArrayCompare.baseArrays[0][i];
                Assert.AreEqual(expectedResult, ArrayCompare.sortedArrays[0][i]);
            }
        }
Esempio n. 16
0
        public void QueueListLengthsAreEqual_EmptyLists_ReturnsTrue()
        {
            ArrayCompare.ClearAlgorithmQueue();

            Assert.IsTrue(ArrayCompare.QueueListLengthsAreEqual());
        }