Exemple #1
0
        public void MaxWithDateObjectInputsReturnsCorrectValue()
        {
            var function            = new Max();
            var dateObject1         = new DateTime(2017, 6, 2);
            var dateObject2         = new DateTime(2017, 6, 15);
            var dateObjectAsOADate1 = new DateTime(2017, 6, 2).ToOADate();
            var dateObjectAsOADate2 = new DateTime(2017, 6, 15).ToOADate();

            var result1 = function.Execute(FunctionsHelper.CreateArgs(dateObject1, dateObject2), this.ParsingContext);
            var result2 = function.Execute(FunctionsHelper.CreateArgs(dateObjectAsOADate1, dateObjectAsOADate2), this.ParsingContext);

            Assert.AreEqual(42901d, result1.Result);
            Assert.AreEqual(42901d, result2.Result);
        }
Exemple #2
0
        public void OneNumberTest()
        {
            var exp    = new Max(new[] { new Number(2) }, 1);
            var result = exp.Execute();

            Assert.Equal(2.0, result);
        }
Exemple #3
0
        public void MaxWithStringInputReturnsPoundValue()
        {
            var function = new Max();
            var result   = function.Execute(FunctionsHelper.CreateArgs("string", "string"), this.ParsingContext);

            Assert.AreEqual(eErrorType.Value, ((ExcelErrorValue)result.Result).Type);
        }
Exemple #4
0
        public void ThreeNumberTest()
        {
            var exp    = new Max(new[] { new Number(9), new Number(2), new Number(4) }, 3);
            var result = exp.Execute();

            Assert.Equal(9.0, result);
        }
Exemple #5
0
        public void MaxWithDoublesInputReturnsCorrectValue()
        {
            var function = new Max();
            var result   = function.Execute(FunctionsHelper.CreateArgs(2.5, 26.5, 123.87, 658.64, 55.6), this.ParsingContext);

            Assert.AreEqual(658.64d, result.Result);
        }
Exemple #6
0
        public void MaxWithDatesAsStringsInputReturnsCorrectValue()
        {
            var function = new Max();
            var result   = function.Execute(FunctionsHelper.CreateArgs("5/2/2017", "6/25/2017"), this.ParsingContext);

            Assert.AreEqual(42911d, result.Result);
        }
Exemple #7
0
        public void TwoNumberTest()
        {
            var exp = new Max(new[] { new Number(2), new Number(4) }, 2);
            var result = exp.Execute();

            Assert.Equal(4.0, result);
        }
Exemple #8
0
        public void VectorTest()
        {
            var exp    = new Max(new[] { new Vector(new[] { new Number(1), new Number(2), new Number(3) }) }, 1);
            var result = exp.Execute();

            Assert.Equal(3.0, result);
        }
Exemple #9
0
        public void ThreeNumberTest()
        {
            var exp = new Max(new[] { new Number(9), new Number(2), new Number(4) }, 3);
            var result = exp.Execute();

            Assert.Equal(9.0, result);
        }
Exemple #10
0
        public void OneNumberTest()
        {
            var exp = new Max(new[] { new Number(2) }, 1);
            var result = exp.Execute();

            Assert.Equal(2.0, result);
        }
Exemple #11
0
        public void TwoNumberTest()
        {
            var exp    = new Max(new[] { new Number(2), new Number(4) }, 2);
            var result = exp.Execute();

            Assert.Equal(4.0, result);
        }
Exemple #12
0
        public void MaxWithIntegerInputReturnsCorrectValue()
        {
            var function = new Max();
            var result   = function.Execute(FunctionsHelper.CreateArgs(12, 2, 99, 1, 25), this.ParsingContext);

            Assert.AreEqual(99d, result.Result);
        }
Exemple #13
0
        public void MaxWithInvalidArgumentReturnsPoundValue()
        {
            var function  = new Max();
            var arguments = FunctionsHelper.CreateArgs();
            var result    = function.Execute(arguments, this.ParsingContext);

            Assert.AreEqual(eErrorType.Value, ((ExcelErrorValue)result.Result).Type);
        }
Exemple #14
0
        public void MaxShouldCalculateCorrectResult()
        {
            var func   = new Max();
            var args   = FunctionsHelper.CreateArgs(4, 2, 5, 2);
            var result = func.Execute(args, _parsingContext);

            Assert.AreEqual(5d, result.Result);
        }
Exemple #15
0
        public void MaxShouldIgnoreHiddenValuesIfIgnoreHiddenValuesIsTrue()
        {
            var func = new Max();

            func.IgnoreHiddenValues = true;
            var args = FunctionsHelper.CreateArgs(4, 2, 5, 2);

            args.ElementAt(2).SetExcelStateFlag(ExcelCellState.HiddenCell);
            var result = func.Execute(args, _parsingContext);

            Assert.AreEqual(4d, result.Result);
        }
        public void SpeedTest()
        {
            int length = 65536, ch = 256;

            Shape shape = Shape.Map1D(ch, length);

            OverflowCheckedTensor v1 = new OverflowCheckedTensor(shape);
            OverflowCheckedTensor v2 = new OverflowCheckedTensor(Shape.Map1D(ch, 1));

            Max ope = new Max(shape, axis: 1);

            Stopwatch sw = new Stopwatch();

            sw.Start();

            ope.Execute(v1, v2);
            ope.Execute(v1, v2);
            ope.Execute(v1, v2);
            ope.Execute(v1, v2);

            sw.Stop();

            Console.WriteLine($"{sw.ElapsedMilliseconds / 4} msec");
        }
        public void ExecuteTest()
        {
            Random rd = new Random(1234);

            int width = 4, height = 5;

            foreach (int length in new int[] { 1, 2, 3, 4, 5, 6, 13, 17, 19 })
            {
                foreach (int ch in new int[] { 1, 2, 3, 4, 5, 6, 13, 17, 19 })
                {
                    foreach (int batch in new int[] { 1, 2, 3 })
                    {
                        float[] x = (new float[ch * width * height * length * batch]).Select((_) => (float)rd.NextDouble() * 2 - 1).ToArray();

                        Shape shape = Shape.Map3D(ch, width, height, length, batch);

                        OverflowCheckedTensor v1 = new OverflowCheckedTensor(shape, x);

                        /*axis = 0*/ {
                            OverflowCheckedTensor v2 = new OverflowCheckedTensor(Shape.Map3D(1, width, height, length, batch));

                            Max ope = new Max(shape, axis: 0);

                            ope.Execute(v1, v2);

                            float[] y = v2.State;

                            for (int th = 0; th < batch; th++)
                            {
                                for (int k = 0; k < length; k++)
                                {
                                    for (int j = 0; j < height; j++)
                                    {
                                        for (int i = 0; i < width; i++)
                                        {
                                            float vmax = float.MinValue;

                                            for (int f = 0; f < ch; f++)
                                            {
                                                int idx = f + ch * (i + width * (j + height * (k + length * th)));

                                                vmax = Math.Max(x[idx], vmax);
                                            }

                                            Assert.AreEqual(vmax, y[i + width * (j + height * (k + length * th))], 1e-4f,
                                                            $"axis:0, width:{width}, height:{height}, length:{length}, ch:{ch}, batch:{batch}");
                                        }
                                    }
                                }
                            }
                        }

                        /*axis = 1*/
                        {
                            OverflowCheckedTensor v2 = new OverflowCheckedTensor(Shape.Map3D(ch, 1, height, length, batch));

                            Max ope = new Max(shape, axis: 1);

                            ope.Execute(v1, v2);

                            float[] y = v2.State;

                            for (int th = 0; th < batch; th++)
                            {
                                for (int k = 0; k < length; k++)
                                {
                                    for (int j = 0; j < height; j++)
                                    {
                                        for (int f = 0; f < ch; f++)
                                        {
                                            float vmax = float.MinValue;

                                            for (int i = 0; i < width; i++)
                                            {
                                                int idx = f + ch * (i + width * (j + height * (k + length * th)));

                                                vmax = Math.Max(x[idx], vmax);
                                            }

                                            Assert.AreEqual(vmax, y[f + ch * (j + height * (k + length * th))], 1e-4f,
                                                            $"axis:1, width:{width}, height:{height}, length:{length}, ch:{ch}, batch:{batch}");
                                        }
                                    }
                                }
                            }
                        }

                        /*axis = 2*/
                        {
                            OverflowCheckedTensor v2 = new OverflowCheckedTensor(Shape.Map3D(ch, width, 1, length, batch));

                            Max ope = new Max(shape, axis: 2);

                            ope.Execute(v1, v2);

                            float[] y = v2.State;

                            for (int th = 0; th < batch; th++)
                            {
                                for (int k = 0; k < length; k++)
                                {
                                    for (int i = 0; i < width; i++)
                                    {
                                        for (int f = 0; f < ch; f++)
                                        {
                                            float vmax = float.MinValue;

                                            for (int j = 0; j < height; j++)
                                            {
                                                int idx = f + ch * (i + width * (j + height * (k + length * th)));

                                                vmax = Math.Max(x[idx], vmax);
                                            }

                                            Assert.AreEqual(vmax, y[f + ch * (i + width * (k + length * th))], 1e-4f,
                                                            $"axis:2, width:{width}, height:{height}, length:{length}, ch:{ch}, batch:{batch}");
                                        }
                                    }
                                }
                            }
                        }

                        /*axis = 3*/
                        {
                            OverflowCheckedTensor v2 = new OverflowCheckedTensor(Shape.Map3D(ch, width, height, 1, batch));

                            Max ope = new Max(shape, axis: 3);

                            ope.Execute(v1, v2);

                            float[] y = v2.State;

                            for (int th = 0; th < batch; th++)
                            {
                                for (int j = 0; j < height; j++)
                                {
                                    for (int i = 0; i < width; i++)
                                    {
                                        for (int f = 0; f < ch; f++)
                                        {
                                            float vmax = float.MinValue;

                                            for (int k = 0; k < length; k++)
                                            {
                                                int idx = f + ch * (i + width * (j + height * (k + length * th)));

                                                vmax = Math.Max(x[idx], vmax);
                                            }

                                            Assert.AreEqual(vmax, y[f + ch * (i + width * (j + height * th))], 1e-4f,
                                                            $"axis:3, width:{width}, height:{height}, length:{length}, ch:{ch}, batch:{batch}");
                                        }
                                    }
                                }
                            }
                        }

                        /*axis = 4*/
                        {
                            OverflowCheckedTensor v2 = new OverflowCheckedTensor(Shape.Map3D(ch, width, height, length, 1));

                            Max ope = new Max(shape, axis: 4);

                            ope.Execute(v1, v2);

                            float[] y = v2.State;

                            for (int k = 0; k < length; k++)
                            {
                                for (int j = 0; j < height; j++)
                                {
                                    for (int i = 0; i < width; i++)
                                    {
                                        for (int f = 0; f < ch; f++)
                                        {
                                            float vmax = float.MinValue;

                                            for (int th = 0; th < batch; th++)
                                            {
                                                int idx = f + ch * (i + width * (j + height * (k + length * th)));

                                                vmax = Math.Max(x[idx], vmax);
                                            }

                                            Assert.AreEqual(vmax, y[f + ch * (i + width * (j + height * k))], 1e-4f,
                                                            $"axis:4, width:{width}, height:{height}, length:{length}, ch:{ch}, batch:{batch}");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #18
0
        public void NotSupportedException()
        {
            var exp = new Max(new[] { new Bool(false), new Bool(false) });

            Assert.Throws <ResultIsNotSupportedException>(() => exp.Execute());
        }
Exemple #19
0
        public void VectorTest()
        {
            var exp = new Max(new[] { new Vector(new[] { new Number(1), new Number(2), new Number(3) }) }, 1);
            var result = exp.Execute();

            Assert.Equal(3.0, result);
        }