Ejemplo n.º 1
0
        public void TestGetMedianSingleArray()
        {
            int[]  a        = { 2, 1, 3 };
            double result   = MedianCalculator.GetMedianValue(a);
            double expected = 2;

            Assert.AreEqual(expected, result);

            //even array
            a        = new int[] { 2, 1, 3, 4, 5, 5 };
            result   = MedianCalculator.GetMedianValue(a);
            expected = 3.5;
            Assert.AreEqual(expected, result);

            //odd array
            a        = new int[] { 1, 2, 3, 4, 4, 5, 5 };
            result   = MedianCalculator.GetMedianValue(a);
            expected = 4;
            Assert.AreEqual(expected, result);

            //even array
            a        = new int[] { 1, 1, 1, 2, 1, 1, 1, 1 };
            result   = MedianCalculator.GetMedianValue(a);
            expected = 1;
            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }