Beispiel #1
0
        public void ModeAggregator()
        {
            Func <object, string, object> getVal = (r, f) => {
                return(r);
            };
            var testInputs = new IEnumerable[] {
                new int[] { 1, 2, 2, 3, 4, 7, 9 },
                new int[] { 2, 7, 4, 7, 3, 5, 10, 3, 2, 7, 7, 3 },
                new int[] { 2, 2, 1, 1 },
                new int[] { 1, 2, 2, 1 },                 // in PivotData impl max value is used in case of single-mode to guarantee determinate result
                new int[] { 1, 2, 3 },
                new string[] { "a", "b", "a", "c" }
            };
            var expectedOutputs = new object[] {
                2,
                7,
                2,
                2,
                null,
                "a"
            };

            for (int i = 0; i < testInputs.Length; i++)
            {
                var input          = testInputs[i];
                var expectedOutput = expectedOutputs[i];
                var mode           = new ModeAggregator("f", false);
                foreach (var entry in input)
                {
                    mode.Push(entry, getVal);
                }

                Assert.Equal(expectedOutput, mode.Value);
            }

            // multi-mode test
            var multiMode = new ModeAggregator("f", true);

            foreach (var entry in new int[] { 1, 3, 2, 2, 3 })
            {
                multiMode.Push(entry, getVal);
            }
            var mmVal = multiMode.Value as object[];

            Assert.Equal(2, mmVal.Length);
            Assert.Equal(2, mmVal[0]);
            Assert.Equal(3, mmVal[1]);
        }
Beispiel #2
0
        public void ModeAggregator_Merge()
        {
            Func <object, string, object> getVal = (r, f) => {
                return(r);
            };
            var mode1 = new ModeAggregator("f", false);

            foreach (var entry in new int[] { 1, 3, 2, 2, 3 })
            {
                mode1.Push(entry, getVal);
            }
            var mode2 = new ModeAggregator("f", false);

            foreach (var entry in new int[] { 4, 2, 1 })
            {
                mode2.Push(entry, getVal);
            }

            mode1.Merge(mode2);

            Assert.Equal(2, mode1.Value);
            Assert.Equal(8, (int)mode1.Count);
        }