public void YearFracWithBothDatesTheSameReturnsCorrectResult() { var date = new DateTime(2017, 1, 1); var func = new Yearfrac(); var args = FunctionsHelper.CreateArgs(date.ToOADate(), date.ToOADate()); var result = func.Execute(args, this.ParsingContext); Assert.AreEqual(0.0, result.Result); }
public void YearFracWithNullSecondParameterReturnsPoundNA() { // Note that 42736 is Excel OADate for 1/1/2017. var func = new Yearfrac(); var args = FunctionsHelper.CreateArgs(42736, null); var result = func.Execute(args, this.ParsingContext); Assert.AreEqual(eErrorType.NA, ((ExcelErrorValue)result.Result).Type); }
public void YearFracWithNullFirstParameterReturnsPoundNA() { // Note that 42878 is the Excel OADate for 5/23/2017. var func = new Yearfrac(); var args = FunctionsHelper.CreateArgs(null, 42878); var result = func.Execute(args, this.ParsingContext); Assert.AreEqual(eErrorType.NA, ((ExcelErrorValue)result.Result).Type); }
public void YearFracWithDateAsNegativeDoubleInStringReturnsPoundNum() { // Note that 42736 is the Excel OADate for 1/1/2017. var func = new Yearfrac(); var args = FunctionsHelper.CreateArgs(42736, "-1.5"); var result = func.Execute(args, this.ParsingContext); Assert.AreEqual(eErrorType.Num, ((ExcelErrorValue)result.Result).Type); }
public void YearFracWithNonNumericStringAsSecondParameterReturnsPoundValue() { // Note that 42736 is the Excel OADate for 1/1/2017. var func = new Yearfrac(); var args = FunctionsHelper.CreateArgs(42736, "word"); var result = func.Execute(args, this.ParsingContext); Assert.AreEqual(eErrorType.Value, ((ExcelErrorValue)result.Result).Type); }
public void YearFracWithBasisIntegerInStringReturnsCorrectResult() { var date1 = new DateTime(2017, 1, 1); var date2 = new DateTime(2017, 5, 23); var func = new Yearfrac(); var args = FunctionsHelper.CreateArgs(date1.ToOADate(), date2.ToOADate(), "1"); var result = func.Execute(args, this.ParsingContext); Assert.AreEqual(0.38904109589, result.Result); }
public void YearFracWithDateAsZeroReturnsCorrectResult() { // Note that 42878 is the Excel OADate for 5/23/2017. // 0 is the Excel OADate for 1/0/1900, which Excel treats as a special date. var func = new Yearfrac(); var args = FunctionsHelper.CreateArgs(0, 42878); var result = func.Execute(args, this.ParsingContext); Assert.AreEqual(117.39722222222, result.Result); }
public void YearFracWithNegativeBasisNumberReturnsPoundNum() { var date1 = new DateTime(2017, 1, 1); var date2 = new DateTime(2017, 5, 23); var func = new Yearfrac(); var args = FunctionsHelper.CreateArgs(date1.ToOADate(), date2.ToOADate(), -1); var result = func.Execute(args, this.ParsingContext); Assert.AreEqual(eErrorType.Num, ((ExcelErrorValue)result.Result).Type); }
public void YearFracWithDateAsDoubleReturnsCorrectResult() { var date1 = new DateTime(2017, 1, 1); var date2 = new DateTime(2017, 5, 23); var func = new Yearfrac(); var args = FunctionsHelper.CreateArgs(date1.ToOADate(), date2.ToOADate()); var result = func.Execute(args, this.ParsingContext); Assert.AreEqual(0.39444444444, result.Result); }
public double GetYearFrac(System.DateTime date1, System.DateTime date2, DayCountBasis basis) { var func = new Yearfrac(); var args = new List <FunctionArgument> { new FunctionArgument(date1.ToOADate()), new FunctionArgument(date2.ToOADate()), new FunctionArgument((int)basis) }; var result = func.Execute(args, _context); return(result.ResultNumeric); }
public void YearFracWithDateTimeObjectInputWith1March1900BetweenReturnsCorrectResult() { var date1 = new DateTime(1900, 1, 31); var date2 = new DateTime(2017, 1, 1); var func = new Yearfrac(); var args = FunctionsHelper.CreateArgs(date1, date2); var result = func.Execute(args, this.ParsingContext); Assert.AreEqual(116.91944444444, result.Result); }
public void YearFracWithDateTimeObjectInputBefore1March1900ReturnsCorrectResult() { var date1 = new DateTime(1900, 1, 31); var date2 = new DateTime(1900, 2, 28); var func = new Yearfrac(); var args = FunctionsHelper.CreateArgs(date1, date2); var result = func.Execute(args, this.ParsingContext); Assert.AreEqual(0.07777777778, result.Result); }
public void YearFracWithBasisAsEmptyStringReturnsPoundValue() { var date1 = new DateTime(2017, 1, 1); var date2 = new DateTime(2017, 5, 23); var func = new Yearfrac(); var args = FunctionsHelper.CreateArgs(date1.ToOADate(), date2.ToOADate(), string.Empty); var result = func.Execute(args, this.ParsingContext); Assert.AreEqual(eErrorType.Value, ((ExcelErrorValue)result.Result).Type); }
public void YearFracWithBasisAsNonEnumeratedNumberReturnsPoundNum() { // Note that the YEARFRAC function in Excel only accepts 0-4 as valid numbers for the basis parameter. var date1 = new DateTime(2017, 1, 1); var date2 = new DateTime(2017, 5, 23); var func = new Yearfrac(); var args = FunctionsHelper.CreateArgs(date1.ToOADate(), date2.ToOADate(), 5); var result = func.Execute(args, this.ParsingContext); Assert.AreEqual(eErrorType.Num, ((ExcelErrorValue)result.Result).Type); }
public void YearFracActualActual() { var func = new Yearfrac(); var dt1arg = new DateTime(2012, 2, 28).ToOADate(); var dt2arg = new DateTime(2013, 3, 31).ToOADate(); var result = func.Execute(FunctionsHelper.CreateArgs(dt1arg, dt2arg, 1), _parsingContext); var roundedResult = Math.Round((double)result.Result, 4); Assert.IsTrue(Math.Abs(1.0862 - roundedResult) < double.Epsilon); }
public void YearFracShouldReturnCorrectResultWithEuroBasis() { var func = new Yearfrac(); var dt1arg = new DateTime(2013, 2, 28).ToOADate(); var dt2arg = new DateTime(2013, 3, 31).ToOADate(); var result = func.Execute(FunctionsHelper.CreateArgs(dt1arg, dt2arg, 4), _parsingContext); var roundedResult = Math.Round((double)result.Result, 4); Assert.IsTrue(Math.Abs(0.0889 - roundedResult) < double.Epsilon); }
public void YearfracFunctionWithErrorValuesAsInputReturnsTheInputErrorValue() { var func = new Yearfrac(); var argNA = FunctionsHelper.CreateArgs(ExcelErrorValue.Create(eErrorType.NA), 33); var argNAME = FunctionsHelper.CreateArgs(ExcelErrorValue.Create(eErrorType.Name), 33); var argVALUE = FunctionsHelper.CreateArgs(ExcelErrorValue.Create(eErrorType.Value), 33); var argNUM = FunctionsHelper.CreateArgs(ExcelErrorValue.Create(eErrorType.Num), 33); var argDIV0 = FunctionsHelper.CreateArgs(ExcelErrorValue.Create(eErrorType.Div0), 33); var argREF = FunctionsHelper.CreateArgs(ExcelErrorValue.Create(eErrorType.Ref), 33); var resultNA = func.Execute(argNA, this.ParsingContext); var resultNAME = func.Execute(argNAME, this.ParsingContext); var resultVALUE = func.Execute(argVALUE, this.ParsingContext); var resultNUM = func.Execute(argNUM, this.ParsingContext); var resultDIV0 = func.Execute(argDIV0, this.ParsingContext); var resultREF = func.Execute(argREF, this.ParsingContext); Assert.AreEqual(eErrorType.NA, ((ExcelErrorValue)resultNA.Result).Type); Assert.AreEqual(eErrorType.Name, ((ExcelErrorValue)resultNAME.Result).Type); Assert.AreEqual(eErrorType.Value, ((ExcelErrorValue)resultVALUE.Result).Type); Assert.AreEqual(eErrorType.Num, ((ExcelErrorValue)resultNUM.Result).Type); Assert.AreEqual(eErrorType.Div0, ((ExcelErrorValue)resultDIV0.Result).Type); Assert.AreEqual(eErrorType.Ref, ((ExcelErrorValue)resultREF.Result).Type); }