Esempio n. 1
0
        public void TestGetMedianDoubleArray()
        {
            int[]  a        = { 1, 2, 3, 4 };
            int[]  b        = { 5, 6, 7, 8 };
            double result   = MedianCalculator.GetMedianValueHighPerformance(a, b);
            double expected = 4.5;

            Assert.AreEqual(expected, result);


            a        = new int[] { 1, 2 };
            b        = new int[] { 1, 2, 3 };
            result   = MedianCalculator.GetMedianValueHighPerformance(a, b);
            expected = 2;
            Assert.AreEqual(expected, result);


            a        = new int[] { 1, 1, 1 };
            b        = new int[] { 1, 1, 3 };
            result   = MedianCalculator.GetMedianValueHighPerformance(a, b);
            expected = 1;
            Assert.AreEqual(expected, result);

            a        = new int[] { 1, 1, 1 };
            b        = new int[] { 1, 1, 1, 1, 1, 3 };
            result   = MedianCalculator.GetMedianValueHighPerformance(a, b);
            expected = 1;
            Assert.AreEqual(expected, result);

            a        = new int[] { 1, 1, 1, 1, 1, 3 };
            b        = new int[] { 1, 1, 1 };
            result   = MedianCalculator.GetMedianValueHighPerformance(a, b);
            expected = 1;
            Assert.AreEqual(expected, result);
        }
Esempio n. 2
0
        public void TestVeryLargeSourceData()
        {
            Random randNumber = new Random();

            int[] a = CreateRandomDataSet(randNumber.Next(3, 10000000));
            int[] b = CreateRandomDataSet(randNumber.Next(3, 10000000));

            double result = MedianCalculator.GetMedianValueHighPerformance(a, b);
            // TODO: validate correct result is given
            // TODO: measure and report on memory and performance of the algorithm
            //       what is the scaling factor when the data set is doubled in size?
        }
Esempio n. 3
0
        public void TestVeryLargeSourceData3()
        {
            Random randNumber = new Random();

            int[] a = CreateRandomDataSet(randNumber.Next(3, 10000000));
            int[] b = { };

            double result = MedianCalculator.GetMedianValueHighPerformance(a, b);

            int[]  combined = a.Concat(b).ToArray();
            double expected = MedianCalculator.GetMedianValue(combined);

            Assert.AreEqual(expected, result);
        }
Esempio n. 4
0
        public void TestGetMedianSingleArray1()
        {
            int[]  a        = { 2, 1, 3 };
            double result   = MedianCalculator.GetMedianValue(a);
            double expected = 2;

            Assert.AreEqual(expected, result);

            a = new int[] { 1, 2, 3, 4 };
            int[] b = { 5, 6, 7 };
            result   = MedianCalculator.GetMedianValueHighPerformance(a, b);
            expected = 4;
            Assert.AreEqual(expected, result);
        }
Esempio n. 5
0
        public void TestVeryLargeSourceData()
        {
            Random randNumber = new Random();

            int[] a = CreateRandomDataSet(randNumber.Next(3, 10000000));
            int[] b = CreateRandomDataSet(randNumber.Next(3, 10000000));

            //my best guess at how to validate the median, using the previous method and a simple concat.
            //I suppose this doesnt have to be efficient if its a test.
            double result = MedianCalculator.GetMedianValueHighPerformance(a, b);

            int[]  combined = a.Concat(b).ToArray();
            double expected = MedianCalculator.GetMedianValue(combined);

            Assert.AreEqual(expected, result);
        }