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); }
public void MinWithLogicalValInArgumentListReturnsCorrectValue() { var function = new Min(); var result = function.Execute(FunctionsHelper.CreateArgs(true, 5, 66, 8), this.ParsingContext); Assert.AreEqual(1d, result.Result); }
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); }
public void MinWithIntegerInputReturnsCorrectValue() { var function = new Min(); var result = function.Execute(FunctionsHelper.CreateArgs(5, 9, 66, 13), this.ParsingContext); Assert.AreEqual(5d, result.Result); }
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); }
public void OneNumberTest() { var exp = new Min(new[] { new Number(2) }, 1); var result = exp.Execute(); Assert.Equal(2.0, result); }
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); }
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); }
public void TwoNumberTest() { var exp = new Min(new[] { new Number(2), new Number(4) }, 2); var result = exp.Execute(); Assert.Equal(2.0, result); }
public void MinWithOneArgumentReturnsCorrectValue() { var function = new Min(); var result = function.Execute(FunctionsHelper.CreateArgs(10), this.ParsingContext); Assert.AreEqual(10d, result.Result); }
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); }
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); }
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); }
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); }
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); }
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)); } }
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"); }
public void NotSupportedException() { var exp = new Min(new[] { new Bool(false), new Bool(false) }); Assert.Throws <ResultIsNotSupportedException>(() => exp.Execute()); }
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); }
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}"); } } } } } } } } }
public void MinWithNoArgumentsReturnsPoundValue() { var function = new Min(); var result = function.Execute(FunctionsHelper.CreateArgs(), this.ParsingContext); }