Пример #1
0
        public void MinWithDatesAsStringsInputReturnsCorrectValue()
        {
            var function = new Min();
            var result   = function.Execute(FunctionsHelper.CreateArgs("5/2/2017", "6/25/2017"), this.ParsingContext);

            Assert.AreEqual(42857d, result.Result);
        }
Пример #2
0
        public void MinWithLogicalValInArgumentListReturnsCorrectValue()
        {
            var function = new Min();
            var result   = function.Execute(FunctionsHelper.CreateArgs(true, 5, 66, 8), this.ParsingContext);

            Assert.AreEqual(1d, result.Result);
        }
Пример #3
0
        public void MinWithStringsInputReturnsPoundValue()
        {
            var function = new Min();
            var result   = function.Execute(FunctionsHelper.CreateArgs("string", "string"), this.ParsingContext);

            Assert.AreEqual(eErrorType.Value, ((ExcelErrorValue)result.Result).Type);
        }
Пример #4
0
        public void MinWithIntegerInputReturnsCorrectValue()
        {
            var function = new Min();
            var result   = function.Execute(FunctionsHelper.CreateArgs(5, 9, 66, 13), this.ParsingContext);

            Assert.AreEqual(5d, result.Result);
        }
Пример #5
0
        public void MinWithDoublesInputReturnsCorrectValue()
        {
            var function = new Min();
            var result   = function.Execute(FunctionsHelper.CreateArgs(5.6, 23.89, 11.5, 2.6), this.ParsingContext);

            Assert.AreEqual(2.6d, result.Result);
        }
Пример #6
0
        public void OneNumberTest()
        {
            var exp    = new Min(new[] { new Number(2) }, 1);
            var result = exp.Execute();

            Assert.Equal(2.0, result);
        }
Пример #7
0
        public void ThreeNumberTest()
        {
            var exp    = new Min(new[] { new Number(9), new Number(2), new Number(4) });
            var result = exp.Execute();

            Assert.Equal(2.0, result);
        }
Пример #8
0
        public void VectorTest()
        {
            var exp    = new Min(new[] { new Vector(new[] { new Number(1), new Number(2), new Number(3) }) });
            var result = exp.Execute();

            Assert.Equal(1.0, result);
        }
Пример #9
0
        public void TwoNumberTest()
        {
            var exp = new Min(new[] { new Number(2), new Number(4) }, 2);
            var result = exp.Execute();

            Assert.Equal(2.0, result);
        }
Пример #10
0
        public void OneNumberTest()
        {
            var exp = new Min(new[] { new Number(2) }, 1);
            var result = exp.Execute();

            Assert.Equal(2.0, result);
        }
Пример #11
0
        public void MinWithOneArgumentReturnsCorrectValue()
        {
            var function = new Min();
            var result   = function.Execute(FunctionsHelper.CreateArgs(10), this.ParsingContext);

            Assert.AreEqual(10d, result.Result);
        }
Пример #12
0
        public void MinWithInvalidArgumentReturnsPoundValue()
        {
            var function  = new Min();
            var arguments = FunctionsHelper.CreateArgs();
            var result    = function.Execute(arguments, this.ParsingContext);

            Assert.AreEqual(eErrorType.Value, ((ExcelErrorValue)result.Result).Type);
        }
Пример #13
0
        public void MinShouldCalculateCorrectResult()
        {
            var func   = new Min();
            var args   = FunctionsHelper.CreateArgs(4, 2, 5, 2);
            var result = func.Execute(args, _parsingContext);

            Assert.AreEqual(2d, result.Result);
        }
Пример #14
0
        public void MinWithDateObjectsInputReturnsCorrectValue()
        {
            var function    = new Min();
            var dateObject1 = new DateTime(2017, 6, 15);
            var dateObject2 = new DateTime(2017, 5, 18);
            var result      = function.Execute(FunctionsHelper.CreateArgs(dateObject1, dateObject2), this.ParsingContext);

            Assert.AreEqual(42873d, result.Result);
        }
Пример #15
0
        public void MinWithReferenceToCellWithDateObjectAsOADate()
        {
            var function    = new Min();
            var dateObject1 = new DateTime(2017, 5, 12).ToOADate();
            var dateObject2 = new DateTime(2017, 6, 2).ToOADate();
            var dateObject3 = new DateTime(2017, 5, 15).ToOADate();
            var result      = function.Execute(FunctionsHelper.CreateArgs(dateObject1, dateObject2, dateObject3), this.ParsingContext);

            Assert.AreEqual(42867d, result.Result);
        }
Пример #16
0
        public void MinShouldIgnoreHiddenValuesIfIgnoreHiddenValuesIsTrue()
        {
            var func = new Min();

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

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

            Assert.AreEqual(3d, result.Result);
        }
Пример #17
0
        public Completion Execute(ExecutionEnvironment enviroment)
        {
            if (Min == null)
            {
                return(Completion.Exception("parameter of random can not be null", Min));
            }
            if (Max == null)
            {
                return(Completion.Exception("parameter of random can not be null", Max));
            }
            var left = Min.Execute(enviroment);

            if (left.Type != CompletionType.Value)
            {
                return(left);
            }
            var right = Max.Execute(enviroment);

            if (right.Type != CompletionType.Value)
            {
                return(right);
            }
            if (right.Type != CompletionType.Value)
            {
                return(right);
            }
            if (!TypeConverters.IsNumber(left.ReturnValue))
            {
                return(Completion.Exception("value is not a number", Min));
            }
            if (!TypeConverters.IsNumber(right.ReturnValue))
            {
                return(Completion.Exception("value is not a number", Max));
            }
            Type T = TypeConverters.GetNumberTypes(left.ReturnValue, right.ReturnValue);

            if (T == null)
            {
                return(Completion.Exception("Only nuber can accepted", this));
            }

            try
            {
                var l = TypeConverters.GetValue <int>(left.ReturnValue);
                var r = TypeConverters.GetValue <int>(right.ReturnValue);
                return(new Completion(new Random(1437).Next(l, r)));
            }
            catch (Exception e)
            {
                return(Completion.Exception(e.Message, this));
            }
        }
Пример #18
0
        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));

            Min ope = new Min(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");
        }
Пример #19
0
 public void MinShouldCalculateCorrectResult()
 {
     var func = new Min();
     var args = FunctionsHelper.CreateArgs(4, 2, 5, 2);
     var result = func.Execute(args, _parsingContext);
     Assert.AreEqual(2d, result.Result);
 }
Пример #20
0
        public void NotSupportedException()
        {
            var exp = new Min(new[] { new Bool(false), new Bool(false) });

            Assert.Throws <ResultIsNotSupportedException>(() => exp.Execute());
        }
Пример #21
0
        public void VectorTest()
        {
            var exp = new Min(new[] { new Vector(new[] { new Number(1), new Number(2), new Number(3) }) }, 1);
            var result = exp.Execute();

            Assert.Equal(1.0, result);
        }
Пример #22
0
        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));

                            Min ope = new Min(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.MaxValue;

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

                                                vmax = Math.Min(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));

                            Min ope = new Min(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.MaxValue;

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

                                                vmax = Math.Min(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));

                            Min ope = new Min(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.MaxValue;

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

                                                vmax = Math.Min(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));

                            Min ope = new Min(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.MaxValue;

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

                                                vmax = Math.Min(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));

                            Min ope = new Min(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.MaxValue;

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

                                                vmax = Math.Min(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}");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #23
0
 public void MinShouldIgnoreHiddenValuesIfIgnoreHiddenValuesIsTrue()
 {
     var func = new Min();
     func.IgnoreHiddenValues = true;
     var args = FunctionsHelper.CreateArgs(4, 2, 5, 3);
     args.ElementAt(1).SetExcelStateFlag(ExcelCellState.HiddenCell);
     var result = func.Execute(args, _parsingContext);
     Assert.AreEqual(3d, result.Result);
 }
Пример #24
0
 public void MinWithNoArgumentsReturnsPoundValue()
 {
     var function = new Min();
     var result   = function.Execute(FunctionsHelper.CreateArgs(), this.ParsingContext);
 }