예제 #1
0
        public void Statistics_TauCorrelationTest()
        {
            var mergeSorter = new MergeSorter <int>();
            var target      = new TauCorrelation <int, int, double>(
                (a, c) => Array.Sort(a, c),
                (a, c) => mergeSorter.SortCountSwaps(a),
                (v, q) => v / q,
                v => Math.Sqrt(v));

            // Correlação perfeita
            var n            = 100;
            var firstColumn  = new int[n];
            var secondColumn = new int[n];

            for (var i = 0; i < n; ++i)
            {
                firstColumn[i]  = i;
                secondColumn[i] = i;
            }

            var result = target.Run(
                firstColumn,
                secondColumn,
                Comparer <int> .Default,
                Comparer <int> .Default);

            Assert.AreEqual(1.0, result);

            // Correlação contrária
            for (var i = 0; i < n; ++i)
            {
                firstColumn[i]  = n - i - 1;
                secondColumn[i] = i;
            }

            result = target.Run(
                firstColumn,
                secondColumn,
                Comparer <int> .Default,
                Comparer <int> .Default);

            Assert.AreEqual(0.0, result);
        }