/* * (c) Copyright Ascensio System SIA 2010-2024 * * This program is a free software product. You can redistribute it and/or * modify it under the terms of the GNU Affero General Public License (AGPL) * version 3 as published by the Free Software Foundation. In accordance with * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect * that Ascensio System SIA expressly excludes the warranty of non-infringement * of any third-party rights. * * This program is distributed WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html * * You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish * street, Riga, Latvia, EU, LV-1050. * * The interactive user interfaces in modified source and object code versions * of the Program must display Appropriate Legal Notices, as required under * Section 5 of the GNU AGPL version 3. * * Pursuant to Section 7(b) of the License you must retain the original Product * logo when distributing the program. Pursuant to Section 7(e) we decline to * grant you any rights under trademark law for use of our trademarks. * * All the Product's GUI elements, including illustrations and icon sets, as * well as technical writing content are licensed under the terms of the * Creative Commons Attribution-ShareAlike 4.0 International. See the License * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode * */ $(function () { var cDate = Asc.cDate; function toFixed(n) { return n;//.toFixed( AscCommonExcel.cExcelSignificantDigits ) - 0; } function difBetween(a, b) { return Math.abs(a - b) < dif } function _getPMT(fZins, fZzr, fBw, fZw, nF) { var fRmz; if (fZins == 0.0) { fRmz = (fBw + fZw) / fZzr; } else { var fTerm = Math.pow(1.0 + fZins, fZzr); if (nF > 0) { fRmz = (fZw * fZins / (fTerm - 1.0) + fBw * fZins / (1.0 - 1.0 / fTerm)) / (1.0 + fZins); } else { fRmz = fZw * fZins / (fTerm - 1.0) + fBw * fZins / (1.0 - 1.0 / fTerm); } } return -fRmz; } function _getFV(fZins, fZzr, fRmz, fBw, nF) { var fZw; if (fZins == 0.0) { fZw = fBw + fRmz * fZzr; } else { var fTerm = Math.pow(1.0 + fZins, fZzr); if (nF > 0) { fZw = fBw * fTerm + fRmz * (1.0 + fZins) * (fTerm - 1.0) / fZins; } else { fZw = fBw * fTerm + fRmz * (fTerm - 1.0) / fZins; } } return -fZw; } function _getDDB(cost, salvage, life, period, factor) { var ddb, ipmt, oldCost, newCost; ipmt = factor / life; if (ipmt >= 1) { ipmt = 1; if (period == 1) { oldCost = cost; } else { oldCost = 0; } } else { oldCost = cost * Math.pow(1 - ipmt, period - 1); } newCost = cost * Math.pow(1 - ipmt, period); if (newCost < salvage) { ddb = oldCost - salvage; } else { ddb = oldCost - newCost; } if (ddb < 0) { ddb = 0; } return ddb; } function _getIPMT(rate, per, pv, type, pmt) { var ipmt; if (per == 1) { if (type > 0) { ipmt = 0; } else { ipmt = -pv; } } else { if (type > 0) { ipmt = _getFV(rate, per - 2, pmt, pv, 1) - pmt; } else { ipmt = _getFV(rate, per - 1, pmt, pv, 0); } } return ipmt * rate } function _diffDate(d1, d2, mode) { var date1 = d1.getDate(), month1 = d1.getMonth(), year1 = d1.getFullYear(), date2 = d2.getDate(), month2 = d2.getMonth(), year2 = d2.getFullYear(); switch (mode) { case 0: return Math.abs(GetDiffDate360(date1, month1, year1, date2, month2, year2, true)); case 1: var yc = Math.abs(year2 - year1), sd = year1 > year2 ? d2 : d1, yearAverage = sd.isLeapYear() ? 366 : 365, dayDiff = Math.abs(d2 - d1); for (var i = 0; i < yc; i++) { sd.addYears(1); yearAverage += sd.isLeapYear() ? 366 : 365; } yearAverage /= (yc + 1); dayDiff /= c_msPerDay; return dayDiff; case 2: var dayDiff = Math.abs(d2 - d1); dayDiff /= c_msPerDay; return dayDiff; case 3: var dayDiff = Math.abs(d2 - d1); dayDiff /= c_msPerDay; return dayDiff; case 4: return Math.abs(GetDiffDate360(date1, month1, year1, date2, month2, year2, false)); default: return "#NUM!"; } } function _yearFrac(d1, d2, mode) { var date1 = d1.getDate(), month1 = d1.getMonth() + 1, year1 = d1.getFullYear(), date2 = d2.getDate(), month2 = d2.getMonth() + 1, year2 = d2.getFullYear(); switch (mode) { case 0: return Math.abs(GetDiffDate360(date1, month1, year1, date2, month2, year2, true)) / 360; case 1: var yc = /*Math.abs*/(year2 - year1), sd = year1 > year2 ? new cDate(d2) : new cDate(d1), yearAverage = sd.isLeapYear() ? 366 : 365, dayDiff = /*Math.abs*/(d2 - d1); for (var i = 0; i < yc; i++) { sd.addYears(1); yearAverage += sd.isLeapYear() ? 366 : 365; } yearAverage /= (yc + 1); dayDiff /= (yearAverage * c_msPerDay); return dayDiff; case 2: var dayDiff = Math.abs(d2 - d1); dayDiff /= (360 * c_msPerDay); return dayDiff; case 3: var dayDiff = Math.abs(d2 - d1); dayDiff /= (365 * c_msPerDay); return dayDiff; case 4: return Math.abs(GetDiffDate360(date1, month1, year1, date2, month2, year2, false)) / 360; default: return "#NUM!"; } } function _lcl_GetCouppcd(settl, matur, freq) { matur.setFullYear(settl.getFullYear()); if (matur < settl) { matur.addYears(1); } while (matur > settl) { matur.addMonths(-12 / freq); } } function _lcl_GetCoupncd(settl, matur, freq) { matur.setFullYear(settl.getFullYear()); if (matur > settl) { matur.addYears(-1); } while (matur <= settl) { matur.addMonths(12 / freq); } } function _getcoupdaybs(settl, matur, frequency, basis) { _lcl_GetCouppcd(settl, matur, frequency); return _diffDate(settl, matur, basis); } function _getcoupdays(settl, matur, frequency, basis) { _lcl_GetCouppcd(settl, matur, frequency); var n = new cDate(matur); n.addMonths(12 / frequency); return _diffDate(matur, n, basis); } function _getdiffdate(d1, d2, nMode) { var bNeg = d1 > d2; if (bNeg) { var n = d2; d2 = d1; d1 = n; } var nRet, pOptDaysIn1stYear; var nD1 = d1.getDate(), nM1 = d1.getMonth(), nY1 = d1.getFullYear(), nD2 = d2.getDate(), nM2 = d2.getMonth(), nY2 = d2.getFullYear(); switch (nMode) { case 0: // 0=USA (NASD) 30/360 case 4: // 4=Europe 30/360 { var bLeap = d1.isLeapYear(); var nDays, nMonths/*, nYears*/; nMonths = nM2 - nM1; nDays = nD2 - nD1; nMonths += (nY2 - nY1) * 12; nRet = nMonths * 30 + nDays; if (nMode == 0 && nM1 == 2 && nM2 != 2 && nY1 == nY2) { nRet -= bLeap ? 1 : 2; } pOptDaysIn1stYear = 360; } break; case 1: // 1=exact/exact pOptDaysIn1stYear = d1.isLeapYear() ? 366 : 365; nRet = d2 - d1; break; case 2: // 2=exact/360 nRet = d2 - d1; pOptDaysIn1stYear = 360; break; case 3: //3=exact/365 nRet = d2 - d1; pOptDaysIn1stYear = 365; break; } return (bNeg ? -nRet : nRet) / c_msPerDay / pOptDaysIn1stYear; } function _getprice(nSettle, nMat, fRate, fYield, fRedemp, nFreq, nBase) { var fdays = AscCommonExcel.getcoupdays(new cDate(nSettle), new cDate(nMat), nFreq, nBase), fdaybs = AscCommonExcel.getcoupdaybs(new cDate(nSettle), new cDate(nMat), nFreq, nBase), fnum = AscCommonExcel.getcoupnum(new cDate(nSettle), (nMat), nFreq, nBase), fdaysnc = (fdays - fdaybs) / fdays, fT1 = 100 * fRate / nFreq, fT2 = 1 + fYield / nFreq, res = fRedemp / (Math.pow(1 + fYield / nFreq, fnum - 1 + fdaysnc)); /*var fRet = fRedemp / ( Math.pow( 1.0 + fYield / nFreq, fnum - 1.0 + fdaysnc ) ); fRet -= 100.0 * fRate / nFreq * fdaybs / fdays; var fT1 = 100.0 * fRate / nFreq; var fT2 = 1.0 + fYield / nFreq; for( var fK = 0.0 ; fK < fnum ; fK++ ){ fRet += fT1 / Math.pow( fT2, fK + fdaysnc ); } return fRet;*/ if (fnum == 1) { return (fRedemp + fT1) / (1 + fdaysnc * fYield / nFreq) - 100 * fRate / nFreq * fdaybs / fdays; } res -= 100 * fRate / nFreq * fdaybs / fdays; for (var i = 0; i < fnum; i++) { res += fT1 / Math.pow(fT2, i + fdaysnc); } return res; } function _getYield(nSettle, nMat, fCoup, fPrice, fRedemp, nFreq, nBase) { var fRate = fCoup, fPriceN = 0.0, fYield1 = 0.0, fYield2 = 1.0; var fPrice1 = _getprice(nSettle, nMat, fRate, fYield1, fRedemp, nFreq, nBase); var fPrice2 = _getprice(nSettle, nMat, fRate, fYield2, fRedemp, nFreq, nBase); var fYieldN = (fYield2 - fYield1) * 0.5; for (var nIter = 0; nIter < 100 && fPriceN != fPrice; nIter++) { fPriceN = _getprice(nSettle, nMat, fRate, fYieldN, fRedemp, nFreq, nBase); if (fPrice == fPrice1) { return fYield1; } else if (fPrice == fPrice2) { return fYield2; } else if (fPrice == fPriceN) { return fYieldN; } else if (fPrice < fPrice2) { fYield2 *= 2.0; fPrice2 = _getprice(nSettle, nMat, fRate, fYield2, fRedemp, nFreq, nBase); fYieldN = (fYield2 - fYield1) * 0.5; } else { if (fPrice < fPriceN) { fYield1 = fYieldN; fPrice1 = fPriceN; } else { fYield2 = fYieldN; fPrice2 = fPriceN; } fYieldN = fYield2 - (fYield2 - fYield1) * ((fPrice - fPrice2) / (fPrice1 - fPrice2)); } } if (Math.abs(fPrice - fPriceN) > fPrice / 100.0) { return "#NUM!"; } // result not precise enough return fYieldN; } function _getyieldmat(nSettle, nMat, nIssue, fRate, fPrice, nBase) { var fIssMat = _yearFrac(nIssue, nMat, nBase); var fIssSet = _yearFrac(nIssue, nSettle, nBase); var fSetMat = _yearFrac(nSettle, nMat, nBase); var y = 1.0 + fIssMat * fRate; y /= fPrice / 100.0 + fIssSet * fRate; y--; y /= fSetMat; return y; } function _coupnum(settlement, maturity, frequency, basis) { basis = (basis !== undefined ? basis : 0); var n = new cDate(maturity); _lcl_GetCouppcd(settlement, n, frequency); var nMonths = (maturity.getFullYear() - n.getFullYear()) * 12 + maturity.getMonth() - n.getMonth(); return nMonths * frequency / 12; } function _duration(settlement, maturity, coupon, yld, frequency, basis) { var dbc = AscCommonExcel.getcoupdaybs(new cDate(settlement), new cDate(maturity), frequency, basis), coupD = AscCommonExcel.getcoupdays(new cDate(settlement), new cDate(maturity), frequency, basis), numCoup = AscCommonExcel.getcoupnum(new cDate(settlement), new cDate(maturity), frequency); if (settlement >= maturity || basis < 0 || basis > 4 || (frequency != 1 && frequency != 2 && frequency != 4) || yld < 0 || coupon < 0) { return "#NUM!"; } var duration = 0, p = 0; var dsc = coupD - dbc; var diff = dsc / coupD - 1; yld = yld / frequency + 1; coupon *= 100 / frequency; for (var index = 1; index <= numCoup; index++) { var di = index + diff; var yldPOW = Math.pow(yld, di); duration += di * coupon / yldPOW; p += coupon / yldPOW; } duration += (diff + numCoup) * 100 / Math.pow(yld, diff + numCoup); p += 100 / Math.pow(yld, diff + numCoup); return duration / p / frequency; } function numDivFact(num, fact) { var res = num / Math.fact(fact); res = res.toString(); return res; } function testArrayFormula(assert, func, dNotSupportAreaArg) { var getValue = function (ref) { oParser = new parserFormula(func + "(" + ref + ")", "A2", ws); assert.ok(oParser.parse()); return oParser.calculate().getValue(); }; //***array-formula*** ws.getRange2("A100").setValue("1"); ws.getRange2("B100").setValue("3"); ws.getRange2("C100").setValue("-4"); ws.getRange2("A101").setValue("2"); ws.getRange2("B101").setValue("4"); ws.getRange2("C101").setValue("5"); oParser = new parserFormula(func + "(A100:C101)", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:H107").bbox); assert.ok(oParser.parse()); var array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), getValue("A100")); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), getValue("B100")); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), getValue("C100")); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), getValue("A101")); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), getValue("B101")); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), getValue("C101")); } else { if (!dNotSupportAreaArg) { assert.strictEqual(false, true); } consoleLog("func: " + func + " don't return area array"); } oParser = new parserFormula(func + "({1,2,-3})", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:H107").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), getValue(1)); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), getValue(2)); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), getValue(-3)); } //returnOnlyValue - те функции, на вход которых всегда должны подаваться массивы и которые возвращают единственное значение function testArrayFormula2(assert, func, minArgCount, maxArgCount, dNotSupportAreaArg, returnOnlyValue) { var getValue = function (ref, countArg) { var argStr = "("; for (var j = 1; j <= countArg; j++) { argStr += ref; if (i !== j) { argStr += ","; } else { argStr += ")"; } } oParser = new parserFormula(func + argStr, "A2", ws); assert.ok(oParser.parse()); return oParser.calculate().getValue(); }; //***array-formula*** ws.getRange2("A100").setValue("1"); ws.getRange2("B100").setValue("3"); ws.getRange2("C100").setValue("-4"); ws.getRange2("A101").setValue("2"); ws.getRange2("B101").setValue("4"); ws.getRange2("C101").setValue("5"); //формируем массив значений var randomArray = []; var randomStrArray = "{"; var maxArg = 4; for (var i = 1; i <= maxArg; i++) { var randVal = Math.random(); randomArray.push(randVal); randomStrArray += randVal; if (i !== maxArg) { randomStrArray += ","; } else { randomStrArray += "}"; } } for (var i = minArgCount; i <= maxArgCount; i++) { var argStrArr = "("; var randomArgStrArr = "("; for (var j = 1; j <= i; j++) { argStrArr += "A100:C101"; randomArgStrArr += randomStrArray; if (i !== j) { argStrArr += ","; randomArgStrArr += ","; } else { argStrArr += ")"; randomArgStrArr += ")"; } } oParser = new parserFormula(func + argStrArr, "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:H107").bbox); assert.ok(oParser.parse()); var array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), getValue("A100", i)); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), getValue("B100", i)); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), getValue("C100", i)); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), getValue("A101", i)); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), getValue("B101", i)); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), getValue("C101", i)); } else { if (!(dNotSupportAreaArg || returnOnlyValue)) { assert.strictEqual(false, true); } consoleLog("func: " + func + " don't return area array"); } oParser = new parserFormula(func + randomArgStrArr, "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:H107").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), getValue(randomArray[0], i)); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), getValue(randomArray[1], i)); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), getValue(randomArray[2], i)); } else { if (!returnOnlyValue) { assert.strictEqual(false, true); } consoleLog("func: " + func + " don't return array"); } } } function testArrayFormulaEqualsValues(assert, str, formula, isNotLowerCase) { //***array-formula*** ws.getRange2("A1").setValue("1"); ws.getRange2("B1").setValue("3.123"); ws.getRange2("C1").setValue("-4"); ws.getRange2("A2").setValue("2"); ws.getRange2("B2").setValue("4"); ws.getRange2("C2").setValue("5"); oParser = new parserFormula(formula, "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E6:H8").bbox); assert.ok(oParser.parse()); var array = oParser.calculate(); var splitStr = str.split(";"); for (var i = 0; i < splitStr.length; i++) { var subSplitStr = splitStr[i].split(","); for (var j = 0; j < subSplitStr.length; j++) { var valMs = subSplitStr[j]; var element; if (array.getElementRowCol) { var row = 1 === array.array.length ? 0 : i; var col = 1 === array.array[0].length ? 0 : j; if (array.array[row] && array.array[row][col]) { element = array.getElementRowCol(row, col); } else { element = new window['AscCommonExcel'].cError(window['AscCommonExcel'].cErrorType.not_available); } } else { element = array; } var ourVal = element && undefined != element.value ? element.value.toString() : "#N/A"; if (!isNotLowerCase) { valMs = valMs.toLowerCase(); ourVal = ourVal.toLowerCase(); } assert.strictEqual(valMs, ourVal, "formula: " + formula + " i: " + i + " j: " + j) } } } function _getValue(from, row, col) { var res; if (from.type === AscCommonExcel.cElementType.array) { res = from.getElementRowCol(row !== undefined ? row : 0, col !== undefined ? col : 0).getValue(); } else if (from.type === AscCommonExcel.cElementType.cellsRange || from.type === AscCommonExcel.cElementType.cellsRange3D) { res = from.getValueByRowCol(row !== undefined ? row : 0, col !== undefined ? col : 0).getValue(); } else if (from.type === AscCommonExcel.cElementType.cell || from.type === AscCommonExcel.cElementType.cell3D) { res = from.getValue().getValue(); } else { res = from.getValue(); } return res; } function consoleLog(val) { //console.log(val); } var newFormulaParser = false; var c_msPerDay = AscCommonExcel.c_msPerDay; var parserFormula = AscCommonExcel.parserFormula; var GetDiffDate360 = AscCommonExcel.GetDiffDate360; var fSortAscending = AscCommon.fSortAscending; var g_oIdCounter = AscCommon.g_oIdCounter; var oParser, wb, ws, dif = 1e-9, sData = AscCommon.getEmpty(), tmp, array; if (AscCommon.c_oSerFormat.Signature === sData.substring(0, AscCommon.c_oSerFormat.Signature.length)) { Asc.spreadsheet_api.prototype._init = function() { this.isLoadFullApi = true; }; let api = new Asc.spreadsheet_api({ 'id-view': 'editor_sdk' }); api.FontLoader = { LoadDocumentFonts: function () { } }; let docInfo = new Asc.asc_CDocInfo(); docInfo.asc_putTitle("TeSt.xlsx"); api.DocInfo = docInfo; window["Asc"]["editor"] = api; AscCommon.g_oTableId.init(api); wb = new AscCommonExcel.Workbook(new AscCommonExcel.asc_CHandlersList(), api, true); AscCommon.History.init(wb); //нет тестовых операция с историей, отключаем чтобы не было лишних сериализаций AscCommon.History.TurnOff(); wb.maxDigitWidth = 7; wb.paddingPlusBorder = 5; api.wbModel = wb; api.initCollaborativeEditing({}); if (this.User) { g_oIdCounter.Set_UserId(this.User.asc_getId()); } AscCommonExcel.g_oUndoRedoCell = new AscCommonExcel.UndoRedoCell(wb); AscCommonExcel.g_oUndoRedoWorksheet = new AscCommonExcel.UndoRedoWoorksheet(wb); AscCommonExcel.g_oUndoRedoWorkbook = new AscCommonExcel.UndoRedoWorkbook(wb); AscCommonExcel.g_oUndoRedoCol = new AscCommonExcel.UndoRedoRowCol(wb, false); AscCommonExcel.g_oUndoRedoRow = new AscCommonExcel.UndoRedoRowCol(wb, true); AscCommonExcel.g_oUndoRedoComment = new AscCommonExcel.UndoRedoComment(wb); AscCommonExcel.g_oUndoRedoAutoFilters = new AscCommonExcel.UndoRedoAutoFilters(wb); AscCommonExcel.g_DefNameWorksheet = new AscCommonExcel.Worksheet(wb, -1); g_oIdCounter.Set_Load(false); var oBinaryFileReader = new AscCommonExcel.BinaryFileReader(); oBinaryFileReader.Read(sData, wb); ws = wb.getWorksheet(wb.getActive()); AscCommonExcel.getFormulasInfo(); } wb.dependencyFormulas.lockRecal(); QUnit.module("Formula"); QUnit.test('Iterative calculation', function (assert) { const g_cCalcRecursion = AscCommonExcel.g_cCalcRecursion; g_cCalcRecursion.initCalcProperties(wb.calcPr); g_cCalcRecursion.setIsEnabledRecursion(true); g_cCalcRecursion.setMaxIterations(10); let nExpectedCellIndex, oFactCellIndex, oCell, bCaFromSelectedCell; // Init necessary functions const selectCell = function (sRange, oWs) { let oSelectCell = oWs ? oWs.getRange2(sRange) : ws.getRange2(sRange); let oCell = null; oSelectCell._foreach2(function (cell) { oCell = cell; }) return oCell; }; const getStartCellForIterCalc = function (oCell) { oCell.initStartCellForIterCalc(); return g_cCalcRecursion.getStartCellIndex(); }; const getCaFromSelectedCell = function (sRange, oWs) { const oSelectedCell = selectCell(sRange, oWs); const oSelectedCellFormula = oSelectedCell.getFormulaParsed(); return oSelectedCellFormula.ca; }; // -- Check recursion formula with iteration limit // - Case: Sequence chain - A1000: A1000+B1000 -> B1000: B1000+C1000 -> C1: 1 // Fill cells ws.getRange2("A1000").setValue("=A1000+B1000"); ws.getRange2("B1000").setValue("=B1000+C1000"); ws.getRange2("C1000").setValue("1"); assert.strictEqual(ws.getRange2("A1000").getValue(), "45", "Test: Sequence chain = A1000: A1000+B1000, B1000: B1000+C1000, C1000: 1. A1000 - 45"); assert.strictEqual(ws.getRange2("B1000").getValue(), "10", "Test: Sequence chain = A1000: A1000+B1000, B1000: B1000+C1000, C1000: 1. B1000 - 10"); // Check work isFormulaRecursive function bCaFromSelectedCell = getCaFromSelectedCell("A1000"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain = A1000: A1000+B1000, B1000: B1000+C1000, C1000: 1. isFormulaRecursion test. A1000 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("B1000"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain = A1000: A1000+B1000, B1000: B1000+C1000, C1000: 1. isFormulaRecursion test. B1000 - flag ca: true"); bCaFromSelectedCell = null; // - Case: Loop chain - D1000: F1000/E1000 <-> F1000: E1000+D1000 ws.getRange2("E1000").setValue("1"); ws.getRange2("D1000").setValue("=F1000/E1000"); ws.getRange2("F1000").setValue("=E1000+D1000"); assert.strictEqual(ws.getRange2("D1000").getValue(), "9", "Test: Loop chain - D1000: F1000/E1000 <-> F1000: E1000+D1000. D1000 - 9"); assert.strictEqual(ws.getRange2("F1000").getValue(), "10", "Test: Loop chain - D1000: F1000/E1000 <-> F1000: E1000+D1000. F1000 - 10"); // Check work isFormulaRecursive function bCaFromSelectedCell = getCaFromSelectedCell("D1000"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Loop chain - D1000: F1000/E1000 <-> F1000: E1000+D1000. isFormulaRecursion test. D1000 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("F1000"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Loop chain - D1000: F1000/E1000 <-> F1000: E1000+D1000. isFormulaRecursion test. F1000 - flag ca: true"); bCaFromSelectedCell = null; // - Case: 3D Loop chain - D1001: Sheet2!A1000/E1001 <-> Sheet2!A1000: Sheet1!D1001+Sheet1!E1001 let ws2 = wb.createWorksheet(0, "Sheet2"); ws.getRange2("E1001").setValue("1"); ws.getRange2("D1001").setValue("=Sheet2!D1001/E1001"); ws2.getRange2("D1001").setValue("=Sheet1!D1001+Sheet1!E1001"); assert.strictEqual(ws.getRange2("D1001").getValue(), "9", "Test: 3D Loop chain - D1001: Sheet2!A1000/E1001 <-> Sheet2!A1000: Sheet1!D1001+Sheet1!E1001. D1001 - 9"); assert.strictEqual(ws2.getRange2("D1001").getValue(), "10", "Test: 3D Loop chain - D1001: Sheet2!A1000/E1001 <-> Sheet2!A1000: Sheet1!D1001+Sheet1!E1001. Sheet2!A1000 - 10"); // Check work isFormulaRecursive function bCaFromSelectedCell = getCaFromSelectedCell("D1001"); assert.strictEqual(bCaFromSelectedCell, true, "Test: 3D Loop chain - D1001: Sheet2!A1000/E1001 <-> Sheet2!A1000: Sheet1!D1001+Sheet1!E1001. isFormulaRecursion test. D1001 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("D1001", ws2); assert.strictEqual(bCaFromSelectedCell, true, "Test: 3D Loop chain - D1001: Sheet2!A1000/E1001 <-> Sheet2!A1000: Sheet1!D1001+Sheet1!E1001. isFormulaRecursion test. Sheet2!A1000 - flag ca: true"); bCaFromSelectedCell = null; // - Case: Loop cell - A1001: A1001+1 ws.getRange2("A1001").setValue("=A1001+1"); assert.strictEqual(ws.getRange2("A1001").getValue(), "10", "Test: Loop cell - A1001: A1001+1. A1001 - 10"); // Check work isFormulaRecursive function bCaFromSelectedCell = getCaFromSelectedCell("A1001"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Loop cell - A1001: A1001+1. isFormulaRecursion test. A1001 - flag ca: true"); bCaFromSelectedCell = null; // - Negative case sequence chain without loop cell. ws.getRange2("A1002").setValue("=1+B1002"); ws.getRange2("B1002").setValue("=1+C1002"); ws.getRange2("C1002").setValue("1"); assert.strictEqual(ws.getRange2("A1002").getValue(), "3", "Test: Negative case sequence chain without loop cell - A1002: 1+B1002. A1002 - 3"); assert.strictEqual(ws.getRange2("B1002").getValue(), "2", "Test: Negative case sequence chain without loop cell - B1002: 1+C1002. B1002 - 2"); assert.strictEqual(ws.getRange2("C1002").getValue(), "1", "Test: Negative case sequence chain without loop cell - C1002: 1. C1002 - 1"); // Check work isFormulaRecursive function bCaFromSelectedCell = getCaFromSelectedCell("A1002"); assert.strictEqual(bCaFromSelectedCell, false, "Test: Negative case sequence chain without loop cell - A1002: 1+B1002. isFormulaRecursion test. A1002 - flag ca: false"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("B1002"); assert.strictEqual(bCaFromSelectedCell, false, "Test: Negative case sequence chain without loop cell - A1002: 1+B1002. isFormulaRecursion test. B1002 - flag ca: false"); bCaFromSelectedCell = null; // - Negative case cell without any chain. ws.getRange2("A1003").setValue("=1+2"); assert.strictEqual(ws.getRange2("A1003").getValue(), "3", "Test: Negative case cell without any chain - A1003: 1+2. A1003 - 3"); // Check work isFormulaRecursive function bCaFromSelectedCell = getCaFromSelectedCell("A1003"); assert.strictEqual(bCaFromSelectedCell, false, "Test: Negative case cell without any chain - A1003: 1+2. isFormulaRecursion test. A1003 - flag ca: false"); bCaFromSelectedCell = null; ws.getRange2("A1004").setValue("1"); ws.getRange2("B1004").setValue("2"); ws.getRange2("C1004").setValue("=A1004+B1004"); assert.strictEqual(ws.getRange2("C1004").getValue(), "3", "Test: Negative case cell without any chain - C1004: A1004+B1004. C1004 - 3"); // Check work isFormulaRecursive function bCaFromSelectedCell = getCaFromSelectedCell("C1004"); assert.strictEqual(bCaFromSelectedCell, false, "Test: Negative case cell without any chain - C1004: A1004+B1004. isFormulaRecursion test. C1004 - flag ca: false"); bCaFromSelectedCell = null; // - Case: Sequence chain - A1005: A1005+B1005, B1005: 1. Deep level of recursion - 0 ws.getRange2("A1005").setValue("=A1005+B1005"); ws.getRange2("B1005").setValue("1"); assert.strictEqual(ws.getRange2("A1005").getValue(), "10", "Test: Sequence chain - A1005: A1005+B1005, B1005: 1"); // Check work isFormulaRecursive function bCaFromSelectedCell = getCaFromSelectedCell("A1005"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1005: A1005+B1005, B1005: 1. isFormulaRecursion test. A1005 - flag ca: true"); bCaFromSelectedCell = null; // - Case: Sequence chain - A1006: A1006+B1006, B1006: B1006+C1006, C1006: C1006+D1006 ... J1006: 1. Deep level of recursion - 10, Max iteration 10 ws.getRange2("A1006").setValue("=A1006+B1006"); ws.getRange2("B1006").setValue("=B1006+C1006"); ws.getRange2("C1006").setValue("=C1006+D1006"); ws.getRange2("D1006").setValue("=D1006+E1006"); ws.getRange2("E1006").setValue("=E1006+F1006"); ws.getRange2("F1006").setValue("=F1006+G1006"); ws.getRange2("G1006").setValue("=G1006+H1006"); ws.getRange2("H1006").setValue("=H1006+I1006"); ws.getRange2("I1006").setValue("=I1006+J1006"); ws.getRange2("J1006").setValue("1"); assert.strictEqual(ws.getRange2("A1006").getValue(), "10", "Test: Sequence chain - A1006: A1006+B1006, B1006: B1006+C1006, C1006: C1006+D1006 ... J1006: 1. A1006 - 10"); assert.strictEqual(ws.getRange2("B1006").getValue(), "45", "Test: Sequence chain - A1006: A1006+B1006, B1006: B1006+C1006, C1006: C1006+D1006 ... J1006: 1. B1006 - 45"); assert.strictEqual(ws.getRange2("C1006").getValue(), "120", "Test: Sequence chain - A1006: A1006+B1006, B1006: B1006+C1006, C1006: C1006+D1006 ... J1006: 1. C1006 - 120"); assert.strictEqual(ws.getRange2("D1006").getValue(), "210", "Test: Sequence chain - A1006: A1006+B1006, B1006: B1006+C1006, C1006: C1006+D1006 ... J1006: 1. D1006 - 210"); assert.strictEqual(ws.getRange2("E1006").getValue(), "252", "Test: Sequence chain - A1006: A1006+B1006, B1006: B1006+C1006, C1006: C1006+D1006 ... J1006: 1. E1006 - 252"); assert.strictEqual(ws.getRange2("F1006").getValue(), "210", "Test: Sequence chain - A1006: A1006+B1006, B1006: B1006+C1006, C1006: C1006+D1006 ... J1006: 1. F1006 - 210"); assert.strictEqual(ws.getRange2("G1006").getValue(), "120", "Test: Sequence chain - A1006: A1006+B1006, B1006: B1006+C1006, C1006: C1006+D1006 ... J1006: 1. G1006 - 120"); assert.strictEqual(ws.getRange2("H1006").getValue(), "45", "Test: Sequence chain - A1006: A1006+B1006, B1006: B1006+C1006, C1006: C1006+D1006 ... J1006: 1. H1006 - 45"); assert.strictEqual(ws.getRange2("I1006").getValue(), "10", "Test: Sequence chain - A1006: A1006+B1006, B1006: B1006+C1006, C1006: C1006+D1006 ... J1006: 1. I1006 - 10"); // Check work isFormulaRecursive function bCaFromSelectedCell = getCaFromSelectedCell("A1006"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1006: A1006+B1006, B1006: B1006+C1006, C1006: C1006+D1006 ... J1006: 1. isFormulaRecursion test. A1006 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("B1006"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1006: A1006+B1006, B1006: B1006+C1006, C1006: C1006+D1006 ... J1006: 1. isFormulaRecursion test. B1006 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("C1006"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1006: A1006+B1006, B1006: B1006+C1006, C1006: C1006+D1006 ... J1006: 1. isFormulaRecursion test. C1006 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("D1006"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1006: A1006+B1006, B1006: B1006+C1006, C1006: C1006+D1006 ... J1006: 1. isFormulaRecursion test. D1006 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("E1006"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1006: A1006+B1006, B1006: B1006+C1006, C1006: C1006+D1006 ... J1006: 1. isFormulaRecursion test. E1006 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("F1006"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1006: A1006+B1006, B1006: B1006+C1006, C1006: C1006+D1006 ... J1006: 1. isFormulaRecursion test. F1006 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("G1006"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1006: A1006+B1006, B1006: B1006+C1006, C1006: C1006+D1006 ... J1006: 1. isFormulaRecursion test. G1006 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("H1006"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1006: A1006+B1006, B1006: B1006+C1006, C1006: C1006+D1006 ... J1006: 1. isFormulaRecursion test. H1006 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("I1006"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1006: A1006+B1006, B1006: B1006+C1006, C1006: C1006+D1006 ... J1006: 1. isFormulaRecursion test. I1006 - flag ca: true"); bCaFromSelectedCell = null; // - Case: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... T1007: 1. Deep level of recursion - 20, Max iteration 10 ws.getRange2("A1007").setValue("=A1007+B1007"); ws.getRange2("B1007").setValue("=B1007+C1007"); ws.getRange2("C1007").setValue("=C1007+D1007"); ws.getRange2("D1007").setValue("=D1007+E1007"); ws.getRange2("E1007").setValue("=E1007+F1007"); ws.getRange2("F1007").setValue("=F1007+G1007"); ws.getRange2("G1007").setValue("=G1007+H1007"); ws.getRange2("H1007").setValue("=H1007+I1007"); ws.getRange2("I1007").setValue("=I1007+J1007"); ws.getRange2("J1007").setValue("=J1007+K1007"); ws.getRange2("K1007").setValue("=K1007+L1007"); ws.getRange2("L1007").setValue("=L1007+Q1007"); ws.getRange2("Q1007").setValue("=Q1007+R1007"); ws.getRange2("R1007").setValue("=R1007+S1007"); ws.getRange2("S1007").setValue("=S1007+T1007"); ws.getRange2("T1007").setValue("=T1007+U1007"); ws.getRange2("U1007").setValue("=U1007+V1007"); ws.getRange2("V1007").setValue("=V1007+W1007"); ws.getRange2("W1007").setValue("=W1007+X1007"); ws.getRange2("X1007").setValue("1"); assert.strictEqual(ws.getRange2("A1007").getValue(), "0", "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. A1007 - 0"); assert.strictEqual(ws.getRange2("B1007").getValue(), "0", "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. B1007 - 0"); assert.strictEqual(ws.getRange2("C1007").getValue(), "0", "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. C1007 - 0"); assert.strictEqual(ws.getRange2("D1007").getValue(), "0", "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. D1007 - 0"); assert.strictEqual(ws.getRange2("E1007").getValue(), "0", "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. E1007 - 0"); assert.strictEqual(ws.getRange2("F1007").getValue(), "0", "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. F1007 - 0"); assert.strictEqual(ws.getRange2("G1007").getValue(), "0", "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. G1007 - 0"); assert.strictEqual(ws.getRange2("H1007").getValue(), "0", "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. H1007 - 0"); assert.strictEqual(ws.getRange2("I1007").getValue(), "0", "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. I1007 - 0"); assert.strictEqual(ws.getRange2("J1007").getValue(), "1", "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. J1007 - 1"); assert.strictEqual(ws.getRange2("K1007").getValue(), "10", "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. K1007 - 10"); assert.strictEqual(ws.getRange2("L1007").getValue(), "45", "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. L1007 - 45"); assert.strictEqual(ws.getRange2("Q1007").getValue(), "120", "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. Q1007 - 120"); assert.strictEqual(ws.getRange2("R1007").getValue(), "210", "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. R1007 - 210"); assert.strictEqual(ws.getRange2("S1007").getValue(), "252", "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. S1007 - 252"); assert.strictEqual(ws.getRange2("T1007").getValue(), "210", "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. T1007 - 210"); assert.strictEqual(ws.getRange2("U1007").getValue(), "120", "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. U1007 - 120"); assert.strictEqual(ws.getRange2("V1007").getValue(), "45", "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. V1007 - 45"); assert.strictEqual(ws.getRange2("W1007").getValue(), "10", "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. W1007 - 10"); // Check work isFormulaRecursion function bCaFromSelectedCell = getCaFromSelectedCell("A1007"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. isFormulaRecursion test. A1007 - flag ca: true"); bCaFromSelectedCell = null bCaFromSelectedCell = getCaFromSelectedCell("B1007"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. isFormulaRecursion test. B1007 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("C1007"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. isFormulaRecursion test. C1007 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("D1007"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. isFormulaRecursion test. D1007 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("E1007"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. isFormulaRecursion test. E1007 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("F1007"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. isFormulaRecursion test. F1007 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("G1007"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. isFormulaRecursion test. G1007 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("H1007"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. isFormulaRecursion test. H1007 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("I1007"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. isFormulaRecursion test. I1007 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("J1007"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. isFormulaRecursion test. J1007 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("K1007"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. isFormulaRecursion test. K1007 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("L1007"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. isFormulaRecursion test. L1007 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("Q1007"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. isFormulaRecursion test. Q1007 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("R1007"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. isFormulaRecursion test. R1007 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("S1007"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. isFormulaRecursion test. S1007 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("T1007"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. isFormulaRecursion test. T1007 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("U1007"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. isFormulaRecursion test. U1007 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("V1007"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. isFormulaRecursion test. V1007 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("W1007"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain - A1007: A1007+B1007, B1007: B1007+C1007, C1007: C1007+D1007 ... X1007: 1. isFormulaRecursion test. W1007 - flag ca: true"); bCaFromSelectedCell = null; // - Case: Vertical sequence chain - A1011: A1011+A1012, A1012: A1012+A1013, A1013: A1013+A1014, A1014: A1014+A1015, A1015: 1 ws.getRange2("A1011").setValue("=A1011+A1012"); ws.getRange2("A1012").setValue("=A1012+A1013"); ws.getRange2("A1013").setValue("=A1013+A1014"); ws.getRange2("A1014").setValue("=A1014+A1015"); ws.getRange2("A1015").setValue("1"); assert.strictEqual(ws.getRange2("A1011").getValue(), "210", "Test: Vertical sequence chain - A1011: A1011+A1012, A1012: A1012+A1013, A1013: A1013+A1014, A1014: A1014+A1015, A1015: 1. A1011 - 1"); assert.strictEqual(ws.getRange2("A1012").getValue(), "120", "Test: Vertical sequence chain - A1011: A1011+A1012, A1012: A1012+A1013, A1013: A1013+A1014, A1014: A1014+A1015, A1015: 1. A1012 - 120"); assert.strictEqual(ws.getRange2("A1013").getValue(), "45", "Test: Vertical sequence chain - A1011: A1011+A1012, A1012: A1012+A1013, A1013: A1013+A1014, A1014: A1014+A1015, A1015: 1. A1013 - 45"); assert.strictEqual(ws.getRange2("A1014").getValue(), "10", "Test: Vertical sequence chain - A1011: A1011+A1012, A1012: A1012+A1013, A1013: A1013+A1014, A1014: A1014+A1015, A1015: 1. A1014 - 10"); // Check work isRecursionFormula function bCaFromSelectedCell = getCaFromSelectedCell("A1011"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Vertical sequence chain - A1011: A1011+A1012, A1012: A1012+A1013, A1013: A1013+A1014, A1014: A1014+A1015, A1015: 1. isFormulaRecursion test. A1011 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("A1012"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Vertical sequence chain - A1011: A1011+A1012, A1012: A1012+A1013, A1013: A1013+A1014, A1014: A1014+A1015, A1015: 1. isFormulaRecursion test. A1012 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("A1013"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Vertical sequence chain - A1011: A1011+A1012, A1012: A1012+A1013, A1013: A1013+A1014, A1014: A1014+A1015, A1015: 1. isFormulaRecursion test. A1013 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("A1014"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Vertical sequence chain - A1011: A1011+A1012, A1012: A1012+A1013, A1013: A1013+A1014, A1014: A1014+A1015, A1015: 1. isFormulaRecursion test. A1014 - flag ca: true"); bCaFromSelectedCell = null; // Remove created sheets. wb.removeWorksheet(0); // - Case: 3D sequence chain - A1016: A1016+Sheet2!A1000, Sheet2!A1000: Sheet2!A1000+Sheet3!A1000, Sheet3!A1000: 1 ws2 = wb.createWorksheet(0, "Sheet2"); let ws3 = wb.createWorksheet(1, "Sheet3"); ws.getRange2("A1016").setValue("=A1016+Sheet2!A1000"); ws2.getRange2("A1000").setValue("=A1000+Sheet3!A1000"); ws3.getRange2("A1000").setValue("1"); assert.strictEqual(ws.getRange2("A1016").getValue(), "45", "Test: 3D sequence chain - A1012: A1012+Sheet2!A1000, Sheet2!A1000: Sheet2!A1000+Sheet3!A1000, Sheet3!A1000: 1. A1012 - 45"); assert.strictEqual(ws2.getRange2("A1000").getValue(), "10", "Test: 3D sequence chain - A1012: A1012+Sheet2!A1000, Sheet2!A1000: Sheet2!A1000+Sheet3!A1000, Sheet3!A1000: 1. Sheet2!A1000 - 10"); assert.strictEqual(ws3.getRange2("A1000").getValue(), "1", "Test: 3D sequence chain - A1012: A1012+Sheet2!A1000, Sheet2!A1000: Sheet2!A1000+Sheet3!A1000, Sheet3!A1000: 1. Sheet3!A1000 - 1"); // Check work isRecursionFormula function bCaFromSelectedCell = getCaFromSelectedCell("A1016"); assert.strictEqual(bCaFromSelectedCell, true, "Test: 3D sequence chain - A1016: A1016+Sheet2!A1000, Sheet2!A1000: Sheet2!A1000+Sheet3!A1000, Sheet3!A1000: 1. isFormulaRecursion test. A1016 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("A1000", ws2); assert.strictEqual(bCaFromSelectedCell, true, "Test: 3D sequence chain - A1016: A1016+Sheet2!A1000, Sheet2!A1000: Sheet2!A1000+Sheet3!A1000, Sheet3!A1000: 1. isFormulaRecursion test. Sheet2!A1000 - flag ca: true"); bCaFromSelectedCell = null; // - Case: 3D sequence chain B1012: B1012+Sheet2!B1012, Sheet2!B1012: Sheet2!B1012+Sheet3!B1012, Sheet3!B1012: 1 ws.getRange2("B1012").setValue("=B1012+Sheet2!B1012"); ws2.getRange2("B1012").setValue("=B1012+Sheet3!B1012"); ws3.getRange2("B1012").setValue("1"); assert.strictEqual(ws.getRange2("B1012").getValue(), "45", "Test: 3D sequence chain - B1012: B1012+Sheet2!B1012, Sheet2!B1012: Sheet2!B1012+Sheet3!B1012, Sheet3!B1012: 1. B1012 - 45"); assert.strictEqual(ws2.getRange2("B1012").getValue(), "10", "Test: 3D sequence chain - B1012: B1012+Sheet2!B1012, Sheet2!B1012: Sheet2!B1012+Sheet3!B1012, Sheet3!B1012: 1. Sheet2!B1012 - 10"); assert.strictEqual(ws3.getRange2("B1012").getValue(), "1", "Test: 3D sequence chain - B1012: B1012+Sheet2!B1012, Sheet2!B1012: Sheet2!B1012+Sheet3!B1012, Sheet3!B1012: 1. Sheet3!B1012 - 1"); // Check work isRecursionFormula function bCaFromSelectedCell = getCaFromSelectedCell("B1012"); assert.strictEqual(bCaFromSelectedCell, true, "Test: 3D sequence chain - B1012: B1012+Sheet2!B1012, Sheet2!B1012: Sheet2!B1012+Sheet3!B1012, Sheet3!B1012: 1. isFormulaRecursion test. B1012 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("B1012", ws2); assert.strictEqual(bCaFromSelectedCell, true, "Test: 3D sequence chain - B1012: B1012+Sheet2!B1012, Sheet2!B1012: Sheet2!B1012+Sheet3!B1012, Sheet3!B1012: 1. isFormulaRecursion test. Sheet2!B1012 - flag ca: true"); bCaFromSelectedCell = null; // Remove created sheets. wb.removeWorksheet(0); wb.removeWorksheet(0); // - Case: DefName loop cell - X: X+1 let oDefName = new Asc.asc_CDefName("x", ws.getName() + "!$A$1017"); wb.editDefinesNames(null, oDefName); ws.getRange2("A1017").setValue("=x+1") assert.strictEqual(ws.getRange2("A1017").getValue(), "10", "Test: DefName loop cell - X: X+1. X - 10"); // Check work isFormulaRecursive function bCaFromSelectedCell = getCaFromSelectedCell("A1017"); assert.strictEqual(bCaFromSelectedCell, true, "Test: DefName loop cell - X: X+1. isFormulaRecursion test. A1017(X) - flag ca: true"); bCaFromSelectedCell = null; // Clean define name wb.delDefinesNames(oDefName); oDefName = null; // - Case: DefName sequence chain - X: X+Y, Y: Y+Z, Z: 1 let oDefNameX = new Asc.asc_CDefName("x", ws.getName() + "!$A$1018"); let oDefNameY = new Asc.asc_CDefName("y", ws.getName() + "!$B$1018"); let oDefNameZ = new Asc.asc_CDefName("z", ws.getName() + "!$C$1018"); wb.editDefinesNames(null, oDefNameX); wb.editDefinesNames(null, oDefNameY); wb.editDefinesNames(null,oDefNameZ); ws.getRange2("A1018").setValue("=x+y"); ws.getRange2("B1018").setValue("=y+z"); ws.getRange2("C1018").setValue("1"); assert.strictEqual(ws.getRange2("A1018").getValue(), "45", "Test: DefName sequence chain - X: X+Y, Y: Y+Z, Z: 1. X - 45"); assert.strictEqual(ws.getRange2("B1018").getValue(), "10", "Test: DefName sequence chain - X: X+Y, Y: Y+Z, Z: 1. Y - 10"); assert.strictEqual(ws.getRange2("C1018").getValue(), "1", "Test: DefName sequence chain - X: X+Y, Y: Y+Z, Z: 1. Z - 1"); // Check work isFormulaRecursive function bCaFromSelectedCell = getCaFromSelectedCell("A1018"); assert.strictEqual(bCaFromSelectedCell, true, "Test: DefName sequence chain - X: X+Y, Y: Y+Z, Z: 1. isFormulaRecursion test. A1018(X) - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("B1018"); assert.strictEqual(bCaFromSelectedCell, true, "Test: DefName sequence chain - X: X+Y, Y: Y+Z, Z: 1. isFormulaRecursion test. B1018(Y) - flag ca: true"); bCaFromSelectedCell = null; // Clean define name wb.delDefinesNames(oDefNameX); wb.delDefinesNames(oDefNameY); wb.delDefinesNames(oDefNameZ); oDefNameX = null; oDefNameY = null; oDefNameZ = null; // - Case: Area recursive formula SUM(A1019:D1019) ws.getRange2("A1019").setValue("1"); ws.getRange2("B1019").setValue("2"); ws.getRange2("C1019").setValue("3"); ws.getRange2("D1019").setValue("=SUM(A1019:D1019)"); assert.strictEqual(ws.getRange2("D1019").getValue(), "60", "Test: Area recursive formula SUM(A1019:D1019). D1019 - 60"); // Check work isFormulaRecursive function bCaFromSelectedCell = getCaFromSelectedCell("D1019"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Area recursive formula SUM(A1019:D1019). isFormulaRecursion test. D1019 - flag ca: true"); bCaFromSelectedCell = null; // - Case: Area recursive formula SUM(D1020, A1020:C1020) ws.getRange2("A1020").setValue("1"); ws.getRange2("B1020").setValue("2"); ws.getRange2("C1020").setValue("3"); ws.getRange2("D1020").setValue("=SUM(D1020, A1020:C1020)"); assert.strictEqual(ws.getRange2("D1020").getValue(), "60", "Test: Area recursive formula SUM(D1020, A1020:C1020). D1020 - 60"); // Check work isFormulaRecursive function bCaFromSelectedCell = getCaFromSelectedCell("D1020"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Area recursive formula SUM(D1020, A1020:C1020). isFormulaRecursion test. D1020 - flag ca: true"); bCaFromSelectedCell = null; // - Case: 3D Area recursive formula SUM(A1021, Sheet2!A1000:C1000) ws2 = wb.createWorksheet(0, "Sheet2"); ws2.getRange2("A1000").setValue("1"); ws2.getRange2("B1000").setValue("2"); ws2.getRange2("C1000").setValue("3"); ws.getRange2("A1021").setValue("=SUM(A1021, Sheet2!A1000:C1000)"); assert.strictEqual(ws.getRange2("A1021").getValue(), "60", "Test: 3D Area recursive formula SUM(A1021, Sheet2!A1000:C1000). A1021 - 60"); // Check work isFormulaRecursive function bCaFromSelectedCell = getCaFromSelectedCell("A1021"); assert.strictEqual(bCaFromSelectedCell, true, "Test: 3D Area recursive formula SUM(A1021, Sheet2!A1000:C1000). isFormulaRecursion test. A1021 - flag ca: true"); bCaFromSelectedCell = null; // Remove created sheets. wb.removeWorksheet(0); // - Case: DefName Area recursive formula SUM(Range) let oDefNameRange = new Asc.asc_CDefName("Range", ws.getName() + "!$A$1022:$D$1022"); wb.editDefinesNames(null, oDefNameRange); ws.getRange2("A1022").setValue("1"); ws.getRange2("B1022").setValue("2"); ws.getRange2("C1022").setValue("3"); ws.getRange2("D1022").setValue("=SUM(Range)"); assert.strictEqual(ws.getRange2("D1022").getValue(), "60", "Test: DefName Area recursive formula SUM(Range). D1022 - 60"); // Check work isFormulaRecursive function bCaFromSelectedCell = getCaFromSelectedCell("D1022"); assert.strictEqual(bCaFromSelectedCell, true, "Test: DefName Area recursive formula SUM(Range). isFormulaRecursion test. D1022 - flag ca: true"); bCaFromSelectedCell = null; // Clean define name wb.delDefinesNames(oDefNameRange); oDefNameRange = null; // - Case: DefName Area 3D recursive formula SUM(А1000,Range3D) ws2 = wb.createWorksheet(0, "Sheet2"); let oDefNameRange3D = new Asc.asc_CDefName("Range3D", ws.getName() + "!$A$1023:$C$1023"); wb.editDefinesNames(null, oDefNameRange3D); ws.getRange2("A1023").setValue("1"); ws.getRange2("B1023").setValue("2"); ws.getRange2("C1023").setValue("3"); ws2.getRange2("A1000").setValue("=SUM(A1000, Range3D)"); assert.strictEqual(ws2.getRange2("A1000").getValue(), "60", "Test: DefName Area 3D recursive formula SUM(А1000,Range3D). Sheet2!A1000 - 60"); // Check work isFormulaRecursive function bCaFromSelectedCell = getCaFromSelectedCell("A1000", ws2); assert.strictEqual(bCaFromSelectedCell, true, "Test: DefName Area 3D recursive formula SUM(А1000,Range3D). isFormulaRecursion test. Sheet2!A1000 - flag ca: true"); bCaFromSelectedCell = null; // Clean define name wb.delDefinesNames(oDefNameRange3D); oDefNameRange3D = null; // Remove created sheets. wb.removeWorksheet(0); // - Case: Chain recursive formula without outStack link. A1024: A1024+1, B1024: A1024+B1024, C1024: B1024+C1024 ws.getRange2("A1024").setValue("=A1024+1"); ws.getRange2("B1024").setValue("=A1024+B1024"); ws.getRange2("C1024").setValue("=B1024+C1024"); assert.strictEqual(ws.getRange2("A1024").getValue(), "30", "Test: Chain recursive formula without outStack link. A1024 - 30"); assert.strictEqual(ws.getRange2("B1024").getValue(), "410", "Test: Chain recursive formula without outStack link. B1024 - 410"); assert.strictEqual(ws.getRange2("C1024").getValue(), "2870", "Test: Chain recursive formula without outStack link. C1024 - 2870"); // Check work isFormulaRecursive function bCaFromSelectedCell = getCaFromSelectedCell("C1024"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Chain recursive formula without outStack link. isFormulaRecursion test. C1024 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("B1024"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Chain recursive formula without outStack link. isFormulaRecursion test. B1024 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("A1024"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Chain recursive formula without outStack link. isFormulaRecursion test. A1024 - flag ca: true"); bCaFromSelectedCell = null; // - Case: Not recursive formula A1025: SUM(B1025:C1025) ws.getRange2("A1025").setValue("=SUM(B1025:C1025)"); ws.getRange2("B1025").setValue("1"); ws.getRange2("C1025").setValue("2"); assert.strictEqual(ws.getRange2("A1025").getValue(), "3", "Test: Not recursive formula A1025 - 3"); // Check work isFormulaRecursive function bCaFromSelectedCell = getCaFromSelectedCell("A1025"); assert.strictEqual(bCaFromSelectedCell, false, "Test: Not recursive formula A1025. isFormulaRecursion test. A1025 - flag ca: false"); bCaFromSelectedCell = null; // - Case: Area recursive formula SUM(Y:Z) ws.getRange2("Y1000").setValue("1"); ws.getRange2("Z1000").setValue("2"); ws.getRange2("Y1001").setValue("=SUM(Y:Z)"); assert.strictEqual(ws.getRange2("Y1001").getValue(), "30", "Test: Area recursive formula SUM(Y:Z). Y1001 - 30"); // Check work isFormulaRecursive function bCaFromSelectedCell = getCaFromSelectedCell("Y1001"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Area recursive formula SUM(Y:Z). isFormulaRecursion test. Y1001 - flag ca: true"); bCaFromSelectedCell = null; // - Case: Def name area recursive formula SUM(All) let oDefNameAll = new Asc.asc_CDefName("All", ws.getName() + "!$Z:$Z"); wb.editDefinesNames(null, oDefNameAll); ws.getRange2("Z1000").setValue("1"); ws.getRange2("Z1001").setValue("2"); ws.getRange2("Z1002").setValue("=SUM(All)"); assert.strictEqual(ws.getRange2("Z1002").getValue(), "30", "Test: Def name area recursive formula SUM(All). Z1002 - 30"); // Check work isFormulaRecursive function bCaFromSelectedCell = getCaFromSelectedCell("Z1002"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Def name area recursive formula SUM(All). isFormulaRecursion test. Z1002 - flag ca: true"); bCaFromSelectedCell = null; // Clean define name wb.delDefinesNames(oDefNameAll); oDefNameAll = null; // - Case: Def name area non-recursive formula SUM(XAll) let oDefNameABAll = new Asc.asc_CDefName("ABAll", ws.getName() + "!$AB:$AB"); wb.editDefinesNames(null, oDefNameABAll); ws.getRange2("AB1000").setValue("1"); ws.getRange2("AB1001").setValue("2"); ws.getRange2("A1026").setValue("=SUM(ABAll)"); assert.strictEqual(ws.getRange2("A1026").getValue(), "3", "Test: Def name area non-recursive formula SUM(ABAll). A1026 - 3"); // Check work isFormulaRecursive function bCaFromSelectedCell = getCaFromSelectedCell("A1026"); assert.strictEqual(bCaFromSelectedCell, false, "Test: Def name area non-recursive formula SUM(ABAll). isFormulaRecursion test. A1026 - flag ca: false"); bCaFromSelectedCell = null; // Clean define name wb.delDefinesNames(oDefNameABAll); oDefNameABAll = null; // - Case: Cross recursive chain formula. B1027: B1027+B1028, B1028: B1028+B1029, A1028: A1028+B1028, C1028: B1028+C1028, B1029: 1 ws.getRange2("B1027").setValue("=B1027+B1028"); ws.getRange2("B1028").setValue("=B1028+B1029"); ws.getRange2("A1028").setValue("=A1028+B1028"); ws.getRange2("C1028").setValue("=B1028+C1028"); ws.getRange2("B1029").setValue("1"); assert.strictEqual(ws.getRange2("B1027").getValue(), "45", "Test: Cross recursive chain formula. B1027 - 45"); assert.strictEqual(ws.getRange2("B1028").getValue(), "10", "Test: Cross recursive chain formula. B1028 - 10"); assert.strictEqual(ws.getRange2("A1028").getValue(), "45", "Test: Cross recursive chain formula. A1028 - 45"); assert.strictEqual(ws.getRange2("C1028").getValue(), "55", "Test: Cross recursive chain formula. C1028 - 55"); // Check work isFormulaRecursive function bCaFromSelectedCell = getCaFromSelectedCell("B1027"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Cross recursive chain formula. isFormulaRecursion test. B1027 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("B1028"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Cross recursive chain formula. isFormulaRecursion test. B1028 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("A1028"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Cross recursive chain formula. isFormulaRecursion test. A1028 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("C1028"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Cross recursive chain formula. isFormulaRecursion test. C1028 - flag ca: true"); bCaFromSelectedCell = null; // - Case: Recrusive cell with IF formula, with empty cell ("") ws.getRange2("A1030").setValue(""); ws.getRange2("B1030").setValue("=IF(A1030<>\"\",IF(B1030<>\"\",B1030,NOW()),\"\")"); assert.strictEqual(ws.getRange2("B1030").getValue(), "", "Test: Recrusive cell with IF formula, with empty cell (\"\"). B1030 - \"\""); ws.getRange2("A1030").setValue("Test"); let date = new cDate(); let excelDate = date.getExcelDate(); assert.strictEqual(Math.floor(ws.getRange2("B1030").getValue()), excelDate, "Test: Recrusive cell with IF formula, with empty cell (\"\"). B1030 - " + excelDate); // Check work isFormulaRecursive function bCaFromSelectedCell = getCaFromSelectedCell("B1030"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Recrusive cell with IF formula, with empty cell (\"\"). isFormulaRecursion test. B1030 - flag ca: true"); bCaFromSelectedCell = null; // - Case: Recursive convergent formula with IF formula ws.getRange2("A1031").setValue("=IF(A1031=0,-5,A1031-(A1031^3-4*A1031^2-4*A1031+5)/(3*A1031^2-8*A1031-4))"); assert.strictEqual(ws.getRange2("A1031").getValue(), "-1.4012223386412388", "Test: Recursive convergent formula with IF formula. A1031 - -1.04122233864124"); // Check work isFormulaRecursive function bCaFromSelectedCell = getCaFromSelectedCell("A1031"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Recursive convergent formula with IF formula. isFormulaRecursion test. A1031 - flag ca: true"); bCaFromSelectedCell = null; // - Case: Recursive cell chain formula: J1031->R1031->K1031->J1031. Bug-42873, Comment #2 ws.getRange2("A1031").setValue("1000"); ws.getRange2("B1031").setValue("0.36"); ws.getRange2("C1031").setValue("23"); ws.getRange2("D1031").setValue("8"); ws.getRange2("E1031").setValue("27"); ws.getRange2("F1031").setValue("=IF(C1031*D1031*E1031/5B1031,C1031*D1031*E1031/5000))"); ws.getRange2("G1031").setValue("8"); ws.getRange2("H1031").setValue("6.5"); ws.getRange2("I1031").setValue("25"); ws.getRange2("J1031").setValue("=IF(F1031<1,R1031*4%,IF(F1031>1,R1031*5%,IF(F1031>3,R1031*5.5%)))"); ws.getRange2("K1031").setValue("=(A1031+I1031+J1031)*100/(100-G1031-H1031)"); ws.getRange2("L1031").setValue("=R1031*100/69.9"); ws.getRange2("Q1031").setValue("=L1031*1.07"); ws.getRange2("R1031").setValue("=K1031*100/94.7"); assert.strictEqual(ws.getRange2("J1031").getValue(), "53.268529249844036", "Test: Recursive cell chain formula: J1031->R1031->K1031->J1031. Bug-42873, Comment #2. J1031 - 53.26854488596814"); assert.strictEqual(ws.getRange2("K1031").getValue(), "1261.1327827483556", "Test: Recursive cell chain formula: J1031->R1031->K1031->J1031. Bug-42873, Comment #2. K1031 - 1261.1328010362201"); assert.strictEqual(ws.getRange2("L1031").getValue(), "1905.1696763189466", "Test: Recursive cell chain formula: J1031->R1031->K1031->J1031. Bug-42873, Comment #2. L1031 - 1905.1697026454983"); assert.strictEqual(ws.getRange2("Q1031").getValue(), "2038.531553661273", "Test: Recursive cell chain formula: J1031->R1031->K1031->J1031. Bug-42873, Comment #2. Q1031 - 2038.5315818306833"); assert.strictEqual(ws.getRange2("R1031").getValue(), "1331.7136037469436", "Test: Recursive cell chain formula: J1031->R1031->K1031->J1031. Bug-42873, Comment #2. R1031 - 1331.7136230583105"); // Check work isFormulaRecursive function bCaFromSelectedCell = getCaFromSelectedCell("J1031"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Recursive cell chain formula: J1031->R1031->K1031->J1031, Bug-42873, Comment #2. isFormulaRecursion test. J1031 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("K1031"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Recursive cell chain formula: J1031->R1031->K1031->J1031, Bug-42873, Comment #2. isFormulaRecursion test. K1031 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("L1031"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Recursive cell chain formula: J1031->R1031->K1031->J1031, Bug-42873, Comment #2. isFormulaRecursion test. L1031 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("Q1031"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Recursive cell chain formula: J1031->R1031->K1031->J1031, Bug-42873, Comment #2. isFormulaRecursion test. Q1031 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("R1031"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Recursive cell chain formula: J1031->R1031->K1031->J1031, Bug-42873, Comment #2. isFormulaRecursion test. R1031 - flag ca: true"); bCaFromSelectedCell = null; // - Case: Sequence-loop chain. D1033 <-> D1034, D1034 <-> D1035 etc. ws.getRange2("A1032").setValue("0"); // P ws.getRange2("A1033").setValue("10"); // deltaY ws.getRange2("A1034").setValue("1"); // X ws.getRange2("B1032").setValue("10"); // mu ws.getRange2("C1032").setValue("10"); // u start ws.getRange2("D1032").setValue("=C1032"); // u ws.getRange2("B1033").setValue("10"); // mu ws.getRange2("C1033").setValue("-10");// u start ws.getRange2("D1033").setValue("=IF($A$1034=0, C1033, -(($A$1032*$A$1033*$A$1033-(D1034-D1032)*(B1034-B1032)/4)/B1033-(D1034+D1032))/2)"); // u ws.getRange2("B1034").setValue("10"); // mu ws.getRange2("C1034").setValue("-10"); // u start ws.getRange2("D1034").setValue("=IF($A$1034=0, C1034, -(($A$1032*$A$1033*$A$1033-(D1035-D1033)*(B1035-B1033)/4)/B1034-(D1035+D1033))/2)"); // u ws.getRange2("B1035").setValue("10"); // mu ws.getRange2("C1035").setValue("-10"); // u start ws.getRange2("D1035").setValue("=IF($A$1034=0, C1035, -(($A$1032*$A$1033*$A$1033-(D1036-D1034)*(B1036-B1034)/4)/B1035-(D1036+D1034))/2)"); // u ws.getRange2("B1036").setValue("10"); // mu ws.getRange2("C1036").setValue("0"); // u start ws.getRange2('D1036').setValue("=C1036"); // u assert.strictEqual(ws.getRange2("D1033").getValue(), "7.499457849531321", "Test: Sequence-loop chain. D1033 <-> D1034, D1034 <-> D1035 etc. D1033 - 7.499728735325547"); assert.strictEqual(ws.getRange2("D1034").getValue(), "4.999457849531321", "Test: Sequence-loop chain. D1033 <-> D1034, D1034 <-> D1035 etc. D1034 - 4.999728735325547"); assert.strictEqual(ws.getRange2("D1035").getValue(), "2.4997289247656607", "Test: Sequence-loop chain. D1033 <-> D1034, D1034 <-> D1035 etc. D1035 - 2.4998643676627736"); // Check work isFormulaRecursion function bCaFromSelectedCell = getCaFromSelectedCell("D1033"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence-loop chain. D1033 <-> D1034, D1034 <-> D1035 etc. isFormulaRecursion test. D1033 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("D1034"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence-loop chain. D1033 <-> D1034, D1034 <-> D1035 etc. isFormulaRecursion test. D1034 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("D1035"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence-loop chain. D1033 <-> D1034, D1034 <-> D1035 etc. isFormulaRecursion test. D1035 - flag ca: true"); bCaFromSelectedCell = null; // Case: Convergent formula calucaltes only once time. g_cCalcRecursion.setMaxIterations(15); ws.getRange2("A1040").setValue("=A1041+A1043"); ws.getRange2("A1041").setValue("25150"); ws.getRange2("A1042").setValue("0.2"); ws.getRange2("A1043").setValue("=A1040*A1042"); assert.strictEqual(ws.getRange2("A1040").getValue(), "31437.49935616", "Test: Convergent formula calculates only once time. First calculate. A1040 - 31437.49987"); assert.strictEqual(ws.getRange2("A1043").getValue(), "6287.499871232", "Test: Convergent formula calculates only once time. First calculate. A1041 - 6287.499974246401"); ws.getRange2("A1041").setValue("25150"); assert.strictEqual(ws.getRange2("A1040").getValue(), "31437.49935616", "Test: Convergent formula calculates only once time. Recalculate. A1040 - 31437.49987"); assert.strictEqual(ws.getRange2("A1043").getValue(), "6287.499871232", "Test: Convergent formula calculates only once time. Recalculate. A1041 - 6287.499974246401"); // Check work isFormulaRecursion function bCaFromSelectedCell = getCaFromSelectedCell("A1040"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Convergent formula calculates only once time. isFormulaRecursion test. A1040 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("A1043"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Convergent formula calculates only once time. isFormulaRecursion test. A1043 - flag ca: true"); bCaFromSelectedCell = null; // - Case: With disabled iterative calculation. g_cCalcRecursion.setIsEnabledRecursion(false); ws.getRange2("A1037").setValue("=A1037+1"); ws.getRange2("A1038").setValue("=A1038+B1038"); ws.getRange2("B1038").setValue("=B1038+C1038"); ws.getRange2("C1038").setValue("1"); assert.strictEqual(ws.getRange2("A1037").getValue(), "0", "Test: Loop cell with disabled iterative calculation. A1037 - 0"); assert.strictEqual(ws.getRange2("A1038").getValue(), "0", "Test: Sequence chain with disabled iterative calculation. A1038 - 0"); assert.strictEqual(ws.getRange2("B1038").getValue(), "0", "Test: Sequence chain with disabled iterative calculation. B1038 - 0"); // Check work isFormulaRecursion function bCaFromSelectedCell = getCaFromSelectedCell("A1037"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Loop cell with disabled iterative calculation. A1037 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("A1038"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain with disabled iterative calculation. A1038 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("B1038"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Sequence chain with disabled iterative calculation. B1038 - flag ca: true"); bCaFromSelectedCell = null; // Case: Exception formulas that ignores rules of recursion recognition ws.getRange2("A1039").setValue("=ROW(A1039)"); assert.strictEqual(ws.getRange2("A1039").getValue(), "1039", "Test: Exception formulas that ignores rules of recursion recognition. A1039 - 1039. Formula - ROW"); bCaFromSelectedCell = getCaFromSelectedCell("A1039"); assert.strictEqual(bCaFromSelectedCell, false, "Test: Exception formulas that ignores rules of recursion recognition. A1039 - flag ca: false"); bCaFromSelectedCell = null; ws.getRange2("B1039").setValue("=COLUMN(B1039)"); assert.strictEqual(ws.getRange2("B1039").getValue(), "2", "Test: Exception formulas that ignores rules of recursion recognition. B1039 - 2. Formula - COLUMN"); bCaFromSelectedCell = getCaFromSelectedCell("B1039"); assert.strictEqual(bCaFromSelectedCell, false, "Test: Exception formulas that ignores rules of recursion recognition. B1039 - flag ca: false"); bCaFromSelectedCell = null; ws.getRange2("C1039").setValue("=ISFORMULA(C1039)"); assert.strictEqual(ws.getRange2("C1039").getValue(), "TRUE", "Test: Exception formulas that ignores rules of recursion recognition. C1039 - TRUE. Formula - ISFORMULA"); bCaFromSelectedCell = getCaFromSelectedCell("C1039"); assert.strictEqual(bCaFromSelectedCell, false, "Test: Exception formulas that ignores rules of recursion recognition. C1039 - flag ca: false"); bCaFromSelectedCell = null; ws.getRange2("D1039").setValue("=SHEETS(D1039)"); assert.strictEqual(ws.getRange2("D1039").getValue(), "1", "Test: Exception formulas that ignores rules of recursion recognition. D1039 - 1. Formula - SHEETS"); bCaFromSelectedCell = getCaFromSelectedCell("D1039"); assert.strictEqual(bCaFromSelectedCell, false, "Test: Exception formulas that ignores rules of recursion recognition. D1039 - flag ca: false"); bCaFromSelectedCell = null; // - Case: SUMIF 2 args recursion range. Recursion formula with disabled Iterative calculation setting. ws.getRange2("A1040").setValue("2"); ws.getRange2("B1040").setValue("4"); ws.getRange2("C1040").setValue("8"); ws.getRange2("D1040").setValue("=SUMIF(A1040:D1040, \">4\")"); assert.strictEqual(ws.getRange2("D1040").getValue(), "0", "Test: SUMIF 2 args recursion range. D1040 - 0"); bCaFromSelectedCell = getCaFromSelectedCell("D1040"); assert.strictEqual(bCaFromSelectedCell, true, "Test: SUMIF 2 args recursion range. D1040 - flag ca: true"); bCaFromSelectedCell = null; // - Case: SUMIF 2 args non recursion range with disabled Iterative calculation setting. ws.getRange2("D1040").setValue("=SUMIF(A1040:C1040, \">4\")"); assert.strictEqual(ws.getRange2("D1040").getValue(), "8", "Test: SUMIF 2 args non recursion range. D1040 - 8"); bCaFromSelectedCell = getCaFromSelectedCell("D1040"); assert.strictEqual(bCaFromSelectedCell, false, "Test: SUMIF 2 args non recursion range. D1040 - flag ca: false"); bCaFromSelectedCell = null; // - Case: SUMIF. 2 args. Recursion criteria. Recursion formula with disabled Iterative calculation setting. ws.getRange2("A1041").setValue("2"); ws.getRange2("B1041").setValue("4"); ws.getRange2("C1041").setValue("8"); ws.getRange2("A1042").setValue("2"); ws.getRange2("B1042").setValue("4"); ws.getRange2("C1042").setValue("=SUMIF(A1041:C1041, A1042:C1042)"); assert.strictEqual(ws.getRange2("C1042").getValue(), "0", "Test: SUMIF. 2 args. Recursion criteria. C1042 - 0"); bCaFromSelectedCell = getCaFromSelectedCell("C1042"); assert.strictEqual(bCaFromSelectedCell, true, "Test: SUMIF. 2 args. Recursion criteria. C1042 - flag ca: true"); bCaFromSelectedCell = null; // - Case: SUMIF. 2 args. Non recursion criteria with disabled Iterative calculation setting. ws.getRange2("A1043").setValue("2"); ws.getRange2("B1043").setValue("4"); ws.getRange2("C1043").setValue("8"); ws.getRange2("A1044").setValue("2"); ws.getRange2("B1044").setValue("4"); ws.getRange2("C1044").setValue("=SUMIF(A1043:C1043, A1044:B1044)"); bCaFromSelectedCell = getCaFromSelectedCell("C1044"); assert.strictEqual(bCaFromSelectedCell, false, "Test: SUMIF. 2 args. Non recursion criteria. C1044 - flag ca: false"); bCaFromSelectedCell = null; // - Case: SUMIF. 2 args. Recursion formula. Recursion criteria name with disabled Iterative calculation setting. let oCriteriaRangeName = new Asc.asc_CDefName("Criteria_range", ws.getName() + "!$A$1045:$C$1045"); wb.editDefinesNames(null, oCriteriaRangeName); ws.getRange2("A1045").setValue("2"); ws.getRange2("B1045").setValue("4"); ws.getRange2("C1045").setValue("=SUMIF(A1043:C1043, Criteria_range)"); assert.strictEqual(ws.getRange2("C1045").getValue(), "0", "Test: SUMIF. 2 args. Recursion formula. Recursion criteria name. C1045 - 0"); bCaFromSelectedCell = getCaFromSelectedCell("C1045"); assert.strictEqual(bCaFromSelectedCell, true, "Test: SUMIF. 2 args. Recursion formula. Recursion criteria name. C1045 - flag ca: true"); bCaFromSelectedCell = null; wb.delDefinesNames(oCriteriaRangeName); oCriteriaRangeName = null; // - Case: SUMIF. 3 args. Recursion formula. Recursion sum_range, but the cell with formula doesn't match with criteria. With disabled Iterative calculation setting. // range row ws.getRange2("A1046").setValue("1"); ws.getRange2("B1046").setValue("0"); ws.getRange2("C1046").setValue("1"); ws.getRange2("D1046").setValue("0"); // criteria row ws.getRange2("A1047").setValue("1"); // sum_range row ws.getRange2("A1048").setValue("2"); ws.getRange2("B1048").setValue("4"); ws.getRange2("C1048").setValue("8"); ws.getRange2("D1048").setValue("=SUMIF(A1046:D1046, A1047 ,A1048:D1048)"); assert.strictEqual(ws.getRange2("D1048").getValue(), "10", "Test: SUMIF. 3 args. Recursion formula. Recursion sum_range, but the cell with formula doesn't match with criteria. D1048 - 10"); bCaFromSelectedCell = getCaFromSelectedCell("D1048"); assert.strictEqual(bCaFromSelectedCell, false, "Test: SUMIF. 3 args. Recursion formula. Recursion sum_range, but the cell with formula doesn't match with criteria. D1048 - flag ca: false"); bCaFromSelectedCell = null; // - Case: SUMIF. 3 args. Recursion formula. Recursion sum_range, but the cell with formula matches with criteria. With disabled Iterative calculation setting. ws.getRange2("D1046").setValue("1"); assert.strictEqual(ws.getRange2("D1048").getValue(), "10", "Test: SUMIF. 3 args. Recursion formula. Recursion sum_range, but the cell with formula matches with criteria. D1048 - 10"); bCaFromSelectedCell = getCaFromSelectedCell("D1048"); assert.strictEqual(bCaFromSelectedCell, true, "Test: SUMIF. 3 args. Recursion formula. Recursion sum_range, but the cell with formula matches with criteria. D1048 - flag ca: true"); bCaFromSelectedCell = null; // - Case: SUMIF. 3 args. Recursion formula. Recursion range. With disabled Iterative calculation setting. // range row ws.getRange2("A1049").setValue("1"); ws.getRange2("B1049").setValue("0"); ws.getRange2("C1049").setValue("1"); // criteria row ws.getRange2("A1050").setValue("1"); // sum_range row ws.getRange2("A1051").setValue("2"); ws.getRange2("B1051").setValue("4"); ws.getRange2("C1051").setValue("8"); ws.getRange2("D1051").setValue("16"); ws.getRange2("D1049").setValue("=SUMIF(A1049:D1049, A1050, A1051:D1051)"); assert.strictEqual(ws.getRange2("D1049").getValue(), "0", "Test: SUMIF. 3 args. Recursion formula. Recursion range. D1049 - 0"); bCaFromSelectedCell = getCaFromSelectedCell("D1049"); assert.strictEqual(bCaFromSelectedCell, true, "Test: SUMIF. 3 args. Recursion formula. Recursion range. D1049 - flag ca: true"); bCaFromSelectedCell = null; // - Case: SUMIF. 3 args. Recursion formula. Recursion criteria. With disabled Iterative calculation setting. // range row ws.getRange2("A1052").setValue("1"); ws.getRange2("B1052").setValue("0"); ws.getRange2("C1052").setValue("1"); ws.getRange2("D1052").setValue("0") // criteria row ws.getRange2("A1053").setValue("1"); // sum_range row ws.getRange2("A1054").setValue("2"); ws.getRange2("B1054").setValue("4"); ws.getRange2("C1054").setValue("8"); ws.getRange2("D1054").setValue("16"); ws.getRange2("B1053").setValue("=SUMIF(A1052:D1052, A1053:B1053, A1054:D1054)"); assert.strictEqual(ws.getRange2("B1053").getValue(), "0", "Test: SUMIF. 3 args. Recursion formula. Recursion criteria. B1053 - 0"); bCaFromSelectedCell = getCaFromSelectedCell("B1053"); assert.strictEqual(bCaFromSelectedCell, true, "Test: SUMIF. 3 args. Recursion formula. Recursion criteria. B1053 - flag ca: true"); bCaFromSelectedCell = null; // - Case: SUMIF. 3 args. Recursion formula. Recursion criteria_range with DefName. With disabled Iterative calculation setting. oCriteriaRangeName = new Asc.asc_CDefName("Criteria_range", ws.getName() + "!$A$1055:$D$1055"); let oCriteriaName = new Asc.asc_CDefName("criteria", ws.getName() + "!$A$1056:$B$1056"); let oSumRangeName = new Asc.asc_CDefName("sum_range", ws.getName() + "!$A$1057:$D$1057"); wb.editDefinesNames(null, oCriteriaRangeName); wb.editDefinesNames(null, oCriteriaName); wb.editDefinesNames(null, oSumRangeName); ws.getRange2("A1055").setValue("1"); ws.getRange2("B1055").setValue("0"); ws.getRange2("C1055").setValue("1"); ws.getRange2("A1056").setValue(">0"); ws.getRange2("A1057").setValue("2"); ws.getRange2("B1057").setValue("4"); ws.getRange2("C1057").setValue("8"); ws.getRange2("D1057").setValue("16"); ws.getRange2("D1055").setValue("=SUMIF(Criteria_range, A1056, sum_range)"); assert.strictEqual(ws.getRange2("D1055").getValue(), "0", "Test: SUMIF. 3 args. Recursion formula. Recursion criteria_range with DefName. D1055 - 0"); bCaFromSelectedCell = getCaFromSelectedCell("D1055"); assert.strictEqual(bCaFromSelectedCell, true, "Test: SUMIF. 3 args. Recursion formula. Recursion criteria_range with DefName. D1055 - flag ca: true"); bCaFromSelectedCell = null; // - Case: SUMIF. 3 args. Recursion formula. Recursion sum_range with DefName. With disabled Iterative calculation setting. ws.getRange2("D1055").setValue("1"); ws.getRange2("D1057").setValue("=SUMIF(Criteria_range, A1056, sum_range)"); assert.strictEqual(ws.getRange2("D1057").getValue(), "0", "Test: SUMIF. 3 args. Recursion formula. Recursion sum_range with DefName. D1057 - 0"); bCaFromSelectedCell = getCaFromSelectedCell("D1057"); assert.strictEqual(bCaFromSelectedCell, true, "Test: SUMIF. 3 args. Recursion formula. Recursion sum_range with DefName. D1057 - flag ca: true"); bCaFromSelectedCell = null; // - Case: SUMIF. 3 args. Recursion formula. Recursion sum_range with DefName, but the cell with formula doesn't match with criteria. With disabled Iterative calculation setting. ws.getRange2("D1055").setValue("0"); ws.getRange2("D1057").setValue("=SUMIF(Criteria_range, A1056, sum_range)"); assert.strictEqual(ws.getRange2("D1057").getValue(), "10", "Test: SUMIF. 3 args. Recursion formula. Recursion sum_range with DefName, but the cell with formula doesn't match with criteria. D1057 - 10") bCaFromSelectedCell = getCaFromSelectedCell("D1057"); assert.strictEqual(bCaFromSelectedCell, false, "Test: SUMIF. 3 args. Recursion formula. Recursion sum_range with DefName, but the cell with formula doesn't match with criteria. D1057 - flag ca: false"); bCaFromSelectedCell = null; // - Case: SUMIF. 3 args. Recursion formula. Recursion criteria with DefName. With disabled Iterative calculation setting. ws.getRange2("D1055").setValue("0"); ws.getRange2("D1057").setValue("16"); ws.getRange2("A1056").setValue("1"); ws.getRange2("B1056").setValue("=SUMIF(Criteria_range, criteria, sum_range)"); assert.strictEqual(ws.getRange2("B1056").getValue(), "0", "Test: SUMIF. 3 args. Recursion formula. Recursion criteria with DefName. B1056 - 0") bCaFromSelectedCell = getCaFromSelectedCell("B1056"); assert.strictEqual(bCaFromSelectedCell, true, "Test: SUMIF. 3 args. Recursion formula. Recursion criteria with DefName. B1056 - flag ca: true"); bCaFromSelectedCell = null; wb.delDefinesNames(oCriteriaRangeName); wb.delDefinesNames(oCriteriaName); wb.delDefinesNames(oSumRangeName); oCriteriaRangeName = null; oCriteriaName = null; oSumRangeName = null; // - Case: SUMIFS. 3 args. Recursion formula. Recursion sum_range, but the cell with formula doesn't match with criteria. Criteria with formula. With disabled Iterative calculation setting. ws.getRange2("A1058").setValue("2"); ws.getRange2("B1058").setValue("4"); ws.getRange2("C1058").setValue("8"); ws.getRange2("A1059").setValue("09/15/2024"); ws.getRange2("B1059").setValue("09/16/2024"); ws.getRange2("C1059").setValue("09/17/2024"); ws.getRange2("D1059").setValue("09/18/2024"); ws.getRange2("D1058").setValue("=SUMIFS(A1058:D1058, A1059:D1059, DATE(2024, 9, 17))"); assert.strictEqual(ws.getRange2("D1058").getValue(), "8", "Test: SUMIFS. 3 args. Recursion formula. Recursion sum_range, but the cell with formula doesn't match with criteria. Criteria with formula. D1058 - 8"); bCaFromSelectedCell = getCaFromSelectedCell("D1058"); assert.strictEqual(bCaFromSelectedCell, false, "Test: SUMIFS. 3 args. Recursion formula. Recursion sum_range, but the cell with formula doesn't match with criteria. Criteria with formula. D1058 - flag ca: false"); bCaFromSelectedCell = null; // - Case: SUMIFS. 3 args. Recursion formula. Recursion sum_range,the cell with formula matches with criteria. Criteria with formula. With disabled Iterative calculation setting. ws.getRange2("D1058").setValue("=SUMIFS(A1058:D1058, A1059:D1059, DATE(2024, 9, 18))"); assert.strictEqual(ws.getRange2("D1058").getValue(), "0", "Test: SUMIFS. 3 args. Recursion formula. Recursion sum_range,the cell with formula matches with criteria. Criteria with formula. D1058 - 0"); bCaFromSelectedCell = getCaFromSelectedCell("D1058"); assert.strictEqual(bCaFromSelectedCell, true, "Test: SUMIFS. 3 args. Recursion formula. Recursion sum_range,the cell with formula matches with criteria. Criteria with formula. D1058 - flag ca: true"); bCaFromSelectedCell = null; // - Case: SUMIFS. 5 args. Recursion formula. Recursion sum_range, but the cell with formula doesn't match with criterias. With disabled Iterative calculation setting. // sum_range row ws.getRange2("A1060").setValue("5"); ws.getRange2("B1060").setValue("4"); ws.getRange2("C1060").setValue("11"); ws.getRange2("D1060").setValue("3"); // criteria_range row ws.getRange2("A1061").setValue("Apples"); ws.getRange2("B1061").setValue("Bananas"); ws.getRange2("C1061").setValue("Artichokes"); ws.getRange2("D1061").setValue("Apples"); ws.getRange2("E1061").setValue("Bananas"); // criteria row ws.getRange2("A1062").setValue("<>Bananas"); // criteria_range2 row ws.getRange2("A1063").setValue("Sarah"); ws.getRange2("B1063").setValue("Tom"); ws.getRange2("C1063").setValue("Sarah"); ws.getRange2("D1063").setValue("Tom"); ws.getRange2("E1063").setValue("Sarah"); // criteria2 row ws.getRange2("A1064").setValue("Tom"); // formula ws.getRange2("E1060").setValue("=SUMIFS(A1060:E1060, A1061:E1061, A1062, A1063:E1063, A1064)"); assert.strictEqual(ws.getRange2("E1060").getValue(), "3", "Test: SUMIFS. 5 args. Recursion formula. Recursion sum_range, but the cell with formula doesn't match with criterias. E1060 - 3"); bCaFromSelectedCell = getCaFromSelectedCell("E1060"); assert.strictEqual(bCaFromSelectedCell, false, "Test: SUMIFS. 5 args. Recursion formula. Recursion sum_range, but the cell with formula doesn't match with criterias. E1060 - flag ca: false"); bCaFromSelectedCell = null; // - Case: SUMIFS. 5 args. Recursion formula. Recursion sum_range,the cell with formula 1 criteria is matches 2 is not. With disabled Iterative calculation setting. ws.getRange2("E1061").setValue("Apples"); ws.getRange2("E1060").setValue("=SUMIFS(A1060:E1060, A1061:E1061, A1062, A1063:E1063, A1064)"); assert.strictEqual(ws.getRange2("E1060").getValue(), "3", "Test: SUMIFS. 5 args. Recursion formula. Recursion sum_range,the cell with formula 1 criteria is matches 2 is not. E1060 - 3"); bCaFromSelectedCell = getCaFromSelectedCell("E1060"); assert.strictEqual(bCaFromSelectedCell, false, "Test: SUMIFS. 5 args. Recursion formula. Recursion sum_range,the cell with formula 1 criteria is matches 2 is not. E1060 - flag ca: false"); bCaFromSelectedCell = null; // - Case: SUMIFS. 5 args. Recursion formula. Recursion sum_range, the cell with formula - 1 criteria doesn't match 2 is matches. With disabled Iterative calculation setting. ws.getRange2("E1061").setValue("Bananas"); ws.getRange2("E1063").setValue("Tom"); ws.getRange2("E1060").setValue("=SUMIFS(A1060:E1060, A1061:E1061, A1062, A1063:E1063, A1064)"); assert.strictEqual(ws.getRange2("E1060").getValue(), "3", "Test: SUMIFS. 5 args. Recursion formula. Recursion sum_range, the cell with formula - 1 criteria doesn't match 2 is matches. E1060 - 3"); bCaFromSelectedCell = getCaFromSelectedCell("E1060"); assert.strictEqual(bCaFromSelectedCell, false, "Test: SUMIFS. 5 args. Recursion formula. Recursion sum_range, the cell with formula - 1 criteria doesn't match 2 is matches. E1060 - flag ca: false"); bCaFromSelectedCell = null; // - Case: SUMIFS. 5 args. Recursion formula. Recursion sum_range, the cell with formula both criterias match. With disabled Iterative calculation setting. ws.getRange2("E1061").setValue("Apples"); ws.getRange2("E1060").setValue("=SUMIFS(A1060:E1060, A1061:E1061, A1062, A1063:E1063, A1064)"); assert.strictEqual(ws.getRange2("E1060").getValue(), "0", "Test: SUMIFS. 5 args. Recursion formula. Recursion sum_range, the cell with formula both criterias match. E1060 - 0"); bCaFromSelectedCell = getCaFromSelectedCell("E1060"); assert.strictEqual(bCaFromSelectedCell, true, "Test: SUMIFS. 5 args. Recursion formula. Recursion sum_range, the cell with formula both criterias match. E1060 - flag ca: true"); bCaFromSelectedCell = null; // - Case: SUMIFS. 5 args. Recursion formula. Recursion criteria_range. With disabled Iterative calculation setting. ws.getRange2("E1060").setValue("3"); ws.getRange2("E1061").setValue("=SUMIFS(A1060:E1060, A1061:E1061, A1062, A1063:E1063, A1064)"); assert.strictEqual(ws.getRange2("E1061").getValue(), "0", "Test: SUMIFS. 5 args. Recursion formula. Recursion criteria_range. E1061 - 0"); bCaFromSelectedCell = getCaFromSelectedCell("E1061"); assert.strictEqual(bCaFromSelectedCell, true, "Test: SUMIFS. 5 args. Recursion formula. Recursion criteria_range. E1061 - flag ca: true"); bCaFromSelectedCell = null; // - Case: SUMIFS. 5 args. Recursion formula. Recursion criteria_range2, but criteria_range is not matches. With disabled Iterative calculation setting. ws.getRange2("E1061").setValue("Bananas"); ws.getRange2("E1063").setValue("=SUMIFS(A1060:E1060, A1061:E1061, A1062, A1063:E1063, A1064)"); assert.strictEqual(ws.getRange2("E1063").getValue(), "3", "Test: SUMIFS. 5 args. Recursion formula. Recursion criteria_range2, but criteria_range is not matches. E1063 - 3"); bCaFromSelectedCell = getCaFromSelectedCell("E1063"); assert.strictEqual(bCaFromSelectedCell, false, "Test: SUMIFS. 5 args. Recursion formula. Recursion criteria_range2, but criteria_range is not matches. E1063 - flag ca: false"); bCaFromSelectedCell = null; // - Case: SUMIFS. 5 args. Recursion formula. Recursion criteria_range2, but criteria_range is matches. With disabled Iterative calculation setting. ws.getRange2("E1061").setValue("Apples"); ws.getRange2("E1063").setValue("=SUMIFS(A1060:E1060, A1061:E1061, A1062, A1063:E1063, A1064)"); assert.strictEqual(ws.getRange2("E1063").getValue(), "0", "Test: SUMIFS. 5 args. Recursion formula. Recursion criteria_range2, but criteria_range is matches. E1063 - 0"); bCaFromSelectedCell = getCaFromSelectedCell("E1063"); assert.strictEqual(bCaFromSelectedCell, true, "Test: SUMIFS. 5 args. Recursion formula. Recursion criteria_range2, but criteria_range is matches. E1063 - flag ca: true"); bCaFromSelectedCell = null; // - Case: COUNTIFS. 4 args. Recursion formula. Recursion criteria_range2, but criteria_range isn't matches. With disabled Iterative calculation setting. // Criteria range ws.getRange2("A1064").setValue("100"); ws.getRange2("B1064").setValue("1000"); ws.getRange2("C1064").setValue("10000"); ws.getRange2("D1064").setValue("10"); ws.getRange2("E1064").setValue("0"); // Criteria ws.getRange2("A1065").setValue(">0"); // Criteria range 2 ws.getRange2("A1066").setValue("Bob"); ws.getRange2("B1066").setValue("Tom"); ws.getRange2("C1066").setValue("Bob"); ws.getRange2("D1066").setValue("Bob"); ws.getRange2("E1066").setValue("=COUNTIFS(A1064:E1064, A1065, A1066:E1066, A1067)"); // Criteria2 ws.getRange2("A1067").setValue("Bob") assert.strictEqual(ws.getRange2("E1066").getValue(), "3", "Test: COUNTIFS. 4 args. Recursion formula. Recursion criteria_range2, but criteria_range isn't matches. E1066 - 3"); bCaFromSelectedCell = getCaFromSelectedCell("E1066"); assert.strictEqual(bCaFromSelectedCell, false, "Test: COUNTIFS. 4 args. Recursion formula. Recursion criteria_range2, but criteria_range isn't matches. E1066 - flag ca: false"); bCaFromSelectedCell = null; // - Case: COUNTIFS. 4 args. Recursion formula. Recursion criteria_range2, but criteria_range is matches. With disabled Iterative calculation setting. ws.getRange2("E1064").setValue("10"); ws.getRange2("E1066").setValue("=COUNTIFS(A1064:E1064, A1065, A1066:E1066, A1067)"); assert.strictEqual(ws.getRange2("E1066").getValue(), "0", "Test: COUNTIFS. 4 args. Recursion formula. Recursion criteria_range2, but criteria_range is matches. E1066 - 0"); bCaFromSelectedCell = getCaFromSelectedCell("E1066"); assert.strictEqual(bCaFromSelectedCell, true, "Test: COUNTIFS. 4 args. Recursion formula. Recursion criteria_range2, but criteria_range is matches. E1066 - flag ca: true"); // - Case: IF. 3 args. Recursion formula. recursion value_false but it doesn't match. With disabled Iterative calculation setting. ws.getRange2("A1067").setValue("Yes"); ws.getRange2("B1067").setValue("23"); ws.getRange2("C1067").setValue("=IF(A1067 = \"Yes\", B1067, C1067)"); assert.strictEqual(ws.getRange2("C1067").getValue(), "23", "Test: IF. 3 args. Recursion formula. recursion value_false. C1067 - 23"); bCaFromSelectedCell = getCaFromSelectedCell("C1067"); assert.strictEqual(bCaFromSelectedCell, false, "Test: IF. 3 args. Recursion formula. recursion value_false. C1067 - flag ca: false"); bCaFromSelectedCell = null; // - Case: IF. 3 args. Recursion formula. Recursion value_false but it matches. With disabled Iterative calculation setting. ws.getRange2("C1067").setValue("=IF(A1067 = \"No\", B1067, C1067)"); assert.strictEqual(ws.getRange2("C1067").getValue(), "0", "Test: IF. 3 args. Recursion formula. Recursion value_false. C1067 - 0"); bCaFromSelectedCell = getCaFromSelectedCell("C1067"); assert.strictEqual(bCaFromSelectedCell, true, "Test: IF. 3 args. Recursion formula. Recursion value_false. C1067 - flag ca: true"); bCaFromSelectedCell = null; // - Case: IF. 3 args. Recursion formula. logical_test is Ref. Recursion value_false, but it doesn't match. With disabled Iterative calculation setting. ws.getRange2("D1067").setValue("TRUE"); ws.getRange2("C1067").setValue("=IF(D1067, B1067, C1067"); assert.strictEqual(ws.getRange2("C1067").getValue(), "23", "Test: IF. 3 args. Recursion formula. logical_test is Ref. Recursion value_false, but it doesn't match. C1067 - 23"); bCaFromSelectedCell = getCaFromSelectedCell("C1067"); assert.strictEqual(bCaFromSelectedCell, false, "Test: IF. 3 args. Recursion formula. logical_test is Ref. Recursion value_false, but it doesn't match. C1067 - flag ca: false"); bCaFromSelectedCell = null; // - Case: IF. 3 args. Recursion formula. logical_test is Ref. Recursion value_false, but it matches. With disabled Iterative calculation setting. ws.getRange2("D1067").setValue("FALSE"); ws.getRange2("C1067").setValue("=IF(D1067, B1067, C1067"); assert.strictEqual(ws.getRange2("C1067").getValue(), "0", "Test: IF. 3 args. Recursion formula. logical_test is Ref. Recursion value_false, but it matches. C1067 - 0"); bCaFromSelectedCell = getCaFromSelectedCell("C1067"); assert.strictEqual(bCaFromSelectedCell, true, "Test: IF. 3 args. Recursion formula. logical_test is Ref. Recursion value_false, but it matches. C1067 - flag ca: true"); bCaFromSelectedCell = null; // - Case: IF. 3 args. Recursion formula.logical_test is DefName. Recursion value_false is DefName, but it doesn't match. With disabled Iterative calculation setting. let oLogicalTest = new Asc.asc_CDefName("logical_test", ws.getName() + "!$D$1067"); let oTrueValue = new Asc.asc_CDefName("true_value", ws.getName() + "!$B$1067"); let oFalseValue = new Asc.asc_CDefName("false_value", ws.getName() + "!$C$1067"); wb.editDefinesNames(null, oLogicalTest); wb.editDefinesNames(null, oTrueValue); wb.editDefinesNames(null, oFalseValue); ws.getRange2("D1067").setValue("TRUE"); ws.getRange2("C1067").setValue("=IF(logical_test, true_value, C1067)"); assert.strictEqual(ws.getRange2("C1067").getValue(), "23", "Case: IF. 3 args. Recursion formula.logical_test is DefName. Recursion value_false is DefName, but it doesn't match. C1067 - 23"); bCaFromSelectedCell = getCaFromSelectedCell("C1067"); assert.strictEqual(bCaFromSelectedCell, false, "Case: IF. 3 args. Recursion formula.logical_test is DefName. Recursion value_false is DefName, but it doesn't match. C1067 - flag ca: false"); bCaFromSelectedCell = null; // - Case: IF. 3 args. Recursion formula.logical_test is DefName. Recursion value_false is DefName, but it matches. With disabled Iterative calculation setting. ws.getRange2("D1067").setValue("FALSE"); ws.getRange2("C1067").setValue("=IF(logical_test, true_value, false_value)"); assert.strictEqual(ws.getRange2("C1067").getValue(), "0", "Case: IF. 3 args. Recursion formula.logical_test is DefName. Recursion value_false is DefName, but it matches. C1067 - 0"); bCaFromSelectedCell = getCaFromSelectedCell("C1067"); assert.strictEqual(bCaFromSelectedCell, true, "Case: IF. 3 args. Recursion formula.logical_test is DefName. Recursion value_false is DefName, but it matches. C1067 - flag ca: true"); bCaFromSelectedCell = null; wb.delDefinesNames(oLogicalTest); oLogicalTest = null; wb.delDefinesNames(oTrueValue); oTrueValue = null; wb.delDefinesNames(oFalseValue); oFalseValue = null; // - Case: IF. 3 args. Recursion formula. With operand function. One of condition is recursion, but it doesn't match. With disabled Iterative calculation setting. ws.getRange2("A1073").setValue("10"); ws.getRange2("B1073").setValue("=IF(A1073=10, 10, B1073)+IF(A1073=10, 10, B1073)"); assert.strictEqual(ws.getRange2("B1073").getValue(), "20", "Test: IF. 3 args. Recursion formula. With operand function. One of condition is recursion, but it doesn't match. B1073 - 20"); bCaFromSelectedCell = getCaFromSelectedCell("B1073"); assert.strictEqual(bCaFromSelectedCell, false, "Test: IF. 3 args. Recursion formula. With operand function. One of condition is recursion, but it doesn't match. B1073 - flag ca: false"); bCaFromSelectedCell = null; // - Case: IF. 3 args. Recursion formula. With operand function. One of condition is recursion but it matches. With disabled Iterative calculation setting. ws.getRange2("A1073").setValue("1"); ws.getRange2("B1073").setValue("=IF(A1073=10, 10, B1073)+IF(A1073=10, 10, B1073)"); assert.strictEqual(ws.getRange2("B1073").getValue(), "0", "Test: IF. 3 args. Recursion formula. With operand function. One of condition is recursion but it matches. B1073 - 0"); bCaFromSelectedCell = getCaFromSelectedCell("B1073"); assert.strictEqual(bCaFromSelectedCell, true, "Test: IF. 3 args. Recursion formula. With operand function. One of condition is recursion but it matches. B1073 - flag ca: true"); bCaFromSelectedCell = null; // - Case: IFS. 6 args. Recursion formula. One of condition is recursion, but it doesn't match. With disabled Iterative calculation setting. ws.getRange2("A1068").setValue("3"); ws.getRange2("B1068").setValue('=IFS(A1068=1, "First", A1068=2, B1068, A1068=3, "Third")'); assert.strictEqual(ws.getRange2("B1068").getValue(), "Third", "Test: IFS. 6 args. Recursion formula. One of condition is recursion but it doesn't match. B1068 - Third"); bCaFromSelectedCell = getCaFromSelectedCell("B1068"); assert.strictEqual(bCaFromSelectedCell, false, "Test: IFS. 6 args. Recursion formula. One of condition is recursion but it doesn't match. B1068 - flag ca: false"); bCaFromSelectedCell = null; // - Case: IFS. 6 args. Recursion formula. One of condition is recursion but it matches. With disabled Iterative calculation setting. ws.getRange2("A1068").setValue("2"); ws.getRange2("B1068").setValue('=IFS(A1068=1, "First", A1068=2, B1068, A1068=3, "Third")'); assert.strictEqual(ws.getRange2("B1068").getValue(), "0", "Test: IFS. 6 args. Recursion formula. One of condition is recursion but it matches. B1068 - 0"); bCaFromSelectedCell = getCaFromSelectedCell("B1068"); assert.strictEqual(bCaFromSelectedCell, true, "Test: IFS. 6 args. Recursion formula. One of condition is recursion but it matches. B1068 - flag ca: true"); bCaFromSelectedCell = null; // - Case: SWITCH. Without default_arg. One of result_arg has recursion, but it doesn't match. With disabled Iterative calculation setting. // expression ws.getRange2("A1069").setValue("3"); // values ws.getRange2("A1070").setValue("1"); ws.getRange2("B1070").setValue("2"); ws.getRange2("C1070").setValue("3"); ws.getRange2("D1070").setValue("4"); ws.getRange2("E1070").setValue("5"); // results ws.getRange2("A1071").setValue("Monday"); ws.getRange2("B1071").setValue("Wednesday"); ws.getRange2("C1071").setValue("Thursday"); ws.getRange2("D1071").setValue("Friday"); // formula ws.getRange2("A1072").setValue("=SWITCH(A1069,A1070, A1071, B1070, A1072, C1070, B1071, D1070, C1071, E1070, D1071)"); assert.strictEqual(ws.getRange2("A1072").getValue(), "Wednesday", "Test: SWITCH. Without default_arg. One of result_arg has recursion but it doesn't matches. A1072 - Wednesday"); bCaFromSelectedCell = getCaFromSelectedCell("A1072"); assert.strictEqual(bCaFromSelectedCell, false, "Test: SWITCH. Without default_arg. One of result_arg has recursion but it doesn't matches. A1072 - flag ca: false"); bCaFromSelectedCell = null; // - Case: SWITCH. Without default_arg. One of result_arg has recursion, but it matches. With disabled Iterative calculation setting. ws.getRange2("A1069").setValue("2"); ws.getRange2("A1072").setValue("=SWITCH(A1069,A1070, A1071, B1070, A1072, C1070, B1071, D1070, C1071, E1070, D1071)"); assert.strictEqual(ws.getRange2("A1072").getValue(), "0", "Test: SWITCH. Without default_arg. One of result_arg has recursion but it matches. A1072 - 0"); bCaFromSelectedCell = getCaFromSelectedCell("A1072"); assert.strictEqual(bCaFromSelectedCell, true, "Test: SWITCH. Without default_arg. One of result_arg has recursion but it matches. A1072 - flag ca: true"); bCaFromSelectedCell = null; // - Case: SWITCH. With default_arg. Default_arg has recursion, but it doesn't match. With disabled Iterative calculation setting. ws.getRange2("A1069").setValue("7"); // default_arg ws.getRange2("E1071").setValue("Unknown day of week"); ws.getRange2("A1072").setValue("=SWITCH(A1069,A1070, A1071, B1070, A1072, C1070, B1071, D1070, C1071, E1070, D1071, E1071)"); assert.strictEqual(ws.getRange2("A1072").getValue(), "Unknown day of week", "Test: SWITCH. With default_arg. Default_arg has recursion but it doesn't matches. A1072 - Unknown day of week"); bCaFromSelectedCell = getCaFromSelectedCell("A1072"); assert.strictEqual(bCaFromSelectedCell, false, "Test: SWITCH. With default_arg. Default_arg has recursion but it doesn't matches. A1072 - flag ca: false"); bCaFromSelectedCell = null; // - Case: SWITCH. With default_arg. Default_arg has recursion, but it matches. With disabled Iterative calculation setting. ws.getRange2("A1072").setValue("=SWITCH(A1069,A1070, A1071, B1070, A1072, C1070, B1071, D1070, C1071, E1070, D1071, A1072)"); assert.strictEqual(ws.getRange2("A1072").getValue(), "0", "Test: SWITCH. With default_arg. Default_arg has recursion but it matches. A1072 - 0"); bCaFromSelectedCell = getCaFromSelectedCell("A1072"); assert.strictEqual(bCaFromSelectedCell, true, "Test: SWITCH. With default_arg. Default_arg has recursion but it matches. A1072 - flag ca: true"); bCaFromSelectedCell = null; // - Case: Exception formula "CELL" that ignores rules of recursion recognition ws.getRange2("A1073").setValue("=CELL(\"filename\",A1073)"); assert.strictEqual(ws.getRange2("A1073").getValue(), "[TeSt.xlsx]Sheet1", "Test: Exception formulas that ignores rules of recursion recognition. A1073 - 1039. Formula - CELL"); bCaFromSelectedCell = getCaFromSelectedCell("A1073"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Exception formulas that ignores rules of recursion recognition. A1039 - flag ca: true"); bCaFromSelectedCell = null; // - Case: Chain without recursion. B1074 <- A1075 <- D1075 <- E1075 <- F1075. With disabled Iterative calculation setting. Case from bug-71996 // year field ws.getRange2("A1074").setValue("2024"); // month field ws.getRange2("B1074").setValue("=DATE(A1074, SHEET(),1"); // time break ws.getRange2("C1074").setValue("0.02"); ws.getRange2("D1074").setValue("0.03"); ws.getRange2("E1074").setValue("0.33"); // additional field ws.getRange2("F1074").setValue("=IF(MONTH(B1074)=1;$G$1074;INDIRECT(TEXT(DATE(YEAR(B1074);MONTH(B1074)-1;1);\"MMM\") & \"!F39\"))"); ws.getRange2("G1074").setValue("0"); // main chain ws.getRange2("A1075").setValue("=B1074"); ws.getRange2("B1075").setValue("0"); ws.getRange2("C1075").setValue("0"); ws.getRange2("D1075").setValue("=IF(ISNUMBER($A1075);IF((C1075-B1075)-$E$1074;G1075=\"kA\");(F1074+E1075);TIME(0;0;0));\"\")"); ws.getRange2("G1075").setValue("Neujahr"); ws.getRange2("H1075").setValue("X"); // Checking via initStartCellForIterCalc method that cells haven't recursion oCell = selectCell("A1075"); let bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, false, "Test: Chain without recursion. B1074 <- A1075 <- D1075 <- E1075 <- F1075. With disabled Iterative calculation setting. Case from bug-71996. A1075 - false"); bCellHasRecursion = null; g_cCalcRecursion.setStartCellIndex(null); oCell = selectCell("D1075"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, false, "Test: Chain without recursion. B1074 <- A1075 <- D1075 <- E1075 <- F1075. With disabled Iterative calculation setting. Case from bug-71996. D1075 - false"); bCellHasRecursion = null; g_cCalcRecursion.setStartCellIndex(null); oCell = selectCell("E1075"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, false, "Test: Chain without recursion. B1074 <- A1075 <- D1075 <- E1075 <- F1075. With disabled Iterative calculation setting. Case from bug-71996. E1075 - false"); bCellHasRecursion = null; g_cCalcRecursion.setStartCellIndex(null); oCell = selectCell("F1075"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, false, "Test: Chain without recursion. B1074 <- A1075 <- D1075 <- E1075 <- F1075. With disabled Iterative calculation setting. Case from bug-71996. F1075 - false"); bCellHasRecursion = null; g_cCalcRecursion.setStartCellIndex(null); // - Case: Chain with recursion. A1076->B1076. B1076 is simple formula without ca flag. // Enable recursion setting g_cCalcRecursion.setIsEnabledRecursion(true); ws.getRange2("A1076").setValue("=A1076+B1076"); ws.getRange2("B1076").setValue("=1"); assert.strictEqual(ws.getRange2("A1076").getValue(), "15", "Test: Chain with recursion. A1076->B1076. B1076 is simple formula without ca flag. A1076 - 15"); bCaFromSelectedCell = getCaFromSelectedCell("A1076"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Chain with recursion. A1076->B1076. B1076 is simple formula without ca flag. A1076 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("B1076"); assert.strictEqual(bCaFromSelectedCell, false, "Test: Chain with recursion. A1076->B1076. B1076 is simple formula without ca flag. B1076 - flag ca: false"); // - Case: Chain with recursion. A1077 -> B1077. B1077 is simple formula without ca flag. ws.getRange2("A1077").setValue("=A1077+B1077"); ws.getRange2("B1077").setValue("=1+2"); assert.strictEqual(ws.getRange2("A1077").getValue(), "45", "Test: Chain with recursion. A1077 -> B1077. B1077 is simple formula without ca flag. A1077 - 45"); bCaFromSelectedCell = getCaFromSelectedCell("A1077"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Chain with recursion. A1077 -> B1077. B1077 is simple formula without ca flag. A1077 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("B1077"); assert.strictEqual(bCaFromSelectedCell, false, "Test: Chain with recursion. A1077 -> B1077. B1077 is simple formula without ca flag. B1077 - flag ca: false"); bCaFromSelectedCell = null; // - Case: Chain with recursion. A1078 -> B1078 -> C1078. When B1078 has a ref to C1078 and C1078 - value. ws.getRange2("A1078").setValue("=A1078+B1078"); ws.getRange2("B1078").setValue("=C1078"); ws.getRange2("C1078").setValue("1"); assert.strictEqual(ws.getRange2("A1078").getValue(), "15", "Test: Chain with recursion. A1078 -> B1078 -> C1078. When B1078 has a ref to C1078 and C1078 - value. A1078 - 15"); bCaFromSelectedCell = getCaFromSelectedCell("A1078"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Chain with recursion. A1078 -> B1078 -> C1078. When B1078 has a ref to C1078 and C1078 - value. A1078 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("B1078"); assert.strictEqual(bCaFromSelectedCell, false, "Test: Chain with recursion. A1078 -> B1078 -> C1078. When B1078 has a ref to C1078 and C1078 - value. B1078 - flag ca: false"); bCaFromSelectedCell = null; // - Case: Chain with recursion. A1079 -> B1079 -> C1079. When B1079 has a ref to C1079. C1079 - simple formula. ws.getRange2("A1079").setValue("=A1079+B1079"); ws.getRange2("B1079").setValue("=C1079"); ws.getRange2("C1079").setValue("=1"); assert.strictEqual(ws.getRange2("A1079").getValue(), "15", "Test: Chain with recursion. A1079 -> B1079 -> C1079. When B1079 has a ref to C1079. C1079 - simple formula. A1079 - 15"); bCaFromSelectedCell = getCaFromSelectedCell("A1079"); assert.strictEqual(bCaFromSelectedCell, true, "Test: Chain with recursion. A1079 -> B1079 -> C1079. When B1079 has a ref to C1079. C1079 - simple formula. A1079 - flag ca: true"); bCaFromSelectedCell = null; bCaFromSelectedCell = getCaFromSelectedCell("B1079"); assert.strictEqual(bCaFromSelectedCell, false, "Test: Chain with recursion. A1079 -> B1079 -> C1079. When B1079 has a ref to C1079. C1079 - simple formula. B1079 - flag ca: false"); bCaFromSelectedCell = null; // - Case: Chain without recursion. A1081 -> B1080 -> A1082 -> B1081 -> A1083 using shared. With disabled recursion settings. Bug #73472 g_cCalcRecursion.setIsEnabledRecursion(false); ws.getRange2("A1080").setValue("5.96"); ws.getRange2("B1080").setValue("=A1080+2.92-MONTH(TODAY())") ws.getRange2("A1081").setValue("=IF(B1080 = \"\", \"\", B1080"); ws.getRange2("A1082").setValue("0"); ws.getRange2("A1083").setValue("0"); ws.getRange2("B1081").setValue("0"); ws.getRange2("B1082").setValue("0"); ws.getRange2("B1083").setValue("0"); // Create bbox and cellWithFormula. let bbox = ws.getRange2("A1081:A1083").bbox; let bbox1 = ws.getRange2("B1080:B1083").bbox; let cellWithFormula = new window['AscCommonExcel'].CCellWithFormula(ws, bbox.r1, bbox.c1); let cellWithFormula1 = new window['AscCommonExcel'].CCellWithFormula(ws, bbox1.r1, bbox1.c1); let oParser = selectCell("A1081").getFormulaParsed().clone(); let sharedRef = bbox.clone(); oParser.setShared(sharedRef, cellWithFormula); oParser.parse(); oParser.calculate(); oParser.ca = true; ws.getRange2("A1081:A1083")._foreachNoEmpty(function(oCell) { oCell.setFormulaParsed(oParser); oCell._BuildDependencies(true, true); }); oParser = selectCell("B1080").getFormulaParsed().clone(); sharedRef = bbox1.clone(); oParser.setShared(sharedRef, cellWithFormula1); oParser.parse(); oParser.calculate(); oParser.ca = true; ws.getRange2("B1080:B1083")._foreachNoEmpty(function(oCell) { oCell.setFormulaParsed(oParser); oCell._BuildDependencies(true, true); }); oCell = selectCell("B1080"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, false, "Test: Chain without recursion. A1081 -> B1080 -> A1082 -> B1081 -> A1083 using shared. With disabled recursion settings. Case from bug-73472. B1080 - false"); bCellHasRecursion = null; g_cCalcRecursion.setStartCellIndex(null); // - Case: Formula OFFSET mustn't recognize as recursive formula. Bug #74432 ws.getRange2("B1084").setValue("1"); ws.getRange2("C1084").setValue("=OFFSET(C1084, 0, -1)"); assert.strictEqual(ws.getRange2("C1084").getValue(), "1", "Test: Formula OFFSET mustn't recognize as recursive formula. Bug #74432. C1084 - 1"); oCell = selectCell("C1084"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, false, "Test: Formula OFFSET mustn't recognize as recursive formula. Bug #74432. C1084 - false"); bCellHasRecursion = null; // - Case: Formula ISFORMULA mustn't recognize as recursive. Is part of formula. Bug #74432 ws.getRange2("A1085").setValue("1"); ws.getRange2("B1085").setValue("=A1085+ISFORMULA(B1085)"); assert.strictEqual(ws.getRange2("B1085").getValue(), "2", "Test: Formula ISFORMULA mustn't recognize as recursive. Is part of formula. Bug #74432. B1085 - 2"); oCell = selectCell("B1085"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, false, "Test: Formula ISFORMULA mustn't recognize as recursive. Is part of formula. Bug #74432. B1085 - false"); bCellHasRecursion = null; // - Case: Formula ISFORMULA contains in recursive formula. Bug #74432 ws.getRange2("A1086").setValue("1"); ws.getRange2("B1086").setValue("=A1086+B1086+ISFORMULA(B1086)"); assert.strictEqual(ws.getRange2("B1086").getValue(), "0", "Test: Formula ISFORMULA contains in recursive formula. Bug #74432. B1086 - 0"); oCell = selectCell("B1086"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, true, "Test: Formula ISFORMULA contains in recursive formula. Bug #74432. B1086 - true"); bCellHasRecursion = null; // - Case: Formula ISFORMULA contains in recursive formula from chain. Bug #74432 ws.getRange2("A1087").setValue("1"); ws.getRange2("B1087").setValue("=C1087"); ws.getRange2("C1087").setValue("=A1087+B1087+ISFORMULA(C1087)"); assert.strictEqual(ws.getRange2("C1087").getValue(), "0", "Test: Formula ISFORMULA contains in recursive formula from chain. Bug #74432. C1087 - 0"); oCell = selectCell("C1087"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, true, "Test: Formula ISFORMULA contains in recursive formula from chain. Bug #74432. C1087 - true"); bCellHasRecursion = null; // - Case: Formula ISFORMULA containts in IF formula mustn't recursive. Bug #74432 ws.getRange2("A1088").setValue("1"); ws.getRange2("B1088").setValue("=IF(A1088 = 1,A1088+ISFORMULA(B1088), -1"); assert.strictEqual(ws.getRange2("B1088").getValue(), "2", "Test: Formula ISFORMULA containts in IF formula mustn't recursive. Bug #74432. B1088 - 2"); oCell = selectCell("B1088"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, false, "Test: Formula ISFORMULA containts in IF formula mustn't recursive. Bug #74432. B1088 - false"); bCellHasRecursion = null; // - Case: Formula ISFORMULA contains in IF formula has recursive element. Bug #74432 ws.getRange2("A1089").setValue("1"); ws.getRange2("B1089").setValue("=IF(A1089 = 1,A1089+B1089+ISFORMULA(B1089), -1"); assert.strictEqual(ws.getRange2("B1089").getValue(), "0", "Test: Formula ISFORMULA contains in IF formula has recursive element. Bug #74432. B1089 - 0"); oCell = selectCell("B1089"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, true, "Test: Formula ISFORMULA contains in IF formula has recursive element. Bug #74432. B1089 - true"); bCellHasRecursion = null; // - Case: Formula COLUMN mustn't recognize as recursive ws.getRange2("A1090").setValue("1"); ws.getRange2("B1090").setValue("=A1090+COLUMN(B1090)"); assert.strictEqual(ws.getRange2("B1090").getValue(), "3", "Test: Formula COLUMN mustn't recognize as recursive. B1090 - 3"); oCell = selectCell("B1090"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, false, "Test: Formula COLUMN mustn't recognize as recursive. B1090 - false"); bCellHasRecursion = null; // - Case: Formula COLUMN contains in recursive formula ws.getRange2("A1091").setValue("1"); ws.getRange2("B1091").setValue("=A1091+B1091+COLUMN(B1091)"); assert.strictEqual(ws.getRange2("B1091").getValue(), "0", "Test: Formula COLUMN contains in recursive formula. B1091 - 0"); oCell = selectCell("B1091"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, true, "Test: Formula COLUMN contains in recursive formula. B1091 - true"); bCellHasRecursion = null; // - Case: Formula COLUMN contains in recursive formula from chain ws.getRange2("A1092").setValue("1"); ws.getRange2("B1092").setValue("=C1092"); ws.getRange2("C1092").setValue("=A1092+B1092+COLUMN(C1092)"); assert.strictEqual(ws.getRange2("C1092").getValue(), "0", "Test: Formula COLUMN contains in recursive formula from chain. C1092 - 0"); oCell = selectCell("C1092"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, true, "Test: Formula COLUMN contains in recursive formula from chain. C1092 - true"); bCellHasRecursion = null; // - Case: Formula COLUMN in IF formula mustn't recursive ws.getRange2("A1093").setValue("1"); ws.getRange2("B1093").setValue("=IF(A1093 = 1, A1093+COLUMN(B1093), -1)"); assert.strictEqual(ws.getRange2("B1093").getValue(), "3", "Test: Formula COLUMN in IF formula mustn't recursive. B1093 - 3"); oCell = selectCell("B1093"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, false, "Test: Formula COLUMN in IF formula mustn't recursive. B1093 - false"); bCellHasRecursion = null; // - Case: Formula COLUMN contains in IF formula has recursive element ws.getRange2("A1094").setValue("1"); ws.getRange2("B1094").setValue("=IF(A1094 = 1, A1094+B1094+COLUMN(B1094), -1)"); assert.strictEqual(ws.getRange2("B1094").getValue(), "0", "Test: Formula COLUMN contains in IF formula has recursive element. B1094 - 0"); oCell = selectCell("B1094"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, true, "Test: Formula COLUMN contains in IF formula has recursive element. B1094 - true"); bCellHasRecursion = null; // - Case: Formula COLUMNS mustn't recognize as recursive. Is part of formula. ws.getRange2("A1095").setValue("1"); ws.getRange2("B1095").setValue("=A1095+COLUMNS(B1095)"); assert.strictEqual(ws.getRange2("B1095").getValue(), "2", "Test: Formula COLUMNS mustn't recognize as recursive. Is part of formula. B1095 - 2"); oCell = selectCell("B1095"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, false, "Test: Formula COLUMNS mustn't recognize as recursive. Is part of formula. B1095 - false"); bCellHasRecursion = null; // - Case: Formula COLUMNS contains in recursive formula ws.getRange2("A1096").setValue("1"); ws.getRange2("B1096").setValue("=A1096+B1096+COLUMNS(B1096)"); assert.strictEqual(ws.getRange2("B1096").getValue(), "0", "Test: Formula COLUMNS contains in recursive formula. B1096 - 0"); oCell = selectCell("B1096"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, true, "Test: Formula COLUMNS contains in recursive formula. B1096 - true"); bCellHasRecursion = null; // - Case: Formula COLUMNS contains in recursive formula from chain ws.getRange2("A1097").setValue("1"); ws.getRange2("B1097").setValue("=C1097"); ws.getRange2("C1097").setValue("=A1097+B1097+COLUMNS(C1097)"); assert.strictEqual(ws.getRange2("C1097").getValue(), "0", "Test: Formula COLUMNS contains in recursive formula from chain. C1097 - 0"); oCell = selectCell("C1097"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, true, "Test: Formula COLUMNS contains in recursive formula from chain. C1097 - true"); bCellHasRecursion = null; // - Case: Formula COLUMNS contains in IF formula mustn't recursive ws.getRange2("A1098").setValue("1"); ws.getRange2("B1098").setValue("=IF(A1098 = 1, A1098+COLUMNS(B1098), -1)"); assert.strictEqual(ws.getRange2("B1098").getValue(), "2", "Test: Formula COLUMNS contains in IF formula mustn't recursive. B1098 - 2"); oCell = selectCell("B1098"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, false, "Test: Formula COLUMNS contains in IF formula mustn't recursive. B1098 - false"); bCellHasRecursion = null; // - Case: Formula COLUMNS contains in IF formula has recursive element ws.getRange2("A1099").setValue("1"); ws.getRange2("B1099").setValue("=IF(A1099 = 1, A1099+B1099+COLUMNS(B1099), -1)"); assert.strictEqual(ws.getRange2("B1099").getValue(), "0", "Test: Formula COLUMNS contains in IF formula has recursive element. B1099 - 0"); oCell = selectCell("B1099"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, true, "Test: Formula COLUMNS contains in IF formula has recursive element. B1099 - true"); bCellHasRecursion = null; // - Case: Formula ROW mustn't recognize as recursive. Is part of formula. ws.getRange2("A1100").setValue("1"); ws.getRange2("B1100").setValue("=A1100+ROW(B1100)"); assert.strictEqual(ws.getRange2("B1100").getValue(), "1101", "Test: Formula ROW mustn't recognize as recursive. Is part of formula. B1100 - 1101"); oCell = selectCell("B1100"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, false, "Test: Formula ROW mustn't recognize as recursive. Is part of formula. B1100 - false"); bCellHasRecursion = null; // - Case: Formula ROW contains in recursive formula ws.getRange2("A1101").setValue("1"); ws.getRange2("B1101").setValue("=A1101+B1101+ROW(B1101)"); assert.strictEqual(ws.getRange2("B1101").getValue(), "0", "Test: Formula ROW contains in recursive formula. B1101 - 0"); oCell = selectCell("B1101"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, true, "Test: Formula ROW contains in recursive formula. B1101 - true"); bCellHasRecursion = null; // - Case: Formula ROW contains in recursive formula from chain ws.getRange2("A1102").setValue("1"); ws.getRange2("B1102").setValue("=C1102"); ws.getRange2("C1102").setValue("=A1102+B1102+ROW(C1102)"); assert.strictEqual(ws.getRange2("C1102").getValue(), "0", "Test: Formula ROW contains in recursive formula from chain. C1102 - 0"); oCell = selectCell("C1102"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, true, "Test: Formula ROW contains in recursive formula from chain. C1102 - true"); bCellHasRecursion = null; // - Case: Formula ROW contains in IF formula mustn't recursive ws.getRange2("A1103").setValue("1"); ws.getRange2("B1103").setValue("=IF(A1103 = 1, A1103+ROW(B1103), -1)"); assert.strictEqual(ws.getRange2("B1103").getValue(), "1104", "Test: Formula ROW contains in IF formula mustn't recursive. B1103 - 1104"); oCell = selectCell("B1103"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, false, "Test: Formula ROW contains in IF formula mustn't recursive. B1103 - false"); bCellHasRecursion = null; // - Case: Formula ROW contains in IF formula has recursive element ws.getRange2("A1104").setValue("1"); ws.getRange2("B1104").setValue("=IF(A1104 = 1, A1104+B1104+ROW(B1104), -1)"); assert.strictEqual(ws.getRange2("B1104").getValue(), "0", "Test: Formula ROW contains in IF formula has recursive element. B1104 - 0"); oCell = selectCell("B1104"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, true, "Test: Formula ROW contains in IF formula has recursive element. B1104 - true"); bCellHasRecursion = null; // - Case: Formula ROWS mustn't recognize as recursive. Is part of formula. ws.getRange2("A1105").setValue("1"); ws.getRange2("B1105").setValue("=A1105+ROWS(B1105:B1106)"); assert.strictEqual(ws.getRange2("B1105").getValue(), "3", "Test: Formula ROWS mustn't recognize as recursive. Is part of formula. B1105 - 4"); oCell = selectCell("B1105"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, false, "Test: Formula ROWS mustn't recognize as recursive. Is part of formula. B1105 - false"); bCellHasRecursion = null; // - Case: Formula ROWS contains in recursive formula ws.getRange2("A1107").setValue("1"); ws.getRange2("B1107").setValue("=A1107+B1107+ROWS(B1107:B1111)"); assert.strictEqual(ws.getRange2("B1107").getValue(), "0", "Test: Formula ROWS contains in recursive formula. B1107 - 0"); oCell = selectCell("B1107"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, true, "Test: Formula ROWS contains in recursive formula. B1107 - true"); bCellHasRecursion = null; // - Case: Formula ROWS contains in recursive formula from chain ws.getRange2("A1109").setValue("1"); ws.getRange2("B1109").setValue("=C1109"); ws.getRange2("C1109").setValue("=A1109+B1109+ROWS(C1109:C1110)"); assert.strictEqual(ws.getRange2("C1109").getValue(), "0", "Test: Formula ROWS contains in recursive formula from chain. C1109 - 0"); oCell = selectCell("C1109"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, true, "Test: Formula ROWS contains in recursive formula from chain. C1109 - true"); bCellHasRecursion = null; // - Case: Formula ROWS contains in IF formula mustn't recursive ws.getRange2("A1111").setValue("1"); ws.getRange2("B1111").setValue("=IF(A1111 = 1, A1111+ROWS(B1111:B1112), -1)"); assert.strictEqual(ws.getRange2("B1111").getValue(), "3", "Test: Formula ROWS contains in IF formula mustn't recursive. B1111 - 3"); oCell = selectCell("B1111"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, false, "Test: Formula ROWS contains in IF formula mustn't recursive. B1111 - false"); bCellHasRecursion = null; // - Case: Formula ROWS contains in IF formula has recursive element ws.getRange2("A1112").setValue("1"); ws.getRange2("B1112").setValue("=IF(A1112 = 1, A1112+B1112+ROWS(B1112:B1113), -1)"); assert.strictEqual(ws.getRange2("B1112").getValue(), "0", "Test: Formula ROWS contains in IF formula has recursive element. B1112 - 0"); oCell = selectCell("B1112"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, true, "Test: Formula ROWS contains in IF formula has recursive element. B1112 - true"); bCellHasRecursion = null; // - Case: Formula SHEETS mustn't recognize as recursive. Is part of formula. ws.getRange2("A1113").setValue("1"); ws.getRange2("B1113").setValue("=A1113+SHEETS(B1113)"); assert.strictEqual(ws.getRange2("B1113").getValue(), "2", "Test: Formula SHEETS mustn't recognize as recursive. Is part of formula. B1113 - 2"); oCell = selectCell("B1113"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, false, "Test: Formula SHEETS mustn't recognize as recursive. Is part of formula. B1113 - false"); bCellHasRecursion = null; // - Case: Formula SHEETS contains in recursive formula ws.getRange2("A1114").setValue("1"); ws.getRange2("B1114").setValue("=A1114+B1114+SHEETS(B1114)"); assert.strictEqual(ws.getRange2("B1114").getValue(), "0", "Test: Formula SHEETS contains in recursive formula. B1114 - 0"); oCell = selectCell("B1114"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, true, "Test: Formula SHEETS contains in recursive formula. B1114 - true"); bCellHasRecursion = null; // - Case: Formula SHEETS contains in recursive formula from chain ws.getRange2("A1115").setValue("1"); ws.getRange2("B1115").setValue("=C1115"); ws.getRange2("C1115").setValue("=A1115+B1115+SHEETS(C1115)"); assert.strictEqual(ws.getRange2("C1115").getValue(), "0", "Test: Formula SHEETS contains in recursive formula from chain. C1115 - 0"); oCell = selectCell("C1115"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, true, "Test: Formula SHEETS contains in recursive formula from chain. C1115 - true"); bCellHasRecursion = null; // - Case: Formula SHEETS contains in IF formula mustn't recursive ws.getRange2("A1116").setValue("1"); ws.getRange2("B1116").setValue("=IF(A1116 = 1, A1116+SHEETS(B1116), -1)"); assert.strictEqual(ws.getRange2("B1116").getValue(), "2", "Test: Formula SHEETS contains in IF formula mustn't recursive. B1116 - 2"); oCell = selectCell("B1116"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, false, "Test: Formula SHEETS contains in IF formula mustn't recursive. B1116 - false"); bCellHasRecursion = null; // - Case: Formula SHEETS contains in IF formula has recursive element ws.getRange2("A1117").setValue("1"); ws.getRange2("B1117").setValue("=IF(A1117 = 1, A1117+B1117+SHEETS(B1117), -1)"); assert.strictEqual(ws.getRange2("B1117").getValue(), "0", "Test: Formula SHEETS contains in IF formula has recursive element. B1117 - 0"); oCell = selectCell("B1117"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, true, "Test: Formula SHEETS contains in IF formula has recursive element. B1117 - true"); bCellHasRecursion = null; // - Case: Formula CELL mustn't recognize as recursive. Is part of formula. ws.getRange2("A1117").setValue("1"); ws.getRange2("B1117").setValue("=A1117+CELL(\"col\", B1117)"); assert.strictEqual(ws.getRange2("B1117").getValue(), "3", "Test: Formula CELL mustn't recognize as recursive. Is part of formula. B1117 - 3"); oCell = selectCell("B1117"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, false, "Test: Formula CELL mustn't recognize as recursive. Is part of formula. B1117 - false"); bCellHasRecursion = null; // - Case: Formula CELL contains in recursive formula ws.getRange2("A1118").setValue("1"); ws.getRange2("B1118").setValue("=A1118+B1118+CELL(\"col\", B1118)"); assert.strictEqual(ws.getRange2("B1118").getValue(), "0", "Test: Formula CELL contains in recursive formula. B1118 - 0"); oCell = selectCell("B1118"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, true, "Test: Formula CELL contains in recursive formula. B1118 - true"); bCellHasRecursion = null; // - Case: Formula CELL contains in recursive formula from chain ws.getRange2("A1119").setValue("1"); ws.getRange2("B1119").setValue("=C1119"); ws.getRange2("C1119").setValue("=A1119+B1119+CELL(\"col\", C1119)"); assert.strictEqual(ws.getRange2("C1119").getValue(), "0", "Test: Formula CELL contains in recursive formula from chain. C1119 - 0"); oCell = selectCell("C1119"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, true, "Test: Formula CELL contains in recursive formula from chain. C1119 - true"); bCellHasRecursion = null; // - Case: Formula CELL contains in IF formula mustn't recursive ws.getRange2("A1120").setValue("1"); ws.getRange2("B1120").setValue("=IF(A1120 = 1, A1120+CELL(\"col\", B1120), -1)"); assert.strictEqual(ws.getRange2("B1120").getValue(), "3", "Test: Formula CELL contains in IF formula mustn't recursive. B1120 - 3"); oCell = selectCell("B1120"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, false, "Test: Formula CELL contains in IF formula mustn't recursive. B1120 - false"); bCellHasRecursion = null; // - Case: Formula CELL contains in IF formula has recursive element ws.getRange2("A1121").setValue("1"); ws.getRange2("B1121").setValue("=IF(A1121 = 1, A1121+B1121+CELL(\"col\", B1121), -1)"); assert.strictEqual(ws.getRange2("B1121").getValue(), "0", "Test: Formula CELL contains in IF formula has recursive element. B1121 - 0"); oCell = selectCell("B1121"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, true, "Test: Formula CELL contains in IF formula has recursive element. B1121 - true"); bCellHasRecursion = null; // - Case: Formula INDIRECT mustn't recognize as recursive. ws.getRange2("A1122").setValue("1"); ws.getRange2("B1122").setValue("=INDIRECT(\"A1122\")"); assert.strictEqual(ws.getRange2("B1122").getValue(), "1", "Test: Formula INDIRECT mustn't recognize as recursive. B1122 - 1"); // - Case: Formula INDIRECT is recursive formula. ws.getRange2("A1123").setValue("=INDIRECT(\"A1123\")"); assert.strictEqual(ws.getRange2("A1123").getValue(), "0", "Test: Formula INDIRECT is recursive formula. A1123 - 0"); // - Case: Formula INDIRECT is recursive formula via chain. ws.getRange2("A1124").setValue("=B1124"); ws.getRange2("B1124").setValue("=INDIRECT(\"A1124\")"); assert.strictEqual(ws.getRange2("B1124").getValue(), "0", "Test: Formula INDIRECT is recursive formula via chain. B1124 - 0"); // - Case: Formula INDIRECT contains in FORMULA mustn't recognize as recursive. ws.getRange2("A1125").setValue("1"); ws.getRange2("B1125").setValue("=INDIRECT(\"A1125\") + A1125"); assert.strictEqual(ws.getRange2("B1125").getValue(), "2", "Test: Formula INDIRECT contains in FORMULA mustn't recognize as recursive. B1125 - 2"); // - Case: Formula INDIRECT contains in FORMULA recognize as recursive. ws.getRange2("A1126").setValue("1"); ws.getRange2("B1126").setValue("=A1126+B1126+INDIRECT(\"A1126\")"); assert.strictEqual(ws.getRange2("B1126").getValue(), "0", "Test: Formula INDIRECT contains in FORMULA recognize as recursive. B1126 - 0"); // - Case: Formula OFFSET is recursive formula. ws.getRange2("A1127").setValue("=OFFSET(A1127, 0, 0)"); assert.strictEqual(ws.getRange2("A1127").getValue(), "0", "Test: Formula OFFSET is recursive formula. A1127 - 0"); // - Case: Formula OFFSET is recursive formula by chain. ws.getRange2("A1128").setValue("=B1128"); ws.getRange2("B1128").setValue("=OFFSET(B1128, 0, -1)"); assert.strictEqual(ws.getRange2("B1128").getValue(), "0", "Test: Formula OFFSET is recursive formula by chain. B1128 - 0"); // - Case: Formula OFFSET contains in recursive formula. ws.getRange2("A1129").setValue("1"); ws.getRange2("B1129").setValue("=A1129+B1129+OFFSET(B1129, 0, -1)"); assert.strictEqual(ws.getRange2("B1129").getValue(), "0", "Test: Formula OFFSET contains in recursive formula. B1129 - 0"); // - Case: Formula CELL with type contents is recursive formula. ws.getRange2("A1130").setValue("=CELL(\"contents\", A1130)"); assert.strictEqual(ws.getRange2("A1130").getValue(), "0", "Test: Formula CELL with type contents is recursive formula. A1130 - 0"); // - Case: Formula INDIRECT - recursive cell with enabled setting. g_cCalcRecursion.setIsEnabledRecursion(true); ws.getRange2("A1131").setValue("=INDIRECT(\"A1131\")+1"); assert.strictEqual(ws.getRange2("A1131").getValue(), "15", "Test: Formula INDIRECT - recursive cell with enabled setting. A1131 - 15"); // - Case: Formula OFFSET isn't recursive cell with disabled setting. g_cCalcRecursion.setIsEnabledRecursion(false); ws.getRange2("B1132").setValue("5"); ws.getRange2("C1132").setValue("0"); ws.getRange2("D1132").setValue("0"); ws.getRange2("A1132").setValue("=OFFSET(B1132,0,0)-C1132-D1132"); ws.getRange2("A1133").setValue("=OFFSET(A1132,0,0)"); assert.strictEqual(ws.getRange2("A1133").getValue(), "5", "Test: Formula OFFSET isn't recursive cell with disabled setting. A1133 - 5"); assert.strictEqual(ws.getRange2("A1132").getValue(), "5", "Test: Formula OFFSET isn't recursive cell with disabled setting. A1132 - 5"); // - Case: Formula INDIRECT Ref3D isn't recursive cell with disabled setting. Bug-76318 ws2 = wb.createWorksheet(0, "Sheet2"); ws2.getRange2("A1134").setValue('=INDIRECT("Sheet1!A1134")'); ws.getRange2("A1134").setValue("123"); assert.strictEqual(ws2.getRange2("A1134").getValue(), "123", "Test: Formula INDIRECT Ref3D isn't recursive cell with disabled setting. Bug-76318. A1134 - 123"); oCell = selectCell("A1134", ws2); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, false, "Test: Formula INDIRECT Ref3D isn't recursive cell with disabled setting. Bug-76318. A1134 - false"); bCellHasRecursion = null; wb.removeWorksheet(0); // - Case: Formula SHEET isn't recursive cell with disabled setting. Bug-77330 ws2 = wb.createWorksheet(0, "Sheet2"); let oDefNameSHEET = new Asc.asc_CDefName("TestSHEET", ws2.getName() + "!$A$2:$E$5"); wb.editDefinesNames(null, oDefNameSHEET); ws.getRange2("A1135").setValue('=SHEET(TestSHEET)'); oCell = selectCell("A1135"); bCellHasRecursion = !!getStartCellForIterCalc(oCell); assert.strictEqual(bCellHasRecursion, false, "Test: Formula SHEET isn't recursive cell with disabled setting. Bug-77330. A1135 - false"); bCellHasRecursion = null; wb.delDefinesNames(oDefNameSHEET); wb.removeWorksheet(0); // -- Test changeLinkedCell method. oCell = selectCell("A1000"); let oCellNeedEnableRecalc = selectCell("B1000"); assert.strictEqual(oCellNeedEnableRecalc.getIsDirty(), false, "Test: changeLinkedCell. Before: Cell B1000 isDirty - false"); oCell.changeLinkedCell(function(oCell) { if (oCell.isFormula && !oCell.getIsDirty()) { oCell.setIsDirty(true); } }, true); oCellNeedEnableRecalc = selectCell("B1000"); assert.strictEqual(oCellNeedEnableRecalc.getIsDirty(), true, "Test: changeLinkedCell. After: Cell B1000 isDirty - true"); // -- Test initStartCellForIterCalc method // - Case: Sequence chain A1000 -> B1000 -> C1000 nExpectedCellIndex = AscCommonExcel.getCellIndex(999, 0); oCell = selectCell("C1000"); oFactCellIndex = getStartCellForIterCalc(oCell); assert.strictEqual(oFactCellIndex.cellId, nExpectedCellIndex, `Test: initStartCellForIterCalc. Sequence chain - A1000 -> B1000 -> C1000. Selected cell: C1000. Start cell index: ${oFactCellIndex.cellId}`); g_cCalcRecursion.setStartCellIndex(null); oCell = selectCell("B1000"); oFactCellIndex = getStartCellForIterCalc(oCell); assert.strictEqual(oFactCellIndex.cellId, nExpectedCellIndex, `Test: initStartCellForIterCalc. Sequence chain - A1000 -> B1000 -> C1000. Selected cell: B1000. Start cell index: ${oFactCellIndex.cellId}`); g_cCalcRecursion.setStartCellIndex(null); oCell = selectCell("A1000"); oFactCellIndex = getStartCellForIterCalc(oCell); assert.strictEqual(oFactCellIndex.cellId, nExpectedCellIndex, `Test: initStartCellForIterCalc. Sequence chain - A1000 -> B1000 -> C1000. Selected cell: A1000. Start cell: ${oFactCellIndex.cellId}`); g_cCalcRecursion.setStartCellIndex(null); // - Case: Loop chain D1000 <-> F1000 oCell = selectCell("D1000"); oFactCellIndex = getStartCellForIterCalc(oCell); nExpectedCellIndex = AscCommonExcel.getCellIndex(999, 3); assert.strictEqual(oFactCellIndex.cellId, nExpectedCellIndex, `Test: initStartCellForIterCalc. Loop chain - D1000 <-> F1000. Selected cell: D1000. Start cell: ${oFactCellIndex.cellId}`); g_cCalcRecursion.setStartCellIndex(null); oCell = selectCell("F1000"); oFactCellIndex = getStartCellForIterCalc(oCell); nExpectedCellIndex = AscCommonExcel.getCellIndex(999, 3); assert.strictEqual(oFactCellIndex.cellId, nExpectedCellIndex, `Test: initStartCellForIterCalc. Loop chain - D1000 <-> F1000. Selected cell: F1000. Start cell: ${oFactCellIndex.cellId}`); g_cCalcRecursion.setStartCellIndex(null); // - Case: Loop cell oCell = selectCell("A1001"); oFactCellIndex = getStartCellForIterCalc(oCell); nExpectedCellIndex = AscCommonExcel.getCellIndex(1000, 0); assert.strictEqual(oFactCellIndex.cellId, nExpectedCellIndex, `Test: initStartCellForIterCalc. Loop cell - A1001. Selected cell: A1001. Start cell: ${oFactCellIndex.cellId}`); g_cCalcRecursion.setStartCellIndex(null); // - Negative case: sequence chain without loop cell. oCell = selectCell("C1002"); oFactCellIndex = getStartCellForIterCalc(oCell); assert.strictEqual(oFactCellIndex, null, `Test: initStartCellForIterCalc. Negative case sequence chain without loop cell. Selected cell: C1002. Start cell: ${oFactCellIndex}`); oCell = selectCell("B1002"); oFactCellIndex = getStartCellForIterCalc(oCell); assert.strictEqual(oFactCellIndex, null, `Test: initStartCellForIterCalc. Negative case sequence chain without loop cell. Selected cell: B1002. Start cell: ${oFactCellIndex}`); oCell = selectCell("A1002"); oFactCellIndex = getStartCellForIterCalc(oCell); assert.strictEqual(oFactCellIndex, null, `Test: initStartCellForIterCalc. Negative case sequence chain without loop cell. Selected cell: A1002. Start cell: ${oFactCellIndex}`); // - Negative case: cell without any chain. oCell = selectCell("A1003"); oFactCellIndex = getStartCellForIterCalc(oCell); assert.strictEqual(oFactCellIndex, null, `Test: initStartCellForIterCalc. Negative case cell without any chain. Selected cell: A1003. Start cell: ${oFactCellIndex}`); oCell = selectCell("C1004"); oFactCellIndex = getStartCellForIterCalc(oCell); assert.strictEqual(oFactCellIndex, null, `Test: initStartCellForIterCalc. Negative case cell without any chain. Selected cell: C1004. Start cell: ${oFactCellIndex}`); }); QUnit.test("Test: \"ABS\"", function (assert) { ws.getRange2("A22").setValue("-4"); oParser = new parserFormula("ABS(2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula("ABS(-2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula("ABS(A22)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); testArrayFormula(assert, "ABS"); }); QUnit.test("Test: \"Absolute reference\"", function (assert) { ws.getRange2("A7").setValue("1"); ws.getRange2("A8").setValue("2"); ws.getRange2("A9").setValue("3"); oParser = new parserFormula('A$7+A8', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); oParser = new parserFormula('A$7+A$8', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); oParser = new parserFormula('$A$7+$A$8', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); oParser = new parserFormula('SUM($A$7:$A$9)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 6); }); QUnit.test("Test: \"Asc\"", function (assert) { oParser = new parserFormula('ASC("teSt")', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "teSt"); oParser = new parserFormula('ASC("デジタル")', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "デジタル"); oParser = new parserFormula('ASC("￯")', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ""); }); QUnit.test("Test: \"Cross\"", function (assert) { ws.getRange2("A7").setValue("1"); ws.getRange2("A8").setValue("2"); ws.getRange2("A9").setValue("3"); let cellWithFormula = new AscCommonExcel.CCellWithFormula(ws, 0, 9); oParser = new parserFormula('A7:A9', cellWithFormula, ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().cross(new Asc.Range(0, 5, 0, 5), ws.getId()).getValue(), "#VALUE!"); assert.strictEqual(oParser.calculate().cross(new Asc.Range(0, 6, 0, 6), ws.getId()).getValue(), 1); assert.strictEqual(oParser.calculate().cross(new Asc.Range(0, 7, 0, 7), ws.getId()).getValue(), 2); assert.strictEqual(oParser.calculate().cross(new Asc.Range(0, 8, 0, 8), ws.getId()).getValue(), 3); assert.strictEqual(oParser.calculate().cross(new Asc.Range(0, 9, 0, 9), ws.getId()).getValue(), "#VALUE!"); }); QUnit.test("Test: \"Defined names cycle\"", function (assert) { AscCommonExcel.g_cCalcRecursion.setIsEnabledRecursion(false); var newNameQ = new Asc.asc_CDefName("q", "SUM('" + ws.getName() + "'!A2)"); wb.editDefinesNames(null, newNameQ); ws.getRange2("Q1").setValue("=q"); ws.getRange2("Q2").setValue("=q"); ws.getRange2("Q3").setValue("1"); assert.strictEqual(ws.getRange2("Q1").getValueWithFormat(), "1"); assert.strictEqual(ws.getRange2("Q2").getValueWithFormat(), "1"); var newNameW = new Asc.asc_CDefName("w", "'" + ws.getName() + "'!A1"); wb.editDefinesNames(null, newNameW); ws.getRange2("Q4").setValue("=w"); assert.strictEqual(ws.getRange2("Q4").getValueWithFormat(), "#NUM!"); //clean up ws.getRange2("Q1:Q4").cleanAll(); wb.delDefinesNames(newNameW); wb.delDefinesNames(newNameQ); }); QUnit.test("Test: \"Parse intersection\"", function (assert) { ws.getRange2("A7").setValue("1"); ws.getRange2("A8").setValue("2"); ws.getRange2("A9").setValue("3"); oParser = new parserFormula('1 + ( A7 +A8 ) * 2', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.assemble(), "1+(A7+A8)*2"); assert.strictEqual(oParser.calculate().getValue(), 7); oParser = new parserFormula('sum A1:A5', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.assemble(), "sum A1:A5"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula('sum( A1:A5 , B1:B5 ) ', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.assemble(), "SUM(A1:A5,B1:B5)"); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula('sum( A1:A5 , B1:B5 , " 3 , 14 15 92 6 " ) ', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.assemble(), 'SUM(A1:A5,B1:B5," 3 , 14 15 92 6 ")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); }); QUnit.test("Test: \"Range union operator tests\"", function (assert) { let array; ws.getRange2("A1").setValue("1"); ws.getRange2("A2").setValue("2"); ws.getRange2("A3").setValue("3"); ws.getRange2("A4").setValue("99"); ws.getRange2("B1").setValue("1"); ws.getRange2("B2").setValue("2"); ws.getRange2("B3").setValue("3"); ws.getRange2("C1").setValue("1"); ws.getRange2("C2").setValue("2"); ws.getRange2("C3").setValue("3"); ws.getRange2("F1").setValue("#NUM!"); ws.getRange2("F2").setValue("#DIV/0!"); ws.getRange2("F3").setValue("#N/A"); oParser = new parserFormula('SUMA2', 'A10', ws); assert.ok(oParser.parse(), 'SUMA2'); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", 'SUMA2'); oParser = new parserFormula('SUMA2:1', 'A10', ws); assert.ok(oParser.parse(), 'SUMA2:1'); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", 'SUMA2:1'); oParser = new parserFormula('SUMA2:A3', 'A10', ws); assert.ok(oParser.parse(), 'SUMA2:A3'); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", 'SUMA2:A3'); oParser = new parserFormula('SECB2', 'A10', ws); assert.ok(oParser.parse(), 'SECB2'); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", 'SECB2'); oParser = new parserFormula('SECB2:1', 'A10', ws); assert.ok(oParser.parse(), 'SECB2:1'); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", 'SECB2:1'); oParser = new parserFormula('SECB2:B3', 'A10', ws); assert.ok(oParser.parse(), 'SECB2:B3'); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", 'SECB2:B3'); oParser = new parserFormula('RANDC2', 'A10', ws); assert.ok(oParser.parse(), 'RANDC2'); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", 'RANDC2'); oParser = new parserFormula('RANDC2:1', 'A10', ws); assert.ok(oParser.parse(), 'RANDC2:1'); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", 'RANDC2:1'); oParser = new parserFormula('RANDC2:C3', 'A10', ws); assert.ok(oParser.parse(), 'RANDC2:C3'); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", 'RANDC2:C3'); oParser = new parserFormula('C1:C3', 'A10', ws); assert.ok(oParser.parse(), 'C1:C3'); array = oParser.calculate(); if (AscCommonExcel.cElementType.cellsRange === array.type || AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(0, 0).getValue() : array.getElementRowCol(0, 0).getValue(), 1, "Result of C1:C3[0,0]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(1, 0).getValue() : array.getElementRowCol(1, 0).getValue(), 2, "Result of C1:C3[1,0]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(2, 0).getValue() : array.getElementRowCol(2, 0).getValue(), 3, "Result of C1:C3[2,0]"); } oParser = new parserFormula('C2:C3:C2', 'A10', ws); assert.ok(oParser.parse(), 'C2:C3:C2'); array = oParser.calculate(); if (AscCommonExcel.cElementType.cellsRange === array.type || AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(0, 0).getValue() : array.getElementRowCol(0, 0).getValue(), 2, "Result of C2:C3:C2[0,0]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(1, 0).getValue() : array.getElementRowCol(1, 0).getValue(), 3, "Result of C2:C3:C2[1,0]"); } oParser = new parserFormula('(A1:A3):F1', 'A10', ws); assert.ok(oParser.parse(), '(A1:A3):F1'); array = oParser.calculate(); if (AscCommonExcel.cElementType.cellsRange === array.type || AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(0, 0).getValue() : array.getElementRowCol(0, 0).getValue(), 1, "Result of (A1:A3):F1[0,0]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(0, 1).getValue() : array.getElementRowCol(0, 1).getValue(), 1, "Result of (A1:A3):F1[0,1]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(0, 2).getValue() : array.getElementRowCol(0, 2).getValue(), 1, "Result of (A1:A3):F1[0,2]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(0, 5).getValue() : array.getElementRowCol(0, 5).getValue(), "#NUM!", "Result of (A1:A3):F1[0,5]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(1, 0).getValue() : array.getElementRowCol(1, 0).getValue(), 2, "Result of (A1:A3):F1[1,0]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(2, 0).getValue() : array.getElementRowCol(2, 0).getValue(), 3, "Result of (A1:A3):F1[2,0]"); } oParser = new parserFormula('F1:(A1:A3)', 'A10', ws); assert.ok(oParser.parse(), 'F1:(A1:A3)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.cellsRange === array.type || AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(0, 0).getValue() : array.getElementRowCol(0, 0).getValue(), 1, "Result of F1:(A1:A3)[0,0]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(0, 1).getValue() : array.getElementRowCol(0, 1).getValue(), 1, "Result of F1:(A1:A3)[0,1]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(0, 2).getValue() : array.getElementRowCol(0, 2).getValue(), 1, "Result of F1:(A1:A3)[0,2]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(0, 5).getValue() : array.getElementRowCol(0, 5).getValue(), "#NUM!", "Result of F1:(A1:A3)[0,5]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(1, 0).getValue() : array.getElementRowCol(1, 0).getValue(), 2, "Result of F1:(A1:A3)[1,0]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(2, 0).getValue() : array.getElementRowCol(2, 0).getValue(), 3, "Result of F1:(A1:A3)[2,0]"); } oParser = new parserFormula('F2:(A2)', 'A10', ws); assert.ok(oParser.parse(), 'F2:(A2)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.cellsRange === array.type || AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(0, 0).getValue() : array.getElementRowCol(0, 0).getValue(), 2, "Result of F2:(A2)[0,0]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(0, 1).getValue() : array.getElementRowCol(0, 1).getValue(), 2, "Result of F2:(A2)[0,1]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(0, 2).getValue() : array.getElementRowCol(0, 2).getValue(), 2, "Result of F2:(A2)[0,2]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(0, 5).getValue() : array.getElementRowCol(0, 5).getValue(), "#DIV/0!", "Result of F2:(A2)[0,5]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(1, 0).getValue() : array.getElementRowCol(1, 0).getValue(), 3, "Result of F2:(A2)[1,0]"); } oParser = new parserFormula('(A2):F2', 'A10', ws); assert.ok(oParser.parse(), '(A2):F2'); array = oParser.calculate(); if (AscCommonExcel.cElementType.cellsRange === array.type || AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(0, 0).getValue() : array.getElementRowCol(0, 0).getValue(), 2, "Result of (A2):F2[0,0]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(0, 1).getValue() : array.getElementRowCol(0, 1).getValue(), 2, "Result of (A2):F2[0,1]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(0, 2).getValue() : array.getElementRowCol(0, 2).getValue(), 2, "Result of (A2):F2[0,2]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(0, 5).getValue() : array.getElementRowCol(0, 5).getValue(), "#DIV/0!", "Result of (A2):F2[0,5]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(1, 0).getValue() : array.getElementRowCol(1, 0).getValue(), 3, "Result of (A2):F2[1,0]"); } oParser = new parserFormula('F2:(E1):A1:F2:F3:(A4)', 'A10', ws); assert.ok(oParser.parse(), 'F2:(E1):A1:F2:F3:(A4)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.cellsRange === array.type || AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(0, 0).getValue() : array.getElementRowCol(0, 0).getValue(), 1, "Result of F2:(E1):A1:F2:F3:(A4)[0,0]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(1, 0).getValue() : array.getElementRowCol(1, 0).getValue(), 2, "Result of F2:(E1):A1:F2:F3:(A4)[1,0]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(2, 0).getValue() : array.getElementRowCol(2, 0).getValue(), 3, "Result of F2:(E1):A1:F2:F3:(A4)[2,0]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(3, 0).getValue() : array.getElementRowCol(3, 0).getValue(), 99, "Result of F2:(E1):A1:F2:F3:(A4)[3,0]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(0, 1).getValue() : array.getElementRowCol(0, 1).getValue(), 1, "Result of F2:(E1):A1:F2:F3:(A4)[0,1]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(0, 2).getValue() : array.getElementRowCol(0, 2).getValue(), 1, "Result of F2:(E1):A1:F2:F3:(A4)[0,2]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(0, 5).getValue() : array.getElementRowCol(0, 5).getValue(), "#NUM!", "Result of F2:(E1):A1:F2:F3:(A4)[0,5]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(1, 5).getValue() : array.getElementRowCol(1, 5).getValue(), "#DIV/0!", "Result of F2:(E1):A1:F2:F3:(A4)[1,5]"); assert.strictEqual(array.getValueByRowCol ? array.getValueByRowCol(2, 5).getValue() : array.getElementRowCol(2, 5).getValue(), "#N/A", "Result of F2:(E1):A1:F2:F3:(A4)[2,5]"); } ws.getRange2("A1:Z100").cleanAll(); }); QUnit.test("Test: \"Arithmetical operations\"", function (assert) { let array; oParser = new parserFormula('1+3', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); oParser = new parserFormula('(1+2)*4+3', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), (1 + 2) * 4 + 3); oParser = new parserFormula('2^52', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), Math.pow(2, 52)); oParser = new parserFormula("(0)^(0)", "A1", ws); assert.ok(oParser.parse(), "(0)^(0)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of (0)^(0)"); // ms - #NUM!, js - 1, LO - 1, gs - 1 oParser = new parserFormula("(0)^(1)", "A1", ws); assert.ok(oParser.parse(), "(0)^(1)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of (0)^(1)"); oParser = new parserFormula("(0)^(-1)", "A1", ws); assert.ok(oParser.parse(), "(0)^(-1)"); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "Result of (0)^(-1)"); oParser = new parserFormula("(0)^(1/3)", "A1", ws); assert.ok(oParser.parse(), "(0)^(1/3)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of (0)^(1/3)"); oParser = new parserFormula("(0)^(-1/3)", "A1", ws); assert.ok(oParser.parse(), "(0)^(-1/3)"); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "Result of (0)^(-1/3)"); oParser = new parserFormula("(0)^(-3)", "A1", ws); assert.ok(oParser.parse(), "(0)^(-3)"); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "Result of (0)^(-3)"); oParser = new parserFormula("(1)^(-3)", "A1", ws); assert.ok(oParser.parse(), "(1)^(-3)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of (1)^(-3)"); oParser = new parserFormula("(1)^(-1/3)", "A1", ws); assert.ok(oParser.parse(), "(1)^(-1/3)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of (1)^(-1/3)"); oParser = new parserFormula("(1)^(1/3)", "A1", ws); assert.ok(oParser.parse(), "(1)^(1/3)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of (1)^(1/3)"); oParser = new parserFormula("(-1)^(1/2)", "A1", ws); assert.ok(oParser.parse(), "(-1)^(1/2)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of (-1)^(1/2)"); oParser = new parserFormula("(-1)^(1/3)", "A1", ws); assert.ok(oParser.parse(), "(-1)^(1/3)"); assert.strictEqual(oParser.calculate().getValue(), -1, "Result of (-1)^(1/3)"); oParser = new parserFormula("(-1)^(-1/3)", "A1", ws); assert.ok(oParser.parse(), "(-1)^(-1/3)"); assert.strictEqual(oParser.calculate().getValue(), -1, "Result of (-1)^(-1/3)"); oParser = new parserFormula("(-1)^(1/4)", "A1", ws); assert.ok(oParser.parse(), "(-1)^(1/4)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of (-1)^(1/4)"); oParser = new parserFormula("(-1)^(1/5)", "A1", ws); assert.ok(oParser.parse(), "(-1)^(1/5)"); assert.strictEqual(oParser.calculate().getValue(), -1, "Result of (-1)^(1/5)"); oParser = new parserFormula("(-8)^(1/3)", "A1", ws); assert.ok(oParser.parse(), "(-8)^(1/3)"); assert.strictEqual(oParser.calculate().getValue(), -2, "Result of (-8)^(1/3)"); oParser = new parserFormula("(-8)^(-1/3)", "A1", ws); assert.ok(oParser.parse(), "(-8)^(-1/3)"); assert.strictEqual(oParser.calculate().getValue(), -0.5, "Result of (-8)^(-1/3)"); oParser = new parserFormula("(-8)^(1/4)", "A1", ws); assert.ok(oParser.parse(), "(-8)^(1/4)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of (-8)^(1/4)"); oParser = new parserFormula("(-8)^(1/5)", "A1", ws); assert.ok(oParser.parse(), "(-8)^(1/5)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2), "-1.52", "Result of (-8)^(1/5)"); oParser = new parserFormula("(-8)^(-1/5)", "A1", ws); assert.ok(oParser.parse(), "(-8)^(-1/5)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2), "-0.66", "Result of (-8)^(-1/5)"); oParser = new parserFormula('-10', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -10); oParser = new parserFormula('-10*2', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -20); oParser = new parserFormula('-10+10', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula('12%', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0.12); oParser = new parserFormula("2<>\"3\"", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TRUE", "2<>\"3\""); oParser = new parserFormula("2=\"3\"", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "FALSE", "2=\"3\""); oParser = new parserFormula("2>\"3\"", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "FALSE", "2>\"3\""); oParser = new parserFormula("\"f\">\"3\"", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TRUE"); oParser = new parserFormula("\"f\"<\"3\"", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual("FALSE", oParser.calculate().getValue(), "FALSE"); oParser = new parserFormula("FALSE>=FALSE", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TRUE"); oParser = new parserFormula("\"TRUE\"&\"TRUE\"", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TRUETRUE"); oParser = new parserFormula("10*\"\"", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("-TRUE", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -1); oParser = new parserFormula('"test" = "test"', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TRUE"); oParser = new parserFormula('"tEsT" = "TeSt"', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TRUE"); oParser = new parserFormula('"TEST" = "TeSt"', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TRUE"); oParser = new parserFormula('"TEST" = "weSt"', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "FALSE"); ws.getRange2("K100:Z200").cleanAll(); ws.getRange2("M106").setValue("1"); ws.getRange2("M107").setValue("2"); ws.getRange2("M108").setValue("2"); ws.getRange2("M109").setValue("4"); ws.getRange2("M110").setValue("5"); ws.getRange2("M111").setValue("-23"); ws.getRange2("M112").setValue("6"); ws.getRange2("M113").setValue("5"); ws.getRange2("N106").setValue("1"); ws.getRange2("N107").setValue(""); ws.getRange2("N108").setValue(""); ws.getRange2("N109").setValue("3"); ws.getRange2("N110").setValue(""); ws.getRange2("N111").setValue("2"); ws.getRange2("N112").setValue(""); ws.getRange2("N113").setValue("3"); ws.getRange2("O106").setValue("1"); ws.getRange2("O107").setValue("3"); ws.getRange2("O108").setValue("2"); ws.getRange2("O109").setValue("12"); ws.getRange2("O110").setValue("3"); ws.getRange2("O111").setValue("4"); ws.getRange2("O112").setValue("3"); ws.getRange2("O113").setValue("2"); ws.getRange2("P106").setValue("3"); ws.getRange2("P107").setValue("4"); ws.getRange2("P108").setValue("5"); ws.getRange2("P109").setValue("1"); ws.getRange2("P110").setValue("23"); ws.getRange2("P111").setValue("4"); ws.getRange2("P112").setValue("3"); ws.getRange2("P113").setValue("1"); oParser = new parserFormula("M106:N107*O107:O107", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:H109").bbox); assert.ok(oParser.parse(), "M106:N107*O107:O107. Result - array 2x2"); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 3, "Array 2x2. [0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 6, "Array 2x2. [1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", "Array 2x2. [2,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, "Array 2x2. [0,1]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 0, "Array 2x2. [1,1]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "", "Array 2x2. [2,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "", "Array 2x2. [0,2]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "", "Array 2x2. [1,2]"); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "", "Array 2x2. [2,2]"); } oParser = new parserFormula("M106:N107+O107:O107", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:H109").bbox); assert.ok(oParser.parse(), "M106:N107+O107:O107. Result - array 2x2"); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 4, "Array 2x2. [0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 5, "Array 2x2. [1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", "Array 2x2. [2,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 4, "Array 2x2. [0,1]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 3, "Array 2x2. [1,1]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "", "Array 2x2. [2,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "", "Array 2x2. [0,2]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "", "Array 2x2. [1,2]"); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "", "Array 2x2. [2,2]"); } oParser = new parserFormula("M106:N107-O107:O107", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:H109").bbox); assert.ok(oParser.parse(), "M106:N107-O107:O107. Result - array 2x2"); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), -2, "Array 2x2. [0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), -1, "Array 2x2. [1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", "Array 2x2. [2,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), -2, "Array 2x2. [0,1]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), -3, "Array 2x2. [1,1]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "", "Array 2x2. [2,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "", "Array 2x2. [0,2]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "", "Array 2x2. [1,2]"); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "", "Array 2x2. [2,2]"); } oParser = new parserFormula("M106:N107/O107:O107", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:H109").bbox); assert.ok(oParser.parse(), "M106:N107/O107:O107. Result - array 2x2"); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue().toFixed(1), "0.3", "Array 2x2. [0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue().toFixed(1), "0.7", "Array 2x2. [1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", "Array 2x2. [2,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue().toFixed(1), "0.3", "Array 2x2. [0,1]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 0, "Array 2x2. [1,1]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "", "Array 2x2. [2,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "", "Array 2x2. [0,2]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "", "Array 2x2. [1,2]"); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "", "Array 2x2. [2,2]"); } // todo problem with cross in cPower // oParser = new parserFormula("M106:N107^O107:O107", "A1", ws); // oParser.setArrayFormulaRef(ws.getRange2("E106:H109").bbox); // assert.ok(oParser.parse(), "M106:N107^O107:O107. Result - array 2x2"); // array = oParser.calculate(); // if (AscCommonExcel.cElementType.array === array.type) { // assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Array 2x2. [0,0]"); // assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 8, "Array 2x2. [1,0]"); // assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", "Array 2x2. [2,0]"); // assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, "Array 2x2. [0,1]"); // assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 0, "Array 2x2. [1,1]"); // assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "", "Array 2x2. [2,1]"); // assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "", "Array 2x2. [0,2]"); // assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "", "Array 2x2. [1,2]"); // assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "", "Array 2x2. [2,2]"); // } oParser = new parserFormula("M106:N107*M106:O108", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:H109").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 4); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 0); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "#N/A"); } oParser = new parserFormula("M106:O108*M106:N107", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:H109").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 4); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 0); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "#N/A"); } oParser = new parserFormula("L105:O108*M106:N107", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:H109").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 0); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 0); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 0); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 0); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(3, 2).getValue(), "#N/A"); } ws.getRange2("A200").setValue("1"); ws.getRange2("A201").setValue("2"); ws.getRange2("A202").setValue("4"); ws.getRange2("B200").setValue("2"); ws.getRange2("B201").setValue("2"); ws.getRange2("B202").setValue("4"); ws.getRange2("C200").setValue("3"); ws.getRange2("D200").setValue("4"); ws.getRange2("E200").setValue("5"); oParser = new parserFormula("A200:E200*A200:B201", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:J110").bbox); assert.ok(oParser.parse(), "A200:E200*A200:B201. Result - array 2x5"); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Array 2x5. [0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, "Array 2x5. [1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", "Array 2x5. [2,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 4, "Array 2x5. [0,1]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, "Array 2x5. [1,1]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "", "Array 2x5. [2,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#N/A", "Array 2x5. [0,2]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "#N/A", "Array 2x5. [1,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "#N/A", "Array 2x5. [0,3]"); assert.strictEqual(array.getElementRowCol(1, 3).getValue(), "#N/A", "Array 2x5. [1,3]"); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), "#N/A", "Array 2x5. [0,4]"); assert.strictEqual(array.getElementRowCol(1, 4).getValue(), "#N/A", "Array 2x5. [1,4]"); } oParser = new parserFormula("A200:B201*A200:E200", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:J110").bbox); assert.ok(oParser.parse(), "A200:B201*A200:E200. Result - array 2x5"); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), ""); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 4); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), ""); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(1, 3).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(1, 4).getValue(), "#N/A"); } oParser = new parserFormula("A200:E200*A200:B202", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:J110").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 4); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 4); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 8); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(1, 3).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(2, 3).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(1, 4).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(2, 4).getValue(), "#N/A"); } oParser = new parserFormula("A200:B202*A200:E200", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:J110").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 4); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 4); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 8); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(1, 3).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(2, 3).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(1, 4).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(2, 4).getValue(), "#N/A"); } oParser = new parserFormula("M106:P113+M106:P113", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:H113").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 4); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 4); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 8); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 10); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), -46); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), 12); assert.strictEqual(array.getElementRowCol(7, 0).getValue(), 10); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 0); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 0); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), 6); assert.strictEqual(array.getElementRowCol(4, 1).getValue(), 0); assert.strictEqual(array.getElementRowCol(5, 1).getValue(), 4); assert.strictEqual(array.getElementRowCol(6, 1).getValue(), 0); assert.strictEqual(array.getElementRowCol(7, 1).getValue(), 6); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 2); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 6); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), 4); assert.strictEqual(array.getElementRowCol(3, 2).getValue(), 24); assert.strictEqual(array.getElementRowCol(4, 2).getValue(), 6); assert.strictEqual(array.getElementRowCol(5, 2).getValue(), 8); assert.strictEqual(array.getElementRowCol(6, 2).getValue(), 6); assert.strictEqual(array.getElementRowCol(7, 2).getValue(), 4); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 6); assert.strictEqual(array.getElementRowCol(1, 3).getValue(), 8); assert.strictEqual(array.getElementRowCol(2, 3).getValue(), 10); assert.strictEqual(array.getElementRowCol(3, 3).getValue(), 2); assert.strictEqual(array.getElementRowCol(4, 3).getValue(), 46); assert.strictEqual(array.getElementRowCol(5, 3).getValue(), 8); assert.strictEqual(array.getElementRowCol(6, 3).getValue(), 6); assert.strictEqual(array.getElementRowCol(7, 3).getValue(), 2); } oParser = new parserFormula("M106:P113*M106:P113", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:H113").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 4); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 4); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 16); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 25); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 529); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), 36); assert.strictEqual(array.getElementRowCol(7, 0).getValue(), 25); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 0); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 0); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), 9); assert.strictEqual(array.getElementRowCol(4, 1).getValue(), 0); assert.strictEqual(array.getElementRowCol(5, 1).getValue(), 4); assert.strictEqual(array.getElementRowCol(6, 1).getValue(), 0); assert.strictEqual(array.getElementRowCol(7, 1).getValue(), 9); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 1); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 9); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), 4); assert.strictEqual(array.getElementRowCol(3, 2).getValue(), 144); assert.strictEqual(array.getElementRowCol(4, 2).getValue(), 9); assert.strictEqual(array.getElementRowCol(5, 2).getValue(), 16); assert.strictEqual(array.getElementRowCol(6, 2).getValue(), 9); assert.strictEqual(array.getElementRowCol(7, 2).getValue(), 4); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 9); assert.strictEqual(array.getElementRowCol(1, 3).getValue(), 16); assert.strictEqual(array.getElementRowCol(2, 3).getValue(), 25); assert.strictEqual(array.getElementRowCol(3, 3).getValue(), 1); assert.strictEqual(array.getElementRowCol(4, 3).getValue(), 529); assert.strictEqual(array.getElementRowCol(5, 3).getValue(), 16); assert.strictEqual(array.getElementRowCol(6, 3).getValue(), 9); assert.strictEqual(array.getElementRowCol(7, 3).getValue(), 1); } oParser = new parserFormula("M106:P113-M106:P113", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:H113").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 0); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 0); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 0); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 0); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 0); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 0); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), 0); assert.strictEqual(array.getElementRowCol(7, 0).getValue(), 0); } oParser = new parserFormula("M106:P113=M106:P113", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:H113").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "TRUE"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "TRUE"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "TRUE"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "TRUE"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "TRUE"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), "TRUE"); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), "TRUE"); assert.strictEqual(array.getElementRowCol(7, 0).getValue(), "TRUE"); } oParser = new parserFormula("M106:P113/M106:P113", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:H113").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 1); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#DIV/0!"); } oParser = new parserFormula("M106:P113<>M106:P113", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:H113").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "FALSE"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "FALSE"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "FALSE"); } oParser = new parserFormula("M106:P113>M106:P113", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:H113").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "FALSE"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "FALSE"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "FALSE"); } oParser = new parserFormula("M106:P113=M106:P113", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:H113").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "TRUE"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "TRUE"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "TRUE"); } oParser = new parserFormula("SUM(M:P*M:P)", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:H113").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getValue(), 1465); oParser = new parserFormula("SUM(M:P+M:P)", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:H113").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getValue(), 170); // for bug 65316 ws.getRange2("A100").setValue("75"); ws.getRange2("A101").setValue("42.4"); ws.getRange2("B100").setValue("100"); ws.getRange2("B101").setValue("42.48"); ws.getRange2("C100").setValue("200"); ws.getRange2("C101").setValue("42"); ws.getRange2("D100").setValue("300"); ws.getRange2("D101").setValue("39.4"); ws.getRange2("E100").setValue("350"); ws.getRange2("E101").setValue("38.4"); oParser = new parserFormula("A100:C100^{1;2;3;4}", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E200:I204").bbox); assert.ok(oParser.parse(), "A100:C100^{1;2;3;4}. Result - array 4x3"); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 75, "Array 4x3. [0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), Math.pow(75, 2), "Array 4x3. [1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), Math.pow(75, 3), "Array 4x3. [2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), Math.pow(75, 4), "Array 4x3. [3,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 100, "Array 4x3. [0,1]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), Math.pow(100, 2), "Array 4x3. [1,1]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), Math.pow(100, 3), "Array 4x3. [2,1]"); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), Math.pow(100, 4), "Array 4x3. [3,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 200, "Array 4x3. [0,2]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), Math.pow(200, 2), "Array 4x3. [1,2]"); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), Math.pow(200, 3), "Array 4x3. [2,2]"); assert.strictEqual(array.getElementRowCol(3, 2).getValue(), Math.pow(200, 4), "Array 4x3. [3,2]"); } oParser = new parserFormula("A100:C101^{1;2;3;4}", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E200:I204").bbox); assert.ok(oParser.parse(), "A100:C101^{1;2;3;4}. Result - array 4x3(2x3 = #N/A)"); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 75, "Array 4x3. [0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 1797.76, "Array 4x3. [1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", "Array 4x3. [2,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 100, "Array 4x3. [0,1]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue().toFixed(2), "1804.55", "Array 4x3. [1,1]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#N/A", "Array 4x3. [2,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 200, "Array 4x3. [0,2]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 1764, "Array 4x3. [1,2]"); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "#N/A", "Array 4x3. [2,2]"); } ws.getRange2("A200").setValue("1"); ws.getRange2("A201").setValue("3"); ws.getRange2("B200").setValue("3"); ws.getRange2("B201").setValue("4"); ws.getRange2("D200").setValue("1"); ws.getRange2("D201").setValue("2"); ws.getRange2("D202").setValue("3"); ws.getRange2("D203").setValue("4"); ws.getRange2("D204").setValue("5"); ws.getRange2("D205").setValue("6"); ws.getRange2("D206:D300").setValue(""); // for bug 54877 oParser = new parserFormula("A200:B201*D200:D203", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E200:H210").bbox); assert.ok(oParser.parse(), "A200:B201*D200:D203. Result - array 4x2"); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Array 4x2. [0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 6, "Array 4x2. [1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", "Array 4x2. [2,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, "Array 4x2. [0,1]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 8, "Array 4x2. [1,1]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#N/A", "Array 4x2. [2,1]"); } oParser = new parserFormula("A200:B201*D200:D300", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E200:H210").bbox); assert.ok(oParser.parse(), "A200:B201*D200:D300. Result - array 100x2"); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Array 100x2. [0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 6, "Array 100x2. [1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", "Array 100x2. [2,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, "Array 100x2. [0,1]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 8, "Array 100x2. [1,1]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#N/A", "Array 100x2. [2,1]"); } oParser = new parserFormula("D200:D300*2", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E200:H210").bbox); assert.ok(oParser.parse(), "D200:D300*2. Result - array 100x1"); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Array 100x1. [0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 4, "Array 100x1. [1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 6, "Array 100x1. [2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 8, "Array 100x1. [3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 10, "Array 100x1. [4,0]"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 12, "Array 100x1. [5,0]"); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), 0, "Array 100x1. [6,0]"); assert.strictEqual(array.getElementRowCol(7, 0).getValue(), 0, "Array 100x1. [7,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Array 100x1. [0,1]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Array 100x1. [1,1]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "", "Array 100x1. [2,1]"); } oParser = new parserFormula("2*D200:D300", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E200:H210").bbox); assert.ok(oParser.parse(), "2*D200:D300. Result - array 100x1"); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Array 100x1. [0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 4, "Array 100x1. [1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 6, "Array 100x1. [2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 8, "Array 100x1. [3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 10, "Array 100x1. [4,0]"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 12, "Array 100x1. [5,0]"); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), 0, "Array 100x1. [6,0]"); assert.strictEqual(array.getElementRowCol(7, 0).getValue(), 0, "Array 100x1. [7,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Array 100x1. [0,1]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Array 100x1. [1,1]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "", "Array 100x1. [2,1]"); } // conditional check and & operator // < oParser = new parserFormula("D200:D300<2", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E200:H210").bbox); assert.ok(oParser.parse(), "D200:D300<2. Result - array 100x1"); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "TRUE", "Array 100x1. [0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "FALSE", "Array 100x1. [1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "FALSE", "Array 100x1. [2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "FALSE", "Array 100x1. [3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "FALSE", "Array 100x1. [4,0]"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), "FALSE", "Array 100x1. [5,0]"); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), "TRUE", "Array 100x1. [6,0]"); assert.strictEqual(array.getElementRowCol(7, 0).getValue(), "TRUE", "Array 100x1. [7,0]"); assert.strictEqual(array.getElementRowCol(8, 0).getValue(), "TRUE", "Array 100x1. [8,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Array 100x1. [0,1]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Array 100x1. [1,1]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "", "Array 100x1. [2,1]"); } oParser = new parserFormula("2 oParser = new parserFormula("D200:D300>2", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E200:H210").bbox); assert.ok(oParser.parse(), "D200:D300>2. Result - array 100x1"); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "FALSE", "Array 100x1. [0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "FALSE", "Array 100x1. [1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "TRUE", "Array 100x1. [2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "TRUE", "Array 100x1. [3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "TRUE", "Array 100x1. [4,0]"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), "TRUE", "Array 100x1. [5,0]"); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), "FALSE", "Array 100x1. [6,0]"); assert.strictEqual(array.getElementRowCol(7, 0).getValue(), "FALSE", "Array 100x1. [7,0]"); assert.strictEqual(array.getElementRowCol(8, 0).getValue(), "FALSE", "Array 100x1. [8,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Array 100x1. [0,1]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Array 100x1. [1,1]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "", "Array 100x1. [2,1]"); } oParser = new parserFormula("2>D200:D300", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E200:H210").bbox); assert.ok(oParser.parse(), "2>D200:D300. Result - array 100x1"); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "TRUE", "Array 100x1. [0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "FALSE", "Array 100x1. [1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "FALSE", "Array 100x1. [2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "FALSE", "Array 100x1. [3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "FALSE", "Array 100x1. [4,0]"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), "FALSE", "Array 100x1. [5,0]"); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), "TRUE", "Array 100x1. [6,0]"); assert.strictEqual(array.getElementRowCol(7, 0).getValue(), "TRUE", "Array 100x1. [7,0]"); assert.strictEqual(array.getElementRowCol(8, 0).getValue(), "TRUE", "Array 100x1. [8,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Array 100x1. [0,1]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Array 100x1. [1,1]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "", "Array 100x1. [2,1]"); } // >= oParser = new parserFormula("D200:D300>=2", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E200:H210").bbox); assert.ok(oParser.parse(), "D200:D300>=2. Result - array 100x1"); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "FALSE", "Array 100x1. [0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "TRUE", "Array 100x1. [1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "TRUE", "Array 100x1. [2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "TRUE", "Array 100x1. [3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "TRUE", "Array 100x1. [4,0]"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), "TRUE", "Array 100x1. [5,0]"); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), "FALSE", "Array 100x1. [6,0]"); assert.strictEqual(array.getElementRowCol(7, 0).getValue(), "FALSE", "Array 100x1. [7,0]"); assert.strictEqual(array.getElementRowCol(8, 0).getValue(), "FALSE", "Array 100x1. [8,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Array 100x1. [0,1]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Array 100x1. [1,1]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "", "Array 100x1. [2,1]"); } oParser = new parserFormula("2>=D200:D300", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E200:H210").bbox); assert.ok(oParser.parse(), "2>=D200:D300. Result - array 100x1"); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "TRUE", "Array 100x1. [0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "TRUE", "Array 100x1. [1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "FALSE", "Array 100x1. [2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "FALSE", "Array 100x1. [3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "FALSE", "Array 100x1. [4,0]"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), "FALSE", "Array 100x1. [5,0]"); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), "TRUE", "Array 100x1. [6,0]"); assert.strictEqual(array.getElementRowCol(7, 0).getValue(), "TRUE", "Array 100x1. [7,0]"); assert.strictEqual(array.getElementRowCol(8, 0).getValue(), "TRUE", "Array 100x1. [8,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Array 100x1. [0,1]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Array 100x1. [1,1]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "", "Array 100x1. [2,1]"); } // = oParser = new parserFormula("D200:D300=2", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E200:H210").bbox); assert.ok(oParser.parse(), "D200:D300=2. Result - array 100x1"); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "FALSE", "Array 100x1. [0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "TRUE", "Array 100x1. [1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "FALSE", "Array 100x1. [2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "FALSE", "Array 100x1. [3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "FALSE", "Array 100x1. [4,0]"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), "FALSE", "Array 100x1. [5,0]"); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), "FALSE", "Array 100x1. [6,0]"); assert.strictEqual(array.getElementRowCol(7, 0).getValue(), "FALSE", "Array 100x1. [7,0]"); assert.strictEqual(array.getElementRowCol(8, 0).getValue(), "FALSE", "Array 100x1. [8,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Array 100x1. [0,1]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Array 100x1. [1,1]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "", "Array 100x1. [2,1]"); } oParser = new parserFormula("2=D200:D300", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E200:H210").bbox); assert.ok(oParser.parse(), "2=D200:D300. Result - array 100x1"); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "FALSE", "Array 100x1. [0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "TRUE", "Array 100x1. [1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "FALSE", "Array 100x1. [2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "FALSE", "Array 100x1. [3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "FALSE", "Array 100x1. [4,0]"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), "FALSE", "Array 100x1. [5,0]"); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), "FALSE", "Array 100x1. [6,0]"); assert.strictEqual(array.getElementRowCol(7, 0).getValue(), "FALSE", "Array 100x1. [7,0]"); assert.strictEqual(array.getElementRowCol(8, 0).getValue(), "FALSE", "Array 100x1. [8,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Array 100x1. [0,1]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Array 100x1. [1,1]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "", "Array 100x1. [2,1]"); } // <> oParser = new parserFormula("D200:D300<>2", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E200:H210").bbox); assert.ok(oParser.parse(), "D200:D300<>2. Result - array 100x1"); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "TRUE", "Array 100x1. [0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "FALSE", "Array 100x1. [1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "TRUE", "Array 100x1. [2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "TRUE", "Array 100x1. [3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "TRUE", "Array 100x1. [4,0]"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), "TRUE", "Array 100x1. [5,0]"); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), "TRUE", "Array 100x1. [6,0]"); assert.strictEqual(array.getElementRowCol(7, 0).getValue(), "TRUE", "Array 100x1. [7,0]"); assert.strictEqual(array.getElementRowCol(8, 0).getValue(), "TRUE", "Array 100x1. [8,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Array 100x1. [0,1]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Array 100x1. [1,1]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "", "Array 100x1. [2,1]"); } oParser = new parserFormula("2<>D200:D300", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E200:H210").bbox); assert.ok(oParser.parse(), "2<>D200:D300. Result - array 100x1"); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "TRUE", "Array 100x1. [0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "FALSE", "Array 100x1. [1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "TRUE", "Array 100x1. [2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "TRUE", "Array 100x1. [3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "TRUE", "Array 100x1. [4,0]"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), "TRUE", "Array 100x1. [5,0]"); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), "TRUE", "Array 100x1. [6,0]"); assert.strictEqual(array.getElementRowCol(7, 0).getValue(), "TRUE", "Array 100x1. [7,0]"); assert.strictEqual(array.getElementRowCol(8, 0).getValue(), "TRUE", "Array 100x1. [8,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Array 100x1. [0,1]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Array 100x1. [1,1]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "", "Array 100x1. [2,1]"); } // & ws.getRange2("D204").setValue("A"); ws.getRange2("D205").setValue("B"); ws.getRange2("D206:D210").setValue(""); ws.getRange2("E204").setValue("A"); ws.getRange2("E205").setValue("B"); ws.getRange2("E206").setValue("C"); ws.getRange2("E207").setValue("D"); ws.getRange2("E208:E210").setValue(""); oParser = new parserFormula("D204:D210&E204:E210", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E300:H310").bbox); assert.ok(oParser.parse(), "D204:D210&E204:E210. Result - array 7x1"); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "AA", "Array 7x1. [0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "BB", "Array 7x1. [1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "C", "Array 7x1. [2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "D", "Array 7x1. [3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "", "Array 7x1. [4,0]"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), "", "Array 7x1. [5,0]"); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), "", "Array 7x1. [6,0]"); assert.strictEqual(array.getElementRowCol(7, 0).getValue(), "", "Array 7x1. [7,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Array 7x1. [0,1]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Array 7x1. [1,1]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "", "Array 7x1. [2,1]"); } }); QUnit.test("Test: \"Concatenation operator test\"", function (assert) { let array, defName; ws.getRange2("A200").setValue("1"); ws.getRange2("A201").setValue("2"); ws.getRange2("A202").setValue("3"); ws.getRange2("A203").setValue("4"); ws.getRange2("A204").setValue("5"); ws.getRange2("B200").setValue("A"); ws.getRange2("B201").setValue("B"); ws.getRange2("B202").setValue("C"); ws.getRange2("B203").setValue("D"); ws.getRange2("B204").setValue("E"); wb.dependencyFormulas.addDefName("def_nums", "Sheet1!$A$200:$A$204"); wb.dependencyFormulas.addDefName("def_strings", "Sheet1!$B$200:$B$204"); wb.dependencyFormulas.addDefName("def_strings", "Sheet1!$B$200:$B$204"); defName = new AscCommonExcel.DefName(wb, "n_1", '{1,2,3}', null, null, Asc.c_oAscDefNameType.none); wb.dependencyFormulas._addDefName(defName); wb.dependencyFormulas.defNames.wb["n_1"].setRef(defName.ref, true, true, true); defName = new AscCommonExcel.DefName(wb, "n_2", '{"str1","str2","str3"}', null, null, Asc.c_oAscDefNameType.none); wb.dependencyFormulas._addDefName(defName); wb.dependencyFormulas.defNames.wb["n_2"].setRef(defName.ref, true, true, true); defName = new AscCommonExcel.DefName(wb, "n_if", 'IF(0,n_2,n_1&n_2)', null, null, Asc.c_oAscDefNameType.none); wb.dependencyFormulas._addDefName(defName); wb.dependencyFormulas.defNames.wb["n_if"].setRef(defName.ref, true, true, true); // wb.dependencyFormulas.addDefNameOpen(defName.Name, defName.Ref, defName.LocalSheetId, defName.Hidden, _type); // INDEX oParser = new parserFormula('INDEX(n_if,2)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "2str2"); oParser = new parserFormula('INDEX(A200:A204&A200:A204,2)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "22"); oParser = new parserFormula('INDEX(def_nums&def_nums,2)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "22"); oParser = new parserFormula('INDEX(B200:B204&B200:B204,2)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "BB"); oParser = new parserFormula('INDEX(def_strings&def_strings,2)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "BB"); // other formulas oParser = new parserFormula('COLUMNS(A200:A204&A200:A204)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula('COLUMNS(1+A200:A204&A200:A204)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula('COLUMNS(def_nums&def_nums)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula('COLUMNS(def_strings&def_strings)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula('ROWS(A200:A204&A200:A204)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5); oParser = new parserFormula('ROWS(1+A200:A204&A200:A204)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5); oParser = new parserFormula('ROWS(def_nums&def_nums)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5); oParser = new parserFormula('ROWS(def_strings&def_strings)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5); oParser = new parserFormula('CONCAT(A200:A204,A200:A204&A200:A204)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123451122334455"); // remove all created earlier defNames wb.dependencyFormulas._foreachDefName(function(defName) { wb.dependencyFormulas.removeDefName(undefined, defName.name); }); }); QUnit.test("Test: \"ACOS\"", function (assert) { oParser = new parserFormula('ACOS(-0.5)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 2.094395102); testArrayFormula(assert, "ACOS"); }); QUnit.test("Test: \"ACOSH\"", function (assert) { oParser = new parserFormula('ACOSH(1)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula('ACOSH(10)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 2.9932228); testArrayFormula(assert, "ACOSH"); }); QUnit.test("Test: \"ASIN\"", function (assert) { oParser = new parserFormula('ASIN(-0.5)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, -0.523598776); testArrayFormula(assert, "ASIN"); }); QUnit.test("Test: \"ASINH\"", function (assert) { oParser = new parserFormula('ASINH(-2.5)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, -1.647231146); oParser = new parserFormula('ASINH(10)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 2.99822295); testArrayFormula(assert, "ASINH"); }); QUnit.test("Test: \"SIN have wrong arguments count\"", function (assert) { oParser = new parserFormula('SIN(3.1415926,3.1415926*2)', "A1", ws); assert.ok(!oParser.parse()); }); QUnit.test("Test: \"SIN(3.1415926)\"", function (assert) { oParser = new parserFormula('SIN(3.1415926)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), Math.sin(3.1415926)); testArrayFormula(assert, "SIN"); }); QUnit.test("Test: \"SQRT\"", function (assert) { ws.getRange2("A202").setValue("-16"); oParser = new parserFormula('SQRT(16)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); oParser = new parserFormula('SQRT(A202)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula('SQRT(ABS(A202))', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); testArrayFormula(assert, "SQRT"); }); QUnit.test("Test: \"SQRTPI\"", function (assert) { oParser = new parserFormula('SQRTPI(1)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 1.772454); oParser = new parserFormula('SQRTPI(2)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 2.506628); testArrayFormula(assert, "SQRTPI", true); }); QUnit.test("Test: \"COS(PI()/2)\"", function (assert) { oParser = new parserFormula('COS(PI()/2)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), Math.cos(Math.PI / 2)); }); QUnit.test("Test: \"ACOT(2)\"", function (assert) { oParser = new parserFormula('ACOT(2)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), Math.PI / 2 - Math.atan(2)); }); QUnit.test("Test: \"ACOTH(6)\"", function (assert) { oParser = new parserFormula('ACOTH(6)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), Math.atanh(1 / 6)); testArrayFormula(assert, "ACOTH"); }); QUnit.test("Test: \"COT\"", function (assert) { oParser = new parserFormula('COT(30)', "A1", ws); assert.ok(oParser.parse(), 'COT(30)'); assert.strictEqual(oParser.calculate().getValue().toFixed(3) - 0, -0.156, 'COT(30)'); oParser = new parserFormula('COT(0)', "A1", ws); assert.ok(oParser.parse(), 'COT(0)'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'COT(0)'); oParser = new parserFormula('COT(1000000000)', "A1", ws); assert.ok(oParser.parse(), 'COT(1000000000)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'COT(1000000000)'); oParser = new parserFormula('COT(-1000000000)', "A1", ws); assert.ok(oParser.parse(), 'COT(-1000000000)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'COT(-1000000000)'); oParser = new parserFormula('COT(test)', "A1", ws); assert.ok(oParser.parse(), 'COT(test)'); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", 'COT(test)'); oParser = new parserFormula('COT("test")', "A1", ws); assert.ok(oParser.parse(), 'COT("test")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'COT("test")'); testArrayFormula(assert, "COT"); }); QUnit.test("Test: \"COTH\"", function (assert) { oParser = new parserFormula('COTH(2)', "A1", ws); assert.ok(oParser.parse(), 'COTH(2)'); assert.strictEqual(oParser.calculate().getValue().toFixed(3) - 0, 1.037, 'COTH(2)'); oParser = new parserFormula('COTH(0)', "A1", ws); assert.ok(oParser.parse(), 'COTH(0)'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'COTH(0)'); oParser = new parserFormula('COTH(1000000000)', "A1", ws); assert.ok(oParser.parse(), 'COTH(1000000000)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'COTH(1000000000)'); oParser = new parserFormula('COTH(-1000000000)', "A1", ws); assert.ok(oParser.parse(), 'COTH(-1000000000)'); assert.strictEqual(oParser.calculate().getValue(), -1, 'COTH(-1000000000)'); oParser = new parserFormula('COTH(test)', "A1", ws); assert.ok(oParser.parse(), 'COTH(test)'); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", 'COTH(test)'); oParser = new parserFormula('COTH("test")', "A1", ws); assert.ok(oParser.parse(), 'COTH("test")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'COTH("test")'); testArrayFormula(assert, "COTH"); }); QUnit.test("Test: \"CSC\"", function (assert) { oParser = new parserFormula('CSC(15)', "A1", ws); assert.ok(oParser.parse(), 'CSC(15)'); assert.strictEqual(oParser.calculate().getValue().toFixed(3) - 0, 1.538, 'CSC(15)'); oParser = new parserFormula('CSC(0)', "A1", ws); assert.ok(oParser.parse(), 'CSC(0)'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'CSC(0)'); oParser = new parserFormula('CSC(1000000000)', "A1", ws); assert.ok(oParser.parse(), 'CSC(1000000000)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'CSC(1000000000)'); oParser = new parserFormula('CSC(-1000000000)', "A1", ws); assert.ok(oParser.parse(), 'CSC(-1000000000)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'CSC(-1000000000)'); oParser = new parserFormula('CSC(test)', "A1", ws); assert.ok(oParser.parse(), 'CSC(test)'); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", 'CSC(test)'); oParser = new parserFormula('CSC("test")', "A1", ws); assert.ok(oParser.parse(), 'CSC("test")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'CSC("test")'); testArrayFormula(assert, "CSC"); }); QUnit.test("Test: \"CSCH\"", function (assert) { oParser = new parserFormula('CSCH(1.5)', "A1", ws); assert.ok(oParser.parse(), 'CSCH(1.5)'); assert.strictEqual(oParser.calculate().getValue().toFixed(4) - 0, 0.4696, 'CSCH(1.5)'); oParser = new parserFormula('CSCH(0)', "A1", ws); assert.ok(oParser.parse(), 'CSCH(0)'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'CSCH(0)'); oParser = new parserFormula('CSCH(1000000000)', "A1", ws); assert.ok(oParser.parse(), 'CSCH(1000000000)'); assert.strictEqual(oParser.calculate().getValue(), 0, 'CSCH(1000000000)'); oParser = new parserFormula('CSCH(-1000000000)', "A1", ws); assert.ok(oParser.parse(), 'CSCH(-1000000000)'); assert.strictEqual(oParser.calculate().getValue(), 0, 'CSCH(-1000000000)'); oParser = new parserFormula('CSCH(test)', "A1", ws); assert.ok(oParser.parse(), 'CSCH(test)'); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", 'CSCH(test)'); oParser = new parserFormula('CSCH("test")', "A1", ws); assert.ok(oParser.parse(), 'CSCH("test")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'CSCH("test")'); testArrayFormula(assert, "CSCH"); }); QUnit.test("Test: \"CLEAN\"", function (assert) { ws.getRange2("A202").setValue('=CHAR(9)&"Monthly report"&CHAR(10)'); oParser = new parserFormula('CLEAN(A202)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "Monthly report"); testArrayFormula(assert, "CLEAN"); }); QUnit.test("Test: \"DEGREES\"", function (assert) { oParser = new parserFormula('DEGREES(PI())', "A1", ws); assert.ok(oParser.parse(), 'DEGREES(PI())'); assert.strictEqual(oParser.calculate().getValue(), 180, 'DEGREES(PI())'); testArrayFormula(assert, "DEGREES"); }); QUnit.test("Test: \"SEC\"", function (assert) { oParser = new parserFormula('SEC(45)', "A1", ws); assert.ok(oParser.parse(), 'SEC(45)'); assert.strictEqual(oParser.calculate().getValue().toFixed(5) - 0, 1.90359, 'SEC(45)'); oParser = new parserFormula('SEC(30)', "A1", ws); assert.ok(oParser.parse(), 'SEC(30)'); assert.strictEqual(oParser.calculate().getValue().toFixed(5) - 0, 6.48292, 'SEC(30)'); oParser = new parserFormula('SEC(0)', "A1", ws); assert.ok(oParser.parse(), 'SEC(0)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'SEC(0)'); oParser = new parserFormula('SEC(1000000000)', "A1", ws); assert.ok(oParser.parse(), 'SEC(1000000000)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'SEC(1000000000)'); oParser = new parserFormula('SEC(test)', "A1", ws); assert.ok(oParser.parse(), 'SEC(test)'); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", 'SEC(test)'); oParser = new parserFormula('SEC("test")', "A1", ws); assert.ok(oParser.parse(), 'SEC("test")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'SEC("test")'); testArrayFormula(assert, "SEC"); }); QUnit.test("Test: \"SECH\"", function (assert) { oParser = new parserFormula('SECH(5)', "A1", ws); assert.ok(oParser.parse(), 'SECH(5)'); assert.strictEqual(oParser.calculate().getValue().toFixed(3) - 0, 0.013, 'SECH(5)'); oParser = new parserFormula('SECH(0)', "A1", ws); assert.ok(oParser.parse(), 'SECH(0)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'SECH(0)'); oParser = new parserFormula('SECH(1000000000)', "A1", ws); assert.ok(oParser.parse(), 'SECH(1000000000)'); assert.strictEqual(oParser.calculate().getValue(), 0, 'SECH(1000000000)'); oParser = new parserFormula('SECH(test)', "A1", ws); assert.ok(oParser.parse(), 'SECH(test)'); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", 'SECH(test)'); oParser = new parserFormula('SECH("test")', "A1", ws); assert.ok(oParser.parse(), 'SECH("test")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'SECH("test")'); testArrayFormula(assert, "SECH"); }); QUnit.test("Test: \"SECOND\"", function (assert) { ws.getRange2("A202").setValue("12:45:03 PM"); ws.getRange2("A203").setValue("4:48:18 PM"); ws.getRange2("A204").setValue("4:48 PM"); oParser = new parserFormula("SECOND(A202)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); oParser = new parserFormula("SECOND(A203)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 18); oParser = new parserFormula("SECOND(A204)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); testArrayFormula2(assert, "SECOND", 1, 1); }); QUnit.test("Test: \"FLOOR\"", function (assert) { oParser = new parserFormula('FLOOR(3.7,2)', "A1", ws); assert.ok(oParser.parse(), 'FLOOR(3.7,2)'); assert.strictEqual(oParser.calculate().getValue(), 2, 'FLOOR(3.7,2)'); oParser = new parserFormula('FLOOR(-2.5,-2)', "A1", ws); assert.ok(oParser.parse(), 'FLOOR(-2.5,-2)'); assert.strictEqual(oParser.calculate().getValue(), -2, 'FLOOR(-2.5,-2)'); oParser = new parserFormula('FLOOR(2.5,-2)', "A1", ws); assert.ok(oParser.parse(), 'FLOOR(2.5,-2)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'FLOOR(2.5,-2)'); oParser = new parserFormula('FLOOR(1.58,0.1)', "A1", ws); assert.ok(oParser.parse(), 'FLOOR(1.58,0.1)'); assert.strictEqual(oParser.calculate().getValue(), 1.5, 'FLOOR(1.58,0.1)'); oParser = new parserFormula('FLOOR(0.234,0.01)', "A1", ws); assert.ok(oParser.parse(), 'FLOOR(0.234,0.01)'); assert.strictEqual(oParser.calculate().getValue(), 0.23, 'FLOOR(0.234,0.01)'); testArrayFormula2(assert, "FLOOR", 2, 2); }); QUnit.test("Test: \"FLOOR.PRECISE\"", function (assert) { oParser = new parserFormula('FLOOR.PRECISE(-3.2, -1)', "A1", ws); assert.ok(oParser.parse(), 'FLOOR.PRECISE(-3.2, -1)'); assert.strictEqual(oParser.calculate().getValue(), -4, 'FLOOR.PRECISE(-3.2, -1)'); oParser = new parserFormula('FLOOR.PRECISE(3.2, 1)', "A1", ws); assert.ok(oParser.parse(), 'FLOOR.PRECISE(3.2, 1)'); assert.strictEqual(oParser.calculate().getValue(), 3, 'FLOOR.PRECISE(3.2, 1)'); oParser = new parserFormula('FLOOR.PRECISE(-3.2, 1)', "A1", ws); assert.ok(oParser.parse(), 'FLOOR.PRECISE(-3.2, 1)'); assert.strictEqual(oParser.calculate().getValue(), -4, 'FLOOR.PRECISE(-3.2, 1)'); oParser = new parserFormula('FLOOR.PRECISE(3.2, -1)', "A1", ws); assert.ok(oParser.parse(), 'FLOOR.PRECISE(3.2, -1)'); assert.strictEqual(oParser.calculate().getValue(), 3, 'FLOOR.PRECISE(3.2, -1)'); oParser = new parserFormula('FLOOR.PRECISE(3.2)', "A1", ws); assert.ok(oParser.parse(), 'FLOOR.PRECISE(3.2)'); assert.strictEqual(oParser.calculate().getValue(), 3, 'FLOOR.PRECISE(3.2)'); oParser = new parserFormula('FLOOR.PRECISE(test)', "A1", ws); assert.ok(oParser.parse(), 'FLOOR.PRECISE(test)'); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", 'FLOOR.PRECISE(test)'); testArrayFormula2(assert, "FLOOR.PRECISE", 1, 2); }); QUnit.test("Test: \"FLOOR.MATH\"", function (assert) { oParser = new parserFormula('FLOOR.MATH(24.3, 5)', "A1", ws); assert.ok(oParser.parse(), 'FLOOR.MATH(24.3, 5)'); assert.strictEqual(oParser.calculate().getValue(), 20, 'FLOOR.MATH(24.3, 5)'); oParser = new parserFormula('FLOOR.MATH(6.7)', "A1", ws); assert.ok(oParser.parse(), 'FLOOR.MATH(6.7)'); assert.strictEqual(oParser.calculate().getValue(), 6, 'FLOOR.MATH(6.7)'); oParser = new parserFormula('FLOOR.MATH(-8.1, 5)', "A1", ws); assert.ok(oParser.parse(), 'FLOOR.MATH(-8.1, 5)'); assert.strictEqual(oParser.calculate().getValue(), -10, 'FLOOR.MATH(-8.1, 5)'); oParser = new parserFormula('FLOOR.MATH(-5.5, 2, -1)', "A1", ws); assert.ok(oParser.parse(), 'FLOOR.MATH(-5.5, 2, -1)'); assert.strictEqual(oParser.calculate().getValue(), -4, 'FLOOR.MATH(-5.5, 2, -1)'); testArrayFormula2(assert, "FLOOR.MATH", 1, 3); }); QUnit.test("Test: \"CEILING.MATH\"", function (assert) { oParser = new parserFormula('CEILING.MATH(24.3, 5)', "A1", ws); assert.ok(oParser.parse(), 'CEILING.MATH(24.3, 5)'); assert.strictEqual(oParser.calculate().getValue(), 25, 'CEILING.MATH(24.3, 5)'); oParser = new parserFormula('CEILING.MATH(6.7)', "A1", ws); assert.ok(oParser.parse(), 'CEILING.MATH(6.7)'); assert.strictEqual(oParser.calculate().getValue(), 7, 'CEILING.MATH(6.7)'); oParser = new parserFormula('CEILING.MATH(-8.1, 2)', "A1", ws); assert.ok(oParser.parse(), 'CEILING.MATH(-8.1, 2)'); assert.strictEqual(oParser.calculate().getValue(), -8, 'CEILING.MATH(-8.1, 2)'); oParser = new parserFormula('CEILING.MATH(-5.5, 2, -1)', "A1", ws); assert.ok(oParser.parse(), 'CEILING.MATH(-5.5, 2, -1)'); assert.strictEqual(oParser.calculate().getValue(), -6, 'CEILING.MATH(-5.5, 2, -1)'); testArrayFormula2(assert, "CEILING.MATH", 1, 3); }); QUnit.test("Test: \"CEILING.PRECISE\"", function (assert) { oParser = new parserFormula('CEILING.PRECISE(4.3)', "A1", ws); assert.ok(oParser.parse(), 'CEILING.PRECISE(4.3)'); assert.strictEqual(oParser.calculate().getValue(), 5, 'CEILING.PRECISE(4.3)'); oParser = new parserFormula('CEILING.PRECISE(-4.3)', "A1", ws); assert.ok(oParser.parse(), 'CEILING.PRECISE(-4.3)'); assert.strictEqual(oParser.calculate().getValue(), -4, 'CEILING.PRECISE(-4.3)'); oParser = new parserFormula('CEILING.PRECISE(4.3, 2)', "A1", ws); assert.ok(oParser.parse(), 'CEILING.PRECISE(4.3, 2)'); assert.strictEqual(oParser.calculate().getValue(), 6, 'CEILING.PRECISE(4.3, 2)'); oParser = new parserFormula('CEILING.PRECISE(4.3,-2)', "A1", ws); assert.ok(oParser.parse(), 'CEILING.PRECISE(4.3,-2)'); assert.strictEqual(oParser.calculate().getValue(), 6, 'CEILING.PRECISE(4.3,-2)'); oParser = new parserFormula('CEILING.PRECISE(-4.3,2)', "A1", ws); assert.ok(oParser.parse(), 'CEILING.PRECISE(-4.3,2)'); assert.strictEqual(oParser.calculate().getValue(), -4, 'CEILING.PRECISE(-4.3,2)'); oParser = new parserFormula('CEILING.PRECISE(-4.3,-2)', "A1", ws); assert.ok(oParser.parse(), 'CEILING.PRECISE(-4.3,-2)'); assert.strictEqual(oParser.calculate().getValue(), -4, 'CEILING.PRECISE(-4.3,-2)'); oParser = new parserFormula('CEILING.PRECISE(test)', "A1", ws); assert.ok(oParser.parse(), 'CEILING.PRECISE(test)'); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", 'CEILING.PRECISE(test)'); testArrayFormula2(assert, "CEILING.PRECISE", 1, 2); }); QUnit.test("Test: \"ISO.CEILING\"", function (assert) { oParser = new parserFormula('ISO.CEILING(4.3)', "A1", ws); assert.ok(oParser.parse(), 'ISO.CEILING(4.3)'); assert.strictEqual(oParser.calculate().getValue(), 5, 'ISO.CEILING(4.3)'); oParser = new parserFormula('ISO.CEILING(-4.3)', "A1", ws); assert.ok(oParser.parse(), 'ISO.CEILING(-4.3)'); assert.strictEqual(oParser.calculate().getValue(), -4, 'ISO.CEILING(-4.3)'); oParser = new parserFormula('ISO.CEILING(4.3, 2)', "A1", ws); assert.ok(oParser.parse(), 'ISO.CEILING(4.3, 2)'); assert.strictEqual(oParser.calculate().getValue(), 6, 'ISO.CEILING(4.3, 2)'); oParser = new parserFormula('ISO.CEILING(4.3,-2)', "A1", ws); assert.ok(oParser.parse(), 'ISO.CEILING(4.3,-2)'); assert.strictEqual(oParser.calculate().getValue(), 6, 'ISO.CEILING(4.3,-2)'); oParser = new parserFormula('ISO.CEILING(-4.3,2)', "A1", ws); assert.ok(oParser.parse(), 'ISO.CEILING(-4.3,2)'); assert.strictEqual(oParser.calculate().getValue(), -4, 'ISO.CEILING(-4.3,2)'); oParser = new parserFormula('ISO.CEILING(-4.3,-2)', "A1", ws); assert.ok(oParser.parse(), 'ISO.CEILING(-4.3,-2)'); assert.strictEqual(oParser.calculate().getValue(), -4, 'ISO.CEILING(-4.3,-2)'); testArrayFormula2(assert, "ISO.CEILING", 1, 2); }); QUnit.test("Test: \"ISBLANK\"", function (assert) { ws.getRange2("A202").setValue(""); ws.getRange2("A203").setValue("test"); oParser = new parserFormula('ISBLANK(A202)', "A1", ws); assert.ok(oParser.parse(), 'ISBLANK(A202)'); assert.strictEqual(oParser.calculate().getValue(), "TRUE", 'ISBLANK(A202)'); oParser = new parserFormula('ISBLANK(A203)', "A1", ws); assert.ok(oParser.parse(), 'ISBLANK(A203)'); assert.strictEqual(oParser.calculate().getValue(), "FALSE", 'ISBLANK(A203)'); testArrayFormula2(assert, "ISBLANK", 1, 1); }); QUnit.test("Test: \"ISERROR\"", function (assert) { ws.getRange2("A202").setValue(""); ws.getRange2("A203").setValue("#N/A"); oParser = new parserFormula('ISERROR(A202)', "A1", ws); assert.ok(oParser.parse(), 'ISERROR(A202)'); assert.strictEqual(oParser.calculate().getValue(), "FALSE", 'ISERROR(A202)'); oParser = new parserFormula('ISERROR(A203)', "A1", ws); assert.ok(oParser.parse(), 'ISERROR(A203)'); assert.strictEqual(oParser.calculate().getValue(), "TRUE", 'ISERROR(A203)'); testArrayFormula2(assert, "ISERROR", 1, 1); }); QUnit.test("Test: \"ISERR\"", function (assert) { ws.getRange2("A202").setValue(""); ws.getRange2("A203").setValue("#N/A"); ws.getRange2("A204").setValue("#VALUE!"); oParser = new parserFormula('ISERR(A202)', "A1", ws); assert.ok(oParser.parse(), 'ISERR(A202)'); assert.strictEqual(oParser.calculate().getValue(), "FALSE", 'ISERR(A202)'); oParser = new parserFormula('ISERR(A203)', "A1", ws); assert.ok(oParser.parse(), 'ISERR(A203)'); assert.strictEqual(oParser.calculate().getValue(), "FALSE", 'ISERR(A203)'); oParser = new parserFormula('ISERR(A203)', "A1", ws); assert.ok(oParser.parse(), 'ISERR(A203)'); assert.strictEqual(oParser.calculate().getValue(), "FALSE", 'ISERR(A203)'); testArrayFormula2(assert, "ISERR", 1, 1); }); QUnit.test("Test: \"ISEVEN\"", function (assert) { oParser = new parserFormula('ISEVEN(-1)', "A1", ws); assert.ok(oParser.parse(), 'ISEVEN(-1)'); assert.strictEqual(oParser.calculate().getValue(), "FALSE", 'ISEVEN(-1)'); oParser = new parserFormula('ISEVEN(2.5)', "A1", ws); assert.ok(oParser.parse(), 'ISEVEN(2.5)'); assert.strictEqual(oParser.calculate().getValue(), "TRUE", 'ISEVEN(2.5)'); oParser = new parserFormula('ISEVEN(5)', "A1", ws); assert.ok(oParser.parse(), 'ISEVEN(5)'); assert.strictEqual(oParser.calculate().getValue(), "FALSE", 'ISEVEN(5)'); oParser = new parserFormula('ISEVEN(0)', "A1", ws); assert.ok(oParser.parse(), 'ISEVEN(0)'); assert.strictEqual(oParser.calculate().getValue(), "TRUE", 'ISEVEN(0)'); oParser = new parserFormula('ISEVEN(12/23/2011)', "A1", ws); assert.ok(oParser.parse(), 'ISEVEN(12/23/2011)'); assert.strictEqual(oParser.calculate().getValue(), "TRUE", 'ISEVEN(12/23/2011)'); testArrayFormula2(assert, "ISEVEN", 1, 1, true, null); }); QUnit.test("Test: \"ISLOGICAL\"", function (assert) { oParser = new parserFormula('ISLOGICAL(TRUE)', "A1", ws); assert.ok(oParser.parse(), 'ISLOGICAL(TRUE)'); assert.strictEqual(oParser.calculate().getValue(), "TRUE", 'ISLOGICAL(TRUE)'); oParser = new parserFormula('ISLOGICAL("TRUE")', "A1", ws); assert.ok(oParser.parse(), 'ISLOGICAL("TRUE")'); assert.strictEqual(oParser.calculate().getValue(), "FALSE", 'ISLOGICAL("TRUE")'); testArrayFormula2(assert, "ISLOGICAL", 1, 1); }); QUnit.test("Test: \"CEILING\"", function (assert) { oParser = new parserFormula('CEILING(2.5, 1)', "A1", ws); assert.ok(oParser.parse(), 'CEILING(2.5, 1)'); assert.strictEqual(oParser.calculate().getValue(), 3, 'CEILING(2.5, 1)'); oParser = new parserFormula('CEILING(-2.5, -2)', "A1", ws); assert.ok(oParser.parse(), 'CEILING(-2.5, -2)'); assert.strictEqual(oParser.calculate().getValue(), -4, 'CEILING(-2.5, -2)'); oParser = new parserFormula('CEILING(-2.5, 2)', "A1", ws); assert.ok(oParser.parse(), 'CEILING(-2.5, 2)'); assert.strictEqual(oParser.calculate().getValue(), -2, 'CEILING(-2.5, 2)'); oParser = new parserFormula('CEILING(1.5, 0.1)', "A1", ws); assert.ok(oParser.parse(), 'CEILING(1.5, 0.1)'); assert.strictEqual(oParser.calculate().getValue(), 1.5, 'CEILING(1.5, 0.1)'); oParser = new parserFormula('CEILING(0.234, 0.01)', "A1", ws); assert.ok(oParser.parse(), 'CEILING(0.234, 0.01)'); assert.strictEqual(oParser.calculate().getValue(), 0.24, 'CEILING(0.234, 0.01)'); testArrayFormula2(assert, "CEILING", 2, 2); }); QUnit.test("Test: \"ECMA.CEILING\"", function (assert) { oParser = new parserFormula('ECMA.CEILING(2.5, 1)', "A1", ws); assert.ok(oParser.parse(), 'ECMA.CEILING(2.5, 1)'); assert.strictEqual(oParser.calculate().getValue(), 3, 'ECMA.CEILING(2.5, 1)'); oParser = new parserFormula('ECMA.CEILING(-2.5, -2)', "A1", ws); assert.ok(oParser.parse(), 'ECMA.CEILING(-2.5, -2)'); assert.strictEqual(oParser.calculate().getValue(), -4, 'ECMA.CEILING(-2.5, -2)'); oParser = new parserFormula('ECMA.CEILING(-2.5, 2)', "A1", ws); assert.ok(oParser.parse(), 'ECMA.CEILING(-2.5, 2)'); assert.strictEqual(oParser.calculate().getValue(), -2, 'ECMA.CEILING(-2.5, 2)'); oParser = new parserFormula('ECMA.CEILING(1.5, 0.1)', "A1", ws); assert.ok(oParser.parse(), 'ECMA.CEILING(1.5, 0.1)'); assert.strictEqual(oParser.calculate().getValue(), 1.5, 'ECMA.CEILING(1.5, 0.1)'); oParser = new parserFormula('ECMA.CEILING(0.234, 0.01)', "A1", ws); assert.ok(oParser.parse(), 'ECMA.CEILING(0.234, 0.01)'); assert.strictEqual(oParser.calculate().getValue(), 0.24, 'ECMA.CEILING(0.234, 0.01)'); }); QUnit.test("Test: \"COMBINA\"", function (assert) { oParser = new parserFormula('COMBINA(4,3)', "A1", ws); assert.ok(oParser.parse(), 'COMBINA(4,3)'); assert.strictEqual(oParser.calculate().getValue(), 20, 'COMBINA(4,3)'); oParser = new parserFormula('COMBINA(10,3)', "A1", ws); assert.ok(oParser.parse(), 'COMBINA(10,3)'); assert.strictEqual(oParser.calculate().getValue(), 220, 'COMBINA(10,3)'); oParser = new parserFormula('COMBINA(3,10)', "A1", ws); assert.ok(oParser.parse(), 'COMBINA(3,10)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'COMBINA(10,3)'); oParser = new parserFormula('COMBINA(10,-3)', "A1", ws); assert.ok(oParser.parse(), 'COMBINA(10,-3)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'COMBINA(10,-3)'); testArrayFormula2(assert, "COMBINA", 2, 2); }); QUnit.test("Test: \"DECIMAL\"", function (assert) { oParser = new parserFormula('DECIMAL("FF",16)', "A1", ws); assert.ok(oParser.parse(), 'DECIMAL("FF",16)'); assert.strictEqual(oParser.calculate().getValue(), 255, 'DECIMAL("FF",16)'); oParser = new parserFormula('DECIMAL(111,2)', "A1", ws); assert.ok(oParser.parse(), 'DECIMAL(111,2)'); assert.strictEqual(oParser.calculate().getValue(), 7, 'DECIMAL(111,2)'); oParser = new parserFormula('DECIMAL("zap",36)', "A1", ws); assert.ok(oParser.parse(), 'DECIMAL("zap",36)'); assert.strictEqual(oParser.calculate().getValue(), 45745, 'DECIMAL("zap",36)'); oParser = new parserFormula('DECIMAL("00FF",16)', "A1", ws); assert.ok(oParser.parse(), 'DECIMAL("00FF",16)'); assert.strictEqual(oParser.calculate().getValue(), 255, 'DECIMAL("00FF",16)'); oParser = new parserFormula('DECIMAL("101b",2)', "A1", ws); assert.ok(oParser.parse(), 'DECIMAL("101b",2)'); assert.strictEqual(oParser.calculate().getValue(), 5, 'DECIMAL("101b",2)'); testArrayFormula2(assert, "DECIMAL", 2, 2); }); QUnit.test("Test: \"BASE\"", function (assert) { oParser = new parserFormula('BASE(7,2)', "A1", ws); assert.ok(oParser.parse(), 'BASE(7,2)'); assert.strictEqual(oParser.calculate().getValue(), "111", 'BASE(7,2)'); oParser = new parserFormula('BASE(100,16)', "A1", ws); assert.ok(oParser.parse(), 'BASE(100,16)'); assert.strictEqual(oParser.calculate().getValue(), "64", 'BASE(100,16)'); oParser = new parserFormula('BASE(15,2,10)', "A1", ws); assert.ok(oParser.parse(), 'BASE(15,2,10)'); assert.strictEqual(oParser.calculate().getValue(), "0000001111", 'BASE(15,2,10)'); testArrayFormula2(assert, "BASE", 2, 3); }); QUnit.test("Test: \"ARABIC('LVII')\"", function (assert) { oParser = new parserFormula('ARABIC("LVII")', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 57); }); QUnit.test("Test: \"TDIST\"", function (assert) { oParser = new parserFormula("TDIST(60,1,2)", "A1", ws); assert.ok(oParser.parse(), "TDIST(60,1,2)"); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 0.010609347, "TDIST(60,1,2)"); oParser = new parserFormula("TDIST(8,3,1)", "A1", ws); assert.ok(oParser.parse(), "TDIST(8,3,1)"); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 0.002038289, "TDIST(8,3,1)"); ws.getRange2("A2").setValue("1.959999998"); ws.getRange2("A3").setValue("60"); oParser = new parserFormula("TDIST(A2,A3,2)", "A1", ws); assert.ok(oParser.parse(), "TDIST(A2,A3,2)"); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 0.054644930, "TDIST(A2,A3,2)"); oParser = new parserFormula("TDIST(A2,A3,1)", "A1", ws); assert.ok(oParser.parse(), "TDIST(A2,A3,1)"); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 0.027322465, "TDIST(A2,A3,1)"); testArrayFormula2(assert, "TDIST", 3, 3); }); QUnit.test("Test: \"T.DIST\"", function (assert) { oParser = new parserFormula("T.DIST(60,1,TRUE)", "A1", ws); assert.ok(oParser.parse(), "T.DIST(60,1,TRUE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 0.99469533, "T.DIST(60,1,TRUE)"); oParser = new parserFormula("T.DIST(8,3,FALSE)", "A1", ws); assert.ok(oParser.parse(), "T.DIST(8,3,FALSE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 0.00073691, "T.DIST(8,3,FALSE)"); testArrayFormula2(assert, "T.DIST", 3, 3); }); QUnit.test("Test: \"T.DIST.2T\"", function (assert) { ws.getRange2("A2").setValue("1.959999998"); ws.getRange2("A3").setValue("60"); oParser = new parserFormula("T.DIST.2T(A2,A3)", "A1", ws); assert.ok(oParser.parse(), "T.DIST.2T(A2,A3)"); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 0.054644930, "T.DIST.2T(A2,A3)"); testArrayFormula2(assert, "T.DIST.2T", 2, 2); }); QUnit.test("Test: \"T.DIST.RT\"", function (assert) { ws.getRange2("A2").setValue("1.959999998"); ws.getRange2("A3").setValue("60"); oParser = new parserFormula("T.DIST.RT(A2,A3)", "A1", ws); assert.ok(oParser.parse(), "T.DIST.RT(A2,A3)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.027322, "T.DIST.RT(A2,A3)"); testArrayFormula2(assert, "T.DIST.RT", 2, 2); }); QUnit.test("Test: \"TTEST\"", function (assert) { ws.getRange2("A2").setValue("3"); ws.getRange2("A3").setValue("4"); ws.getRange2("A4").setValue("5"); ws.getRange2("A5").setValue("8"); ws.getRange2("A6").setValue("9"); ws.getRange2("A7").setValue("1"); ws.getRange2("A8").setValue("2"); ws.getRange2("A9").setValue("4"); ws.getRange2("A10").setValue("5"); ws.getRange2("B2").setValue("6"); ws.getRange2("B3").setValue("19"); ws.getRange2("B4").setValue("3"); ws.getRange2("B5").setValue("2"); ws.getRange2("B6").setValue("14"); ws.getRange2("B7").setValue("4"); ws.getRange2("B8").setValue("5"); ws.getRange2("B9").setValue("17"); ws.getRange2("B10").setValue("1"); oParser = new parserFormula("TTEST(A2:A10,B2:B10,2,1)", "A1", ws); assert.ok(oParser.parse(), "TTEST(A2:A10,B2:B10,2,1)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.196016, "TTEST(A2:A10,B2:B10,2,1)"); //TODO нужна другая функция для тестирования //testArrayFormula2(assert, "TTEST", 4, 4, null, true); }); QUnit.test("Test: \"T.TEST\"", function (assert) { ws.getRange2("A2").setValue("3"); ws.getRange2("A3").setValue("4"); ws.getRange2("A4").setValue("5"); ws.getRange2("A5").setValue("8"); ws.getRange2("A6").setValue("9"); ws.getRange2("A7").setValue("1"); ws.getRange2("A8").setValue("2"); ws.getRange2("A9").setValue("4"); ws.getRange2("A10").setValue("5"); ws.getRange2("B2").setValue("6"); ws.getRange2("B3").setValue("19"); ws.getRange2("B4").setValue("3"); ws.getRange2("B5").setValue("2"); ws.getRange2("B6").setValue("14"); ws.getRange2("B7").setValue("4"); ws.getRange2("B8").setValue("5"); ws.getRange2("B9").setValue("17"); ws.getRange2("B10").setValue("1"); oParser = new parserFormula("T.TEST(A2:A10,B2:B10,2,1)", "A1", ws); assert.ok(oParser.parse(), "T.TEST(A2:A10,B2:B10,2,1)"); assert.strictEqual(oParser.calculate().getValue().toFixed(5) - 0, 0.19602, "T.TEST(A2:A10,B2:B10,2,1)"); }); QUnit.test("Test: \"ZTEST\"", function (assert) { ws.getRange2("A2").setValue("3"); ws.getRange2("A3").setValue("6"); ws.getRange2("A4").setValue("7"); ws.getRange2("A5").setValue("8"); ws.getRange2("A6").setValue("6"); ws.getRange2("A7").setValue("5"); ws.getRange2("A8").setValue("4"); ws.getRange2("A9").setValue("2"); ws.getRange2("A10").setValue("1"); ws.getRange2("A11").setValue("9"); oParser = new parserFormula("ZTEST(A2:A11,4)", "A1", ws); assert.ok(oParser.parse(), "ZTEST(A2:A11,4)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.090574, "ZTEST(A2:A11,4)"); oParser = new parserFormula("2 * MIN(ZTEST(A2:A11,4), 1 - ZTEST(A2:A11,4))", "A1", ws); assert.ok(oParser.parse(), "2 * MIN(ZTEST(A2:A11,4), 1 - ZTEST(A2:A11,4))"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.181148, "2 * MIN(ZTEST(A2:A11,4), 1 - ZTEST(A2:A11,4))"); oParser = new parserFormula("ZTEST(A2:A11,6)", "A1", ws); assert.ok(oParser.parse(), "ZTEST(A2:A11,6)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.863043, "ZTEST(A2:A11,6)"); oParser = new parserFormula("2 * MIN(ZTEST(A2:A11,6), 1 - ZTEST(A2:A11,6))", "A1", ws); assert.ok(oParser.parse(), "2 * MIN(ZTEST(A2:A11,6), 1 - ZTEST(A2:A11,6))"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.273913, "2 * MIN(ZTEST(A2:A11,6), 1 - ZTEST(A2:A11,6))"); //TODO нужна другая функция для тестирования //testArrayFormula2(assert, "Z.TEST", 2, 3, null, true); }); QUnit.test("Test: \"Z.TEST\"", function (assert) { ws.getRange2("A2").setValue("3"); ws.getRange2("A3").setValue("6"); ws.getRange2("A4").setValue("7"); ws.getRange2("A5").setValue("8"); ws.getRange2("A6").setValue("6"); ws.getRange2("A7").setValue("5"); ws.getRange2("A8").setValue("4"); ws.getRange2("A9").setValue("2"); ws.getRange2("A10").setValue("1"); ws.getRange2("A11").setValue("9"); oParser = new parserFormula("Z.TEST(A2:A11,4)", "A1", ws); assert.ok(oParser.parse(), "Z.TEST(A2:A11,4)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.090574, "Z.TEST(A2:A11,4)"); oParser = new parserFormula("2 * MIN(Z.TEST(A2:A11,4), 1 - Z.TEST(A2:A11,4))", "A1", ws); assert.ok(oParser.parse(), "2 * MIN(Z.TEST(A2:A11,4), 1 - Z.TEST(A2:A11,4))"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.181148, "2 * MIN(Z.TEST(A2:A11,4), 1 - Z.TEST(A2:A11,4))"); oParser = new parserFormula("Z.TEST(A2:A11,6)", "A1", ws); assert.ok(oParser.parse(), "Z.TEST(A2:A11,6)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.863043, "Z.TEST(A2:A11,6)"); oParser = new parserFormula("2 * MIN(Z.TEST(A2:A11,6), 1 - Z.TEST(A2:A11,6))", "A1", ws); assert.ok(oParser.parse(), "2 * MIN(Z.TEST(A2:A11,6), 1 - Z.TEST(A2:A11,6))"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.273913, "2 * MIN(Z.TEST(A2:A11,6), 1 - Z.TEST(A2:A11,6))"); //TODO нужна другая функция для тестирования //testArrayFormula2(assert, "Z.TEST", 2, 3, null, true); }); QUnit.test("Test: \"F.DIST\"", function (assert) { ws.getRange2("A2").setValue("15.2069"); ws.getRange2("A3").setValue("6"); ws.getRange2("A4").setValue("4"); oParser = new parserFormula("F.DIST(A2,A3,A4,TRUE)", "A1", ws); assert.ok(oParser.parse(), "F.DIST(A2,A3,A4,TRUE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.99, "F.DIST(A2,A3,A4,TRUE)"); oParser = new parserFormula("F.DIST(A2,A3,A4,FALSE)", "A1", ws); assert.ok(oParser.parse(), "F.DIST(A2,A3,A4,FALSE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.0012238, "F.DIST(A2,A3,A4,FALSE)"); testArrayFormula2(assert, "F.DIST", 4, 4); }); QUnit.test("Test: \"F.DIST.RT\"", function (assert) { ws.getRange2("A2").setValue("15.2069"); ws.getRange2("A3").setValue("6"); ws.getRange2("A4").setValue("4"); oParser = new parserFormula("F.DIST.RT(A2,A3,A4)", "A1", ws); assert.ok(oParser.parse(), "F.DIST.RT(A2,A3,A4)"); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.01, "F.DIST.RT(A2,A3,A4)"); testArrayFormula2(assert, "F.DIST.RT", 3, 3); }); QUnit.test("Test: \"FDIST\"", function (assert) { ws.getRange2("A2").setValue("15.2069"); ws.getRange2("A3").setValue("6"); ws.getRange2("A4").setValue("4"); oParser = new parserFormula("FDIST(A2,A3,A4)", "A1", ws); assert.ok(oParser.parse(), "FDIST(A2,A3,A4)"); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.01, "FDIST(A2,A3,A4)"); }); QUnit.test("Test: \"FINV\"", function (assert) { ws.getRange2("A2").setValue("0.01"); ws.getRange2("A3").setValue("6"); ws.getRange2("A4").setValue("4"); oParser = new parserFormula("FINV(A2,A3,A4)", "A1", ws); assert.ok(oParser.parse(), "FINV(A2,A3,A4)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 15.206865, "FINV(A2,A3,A4)"); testArrayFormula2(assert, "FINV", 3, 3); }); QUnit.test("Test: \"F.INV\"", function (assert) { ws.getRange2("A2").setValue("0.01"); ws.getRange2("A3").setValue("6"); ws.getRange2("A4").setValue("4"); oParser = new parserFormula("F.INV(A2,A3,A4)", "A1", ws); assert.ok(oParser.parse(), "F.INV(A2,A3,A4)"); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 0.10930991, "F.INV(A2,A3,A4)"); testArrayFormula2(assert, "F.INV", 3, 3); }); QUnit.test("Test: \"F.INV.RT\"", function (assert) { ws.getRange2("A2").setValue("0.01"); ws.getRange2("A3").setValue("6"); ws.getRange2("A4").setValue("4"); oParser = new parserFormula("F.INV.RT(A2,A3,A4)", "A1", ws); assert.ok(oParser.parse(), "F.INV.RT(A2,A3,A4)"); assert.strictEqual(oParser.calculate().getValue().toFixed(5) - 0, 15.20686, "F.INV.RT(A2,A3,A4)"); }); function fTestFormulaTest(assert) { ws.getRange2("A2").setValue("6"); ws.getRange2("A3").setValue("7"); ws.getRange2("A4").setValue("9"); ws.getRange2("A5").setValue("15"); ws.getRange2("A6").setValue("21"); ws.getRange2("B2").setValue("20"); ws.getRange2("B3").setValue("28"); ws.getRange2("B4").setValue("31"); ws.getRange2("B5").setValue("38"); ws.getRange2("B6").setValue("40"); oParser = new parserFormula("FTEST(A2:A6,B2:B6)", "A1", ws); assert.ok(oParser.parse(), "FTEST(A2:A6,B2:B6)"); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 0.64831785, "FTEST(A2:A6,B2:B6)"); oParser = new parserFormula("FTEST(A2,B2:B6)", "A1", ws); assert.ok(oParser.parse(), "FTEST(A2,B2:B6)"); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "FTEST(A2,B2:B6)"); oParser = new parserFormula("FTEST(1,B2:B6)", "A1", ws); assert.ok(oParser.parse(), "FTEST(1,B2:B6)"); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "FTEST(1,B2:B6)"); oParser = new parserFormula("FTEST({1,2,3},{2,3,4,5})", "A1", ws); assert.ok(oParser.parse(), "FTEST({1,2,3},{2,3,4,5})"); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 0.792636779, "FTEST({1,2,3},{2,3,4,5})"); oParser = new parserFormula("FTEST({1,\"test\",\"test\"},{2,3,4,5})", "A1", ws); assert.ok(oParser.parse(), "FTEST({1,\"test\",\"test\"},{2,3,4,5})"); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "FTEST({1,\"test\",\"test\"},{2,3,4,5})"); } QUnit.test("Test: \"FTEST\"", function (assert) { fTestFormulaTest(assert); testArrayFormula2(assert, "FTEST", 2, 2, null, true); }); QUnit.test("Test: \"F.TEST\"", function (assert) { fTestFormulaTest(assert); testArrayFormula2(assert, "F.TEST", 2, 2, null, true); }); QUnit.test("Test: \"T.INV\"", function (assert) { oParser = new parserFormula("T.INV(0.75,2)", "A1", ws); assert.ok(oParser.parse(), "T.INV(0.75,2)"); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.8164966, "T.INV(0.75,2)"); testArrayFormula2(assert, "T.INV", 2, 2); }); QUnit.test("Test: \"T.INV.2T\"", function (assert) { ws.getRange2("A2").setValue("0.546449"); ws.getRange2("A3").setValue("60"); oParser = new parserFormula("T.INV.2T(A2,A3)", "A1", ws); assert.ok(oParser.parse(), "T.INV.2T(A2,A3)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.606533, "T.INV.2T(A2,A3)"); testArrayFormula2(assert, "T.INV.2T", 2, 2); }); QUnit.test("Test: \"RANK\"", function (assert) { ws.getRange2("A2").setValue("7"); ws.getRange2("A3").setValue("3.5"); ws.getRange2("A4").setValue("3.5"); ws.getRange2("A5").setValue("1"); ws.getRange2("A6").setValue("2"); oParser = new parserFormula("RANK(A3,A2:A6,1)", "A1", ws); assert.ok(oParser.parse(), "RANK(A3,A2:A6,1)"); assert.strictEqual(oParser.calculate().getValue(), 3, "RANK(A3,A2:A6,1)"); oParser = new parserFormula("RANK(A2,A2:A6,1)", "A1", ws); assert.ok(oParser.parse(), "RANK(A2,A2:A6,1)"); assert.strictEqual(oParser.calculate().getValue(), 5, "RANK(A2,A2:A6,1)"); }); QUnit.test("Test: \"RANK.EQ\"", function (assert) { ws.getRange2("A2").setValue("7"); ws.getRange2("A3").setValue("3.5"); ws.getRange2("A4").setValue("3.5"); ws.getRange2("A5").setValue("1"); ws.getRange2("A6").setValue("2"); oParser = new parserFormula("RANK.EQ(A2,A2:A6,1)", "A1", ws); assert.ok(oParser.parse(), "RANK.EQ(A2,A2:A6,1)"); assert.strictEqual(oParser.calculate().getValue(), 5, "RANK.EQ(A2,A2:A6,1)"); oParser = new parserFormula("RANK.EQ(A6,A2:A6)", "A1", ws); assert.ok(oParser.parse(), "RANK.EQ(A6,A2:A6)"); assert.strictEqual(oParser.calculate().getValue(), 4, "RANK.EQ(A6,A2:A6)"); oParser = new parserFormula("RANK.EQ(A3,A2:A6,1)", "A1", ws); assert.ok(oParser.parse(), "RANK.EQ(A3,A2:A6,1)"); assert.strictEqual(oParser.calculate().getValue(), 3, "RANK.EQ(A3,A2:A6,1)"); }); QUnit.test("Test: \"RANK.AVG\"", function (assert) { ws.getRange2("A2").setValue("89"); ws.getRange2("A3").setValue("88"); ws.getRange2("A4").setValue("92"); ws.getRange2("A5").setValue("101"); ws.getRange2("A6").setValue("94"); ws.getRange2("A7").setValue("97"); ws.getRange2("A8").setValue("95"); oParser = new parserFormula("RANK.AVG(94,A2:A8)", "A1", ws); assert.ok(oParser.parse(), "RANK.AVG(94,A2:A8)"); assert.strictEqual(oParser.calculate().getValue(), 4, "RANK.AVG(94,A2:A8)"); }); QUnit.test("Test: \"RADIANS\"", function (assert) { oParser = new parserFormula("RADIANS(270)", "A1", ws); assert.ok(oParser.parse(), "RADIANS(270)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 4.712389); testArrayFormula(assert, "RADIANS"); }); QUnit.test("Test: \"LOG\"", function (assert) { oParser = new parserFormula("LOG(10)", "A1", ws); assert.ok(oParser.parse(), "LOG(10)"); assert.strictEqual(oParser.calculate().getValue(), 1, "LOG(10)"); oParser = new parserFormula("LOG(8,2)", "A1", ws); assert.ok(oParser.parse(), "LOG(8,2)"); assert.strictEqual(oParser.calculate().getValue(), 3, "LOG(8,2)"); oParser = new parserFormula("LOG(86, 2.7182818)", "A1", ws); assert.ok(oParser.parse(), "LOG(86, 2.7182818)"); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 4.4543473, "LOG(86, 2.7182818)"); oParser = new parserFormula("LOG(8,1)", "A1", ws); assert.ok(oParser.parse(), "LOG(8,1)"); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "LOG(8,1)"); testArrayFormula(assert, "LOG", 1, 2); }); QUnit.test("Test: \"LOGNORM.DIST\"", function (assert) { ws.getRange2("A2").setValue("4"); ws.getRange2("A3").setValue("3.5"); ws.getRange2("A4").setValue("1.2"); oParser = new parserFormula("LOGNORM.DIST(A2,A3,A4,TRUE)", "A1", ws); assert.ok(oParser.parse(), "LOGNORM.DIST(A2,A3,A4,TRUE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.0390836, "LOGNORM.DIST(A2,A3,A4,TRUE)"); oParser = new parserFormula("LOGNORM.DIST(A2,A3,A4,FALSE)", "A1", ws); assert.ok(oParser.parse(), "LOGNORM.DIST(A2,A3,A4,FALSE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.0176176, "LOGNORM.DIST(A2,A3,A4,FALSE)"); testArrayFormula2(assert, "LOGNORM.DIST", 4, 4); }); QUnit.test("Test: \"LOGNORM.INV\"", function (assert) { ws.getRange2("A2").setValue("0.039084"); ws.getRange2("A3").setValue("3.5"); ws.getRange2("A4").setValue("1.2"); oParser = new parserFormula("LOGNORM.INV(A2, A3, A4)", "A1", ws); assert.ok(oParser.parse(), "LOGNORM.INV(A2, A3, A4)"); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 4.0000252, "LOGNORM.INV(A2, A3, A4)"); testArrayFormula2(assert, "LOGNORM.INV", 3, 3); }); QUnit.test("Test: \"LOGNORMDIST\"", function (assert) { ws.getRange2("A2").setValue("4"); ws.getRange2("A3").setValue("3.5"); ws.getRange2("A4").setValue("1.2"); oParser = new parserFormula("LOGNORMDIST(A2, A3, A4)", "A1", ws); assert.ok(oParser.parse(), "LOGNORMDIST(A2, A3, A4)"); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.0390836, "LOGNORMDIST(A2, A3, A4)"); testArrayFormula2(assert, "LOGNORMDIST", 3, 3); }); QUnit.test("Test: \"LOWER\"", function (assert) { ws.getRange2("A2").setValue("E. E. Cummings"); ws.getRange2("A3").setValue("Apt. 2B"); oParser = new parserFormula("LOWER(A2)", "A1", ws); assert.ok(oParser.parse(), "LOWER(A2)"); assert.strictEqual(oParser.calculate().getValue(), "e. e. cummings", "LOWER(A2)"); oParser = new parserFormula("LOWER(A3)", "A1", ws); assert.ok(oParser.parse(), "LOWER(A3)"); assert.strictEqual(oParser.calculate().getValue(), "apt. 2b", "LOWER(A3)"); testArrayFormula2(assert, "LOWER", 1, 1); }); QUnit.test("Test: \"EXPON.DIST\"", function (assert) { ws.getRange2("A2").setValue("0.2"); ws.getRange2("A3").setValue("10"); oParser = new parserFormula("EXPON.DIST(A2,A3,TRUE)", "A1", ws); assert.ok(oParser.parse(), "EXPON.DIST(A2,A3,TRUE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 0.86466472, "EXPON.DIST(A2,A3,TRUE)"); oParser = new parserFormula("EXPON.DIST(0.2,10,FALSE)", "A1", ws); assert.ok(oParser.parse(), "EXPON.DIST(0.2,10,FALSE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 1.35335283, "EXPON.DIST(0.2,10,FALSE)"); testArrayFormula2(assert, "EXPON.DIST", 3, 3); }); QUnit.test("Test: \"GAMMA.DIST\"", function (assert) { ws.getRange2("A2").setValue("10.00001131"); ws.getRange2("A3").setValue("9"); ws.getRange2("A4").setValue("2"); oParser = new parserFormula("GAMMA.DIST(A2,A3,A4,FALSE)", "A1", ws); assert.ok(oParser.parse(), "GAMMA.DIST(A2,A3,A4,FALSE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.032639, "GAMMA.DIST(A2,A3,A4,FALSE)"); oParser = new parserFormula("GAMMA.DIST(A2,A3,A4,TRUE)", "A1", ws); assert.ok(oParser.parse(), "GAMMA.DIST(A2,A3,A4,TRUE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.068094, "GAMMA.DIST(A2,A3,A4,TRUE)"); testArrayFormula2(assert, "GAMMA.DIST", 4, 4); }); QUnit.test("Test: \"GAMMADIST\"", function (assert) { ws.getRange2("A2").setValue("10.00001131"); ws.getRange2("A3").setValue("9"); ws.getRange2("A4").setValue("2"); oParser = new parserFormula("GAMMADIST(A2,A3,A4,FALSE)", "A1", ws); assert.ok(oParser.parse(), "GAMMADIST(A2,A3,A4,FALSE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.032639, "GAMMADIST(A2,A3,A4,FALSE)"); oParser = new parserFormula("GAMMADIST(A2,A3,A4,TRUE)", "A1", ws); assert.ok(oParser.parse(), "GAMMADIST(A2,A3,A4,TRUE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.068094, "GAMMADIST(A2,A3,A4,TRUE)"); }); QUnit.test("Test: \"GAMMADIST\"", function (assert) { oParser = new parserFormula("GAMMADIST(A2,A3,A4,FALSE)", "A1", ws); assert.ok(oParser.parse(), "GAMMADIST(A2,A3,A4,FALSE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.032639, "GAMMADIST(A2,A3,A4,FALSE)"); oParser = new parserFormula("GAMMADIST(A2,A3,A4,TRUE)", "A1", ws); assert.ok(oParser.parse(), "GAMMADIST(A2,A3,A4,TRUE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.068094, "GAMMADIST(A2,A3,A4,TRUE)"); }); QUnit.test("Test: \"GAMMA\"", function (assert) { oParser = new parserFormula("GAMMA(2.5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(3), "1.329"); oParser = new parserFormula("GAMMA(-3.75)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(3), "0.268"); oParser = new parserFormula("GAMMA(0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("GAMMA(-2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); testArrayFormula2(assert, "GAMMA", 1, 1); }); QUnit.test("Test: \"CHITEST\"", function (assert) { ws.getRange2("A2").setValue("58"); ws.getRange2("A3").setValue("11"); ws.getRange2("A4").setValue("10"); ws.getRange2("A5").setValue("x"); ws.getRange2("A6").setValue("45.35"); ws.getRange2("A7").setValue("17.56"); ws.getRange2("A8").setValue("16.09"); ws.getRange2("B2").setValue("35"); ws.getRange2("B3").setValue("25"); ws.getRange2("B4").setValue("23"); ws.getRange2("B5").setValue("x"); ws.getRange2("B6").setValue("47.65"); ws.getRange2("B7").setValue("18.44"); ws.getRange2("B8").setValue("16.91"); oParser = new parserFormula("CHITEST(A2:B4,A6:B8)", "A1", ws); assert.ok(oParser.parse(), "CHITEST(A2:B4,A6:B8)"); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.0003082, "CHITEST(A2:B4,A6:B8)"); testArrayFormula2(assert, "CHITEST", 2, 2, null, true); }); QUnit.test("Test: \"CHISQ.TEST\"", function (assert) { ws.getRange2("A2").setValue("58"); ws.getRange2("A3").setValue("11"); ws.getRange2("A4").setValue("10"); ws.getRange2("A5").setValue("x"); ws.getRange2("A6").setValue("45.35"); ws.getRange2("A7").setValue("17.56"); ws.getRange2("A8").setValue("16.09"); ws.getRange2("B2").setValue("35"); ws.getRange2("B3").setValue("25"); ws.getRange2("B4").setValue("23"); ws.getRange2("B5").setValue("x"); ws.getRange2("B6").setValue("47.65"); ws.getRange2("B7").setValue("18.44"); ws.getRange2("B8").setValue("16.91"); oParser = new parserFormula("CHISQ.TEST(A2:B4,A6:B8)", "A1", ws); assert.ok(oParser.parse(), "CHISQ.TEST(A2:B4,A6:B8)"); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.0003082, "CHISQ.TEST(A2:B4,A6:B8)"); }); QUnit.test("Test: \"CHITEST\"", function (assert) { ws.getRange2("A2").setValue("18.307"); ws.getRange2("A3").setValue("10"); oParser = new parserFormula("CHIDIST(A2,A3)", "A1", ws); assert.ok(oParser.parse(), "CHIDIST(A2,A3)"); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.0500006, "CHIDIST(A2,A3)"); testArrayFormula2(assert, "CHIDIST", 2, 2); }); QUnit.test("Test: \"GAUSS\"", function (assert) { oParser = new parserFormula("GAUSS(2)", "A1", ws); assert.ok(oParser.parse(), "GAUSS(2)"); assert.strictEqual(oParser.calculate().getValue().toFixed(5) - 0, 0.47725, "GAUSS(2)"); testArrayFormula2(assert, "GAUSS", 1, 1); }); QUnit.test("Test: \"CHISQ.DIST.RT\"", function (assert) { ws.getRange2("A2").setValue("18.307"); ws.getRange2("A3").setValue("10"); oParser = new parserFormula("CHISQ.DIST.RT(A2,A3)", "A1", ws); assert.ok(oParser.parse(), "CHISQ.DIST.RT(A2,A3)"); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.0500006, "CHISQ.DIST.RT(A2,A3)"); testArrayFormula2(assert, "CHISQ.INV.RT", 2, 2); }); QUnit.test("Test: \"CHISQ.INV\"", function (assert) { oParser = new parserFormula("CHISQ.INV(0.93,1)", "A1", ws); assert.ok(oParser.parse(), "CHISQ.INV(0.93,1)"); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 3.283020287, "CHISQ.INV(0.93,1)"); oParser = new parserFormula("CHISQ.INV(0.6,2)", "A1", ws); assert.ok(oParser.parse(), "CHISQ.INV(0.6,2)"); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 1.832581464, "CHISQ.INV(0.6,2)"); testArrayFormula2(assert, "CHISQ.INV", 2, 2); }); QUnit.test("Test: \"CHISQ.DIST\"", function (assert) { oParser = new parserFormula("CHISQ.DIST(0.5,1,TRUE)", "A1", ws); assert.ok(oParser.parse(), "CHISQ.DIST(0.5,1,TRUE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 0.52049988, "CHISQ.DIST(0.5,1,TRUE)"); oParser = new parserFormula("CHISQ.DIST(2,3,FALSE)", "A1", ws); assert.ok(oParser.parse(), "CHISQ.DIST(2,3,FALSE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 0.20755375, "CHISQ.DIST(2,3,FALSE)"); testArrayFormula2(assert, "CHISQ.DIST", 3, 3); }); QUnit.test("Test: \"CHIINV\"", function (assert) { ws.getRange2("A2").setValue("0.050001"); ws.getRange2("A3").setValue("10"); oParser = new parserFormula("CHIINV(A2,A3)", "A1", ws); assert.ok(oParser.parse(), "CHIINV(A2,A3)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 18.306973, "CHIINV(A2,A3)"); testArrayFormula2(assert, "CHIINV", 2, 2); }); QUnit.test("Test: \"CHISQ.INV.RT\"", function (assert) { ws.getRange2("A2").setValue("0.050001"); ws.getRange2("A3").setValue("10"); oParser = new parserFormula("CHISQ.INV.RT(A2,A3)", "A1", ws); assert.ok(oParser.parse(), "CHISQ.INV.RT(A2,A3)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 18.306973, "CHISQ.INV.RT(A2,A3)"); testArrayFormula2(assert, "CHISQ.INV.RT", 2, 2); }); QUnit.test("Test: \"CHOOSE\"", function (assert) { let array; ws.getRange2("A2").setValue("st"); ws.getRange2("A3").setValue("2nd"); ws.getRange2("A4").setValue("3rd"); ws.getRange2("A5").setValue("Finished"); ws.getRange2("B2").setValue("Nails"); ws.getRange2("B3").setValue("Screws"); ws.getRange2("B4").setValue("Nuts"); ws.getRange2("B5").setValue("Bolts"); oParser = new parserFormula("CHOOSE(2,A2,A3,A4,A5)", "A1", ws); assert.ok(oParser.parse(), "CHOOSE(2,A2,A3,A4,A5)"); assert.strictEqual(oParser.calculate().getValue().getValue(), "2nd", "CHOOSE(2,A2,A3,A4,A5)"); oParser = new parserFormula("CHOOSE(4,B2,B3,B4,B5)", "A1", ws); assert.ok(oParser.parse(), "CHOOSE(4,B2,B3,B4,B5)"); assert.strictEqual(oParser.calculate().getValue().getValue(), "Bolts", "CHOOSE(4,B2,B3,B4,B5))"); oParser = new parserFormula('CHOOSE(3,"Wide",115,"world",8)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "world"); // bool oParser = new parserFormula('CHOOSE(FALSE,1,2,3)', "A1", ws); assert.ok(oParser.parse(), 'CHOOSE(FALSE,1,2,3)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of CHOOSE(FALSE,1,2,3)'); oParser = new parserFormula('CHOOSE(TRUE,1,2,3)', "A1", ws); assert.ok(oParser.parse(), 'CHOOSE(TRUE,1,2,3)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of CHOOSE(TRUE,1,2,3)'); // string oParser = new parserFormula('CHOOSE("1",1,2,3)', "A1", ws); assert.ok(oParser.parse(), 'CHOOSE("1",1,2,3)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of CHOOSE("1",1,2,3)'); oParser = new parserFormula('CHOOSE("1s",1,2,3)', "A1", ws); assert.ok(oParser.parse(), 'CHOOSE("1s",1,2,3)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of CHOOSE("1s",1,2,3)'); // err ws.getRange2("B2").setValue("#N/A"); ws.getRange2("B3").setValue("#DIV/0!"); oParser = new parserFormula('CHOOSE(B2,1,2,3)', "A1", ws); assert.ok(oParser.parse(), 'CHOOSE(B2,1,2,3)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of CHOOSE(B2,1,2,3)'); oParser = new parserFormula('CHOOSE(1,B2,2,3)', "A1", ws); assert.ok(oParser.parse(), 'CHOOSE(1,B2,2,3)'); assert.strictEqual(oParser.calculate().getValue().getValue(), "#N/A", 'Result of CHOOSE(1,B2,2,3)'); oParser = new parserFormula('CHOOSE(B3,B2,2,3)', "A1", ws); assert.ok(oParser.parse(), 'CHOOSE(B3,B2,2,3)'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of CHOOSE(B3,B2,2,3)'); oParser = new parserFormula('CHOOSE(B3,B2,2,3)', "A1", ws); assert.ok(oParser.parse(), 'CHOOSE(B3,B2,2,3)'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of CHOOSE(B3,B2,2,3)'); oParser = new parserFormula('CHOOSE(#N/A,1,2,3)', "A1", ws); assert.ok(oParser.parse(), 'CHOOSE(#N/A,1,2,3)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of CHOOSE(#N/A,1,2,3)'); oParser = new parserFormula('CHOOSE(1,#N/A,2,3)', "A1", ws); assert.ok(oParser.parse(), 'CHOOSE(1,#N/A,2,3)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of CHOOSE(1,#N/A,2,3)'); oParser = new parserFormula('CHOOSE(#DIV/0!,#N/A,2,3)', "A1", ws); assert.ok(oParser.parse(), 'CHOOSE(#DIV/0!,#N/A,2,3)'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of CHOOSE(#DIV/0!,#N/A,2,3)'); oParser = new parserFormula('CHOOSE(#DIV/0!,#N/A,2,3)', "A1", ws); assert.ok(oParser.parse(), 'CHOOSE(#DIV/0!,#N/A,2,3)'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of CHOOSE(#DIV/0!,#N/A,2,3)'); // arr oParser = new parserFormula('CHOOSE(2,1,{1,2,3},3)', "A1", ws); assert.ok(oParser.parse(), 'CHOOSE(2,1,{1,2,3},3)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of CHOOSE(2,1,{1,2,3},3)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, 'Result of CHOOSE(2,1,{1,2,3},3)[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 3, 'Result of CHOOSE(2,1,{1,2,3},3)[0,2]'); oParser = new parserFormula('CHOOSE({-1,0,1},1,2,3)', "A1", ws); assert.ok(oParser.parse(), 'CHOOSE({-1,0,1},1,2,3)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", 'Result of CHOOSE({-1,0,1},1,2,3)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", 'Result of CHOOSE({-1,0,1},1,2,3)[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 1, 'Result of CHOOSE({-1,0,1},1,2,3)[0,2]'); // for bug 58523 ws.getRange2("C1").setValue("CBT-1"); ws.getRange2("C2").setValue("CBT-2"); ws.getRange2("C3").setValue("CBT-3"); ws.getRange2("E1").setValue("HIS0361"); ws.getRange2("E2").setValue("HIS0362"); ws.getRange2("E3").setValue("HIS0363"); let bbox = ws.getRange2("G1").bbox; let cellWithFormula = new window['AscCommonExcel'].CCellWithFormula(ws, bbox.r1, bbox.c1); oParser = new parserFormula('CHOOSE({1,2},C1:C3,E1:E3)', cellWithFormula, ws); assert.ok(oParser.parse(), 'CHOOSE({1,2},C1:C3,E1:E3)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "CBT-1", 'Result of CHOOSE({1,2},C1:C3,E1:E3)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "HIS0361", 'Result of CHOOSE({1,2},C1:C3,E1:E3)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "CBT-2", 'Result of CHOOSE({1,2},C1:C3,E1:E3)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "HIS0362", 'Result of CHOOSE({1,2},C1:C3,E1:E3)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "CBT-3", 'Result of CHOOSE({1,2},C1:C3,E1:E3)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "HIS0363", 'Result of CHOOSE({1,2},C1:C3,E1:E3)[2,1]'); bbox = ws.getRange2("G2").bbox; cellWithFormula = new window['AscCommonExcel'].CCellWithFormula(ws, bbox.r1, bbox.c1); oParser = new parserFormula('CHOOSE({1,2},C1:C3,E1:E3)', cellWithFormula, ws); assert.ok(oParser.parse(), 'CHOOSE({1,2},C1:C3,E1:E3)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "CBT-1", 'Result of CHOOSE({1,2},C1:C3,E1:E3)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "HIS0361", 'Result of CHOOSE({1,2},C1:C3,E1:E3)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "CBT-2", 'Result of CHOOSE({1,2},C1:C3,E1:E3)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "HIS0362", 'Result of CHOOSE({1,2},C1:C3,E1:E3)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "CBT-3", 'Result of CHOOSE({1,2},C1:C3,E1:E3)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "HIS0363", 'Result of CHOOSE({1,2},C1:C3,E1:E3)[2,1]'); bbox = ws.getRange2("G3").bbox; cellWithFormula = new window['AscCommonExcel'].CCellWithFormula(ws, bbox.r1, bbox.c1); oParser = new parserFormula('CHOOSE({"",2},C1:C3,E1:E3)', cellWithFormula, ws); assert.ok(oParser.parse(), 'CHOOSE({"",2},C1:C3,E1:E3)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", 'Result of CHOOSE({"",2},C1:C3,E1:E3)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "HIS0361", 'Result of CHOOSE({"",2},C1:C3,E1:E3)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", 'Result of CHOOSE({"",2},C1:C3,E1:E3)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "HIS0362", 'Result of CHOOSE({"",2},C1:C3,E1:E3)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#VALUE!", 'Result of CHOOSE({"",2},C1:C3,E1:E3)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "HIS0363", 'Result of CHOOSE({"",2},C1:C3,E1:E3)[2,1]'); bbox = ws.getRange2("G3").bbox; cellWithFormula = new window['AscCommonExcel'].CCellWithFormula(ws, bbox.r1, bbox.c1); oParser = new parserFormula('CHOOSE({1,1.1},C1:C3,E1:E3)', cellWithFormula, ws); assert.ok(oParser.parse(), 'CHOOSE({1,1.1},C1:C3,E1:E3)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "CBT-1", 'Result of CHOOSE({1,1.1},C1:C3,E1:E3)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "CBT-1", 'Result of CHOOSE({1,1.1},C1:C3,E1:E3)[0,1]'); bbox = ws.getRange2("G3").bbox; cellWithFormula = new window['AscCommonExcel'].CCellWithFormula(ws, bbox.r1, bbox.c1); oParser = new parserFormula('CHOOSE({1,1.9},C1:C3,E1:E3)', cellWithFormula, ws); assert.ok(oParser.parse(), 'CHOOSE({1,1.9},C1:C3,E1:E3)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "CBT-1", 'Result of CHOOSE({1,1.9},C1:C3,E1:E3)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "CBT-1", 'Result of CHOOSE({1,1.9},C1:C3,E1:E3)[0,1]'); bbox = ws.getRange2("G3").bbox; cellWithFormula = new window['AscCommonExcel'].CCellWithFormula(ws, bbox.r1, bbox.c1); oParser = new parserFormula('CHOOSE({1,2.1},C1:C3,E1:E3)', cellWithFormula, ws); assert.ok(oParser.parse(), 'CHOOSE({1,2.1},C1:C3,E1:E3)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "CBT-1", 'Result of CHOOSE({1,2.1},C1:C3,E1:E3)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "HIS0361", 'Result of CHOOSE({1,2.1},C1:C3,E1:E3)[0,1]'); // for bug 67639 let arraySize; ws.getRange2("A102").setValue("23"); ws.getRange2("A103").setValue("45"); ws.getRange2("A104").setValue("12"); ws.getRange2("A105").setValue("10"); ws.getRange2("B102").setValue("1"); ws.getRange2("B103").setValue("2"); ws.getRange2("B104").setValue("3"); ws.getRange2("C102").setValue("2"); ws.getRange2("C103").setValue("1"); ws.getRange2("E102").setValue("ds"); ws.getRange2("E103").setValue("fasf"); ws.getRange2("E104").setValue("gas"); ws.getRange2("F102").setValue("123das"); ws.getRange2("F103").setValue("jkl"); ws.getRange2("F104").setValue("zcasd"); oParser = new parserFormula('SUM(A102:CHOOSE(2,A103,A104,A105))', "A1", ws); assert.ok(oParser.parse(), 'SUM(A102:CHOOSE(2,A103,A104,A105))'); assert.strictEqual(oParser.calculate().getValue(), 80, 'Result of SUM(A102:CHOOSE(2,A103,A104,A105))'); oParser = new parserFormula('SIN(A102:CHOOSE(2,A103,A104,A105))', "A1", ws); assert.ok(oParser.parse(), 'SIN(A102:CHOOSE(2,A103,A104,A105))'); oParser.setArrayFormulaRef(ws.getRange2("E200:F210").bbox); array = oParser.calculate(); arraySize = array.getDimensions(); assert.ok(arraySize.row === 3 && arraySize.col === 1, 'Array size in SIN(A102:CHOOSE(2,A103,A104,A105))'); assert.strictEqual(array.getElementRowCol(0, 0).getValue().toFixed(2), "-0.85", 'Result of SIN(A102:CHOOSE(2,A103,A104,A105))[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue().toFixed(2), "0.85", 'Result of SIN(A102:CHOOSE(2,A103,A104,A105))[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue().toFixed(2), "-0.54", 'Result of SIN(A102:CHOOSE(2,A103,A104,A105))[2,0]'); oParser = new parserFormula('CHOOSE({1,2},A102:A104,B102:B103)', "A1", ws); assert.ok(oParser.parse(), 'CHOOSE({1,2},A102:A104,B102:B103)'); array = oParser.calculate(); arraySize = array.getDimensions(); assert.ok(arraySize.row === 3 && arraySize.col === 2, 'Array size in CHOOSE({1,2},A102:A104,B102:B103'); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 23, 'Result of CHOOSE({1,2},A102:A104,B102:B103[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, 'Result of CHOOSE({1,2},A102:A104,B102:B103[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 45, 'Result of CHOOSE({1,2},A102:A104,B102:B103[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 2, 'Result of CHOOSE({1,2},A102:A104,B102:B103[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 12, 'Result of CHOOSE({1,2},A102:A104,B102:B103[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#N/A", 'Result of CHOOSE({1,2},A102:A104,B102:B103[2,1]'); oParser = new parserFormula('CHOOSE(B102:C102,A102:A104,B102:B103)', "A1", ws); assert.ok(oParser.parse(), 'CHOOSE(B102:C102,A102:A104,B102:B103)'); array = oParser.calculate(); arraySize = array.getDimensions(); assert.ok(arraySize.row === 3 && arraySize.col === 2, 'Array size in CHOOSE(B102:C102,A102:A104,B102:B103)'); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 23, 'Result of CHOOSE(B102:C102,A102:A104,B102:B103[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, 'Result of CHOOSE({B102:C102,A102:A104,B102:B103[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 45, 'Result of CHOOSE(B102:C102,A102:A104,B102:B103[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 2, 'Result of CHOOSE(B102:C102,A102:A104,B102:B103[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 12, 'Result of CHOOSE(B102:C102,A102:A104,B102:B103[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#N/A", 'Result of CHOOSE(B102:C102,A102:A104,B102:B103[2,1]'); oParser = new parserFormula('CHOOSE(B102:C102,A102:B104,9)', "A1", ws); assert.ok(oParser.parse(), 'CHOOSE(B102:C102,A102:B104,9)'); array = oParser.calculate(); arraySize = array.getDimensions(); assert.ok(arraySize.row === 3 && arraySize.col === 2, 'Array size in CHOOSE(B102:C102,A102:B104,9)'); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 23, 'Result of CHOOSE(B102:C102,A102:B104,9)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 9, 'Result of CHOOSE(B102:C102,A102:B104,9)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 45, 'Result of CHOOSE(B102:C102,A102:B104,9)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 9, 'Result of CHOOSE(B102:C102,A102:B104,9)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 12, 'Result of CHOOSE(B102:C102,A102:B104,9)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 9, 'Result of CHOOSE(B102:C102,A102:B104,9)[2,1]'); oParser = new parserFormula('CHOOSE(B102:C102,9,A102:B104)', "A1", ws); assert.ok(oParser.parse(), 'CHOOSE(B102:C102,9,A102:B104)'); array = oParser.calculate(); arraySize = array.getDimensions(); assert.ok(arraySize.row === 3 && arraySize.col === 2, 'Array size in CHOOSE(B102:C102,9,A102:B104)'); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 9, 'Result of CHOOSE(B102:C102,9,A102:B104)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, 'Result of CHOOSE(B102:C102,9,A102:B104)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 9, 'Result of CHOOSE(B102:C102,9,A102:B104)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 2, 'Result of CHOOSE(B102:C102,9,A102:B104)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 9, 'Result of CHOOSE(B102:C102,9,A102:B104)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 3, 'Result of CHOOSE(B102:C102,9,A102:B104)[2,1]'); oParser = new parserFormula('CHOOSE(B102:B103,A102:A105,E102:F104)', "A1", ws); assert.ok(oParser.parse(), 'CHOOSE(B102:B103,A102:A105,E102:F104)'); array = oParser.calculate(); arraySize = array.getDimensions(); assert.ok(arraySize.row === 4 && arraySize.col === 2, 'Array size in CHOOSE(B102:B103,A102:A105,E102:F104)'); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 23, 'Result of CHOOSE(B102:B103,A102:A105,E102:F104)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 23, 'Result of CHOOSE(B102:B103,A102:A105,E102:F104)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "fasf", 'Result of CHOOSE(B102:B103,A102:A105,E102:F104)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "jkl", 'Result of CHOOSE(B102:B103,A102:A105,E102:F104)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", 'Result of CHOOSE(B102:B103,A102:A105,E102:F104)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#N/A", 'Result of CHOOSE(B102:B103,A102:A105,E102:F104)[2,1]'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#N/A", 'Result of CHOOSE(B102:B103,A102:A105,E102:F104)[3,0]'); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), "#N/A", 'Result of CHOOSE(B102:B103,A102:A105,E102:F104)[3,1]'); oParser = new parserFormula('CHOOSE({1;2},A102:A105,E102:F104)', "A1", ws); assert.ok(oParser.parse(), 'CHOOSE({1;2},A102:A105,E102:F104)'); array = oParser.calculate(); arraySize = array.getDimensions(); assert.ok(arraySize.row === 4 && arraySize.col === 2, 'Array size in CHOOSE({1;2},A102:A105,E102:F104'); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 23, 'Result of CHOOSE({1;2},A102:A105,E102:F104)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 23, 'Result of CHOOSE({1;2},A102:A105,E102:F104)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "fasf", 'Result of CHOOSE({1;2},A102:A105,E102:F104)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "jkl", 'Result of CHOOSE({1;2},A102:A105,E102:F104)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", 'Result of CHOOSE({1;2},A102:A105,E102:F104)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#N/A", 'Result of CHOOSE({1;2},A102:A105,E102:F104)[2,1]'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#N/A", 'Result of CHOOSE({1;2},A102:A105,E102:F104)[3,0]'); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), "#N/A", 'Result of CHOOSE({1;2},A102:A105,E102:F104)[3,1]'); oParser = new parserFormula('CHOOSE({2,2;1,1;1,1},A102:A105,E102:F104)', "A1", ws); assert.ok(oParser.parse(), 'CHOOSE({2,2;1,1;1,1},A102:A105,E102:F104)'); array = oParser.calculate(); arraySize = array.getDimensions(); assert.ok(arraySize.row === 4 && arraySize.col === 2, 'Array size in CHOOSE({1;2},A102:A105,E102:F104'); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "ds", 'Result of CHOOSE({2,2;1,1;1,1},A102:A105,E102:F104)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "123das", 'Result of CHOOSE({2,2;1,1;1,1},A102:A105,E102:F104)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 45, 'Result of CHOOSE({2,2;1,1;1,1},A102:A105,E102:F104)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 45, 'Result of CHOOSE({2,2;1,1;1,1},A102:A105,E102:F104)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 12, 'Result of CHOOSE({2,2;1,1;1,1},A102:A105,E102:F104)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 12, 'Result of CHOOSE({2,2;1,1;1,1},A102:A105,E102:F104)[2,1]'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#N/A", 'Result of CHOOSE({2,2;1,1;1,1},A102:A105,E102:F104)[3,0]'); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), "#N/A", 'Result of CHOOSE({2,2;1,1;1,1},A102:A105,E102:F104)[3,1]'); //функция возвращает ref //testArrayFormula2(assert, "CHOOSE", 2, 9); }); QUnit.test("Test: \"CHOOSECOLS\"", function (assert) { //1. добавляем общие тесты ws.getRange2("A1").setValue("1"); ws.getRange2("A2").setValue("2"); ws.getRange2("A3").setValue(""); ws.getRange2("A4").setValue("4"); ws.getRange2("A5").setValue("#N/A"); ws.getRange2("A6").setValue("f"); ws.getRange2("B1").setValue("q"); ws.getRange2("B2").setValue("w"); ws.getRange2("B3").setValue("e"); ws.getRange2("B4").setValue("test"); ws.getRange2("B5").setValue("hhh"); ws.getRange2("B6").setValue("g"); ws.getRange2("C1").setValue("r"); ws.getRange2("C2").setValue("3"); ws.getRange2("C3").setValue("5"); ws.getRange2("C4").setValue(""); ws.getRange2("C5").setValue("6"); ws.getRange2("C6").setValue("h"); oParser = new parserFormula("CHOOSECOLS(A1:C6;-1;1)", "A1", ws); assert.ok(oParser.parse()); let array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 'r'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 5); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), ''); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 6); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 'h'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 2); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), ''); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), 4); assert.strictEqual(array.getElementRowCol(4, 1).getValue(), '#N/A'); assert.strictEqual(array.getElementRowCol(5, 1).getValue(), 'f'); oParser = new parserFormula("CHOOSECOLS(A1:C6;-2;3)", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 'q'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 'w'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 'e'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 'test'); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 'hhh'); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 'g'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 'r'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 3); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 5); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), ''); assert.strictEqual(array.getElementRowCol(4, 1).getValue(), 6); assert.strictEqual(array.getElementRowCol(5, 1).getValue(), 'h'); oParser = new parserFormula("CHOOSECOLS(A1:C6;-4;3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("CHOOSECOLS(A1:C6;-2;4)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("CHOOSECOLS(A1:C6;-2;0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2. аргументы - разные типы. нужно пербрать все аргументы //2.1 аргумент - number oParser = new parserFormula("CHOOSECOLS(1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.2 аргумент - string oParser = new parserFormula("CHOOSECOLS(\"test\",1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "test"); //2.3 аргумент - bool oParser = new parserFormula("CHOOSECOLS(true,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "TRUE"); //2.4 аргумент - error oParser = new parserFormula("CHOOSECOLS(#VALUE!,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.5 аргумент - empty oParser = new parserFormula("CHOOSECOLS(,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.6 аргумент - cellsRange //2.7 аргумент - cell oParser = new parserFormula("CHOOSECOLS(B1, 1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "q"); //2.8 аргумент - array oParser = new parserFormula("CHOOSECOLS({2;\"\";\"test\"},3)", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.8 аргумент - array oParser = new parserFormula("CHOOSECOLS({2,\"\",\"test\"},3)", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "test"); //2.2 аргумент - string oParser = new parserFormula("CHOOSECOLS(1,\"test\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.3 аргумент - bool oParser = new parserFormula("CHOOSECOLS(1,true)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.4 аргумент - error oParser = new parserFormula("CHOOSECOLS(1, #VALUE!)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.5 аргумент - empty oParser = new parserFormula("CHOOSECOLS(1,)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.6 аргумент - cellsRange //2.7 аргумент - cell oParser = new parserFormula("CHOOSECOLS(1,A1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); oParser = new parserFormula("CHOOSECOLS(1,A1:B5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.8 аргумент - array oParser = new parserFormula("CHOOSECOLS(1,{2;\"\";\"test\"})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); ws.getRange2("F1").setValue("1"); ws.getRange2("G1").setValue("3"); oParser = new parserFormula("CHOOSECOLS(A1:C2,F1:G1,F1:G1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue(), "r"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 1).getValue(), 3); assert.strictEqual(oParser.calculate().getElementRowCol(0, 2).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(1, 2).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(0, 3).getValue(), "r"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 3).getValue(), 3); oParser = new parserFormula("CHOOSECOLS(A1:C2,F1:G1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue(), "r"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 1).getValue(), 3); oParser = new parserFormula("CHOOSECOLS(A1:C2,{1,2},{1,2},{1,2,3})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue(), "q"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 1).getValue(), "w"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 2).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(1, 2).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(0, 3).getValue(), "q"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 3).getValue(), "w"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 4).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(1, 4).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(0, 5).getValue(), "q"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 5).getValue(), "w"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 6).getValue(), "r"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 6).getValue(), 3); oParser = new parserFormula("CHOOSECOLS(A1:C2,{1;2},{1;2},{1;2;3})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue(), "q"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 1).getValue(), "w"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 2).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(1, 2).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(0, 3).getValue(), "q"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 3).getValue(), "w"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 4).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(1, 4).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(0, 5).getValue(), "q"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 5).getValue(), "w"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 6).getValue(), "r"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 6).getValue(), 3); oParser = new parserFormula("CHOOSECOLS(A1:C2,{1;2},{1,1;2,1},{1;2;3})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("CHOOSECOLS(A1:C2,{1;2},F1:G2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); }); QUnit.test("Test: \"CHOOSEROWS\"", function (assert) { //1. добавляем общие тесты ws.getRange2("A1").setValue("1"); ws.getRange2("A2").setValue("2"); ws.getRange2("A3").setValue(""); ws.getRange2("A4").setValue("4"); ws.getRange2("A5").setValue("#N/A"); ws.getRange2("A6").setValue("f"); ws.getRange2("B1").setValue("q"); ws.getRange2("B2").setValue("w"); ws.getRange2("B3").setValue("e"); ws.getRange2("B4").setValue("test"); ws.getRange2("B5").setValue("hhh"); ws.getRange2("B6").setValue("g"); ws.getRange2("C1").setValue("r"); ws.getRange2("C2").setValue("3"); ws.getRange2("C3").setValue("5"); ws.getRange2("C4").setValue(""); ws.getRange2("C5").setValue("6"); ws.getRange2("C6").setValue("h"); oParser = new parserFormula("CHOOSEROWS(A1:C6;-1;1)", "A1", ws); assert.ok(oParser.parse()); let array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 'f'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 1); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 'g'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 'q'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 'h'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 'r'); oParser = new parserFormula("CHOOSEROWS(A1:C6;-2;3)", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), '#N/A'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), ''); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 'hhh'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 'e'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 6); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 5); oParser = new parserFormula("CHOOSEROWS(A1:C6;-4;20)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("CHOOSEROWS(A1:C6;-10;4)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("CHOOSEROWS(A1:C6;-2;0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2. аргументы - разные типы. нужно пербрать все аргументы //2.1 аргумент - number oParser = new parserFormula("CHOOSEROWS(1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.2 аргумент - string oParser = new parserFormula("CHOOSEROWS(\"test\",1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "test"); //2.3 аргумент - bool oParser = new parserFormula("CHOOSEROWS(true,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "TRUE"); //2.4 аргумент - error oParser = new parserFormula("CHOOSEROWS(#VALUE!,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.5 аргумент - empty oParser = new parserFormula("CHOOSEROWS(,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.6 аргумент - cellsRange //2.7 аргумент - cell oParser = new parserFormula("CHOOSEROWS(B1, 1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "q"); //2.8 аргумент - array oParser = new parserFormula("CHOOSEROWS({2;\"\";\"test\"},3)", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "test"); //2.8 аргумент - array oParser = new parserFormula("CHOOSEROWS({2,\"\",\"test\"},3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.2 аргумент - string oParser = new parserFormula("CHOOSEROWS(1,\"test\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.3 аргумент - bool oParser = new parserFormula("CHOOSEROWS(1,true)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.4 аргумент - error oParser = new parserFormula("CHOOSEROWS(1, #VALUE!)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.5 аргумент - empty oParser = new parserFormula("CHOOSEROWS(1,)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.6 аргумент - cellsRange //2.7 аргумент - cell oParser = new parserFormula("CHOOSEROWS(1,A1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); oParser = new parserFormula("CHOOSEROWS(1,A1:B5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.8 аргумент - array oParser = new parserFormula("CHOOSEROWS(1,{2;\"\";\"test\"})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); ws.getRange2("F1").setValue("1"); ws.getRange2("G1").setValue("3"); oParser = new parserFormula("CHOOSEROWS(A1:C2,F1:G1,F1:G1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); ws.getRange2("G1").setValue("2"); oParser = new parserFormula("CHOOSEROWS(A1:C2,F1:G1,F1:G1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue(), "q"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 2).getValue(), "r"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(1, 1).getValue(), "w"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 2).getValue(), 3); assert.strictEqual(oParser.calculate().getElementRowCol(2, 0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(2, 1).getValue(), "q"); assert.strictEqual(oParser.calculate().getElementRowCol(2, 2).getValue(), "r"); assert.strictEqual(oParser.calculate().getElementRowCol(3, 0).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(3, 1).getValue(), "w"); assert.strictEqual(oParser.calculate().getElementRowCol(3, 2).getValue(), 3); oParser = new parserFormula("CHOOSEROWS(A1:C2,{1;2},{1;2})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue(), "q"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 2).getValue(), "r"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(1, 1).getValue(), "w"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 2).getValue(), 3); assert.strictEqual(oParser.calculate().getElementRowCol(2, 0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(2, 1).getValue(), "q"); assert.strictEqual(oParser.calculate().getElementRowCol(2, 2).getValue(), "r"); assert.strictEqual(oParser.calculate().getElementRowCol(3, 0).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(3, 1).getValue(), "w"); assert.strictEqual(oParser.calculate().getElementRowCol(3, 2).getValue(), 3); oParser = new parserFormula("CHOOSEROWS(A1:C2,{1;2},{1;3})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("CHOOSEROWS(A1:C2,{1,2},{1,2})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue(), "q"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 2).getValue(), "r"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(1, 1).getValue(), "w"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 2).getValue(), 3); assert.strictEqual(oParser.calculate().getElementRowCol(2, 0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(2, 1).getValue(), "q"); assert.strictEqual(oParser.calculate().getElementRowCol(2, 2).getValue(), "r"); assert.strictEqual(oParser.calculate().getElementRowCol(3, 0).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(3, 1).getValue(), "w"); assert.strictEqual(oParser.calculate().getElementRowCol(3, 2).getValue(), 3); }); QUnit.test("Test: \"BETA.INV\"", function (assert) { ws.getRange2("A2").setValue("0.685470581"); ws.getRange2("A3").setValue("8"); ws.getRange2("A4").setValue("10"); ws.getRange2("A5").setValue("1"); ws.getRange2("A6").setValue("3"); oParser = new parserFormula("BETA.INV(A2,A3,A4,A5,A6)", "A1", ws); assert.ok(oParser.parse(), "BETA.INV(A2,A3,A4,A5,A6)"); assert.strictEqual(oParser.calculate().getValue().toFixed(1) - 0, 2, "BETA.INV(A2,A3,A4,A5,A6)"); testArrayFormula2(assert, "BETA.INV", 3, 5); }); QUnit.test("Test: \"BETAINV\"", function (assert) { ws.getRange2("A2").setValue("0.685470581"); ws.getRange2("A3").setValue("8"); ws.getRange2("A4").setValue("10"); ws.getRange2("A5").setValue("1"); ws.getRange2("A6").setValue("3"); oParser = new parserFormula("BETAINV(A2,A3,A4,A5,A6)", "A1", ws); assert.ok(oParser.parse(), "BETAINV(A2,A3,A4,A5,A6)"); assert.strictEqual(oParser.calculate().getValue().toFixed(1) - 0, 2, "BETAINV(A2,A3,A4,A5,A6)"); testArrayFormula2(assert, "BETAINV", 3, 5); }); QUnit.test("Test: \"BETA.DIST\"", function (assert) { ws.getRange2("A2").setValue("2"); ws.getRange2("A3").setValue("8"); ws.getRange2("A4").setValue("10"); ws.getRange2("A5").setValue("1"); ws.getRange2("A6").setValue("3"); oParser = new parserFormula("BETA.DIST(A2,A3,A4,TRUE,A5,A6)", "A1", ws); assert.ok(oParser.parse(), "BETA.DIST(A2,A3,A4,TRUE,A5,A6)"); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.6854706, "BETA.DIST(A2,A3,A4,TRUE,A5,A6)"); oParser = new parserFormula("BETA.DIST(A2,A3,A4,FALSE,A5,A6)", "A1", ws); assert.ok(oParser.parse(), "BETA.DIST(A2,A3,A4,FALSE,A5,A6)"); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 1.4837646, "BETA.DIST(A2,A3,A4,FALSE,A5,A6)"); testArrayFormula2(assert, "BETA.DIST", 4, 6); }); QUnit.test("Test: \"BETADIST\"", function (assert) { ws.getRange2("A2").setValue("2"); ws.getRange2("A3").setValue("8"); ws.getRange2("A4").setValue("10"); ws.getRange2("A5").setValue("1"); ws.getRange2("A6").setValue("3"); oParser = new parserFormula("BETADIST(A2,A3,A4,A5,A6)", "A1", ws); assert.ok(oParser.parse(), "BETADIST(A2,A3,A4,A5,A6)"); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.6854706, "BETADIST(A2,A3,A4,A5,A6)"); oParser = new parserFormula("BETADIST(1,2,3,1,6)", "A1", ws); assert.ok(oParser.parse(), "BETADIST(1,2,3,1,6)"); assert.strictEqual(oParser.calculate().getValue(), 0, "BETADIST(1,2,3,1,6)"); oParser = new parserFormula("BETADIST(6,2,3,1,6)", "A1", ws); assert.ok(oParser.parse(), "BETADIST(6,2,3,1,6)"); assert.strictEqual(oParser.calculate().getValue(), 1, "BETADIST(6,2,3,1,6)"); testArrayFormula2(assert, "BETADIST", 3, 5); }); QUnit.test("Test: \"BESSELJ\"", function (assert) { oParser = new parserFormula("BESSELJ(1.9, 2)", "A1", ws); assert.ok(oParser.parse(), "BESSELJ(1.9, 2)"); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 0.329925728, "BESSELJ(1.9, 2)"); oParser = new parserFormula("BESSELJ(1.9, 2.4)", "A1", ws); assert.ok(oParser.parse(), "BESSELJ(1.9, 2.4)"); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 0.329925728, "BESSELJ(1.9, 2.4)"); oParser = new parserFormula("BESSELJ(-1.9, 2.4)", "A1", ws); assert.ok(oParser.parse(), "BESSELJ(-1.9, 2.4)"); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 0.329925728, "BESSELJ(-1.9, 2.4)"); oParser = new parserFormula("BESSELJ(-1.9, -2.4)", "A1", ws); assert.ok(oParser.parse(), "BESSELJ(-1.9, -2.4)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); testArrayFormula2(assert, "BESSELJ", 2, 2, true, null); }); QUnit.test("Test: \"BESSELK\"", function (assert) { oParser = new parserFormula("BESSELK(1.5, 1)", "A1", ws); assert.ok(oParser.parse(), "BESSELK(1.5, 1)"); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 0.277387804, "BESSELK(1.5, 1)"); oParser = new parserFormula("BESSELK(1, 3)", "A1", ws); assert.ok(oParser.parse(), "BESSELK(1, 3)"); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 7.10126281, "BESSELK(1, 3)"); oParser = new parserFormula("BESSELK(-1.123,2)", "A1", ws); assert.ok(oParser.parse(), "BESSELK(-1.123,2)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("BESSELK(1,-2)", "A1", ws); assert.ok(oParser.parse(), "BESSELK(1,-2)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); testArrayFormula2(assert, "BESSELK", 2, 2, true, null); }); QUnit.test("Test: \"BESSELY\"", function (assert) { oParser = new parserFormula("BESSELY(2.5, 1)", "A1", ws); assert.ok(oParser.parse(), "BESSELY(2.5, 1)"); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.1459181, "BESSELY(2.5, 1)"); oParser = new parserFormula("BESSELY(1,-2)", "A1", ws); assert.ok(oParser.parse(), "BESSELY(1,-2)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "BESSELY(1,-2)"); oParser = new parserFormula("BESSELY(-1,2)", "A1", ws); assert.ok(oParser.parse(), "BESSELY(-1,2)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "BESSELY(-1,2)"); testArrayFormula2(assert, "BESSELY", 2, 2, true, null); }); QUnit.test("Test: \"BESSELI\"", function (assert) { //есть различия excel в некоторых формулах(неточности в 7 цифре после точки) oParser = new parserFormula("BESSELI(1.5, 1)", "A1", ws); assert.ok(oParser.parse(), "BESSELI(1.5, 1)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.981666, "BESSELI(1.5, 1)"); oParser = new parserFormula("BESSELI(1,2)", "A1", ws); assert.ok(oParser.parse(), "BESSELI(1,2)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.135748, "BESSELI(1,2)"); oParser = new parserFormula("BESSELI(1,-2)", "A1", ws); assert.ok(oParser.parse(), "BESSELI(1,-2)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "BESSELI(1,-2)"); oParser = new parserFormula("BESSELI(-1,2)", "A1", ws); assert.ok(oParser.parse(), "BESSELI(-1,2)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.135748, "BESSELI(-1,2)"); testArrayFormula2(assert, "BESSELI", 2, 2, true, null); }); QUnit.test("Test: \"GAMMA.INV\"", function (assert) { ws.getRange2("A2").setValue("0.068094"); ws.getRange2("A3").setValue("9"); ws.getRange2("A4").setValue("2"); oParser = new parserFormula("GAMMA.INV(A2,A3,A4)", "A1", ws); assert.ok(oParser.parse(), "GAMMA.INV(A2,A3,A4)"); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 10.0000112, "GAMMA.INV(A2,A3,A4)"); testArrayFormula2(assert, "GAMMA.INV", 3, 3); }); QUnit.test("Test: \"GAMMAINV\"", function (assert) { ws.getRange2("A2").setValue("0.068094"); ws.getRange2("A3").setValue("9"); ws.getRange2("A4").setValue("2"); oParser = new parserFormula("GAMMAINV(A2,A3,A4)", "A1", ws); assert.ok(oParser.parse(), "GAMMAINV(A2,A3,A4)"); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 10.0000112, "GAMMAINV(A2,A3,A4)"); }); QUnit.test("Test: \"SUM(1,2,3)\"", function (assert) { oParser = new parserFormula('SUM(1,2,3)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1 + 2 + 3); testArrayFormula2(assert, "SUM", 1, 8, null, true); }); QUnit.test("Test: \"\"s\"&5\"", function (assert) { oParser = new parserFormula("\"s\"&5", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "s5"); }); QUnit.test("Test: \"String+Number\"", function (assert) { oParser = new parserFormula("1+\"099\"", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 100); ws.getRange2("A1469").setValue("'099"); ws.getRange2("A1470").setValue("\"099\""); oParser = new parserFormula("1+A1469", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 100); oParser = new parserFormula("1+A1470", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); }); QUnit.test("Test: \"Pow operator tests\"", function (assert) { let array; ws.getRange2("A100").setValue("2"); ws.getRange2("A101").setValue("3"); ws.getRange2("A102").setValue("4"); ws.getRange2("B100").setValue("1"); ws.getRange2("B101").setValue("2"); ws.getRange2("B102").setValue("#DIV/0!"); ws.getRange2("D100").setValue("2"); ws.getRange2("D101").setValue("3"); ws.getRange2("E100").setValue("3"); ws.getRange2("E101").setValue(""); oParser = new parserFormula("A100:B102^2", "A1", ws); assert.ok(oParser.parse(), 'A100:B102^2'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 4, 'Result of A100:B102^2[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 9, 'Result of A100:B102^2[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 16, 'Result of A100:B102^2[2,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, 'Result of A100:B102^2[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, 'Result of A100:B102^2[1,1]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#DIV/0!", 'Result of A100:B102^2[2,1]'); oParser = new parserFormula("A100:B102^A100", "A1", ws); assert.ok(oParser.parse(), 'A100:B102^A100'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 4, 'Result of A100:B102^A100[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 9, 'Result of A100:B102^A100[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 16, 'Result of A100:B102^A100[2,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, 'Result of A100:B102^A100[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, 'Result of A100:B102^A100[1,1]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#DIV/0!", 'Result of A100:B102^A100[2,1]'); oParser = new parserFormula("A100:B102^A100:A100", "A1", ws); assert.ok(oParser.parse(), 'A100:B102^A100:A100'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 4, 'Result of A100:B102^A100:A100[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 9, 'Result of A100:B102^A100:A100[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 16, 'Result of A100:B102^A100:A100[2,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, 'Result of A100:B102^A100:A100[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, 'Result of A100:B102^A100:A100[1,1]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#DIV/0!", 'Result of A100:B102^A100:A100[2,1]'); oParser = new parserFormula("2^A100:B102", "A1", ws); assert.ok(oParser.parse(), '2^A100:B102'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 4, 'Result of 2^A100:B102[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 8, 'Result of 2^A100:B102[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 16, 'Result of 2^A100:B102[2,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, 'Result of 2^A100:B102[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, 'Result of 2^A100:B102[1,1]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#DIV/0!", 'Result of 2^A100:B102[2,1]'); oParser = new parserFormula("A100^A100:B102", "A1", ws); assert.ok(oParser.parse(), 'A100^A100:B102'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 4, 'Result of A100^A100:B102[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 8, 'Result of A100^A100:B102[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 16, 'Result of A100^A100:B102[2,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, 'Result of A100^A100:B102[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, 'Result of A100^A100:B102[1,1]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#DIV/0!", 'Result of A100^A100:B102[2,1]'); oParser = new parserFormula("A100:A100^A100:B102", "A1", ws); assert.ok(oParser.parse(), 'A100:A100^A100:B102'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 4, 'Result of A100:A100^A100:B102[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 8, 'Result of A100:A100^A100:B102[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 16, 'Result of A100:A100^A100:B102[2,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, 'Result of A100:A100^A100:B102[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, 'Result of A100:A100^A100:B102[1,1]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#DIV/0!", 'Result of A100:A100^A100:B102[2,1]'); oParser = new parserFormula("A100:B102^D100:E101", "A1", ws); assert.ok(oParser.parse(), 'A100:B102^D100:E101'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 4, 'Result of A100:B102^D100:E101[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 27, 'Result of A100:B102^D100:E101[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", 'Result of A100:B102^D100:E101[2,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, 'Result of A100:B102^D100:E101[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 1, 'Result of A100:B102^D100:E101[1,1]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#DIV/0!", 'Result of A100:B102^D100:E101[2,1]'); ws.getRange2("G100").setValue("a"); ws.getRange2("G101").setValue("b"); ws.getRange2("H100").setValue("c"); ws.getRange2("H101").setValue("d"); oParser = new parserFormula("G100:H101^2", "A1", ws); assert.ok(oParser.parse(), 'G100:H101^2'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", 'Result of G100:H101^2[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", 'Result of G100:H101^2[1,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", 'Result of G100:H101^2[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#VALUE!", 'Result of G100:H101^2[1,1]'); oParser = new parserFormula("2^G100:H101", "A1", ws); assert.ok(oParser.parse(), '2^G100:H101'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", 'Result of 2^G100:H101[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", 'Result of 2^G100:H101[1,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", 'Result of 2^G100:H101[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#VALUE!", 'Result of 2^G100:H101[1,1]'); oParser = new parserFormula("G100:H101^G100:H101", "A1", ws); assert.ok(oParser.parse(), 'G100:H101^G100:H101'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", 'Result of G100:H101^G100:H101[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", 'Result of G100:H101^G100:H101[1,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", 'Result of G100:H101^G100:H101[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#VALUE!", 'Result of G100:H101^G100:H101[1,1]'); ws.getRange2("I100").setValue("#N/A"); ws.getRange2("I101").setValue("#DIV/0!"); ws.getRange2("J100").setValue("#NUM!"); ws.getRange2("J101").setValue("0"); oParser = new parserFormula("I100:J101^2", "A1", ws); assert.ok(oParser.parse(), 'I100:J101^2'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#N/A", 'Result of I100:J101^2[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#DIV/0!", 'Result of I100:J101^2[1,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#NUM!", 'Result of I100:J101^2[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 0, 'Result of I100:J101^2[1,1]'); ws.getRange2("A100").setValue("75"); ws.getRange2("B100").setValue("100"); ws.getRange2("C100").setValue("200"); ws.getRange2("D100").setValue("300"); ws.getRange2("E100").setValue("350"); ws.getRange2("F100").setValue("400"); ws.getRange2("G100").setValue("500"); oParser = new parserFormula("A100:G100^{1,2,1}", "A1", ws); assert.ok(oParser.parse(), 'A100:G100^{1,2,1}'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 75, 'Result of A100:G100^{1,2,1}[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 10000, 'Result of A100:G100^{1,2,1}[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 200, 'Result of A100:G100^{1,2,1}[0,2]'); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "#N/A", 'Result of A100:G100^{1,2,1}[0,3]'); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), "#N/A", 'Result of A100:G100^{1,2,1}[0,4]'); assert.strictEqual(array.getElementRowCol(0, 5).getValue(), "#N/A", 'Result of A100:G100^{1,2,1}[0,5]'); assert.strictEqual(array.getElementRowCol(0, 6).getValue(), "#N/A", 'Result of A100:G100^{1,2,1}[0,6]'); }); QUnit.test("Test: \"POWER\"", function (assert) { let array; // ------------------------- same tests as in Pow operator tests ------------------------- // ws.getRange2("A100").setValue("2"); ws.getRange2("A101").setValue("3"); ws.getRange2("A102").setValue("4"); ws.getRange2("B100").setValue("1"); ws.getRange2("B101").setValue("2"); ws.getRange2("B102").setValue("#DIV/0!"); ws.getRange2("D100").setValue("2"); ws.getRange2("D101").setValue("3"); ws.getRange2("E100").setValue("3"); ws.getRange2("E101").setValue(""); oParser = new parserFormula("POWER(A100:B102,2)", "A1", ws); assert.ok(oParser.parse(), 'POWER(A100:B102,2)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 4, 'Result of A100:B102^2[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 9, 'Result of A100:B102^2[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 16, 'Result of A100:B102^2[2,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, 'Result of A100:B102^2[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, 'Result of A100:B102^2[1,1]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#DIV/0!", 'Result of A100:B102^2[2,1]'); oParser = new parserFormula("POWER(A100:B102,A100)", "A1", ws); assert.ok(oParser.parse(), 'POWER(A100:B102,A100)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 4, 'Result of A100:B102^A100[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 9, 'Result of A100:B102^A100[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 16, 'Result of A100:B102^A100[2,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, 'Result of A100:B102^A100[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, 'Result of A100:B102^A100[1,1]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#DIV/0!", 'Result of A100:B102^A100[2,1]'); oParser = new parserFormula("POWER(A100:B102,A100:A100)", "A1", ws); assert.ok(oParser.parse(), 'POWER(A100:B102,A100:A100)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 4, 'Result of A100:B102^A100:A100[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 9, 'Result of A100:B102^A100:A100[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 16, 'Result of A100:B102^A100:A100[2,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, 'Result of A100:B102^A100:A100[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, 'Result of A100:B102^A100:A100[1,1]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#DIV/0!", 'Result of A100:B102^A100:A100[2,1]'); oParser = new parserFormula("POWER(2,A100:B102)", "A1", ws); assert.ok(oParser.parse(), 'POWER(2,A100:B102)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 4, 'Result of 2^A100:B102[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 8, 'Result of 2^A100:B102[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 16, 'Result of 2^A100:B102[2,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, 'Result of 2^A100:B102[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, 'Result of 2^A100:B102[1,1]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#DIV/0!", 'Result of 2^A100:B102[2,1]'); oParser = new parserFormula("POWER(A100,A100:B102)", "A1", ws); assert.ok(oParser.parse(), 'POWER(A100,A100:B102)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 4, 'Result of A100^A100:B102[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 8, 'Result of A100^A100:B102[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 16, 'Result of A100^A100:B102[2,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, 'Result of A100^A100:B102[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, 'Result of A100^A100:B102[1,1]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#DIV/0!", 'Result of A100^A100:B102[2,1]'); oParser = new parserFormula("POWER(A100:A100,A100:B102)", "A1", ws); assert.ok(oParser.parse(), 'POWER(A100:A100,A100:B102)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 4, 'Result of A100:A100^A100:B102[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 8, 'Result of A100:A100^A100:B102[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 16, 'Result of A100:A100^A100:B102[2,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, 'Result of A100:A100^A100:B102[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, 'Result of A100:A100^A100:B102[1,1]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#DIV/0!", 'Result of A100:A100^A100:B102[2,1]'); oParser = new parserFormula("POWER(A100:B102,D100:E101)", "A1", ws); assert.ok(oParser.parse(), 'POWER(A100:B102,D100:E101)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 4, 'Result of A100:B102^D100:E101[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 27, 'Result of A100:B102^D100:E101[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", 'Result of A100:B102^D100:E101[2,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, 'Result of A100:B102^D100:E101[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 1, 'Result of A100:B102^D100:E101[1,1]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#DIV/0!", 'Result of A100:B102^D100:E101[2,1]'); ws.getRange2("G100").setValue("a"); ws.getRange2("G101").setValue("b"); ws.getRange2("H100").setValue("c"); ws.getRange2("H101").setValue("d"); oParser = new parserFormula("POWER(G100:H101,2)", "A1", ws); assert.ok(oParser.parse(), 'POWER(G100:H101,2)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", 'Result of G100:H101^2[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", 'Result of G100:H101^2[1,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", 'Result of G100:H101^2[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#VALUE!", 'Result of G100:H101^2[1,1]'); oParser = new parserFormula("POWER(2,G100:H101)", "A1", ws); assert.ok(oParser.parse(), 'POWER(2,G100:H101)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", 'Result of 2^G100:H101[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", 'Result of 2^G100:H101[1,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", 'Result of 2^G100:H101[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#VALUE!", 'Result of 2^G100:H101[1,1]'); oParser = new parserFormula("POWER(G100:H101,G100:H101)", "A1", ws); assert.ok(oParser.parse(), 'POWER(G100:H101,G100:H101)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", 'Result of G100:H101^G100:H101[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", 'Result of G100:H101^G100:H101[1,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", 'Result of G100:H101^G100:H101[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#VALUE!", 'Result of G100:H101^G100:H101[1,1]'); ws.getRange2("I100").setValue("#N/A"); ws.getRange2("I101").setValue("#DIV/0!"); ws.getRange2("J100").setValue("#NUM!"); ws.getRange2("J101").setValue("0"); oParser = new parserFormula("POWER(I100:J101,2)", "A1", ws); assert.ok(oParser.parse(), 'POWER(I100:J101,2)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#N/A", 'Result of POWER(I100:J101,2)[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#DIV/0!", 'Result of POWER(I100:J101,2)[1,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#NUM!", 'Result of POWER(I100:J101,2)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 0, 'Result of POWER(I100:J101,2)[1,1]'); ws.getRange2("A100").setValue("75"); ws.getRange2("B100").setValue("100"); ws.getRange2("C100").setValue("200"); ws.getRange2("D100").setValue("300"); ws.getRange2("E100").setValue("350"); ws.getRange2("F100").setValue("400"); ws.getRange2("G100").setValue("500"); oParser = new parserFormula("POWER(A100:G100,{1,2,1})", "A1", ws); assert.ok(oParser.parse(), 'POWER(A100:G100,{1,2,1})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 75, 'Result of POWER(A100:G100,{1,2,1})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 10000, 'Result of POWER(A100:G100,{1,2,1})[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 200, 'Result of POWER(A100:G100,{1,2,1})[0,2]'); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "#N/A", 'Result of POWER(A100:G100,{1,2,1})[0,3]'); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), "#N/A", 'Result of POWER(A100:G100,{1,2,1})[0,4]'); assert.strictEqual(array.getElementRowCol(0, 5).getValue(), "#N/A", 'Result of POWER(A100:G100,{1,2,1})[0,5]'); assert.strictEqual(array.getElementRowCol(0, 6).getValue(), "#N/A", 'Result of POWER(A100:G100,{1,2,1})[0,6]'); // ------------------------- same tests as in Pow operator tests ------------------------- // oParser = new parserFormula("POWER(0,0)", "A1", ws); assert.ok(oParser.parse(), "POWER(0,0)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of POWER(0,0)"); // ms - #NUM!, js - 1, LO - 1, gs - 1 oParser = new parserFormula("POWER(0,1)", "A1", ws); assert.ok(oParser.parse(), "POWER(0,1)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of POWER(0,1)"); oParser = new parserFormula("POWER(0,-1)", "A1", ws); assert.ok(oParser.parse(), "POWER(0,-1)"); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "Result of POWER(0,-1)"); oParser = new parserFormula("POWER(0,1/3)", "A1", ws); assert.ok(oParser.parse(), "POWER(0,1/3)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of POWER(0,1/3)"); oParser = new parserFormula("POWER(0,-1/3)", "A1", ws); assert.ok(oParser.parse(), "POWER(0,-1/3)"); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "Result of POWER(0,-1/3)"); oParser = new parserFormula("POWER(0,-3)", "A1", ws); assert.ok(oParser.parse(), "POWER(0,-3)"); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "Result of POWER(0,-3)"); oParser = new parserFormula("POWER(1,-3)", "A1", ws); assert.ok(oParser.parse(), "POWER(1,-3)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of POWER(1,-3)"); oParser = new parserFormula("POWER(1,-1/3)", "A1", ws); assert.ok(oParser.parse(), "POWER(1,-1/3)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of POWER(1,-1/3)"); oParser = new parserFormula("POWER(1,1/3)", "A1", ws); assert.ok(oParser.parse(), "POWER(1,1/3)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of POWER(1,1/3)"); oParser = new parserFormula("POWER(-1,1/2)", "A1", ws); assert.ok(oParser.parse(), "POWER(-1,1/2)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of POWER(-1,1/2)"); oParser = new parserFormula("POWER(-1,1/3)", "A1", ws); assert.ok(oParser.parse(), "POWER(-1,1/3)"); assert.strictEqual(oParser.calculate().getValue(), -1, "Result of POWER(-1,1/3)"); oParser = new parserFormula("POWER(-1,-1/3)", "A1", ws); assert.ok(oParser.parse(), "POWER(-1,-1/3)"); assert.strictEqual(oParser.calculate().getValue(), -1, "Result of POWER(-1,-1/3)"); oParser = new parserFormula("POWER(-1,1/4)", "A1", ws); assert.ok(oParser.parse(), "POWER(-1,1/4)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of POWER(-1,1/4)"); oParser = new parserFormula("POWER(-1,1/5)", "A1", ws); assert.ok(oParser.parse(), "POWER(-1,1/5)"); assert.strictEqual(oParser.calculate().getValue(), -1, "Result of POWER(-1,1/5)"); oParser = new parserFormula("POWER(-8,1/3)", "A1", ws); assert.ok(oParser.parse(), "POWER(-8,1/3)"); assert.strictEqual(oParser.calculate().getValue(), -2, "Result of POWER(-8,1/3)"); oParser = new parserFormula("POWER(-8,-1/3)", "A1", ws); assert.ok(oParser.parse(), "POWER(-8,-1/3)"); assert.strictEqual(oParser.calculate().getValue(), -0.5, "Result of POWER(-8,-1/3)"); oParser = new parserFormula("POWER(-8,1/4)", "A1", ws); assert.ok(oParser.parse(), "POWER(-8,1/4)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of POWER(-8,1/4)"); oParser = new parserFormula("POWER(-8,1/5)", "A1", ws); assert.ok(oParser.parse(), "POWER(-8,1/5)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2), "-1.52", "Result of POWER(-8,1/5)"); oParser = new parserFormula("POWER(-8,-1/5)", "A1", ws); assert.ok(oParser.parse(), "POWER(-8,-1/5)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2), "-0.66", "Result of POWER(-8,-1/5)"); oParser = new parserFormula('POWER("8",2)', "A1", ws); assert.ok(oParser.parse(), 'POWER("8",2)'); assert.strictEqual(oParser.calculate().getValue(), 64, 'Result of POWER("8",2)'); oParser = new parserFormula('POWER("8","2")', "A1", ws); assert.ok(oParser.parse(), 'POWER("8","2")'); assert.strictEqual(oParser.calculate().getValue(), 64, 'Result of POWER("8","2")'); oParser = new parserFormula('POWER("-8","2")', "A1", ws); assert.ok(oParser.parse(), 'POWER("-8","2")'); assert.strictEqual(oParser.calculate().getValue(), 64, 'Result of POWER("-8","2")'); oParser = new parserFormula('POWER("8s",2)', "A1", ws); assert.ok(oParser.parse(), 'POWER("8s",2)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of POWER("8s",2)'); }); QUnit.test("Test: \"POWER(2,8)\"", function (assert) { oParser = new parserFormula("POWER(2,8)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), Math.pow(2, 8)); }); QUnit.test("Test: \"POWER(0,-3)\"", function (assert) { oParser = new parserFormula("POWER(0,-3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!"); testArrayFormula2(assert, "POWER", 2, 2); }); QUnit.test("Test: \"ISNA(A1)\"", function (assert) { ws.getRange2("A1").setValue("#N/A"); oParser = new parserFormula("ISNA(A1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TRUE"); testArrayFormula2(assert, "ISNA", 1, 1); }); QUnit.test("Test: \"ISNONTEXT\"", function (assert) { oParser = new parserFormula('ISNONTEXT("123")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "FALSE"); testArrayFormula2(assert, "ISNONTEXT", 1, 1); }); QUnit.test("Test: \"ISNUMBER\"", function (assert) { ws.getRange2("A1").setValue("123"); oParser = new parserFormula('ISNUMBER(4)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TRUE"); oParser = new parserFormula('ISNUMBER(A1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TRUE"); testArrayFormula2(assert, "ISNUMBER", 1, 1); }); QUnit.test("Test: \"ISODD\"", function (assert) { oParser = new parserFormula('ISODD(-1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TRUE"); oParser = new parserFormula('ISODD(2.5)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "FALSE"); oParser = new parserFormula('ISODD(5)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TRUE"); testArrayFormula2(assert, "ISODD", 1, 1, true, null); }); QUnit.test("Test: \"ROUND\"", function (assert) { oParser = new parserFormula("ROUND(2.15, 1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2.2); oParser = new parserFormula("ROUND(2.149, 1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2.1); oParser = new parserFormula("ROUND(-1.475, 2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -1.48); oParser = new parserFormula("ROUND(21.5, -1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 20); oParser = new parserFormula("ROUND(626.3,-3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1000); oParser = new parserFormula("ROUND(1.98,-1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("ROUND(-50.55,-2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -100); oParser = new parserFormula('ROUND("test",-2.1)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula('ROUND(123.431,"test")', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula('ROUND(123.431,#NUM!)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula('ROUND(#NUM!,123.431)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("ROUND(-50.55,-2.1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -100); oParser = new parserFormula("ROUND(-50.55,-2.9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -100); oParser = new parserFormula("ROUND(-50.55,0.9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -51); oParser = new parserFormula("ROUND(-50.55,0.1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -51); oParser = new parserFormula("ROUND(183.64, 2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 183.64); ws.getRange2("A100").setValue("3.14159"); ws.getRange2("A101").setValue("2.71828"); ws.getRange2("A102").setValue("1.005"); ws.getRange2("A103").setValue("-1.56789"); ws.getRange2("A104").setValue("123.456"); ws.getRange2("A105").setValue("0.4999"); ws.getRange2("A106").setValue("-0.4999"); ws.getRange2("A107").setValue("1000.567"); ws.getRange2("A108").setValue("999.999"); ws.getRange2("A109").setValue("5.55555"); ws.getRange2("A110").setValue("1.123123"); ws.getRange2("A111").setValue("1.123123"); ws.getRange2("B100").setValue("2"); ws.getRange2("B101").setValue("3"); ws.getRange2("B102").setValue("2"); ws.getRange2("B103").setValue("1"); ws.getRange2("B104").setValue("0"); ws.getRange2("B105").setValue("2"); ws.getRange2("B106").setValue("2"); ws.getRange2("B107").setValue("-1"); ws.getRange2("B108").setValue("2"); ws.getRange2("B109").setValue("4"); ws.getRange2("B110").setValue("6"); ws.getRange2("B111").setValue("5"); oParser = new parserFormula("ROUND(A100, B100)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3.14, "Round ROUND(A100, B100)"); oParser = new parserFormula("ROUND(A101, B101)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2.718, "Round ROUND(A101, B101)"); oParser = new parserFormula("ROUND(A102, B102)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1.01, "Round ROUND(A102, B102)"); oParser = new parserFormula("ROUND(A103, B103)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -1.6, "Round ROUND(A103, B103)"); oParser = new parserFormula("ROUND(A104, B104)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 123, "Round ROUND(A104, B104)"); oParser = new parserFormula("ROUND(A105, B105)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0.5, "Round ROUND(A105, B105)"); oParser = new parserFormula("ROUND(A106, B106)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -0.5, "Round ROUND(A106, B106)"); oParser = new parserFormula("ROUND(A107, B107)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1000, "Round ROUND(A107, B107)"); oParser = new parserFormula("ROUND(A108, B108)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1000, "Round ROUND(A108, B108)"); oParser = new parserFormula("ROUND(A109, B109)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5.5556, "Round ROUND(A109, B109)"); oParser = new parserFormula("ROUND(A110, B110)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1.123123, "Round ROUND(A110, B110)"); oParser = new parserFormula("ROUND(A111, B111)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1.12312, "Round ROUND(A111, B111)"); oParser = new parserFormula("ROUND(1.123,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1.12, "ROUND(1.123,2)"); oParser = new parserFormula("ROUND(1.125,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1.13, "ROUND(1.125,2)"); oParser = new parserFormula("ROUND(1.005,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1.01, "ROUND(1.005,2)"); oParser = new parserFormula("ROUND(1.995,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2.00, "ROUND(1.995,2)"); oParser = new parserFormula("ROUND(3.14159,0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3, "ROUND(3.14159,0)"); oParser = new parserFormula("ROUND(3.14159,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3.1, "ROUND(3.14159,1)"); oParser = new parserFormula("ROUND(3.14159,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3.14, "ROUND(3.14159,2)"); oParser = new parserFormula("ROUND(3.14159,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3.142, "ROUND(3.14159,3)"); oParser = new parserFormula("ROUND(3.14159,4)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3.1416, "ROUND(3.14159,4)"); oParser = new parserFormula("ROUND(-1.123,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -1.12, "ROUND(-1.123,2)"); oParser = new parserFormula("ROUND(-1.125,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -1.13, "ROUND(-1.125,2)"); oParser = new parserFormula("ROUND(-1.005,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -1.01, "ROUND(-1.005,2)"); oParser = new parserFormula("ROUND(-1.995,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -2.00, "ROUND(-1.995,2)"); oParser = new parserFormula("ROUND(1.5,0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2, "ROUND(1.5,0)"); oParser = new parserFormula("ROUND(2.5,0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3, "ROUND(2.5,0)"); oParser = new parserFormula("ROUND(3.5,0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4, "ROUND(3.5,0)"); oParser = new parserFormula("ROUND(-1.5,0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -2, "ROUND(-1.5,0)"); oParser = new parserFormula("ROUND(-2.5,0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -3, "ROUND(-2.5,0)"); // Negative decimal places tests oParser = new parserFormula("ROUND(123.456,-1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 120, "ROUND(123.456,-1)"); oParser = new parserFormula("ROUND(123.456,-2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 100, "ROUND(123.456,-2)"); oParser = new parserFormula("ROUND(555.555,-1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 560, "ROUND(555.555,-1)"); oParser = new parserFormula("ROUND(555.555,-2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 600, "ROUND(555.555,-2)"); oParser = new parserFormula("ROUND(555.555,-3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1000, "ROUND(555.555,-3)"); oParser = new parserFormula("ROUND(0.123456,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0.12, "ROUND(0.123456,2)"); oParser = new parserFormula("ROUND(0.123456,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0.123, "ROUND(0.123456,3)"); oParser = new parserFormula("ROUND(0.123456,4)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0.1235, "ROUND(0.123456,4)"); oParser = new parserFormula("ROUND(0.999999,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1.00, "ROUND(0.999999,2)"); oParser = new parserFormula("ROUND(123456.789,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 123456.79, "ROUND(123456.789,2)"); oParser = new parserFormula("ROUND(999999.999,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1000000.00, "ROUND(999999.999,2)"); oParser = new parserFormula("ROUND(1000000.001,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1000000.00, "ROUND(1000000.001,2)"); oParser = new parserFormula("ROUND(0.0000123456,5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0.00001, "ROUND(0.0000123456,5)"); oParser = new parserFormula("ROUND(0.0000123456,6)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0.000012, "ROUND(0.0000123456,6)"); oParser = new parserFormula("ROUND(0.0000123456,7)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0.0000123, "ROUND(0.0000123456,7)"); oParser = new parserFormula("ROUND(2.005,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2.01, "ROUND(2.005,2)"); oParser = new parserFormula("ROUND(3.005,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3.01, "ROUND(3.005,2)"); oParser = new parserFormula("ROUND(4.005,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4.01, "ROUND(4.005,2)"); oParser = new parserFormula("ROUND(5.005,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5.01, "ROUND(5.005,2)"); oParser = new parserFormula("ROUND(0.333333,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0.33, "ROUND(0.333333,2)"); oParser = new parserFormula("ROUND(0.666666,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0.67, "ROUND(0.666666,2)"); oParser = new parserFormula("ROUND(0.166666,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0.17, "ROUND(0.166666,2)"); oParser = new parserFormula("ROUND(0.142857,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0.14, "ROUND(0.142857,2)"); oParser = new parserFormula("ROUND(3.141592653589793,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3.14, "ROUND(3.141592653589793,2)"); oParser = new parserFormula("ROUND(2.718281828459045,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2.72, "ROUND(2.718281828459045,2)"); oParser = new parserFormula("ROUND(1.414213562373095,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1.41, "ROUND(1.414213562373095,2)"); oParser = new parserFormula("ROUND(0.5,0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1, "ROUND(0.5,0)"); oParser = new parserFormula("ROUND(1.5,0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2, "ROUND(1.5,0)"); oParser = new parserFormula("ROUND(2.5,0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3, "ROUND(2.5,0)"); oParser = new parserFormula("ROUND(-0.5,0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -1, "ROUND(-0.5,0)"); oParser = new parserFormula("ROUND(-1.5,0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -2, "ROUND(-1.5,0)"); oParser = new parserFormula("ROUND(1.23456789,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1.2, "ROUND(1.23456789,1)"); oParser = new parserFormula("ROUND(1.23456789,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1.23, "ROUND(1.23456789,2)"); oParser = new parserFormula("ROUND(1.23456789,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1.235, "ROUND(1.23456789,3)"); oParser = new parserFormula("ROUND(1.23456789,4)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1.2346, "ROUND(1.23456789,4)"); oParser = new parserFormula("ROUND(1.23456789,5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1.23457, "ROUND(1.23456789,5)"); oParser = new parserFormula("ROUND(0,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0, "ROUND(0,2)"); oParser = new parserFormula("ROUND(0,0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0, "ROUND(0,0)"); oParser = new parserFormula("ROUND(0,-2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0, "ROUND(0,-2)"); oParser = new parserFormula("ROUND(1.15,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1.2, "ROUND(1.15,1)"); oParser = new parserFormula("ROUND(1.25,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1.3, "ROUND(1.25,1)"); oParser = new parserFormula("ROUND(1.35,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1.4, "ROUND(1.35,1)"); oParser = new parserFormula("ROUND(1.45,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1.5, "ROUND(1.45,1)"); oParser = new parserFormula("ROUND(1.55,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1.6, "ROUND(1.55,1)"); oParser = new parserFormula("ROUND(0.01,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0.01, "ROUND(0.01,2)"); oParser = new parserFormula("ROUND(0.02,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0.02, "ROUND(0.02,2)"); oParser = new parserFormula("ROUND(0.03,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0.03, "ROUND(0.03,2)"); oParser = new parserFormula("ROUND(0.04,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0.04, "ROUND(0.04,2)"); oParser = new parserFormula("ROUND(0.05,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0.05, "ROUND(0.05,2)"); oParser = new parserFormula("ROUND(-0.01,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -0.01, "ROUND(-0.01,2)"); oParser = new parserFormula("ROUND(-0.02,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -0.02, "ROUND(-0.02,2)"); oParser = new parserFormula("ROUND(-0.03,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -0.03, "ROUND(-0.03,2)"); oParser = new parserFormula("ROUND(-0.04,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -0.04, "ROUND(-0.04,2)"); oParser = new parserFormula("ROUND(-0.05,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -0.05, "ROUND(-0.05,2)"); oParser = new parserFormula("ROUND(19.99,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 19.99, "ROUND(19.99,2)"); oParser = new parserFormula("ROUND(19.90,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 19.90, "ROUND(19.90,2)"); oParser = new parserFormula("ROUND(19.00,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 19.00, "ROUND(19.00,2)"); oParser = new parserFormula("ROUND(19.999,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 20.00, "ROUND(19.999,2)"); oParser = new parserFormula("ROUND(19.001,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 19.00, "ROUND(19.001,2)"); testArrayFormula2(assert, "ROUND", 2, 2); }); QUnit.test("Test: \"ROUNDUP(31415.92654,-2)\"", function (assert) { oParser = new parserFormula("ROUNDUP(31415.92654,-2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 31500); }); QUnit.test("Test: \"ROUNDUP(3.2,0)\"", function (assert) { oParser = new parserFormula("ROUNDUP(3.2,0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); }); QUnit.test("Test: \"ROUNDUP(-3.14159,1)\"", function (assert) { oParser = new parserFormula("ROUNDUP(-3.14159,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -3.2); }); QUnit.test("Test: \"ROUNDUP(3.14159,3)\"", function (assert) { oParser = new parserFormula("ROUNDUP(3.14159,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3.142); testArrayFormula2(assert, "ROUNDUP", 2, 2); }); QUnit.test("Test: \"ROUNDUP\"", function (assert) { let array; oParser = new parserFormula("ROUNDUP(2.1123,4)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(4) - 0, 2.1123); //TODO в хроме при расчёте разница, временно убираю oParser = new parserFormula("ROUNDUP(2,4)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual( oParser.calculate().getValue(), 2); oParser = new parserFormula("ROUNDUP(2,0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula("ROUNDUP(2.1123,-1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 10); oParser = new parserFormula("ROUNDUP(2.1123,0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); oParser = new parserFormula("ROUNDUP(123.431,0.1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 124); oParser = new parserFormula("ROUNDUP(123.431,0.9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 124); oParser = new parserFormula("ROUNDUP(123.431,-0.9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 124); oParser = new parserFormula("ROUNDUP(123.431,-0.1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 124); oParser = new parserFormula("ROUNDUP(123.431,-2.1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 200); oParser = new parserFormula('ROUNDUP("test",-2.1)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula('ROUNDUP(123.431,"test")', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula('ROUNDUP(123.431,#NUM!)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula('ROUNDUP(#NUM!,123.431)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula('ROUNDUP(123.431,-1.9)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 130); oParser = new parserFormula("ROUNDUP(-50.55,0.9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -51); oParser = new parserFormula("ROUNDUP(-50.55,0.1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -51); oParser = new parserFormula("ROUNDUP(26.7047619,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 26.8); oParser = new parserFormula("ROUNDUP(26.7047619,4)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 26.7048); oParser = new parserFormula("ROUNDUP(26.7047619,8)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 26.7047619); oParser = new parserFormula("ROUNDUP(267.047619,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 267.1); oParser = new parserFormula("ROUNDUP(267.047619,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 267.05); oParser = new parserFormula("ROUNDUP(267.047619,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 267.048); oParser = new parserFormula("ROUNDUP(267.047619,4)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 267.0477); oParser = new parserFormula("ROUNDUP(267.047619,5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 267.04762); oParser = new parserFormula("ROUNDUP(267.047619,6)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 267.047619); oParser = new parserFormula("ROUNDUP(267.047619,7)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 267.047619); oParser = new parserFormula("ROUNDUP(267.047619,8)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 267.047619); oParser = new parserFormula("ROUNDUP(0.1+0.2,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 0.4); // 0.4 oParser = new parserFormula("ROUNDUP(22.123,99999999999999999)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 22.123); oParser = new parserFormula("ROUNDUP(22.123,-99999999999999999)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("ROUNDUP(267.047619,-2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 300); oParser = new parserFormula("ROUNDUP(-267.047619,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, -267.05); oParser = new parserFormula("ROUNDUP(-267.047619,-2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, -300); oParser = new parserFormula("ROUNDUP(-267.047619,-3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, -1000); oParser = new parserFormula("ROUNDUP(26709,-1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 26710); oParser = new parserFormula("ROUNDUP(26709,-2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 26800); oParser = new parserFormula("ROUNDUP(26709,-3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 27000); oParser = new parserFormula("ROUNDUP(26709,-4)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed() - 0, 30000); // 30000 // cEmpty ws.getRange2("B101").setValue(); oParser = new parserFormula("ROUNDUP(,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 0); oParser = new parserFormula("ROUNDUP(B101,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 0); oParser = new parserFormula("ROUNDUP(2.2,)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 3); oParser = new parserFormula("ROUNDUP(B101,B101)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 0); oParser = new parserFormula("ROUNDUP(,)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 0); // cError ws.getRange2("C101").setValue("#NUM!"); ws.getRange2("C102").setValue("#N/A"); ws.getRange2("C103").setValue("#DIV/0!"); oParser = new parserFormula("ROUNDUP(#N/A,#NUM!)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); oParser = new parserFormula("ROUNDUP(C102,C101)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); oParser = new parserFormula("ROUNDUP(25,#NUM!)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("ROUNDUP(25,C101)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("ROUNDUP(#DIV/0!,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!"); oParser = new parserFormula("ROUNDUP(C103,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!"); // cString oParser = new parserFormula('ROUNDUP("22.2567",3)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 22.257); oParser = new parserFormula('ROUNDUP("22.2567s",3)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula('ROUNDUP("22.2567","3")', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 22.257); oParser = new parserFormula('ROUNDUP("22.2567","3s")', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); // cBool oParser = new parserFormula('ROUNDUP(22.2567,FALSE)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 23); oParser = new parserFormula('ROUNDUP(22.2567,TRUE)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 22.3); oParser = new parserFormula('ROUNDUP(FALSE, 2)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 0); oParser = new parserFormula('ROUNDUP(TRUE, 2)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 1); oParser = new parserFormula('ROUNDUP(FALSE, -2)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 0); oParser = new parserFormula('ROUNDUP(TRUE, -2)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 100); oParser = new parserFormula('ROUNDUP(TRUE, TRUE)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 1); oParser = new parserFormula('ROUNDUP(TRUE, FALSE)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 1); oParser = new parserFormula('ROUNDUP(FALSE, FALSE)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 0); // cArray oParser = new parserFormula("ROUNDUP({22.123,2.2},{1;2;3;0})", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:F110").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 22.2); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2.2); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 22.13); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 2.21); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 22.123); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 2.2); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 23); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), 3); // cellsRange ws.getRange2("E101").setValue("22.123"); ws.getRange2("F101").setValue("3"); ws.getRange2("G101").setValue(); ws.getRange2("E102").setValue("1"); ws.getRange2("F102").setValue("2"); ws.getRange2("G102").setValue("3"); ws.getRange2("E103").setValue("1.23"); ws.getRange2("F103").setValue("1.32"); ws.getRange2("G103").setValue("3.33"); oParser = new parserFormula("ROUNDUP(E101:G103,E102:G102)", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:F110").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 22.2); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 0); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 1); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 2); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 3); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 1.3); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 1.32); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), 3.33); // for bug 71525 oParser = new parserFormula('ROUNDUP(8.175,3)', "A1", ws); assert.ok(oParser.parse(), "ROUNDUP(8.175,3)"); assert.strictEqual(oParser.calculate().getValue(), 8.175, "Result of ROUNDUP(8.175,3)"); oParser = new parserFormula('ROUNDUP(8.17529,5)', "A1", ws); assert.ok(oParser.parse(), "ROUNDUP(8.17529,5)"); assert.strictEqual(oParser.calculate().getValue(), 8.17529, "Result of ROUNDUP(8.17529,5)"); }); QUnit.test("Test: \"ROUNDDOWN\"", function (assert) { oParser = new parserFormula("ROUNDDOWN(3.2,0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); oParser = new parserFormula("ROUNDDOWN(3.14159,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3.141); oParser = new parserFormula("ROUNDDOWN(-3.14159,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -3.1); oParser = new parserFormula("ROUNDDOWN(31415.92654,-2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 31400); oParser = new parserFormula("ROUNDDOWN(123.431,0.1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 123); oParser = new parserFormula("ROUNDDOWN(123.431,0.9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 123); oParser = new parserFormula("ROUNDDOWN(123.431,-0.9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 123); oParser = new parserFormula("ROUNDDOWN(123.431,-0.1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 123); oParser = new parserFormula("ROUNDDOWN(123.431,-2.1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 100); oParser = new parserFormula('ROUNDDOWN("test",-2.1)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula('ROUNDDOWN(123.431,"test")', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula('ROUNDDOWN(123.431,#NUM!)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula('ROUNDDOWN(#NUM!,123.431)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("ROUNDDOWN(-50.55,0.9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -50); oParser = new parserFormula("ROUNDDOWN(-50.55,0.1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -50); oParser = new parserFormula("ROUNDDOWN(10000000000,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 10000000000); oParser = new parserFormula("ROUNDDOWN(10000000000,-3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 10000000000); oParser = new parserFormula("ROUNDDOWN(12345678901,-3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 12345678000); // Tests for negative numbers with fractional second argument oParser = new parserFormula("ROUNDDOWN(-123.456, 1.9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -123.4); oParser = new parserFormula("ROUNDDOWN(-123.456, -1.9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -120); // More tests with negative second argument oParser = new parserFormula("ROUNDDOWN(5555.55, -2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5500); oParser = new parserFormula("ROUNDDOWN(-5555.55, -2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -5500); // Tests with decimal places in second argument oParser = new parserFormula("ROUNDDOWN(123.456, 1.1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 123.4); oParser = new parserFormula("ROUNDDOWN(123.456, 1.9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 123.4); testArrayFormula2(assert, "ROUNDDOWN", 2, 2); }); QUnit.test("Test: \"MROUND\"", function (assert) { var multiple;//должен равняться значению второго аргумента function mroundHelper(num) { var multiplier = Math.pow(10, Math.floor(Math.log(Math.abs(num)) / Math.log(10)) - AscCommonExcel.cExcelSignificantDigits + 1); var nolpiat = 0.5 * (num > 0 ? 1 : num < 0 ? -1 : 0) * multiplier; var y = (num + nolpiat) / multiplier; y = y / Math.abs(y) * Math.floor(Math.abs(y)) var x = y * multiplier / multiple // var x = number / multiple; var nolpiat = 5 * (x / Math.abs(x)) * Math.pow(10, Math.floor(Math.log(Math.abs(x)) / Math.log(10)) - AscCommonExcel.cExcelSignificantDigits); x = x + nolpiat; x = x | x; return x * multiple; } oParser = new parserFormula("MROUND(10,3)", "A1", ws); assert.ok(oParser.parse()); multiple = 3; assert.strictEqual(oParser.calculate().getValue(), mroundHelper(10 + 3 / 2)); oParser = new parserFormula("MROUND(-10,-3)", "A1", ws); assert.ok(oParser.parse()); multiple = -3; assert.strictEqual(oParser.calculate().getValue(), mroundHelper(-10 + -3 / 2)); oParser = new parserFormula("MROUND(1.3,0.2)", "A1", ws); assert.ok(oParser.parse()); multiple = 0.2; assert.strictEqual(oParser.calculate().getValue(), mroundHelper(1.3 + 0.2 / 2)); testArrayFormula2(assert, "MROUND", 2, 2, true, null); }); QUnit.test("Test: \"T(\"HELLO\")\"", function (assert) { oParser = new parserFormula("T(\"HELLO\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "HELLO"); }); QUnit.test("Test: \"MMULT\"", function (assert) { ws.getRange2("AAA102").setValue("4"); ws.getRange2("AAA103").setValue("5"); ws.getRange2("AAA104").setValue("6"); ws.getRange2("AAA105").setValue("7"); ws.getRange2("AAB102").setValue("1"); ws.getRange2("AAB103").setValue("2"); ws.getRange2("AAB104").setValue("3"); ws.getRange2("AAB105").setValue("2"); ws.getRange2("AAC102").setValue("4"); ws.getRange2("AAC103").setValue("5"); ws.getRange2("AAC104").setValue("6"); ws.getRange2("AAC105").setValue("3"); ws.getRange2("AAD102").setValue("7"); ws.getRange2("AAD103").setValue("8"); ws.getRange2("AAD104").setValue("9"); ws.getRange2("AAD105").setValue("4"); ws.getRange2("AAF102").setValue("1"); ws.getRange2("AAF103").setValue("2"); ws.getRange2("AAF104").setValue("3"); ws.getRange2("AAF105").setValue("6"); ws.getRange2("AAG102").setValue("2"); ws.getRange2("AAG103").setValue("3"); ws.getRange2("AAG104").setValue("4"); ws.getRange2("AAG105").setValue("5"); oParser = new parserFormula("MMULT(AAC102,AAF104)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 12); oParser = new parserFormula("MMULT(AAA102:AAD105,AAF104)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("MMULT(AAC102,AAF104)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 12); oParser = new parserFormula("MMULT(AAA102:AAD105,AAF102:AAG105)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 60); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue(), 62); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue(), 72); assert.strictEqual(oParser.calculate().getElementRowCol(1, 1).getValue(), 76); oParser = new parserFormula("MMULT(AAA102:AAD105,AAF102:AAF105)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 60); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue(), 72); oParser = new parserFormula("MMULT(AAA102:AAD105,AAF102:AAF105)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 60); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue(), 72); oParser = new parserFormula("MMULT(AAA102:AAD105,AAF102:AAF104)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("MMULT(AAA102:AAD105,AAK110:AAN110)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("MMULT(AAA102:AAD105,AAA102:AAD105)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 94); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue(), 116); assert.strictEqual(oParser.calculate().getElementRowCol(2, 0).getValue(), 138); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue(), 32); assert.strictEqual(oParser.calculate().getElementRowCol(1, 1).getValue(), 40); assert.strictEqual(oParser.calculate().getElementRowCol(2, 1).getValue(), 48); oParser = new parserFormula("MMULT(AAF102:AAF105,AAG102:AAG105)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("MMULT(AAF102:AAF105,AAA102:AAD102)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 4); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue(), 8); assert.strictEqual(oParser.calculate().getElementRowCol(2, 0).getValue(), 12); oParser = new parserFormula("MMULT({1,2,3},{1;2;3})", "A1", ws); assert.ok(oParser.parse(), "MMULT({1,2,3},{1;2;3})"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 14, "Result of MMULT({1,2,3},{1;2;3})"); oParser = new parserFormula("MMULT({1,3,4},{2;3;4;5})", "A1", ws); assert.ok(oParser.parse(), "MMULT({1,3,4},{2;3;4;5})"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of MMULT({1,3,4},{2;3;4;5})"); oParser = new parserFormula("MMULT({1,2,3,4},{1;2;3})", "A1", ws); assert.ok(oParser.parse(), "MMULT({1,2,3,4},{1;2;3})"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of MMULT({1,2,3,4},{1;2;3})"); oParser = new parserFormula("MMULT({1;2;3},{1,2,3})", "A1", ws); assert.ok(oParser.parse(), "MMULT({1;2;3},{1,2,3})"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(0, 2).getValue(), 3); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(1, 1).getValue(), 4); assert.strictEqual(oParser.calculate().getElementRowCol(1, 2).getValue(), 6); assert.strictEqual(oParser.calculate().getElementRowCol(2, 0).getValue(), 3); assert.strictEqual(oParser.calculate().getElementRowCol(2, 1).getValue(), 6); assert.strictEqual(oParser.calculate().getElementRowCol(2, 2).getValue(), 9); oParser = new parserFormula('MMULT({1;2;3},{1,"2",3})', "A1", ws); assert.ok(oParser.parse(), 'MMULT({1;2;3},{1,2,3})'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of MMULT({1;2;3},{1,2,3})'); ws.getRange2("K100").setValue(""); oParser = new parserFormula("MMULT({1;2;3},{1;2;3})", "A1", ws); assert.ok(oParser.parse(), "MMULT({1;2;3},{1;2;3})"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of MMULT({1;2;3},{1;2;3})"); oParser = new parserFormula("MMULT({1,2,3},{1,2,3})", "A1", ws); assert.ok(oParser.parse(), "MMULT({1,2,3},{1,2,3})"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of MMULT({1,2,3},{1,2,3})"); oParser = new parserFormula("MMULT({1;2},2)", "A1", ws); assert.ok(oParser.parse(), "MMULT({1;2},2)"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue(), 4); oParser = new parserFormula("MMULT(2,3)", "A1", ws); assert.ok(oParser.parse(), "MMULT(2,3)"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 6); oParser = new parserFormula('MMULT("2",3)', "A1", ws); assert.ok(oParser.parse(), 'MMULT("2",3)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of MMULT("2",3)'); oParser = new parserFormula('MMULT(2,TRUE)', "A1", ws); assert.ok(oParser.parse(), 'MMULT(2,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of MMULT(2,TRUE)'); oParser = new parserFormula('MMULT(TRUE,2)', "A1", ws); assert.ok(oParser.parse(), 'MMULT(TRUE,2)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of MMULT(TRUE,2)'); oParser = new parserFormula('MMULT(2,-1)', "A1", ws); assert.ok(oParser.parse(), 'MMULT(2,-1)'); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), -2, 'Result of MMULT(2,-1)'); oParser = new parserFormula('MMULT(2,)', "A1", ws); assert.ok(oParser.parse(), 'MMULT(2,)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of MMULT(2,)'); oParser = new parserFormula('MMULT(,2)', "A1", ws); assert.ok(oParser.parse(), 'MMULT(,2)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of MMULT(,2)'); oParser = new parserFormula('MMULT(2,K100)', "A1", ws); assert.ok(oParser.parse(), 'MMULT(2,K100)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of MMULT(2,K100)'); oParser = new parserFormula('MMULT(K100,2)', "A1", ws); assert.ok(oParser.parse(), 'MMULT(K100,2)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of MMULT(K100,2)'); oParser = new parserFormula('MMULT(2,0)', "A1", ws); assert.ok(oParser.parse(), 'MMULT(2,0)'); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 0, 'Result of MMULT(2,0)'); oParser = new parserFormula('MMULT(0,2)', "A1", ws); assert.ok(oParser.parse(), 'MMULT(0,2)'); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 0, 'Result of MMULT(0,2)'); oParser = new parserFormula('MMULT(0,0)', "A1", ws); assert.ok(oParser.parse(), 'MMULT(0,0)'); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 0, 'Result of MMULT(0,0)'); ws.getRange2("A100").setValue("1"); ws.getRange2("B100").setValue("2"); ws.getRange2("C100").setValue("3"); ws.getRange2("A101").setValue("4"); ws.getRange2("B101").setValue("5"); ws.getRange2("C101").setValue("6"); ws.getRange2("A102").setValue("7"); ws.getRange2("B102").setValue("8"); ws.getRange2("C102").setValue("9"); oParser = new parserFormula("MMULT(A100:B102,A100:C101)", "A1", ws); assert.ok(oParser.parse(), "MMULT(A100:B102,A100:C101)"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 9); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue(), 12); assert.strictEqual(oParser.calculate().getElementRowCol(0, 2).getValue(), 15); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue(), 24); assert.strictEqual(oParser.calculate().getElementRowCol(1, 1).getValue(), 33); assert.strictEqual(oParser.calculate().getElementRowCol(1, 2).getValue(), 42); assert.strictEqual(oParser.calculate().getElementRowCol(2, 0).getValue(), 39); assert.strictEqual(oParser.calculate().getElementRowCol(2, 1).getValue(), 54); assert.strictEqual(oParser.calculate().getElementRowCol(2, 2).getValue(), 69); oParser = new parserFormula("MMULT(A100:C102,A100:A102)", "A1", ws); assert.ok(oParser.parse(), "MMULT(A100:C102,A100:A102)"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 30); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue(), 66); assert.strictEqual(oParser.calculate().getElementRowCol(2, 0).getValue(), 102); oParser = new parserFormula("MMULT(A100:A102,A100:C102)", "A1", ws); assert.ok(oParser.parse(), "MMULT(A100:A102,A100:C102)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); }); QUnit.test("Test: \"T(123)\"", function (assert) { oParser = new parserFormula("T(123)", "A1", ws); assert.ok(oParser.parse()); assert.ok(!oParser.calculate().getValue(), "123"); }); QUnit.test("Test: YEAR", function (assert) { oParser = new parserFormula("YEAR(2013)", "A1", ws); assert.ok(oParser.parse()); if (AscCommon.bDate1904) { assert.strictEqual(oParser.calculate().getValue(), 1909); } else { assert.strictEqual(oParser.calculate().getValue(), 1905); } testArrayFormula2(assert, "YEAR", 1, 1); }); QUnit.test("Test: DAY", function (assert) { oParser = new parserFormula("DAY(2013)", "A1", ws); assert.ok(oParser.parse()); if (AscCommon.bDate1904) { assert.strictEqual(oParser.calculate().getValue(), 6); } else { assert.strictEqual(oParser.calculate().getValue(), 5); } testArrayFormula2(assert, "DAY", 1, 1); }); QUnit.test("Test: DAYS", function (assert) { let array; ws.getRange2("A2").setValue("12/31/2011"); ws.getRange2("A3").setValue("1/1/2011"); oParser = new parserFormula('DAYS("3/15/11","2/1/11")', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 42); oParser = new parserFormula("DAYS(A2,A3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 364); oParser = new parserFormula("DAYS(A2,A3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 364); oParser = new parserFormula('DAYS("2008-03-03","2008-03-01")', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula('DAYS("2008-03-01","2008-03-03")', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -2); ws.getRange2("B3").setValue("44229.4673611111"); ws.getRange2("B4").setValue("44229.46875"); ws.getRange2("B5").setValue("1"); ws.getRange2("B6").setValue("1.9"); ws.getRange2("B7").setValue("2.1"); ws.getRange2("B8").setValue("10"); oParser = new parserFormula('DAYS(B4,B3)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(B4,B3)'); assert.strictEqual(oParser.calculate().getValue(), 0, 'Result of DAYS(B4,B3)'); oParser = new parserFormula('DAYS(B5,B8)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(B5,B8)'); assert.strictEqual(oParser.calculate().getValue(), -9, 'Result of DAYS(B5,B8)'); oParser = new parserFormula('DAYS(1,10)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(1,10)'); assert.strictEqual(oParser.calculate().getValue(), -9, 'Result of DAYS(1,10)'); oParser = new parserFormula('DAYS(B6,B8)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(B6,B8)'); assert.strictEqual(oParser.calculate().getValue(), -9, 'Result of DAYS(B6,B8)'); oParser = new parserFormula('DAYS(1.9,10)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(1.9,10)'); assert.strictEqual(oParser.calculate().getValue(), -9, 'Result of DAYS(1.9,10)'); oParser = new parserFormula('DAYS(B7,B8)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(B7,B8)'); assert.strictEqual(oParser.calculate().getValue(), -8, 'Result of DAYS(B7,B8)'); oParser = new parserFormula('DAYS(2.1,10)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(2.1,10)'); assert.strictEqual(oParser.calculate().getValue(), -8, 'Result of DAYS(2.1,10)'); oParser = new parserFormula('DAYS(2.1,10.1)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(2.1,10.1)'); assert.strictEqual(oParser.calculate().getValue(), -8, 'Result of DAYS(2.1,10.1)'); oParser = new parserFormula('DAYS(2.1,10.9)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(2.1,10.9)'); assert.strictEqual(oParser.calculate().getValue(), -8, 'Result of DAYS(2.1,10.9)'); oParser = new parserFormula('DAYS(2.1,-10.9)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(2.1,-10.9)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of DAYS(2.1,-10.9)'); oParser = new parserFormula('DAYS(-2.1,10.9)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(-2.1,10.9)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of DAYS(2.1,10.9)'); oParser = new parserFormula('DAYS(-2.1,-10.9)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(-2.1,-10.9)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of DAYS(-2.1,-10.9)'); oParser = new parserFormula('DAYS(,10.9)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(,10.9)'); assert.strictEqual(oParser.calculate().getValue(), -10, 'Result of DAYS(,10.9)'); oParser = new parserFormula('DAYS(2.1,)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(2.1,)'); assert.strictEqual(oParser.calculate().getValue(), 2, 'Result of DAYS(2.1,)'); oParser = new parserFormula('DAYS(,)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(,)'); assert.strictEqual(oParser.calculate().getValue(), 0, 'Result of DAYS(,)'); // string oParser = new parserFormula('DAYS("1","10")', "A1", ws); assert.ok(oParser.parse(), 'DAYS("1","10")'); assert.strictEqual(oParser.calculate().getValue(), -9, 'Result of DAYS("1","10")'); oParser = new parserFormula('DAYS("1s","10")', "A1", ws); assert.ok(oParser.parse(), 'DAYS("1s","10")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of DAYS("1s","10")'); oParser = new parserFormula('DAYS("1","10s")', "A1", ws); assert.ok(oParser.parse(), 'DAYS("1","10s")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of DAYS("1","10s")'); // bool oParser = new parserFormula('DAYS(TRUE,10)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(TRUE,10)'); assert.strictEqual(oParser.calculate().getValue(), -9, 'Result of DAYS(TRUE,10)'); oParser = new parserFormula('DAYS(FALSE,10)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(FALSE,10)'); assert.strictEqual(oParser.calculate().getValue(), -10, 'Result of DAYS(FALSE,10)'); oParser = new parserFormula('DAYS(1,TRUE)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(1,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), 0, 'Result of DAYS(1,TRUE)'); oParser = new parserFormula('DAYS(1,FALSE)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(1,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of DAYS(1,FALSE)'); oParser = new parserFormula('DAYS(TRUE,TRUE)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(TRUE,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), 0, 'Result of DAYS(TRUE,TRUE)'); // errors ws.getRange2("B100").setValue("#N/A"); ws.getRange2("B101").setValue("#NUM!"); oParser = new parserFormula('DAYS(#N/A,10)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(#N/A,10)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of DAYS(#N/A,10)'); oParser = new parserFormula('DAYS(B100,10)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(B100,10)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of DAYS(B100,10)'); oParser = new parserFormula('DAYS(#N/A,#NUM!)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(#N/A,#NUM!)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of DAYS(#N/A,#NUM!)'); oParser = new parserFormula('DAYS(B100,B101)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(B100,B101)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of DAYS(B100,B101)'); oParser = new parserFormula('DAYS(#NUM!,#N/A)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(#NUM!,#N/A)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of DAYS(#NUM!,#N/A)'); oParser = new parserFormula('DAYS(B101,B100)', "A1", ws); assert.ok(oParser.parse(), 'DAYS(B101,B100)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of DAYS(B101,B100)'); // array oParser = new parserFormula('DAYS({1;2;3},10)', "A1", ws); assert.ok(oParser.parse(), 'DAYS({1;2;3},10)'); assert.strictEqual(oParser.calculate().getValue(), -9, 'Result of DAYS({1;2;3},10)'); oParser = new parserFormula('DAYS({1;2;3},10)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("F106:I109").bbox); assert.ok(oParser.parse(), 'DAYS({1;2;3},10)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), -9, 'Result of DAYS({1;2;3},10)[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), -8, 'Result of DAYS({1;2;3},10)[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), -7, 'Result of DAYS({1;2;3},10)[2,0]'); oParser = new parserFormula('DAYS({1;2;3},{10;9;8})', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("F106:I109").bbox); assert.ok(oParser.parse(), 'DAYS({1;2;3},{10;9;8})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), -9, 'Result of DAYS({1;2;3},{10;9;8})[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), -7, 'Result of DAYS({1;2;3},{10;9;8})[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), -5, 'Result of DAYS({1;2;3},{10;9;8})[2,0]'); // range ws.getRange2("A25").setValue("1"); ws.getRange2("A26").setValue("2"); ws.getRange2("A27").setValue("3"); ws.getRange2("B25").setValue("10"); ws.getRange2("B26").setValue("9"); ws.getRange2("B27").setValue("8"); oParser = new parserFormula('DAYS(A25:A27,B25:B27)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("F106:I109").bbox); assert.ok(oParser.parse(), 'DAYS(A25:A27,B25:B27)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), -9, "Result of DAYS(A25:A27,B25:B27)[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), -7, "Result of DAYS(A25:A27,B25:B27)[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), -5, "Result of DAYS(A25:A27,B25:B27)[2,0]"); testArrayFormula2(assert, "DAYS", 2, 2); }); QUnit.test("Test: DAY 2", function (assert) { oParser = new parserFormula("DAY(\"20 may 2045\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 20); }); QUnit.test("Test: MONTH #1", function (assert) { oParser = new parserFormula("MONTH(2013)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 7); }); QUnit.test("Test: MONTH #2", function (assert) { oParser = new parserFormula("MONTH(DATE(2013,2,2))", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); }); QUnit.test("Test: MONTH #3", function (assert) { oParser = new parserFormula("MONTH(NOW())", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), new cDate().getUTCMonth() + 1); testArrayFormula2(assert, "MONTH", 1, 1); }); QUnit.test("Test: \"10-3\"", function (assert) { oParser = new parserFormula("10-3", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 7); }); QUnit.test("Test: \"SUM\"", function (assert) { ws.getRange2("S5").setValue("1"); ws.getRange2("S6").setValue(numDivFact(-1, 2)); ws.getRange2("S7").setValue(numDivFact(1, 4)); ws.getRange2("S8").setValue(numDivFact(-1, 6)); oParser = new parserFormula("SUM(S5:S8)", "A1", ws); assert.ok(oParser.parse()); // assert.strictEqual( oParser.calculate().getValue(), 1-1/Math.fact(2)+1/Math.fact(4)-1/Math.fact(6) ); assert.ok(Math.abs(oParser.calculate().getValue() - (1 - 1 / Math.fact(2) + 1 / Math.fact(4) - 1 / Math.fact(6))) < dif); // for bug 66800 ws.getRange2("A101").setValue("1"); ws.getRange2("A102").setValue("2"); ws.getRange2("A103").setValue("3"); oParser = new parserFormula("SUM(A101:A103+A101:A103)", "A1", ws); assert.ok(oParser.parse(), 'SUM(A101:A103+A101:A103)'); assert.strictEqual(oParser.calculate().getValue(), 12, 'Result of SUM(A101:A103+A101:A103)'); oParser = new parserFormula("SUM(SIN(A101:A103))", "A1", ws); assert.ok(oParser.parse(), 'SUM(SIN(A101:A103))'); assert.strictEqual(oParser.calculate().getValue().toFixed(2), "1.89", 'Result of SUM(SIN(A101:A103))'); }); QUnit.test("Test: \"MAX\"", function (assert) { oParser = new parserFormula("MAX(-1, TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("MAX(0, FALSE)", "A1", ws); assert.ok(oParser.parse(), "MAX(0, FALSE)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of MAX(0, FALSE)"); oParser = new parserFormula("MAX(25, 25.1, 25.01, 25.02, 25.2, 25.222, 25.333, 25.3334)", "A1", ws); assert.ok(oParser.parse(), "MAX(25, 25.1, 25.01, 25.02, 25.2, 25.222, 25.333, 25.3334)"); assert.strictEqual(oParser.calculate().getValue(), 25.3334, "Result of MAX(25, 25.1, 25.01, 25.02, 25.2, 25.222, 25.333, 25.3334)"); oParser = new parserFormula("MAX(TRUE, FALSE)", "A1", ws); assert.ok(oParser.parse(), "MAX(TRUE, FALSE)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MAX(TRUE, FALSE)"); oParser = new parserFormula("MAX(FALSE, FALSE)", "A1", ws); assert.ok(oParser.parse(), "MAX(FALSE, FALSE)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of MAX(FALSE, FALSE)"); oParser = new parserFormula("MAX(str)", "A1", ws); assert.ok(oParser.parse(), "MAX(str)"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Result of MAX(str)"); oParser = new parserFormula("MAX(49.08 - 432.81, 0)", "A1", ws); assert.ok(oParser.parse(), "MAX(49.08 - 432.81, 0)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of MAX(49.08 - 432.81, 0)"); oParser = new parserFormula("MAX(FALSE,-1-2,3-8,FALSE,TRUE)", "A1", ws); assert.ok(oParser.parse(), "MAX(FALSE,-1-2,3-8,FALSE,TRUE)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MAX(FALSE,-1-2,3-8,FALSE,TRUE)"); oParser = new parserFormula("MAX(49.08 - 432.81, 9,99999999999999E+43)", "A1", ws); assert.ok(oParser.parse(), "MAX(49.08 - 432.81, 9,99999999999999E+43)"); assert.strictEqual(oParser.calculate().getValue(), 9.9999999999999e+56, "Result of MAX(49.08 - 432.81, 9,99999999999999E+43)"); oParser = new parserFormula("MAX(49.08 - 432.81, {9,99999999999999E+43})", "A1", ws); assert.ok(oParser.parse(), "MAX(49.08 - 432.81, {9,99999999999999E+43})"); assert.strictEqual(oParser.calculate().getValue(), 9.9999999999999e+56, "Result of MAX(49.08 - 432.81, {9,99999999999999E+43})"); oParser = new parserFormula("MAX(49.08 - 432.81, {12,13;14,15})", "A1", ws); assert.ok(oParser.parse(), "MAX(49.08 - 432.81, {12,13;14,15})"); assert.strictEqual(oParser.calculate().getValue(), 15, "Result of MAX(49.08 - 432.81, {12,13;14,15})"); oParser = new parserFormula("MAX({1,1,TRUE,2})", "A1", ws); assert.ok(oParser.parse(), "MAX({1,1,TRUE,2})"); assert.strictEqual(oParser.calculate().getValue(), 2, "Result of MAX({1,1,TRUE,2})"); oParser = new parserFormula("MAX({1,1,TRUE,2},{1,2,3,4,5,6,7,8,9,11,1})", "A1", ws); assert.ok(oParser.parse(), "MAX({1,1,TRUE,2},{1,2,3,4,5,6,7,8,9,11,1})"); assert.strictEqual(oParser.calculate().getValue(), 11, "Result of MAX({1,1,TRUE,2},{1,2,3,4,5,6,7,8,9,11,1})"); oParser = new parserFormula("MAX({1,1,TRUE,2},{12;12;13;11},{1,2,3,4,5,6,7,8,9,11,1})", "A1", ws); assert.ok(oParser.parse(), "MAX({1,1,TRUE,2},{12;12;13;11},{1,2,3,4,5,6,7,8,9,11,1})"); assert.strictEqual(oParser.calculate().getValue(), 13, "Result of MAX({1,1,TRUE,2},{12;12;13;11},{1,2,3,4,5,6,7,8,9,11,1})"); ws.getRange2("S5").setValue("1"); ws.getRange2("S6").setValue(numDivFact(-1, 2)); ws.getRange2("S7").setValue(numDivFact(1, 4)); ws.getRange2("S8").setValue(numDivFact(-1, 6)); oParser = new parserFormula("MAX(S5:S8)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); ws.getRange2("S5").setValue("#DIV/0!"); ws.getRange2("S6").setValue("TRUE"); ws.getRange2("S7").setValue("qwe"); ws.getRange2("S8").setValue(""); ws.getRange2("S9").setValue("-1"); ws.getRange2("J10").setValue(); ws.getRange2("J11").setValue(""); ws.getRange2("J12").setValue("10"); ws.getRange2("J13").setValue("7"); ws.getRange2("J14").setValue("2"); ws.getRange2("J15").setValue("27"); ws.getRange2("J16").setValue("TRUE"); ws.getRange2("J17").setValue("FALSE"); ws.getRange2("J18").setValue("#N/A"); ws.getRange2("J19").setValue("{2;3;4;5}"); ws.getRange2("J20").setValue("{999;2;3;4;5}"); ws.getRange2("J21").setValue("9.99999999999999E+43"); ws.getRange2("J22").setValue("-9.99999999999999E+43"); ws.getRange2("J23").setValue("0.000009"); ws.getRange2("J24").setValue("-0.000009"); ws.getRange2("J25").setValue("255"); // string ws.getRange2("J25").setNumFormat("@"); oParser = new parserFormula("MAX(J10)", "A1", ws); assert.ok(oParser.parse(), "MAX(J10)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of MAX(J10)"); oParser = new parserFormula("MAX(J11)", "A1", ws); assert.ok(oParser.parse(), "MAX(J11)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of MAX(J11)"); oParser = new parserFormula("MAX(J12)", "A1", ws); assert.ok(oParser.parse(), "MAX(J12)"); assert.strictEqual(oParser.calculate().getValue(), 10, "Result of MAX(J12)"); oParser = new parserFormula("MAX(J10:J17,J19:J24)", "A1", ws); assert.ok(oParser.parse(), "MAX(J10:J17,J19:J24)"); assert.strictEqual(oParser.calculate().getValue(), 9.99999999999999E+43, "Result of MAX(J10:J17,J19:J24)"); oParser = new parserFormula("MAX(J12:J19)", "A1", ws); assert.ok(oParser.parse(), "MAX(J12:J19)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of MAX(J12:J19)"); oParser = new parserFormula("MAX(J10:J25)", "A1", ws); assert.ok(oParser.parse(), "MAX(J10:J25)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of MAX(J10:J25)"); oParser = new parserFormula("MAX(J25, J10:J17)", "A1", ws); assert.ok(oParser.parse(), "MAX(J25, J10:J17)"); assert.strictEqual(oParser.calculate().getValue(), 255, "Result of MAX(J25, J10:J17)"); oParser = new parserFormula("MAX(J25, J10:J17, J18)", "A1", ws); assert.ok(oParser.parse(), "MAX(J25, J10:J17, J18)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of MAX(J25, J10:J17, J18)"); oParser = new parserFormula("MAX(S5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!"); oParser = new parserFormula("MAX(S6)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("MAX(S7)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("MAX(S8)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("MAX(S5:S9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!"); oParser = new parserFormula("MAX(S6:S9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -1); testArrayFormula2(assert, "MAX", 1, 8, null, true); }); QUnit.test("Test: \"MAXA\"", function (assert) { ws.getRange2("S5").setValue("1"); ws.getRange2("S6").setValue(numDivFact(-1, 2)); ws.getRange2("S7").setValue(numDivFact(1, 4)); ws.getRange2("S8").setValue(numDivFact(-1, 6)); oParser = new parserFormula("MAXA(S5:S8)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); ws.getRange2("S5").setValue("#DIV/0!"); ws.getRange2("S6").setValue("TRUE"); ws.getRange2("S7").setValue("qwe"); ws.getRange2("S8").setValue(""); ws.getRange2("S9").setValue("-1"); oParser = new parserFormula("MAXA(S5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!"); oParser = new parserFormula("MAXA(S6)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("MAXA(S7)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("MAXA(S8)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("MAXA(S5:S9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!"); oParser = new parserFormula("MAXA(S6:S9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("MAXA(-1, TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); testArrayFormula2(assert, "MAXA", 1, 8, null, true); }); QUnit.test("Test: \"MIN\"", function (assert) { ws.getRange2("S5").setValue("1"); ws.getRange2("S6").setValue(numDivFact(-1, 2)); ws.getRange2("S7").setValue(numDivFact(1, 4)); ws.getRange2("S8").setValue(numDivFact(-1, 6)); oParser = new parserFormula("MIN(S5:S8)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -1 / Math.fact(2)); ws.getRange2("S5").setValue("#DIV/0!"); ws.getRange2("S6").setValue("TRUE"); ws.getRange2("S7").setValue("qwe"); ws.getRange2("S8").setValue(""); ws.getRange2("S9").setValue("2"); oParser = new parserFormula("MIN(S5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!"); oParser = new parserFormula("MIN(S6)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("MIN(S7)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("MIN(S8)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("MIN(S5:S9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!"); oParser = new parserFormula("MIN(S6:S9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula("MIN(2, TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); testArrayFormula2(assert, "min", 1, 8, null, true); }); QUnit.test("Test: \"MINA\"", function (assert) { ws.getRange2("S5").setValue("1"); ws.getRange2("S6").setValue(numDivFact(-1, 2)); ws.getRange2("S7").setValue(numDivFact(1, 4)); ws.getRange2("S8").setValue(numDivFact(-1, 6)); oParser = new parserFormula("MINA(S5:S8)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -1 / Math.fact(2)); ws.getRange2("S5").setValue("#DIV/0!"); ws.getRange2("S6").setValue("TRUE"); ws.getRange2("S7").setValue("qwe"); ws.getRange2("S8").setValue(""); ws.getRange2("S9").setValue("2"); oParser = new parserFormula("MINA(S5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!"); oParser = new parserFormula("MINA(S6)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("MINA(S7)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("MINA(S8)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("MINA(S5:S9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!"); oParser = new parserFormula("MINA(S6:S9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("MINA(2, TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); testArrayFormula2(assert, "mina", 1, 8, null, true); }); QUnit.test("Test: SUM(S7:S9,{1,2,3})", function (assert) { ws.getRange2("S7").setValue("1"); ws.getRange2("S8").setValue("2"); ws.getRange2("S9").setValue("3"); oParser = new parserFormula("SUM(S7:S9,{1,2,3})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 12); }); QUnit.test("Test: ISREF", function (assert) { oParser = new parserFormula("ISREF(G0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "FALSE"); testArrayFormula2(assert, "ISREF", 1, 1, null, true); }); QUnit.test("Test: ISTEXT", function (assert) { ws.getRange2("S7").setValue("test"); oParser = new parserFormula("ISTEXT(S7)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TRUE"); testArrayFormula2(assert, "ISTEXT", 1, 1); }); QUnit.test("Test: MOD", function (assert) { oParser = new parserFormula("MOD(7,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("MOD(-10,5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("MOD(-9,5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("MOD(-8,5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula("MOD(-7,5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); oParser = new parserFormula("MOD(-6,5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); oParser = new parserFormula("MOD(-5,5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("MOD(10,5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("MOD(9,5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); oParser = new parserFormula("MOD(8,5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); oParser = new parserFormula("MOD(15,5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("MOD(15,0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!"); testArrayFormula2(assert, "MOD", 2, 2); }); QUnit.test("Test: rename sheet #1", function (assert) { wb.dependencyFormulas.unlockRecal(); ws.getRange2("S95").setValue("2"); ws.getRange2("S100").setValue("=" + wb.getWorksheet(0).getName() + "!S95"); ws.setName("SheetTmp"); assert.strictEqual(ws.getCell2("S100").getFormula(), ws.getName() + "!S95"); wb.dependencyFormulas.lockRecal(); }); QUnit.test("Test: wrong ref", function (assert) { oParser = new parserFormula("1+XXX1", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NAME?"); }); QUnit.test("Test: \"CODE\"", function (assert) { oParser = new parserFormula("CODE(\"abc\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 97); oParser = new parserFormula("CODE(TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 84); testArrayFormula2(assert, "CODE", 1, 1); }); QUnit.test("Test: \"CHAR\"", function (assert) { oParser = new parserFormula("CHAR(97)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "a"); testArrayFormula2(assert, "CHAR", 1, 1); }); QUnit.test("Test: \"CHAR(CODE())\"", function (assert) { oParser = new parserFormula("CHAR(CODE(\"A\"))", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "A"); }); QUnit.test("Test: \"PROPER\"", function (assert) { oParser = new parserFormula("PROPER(\"2-cent's worth\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "2-Cent'S Worth"); oParser = new parserFormula("PROPER(\"76BudGet\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "76Budget"); oParser = new parserFormula("PROPER(\"this is a TITLE\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "This Is A Title"); oParser = new parserFormula('PROPER(TRUE)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "True"); testArrayFormula2(assert, "PROPER", 1, 1); }); QUnit.test("Test: \"GCD\"", function (assert) { oParser = new parserFormula("GCD(10,100,50)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 10); oParser = new parserFormula("GCD(24.6,36.2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 12); oParser = new parserFormula("GCD(-1,39,52)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); testArrayFormula2(assert, "GCD", 1, 8, null, true); }); QUnit.test("Test: \"FIXED\"", function (assert) { oParser = new parserFormula("FIXED(1234567,-3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "1,235,000"); oParser = new parserFormula("FIXED(.555555,10)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "0.5555550000"); oParser = new parserFormula("FIXED(1234567.555555,4,TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "1234567.5556"); oParser = new parserFormula("FIXED(1234567)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "1,234,567.00"); testArrayFormula2(assert, "FIXED", 2, 3); }); QUnit.test("Test: \"REPLACE\"", function (assert) { oParser = new parserFormula("REPLACE(\"abcdefghijk\",3,4,\"XY\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "abXYghijk"); oParser = new parserFormula("REPLACE(\"abcdefghijk\",3,1,\"12345\")", "B2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "ab12345defghijk"); oParser = new parserFormula("REPLACE(\"abcdefghijk\",15,4,\"XY\")", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "abcdefghijkXY"); testArrayFormula2(assert, "REPLACE", 4, 4); }); QUnit.test("Test: \"SEARCH\"", function (assert) { let array; oParser = new parserFormula("SEARCH(\"~*\",\"abc*dEF\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); oParser = new parserFormula("SEARCH(\"~\",\"abc~dEF\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); oParser = new parserFormula("SEARCH(\"de\",\"abcdEF\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); oParser = new parserFormula("SEARCH(\"?c*e\",\"abcdEF\")", "B2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula("SEARCH(\"de\",\"dEFabcdEF\",3)", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 7); oParser = new parserFormula("SEARCH(\"de\",\"dEFabcdEF\",30)", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("SEARCH(\"pe\",\"dEFabcdEF\",2)", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("SEARCH(\"de\",\"dEFabcdEF\",2)", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 7); oParser = new parserFormula("SEARCH(\"de\",\"dEFabcdEF\",0)", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("SEARCH(\"de\",\"dEFabcdEF\",-2)", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); // bool oParser = new parserFormula('SEARCH("a", "abcde", FALSE)', "C2", ws); assert.ok(oParser.parse(), 'SEARCH("a", "abcde", FALSE)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of SEARCH("a", "abcde", FALSE)'); oParser = new parserFormula('SEARCH("a", "abcde", TRUE)', "C2", ws); assert.ok(oParser.parse(), 'SEARCH("a", "abcde", TRUE)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of SEARCH("a", "abcde", TRUE)'); oParser = new parserFormula('SEARCH(FALSE,"abc10dTRUEFALSE")', "C2", ws); assert.ok(oParser.parse(), 'SEARCH(FALSE,"abc10dTRUEFALSE")'); assert.strictEqual(oParser.calculate().getValue(), 11, 'Result of SEARCH(FALSE,"abc10dTRUEFALSE")'); oParser = new parserFormula('SEARCH(TRUE,"abc10dTRUEFALSE")', "C2", ws); assert.ok(oParser.parse(), 'SEARCH(TRUE,"abc10dTRUEFALSE")'); assert.strictEqual(oParser.calculate().getValue(), 7, 'Result of SEARCH(TRUE,"abc10dTRUEFALSE")'); oParser = new parserFormula('SEARCH("T",TRUE)', "C2", ws); assert.ok(oParser.parse(), 'SEARCH("T",TRUE)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of SEARCH("T",TRUE)'); oParser = new parserFormula('SEARCH("F",FALSE)', "C2", ws); assert.ok(oParser.parse(), 'SEARCH("F",FALSE)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of SEARCH("F",FALSE)'); // err oParser = new parserFormula('SEARCH(#N/A, "abcde", 1)', "C2", ws); assert.ok(oParser.parse(), 'SEARCH(#N/A, "abcde", 1)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of SEARCH(#N/A, "abcde", 1)'); oParser = new parserFormula('SEARCH("abcde", #DIV/0!, 1)', "C2", ws); assert.ok(oParser.parse(), 'SEARCH("abcde", #DIV/0!, 1)'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of SEARCH("abcde", #DIV/0!, 1)'); oParser = new parserFormula('SEARCH("abcde","a",#NUM!)', "C2", ws); assert.ok(oParser.parse(), 'SEARCH("abcde","a",#NUM!)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of SEARCH("abcde","a",#NUM!)'); oParser = new parserFormula('SEARCH(#N/A,"a",#NUM!)', "C2", ws); assert.ok(oParser.parse(), 'SEARCH(#N/A,"a",#NUM!)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of SEARCH(#N/A,"a",#NUM!)'); oParser = new parserFormula('SEARCH("abcde",#DIV/0!,#NUM!)', "C2", ws); assert.ok(oParser.parse(), 'SEARCH("abcde",#DIV/0!,#NUM!)'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of SEARCH("abcde",#DIV/0!,#NUM!)'); oParser = new parserFormula('SEARCH({5;6;7;1;2;3;4},123)', "K4", ws); oParser.setArrayFormulaRef(ws.getRange2("K4:K10").bbox); assert.ok(oParser.parse(), 'SEARCH({5;6;7;1;2;3;4},123)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", 'Result of SEARCH({5;6;7;1;2;3;4},123)[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", 'Result of SEARCH({5;6;7;1;2;3;4},123)[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#VALUE!", 'Result of SEARCH({5;6;7;1;2;3;4},123)[2,0]'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 1, 'Result of SEARCH({5;6;7;1;2;3;4},123)[3,0]'); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 2, 'Result of SEARCH({5;6;7;1;2;3;4},123)[4,0]'); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 3, 'Result of SEARCH({5;6;7;1;2;3;4},123)[5,0]'); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), "#VALUE!", 'Result of SEARCH({5;6;7;1;2;3;4},123)[6,0]'); ws.getRange2("K1").setValue("hcd*prd"); ws.getRange2("L1").setValue("*vmwprd*"); ws.getRange2("M1").setValue("*vmcprd*"); oParser = new parserFormula('SEARCH({"hcd*prd","*vmwprd*","*vmcprd*"},K1:M2)', "K4", ws); oParser.setArrayFormulaRef(ws.getRange2("K4:M4").bbox); assert.ok(oParser.parse(), 'SEARCH({"hcd*prd","*vmwprd*","*vmcprd*"},K1:M2)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", 'Result of SEARCH({"hcd*prd","*vmwprd*","*vmcprd*"},K1:M2)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", 'Result of SEARCH({"hcd*prd","*vmwprd*","*vmcprd*"},K1:M2)[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#VALUE!", 'Result of SEARCH({"hcd*prd","*vmwprd*","*vmcprd*"},K1:M2)[0,2]'); oParser = new parserFormula('SEARCH({"hcd*prd","*vmwprd*","*vmcprd*"},{"hcdpmhatlvmctst71a";"dsdsvmwprd";"hcdpmhatlvmcprd71a";"hcd*prd*vmwprd**vmcprd*"})', "K4", ws); oParser.setArrayFormulaRef(ws.getRange2("K4:M7").bbox); assert.ok(oParser.parse(), 'SEARCH({"hcd*prd","*vmwprd*","*vmcprd*"},{"hcdpmhatlvmctst71a";"dsdsvmwprd";"hcdpmhatlvmcprd71a";"hcd*prd*vmwprd**vmcprd*"})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", 'Result of SEARCH({"hcd*prd","*vmwprd*","*vmcprd*"},{"hcdpmhatlvmctst71a";"dsdsvmwprd";"hcdpmhatlvmcprd71a";"hcd*prd*vmwprd**vmcprd*"})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", 'Result of SEARCH({"hcd*prd","*vmwprd*","*vmcprd*"},{"hcdpmhatlvmctst71a";"dsdsvmwprd";"hcdpmhatlvmcprd71a";"hcd*prd*vmwprd**vmcprd*"})[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#VALUE!", 'Result of SEARCH({"hcd*prd","*vmwprd*","*vmcprd*"},{"hcdpmhatlvmctst71a";"dsdsvmwprd";"hcdpmhatlvmcprd71a";"hcd*prd*vmwprd**vmcprd*"})[0,2]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", 'Result of SEARCH({"hcd*prd","*vmwprd*","*vmcprd*"},{"hcdpmhatlvmctst71a";"dsdsvmwprd";"hcdpmhatlvmcprd71a";"hcd*prd*vmwprd**vmcprd*"})[0,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 1, 'Result of SEARCH({"hcd*prd","*vmwprd*","*vmcprd*"},{"hcdpmhatlvmctst71a";"dsdsvmwprd";"hcdpmhatlvmcprd71a";"hcd*prd*vmwprd**vmcprd*"})[0,1]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "#VALUE!", 'Result of SEARCH({"hcd*prd","*vmwprd*","*vmcprd*"},{"hcdpmhatlvmctst71a";"dsdsvmwprd";"hcdpmhatlvmcprd71a";"hcd*prd*vmwprd**vmcprd*"})[0,2]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 1, 'Result of SEARCH({"hcd*prd","*vmwprd*","*vmcprd*"},{"hcdpmhatlvmctst71a";"dsdsvmwprd";"hcdpmhatlvmcprd71a";"hcd*prd*vmwprd**vmcprd*"})[0,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#VALUE!", 'Result of SEARCH({"hcd*prd","*vmwprd*","*vmcprd*"},{"hcdpmhatlvmctst71a";"dsdsvmwprd";"hcdpmhatlvmcprd71a";"hcd*prd*vmwprd**vmcprd*"})[0,1]'); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), 1, 'Result of SEARCH({"hcd*prd","*vmwprd*","*vmcprd*"},{"hcdpmhatlvmctst71a";"dsdsvmwprd";"hcdpmhatlvmcprd71a";"hcd*prd*vmwprd**vmcprd*"})[0,2]'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 1, 'Result of SEARCH({"hcd*prd","*vmwprd*","*vmcprd*"},{"hcdpmhatlvmctst71a";"dsdsvmwprd";"hcdpmhatlvmcprd71a";"hcd*prd*vmwprd**vmcprd*"})[0,0]'); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), 1, 'Result of SEARCH({"hcd*prd","*vmwprd*","*vmcprd*"},{"hcdpmhatlvmctst71a";"dsdsvmwprd";"hcdpmhatlvmcprd71a";"hcd*prd*vmwprd**vmcprd*"})[0,1]'); assert.strictEqual(array.getElementRowCol(3, 2).getValue(), 1, 'Result of SEARCH({"hcd*prd","*vmwprd*","*vmcprd*"},{"hcdpmhatlvmctst71a";"dsdsvmwprd";"hcdpmhatlvmcprd71a";"hcd*prd*vmwprd**vmcprd*"})[0,2]'); ws.getRange2("A1").setValue("hcdpmhatlvmctst71a"); ws.getRange2("A2").setValue("pmhwebvmwtst01"); ws.getRange2("B1").setValue("sd"); ws.getRange2("B2").setValue("dd"); // array|area let bbox = ws.getRange2("K4").bbox; let cellWithFormula = new window['AscCommonExcel'].CCellWithFormula(ws, bbox.r1, bbox.c1); oParser = new parserFormula('SEARCH({"hcd*prd","*vmwprd*","*vmcprd*"},K1:M1)', cellWithFormula, ws); oParser.setArrayFormulaRef(ws.getRange2("K4:M4").bbox); assert.ok(oParser.parse(), 'SEARCH({"hcd*prd","*vmwprd*","*vmcprd*"},K1:M1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of SEARCH({"hcd*prd","*vmwprd*","*vmcprd*"},K1:M1)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", 'Result of SEARCH({"hcd*prd","*vmwprd*","*vmcprd*"},K1:M1)[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#VALUE!", 'Result of SEARCH({"hcd*prd","*vmwprd*","*vmcprd*"},K1:M1)[0,2]'); bbox = ws.getRange2("D1:F2").bbox; cellWithFormula = new window['AscCommonExcel'].CCellWithFormula(ws, bbox.r1, bbox.c1); oParser = new parserFormula('SEARCH({"*vmwtst*","hcd*tst","*vmctst*"}, A1:A2)', cellWithFormula, ws); oParser.setArrayFormulaRef(ws.getRange2("D1:F2").bbox); assert.ok(oParser.parse(), 'SEARCH({"*vmwtst*","hcd*tst","*vmctst*"}, A1:A2)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", 'Result of SEARCH({"*vmwtst*","hcd*tst","*vmctst*"}, A1:A2)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, 'Result of SEARCH({"*vmwtst*","hcd*tst","*vmctst*"}, A1:A2)[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 1, 'Result of SEARCH({"*vmwtst*","hcd*tst","*vmctst*"}, A1:A2)[0,2]'); bbox = ws.getRange2("E1").bbox; cellWithFormula = new window['AscCommonExcel'].CCellWithFormula(ws, bbox.r1, bbox.c1); oParser = new parserFormula('SEARCH({"*vmwtst*","hcd*tst","*vmctst*"}, A1:A2)', cellWithFormula, ws); oParser.setArrayFormulaRef(ws.getRange2("D1:F2").bbox); assert.ok(oParser.parse(), 'SEARCH({"*vmwtst*","hcd*tst","*vmctst*"}, A1:A2)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", 'Result of SEARCH({"*vmwtst*","hcd*tst","*vmctst*"}, A1:A2)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, 'Result of SEARCH({"*vmwtst*","hcd*tst","*vmctst*"}, A1:A2)[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 1, 'Result of SEARCH({"*vmwtst*","hcd*tst","*vmctst*"}, A1:A2)[0,2]'); bbox = ws.getRange2("D1:F2").bbox; cellWithFormula = new window['AscCommonExcel'].CCellWithFormula(ws, bbox.r1, bbox.c1); oParser = new parserFormula('SEARCH({"*vmwtst*","hcd*tst","*vmctst*"}, A1:B2)', cellWithFormula, ws); oParser.setArrayFormulaRef(ws.getRange2("D1:F2").bbox); assert.ok(oParser.parse(), 'SEARCH({"*vmwtst*","hcd*tst","*vmctst*"}, A1:B2)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", 'Result of SEARCH({"*vmwtst*","hcd*tst","*vmctst*"}, A1:B2)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", 'Result of SEARCH({"*vmwtst*","hcd*tst","*vmctst*"}, A1:B2)[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#VALUE!", 'Result of SEARCH({"*vmwtst*","hcd*tst","*vmctst*"}, A1:B2)[0,2]'); ws.getRange2("A3:A5").cleanAll(); bbox = ws.getRange2("D1:F5").bbox; cellWithFormula = new window['AscCommonExcel'].CCellWithFormula(ws, bbox.r1, bbox.c1); oParser = new parserFormula('SEARCH({"mhat","vmc"}, A1:A5)', cellWithFormula, ws); oParser.setArrayFormulaRef(ws.getRange2("D1:F5").bbox); assert.ok(oParser.parse(), 'SEARCH({"mhat","vmc"}, A1:A5)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 5, 'Result of SEARCH({"mhat","vmc"}, A1:A5)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 10, 'Result of SEARCH({"mhat","vmc"}, A1:A5)[0,1]'); ws.getRange2("S1").setValue("hcd*tst"); ws.getRange2("S2").setValue("2"); ws.getRange2("T1").setValue("#DIV/0!"); ws.getRange2("T2").setValue("*vmwtst*"); ws.getRange2("U1").setValue("1"); ws.getRange2("U2").setValue("*vmctst*"); oParser = new parserFormula('SEARCH(S1:U2,A1:A2)', cellWithFormula, ws); oParser.setArrayFormulaRef(ws.getRange2("D1:F5").bbox); assert.ok(oParser.parse(), 'SEARCH(S1:U2,A1:A2)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of SEARCH(S1:U2,A1:A2)'); oParser = new parserFormula('SEARCH(S1:U2,"hcdpmh71")', cellWithFormula, ws); oParser.setArrayFormulaRef(ws.getRange2("D1:F5").bbox); assert.ok(oParser.parse(), 'SEARCH(S1:U2,"hcdpmh71")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of SEARCH(S1:U2,"hcdpmh71")'); oParser = new parserFormula('SEARCH("hcd",A1:A2)', cellWithFormula, ws); oParser.setArrayFormulaRef(ws.getRange2("D1:F5").bbox); assert.ok(oParser.parse(), 'SEARCH("hcd",A1:A2)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of SEARCH("hcd",A1:A2)[0,0]'); // testArrayFormula2(assert, "SEARCH", 2, 3); }); QUnit.test("Test: \"SUBSTITUTE\"", function (assert) { oParser = new parserFormula("SUBSTITUTE(\"abcaAabca\",\"a\",\"xx\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "xxbcxxAxxbcxx"); oParser = new parserFormula("SUBSTITUTE(\"abcaaabca\",\"a\",\"xx\")", "B2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "xxbcxxxxxxbcxx"); oParser = new parserFormula("SUBSTITUTE(\"abcaaabca\",\"a\",\"\",10)", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "bcbc"); oParser = new parserFormula("SUBSTITUTE(\"abcaaabca\",\"a\",\"xx\",3)", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "abcaxxabca"); testArrayFormula2(assert, "SUBSTITUTE", 3, 4); }); QUnit.test("Test: \"SHEET\"", function (assert) { oParser = new parserFormula("SHEET(Hi_Temps)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NAME?"); testArrayFormula2(assert, "SHEET", 1, 1, null, true); }); QUnit.test("Test: \"SHEETS\"", function (assert) { oParser = new parserFormula("SHEETS(Hi_Temps)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NAME?"); oParser = new parserFormula("SHEETS()", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); testArrayFormula2(assert, "SHEETS", 1, 1, null, true); }); QUnit.test("Test: \"TRIM\"", function (assert) { oParser = new parserFormula("TRIM(\" abc def \")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "abc def"); oParser = new parserFormula("TRIM(\" First Quarter Earnings \")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "First Quarter Earnings"); testArrayFormula2(assert, "TRIM", 1, 1); }); QUnit.test("Test: \"TRIMMEAN\"", function (assert) { ws.getRange2("A2").setValue("4"); ws.getRange2("A3").setValue("5"); ws.getRange2("A4").setValue("6"); ws.getRange2("A5").setValue("7"); ws.getRange2("A6").setValue("2"); ws.getRange2("A7").setValue("3"); ws.getRange2("A8").setValue("4"); ws.getRange2("A9").setValue("5"); ws.getRange2("A10").setValue("1"); ws.getRange2("A11").setValue("2"); ws.getRange2("A12").setValue("3"); oParser = new parserFormula("TRIMMEAN(A2:A12,0.2)", "A1", ws); assert.ok(oParser.parse(), "TRIMMEAN(A2:A12,0.2)"); assert.strictEqual(oParser.calculate().getValue().toFixed(3) - 0, 3.778, "TRIMMEAN(A2:A12,0.2)"); //TODO нужна другая функция для тестирования //testArrayFormula2(assert, "TRIMMEAN", 2, 2); }); QUnit.test("Test: \"DOLLAR\"", function (assert) { oParser = new parserFormula("DOLLAR(1234.567)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "$1,234.57"); oParser = new parserFormula("DOLLAR(1234.567,-2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "$1,200"); oParser = new parserFormula("DOLLAR(-1234.567,4)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "($1,234.5670)"); oParser = new parserFormula("DOLLAR(-1234.567,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "($1,235)"); //set russia locale window["Asc"]["editor"].asc_setLocale(1049); oParser = new parserFormula("DOLLAR(1234.567)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "1 234,57 ₽"); oParser = new parserFormula("DOLLAR(1234.567,-2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "1 200 ₽"); oParser = new parserFormula("DOLLAR(-1234.567,4)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "-1 234,5670 ₽"); oParser = new parserFormula("DOLLAR(-1234.567,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "-1 235 ₽"); //set default locale window["Asc"]["editor"].asc_setLocale(1033); testArrayFormula2(assert, "DOLLAR", 2, 2); }); QUnit.test("Test: \"EXACT\"", function (assert) { ws.getRange2("A2").setValue("word"); ws.getRange2("A3").setValue("Word"); ws.getRange2("A4").setValue("w ord"); ws.getRange2("B2").setValue("word"); ws.getRange2("B3").setValue("word"); ws.getRange2("B4").setValue("word"); oParser = new parserFormula("EXACT(A2,B2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TRUE"); oParser = new parserFormula("EXACT(A3,B3)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "FALSE"); oParser = new parserFormula("EXACT(A4,B4)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "FALSE"); oParser = new parserFormula("EXACT(TRUE,TRUE)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TRUE"); oParser = new parserFormula('EXACT("TRUE",TRUE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TRUE"); oParser = new parserFormula('EXACT("TRUE","TRUE")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TRUE"); oParser = new parserFormula('EXACT("true",TRUE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "FALSE"); testArrayFormula2(assert, "EXACT", 2, 2); }); QUnit.test("Test: \"LEFT\"", function (assert) { ws.getRange2("A2").setValue("Sale Price"); ws.getRange2("A3").setValue("Sweden"); oParser = new parserFormula("LEFT(A2,4)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "Sale"); oParser = new parserFormula("LEFT(A3)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "S"); testArrayFormula2(assert, "LEFT", 1, 2); }); QUnit.test("Test: \"LEN\"", function (assert) { ws.getRange2("A201").setValue("Phoenix, AZ"); ws.getRange2("A202").setValue(""); ws.getRange2("A203").setValue(" One "); oParser = new parserFormula("LEN(A201)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 11); oParser = new parserFormula("LEN(A202)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("LEN(A203)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 11); oParser = new parserFormula('LEN(TRUE)', "A2", ws); assert.ok(oParser.parse(), 'LEN(TRUE)'); assert.strictEqual(oParser.calculate().getValue(), 4, 'LEN(TRUE)'); testArrayFormula2(assert, "LEN", 1, 1); }); QUnit.test("Test: \"REPT\"", function (assert) { oParser = new parserFormula('REPT("*-", 3)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "*-*-*-"); oParser = new parserFormula('REPT("-",10)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "----------"); testArrayFormula2(assert, "REPT", 2, 2); }); QUnit.test("Test: \"RIGHT\"", function (assert) { ws.getRange2("A2").setValue("Sale Price"); ws.getRange2("A3").setValue("Stock Number"); oParser = new parserFormula("RIGHT(A2,5)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "Price"); oParser = new parserFormula("RIGHT(A3)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "r"); testArrayFormula2(assert, "RIGHT", 1, 2); }); QUnit.test("Test: \"VALUE\"", function (assert) { oParser = new parserFormula("VALUE(\"123.456\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 123.456); oParser = new parserFormula("VALUE(\"$1,000\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1000); oParser = new parserFormula("VALUE(\"23-Mar-2002\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 37338); oParser = new parserFormula("VALUE(\"03-26-2006\")", "A2", ws); assert.ok(oParser.parse()); if (AscCommon.bDate1904) { assert.strictEqual(oParser.calculate().getValue(), 37340); } else { assert.strictEqual(oParser.calculate().getValue(), 38802); } oParser = new parserFormula("VALUE(\"16:48:00\")-VALUE(\"12:17:12\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), AscCommon.g_oFormatParser.parse("16:48:00").value - AscCommon.g_oFormatParser.parse("12:17:12").value); testArrayFormula2(assert, "value", 1, 1); }); QUnit.test("Test: \"DATE\"", function (assert) { testArrayFormula2(assert, "DATE", 3, 3); }); QUnit.test("Test: \"DATEVALUE\"", function (assert) { oParser = new parserFormula("DATEVALUE(\"10-10-2010 10:26\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 40461); oParser = new parserFormula("DATEVALUE(\"10-10-2010 10:26\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 40461); tmp = ws.getRange2("A7"); tmp.setNumFormat('@'); tmp.setValue("3-Mar"); oParser = new parserFormula("DATEVALUE(A7)", "A2", ws); assert.ok(oParser.parse()); var d = new cDate(); d.setUTCMonth(2); d.setUTCDate(3); assert.strictEqual(oParser.calculate().getValue(), d.getExcelDate()); oParser = new parserFormula("DATEVALUE(\"$1,000\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("DATEVALUE(\"23-Mar-2002\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 37338); oParser = new parserFormula("DATEVALUE(\"03-26-2006\")", "A2", ws); assert.ok(oParser.parse()); if (AscCommon.bDate1904) { assert.strictEqual(oParser.calculate().getValue(), 37340); } else { assert.strictEqual(oParser.calculate().getValue(), 38802); } testArrayFormula(assert, "DATEVALUE"); }); QUnit.test("Test: \"EDATE\"", function (assert) { let array; // base mode ws.workbook.setDate1904(false, true); oParser = new parserFormula("EDATE(DATE(2006,1,31),5)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(DATE(2006,1,31),5)'); assert.strictEqual(oParser.calculate().getValue(), 38898, 'Result of EDATE(DATE(2006,1,31),5)'); oParser = new parserFormula("EDATE(DATE(2004,2,29),12)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(DATE(2004,2,29),12)'); assert.strictEqual(oParser.calculate().getValue(), 38411, 'Result of EDATE(DATE(2004,2,29),12)'); ws.getRange2("A7").setValue("02-28-2004"); oParser = new parserFormula("EDATE(A7,12)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(A7,12)'); assert.strictEqual(oParser.calculate().getValue(), 38411, 'Result of EDATE(A7,12)'); oParser = new parserFormula("EDATE(DATE(2004,1,15),-23)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(DATE(2004,1,15),-23)'); assert.strictEqual(oParser.calculate().getValue(), 37302, 'Result of EDATE(DATE(2004,1,15),-23)'); oParser = new parserFormula("EDATE(DATE(2000,1,30),1)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(DATE(2000,1,30),1)'); assert.strictEqual(oParser.calculate().getValue(), 36585, 'Result of EDATE(DATE(2000,1,30),1)'); oParser = new parserFormula("EDATE(DATE(2001,1,30),1)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(DATE(2001,1,30),1)'); assert.strictEqual(oParser.calculate().getValue(), 36950, 'Result of EDATE(DATE(2001,1,30),1)'); oParser = new parserFormula("EDATE(DATE(2002,1,30),1)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(DATE(2002,1,30),1)'); assert.strictEqual(oParser.calculate().getValue(), 37315, 'Result of EDATE(DATE(2002,1,30),1)'); oParser = new parserFormula("EDATE(DATE(2003,1,30),1)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(DATE(2003,1,30),1)'); assert.strictEqual(oParser.calculate().getValue(), 37680, 'Result of EDATE(DATE(2003,1,30),1)'); oParser = new parserFormula("EDATE(DATE(2004,1,30),1)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(DATE(2004,1,30),1)'); assert.strictEqual(oParser.calculate().getValue(), 38046, 'Result of EDATE(DATE(2004,1,30),1)'); oParser = new parserFormula("EDATE(0,0)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(0,0)'); assert.strictEqual(oParser.calculate().getValue(), 0, 'Result of EDATE(0,0)'); oParser = new parserFormula("EDATE(0,1)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(0,1)'); assert.strictEqual(oParser.calculate().getValue(), 32, 'Result of EDATE(0,1)'); // 31 oParser = new parserFormula("EDATE(1,1)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(1,1)'); assert.strictEqual(oParser.calculate().getValue(), 33, 'Result of EDATE(1,1)'); // 32 oParser = new parserFormula("EDATE(2,1)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(2,1)'); assert.strictEqual(oParser.calculate().getValue(), 34, 'Result of EDATE(2,1)'); // 33 oParser = new parserFormula("EDATE(10,1)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(10,1)'); assert.strictEqual(oParser.calculate().getValue(), 42, 'Result of EDATE(10,1)'); // 41 oParser = new parserFormula("EDATE(30,1)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(30,1)'); assert.strictEqual(oParser.calculate().getValue(), 60, 'Result of EDATE(30,1)'); // 59 oParser = new parserFormula("EDATE(59,1)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(59,1)'); assert.strictEqual(oParser.calculate().getValue(), 88, 'Result of EDATE(59,1)'); oParser = new parserFormula("EDATE(60,1)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(60,1)'); assert.strictEqual(oParser.calculate().getValue(), 92, 'Result of EDATE(60,1)'); // 89 oParser = new parserFormula("EDATE(61,1)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(61,1)'); assert.strictEqual(oParser.calculate().getValue(), 92, 'Result of EDATE(61,1)'); // 92 oParser = new parserFormula("EDATE(0,-1)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(0,-1)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of EDATE(0,-1)'); oParser = new parserFormula("EDATE(0,-2)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(0,-2)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of EDATE(0,-2)'); oParser = new parserFormula("EDATE(-1,1)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(-1,1)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of EDATE(-1,1)'); oParser = new parserFormula("EDATE(100,)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(100,)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of EDATE(100,)'); oParser = new parserFormula("EDATE(,100)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(,100)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of EDATE(,100)'); oParser = new parserFormula("EDATE(0,10)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(0,10)'); assert.strictEqual(oParser.calculate().getValue(), 305, 'Result of EDATE(0,10)'); // 305 oParser = new parserFormula("EDATE(1,10)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(1,10)'); assert.strictEqual(oParser.calculate().getValue(), 306, 'Result of EDATE(1,10)'); // 306 // strings oParser = new parserFormula('EDATE("100",1)', "A2", ws); assert.ok(oParser.parse(), 'EDATE("100",1)'); assert.strictEqual(oParser.calculate().getValue(), 130, 'Result of EDATE("100",1)'); oParser = new parserFormula('EDATE("100s",1)', "A2", ws); assert.ok(oParser.parse(), 'EDATE("100s",1)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of EDATE("100s",1)'); oParser = new parserFormula('EDATE("100","1")', "A2", ws); assert.ok(oParser.parse(), 'EDATE("100","1")'); assert.strictEqual(oParser.calculate().getValue(), 130, 'Result of EDATE("100","1")'); oParser = new parserFormula('EDATE("100","1s")', "A2", ws); assert.ok(oParser.parse(), 'EDATE("100","1s")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of EDATE("100","1s")'); // bool oParser = new parserFormula("EDATE(TRUE,1)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(TRUE,1)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of EDATE(TRUE,1)'); oParser = new parserFormula("EDATE(FALSE,1)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(FALSE,1)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of EDATE(FALSE,1)'); oParser = new parserFormula("EDATE(1,TRUE)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(1,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of EDATE(1,TRUE)'); oParser = new parserFormula("EDATE(1,FALSE)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(1,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of EDATE(1,FALSE)'); oParser = new parserFormula("EDATE(TRUE,TRUE)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(TRUE,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of EDATE(TRUE,TRUE)'); // err oParser = new parserFormula("EDATE(#N/A,#NUM!)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(#N/A,#NUM!)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of EDATE(#N/A,#NUM!)'); oParser = new parserFormula("EDATE(#DIV/0!,#NUM!)", "A2", ws); assert.ok(oParser.parse(), 'EDATE(#DIV/0!,#NUM!)'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of EDATE(#DIV/0!,#NUM!)'); // arr oParser = new parserFormula('EDATE({100;101;102},1)', "A2", ws); assert.ok(oParser.parse(), 'EDATE({100;101;102},1)'); assert.strictEqual(oParser.calculate().getValue(), 130, 'Result of EDATE({100;101;102},1)'); oParser = new parserFormula('EDATE(100,{1;2;3})', "A2", ws); assert.ok(oParser.parse(), 'EDATE(100,{1;2;3})'); assert.strictEqual(oParser.calculate().getValue(), 130, 'Result of EDATE(100,{1;2;3})'); oParser = new parserFormula('EDATE({100;100;100},{1;2;3})', "A2", ws); assert.ok(oParser.parse(), 'EDATE({100;100;100},{1;2;3})'); assert.strictEqual(oParser.calculate().getValue(), 130, 'Result of EDATE({100;100;100},{1;2;3})'); oParser = new parserFormula('EDATE({100;101;102},1)', "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("F106:I109").bbox); assert.ok(oParser.parse(), 'EDATE({100;101;102},1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 130, 'Result of EDATE({100;101;102},1)[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 131, 'Result of EDATE({100;101;102},1)[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 132, 'Result of EDATE({100;101;102},1)[2,0]'); oParser = new parserFormula('EDATE({100;100;100},{1;2;3})', "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("F106:I109").bbox); assert.ok(oParser.parse(), 'EDATE({100;100;100},{1;2;3})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 130, 'Result of EDATE({100;100;100},{1;2;3})[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 161, 'Result of EDATE({100;100;100},{1;2;3})[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 191, 'Result of EDATE({100;100;100},{1;2;3})[2,0]'); // range ws.getRange2("A100").setValue("100"); ws.getRange2("A101").setValue("101"); ws.getRange2("A102").setValue("102"); ws.getRange2("B100").setValue("1"); ws.getRange2("B101").setValue("2"); ws.getRange2("B102").setValue("3"); oParser = new parserFormula('EDATE(A100:A100,1)', "A2", ws); assert.ok(oParser.parse(), 'EDATE(A100:A100,1)'); assert.strictEqual(oParser.calculate().getValue(), 130, 'Result of EDATE(A100:A100,1)'); oParser = new parserFormula('EDATE(A100:A102,1)', "A2", ws); assert.ok(oParser.parse(), 'EDATE(A100:A102,1)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of EDATE(A100:A102,1)'); oParser = new parserFormula('EDATE(A100,B100:B100)', "A2", ws); assert.ok(oParser.parse(), 'EDATE(A100,B100:B100)'); assert.strictEqual(oParser.calculate().getValue(), 130, 'Result of EDATE(A100,B100:B100)'); oParser = new parserFormula('EDATE(A100,B100:B102)', "A2", ws); assert.ok(oParser.parse(), 'EDATE(A100,B100:B102)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of EDATE(A100,B100:B102)'); // 1904 mode ws.workbook.setDate1904(true, true); oParser = new parserFormula("EDATE(37286,5)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 37436); oParser = new parserFormula("EDATE(37286,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 37314); oParser = new parserFormula("EDATE(DATE(2004,2,29),12)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 36949); ws.getRange2("A7").setValue("02-28-2004"); oParser = new parserFormula("EDATE(A7,12)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 36949); oParser = new parserFormula("EDATE(DATE(2004,1,15),-23)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 35840); // return to base mode ws.workbook.setDate1904(false, true); testArrayFormula2(assert, "EDATE", 2, 2, true, null); }); QUnit.test("Test: \"EOMONTH\"", function (assert) { // base mode ws.workbook.setDate1904(false, true); oParser = new parserFormula("EOMONTH(0,1)", "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(0,1)'); assert.strictEqual(oParser.calculate().getValue(), 59, 'Result of EOMONTH(0,1)'); oParser = new parserFormula("EOMONTH(1,1)", "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(1,1)'); assert.strictEqual(oParser.calculate().getValue(), 59, 'Result of EOMONTH(1,1)'); oParser = new parserFormula("EOMONTH(2,1)", "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(2,1)'); assert.strictEqual(oParser.calculate().getValue(), 59, 'Result of EOMONTH(2,1)'); oParser = new parserFormula("EOMONTH(59,1)", "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(59,1)'); assert.strictEqual(oParser.calculate().getValue(), 91, 'Result of EOMONTH(59,1)'); oParser = new parserFormula("EOMONTH(60,1)", "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(60,1)'); assert.strictEqual(oParser.calculate().getValue(), 91, 'Result of EOMONTH(60,1)'); oParser = new parserFormula("EOMONTH(61,1)", "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(61,1)'); assert.strictEqual(oParser.calculate().getValue(), 121, 'Result of EOMONTH(61,1)'); oParser = new parserFormula("EOMONTH(62,1)", "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(62,1)'); assert.strictEqual(oParser.calculate().getValue(), 121, 'Result of EOMONTH(62,1)'); oParser = new parserFormula("EOMONTH(DATE(2006,1,31),5)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 38898); oParser = new parserFormula("EOMONTH(DATE(2004,2,29),12)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 38411); ws.getRange2("A7").setValue("02-28-2004"); oParser = new parserFormula("EOMONTH(A7,12)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 38411); oParser = new parserFormula("EOMONTH(DATE(2004,1,15),-23)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 37315); oParser = new parserFormula("EOMONTH(DATE(2018,3,16),10)", "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(DATE(2018,3,16),10)'); assert.strictEqual(oParser.calculate().getValue(), 43496, 'Result of EOMONTH(DATE(2018,3,16),10)'); // string oParser = new parserFormula('EOMONTH("43175","10")', "A2", ws); assert.ok(oParser.parse(), 'EOMONTH("43175","10")'); assert.strictEqual(oParser.calculate().getValue(), 43496, 'Result of EOMONTH("43175","10")'); oParser = new parserFormula('EOMONTH("43175+1","10")', "A2", ws); assert.ok(oParser.parse(), 'EOMONTH("43175+1","10")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of EOMONTH("43175+1","10")'); oParser = new parserFormula('EOMONTH("43175","10+1")', "A2", ws); assert.ok(oParser.parse(), 'EOMONTH("43175","10+1")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of EOMONTH("43175","10+1")'); // bool oParser = new parserFormula('EOMONTH(43175,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(43175,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of EOMONTH(43175,FALSE)'); oParser = new parserFormula('EOMONTH(43175,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(43175,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of EOMONTH(43175,TRUE)'); oParser = new parserFormula('EOMONTH(TRUE,1)', "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(TRUE,1)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of EOMONTH(TRUE,1)'); // err oParser = new parserFormula('EOMONTH(#N/A,1)', "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(#N/A,1)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of EOMONTH(#N/A,1)'); oParser = new parserFormula('EOMONTH(#N/A,#NUM!)', "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(#N/A,#NUM!)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of EOMONTH(#N/A,#NUM!)'); oParser = new parserFormula('EOMONTH(#NUM!,#N/A)', "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(#NUM!,#N/A)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of EOMONTH(#NUM!,#N/A)'); ws.getRange2("A100").setValue("44227.50069"); ws.getRange2("A101").setValue("44227.49861"); ws.getRange2("A102").setValue("44227.00069"); oParser = new parserFormula("EOMONTH(A100,0)", "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(A100,0)'); assert.strictEqual(oParser.calculate().getValue(), 44227, 'Result of EOMONTH(A100,0)'); oParser = new parserFormula("EOMONTH(A100,1.5)", "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(A100,1.5)'); assert.strictEqual(oParser.calculate().getValue(), 44255, 'Result of EOMONTH(A100,1.5)'); oParser = new parserFormula("EOMONTH(A100,-1.6)", "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(A100,-1.6)'); assert.strictEqual(oParser.calculate().getValue(), 44196, 'Result of EOMONTH(A100,-1.6)'); oParser = new parserFormula("EOMONTH(A101,0)", "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(A100,0)'); assert.strictEqual(oParser.calculate().getValue(), 44227, 'Result of EOMONTH(A100,0)'); oParser = new parserFormula("EOMONTH(A101,1.5)", "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(A101,1.5)'); assert.strictEqual(oParser.calculate().getValue(), 44255, 'Result of EOMONTH(A101,1.5)'); oParser = new parserFormula("EOMONTH(A101,-1.6)", "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(A101,-1.6)'); assert.strictEqual(oParser.calculate().getValue(), 44196, 'Result of EOMONTH(A102,-1.6)'); oParser = new parserFormula("EOMONTH(A102,0)", "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(A102,0)'); assert.strictEqual(oParser.calculate().getValue(), 44227, 'Result of EOMONTH(A102,0)'); oParser = new parserFormula("EOMONTH(A102,1.5)", "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(A102,1.5)'); assert.strictEqual(oParser.calculate().getValue(), 44255, 'Result of EOMONTH(A102,1.5)'); oParser = new parserFormula("EOMONTH(A102,-1.6)", "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(A102,-1.6)'); assert.strictEqual(oParser.calculate().getValue(), 44196, 'Result of EOMONTH(A102,-1.6)'); // set 1904 mode ws.workbook.setDate1904(true, true); oParser = new parserFormula("EOMONTH(0,1)", "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(0,1) 1904 mode'); assert.strictEqual(oParser.calculate().getValue(), 59, 'Result of EOMONTH(0,1) 1904 mode'); oParser = new parserFormula("EOMONTH(1,1)", "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(1,1) 1904 mode'); assert.strictEqual(oParser.calculate().getValue(), 59, 'Result of EOMONTH(1,1) 1904 mode'); oParser = new parserFormula("EOMONTH(2,1)", "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(2,1) 1904 mode'); assert.strictEqual(oParser.calculate().getValue(), 59, 'Result of EOMONTH(2,1) 1904 mode'); oParser = new parserFormula("EOMONTH(59,1)", "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(59,1) 1904 mode'); assert.strictEqual(oParser.calculate().getValue(), 90, 'Result of EOMONTH(59,1) 1904 mode'); oParser = new parserFormula("EOMONTH(60,1)", "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(60,1) 1904 mode'); assert.strictEqual(oParser.calculate().getValue(), 120, 'Result of EOMONTH(60,1) 1904 mode'); oParser = new parserFormula("EOMONTH(61,1)", "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(61,1) 1904 mode'); assert.strictEqual(oParser.calculate().getValue(), 120, 'Result of EOMONTH(61,1) 1904 mode'); oParser = new parserFormula("EOMONTH(DATE(2006,1,31),5)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 37436); oParser = new parserFormula("EOMONTH(DATE(2004,2,29),12)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 36949); ws.getRange2("A7").setValue("02-28-2004"); oParser = new parserFormula("EOMONTH(A7,12)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 36949); oParser = new parserFormula("EOMONTH(DATE(2004,1,15),-23)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 35853); oParser = new parserFormula("EOMONTH(0,1)", "A2", ws); assert.ok(oParser.parse(), 'EOMONTH(0,1)'); assert.strictEqual(oParser.calculate().getValue(), 59, 'Result of EOMONTH(0,1)'); // base mode ws.workbook.setDate1904(false, true); testArrayFormula2(assert, "EOMONTH", 2, 2, true, null); }); QUnit.test("Test: \"MONTH\"", function (assert) { ws.getRange2("A1:A15").cleanAll(); // base mode ws.workbook.setDate1904(false, true); // inline oParser = new parserFormula("MONTH(44469)", "A2", ws); assert.ok(oParser.parse(), "MONTH(30.09.21)"); assert.strictEqual(oParser.calculate().getValue(), 9, "Result of MONTH(30.09.21)"); oParser = new parserFormula("MONTH(44560)", "A2", ws); assert.ok(oParser.parse(), "MONTH(30.12.21)"); assert.strictEqual(oParser.calculate().getValue(), 12, "Result of MONTH(30.12.21)"); oParser = new parserFormula("MONTH(44561)", "A2", ws); assert.ok(oParser.parse(), "MONTH(31.12.21)"); assert.strictEqual(oParser.calculate().getValue(), 12, "Result of MONTH(31.12.21)"); oParser = new parserFormula("MONTH(44510)", "A2", ws); assert.ok(oParser.parse(), "MONTH(10.11.21)"); assert.strictEqual(oParser.calculate().getValue(), 11, "Result of MONTH(10.11.21)"); oParser = new parserFormula('MONTH("2021-10-01")', "A2", ws); assert.ok(oParser.parse(), 'MONTH("2021-10-01")'); assert.strictEqual(oParser.calculate().getValue(), 10, 'Result of MONTH("2021-10-01")'); oParser = new parserFormula('MONTH("2021-12-31")', "A2", ws); assert.ok(oParser.parse(), "MONTH('2021-12-31')"); assert.strictEqual(oParser.calculate().getValue(), 12, "Result of MONTH('2021-12-31')"); oParser = new parserFormula('MONTH("2021-09-30")', "A2", ws); assert.ok(oParser.parse(), "MONTH('2021-09-30')"); assert.strictEqual(oParser.calculate().getValue(), 9, "Result of MONTH('2021-09-30')"); oParser = new parserFormula('MONTH("2021-10-31")', "A2", ws); assert.ok(oParser.parse(), "MONTH('2021-10-31')"); assert.strictEqual(oParser.calculate().getValue(), 10, "Result of MONTH('2021-10-31')"); oParser = new parserFormula('MONTH("2021-12-29")', "A2", ws); assert.ok(oParser.parse(), "MONTH('2021-12-29')"); assert.strictEqual(oParser.calculate().getValue(), 12, "Result of MONTH('2021-12-29')"); oParser = new parserFormula('MONTH(0)', "A2", ws); assert.ok(oParser.parse(), "MONTH(0)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH(0)"); oParser = new parserFormula('MONTH("1s")', "A2", ws); assert.ok(oParser.parse(), "MONTH('1s')"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of MONTH('1s')"); oParser = new parserFormula('MONTH(TRUE)', "A2", ws); assert.ok(oParser.parse(), "MONTH(TRUE)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH(TRUE)"); oParser = new parserFormula('MONTH(FALSE)', "A2", ws); assert.ok(oParser.parse(), "MONTH(FALSE)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH(FALSE)"); oParser = new parserFormula('MONTH(#DIV/0!)', "A2", ws); assert.ok(oParser.parse(), "MONTH(#DIV/0!)"); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "Result of MONTH(#DIV/0!)"); // cell ws.getRange2("A1").setValue("44469"); ws.getRange2("A2").setValue("44560"); ws.getRange2("A3").setValue("44561"); ws.getRange2("A4").setValue("44510"); ws.getRange2("A5").setValue("2021-10-01"); ws.getRange2("A6").setValue("2021-12-31"); ws.getRange2("A7").setValue("2021-09-30"); ws.getRange2("A8").setValue("2021-10-31"); ws.getRange2("A9").setValue("2021-12-29"); ws.getRange2("A10").setValue("0"); ws.getRange2("A11").setValue("1s"); ws.getRange2("A12").setValue("TRUE"); ws.getRange2("A13").setValue("FALSE"); ws.getRange2("A14").setValue("#DIV/0!"); ws.getRange2("A15").setValue(""); oParser = new parserFormula("MONTH(A1)", "A2", ws); assert.ok(oParser.parse(), "MONTH(30.09.21)"); assert.strictEqual(oParser.calculate().getValue(), 9, "Result of MONTH(30.09.21)"); oParser = new parserFormula("MONTH(A2)", "A2", ws); assert.ok(oParser.parse(), "MONTH(30.12.21)"); assert.strictEqual(oParser.calculate().getValue(), 12, "Result of MONTH(30.12.21)"); oParser = new parserFormula("MONTH(A3)", "A2", ws); assert.ok(oParser.parse(), "MONTH(31.12.21)"); assert.strictEqual(oParser.calculate().getValue(), 12, "Result of MONTH(31.12.21)"); oParser = new parserFormula("MONTH(A4)", "A2", ws); assert.ok(oParser.parse(), "MONTH(10.11.21)"); assert.strictEqual(oParser.calculate().getValue(), 11, "Result of MONTH(10.11.21)"); oParser = new parserFormula("MONTH(A5)", "A2", ws); assert.ok(oParser.parse(), "MONTH('2021-10-01')"); assert.strictEqual(oParser.calculate().getValue(), 10, "Result of MONTH('2021-10-01')"); oParser = new parserFormula("MONTH(A6)", "A2", ws); assert.ok(oParser.parse(), "MONTH('2021-12-31')"); assert.strictEqual(oParser.calculate().getValue(), 12, "Result of MONTH('2021-12-31')"); oParser = new parserFormula("MONTH(A7)", "A2", ws); assert.ok(oParser.parse(), "MONTH('2021-09-30')"); assert.strictEqual(oParser.calculate().getValue(), 9, "Result of MONTH('2021-09-30')"); oParser = new parserFormula("MONTH(A8)", "A2", ws); assert.ok(oParser.parse(), "MONTH('2021-10-31')"); assert.strictEqual(oParser.calculate().getValue(), 10, "Result of MONTH('2021-10-31')"); oParser = new parserFormula("MONTH(A9)", "A2", ws); assert.ok(oParser.parse(), "MONTH('2021-12-29')"); assert.strictEqual(oParser.calculate().getValue(), 12, "Result of MONTH('2021-12-29')"); oParser = new parserFormula('MONTH(A10)', "A2", ws); assert.ok(oParser.parse(), "MONTH(0)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH(0)"); oParser = new parserFormula('MONTH(A11)', "A2", ws); assert.ok(oParser.parse(), "MONTH('1s')"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of MONTH('1s')"); oParser = new parserFormula('MONTH(A12)', "A2", ws); assert.ok(oParser.parse(), "MONTH(TRUE)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH(TRUE)"); oParser = new parserFormula('MONTH(A13)', "A2", ws); assert.ok(oParser.parse(), "MONTH(FALSE)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH(FALSE)"); oParser = new parserFormula('MONTH(A14)', "A2", ws); assert.ok(oParser.parse(), "MONTH(#DIV/0!)"); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "Result of MONTH(#DIV/0!)"); oParser = new parserFormula('MONTH(A15)', "A2", ws); assert.ok(oParser.parse(), "MONTH('')"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH('')"); oParser = new parserFormula('MONTH(A1:A4)', "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("C1:C5").bbox); assert.ok(oParser.parse(), "MONTH(A1:A4)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 9, "Result of MONTH(A1:A4)[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 12, "Result of MONTH(A1:A4)[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 12, "Result of MONTH(A1:A4)[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 11, "Result of MONTH(A1:A4)[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "", "Result of MONTH(A1:A4)[4,0]"); oParser = new parserFormula('MONTH({1,100,1000,10000})', "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("D1:H1").bbox); assert.ok(oParser.parse(), "MONTH({1,100,1000,10000})"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of MONTH({1,100,1000,10000})[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 4, "Result of MONTH({1,100,1000,10000})[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 9, "Result of MONTH({1,100,1000,10000})[0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 5, "Result of MONTH({1,100,1000,10000})[0,3]"); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), "#N/A", "Result of MONTH({1,100,1000,10000})[0,4]"); // set 1904 mode ws.workbook.setDate1904(true, true); oParser = new parserFormula("MONTH(A1)", "A2", ws); assert.ok(oParser.parse(), "MONTH(30.09.21)"); assert.strictEqual(oParser.calculate().getValue(), 10, "Result of MONTH(30.09.21)"); oParser = new parserFormula("MONTH(A2)", "A2", ws); assert.ok(oParser.parse(), "MONTH(30.12.21)"); assert.strictEqual(oParser.calculate().getValue(), 12, "Result of MONTH(30.12.21)"); oParser = new parserFormula("MONTH(A3)", "A2", ws); assert.ok(oParser.parse(), "MONTH(31.12.21)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH(31.12.21)"); oParser = new parserFormula("MONTH(A4)", "A2", ws); assert.ok(oParser.parse(), "MONTH(10.11.21)"); assert.strictEqual(oParser.calculate().getValue(), 11, "Result of MONTH(10.11.21)"); oParser = new parserFormula("MONTH(A5)", "A2", ws); assert.ok(oParser.parse(), "MONTH('2021-10-01')"); assert.strictEqual(oParser.calculate().getValue(), 10, "Result of MONTH('2021-10-01')"); oParser = new parserFormula("MONTH(A6)", "A2", ws); assert.ok(oParser.parse(), "MONTH('2021-12-31')"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH('2021-12-31')"); oParser = new parserFormula("MONTH(A7)", "A2", ws); assert.ok(oParser.parse(), "MONTH('2021-09-30')"); assert.strictEqual(oParser.calculate().getValue(), 10, "Result of MONTH('2021-09-30')"); oParser = new parserFormula("MONTH(A8)", "A2", ws); assert.ok(oParser.parse(), "MONTH('2021-10-31')"); assert.strictEqual(oParser.calculate().getValue(), 11, "Result of MONTH('2021-10-31')"); oParser = new parserFormula("MONTH(A9)", "A2", ws); assert.ok(oParser.parse(), "MONTH('2021-12-29')"); assert.strictEqual(oParser.calculate().getValue(), 12, "Result of MONTH('2021-12-29')"); oParser = new parserFormula('MONTH(A10)', "A2", ws); assert.ok(oParser.parse(), "MONTH(0)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH(0)"); oParser = new parserFormula('MONTH(A11)', "A2", ws); assert.ok(oParser.parse(), "MONTH('1s')"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of MONTH('1s')"); oParser = new parserFormula('MONTH(A12)', "A2", ws); assert.ok(oParser.parse(), "MONTH(TRUE)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH(TRUE)"); oParser = new parserFormula('MONTH(A13)', "A2", ws); assert.ok(oParser.parse(), "MONTH(FALSE)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH(FALSE)"); oParser = new parserFormula('MONTH(A14)', "A2", ws); assert.ok(oParser.parse(), "MONTH(#DIV/0!)"); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "Result of MONTH(#DIV/0!)"); oParser = new parserFormula('MONTH(A15)', "A2", ws); assert.ok(oParser.parse(), "MONTH('')"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of MONTH('')"); oParser = new parserFormula('MONTH(A1:A4)', "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("C1:C5").bbox); assert.ok(oParser.parse(), "MONTH(A1:A4)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 10, "Result of MONTH(A1:A4)[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 12, "Result of MONTH(A1:A4)[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 1, "Result of MONTH(A1:A4)[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 11, "Result of MONTH(A1:A4)[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "", "Result of MONTH(A1:A4)[4,0]"); oParser = new parserFormula('MONTH({1,100,1000,10000})', "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("D1:H1").bbox); assert.ok(oParser.parse(), "MONTH({1,100,1000,10000})"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of MONTH({1,100,1000,10000})[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 4, "Result of MONTH({1,100,1000,10000})[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 9, "Result of MONTH({1,100,1000,10000})[0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 5, "Result of MONTH({1,100,1000,10000})[0,3]"); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), "#N/A", "Result of MONTH({1,100,1000,10000})[0,4]"); // return to base mode ws.workbook.setDate1904(false, true); testArrayFormula2(assert, "MONTH"); }); QUnit.test("Test: \"YEAR\"", function (assert) { let array; ws.getRange2("A1:A15").cleanAll(); // base mode ws.workbook.setDate1904(false, true); // inline oParser = new parserFormula("YEAR(44469)", "A2", ws); assert.ok(oParser.parse(), "YEAR(30.09.21)"); assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR(30.09.21)"); oParser = new parserFormula("YEAR(44560)", "A2", ws); assert.ok(oParser.parse(), "YEAR(30.12.21)"); assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR(30.12.21)"); oParser = new parserFormula("YEAR(44561)", "A2", ws); assert.ok(oParser.parse(), "YEAR(31.12.21)"); assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR(31.12.21)"); oParser = new parserFormula("YEAR(44510)", "A2", ws); assert.ok(oParser.parse(), "YEAR(10.11.21)"); assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR(10.11.21)"); oParser = new parserFormula('YEAR("2021-10-01")', "A2", ws); assert.ok(oParser.parse(), 'YEAR("2021-10-01")'); assert.strictEqual(oParser.calculate().getValue(), 2021, 'Result of YEAR("2021-10-01")'); oParser = new parserFormula('YEAR("2021-12-31")', "A2", ws); assert.ok(oParser.parse(), "YEAR('2021-12-31')"); assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR('2021-12-31')"); oParser = new parserFormula('YEAR("2021-09-30")', "A2", ws); assert.ok(oParser.parse(), "YEAR('2021-09-30')"); assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR('2021-09-30')"); oParser = new parserFormula('YEAR("2021-10-31")', "A2", ws); assert.ok(oParser.parse(), "YEAR('2021-10-31')"); assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR('2021-10-31')"); oParser = new parserFormula('YEAR("2021-12-29")', "A2", ws); assert.ok(oParser.parse(), "YEAR('2021-12-29')"); assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR('2021-12-29')"); oParser = new parserFormula('YEAR(0)', "A2", ws); assert.ok(oParser.parse(), "YEAR(0)"); assert.strictEqual(oParser.calculate().getValue(), 1900, "Result of YEAR(0)"); oParser = new parserFormula('YEAR("1s")', "A2", ws); assert.ok(oParser.parse(), "YEAR('1s')"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of YEAR('1s')"); oParser = new parserFormula('YEAR(TRUE)', "A2", ws); assert.ok(oParser.parse(), "YEAR(TRUE)"); assert.strictEqual(oParser.calculate().getValue(), 1900, "Result of YEAR(TRUE)"); oParser = new parserFormula('YEAR(FALSE)', "A2", ws); assert.ok(oParser.parse(), "YEAR(FALSE)"); assert.strictEqual(oParser.calculate().getValue(), 1900, "Result of YEAR(FALSE)"); oParser = new parserFormula('YEAR(#DIV/0!)', "A2", ws); assert.ok(oParser.parse(), "YEAR(#DIV/0!)"); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "Result of YEAR(#DIV/0!)"); // cell ws.getRange2("A1").setValue("44469"); ws.getRange2("A2").setValue("44560"); ws.getRange2("A3").setValue("44561"); ws.getRange2("A4").setValue("44510"); ws.getRange2("A5").setValue("2021-10-01"); ws.getRange2("A6").setValue("2021-12-31"); ws.getRange2("A7").setValue("2021-09-30"); ws.getRange2("A8").setValue("2021-10-31"); ws.getRange2("A9").setValue("2021-12-29"); ws.getRange2("A10").setValue("0"); ws.getRange2("A11").setValue("1s"); ws.getRange2("A12").setValue("TRUE"); ws.getRange2("A13").setValue("FALSE"); ws.getRange2("A14").setValue("#DIV/0!"); ws.getRange2("A15").setValue(""); oParser = new parserFormula("YEAR(A1)", "A2", ws); assert.ok(oParser.parse(), "YEAR(30.09.21)"); assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR(30.09.21)"); oParser = new parserFormula("YEAR(A2)", "A2", ws); assert.ok(oParser.parse(), "YEAR(30.12.21)"); assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR(30.12.21)"); oParser = new parserFormula("YEAR(A3)", "A2", ws); assert.ok(oParser.parse(), "YEAR(31.12.21)"); assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR(31.12.21)"); oParser = new parserFormula("YEAR(A4)", "A2", ws); assert.ok(oParser.parse(), "YEAR(10.11.21)"); assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR(10.11.21)"); oParser = new parserFormula("YEAR(A5)", "A2", ws); assert.ok(oParser.parse(), "YEAR('2021-10-01')"); assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR('2021-10-01')"); oParser = new parserFormula("YEAR(A6)", "A2", ws); assert.ok(oParser.parse(), "YEAR('2021-12-31')"); assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR('2021-12-31')"); oParser = new parserFormula("YEAR(A7)", "A2", ws); assert.ok(oParser.parse(), "YEAR('2021-09-30')"); assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR('2021-09-30')"); oParser = new parserFormula("YEAR(A8)", "A2", ws); assert.ok(oParser.parse(), "YEAR('2021-10-31')"); assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR('2021-10-31')"); oParser = new parserFormula("YEAR(A9)", "A2", ws); assert.ok(oParser.parse(), "YEAR('2021-12-29')"); assert.strictEqual(oParser.calculate().getValue(), 2021, "Result of YEAR('2021-12-29')"); oParser = new parserFormula('YEAR(A10)', "A2", ws); assert.ok(oParser.parse(), "YEAR(0)"); assert.strictEqual(oParser.calculate().getValue(), 1900, "Result of YEAR(0)"); oParser = new parserFormula('YEAR(A11)', "A2", ws); assert.ok(oParser.parse(), "YEAR('1s')"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of YEAR('1s')"); oParser = new parserFormula('YEAR(A12)', "A2", ws); assert.ok(oParser.parse(), "YEAR(TRUE)"); assert.strictEqual(oParser.calculate().getValue(), 1900, "Result of YEAR(TRUE)"); oParser = new parserFormula('YEAR(A13)', "A2", ws); assert.ok(oParser.parse(), "YEAR(FALSE)"); assert.strictEqual(oParser.calculate().getValue(), 1900, "Result of YEAR(FALSE)"); oParser = new parserFormula('YEAR(A14)', "A2", ws); assert.ok(oParser.parse(), "YEAR(#DIV/0!)"); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "Result of YEAR(#DIV/0!)"); oParser = new parserFormula('YEAR(A15)', "A2", ws); assert.ok(oParser.parse(), "YEAR('')"); assert.strictEqual(oParser.calculate().getValue(), 1900, "Result of YEAR('')"); oParser = new parserFormula('YEAR(A1:A4)', "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("C1:C5").bbox); assert.ok(oParser.parse(), "YEAR(A1:A4)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2021, "Result of YEAR(A1:A4)[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2021, "Result of YEAR(A1:A4)[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 2021, "Result of YEAR(A1:A4)[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 2021, "Result of YEAR(A1:A4)[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "", "Result of YEAR(A1:A4)[4,0]"); oParser = new parserFormula('YEAR({1,100,1000,10000})', "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("D1:H1").bbox); assert.ok(oParser.parse(), "YEAR({1,100,1000,10000})"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1900, "Result of YEAR({1,100,1000,10000})[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1900, "Result of YEAR({1,100,1000,10000})[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 1902, "Result of YEAR({1,100,1000,10000})[0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 1927, "Result of YEAR({1,100,1000,10000})[0,3]"); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), "#N/A", "Result of YEAR({1,100,1000,10000})[0,4]"); // set 1904 mode ws.workbook.setDate1904(true, true); oParser = new parserFormula("YEAR(A1)", "A2", ws); assert.ok(oParser.parse(), "YEAR(A1)"); assert.strictEqual(oParser.calculate().getValue(), 2025, "Result of YEAR(A1)"); oParser = new parserFormula("YEAR(A2)", "A2", ws); assert.ok(oParser.parse(), "YEAR(A2)"); assert.strictEqual(oParser.calculate().getValue(), 2025, "Result of YEAR(A2)"); oParser = new parserFormula("YEAR(A3)", "A2", ws); assert.ok(oParser.parse(), "YEAR(A3)"); assert.strictEqual(oParser.calculate().getValue(), 2025, "Result of YEAR(A3)"); oParser = new parserFormula("YEAR(A4)", "A2", ws); assert.ok(oParser.parse(), "YEAR(A4)"); assert.strictEqual(oParser.calculate().getValue(), 2025, "Result of YEAR(A4)"); oParser = new parserFormula("YEAR(A5)", "A2", ws); assert.ok(oParser.parse(), "YEAR(A5)"); assert.strictEqual(oParser.calculate().getValue(), 2025, "Result of YEAR(A5)"); oParser = new parserFormula("YEAR(A6)", "A2", ws); assert.ok(oParser.parse(), "YEAR(A6)"); assert.strictEqual(oParser.calculate().getValue(), 2025, "Result of YEAR(A6)"); oParser = new parserFormula("YEAR(A7)", "A2", ws); assert.ok(oParser.parse(), "YEAR(A7)"); assert.strictEqual(oParser.calculate().getValue(), 2025, "Result of YEAR(A7)"); oParser = new parserFormula("YEAR(A8)", "A2", ws); assert.ok(oParser.parse(), "YEAR(A8)"); assert.strictEqual(oParser.calculate().getValue(), 2025, "Result of YEAR(A8)"); oParser = new parserFormula("YEAR(A9)", "A2", ws); assert.ok(oParser.parse(), "YEAR(A9)"); assert.strictEqual(oParser.calculate().getValue(), 2025, "Result of YEAR(A9)"); oParser = new parserFormula('YEAR(A10)', "A2", ws); assert.ok(oParser.parse(), "YEAR(A10)"); assert.strictEqual(oParser.calculate().getValue(), 1904, "Result of YEAR(A10)"); oParser = new parserFormula('YEAR(A11)', "A2", ws); assert.ok(oParser.parse(), "YEAR(A11)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of YEAR(A11)"); oParser = new parserFormula('YEAR(A12)', "A2", ws); assert.ok(oParser.parse(), "YEAR(A12)"); assert.strictEqual(oParser.calculate().getValue(), 1904, "Result of YEAR(A12)"); oParser = new parserFormula('YEAR(A13)', "A2", ws); assert.ok(oParser.parse(), "YEAR(A13)"); assert.strictEqual(oParser.calculate().getValue(), 1904, "Result of YEAR(A13)"); oParser = new parserFormula('YEAR(A14)', "A2", ws); assert.ok(oParser.parse(), "YEAR(A14)"); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "Result of YEAR(A14)"); oParser = new parserFormula('YEAR(A15)', "A2", ws); assert.ok(oParser.parse(), "YEAR(A15)"); assert.strictEqual(oParser.calculate().getValue(), 1904, "Result of YEAR(A15)"); oParser = new parserFormula('YEAR({1,100,1000,10000})', "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("D1:H1").bbox); assert.ok(oParser.parse(), "YEAR({1,100,1000,10000})"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1904, "Result of YEAR({1,100,1000,10000})[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1904, "Result of YEAR({1,100,1000,10000})[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 1906, "Result of YEAR({1,100,1000,10000})[0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 1931, "Result of YEAR({1,100,1000,10000})[0,3]"); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), "#N/A", "Result of YEAR({1,100,1000,10000})[0,4]"); // return to base mode ws.workbook.setDate1904(false, true); testArrayFormula2(assert, "YEAR"); }); QUnit.test("Test: \"EVEN\"", function (assert) { oParser = new parserFormula("EVEN(1.5)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula("EVEN(3)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); oParser = new parserFormula("EVEN(2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula("EVEN(-1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -2); testArrayFormula(assert, "EVEN"); }); QUnit.test("Test: \"NETWORKDAYS\"", function (assert) { oParser = new parserFormula("NETWORKDAYS(DATE(2006,1,1),DATE(2006,1,31))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 22); oParser = new parserFormula("NETWORKDAYS(DATE(2006,1,31),DATE(2006,1,1))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -22); oParser = new parserFormula("NETWORKDAYS(DATE(1700,1,1),DATE(1700,2,2))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 23); oParser = new parserFormula("NETWORKDAYS(DATE(2006,1,1),DATE(2006,2,1),{\"01-02-2006\",\"01-16-2006\"})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 21); oParser = new parserFormula("NETWORKDAYS(0,0)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(0,0)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of NETWORKDAYS(0,0)"); // in js new Date(1900,0,1) === monday, in ms 01.01.1990 === sunday oParser = new parserFormula("NETWORKDAYS(1,1)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(1,1)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of NETWORKDAYS(1,1)"); oParser = new parserFormula("NETWORKDAYS(2,2)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(2,2)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of NETWORKDAYS(2,2)"); oParser = new parserFormula("NETWORKDAYS(3,3)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(3,3)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of NETWORKDAYS(3,3)"); oParser = new parserFormula("NETWORKDAYS(4,4)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(4,4)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of NETWORKDAYS(4,4)"); oParser = new parserFormula("NETWORKDAYS(5,5)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(5,5)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of NETWORKDAYS(5,5)"); oParser = new parserFormula("NETWORKDAYS(6,6)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(6,6)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of NETWORKDAYS(6,6)"); oParser = new parserFormula("NETWORKDAYS(7,7)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(7,7)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of NETWORKDAYS(7,7)"); oParser = new parserFormula("NETWORKDAYS(8,8)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(8,8)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of NETWORKDAYS(8,8)"); oParser = new parserFormula("NETWORKDAYS(9,9)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(9,9)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of NETWORKDAYS(9,9)"); oParser = new parserFormula("NETWORKDAYS(10,10)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(10,10)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of NETWORKDAYS(10,10)"); oParser = new parserFormula("NETWORKDAYS(11,11)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(11,11)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of NETWORKDAYS(11,11)"); oParser = new parserFormula("NETWORKDAYS(0,11)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(0,11)"); assert.strictEqual(oParser.calculate().getValue(), 8, "Result of NETWORKDAYS(0,11)"); oParser = new parserFormula("NETWORKDAYS(1,11)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(1,11)"); assert.strictEqual(oParser.calculate().getValue(), 8, "Result of NETWORKDAYS(1,11)"); oParser = new parserFormula("NETWORKDAYS(11,0)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(11,0)"); assert.strictEqual(oParser.calculate().getValue(), -8, "Result of NETWORKDAYS(11,0)"); oParser = new parserFormula("NETWORKDAYS(11,1)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(11,1)"); assert.strictEqual(oParser.calculate().getValue(), -8, "Result of NETWORKDAYS(11,1)"); oParser = new parserFormula("NETWORKDAYS(-1,15)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(-1,15)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of NETWORKDAYS(-1,15)"); oParser = new parserFormula("NETWORKDAYS(15,-1)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(15,-1)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of NETWORKDAYS(15,-1)"); oParser = new parserFormula("NETWORKDAYS(-1,-15)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(-1,-15)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of NETWORKDAYS(-1,-15)"); oParser = new parserFormula("NETWORKDAYS(1,3889)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(1,3889)"); assert.strictEqual(oParser.calculate().getValue(), 2778, "Result of NETWORKDAYS(1,3889)"); oParser = new parserFormula("NETWORKDAYS(1,45689)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(1,45689)"); assert.strictEqual(oParser.calculate().getValue(), 32635, "Result of NETWORKDAYS(1,45689)"); oParser = new parserFormula("NETWORKDAYS(0.1,0.9)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(0.1,0.9)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of NETWORKDAYS(0.1,0.9)"); oParser = new parserFormula("NETWORKDAYS(1.1,3889)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(1.1,3889)"); assert.strictEqual(oParser.calculate().getValue(), 2778, "Result of NETWORKDAYS(1.1,3889)"); oParser = new parserFormula("NETWORKDAYS(1.9,3889)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(1.9,3889)"); assert.strictEqual(oParser.calculate().getValue(), 2778, "Result of NETWORKDAYS(1.9,3889)"); oParser = new parserFormula("NETWORKDAYS(1,3889.1)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(1,3889.1)"); assert.strictEqual(oParser.calculate().getValue(), 2778, "Result of NETWORKDAYS(1,3889.1)"); oParser = new parserFormula("NETWORKDAYS(1.9,3889.9)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(1.9,3889.9)"); assert.strictEqual(oParser.calculate().getValue(), 2778, "Result of NETWORKDAYS(1.9,3889.9)"); // bool oParser = new parserFormula("NETWORKDAYS(11,TRUE)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(11,TRUE)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of NETWORKDAYS(11,TRUE)"); oParser = new parserFormula("NETWORKDAYS(TRUE,TRUE)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(TRUE,TRUE)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of NETWORKDAYS(TRUE,TRUE)"); oParser = new parserFormula("NETWORKDAYS(TRUE,11)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(TRUE,11)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of NETWORKDAYS(TRUE,11)"); oParser = new parserFormula("NETWORKDAYS(#VALUE!,#NUM!)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(#VALUE!,#NUM!)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of NETWORKDAYS(#VALUE!,#NUM!)"); // array oParser = new parserFormula("NETWORKDAYS({1,11,255},11)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS({1,11,255},11)"); assert.strictEqual(oParser.calculate().getValue(), 8, "Result of NETWORKDAYS({1,11,255},11)"); oParser = new parserFormula("NETWORKDAYS(1,{11,85,255})", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(1,{11,85,255})"); assert.strictEqual(oParser.calculate().getValue(), 8, "Result of NETWORKDAYS(1,{11,85,255})"); oParser = new parserFormula("NETWORKDAYS({1,11,255},{11,85,255})", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS({1,11,255},{11,85,255})"); assert.strictEqual(oParser.calculate().getValue(), 8, "Result of NETWORKDAYS({1,11,255},{11,85,255})"); ws.getRange2("A101").setValue(); ws.getRange2("A102").setValue(""); ws.getRange2("A103").setValue("0"); ws.getRange2("A104").setValue("9"); ws.getRange2("A105").setValue("25"); ws.getRange2("A106").setValue("TRUE"); ws.getRange2("A107").setValue("FALSE"); ws.getRange2("A108").setValue("{999,25,0}"); ws.getRange2("A109").setValue("{777,25,0}"); ws.getRange2("A110").setValue("{0,777,25,0}"); ws.getRange2("A111").setValue("#N/A"); ws.getRange2("A112").setValue("99999999999999999999"); ws.getRange2("A113").setValue("-99999999999999999999"); ws.getRange2("A114").setValue("str"); ws.getRange2("A115").setValue("str2"); ws.getRange2("B101").setValue("0"); ws.getRange2("B102").setValue("1"); ws.getRange2("B103").setValue("4"); ws.getRange2("B104").setValue("9"); ws.getRange2("B105").setValue("25"); ws.getRange2("B106").setValue("255"); ws.getRange2("B107").setValue("312778"); // cellsrange oParser = new parserFormula("NETWORKDAYS(A101:A105,A105)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(A101:A105,25)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of NETWORKDAYS(A101:A105,25)"); oParser = new parserFormula("NETWORKDAYS(A104,A101:A105)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(A104,A101:A105)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of NETWORKDAYS(A104,A101:A105)"); oParser = new parserFormula("NETWORKDAYS(A101:A105,A101:A105)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(A101:A105,A101:A105)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of NETWORKDAYS(A101:A105,A101:A105)"); oParser = new parserFormula("NETWORKDAYS(B101:B107,B101:B107)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(B101:B107,B101:B107)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of NETWORKDAYS(B101:B107,B101:B107)"); // cells oParser = new parserFormula("NETWORKDAYS(A102,A102)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(A102,A102)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of NETWORKDAYS('','')"); oParser = new parserFormula("NETWORKDAYS(A102:A102,A102:A102)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(A102:A102,A102:A102)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of NETWORKDAYS('','')"); oParser = new parserFormula("NETWORKDAYS(A103,A104)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(A103,A104)"); assert.strictEqual(oParser.calculate().getValue(), 6, "Result of NETWORKDAYS(0,9)"); oParser = new parserFormula("NETWORKDAYS(A104:A104,A104:A104)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("NETWORKDAYS(A106,A107)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("NETWORKDAYS(A109,A108)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS({777,25,0},{999,25,0})"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of NETWORKDAYS({777,25,0},{999,25,0})"); oParser = new parserFormula("NETWORKDAYS(A105,A108)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(25,{999,25,0})"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of NETWORKDAYS(25,{999,25,0})"); oParser = new parserFormula("NETWORKDAYS(A108,25)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS({999,25,0},25)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of NETWORKDAYS({999,25,0},25)"); oParser = new parserFormula("NETWORKDAYS(A111,A105)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(A114,A115)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of NETWORKDAYS(str,str2)"); oParser = new parserFormula("NETWORKDAYS(A114,A115)", "A2", ws); assert.ok(oParser.parse(), "NETWORKDAYS(A114,A115)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of NETWORKDAYS(str,str2)"); // bug case oParser = new parserFormula("NETWORKDAYS(A101,A101)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("NETWORKDAYS(A101,A102)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("NETWORKDAYS(A101,A109)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("NETWORKDAYS(A102,A109)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("NETWORKDAYS(A101:A101,A101:A101)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); testArrayFormula2(assert, "NETWORKDAYS", 2, 3, true, null); }); QUnit.test("Test: \"NETWORKDAYS.INTL\"", function (assert) { var formulaStr = "NETWORKDAYS.INTL(DATE(2006,1,1),DATE(2006,1,31))"; oParser = new parserFormula(formulaStr, "A2", ws); assert.ok(oParser.parse(), formulaStr); assert.strictEqual(oParser.calculate().getValue(), 22, formulaStr); formulaStr = "NETWORKDAYS.INTL(DATE(2006,2,28),DATE(2006,1,31))"; oParser = new parserFormula(formulaStr, "A2", ws); assert.ok(oParser.parse(), formulaStr); assert.strictEqual(oParser.calculate().getValue(), -21, formulaStr); formulaStr = 'NETWORKDAYS.INTL(DATE(2006,1,1),DATE(2006,2,1),7,{"1/2/2006","1/16/2006"})'; oParser = new parserFormula(formulaStr, "A2", ws); assert.ok(oParser.parse(), formulaStr); assert.strictEqual(oParser.calculate().getValue(), 22, formulaStr); formulaStr = 'NETWORKDAYS.INTL(DATE(2006,1,1),DATE(2006,2,1),17,{"1/2/2006","1/16/2006"})'; oParser = new parserFormula(formulaStr, "A2", ws); assert.ok(oParser.parse(), formulaStr); assert.strictEqual(oParser.calculate().getValue(), 26, formulaStr); formulaStr = 'NETWORKDAYS.INTL(DATE(2006,1,1),DATE(2006,2,1),"1111111",{"1/2/2006","1/16/2006"})'; oParser = new parserFormula(formulaStr, "A2", ws); assert.ok(oParser.parse(), formulaStr); assert.strictEqual(oParser.calculate().getValue(), 0, formulaStr); formulaStr = 'NETWORKDAYS.INTL(DATE(2006,1,1),DATE(2006,2,1),"0010001",{"1/2/2006","1/16/2006"})'; oParser = new parserFormula(formulaStr, "A2", ws); assert.ok(oParser.parse(), formulaStr); assert.strictEqual(oParser.calculate().getValue(), 20, formulaStr); formulaStr = 'NETWORKDAYS.INTL(DATE(2006,1,1),DATE(2006,2,1),"0000000",{"1/2/2006","1/16/2006"})'; oParser = new parserFormula(formulaStr, "A2", ws); assert.ok(oParser.parse(), formulaStr); assert.strictEqual(oParser.calculate().getValue(), 30, formulaStr); formulaStr = 'NETWORKDAYS.INTL(DATE(2006,1,1),DATE(2006,2,1),"19",{"1/2/2006","1/16/2006"})'; oParser = new parserFormula(formulaStr, "A2", ws); assert.ok(oParser.parse(), formulaStr); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", formulaStr); formulaStr = 'NETWORKDAYS.INTL(DATE(2006,1,1),DATE(2006,2,1),19,{"1/2/2006","1/16/2006"})'; oParser = new parserFormula(formulaStr, "A2", ws); assert.ok(oParser.parse(), formulaStr); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", formulaStr); formulaStr = 'NETWORKDAYS.INTL(DATE(1901,1,1),DATE(2006,2,1),"0000000",{"1/2/2006","1/16/2006"})'; oParser = new parserFormula(formulaStr, "A2", ws); assert.ok(oParser.parse(), formulaStr); assert.strictEqual(oParser.calculate().getValue(), 38381, formulaStr); formulaStr = 'NETWORKDAYS.INTL(DATE(1901,1,1),DATE(2006,2,1),17,{"1/2/2006","1/16/2006"})'; oParser = new parserFormula(formulaStr, "A2", ws); assert.ok(oParser.parse(), formulaStr); assert.strictEqual(oParser.calculate().getValue(), 32898, formulaStr); formulaStr = 'NETWORKDAYS.INTL(100.123,10003.556,11)'; oParser = new parserFormula(formulaStr, "A2", ws); assert.ok(oParser.parse(), formulaStr); assert.strictEqual(oParser.calculate().getValue(), 8490, formulaStr); formulaStr = 'NETWORKDAYS.INTL(100.123,10003.556,1)'; oParser = new parserFormula(formulaStr, "A2", ws); assert.ok(oParser.parse(), formulaStr); assert.strictEqual(oParser.calculate().getValue(), 7075, formulaStr); formulaStr = 'NETWORKDAYS.INTL(100.123,10003.556,2)'; oParser = new parserFormula(formulaStr, "A2", ws); assert.ok(oParser.parse(), formulaStr); assert.strictEqual(oParser.calculate().getValue(), 7075, formulaStr); //TODO посмотреть почему неверно считается //проблема повторяется с новым и со старым вариантом реализации NETWORKDAYS.INTL /*formulaStr = 'NETWORKDAYS.INTL(100.123,10003.556,5)'; oParser = new parserFormula( formulaStr, "A2", ws ); assert.ok( oParser.parse(), formulaStr ); assert.strictEqual( oParser.calculate().getValue(), 7074, formulaStr ); formulaStr = 'NETWORKDAYS.INTL(100.123,10003.556,5,{123,1000})'; oParser = new parserFormula( formulaStr, "A2", ws ); assert.ok( oParser.parse(), formulaStr ); assert.strictEqual( oParser.calculate().getValue(), 7073, formulaStr );*/ }); QUnit.test("Test: \"N\"", function (assert) { ws.getRange2("A2").setValue("7"); ws.getRange2("A3").setValue("Even"); ws.getRange2("A4").setValue("TRUE"); ws.getRange2("A5").setValue("4/17/2011"); oParser = new parserFormula("N(A2)", "A7", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 7); oParser = new parserFormula("N(A3)", "A7", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("N(A4)", "A7", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("N(A5)", "A7", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 40650); oParser = new parserFormula('N("7")', "A7", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); //TODO нужна другая функция для тестирования //testArrayFormula2(assert, "N", 1, 1); }); QUnit.test("Test: \"SUMIF\"", function (assert) { ws.getRange2("A2").setValue("100000"); ws.getRange2("A3").setValue("200000"); ws.getRange2("A4").setValue("300000"); ws.getRange2("A5").setValue("400000"); ws.getRange2("B2").setValue("7000"); ws.getRange2("B3").setValue("14000"); ws.getRange2("B4").setValue("21000"); ws.getRange2("B5").setValue("28000"); ws.getRange2("C2").setValue("250000"); oParser = new parserFormula("SUMIF(A2:A5,\">160000\",B2:B5)", "A7", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 63000); oParser = new parserFormula("SUMIF(A2:A5,\">160000\")", "A8", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 900000); oParser = new parserFormula("SUMIF(A2:A5,300000,B2:B5)", "A9", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 21000); oParser = new parserFormula("SUMIF(A2:A5,\">\" & C2,B2:B5)", "A10", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 49000); oParser = new parserFormula("SUMIF(A2,\">160000\",B2:B5)", "A7", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("SUMIF(A3,\">160000\",B2:B5)", "A7", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 7000); oParser = new parserFormula("SUMIF(A4,\">160000\",B4:B5)", "A7", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 21000); oParser = new parserFormula("SUMIF(A4,\">160000\")", "A7", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 300000); ws.getRange2("A12").setValue("Vegetables"); ws.getRange2("A13").setValue("Vegetables"); ws.getRange2("A14").setValue("Fruits"); ws.getRange2("A15").setValue(""); ws.getRange2("A16").setValue("Vegetables"); ws.getRange2("A17").setValue("Fruits"); ws.getRange2("B12").setValue("Tomatoes"); ws.getRange2("B13").setValue("Celery"); ws.getRange2("B14").setValue("Oranges"); ws.getRange2("B15").setValue("Butter"); ws.getRange2("B16").setValue("Carrots"); ws.getRange2("B17").setValue("Apples"); ws.getRange2("C12").setValue("2300"); ws.getRange2("C13").setValue("5500"); ws.getRange2("C14").setValue("800"); ws.getRange2("C15").setValue("400"); ws.getRange2("C16").setValue("4200"); ws.getRange2("C17").setValue("1200"); oParser = new parserFormula("SUMIF(A12:A17,\"Fruits\",C12:C17)", "A19", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2000); oParser = new parserFormula("SUMIF(A12:A17,\"Vegetables\",C12:C17)", "A20", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 12000); oParser = new parserFormula("SUMIF(B12:B17,\"*es\",C12:C17)", "A21", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4300); oParser = new parserFormula("SUMIF(A12:A17,\"\",C12:C17)", "A22", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 400); }); QUnit.test("Test: \"SUMIFS\"", function (assert) { ws.getRange2("A2").setValue("5"); ws.getRange2("A3").setValue("4"); ws.getRange2("A4").setValue("15"); ws.getRange2("A5").setValue("3"); ws.getRange2("A6").setValue("22"); ws.getRange2("A7").setValue("12"); ws.getRange2("A8").setValue("10"); ws.getRange2("A9").setValue("33"); ws.getRange2("B2").setValue("Apples"); ws.getRange2("B3").setValue("Apples"); ws.getRange2("B4").setValue("Artichokes"); ws.getRange2("B5").setValue("Artichokes"); ws.getRange2("B6").setValue("Bananas"); ws.getRange2("B7").setValue("Bananas"); ws.getRange2("B8").setValue("Carrots"); ws.getRange2("B9").setValue("Carrots"); ws.getRange2("C2").setValue("Tom"); ws.getRange2("C3").setValue("Sarah"); ws.getRange2("C4").setValue("Tom"); ws.getRange2("C5").setValue("Sarah"); ws.getRange2("C6").setValue("Tom"); ws.getRange2("C7").setValue("Sarah"); ws.getRange2("C8").setValue("Tom"); ws.getRange2("C9").setValue("Sarah"); ws.getRange2("D:E").cleanAll(); oParser = new parserFormula("SUMIFS(A2:A9, B2:B9, \"=A*\", C2:C9, \"Tom\")", "A10", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 20); oParser = new parserFormula("SUMIFS(A2:A9, B2:B9, \"<>Bananas\", C2:C9, \"Tom\")", "A11", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 30); oParser = new parserFormula("SUMIFS(D:D,E:E,$H2)", "A11", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("SUMIFS(C:D,E:E,$H2)", "A11", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); // for bug 58684 let calculateResult = new AscCommonExcel.CalculateResult(true); oParser = new parserFormula("SUMIFS({1,2,3},A2:A9,A2)", "A11", ws); assert.ok(oParser.parse(), 'SUMIFS({1,2,3},A2:A9,A2) - wrong argument type check'); assert.strictEqual(oParser.calculate(null, null, null, null, calculateResult).getValue(), "#NULL!", 'Result of SUMIFS({1,2,3},A2:A9,A2) - wrong argument type check'); oParser = new parserFormula("SUMIFS(MONTH(A2:A9),A2:A9,A2)", "A11", ws); assert.ok(oParser.parse(), 'SUMIFS(MONTH(A2:A9),A2:A9,A2) - wrong argument type check'); assert.strictEqual(oParser.calculate(null, null, null, null, calculateResult).getValue(), "#NULL!", 'Result of SUMIFS(MONTH(A2:A9),A2:A9,A2) - wrong argument type check'); oParser = new parserFormula("SUMIFS(A2:A9,{1,2,3},A2)", "A11", ws); assert.ok(oParser.parse(), 'SUMIFS(A2:A9,{1,2,3},A2) - wrong argument type check'); assert.strictEqual(oParser.calculate(null, null, null, null, calculateResult).getValue(), "#NULL!", 'Result of SUMIFS(A2:A9,{1,2,3},A2) - wrong argument type check'); oParser = new parserFormula("SUMIFS(A2:A9,A2:A9*2,A2)", "A11", ws); assert.ok(oParser.parse(), 'SUMIFS(A2:A9,A2:A9*2,A2) - wrong argument type check'); assert.strictEqual(oParser.calculate(null, null, null, null, calculateResult).getValue(), "#NULL!", 'Result of SUMIFS(A2:A9,A2:A9*2,A2) - wrong argument type check'); oParser = new parserFormula("SUMIFS(A2:A9,A2:A9,A2,{1,2,3},A2)", "A11", ws); assert.ok(oParser.parse(), 'SUMIFS(A2:A9,A2:A9,A2,{1,2,3},A2) - wrong argument type check'); assert.strictEqual(oParser.calculate(null, null, null, null, calculateResult).getValue(), "#NULL!", 'Result of SUMIFS(A2:A9,A2:A9,A2,{1,2,3},A2) - wrong argument type check'); oParser = new parserFormula("SUMIFS(A2:A9,A2:A9,A2,A2:A9*2,A2)", "A11", ws); assert.ok(oParser.parse(), 'SUMIFS(A2:A9,A2:A9,A2,A2:A9*2,A2) - wrong argument type check'); assert.strictEqual(oParser.calculate(null, null, null, null, calculateResult).getValue(), "#NULL!", 'Result of SUMIFS(A2:A9,A2:A9,A2,A2:A9*2,A2) - wrong argument type check'); }); QUnit.test("Test: \"SUMIFS with multiple criteria ranges\"", function (assert) { // Setup test data with 5 columns for testing ws.getRange2("E2").setValue("10"); ws.getRange2("E3").setValue("20"); ws.getRange2("E4").setValue("30"); ws.getRange2("E5").setValue("40"); ws.getRange2("E6").setValue("50"); ws.getRange2("E7").setValue("60"); ws.getRange2("F2").setValue("Red"); ws.getRange2("F3").setValue("Blue"); ws.getRange2("F4").setValue("Green"); ws.getRange2("F5").setValue("Red"); ws.getRange2("F6").setValue("Blue"); ws.getRange2("F7").setValue("Green"); ws.getRange2("G2").setValue("Small"); ws.getRange2("G3").setValue("Medium"); ws.getRange2("G4").setValue("Large"); ws.getRange2("G5").setValue("Large"); ws.getRange2("G6").setValue("Medium"); ws.getRange2("G7").setValue("Small"); ws.getRange2("H2").setValue("2023"); ws.getRange2("H3").setValue("2023"); ws.getRange2("H4").setValue("2024"); ws.getRange2("H5").setValue("2024"); ws.getRange2("H6").setValue("2025"); ws.getRange2("H7").setValue("2025"); ws.getRange2("I2").setValue("A"); ws.getRange2("I3").setValue("B"); ws.getRange2("I4").setValue("C"); ws.getRange2("I5").setValue("A"); ws.getRange2("I6").setValue("B"); ws.getRange2("I7").setValue("C"); // Test with 11 arguments (1 sum_range + 5 criteria pairs) oParser = new parserFormula("SUMIFS(E2:E7, F2:F7, \"Red\", G2:G7, \"Large\", H2:H7, 2024, I2:I7, \"A\", I2:I7, \"*\")", "A1", ws); assert.ok(oParser.parse(), "SUMIFS with 5 criteria pairs"); assert.strictEqual(oParser.calculate().getValue(), 40, "SUMIFS with 5 criteria pairs"); // Test with 11 arguments where none match all criteria oParser = new parserFormula("SUMIFS(E2:E7, F2:F7, \"Red\", G2:G7, \"Small\", H2:H7, 2024, I2:I7, \"A\", I2:I7, \"Z\")", "A1", ws); assert.ok(oParser.parse(), "SUMIFS with 5 criteria pairs - no match"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUMIFS with 5 criteria pairs - no match"); // Test with OR condition using multiple SUMIFS with max params oParser = new parserFormula("SUMIFS(E2:E7, F2:F7, \"Red\", G2:G7, \"Large\", H2:H7, 2024, I2:I7, \"A\")" + "+SUMIFS(E2:E7, F2:F7, \"Blue\", G2:G7, \"Medium\", H2:H7, 2025, I2:I7, \"B\")", "A1", ws); assert.ok(oParser.parse(), "Multiple SUMIFS with 4 criteria pairs"); assert.strictEqual(oParser.calculate().getValue(), 40 + 50, "Multiple SUMIFS with 4 criteria pairs"); // Test with cell references for criteria ws.getRange2("J2").setValue("Red"); ws.getRange2("J3").setValue("Large"); ws.getRange2("J4").setValue("2024"); ws.getRange2("J5").setValue("A"); oParser = new parserFormula("SUMIFS(E2:E7, F2:F7, J2, G2:G7, J3, H2:H7, J4, I2:I7, J5, I2:I7, \"*\")", "A1", ws); assert.ok(oParser.parse(), "SUMIFS with cell references for all criteria"); assert.strictEqual(oParser.calculate().getValue(), 40, "SUMIFS with cell references for all criteria"); // Test with complex criteria expressions oParser = new parserFormula("SUMIFS(E2:E7, F2:F7, \"Red\", G2:G7, \"*\", H2:H7, \">\" & 2023, I2:I7, \"A\", I2:I7, \"<>Z\")", "A1", ws); assert.ok(oParser.parse(), "SUMIFS with complex criteria expressions"); assert.strictEqual(oParser.calculate().getValue(), 40, "SUMIFS with complex criteria expressions"); // Test with criteria that select a single row oParser = new parserFormula("SUMIFS(E2:E7, F2:F7, \"Red\", G2:G7, \"Large\", H2:H7, 2024, I2:I7, \"A\", E2:E7, 40)", "A1", ws); assert.ok(oParser.parse(), "SUMIFS with criteria selecting one row"); assert.strictEqual(oParser.calculate().getValue(), 40, "SUMIFS with criteria selecting one row"); }); QUnit.test("Test: \"MAXIFS\"", function (assert) { ws.getRange2("AAA2").setValue("10"); ws.getRange2("AAA3").setValue("1"); ws.getRange2("AAA4").setValue("100"); ws.getRange2("AAA5").setValue("1"); ws.getRange2("AAA6").setValue("1"); ws.getRange2("AAA7").setValue("50"); ws.getRange2("BBB2").setValue("b"); ws.getRange2("BBB3").setValue("a"); ws.getRange2("BBB4").setValue("a"); ws.getRange2("BBB5").setValue("b"); ws.getRange2("BBB6").setValue("a"); ws.getRange2("BBB7").setValue("b"); ws.getRange2("DDD2").setValue("100"); ws.getRange2("DDD3").setValue("100"); ws.getRange2("DDD4").setValue("200"); ws.getRange2("DDD5").setValue("300"); ws.getRange2("DDD6").setValue("100"); ws.getRange2("DDD7").setValue("400"); oParser = new parserFormula('MAXIFS(AAA2:AAA7,BBB2:BBB7,"b",DDD2:DDD7,">100")', "A22", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 50); oParser = new parserFormula('MAXIFS(AAA2:AAA6,BBB2:BBB6,"a",DDD2:DDD6,">200")', "A22", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); testArrayFormulaEqualsValues(assert, "1,3.123,-4,#N/A;2,4,5,#N/A;#N/A,#N/A,#N/A,#N/A", "MAXIFS(A1:C2,A1:C2,A1:C2,A1:C2, A1:C2,A1:C2,A1:C2)"); testArrayFormulaEqualsValues(assert, "1,0,0,#N/A;0,0,0,#N/A;#N/A,#N/A,#N/A,#N/A", "MAXIFS(A1:C2,A1:C2,A1:A1,A1:C2,A1:C2,A1:C2,A1:C2)"); testArrayFormulaEqualsValues(assert, "1,0,0,#N/A;2,0,0,#N/A;#N/A,#N/A,#N/A,#N/A", "MAXIFS(A1:C2,A1:C2,A1:A2,A1:C2,A1:C2,A1:C2,A1:C2)"); }); QUnit.test("Test: \"MAXIFS with multiple criteria ranges\"", function (assert) { // Setup test data with 5 columns for testing ws.getRange2("E2").setValue("10"); ws.getRange2("E3").setValue("20"); ws.getRange2("E4").setValue("30"); ws.getRange2("E5").setValue("40"); ws.getRange2("E6").setValue("50"); ws.getRange2("E7").setValue("60"); ws.getRange2("F2").setValue("Red"); ws.getRange2("F3").setValue("Blue"); ws.getRange2("F4").setValue("Green"); ws.getRange2("F5").setValue("Red"); ws.getRange2("F6").setValue("Blue"); ws.getRange2("F7").setValue("Green"); ws.getRange2("G2").setValue("Small"); ws.getRange2("G3").setValue("Medium"); ws.getRange2("G4").setValue("Large"); ws.getRange2("G5").setValue("Large"); ws.getRange2("G6").setValue("Medium"); ws.getRange2("G7").setValue("Small"); ws.getRange2("H2").setValue("2023"); ws.getRange2("H3").setValue("2023"); ws.getRange2("H4").setValue("2024"); ws.getRange2("H5").setValue("2024"); ws.getRange2("H6").setValue("2025"); ws.getRange2("H7").setValue("2025"); ws.getRange2("I2").setValue("A"); ws.getRange2("I3").setValue("B"); ws.getRange2("I4").setValue("C"); ws.getRange2("I5").setValue("A"); ws.getRange2("I6").setValue("B"); ws.getRange2("I7").setValue("C"); // Test with 11 arguments (1 max_range + 5 criteria pairs) oParser = new parserFormula("MAXIFS(E2:E7, F2:F7, \"Red\", G2:G7, \"Large\", H2:H7, 2024, I2:I7, \"A\", I2:I7, \"*\")", "A1", ws); assert.ok(oParser.parse(), "MAXIFS with 5 criteria pairs"); assert.strictEqual(oParser.calculate().getValue(), 40, "MAXIFS with 5 criteria pairs"); // Test multiple conditions that match different values oParser = new parserFormula("MAXIFS(E2:E7, F2:F7, \"Blue\", G2:G7, \"Medium\")", "A1", ws); assert.ok(oParser.parse(), "MAXIFS with multiple matching values"); assert.strictEqual(oParser.calculate().getValue(), 50, "MAXIFS with multiple matching values"); // Test with cell references for criteria ws.getRange2("J2").setValue("Red"); ws.getRange2("J3").setValue("Large"); ws.getRange2("J4").setValue("2024"); ws.getRange2("J5").setValue("A"); oParser = new parserFormula("MAXIFS(E2:E7, F2:F7, J2, G2:G7, J3, H2:H7, J4, I2:I7, J5, I2:I7, \"*\")", "A1", ws); assert.ok(oParser.parse(), "MAXIFS with cell references for all criteria"); assert.strictEqual(oParser.calculate().getValue(), 40, "MAXIFS with cell references for all criteria"); // Test with complex criteria expressions oParser = new parserFormula("MAXIFS(E2:E7, F2:F7, \"Red\", G2:G7, \"*\", H2:H7, \">\" & 2023, I2:I7, \"A\", I2:I7, \"<>Z\")", "A1", ws); assert.ok(oParser.parse(), "MAXIFS with complex criteria expressions"); assert.strictEqual(oParser.calculate().getValue(), 40, "MAXIFS with complex criteria expressions"); // Test with criteria that select a single row oParser = new parserFormula("MAXIFS(E2:E7, F2:F7, \"Red\", G2:G7, \"Large\", H2:H7, 2024, I2:I7, \"A\", E2:E7, 40)", "A1", ws); assert.ok(oParser.parse(), "MAXIFS with criteria selecting one row"); assert.strictEqual(oParser.calculate().getValue(), 40, "MAXIFS with criteria selecting one row"); // Test finding maximum value for a specific color oParser = new parserFormula("MAXIFS(E2:E7, F2:F7, \"Green\")", "A1", ws); assert.ok(oParser.parse(), "MAXIFS with single color criteria"); assert.strictEqual(oParser.calculate().getValue(), 60, "MAXIFS with single color criteria"); }); QUnit.test("Test: \"MINIFS\"", function (assert) { ws.getRange2("AAA2").setValue("10"); ws.getRange2("AAA3").setValue("1"); ws.getRange2("AAA4").setValue("100"); ws.getRange2("AAA5").setValue("1"); ws.getRange2("AAA6").setValue("1"); ws.getRange2("AAA7").setValue("50"); ws.getRange2("BBB2").setValue("b"); ws.getRange2("BBB3").setValue("a"); ws.getRange2("BBB4").setValue("a"); ws.getRange2("BBB5").setValue("b"); ws.getRange2("BBB6").setValue("a"); ws.getRange2("BBB7").setValue("b"); ws.getRange2("DDD2").setValue("100"); ws.getRange2("DDD3").setValue("100"); ws.getRange2("DDD4").setValue("200"); ws.getRange2("DDD5").setValue("300"); ws.getRange2("DDD6").setValue("100"); ws.getRange2("DDD7").setValue("400"); oParser = new parserFormula('MINIFS(AAA2:AAA7,BBB2:BBB7,"b",DDD2:DDD7,">100")', "A22", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula('MINIFS(AAA2:AAA6,BBB2:BBB6,"a",DDD2:DDD6,">200")', "A22", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); testArrayFormulaEqualsValues(assert, "1,3.123,-4,#N/A;2,4,5,#N/A;#N/A,#N/A,#N/A,#N/A", "MINIFS(A1:C2,A1:C2,A1:C2,A1:C2, A1:C2,A1:C2,A1:C2)"); testArrayFormulaEqualsValues(assert, "1,0,0,#N/A;0,0,0,#N/A;#N/A,#N/A,#N/A,#N/A", "MINIFS(A1:C2,A1:C2,A1:A1,A1:C2,A1:C2,A1:C2,A1:C2)"); testArrayFormulaEqualsValues(assert, "1,0,0,#N/A;2,0,0,#N/A;#N/A,#N/A,#N/A,#N/A", "MINIFS(A1:C2,A1:C2,A1:A2,A1:C2,A1:C2,A1:C2,A1:C2)"); }); QUnit.test("Test: \"MINIFS with multiple criteria ranges\"", function (assert) { // Setup test data with 5 columns for testing ws.getRange2("E2").setValue("10"); ws.getRange2("E3").setValue("20"); ws.getRange2("E4").setValue("30"); ws.getRange2("E5").setValue("40"); ws.getRange2("E6").setValue("50"); ws.getRange2("E7").setValue("60"); ws.getRange2("F2").setValue("Red"); ws.getRange2("F3").setValue("Blue"); ws.getRange2("F4").setValue("Green"); ws.getRange2("F5").setValue("Red"); ws.getRange2("F6").setValue("Blue"); ws.getRange2("F7").setValue("Green"); ws.getRange2("G2").setValue("Small"); ws.getRange2("G3").setValue("Medium"); ws.getRange2("G4").setValue("Large"); ws.getRange2("G5").setValue("Large"); ws.getRange2("G6").setValue("Medium"); ws.getRange2("G7").setValue("Small"); ws.getRange2("H2").setValue("2023"); ws.getRange2("H3").setValue("2023"); ws.getRange2("H4").setValue("2024"); ws.getRange2("H5").setValue("2024"); ws.getRange2("H6").setValue("2025"); ws.getRange2("H7").setValue("2025"); ws.getRange2("I2").setValue("A"); ws.getRange2("I3").setValue("B"); ws.getRange2("I4").setValue("C"); ws.getRange2("I5").setValue("A"); ws.getRange2("I6").setValue("B"); ws.getRange2("I7").setValue("C"); // Test with 11 arguments (1 min_range + 5 criteria pairs) oParser = new parserFormula("MINIFS(E2:E7, F2:F7, \"Red\", G2:G7, \"Large\", H2:H7, 2024, I2:I7, \"A\", I2:I7, \"*\")", "A1", ws); assert.ok(oParser.parse(), "MINIFS with 5 criteria pairs"); assert.strictEqual(oParser.calculate().getValue(), 40, "MINIFS with 5 criteria pairs"); // Test multiple conditions that match different values oParser = new parserFormula("MINIFS(E2:E7, F2:F7, \"Blue\", G2:G7, \"Medium\")", "A1", ws); assert.ok(oParser.parse(), "MINIFS with multiple matching values"); assert.strictEqual(oParser.calculate().getValue(), 20, "MINIFS with multiple matching values"); // Test with cell references for criteria ws.getRange2("J2").setValue("Red"); ws.getRange2("J3").setValue("Large"); ws.getRange2("J4").setValue("2024"); ws.getRange2("J5").setValue("A"); oParser = new parserFormula("MINIFS(E2:E7, F2:F7, J2, G2:G7, J3, H2:H7, J4, I2:I7, J5, I2:I7, \"*\")", "A1", ws); assert.ok(oParser.parse(), "MINIFS with cell references for all criteria"); assert.strictEqual(oParser.calculate().getValue(), 40, "MINIFS with cell references for all criteria"); // Test with complex criteria expressions oParser = new parserFormula("MINIFS(E2:E7, F2:F7, \"Red\", G2:G7, \"*\", H2:H7, \">\" & 2023, I2:I7, \"A\", I2:I7, \"<>Z\")", "A1", ws); assert.ok(oParser.parse(), "MINIFS with complex criteria expressions"); assert.strictEqual(oParser.calculate().getValue(), 40, "MINIFS with complex criteria expressions"); // Test with criteria that select a single row oParser = new parserFormula("MINIFS(E2:E7, F2:F7, \"Red\", G2:G7, \"Large\", H2:H7, 2024, I2:I7, \"A\", E2:E7, 40)", "A1", ws); assert.ok(oParser.parse(), "MINIFS with criteria selecting one row"); assert.strictEqual(oParser.calculate().getValue(), 40, "MINIFS with criteria selecting one row"); }); QUnit.test("Test: \"TEXT\"", function (assert) { var culturelciddefault = AscCommon.g_oDefaultCultureInfo.LCID; oParser = new parserFormula("TEXT(1234.567,\"$0.00\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "$1234.57"); oParser = new parserFormula("TEXT(0.125,\"0.0%\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "12.5%"); oParser = new parserFormula("TEXT(123123,\"hh:mmm:ss\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00:Feb:00"); oParser = new parserFormula("TEXT(123123,\"hh:mmmm:ss\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00:February:00"); oParser = new parserFormula("TEXT(123123,\"hh:mmmmm:ss\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00:F:00"); testArrayFormula2(assert, "TEXT", 2, 2); //____________________________________en_____________________________________________ AscCommon.setCurrentCultureInfo(1033); oParser = new parserFormula("TEXT(123,\"yy-mm-dd\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00-05-02"); oParser = new parserFormula("TEXT(123,\"yy-MM-dd\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00-05-02"); oParser = new parserFormula("TEXT(123,\"hh:MM:ss\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00:00:00"); oParser = new parserFormula("TEXT(123,\"hh:mm:ss\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00:00:00"); oParser = new parserFormula("TEXT(123,\"general\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123"); oParser = new parserFormula("TEXT(123,\"0.00\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123.00"); oParser = new parserFormula("TEXT(123123123,\"#,###\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123,123,123"); oParser = new parserFormula("TEXT(123123123,\"#,##0.00\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123,123,123.00"); //todo // oParser = new parserFormula( "TEXT(123123123,\"###0,.00\")", "A2", ws ); // assert.ok( oParser.parse() ); // assert.strictEqual( oParser.calculate().getValue(), "123123.12" ); // // oParser = new parserFormula( "TEXT(123123123,\"###0,.00,\")", "A2", ws ); // assert.ok( oParser.parse() ); // assert.strictEqual( oParser.calculate().getValue(), "123.12" ); oParser = new parserFormula("TEXT(123123123,\"###0.,0,0\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123123123.00"); oParser = new parserFormula("TEXT(123123123,\"#,,,#,#,0.,,0,0\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123,123,123.00"); oParser = new parserFormula("TEXT(123123123,\"0,0,, q,w,,,w,,0,,0\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123,123,1 q,w,w,23"); oParser = new parserFormula("TEXT(123123123,\"00,,q,,,q00\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "1231231q,q23"); oParser = new parserFormula("TEXT(123123123,\"0,q,w,,\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123123q,w,"); oParser = new parserFormula("TEXT(123123123,\"#,,\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123"); oParser = new parserFormula("TEXT(123123123,\",,,#\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ",123123123"); oParser = new parserFormula("TEXT(123123123,\"###0,.\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123123."); oParser = new parserFormula("TEXT(123123123,\"###0.,\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123123."); oParser = new parserFormula("TEXT(123123123,\"###0.,q\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123123.q"); oParser = new parserFormula("TEXT(123123123,\"###0,.\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123123."); oParser = new parserFormula("TEXT(123123123,\"###0 ,\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123123123 ,"); oParser = new parserFormula("TEXT(123,\"hh qq\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00 qq"); oParser = new parserFormula("TEXT(123,\"dd hh\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "02 00"); oParser = new parserFormula("TEXT(123,\"aaa-aaaa am/pm\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "Wed-Wednesday AM"); AscCommon.setCurrentCultureInfo(culturelciddefault); //__________________________________fi________________________________________________ AscCommon.setCurrentCultureInfo(1035); oParser = new parserFormula("TEXT(123,\"vv-kk-pp\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00-05-02"); oParser = new parserFormula("TEXT(123,\"vv-mm-pp\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00-00-02"); oParser = new parserFormula("TEXT(123,\"tt.mm.ss\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00.00.00"); oParser = new parserFormula("TEXT(123,\"tt.MM.ss\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00.00.00"); oParser = new parserFormula("TEXT(123,\"tt.kk.ss\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00.05.00"); oParser = new parserFormula("TEXT(125,\"yleinen\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "125"); oParser = new parserFormula("TEXT(125,\"0,00\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "125,00"); oParser = new parserFormula("TEXT(125125,\"# ###\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "125 125"); oParser = new parserFormula("TEXT(123,\"pp tt\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "02 00"); oParser = new parserFormula("TEXT(123,\"p t\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "2 0"); oParser = new parserFormula("TEXT(123,\"tt qq\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00 qq"); oParser = new parserFormula("TEXT(123,\"aaa-aaaa\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "ke-keskiviikko"); AscCommon.setCurrentCultureInfo(culturelciddefault); //__________________________________fy________________________________________________ AscCommon.setCurrentCultureInfo(1043); oParser = new parserFormula("TEXT(123,\"jj-mm-dd\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00-05-02"); oParser = new parserFormula("TEXT(123,\"uu:mm:ss\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00:00:00"); oParser = new parserFormula("TEXT(126,\"standaard\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "126"); oParser = new parserFormula("TEXT(126,\"0,00\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "126,00"); oParser = new parserFormula("TEXT(126126,\"#.###\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "126.126"); oParser = new parserFormula("TEXT(123,\"dd uu\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "02 00"); oParser = new parserFormula("TEXT(123,\"d u\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "2 0"); oParser = new parserFormula("TEXT(123,\"uu qq\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00 qq"); oParser = new parserFormula("TEXT(123,\"aaa-aaaa\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "wo-woensdag"); AscCommon.setCurrentCultureInfo(culturelciddefault); //__________________________________es________________________________________________ AscCommon.setCurrentCultureInfo(3082); oParser = new parserFormula("TEXT(123,\"aa-mm-dd\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00-05-02"); oParser = new parserFormula("TEXT(123,\"estándar\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123"); oParser = new parserFormula("TEXT(123,\"hh:mm:ss\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00:00:00"); oParser = new parserFormula("TEXT(123,\"0,00\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123,00"); oParser = new parserFormula("TEXT(123123123,\"#.###\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123.123.123"); oParser = new parserFormula("TEXT(123,\"dd hh\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "02 00"); oParser = new parserFormula("TEXT(123,\"hh qq\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00 qq"); oParser = new parserFormula("TEXT(123,\"ooo-oooo\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "mi.-miércoles"); AscCommon.setCurrentCultureInfo(culturelciddefault); //___________________________________ru______________________________________________ AscCommon.setCurrentCultureInfo(1049); oParser = new parserFormula("TEXT(123,\"гг-ММ-дд\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00-05-02"); oParser = new parserFormula("TEXT(123,\"чч:ММ:сс\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00:00:00"); oParser = new parserFormula("TEXT(123,\"чч:мм:сс\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00:00:00"); oParser = new parserFormula("TEXT(123,\"гг-мм-дд\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00-00-02"); oParser = new parserFormula("TEXT(123,\"основной\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123"); oParser = new parserFormula("TEXT(123,\"0,00\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123,00"); oParser = new parserFormula("TEXT(123123123,\"# ###\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123 123 123"); oParser = new parserFormula("TEXT(123123123;\"# ##0,00\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123 123 123,00"); //todo // oParser = new parserFormula( "TEXT(123123123,\"###0 ,00\")", "A2", ws ); // assert.ok( oParser.parse() ); // assert.strictEqual( oParser.calculate().getValue(), "123123,12" ); // // oParser = new parserFormula( "TEXT(123123123,\"###0 ,00 \")", "A2", ws ); // assert.ok( oParser.parse() ); // assert.strictEqual( oParser.calculate().getValue(), "123,12" ); oParser = new parserFormula("TEXT(123123123,\"###0, 0 0\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123123123,00"); oParser = new parserFormula("TEXT(123123123,\"# # # 0, 0 0\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123 123 123,00"); oParser = new parserFormula("TEXT(123123123,\"0 0 q w w 0 0\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123 123 1q w w 23"); oParser = new parserFormula("TEXT(123123123,\"00 q q00\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "1231231q q23"); oParser = new parserFormula("TEXT(123123123,\"0 q w \")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123123q w "); oParser = new parserFormula("TEXT(123123123,\"# \")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123"); oParser = new parserFormula("TEXT(123123123,\" #\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), " 123123123"); oParser = new parserFormula("TEXT(123123123,\"###0 ,\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123123,"); oParser = new parserFormula("TEXT(123123123,\"###0, \")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123123,"); oParser = new parserFormula("TEXT(123,\"дд чч\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "02 00"); oParser = new parserFormula("TEXT(123,\"чч qq\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00 qq"); oParser = new parserFormula("TEXT(123,\"ММ мм\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "05 00"); oParser = new parserFormula("TEXT(123,\"aaa-aaaa\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "Ср-среда"); AscCommon.setCurrentCultureInfo(culturelciddefault); //__________________________________fr________________________________________________ AscCommon.setCurrentCultureInfo(1036); oParser = new parserFormula("TEXT(123,\"aa-mm-jj\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00-05-02"); oParser = new parserFormula("TEXT(123,\"hh:mm:ss\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00:00:00"); oParser = new parserFormula("TEXT(123,\"standard\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123"); oParser = new parserFormula("TEXT(123,\"0,00\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123,00"); oParser = new parserFormula("TEXT(123123123,\"# ###\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123 123 123"); oParser = new parserFormula("TEXT(123,\"jj hh\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "02 00"); oParser = new parserFormula("TEXT(123,\"j h\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "2 0"); oParser = new parserFormula("TEXT(123,\"hh qq\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00 qq"); oParser = new parserFormula("TEXT(123,\"ooo-oooo\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "mer.-mercredi"); AscCommon.setCurrentCultureInfo(culturelciddefault); //_______________________________de___________________________________________________ AscCommon.setCurrentCultureInfo(1031); oParser = new parserFormula("TEXT(123,\"jj-MM-tt\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00-05-02"); oParser = new parserFormula("TEXT(123,\"hh:mm:ss\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00:00:00"); oParser = new parserFormula("TEXT(123,\"hh:MM:ss\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00:00:00"); oParser = new parserFormula("TEXT(123,\"jj-mm-tt\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00-00-02"); oParser = new parserFormula("TEXT(123,\"standard\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123"); oParser = new parserFormula("TEXT(123,\"0,00\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123,00"); oParser = new parserFormula("TEXT(123123123,\"#.###\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123.123.123"); oParser = new parserFormula("TEXT(123,\"t h\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "2 0"); oParser = new parserFormula("TEXT(123,\"h qq\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "0 qq"); oParser = new parserFormula("TEXT(123,\"s t\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "0 2"); oParser = new parserFormula("TEXT(123,\"aaa-aaaa\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "Mi-Mittwoch"); AscCommon.setCurrentCultureInfo(culturelciddefault); //_______________________________it___________________________________________________ AscCommon.setCurrentCultureInfo(1040); oParser = new parserFormula("TEXT(123,\"aa-MM-gg\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00-05-02"); oParser = new parserFormula("TEXT(123,\"aa-mm-gg\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00-05-02"); oParser = new parserFormula("TEXT(123,\"hh:MM:ss\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00:00:00"); oParser = new parserFormula("TEXT(123,\"hh:mm:ss\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00:00:00"); oParser = new parserFormula("TEXT(123,\"standard\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123"); oParser = new parserFormula("TEXT(123,\"0,00\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123,00"); oParser = new parserFormula("TEXT(123123123,\"#.###\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123.123.123"); oParser = new parserFormula("TEXT(123,\"gg hh\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "02 00"); oParser = new parserFormula("TEXT(123,\"hh qq\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00 qq"); oParser = new parserFormula("TEXT(123,\"ooo-oooo\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "mer-mercoledì"); AscCommon.setCurrentCultureInfo(culturelciddefault); //_______________________________da____________________________________________________ AscCommon.setCurrentCultureInfo(1053); oParser = new parserFormula("TEXT(123,\"åå-MM-dd\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00-05-02"); oParser = new parserFormula("TEXT(123,\"åå-mm-dd\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00-00-02"); oParser = new parserFormula("TEXT(123,\"tt:mm:ss\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00:00:00"); oParser = new parserFormula("TEXT(123,\"tt:MM:ss\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00:00:00"); oParser = new parserFormula("TEXT(123,\"standard\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123"); oParser = new parserFormula("TEXT(123,\"0,00\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123,00"); oParser = new parserFormula("TEXT(123,\"0,00\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123,00"); oParser = new parserFormula("TEXT(123123123,\"# ###\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123 123 123"); oParser = new parserFormula("TEXT(123,\"dd tt\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "02 00"); oParser = new parserFormula("TEXT(123,\"tt qq\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00 qq"); oParser = new parserFormula("TEXT(123,\"aaa-aaaa\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "ons-onsdag"); AscCommon.setCurrentCultureInfo(culturelciddefault); //_____________________________ch________________________________________________ AscCommon.setCurrentCultureInfo(1028); oParser = new parserFormula("TEXT(123,\"g/通用格式\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123"); oParser = new parserFormula("TEXT(123,\"0.00\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123.00"); oParser = new parserFormula("TEXT(123,\"dd hh\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "02 00"); oParser = new parserFormula("TEXT(123,\"aaa-aaaa\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "週三-星期三"); AscCommon.setCurrentCultureInfo(culturelciddefault); //_____________________________el________________________________________________ AscCommon.setCurrentCultureInfo(1032); oParser = new parserFormula("TEXT(123,\"εε-μμ-ηη\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00-05-02"); oParser = new parserFormula("TEXT(123,\"ωω:λλ:δδ\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00:00:00"); oParser = new parserFormula("TEXT(123,\"γενικός τύπος\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123"); oParser = new parserFormula("TEXT(123,\"0,00\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123,00"); oParser = new parserFormula("TEXT(123123123,\"#.###\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123.123.123"); oParser = new parserFormula("TEXT(123,\"ηη ωω\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "02 00"); oParser = new parserFormula("TEXT(123,\"ωω qq\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00 qq"); oParser = new parserFormula("TEXT(123,\"ηη qq\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "02 qq"); oParser = new parserFormula("TEXT(123,\"δδ ηη\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00 02"); oParser = new parserFormula("TEXT(123,\"aaa-aaaa\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "Τετ-Τετάρτη"); AscCommon.setCurrentCultureInfo(culturelciddefault); //_____________________________hu________________________________________________ AscCommon.setCurrentCultureInfo(1038); oParser = new parserFormula("TEXT(123,\"éé-hh-nn\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00-05-02"); oParser = new parserFormula("TEXT(123,\"óó:pp:mm\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00:00:00"); oParser = new parserFormula("TEXT(123,\"éé-pp-nn\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00-00-02"); oParser = new parserFormula("TEXT(123,\"óó:hh:mm\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00:05:00"); oParser = new parserFormula("TEXT(125,\"normál\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "125"); oParser = new parserFormula("TEXT(125,\"0,00\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "125,00"); oParser = new parserFormula("TEXT(123123123,\"# ###\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123 123 123"); oParser = new parserFormula("TEXT(123,\"aaa-aaaa\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "Sze-szerda"); AscCommon.setCurrentCultureInfo(culturelciddefault); //_____________________________tr________________________________________________ AscCommon.setCurrentCultureInfo(1055); oParser = new parserFormula("TEXT(123,\"yy-aa-gg\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00-05-02"); oParser = new parserFormula("TEXT(123,\"ss:dd:nn\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00:00:00"); oParser = new parserFormula("TEXT(123,\"yy-dd-gg\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00-00-02"); oParser = new parserFormula("TEXT(123,\"ss:aa:nn\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00:05:00"); oParser = new parserFormula("TEXT(125,\"genel\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "125"); oParser = new parserFormula("TEXT(125,\"0,00\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "125,00"); oParser = new parserFormula("TEXT(123123123,\"#.###\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123.123.123"); oParser = new parserFormula("TEXT(123,\"aaa-aaaa\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "May-Mayıs"); AscCommon.setCurrentCultureInfo(culturelciddefault); //_____________________________pl________________________________________________ AscCommon.setCurrentCultureInfo(1045); oParser = new parserFormula("TEXT(123,\"rr-mm-dd\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00-05-02"); oParser = new parserFormula("TEXT(123,\"gg:mm:ss\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00:00:00"); oParser = new parserFormula("TEXT(125,\"standardowy\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "125"); oParser = new parserFormula("TEXT(125,\"0,00\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "125,00"); oParser = new parserFormula("TEXT(123123123,\"# ###\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123 123 123"); oParser = new parserFormula("TEXT(123,\"aaa-aaaa\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "śr.-środa"); AscCommon.setCurrentCultureInfo(culturelciddefault); //_____________________________cs________________________________________________ AscCommon.setCurrentCultureInfo(1029); oParser = new parserFormula("TEXT(123,\"rr-mm-dd\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00-05-02"); oParser = new parserFormula("TEXT(123,\"hh:mm:ss\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00:00:00"); oParser = new parserFormula("TEXT(123,\"vęeobecný\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123"); oParser = new parserFormula("TEXT(123,\"0,00\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123,00"); oParser = new parserFormula("TEXT(123123123,\"# ###\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123 123 123"); oParser = new parserFormula("TEXT(123,\"rr ss\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00 00"); oParser = new parserFormula("TEXT(123,\"dd hh\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "02 00"); oParser = new parserFormula("TEXT(123,\"hh qq\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "00 qq"); oParser = new parserFormula("TEXT(123,\"aaa-aaaa\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "st-středa"); AscCommon.setCurrentCultureInfo(culturelciddefault); //_____________________________ja________________________________________________ AscCommon.setCurrentCultureInfo(1041); oParser = new parserFormula("TEXT(124,\"G/標準\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "124"); oParser = new parserFormula("TEXT(123,\"0.00\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123.00"); oParser = new parserFormula("TEXT(123123123,\"#,###\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123,123,123"); //_____________________________ko________________________________________________ AscCommon.setCurrentCultureInfo(1042); oParser = new parserFormula("TEXT(124,\"g/표준\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "124"); oParser = new parserFormula("TEXT(123,\"0.00\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123.00"); oParser = new parserFormula("TEXT(123123123,\"#,###\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123,123,123"); oParser = new parserFormula("TEXT(123,\"aaa-aaaa\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "수-수요일"); AscCommon.setCurrentCultureInfo(culturelciddefault); }); QUnit.test("Test: \"TEXTJOIN\"", function (assert) { ws.getRange2("A2").setValue("Tulsa"); ws.getRange2("A3").setValue("Seattle"); ws.getRange2("A4").setValue("Iselin"); ws.getRange2("A5").setValue("Fort Lauderdale"); ws.getRange2("A6").setValue("Tempe"); ws.getRange2("A7").setValue("end"); ws.getRange2("B2").setValue("OK"); ws.getRange2("B3").setValue("WA"); ws.getRange2("B4").setValue("NJ"); ws.getRange2("B5").setValue("FL"); ws.getRange2("B6").setValue("AZ"); ws.getRange2("B7").setValue(""); ws.getRange2("C2").setValue("74133"); ws.getRange2("C3").setValue("98109"); ws.getRange2("C4").setValue("8830"); ws.getRange2("C5").setValue("33309"); ws.getRange2("C6").setValue("85285"); ws.getRange2("C7").setValue(""); ws.getRange2("D2").setValue("US"); ws.getRange2("D3").setValue("US"); ws.getRange2("D4").setValue("US"); ws.getRange2("D5").setValue("US"); ws.getRange2("D6").setValue("US"); ws.getRange2("D7").setValue(""); ws.getRange2("A9").setValue(","); ws.getRange2("B9").setValue(","); ws.getRange2("C9").setValue(","); ws.getRange2("D9").setValue(";"); oParser = new parserFormula("TEXTJOIN(A9:D9, TRUE, A2:D7)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "Tulsa,OK,74133,US;Seattle,WA,98109,US;Iselin,NJ,8830,US;Fort Lauderdale,FL,33309,US;Tempe,AZ,85285,US;end"); oParser = new parserFormula("TEXTJOIN(A9:D9, FALSE, A2:D7)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "Tulsa,OK,74133,US;Seattle,WA,98109,US;Iselin,NJ,8830,US;Fort Lauderdale,FL,33309,US;Tempe,AZ,85285,US;end,,,"); oParser = new parserFormula("TEXTJOIN(A2:D5, 1, B6:D6)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "AZTulsa85285OKUS"); testArrayFormulaEqualsValues(assert, "113.1233.123-4-4224455113.1233.123-4-4224455113.1233.123-4-422445,113.1233.123-4-4224455113.1233.123-4-4224455113.1233.123-4-422445,113.1233.123-4-4224455113.1233.123-4-4224455113.1233.123-4-422445,#N/A;113.1233.123-4-4224455113.1233.123-4-4224455113.1233.123-4-422445,113.1233.123-4-4224455113.1233.123-4-4224455113.1233.123-4-422445,113.1233.123-4-4224455113.1233.123-4-4224455113.1233.123-4-422445,#N/A;#N/A,#N/A,#N/A,#N/A", "TEXTJOIN(A1:C2,A1:C2,A1:C2,A1:C2, A1:C2)"); testArrayFormulaEqualsValues(assert, "113.1232-41224152113.1232-4122415,113.1232-41224152113.1232-4122415,113.1232-41224152113.1232-4122415,#N/A;113.1232-41224152113.1232-4122415,113.1232-41224152113.1232-4122415,113.1232-41224152113.1232-4122415,#N/A;#N/A,#N/A,#N/A,#N/A", "TEXTJOIN(A1:A2,A1:C2,A1:C2,A1:C2)"); testArrayFormulaEqualsValues(assert, "113.1233.123-4-4224455113.1233.123-4-4224455113.1233.123-4-4224455113.1233.123-4-422445,113.1233.123-4-4224455113.1233.123-4-4224455113.1233.123-4-4224455113.1233.123-4-422445,113.1233.123-4-4224455113.1233.123-4-4224455113.1233.123-4-4224455113.1233.123-4-422445,113.1233.123-4-4224455113.1233.123-4-4224455113.1233.123-4-4224455113.1233.123-4-422445;113.1233.123-4-4224455113.1233.123-4-4224455113.1233.123-4-4224455113.1233.123-4-422445,113.1233.123-4-4224455113.1233.123-4-4224455113.1233.123-4-4224455113.1233.123-4-422445,113.1233.123-4-4224455113.1233.123-4-4224455113.1233.123-4-4224455113.1233.123-4-422445,113.1233.123-4-4224455113.1233.123-4-4224455113.1233.123-4-4224455113.1233.123-4-422445;#N/A,#N/A,#N/A,#N/A", "TEXTJOIN(A1:C2,A1:A2,A1:C2,A1:C2,A1:C2,A1:C2)"); }); QUnit.test("Test: \"TEXTBEFORE\"", function (assert) { ws.getRange2("B2").setValue("TesttestTeesttestTESTttetstetest"); ws.getRange2("B3").setValue("test"); ws.getRange2("B4").setValue("test2"); oParser = new parserFormula("TEXTBEFORE(B2;B3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "Test"); oParser = new parserFormula("TEXTBEFORE(B2;B4)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); oParser = new parserFormula("TEXTBEFORE(B2;B3;1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "Test"); oParser = new parserFormula("TEXTBEFORE(B2;B3;2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TesttestTeest"); oParser = new parserFormula("TEXTBEFORE(B2;B3;3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TesttestTeesttestTESTttetste"); oParser = new parserFormula("TEXTBEFORE(B2;B3;4)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); oParser = new parserFormula("TEXTBEFORE(B2;B3;1;TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ""); oParser = new parserFormula("TEXTBEFORE(B2;B3;2;TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "Test"); oParser = new parserFormula("TEXTBEFORE(B2;B3;3;TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TesttestTeest"); oParser = new parserFormula("TEXTBEFORE(B2;B3;4;TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TesttestTeesttest"); oParser = new parserFormula("TEXTBEFORE(B2;B3;5;TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TesttestTeesttestTESTttetste"); oParser = new parserFormula("TEXTBEFORE(B2;B3;6, TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); oParser = new parserFormula("TEXTBEFORE(B2;B3;0, TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("TEXTBEFORE(B2;B3;-1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TesttestTeesttestTESTttetste"); oParser = new parserFormula("TEXTBEFORE(B2;B3;-2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TesttestTeest"); oParser = new parserFormula("TEXTBEFORE(B2;B3;-3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "Test"); oParser = new parserFormula("TEXTBEFORE(B2;B3;-4)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); oParser = new parserFormula("TEXTBEFORE(B2;B3;-1;TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TesttestTeesttestTESTttetste"); oParser = new parserFormula("TEXTBEFORE(B2;B3;-2;TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TesttestTeesttest"); oParser = new parserFormula("TEXTBEFORE(B2;B3;-3;TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TesttestTeest"); oParser = new parserFormula("TEXTBEFORE(B2;B3;-4;TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "Test"); oParser = new parserFormula("TEXTBEFORE(B2;B3;-5;TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ""); ws.getRange2("B2").setValue("12test434TESTtest233"); ws.getRange2("B3").setValue("TEST"); oParser = new parserFormula("TEXTBEFORE(B2;B3;1;TRUE;TRUE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "12"); oParser = new parserFormula("TEXTBEFORE(B2;B3;2;TRUE;TRUE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "12test434"); oParser = new parserFormula("TEXTBEFORE(B2;B3;3;TRUE;TRUE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "12test434TEST"); oParser = new parserFormula("TEXTBEFORE(B2;B3;4;TRUE;TRUE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "12test434TESTtest233"); oParser = new parserFormula("TEXTBEFORE(B2;B3;5;TRUE;TRUE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "error"); oParser = new parserFormula("TEXTBEFORE(B2;B3;5;TRUE;TRUE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "error"); oParser = new parserFormula("TEXTBEFORE(B2;B3;-1;TRUE;TRUE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "12test434TEST"); oParser = new parserFormula("TEXTBEFORE(B2;B3;-2;TRUE;TRUE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "12test434"); oParser = new parserFormula("TEXTBEFORE(B2;B3;-3;TRUE;TRUE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "12"); oParser = new parserFormula("TEXTBEFORE(B2;B3;-4;TRUE;TRUE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ""); oParser = new parserFormula("TEXTBEFORE(B2;B3;-5;TRUE;TRUE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "error"); oParser = new parserFormula("TEXTBEFORE(\"12tessdadsadtestt434TESTtest233sd\";\"TEST\";2;TRUE;TRUE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "12tessdadsadtestt434"); oParser = new parserFormula("TEXTBEFORE(\"12tessdadsadtestt434TESTtest233sd\";\"TEST\";;TRUE;TRUE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "12tessdadsad"); oParser = new parserFormula("TEXTBEFORE(\"12tessdadsadtestt434TESTtest233sd\";\"TEST\";;;;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "12tessdadsadtestt434"); oParser = new parserFormula("TEXTBEFORE(\"12tessdadsadtestt434TESTtest233sd\";;;;;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ""); oParser = new parserFormula("TEXTBEFORE(;;;;;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ""); oParser = new parserFormula("TEXTBEFORE(\"\",\",\",\"test\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("TEXTBEFORE(\"\",\",\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); oParser = new parserFormula("TEXTBEFORE(B1,\",\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); ws.getRange2("A1").setValue("TRUE1Brown,Jim"); oParser = new parserFormula("TEXTBEFORE(A1,{\"i\",\"n\",\"b\"})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TRUE1Brow"); oParser = new parserFormula("TEXTBEFORE(A1,{\"i\",\"n\",TRUE})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ""); oParser = new parserFormula("TEXTBEFORE(A1,{\"i\",\"n\",#VALUE!})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("TEXTBEFORE(A1,{\"i\",\"J\",\"o\",\"O\",\"m\"})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TRUE1Br"); ws.getRange2("A1").setValue("test125test2test3test4FALSEtest5"); ws.getRange2("B4").setValue("w"); ws.getRange2("C4").setValue("FALSE"); ws.getRange2("B5").setValue("tE"); ws.getRange2("C5").setValue("125te"); oParser = new parserFormula("TEXTBEFORE(A1,B4:C5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "test"); oParser = new parserFormula("TEXTBEFORE(A1,B4:C5, 0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("TEXTBEFORE(A1,B4:C5, 1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "test"); oParser = new parserFormula("TEXTBEFORE(A1,B4:C5, 2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "test125test2test3test4"); oParser = new parserFormula("TEXTBEFORE(A1,B4:C5, 3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); }); QUnit.test("Test: \"TEXTAFTER\"", function (assert) { ws.getRange2("C3").setValue("txttextTeXttextText234text stext text"); ws.getRange2("C6").setValue("te"); oParser = new parserFormula("TEXTAFTER(C3;C6;1;TRUE;TRUE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "xtTeXttextText234text stext text"); oParser = new parserFormula("TEXTAFTER(C3;C6;2;TRUE;TRUE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "XttextText234text stext text"); oParser = new parserFormula("TEXTAFTER(C3;C6;4;TRUE;TRUE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "xt234text stext text"); oParser = new parserFormula("TEXTAFTER(C3;C6;6;TRUE;TRUE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "xt text"); oParser = new parserFormula("TEXTAFTER(C3;C6;7;TRUE;TRUE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "xt"); oParser = new parserFormula("TEXTAFTER(C3;C6;8;TRUE;TRUE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ""); oParser = new parserFormula("TEXTAFTER(C3;C6;8;TRUE;FALSE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "error"); oParser = new parserFormula("TEXTAFTER(C3;C6;9;TRUE;TRUE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "error"); oParser = new parserFormula("TEXTAFTER(C3;C6;-1;TRUE;FALSE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "xt"); oParser = new parserFormula("TEXTAFTER(C3;C6;-2;TRUE;FALSE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "xt text"); oParser = new parserFormula("TEXTAFTER(C3;C6;-3;TRUE;FALSE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "xt stext text"); oParser = new parserFormula("TEXTAFTER(C3;C6;-4;TRUE;FALSE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "xt234text stext text"); oParser = new parserFormula("TEXTAFTER(C3;C6;-5;TRUE;FALSE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "xtText234text stext text"); oParser = new parserFormula("TEXTAFTER(C3;C6;-6;TRUE;FALSE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "XttextText234text stext text"); oParser = new parserFormula("TEXTAFTER(C3;C6;-7;TRUE;FALSE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "xtTeXttextText234text stext text"); oParser = new parserFormula("TEXTAFTER(C3;C6;-7;TRUE;FALSE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "xtTeXttextText234text stext text"); oParser = new parserFormula("TEXTAFTER(C3;C6;-8;TRUE;FALSE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "error"); oParser = new parserFormula("TEXTAFTER(C3;C6;-8;TRUE;TRUE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "txttextTeXttextText234text stext text"); oParser = new parserFormula("TEXTAFTER(C3:D4;C6;-8;TRUE;TRUE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "txttextTeXttextText234text stext text"); oParser = new parserFormula("TEXTAFTER(C3:D4;C6:D7;-8;TRUE;TRUE;\"error\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ""); oParser = new parserFormula("TEXTAFTER(C3;\"asdasd\";-8;TRUE;TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); oParser = new parserFormula("TEXTAFTER(12333;123;1;TRUE;TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "33"); oParser = new parserFormula("TEXTAFTER(12333;123;-1;TRUE;TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "33"); oParser = new parserFormula("TEXTAFTER(12333;123;-2;TRUE;TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "12333"); oParser = new parserFormula("TEXTAFTER(12333;123;3;TRUE;TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); oParser = new parserFormula("TEXTAFTER(\"\",\",\",\"test\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("TEXTAFTER(\"\",\",\",\"test\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("TEXTAFTER(\"\",\",\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); oParser = new parserFormula("TEXTAFTER(B1,\",\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); ws.getRange2("A1").setValue("TRUE1Brown,Jim"); oParser = new parserFormula("TEXTAFTER(A1,{\"i\",\"n\",\"b\"})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ",Jim"); oParser = new parserFormula("TEXTAFTER(A1,{\"i\",\"n\",TRUE})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "1Brown,Jim"); oParser = new parserFormula("TEXTAFTER(A1,{\"i\",\"n\",#VALUE!})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("TEXTAFTER(A1,{\"i\",\"J\",\"o\",\"O\",\"m\"})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "wn,Jim"); ws.getRange2("A1").setValue("test125test2test3test4FALSEtest5"); ws.getRange2("B4").setValue("w"); ws.getRange2("B5").setValue("test"); ws.getRange2("C4").setValue("FALSE"); ws.getRange2("C5").setValue("125"); oParser = new parserFormula("TEXTAFTER(A1,B4:C5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "125test2test3test4FALSEtest5"); ws.getRange2("B5").setValue("tE"); ws.getRange2("C5").setValue("125te"); oParser = new parserFormula("TEXTAFTER(A1,B4:C5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "st2test3test4FALSEtest5"); oParser = new parserFormula("TEXTAFTER(A1,B4:C5, 0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("TEXTAFTER(A1,B4:C5, 1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "st2test3test4FALSEtest5"); oParser = new parserFormula("TEXTAFTER(A1,B4:C5, 2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "test5"); oParser = new parserFormula("TEXTAFTER(A1,B4:C5, 3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); }); QUnit.test("Test: \"TEXTSPLIT\"", function (assert) { ws.getRange2("C3").setValue( "test1del1TEst2Del2#NUM!DEl2 test3 tedel3del3st3del1del1del1 del2del2del2 testdel1\n" + "test3 del1del2del1 test123testdel3testwDEL3test2DeL4jjjdel4rrrDEL123rrrdEl4"); ws.getRange2("C4").setValue("tedel1asd"); ws.getRange2("D3").setValue("fffdel1sdf"); ws.getRange2("D4").setValue("rflde1"); ws.getRange2("C5").setValue("del2"); ws.getRange2("D5").setValue("teST"); ws.getRange2("C6").setValue("del3"); ws.getRange2("D6").setValue("del1"); ws.getRange2("C11").setValue("error"); let array; oParser = new parserFormula("TEXTSPLIT(C3,\"del1\")", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "test1"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "TEst2Del2#NUM!DEl2 test3 tedel3del3st3"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), ""); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), ""); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), " del2del2del2 test"); assert.strictEqual(array.getElementRowCol(0, 5).getValue(), "\n" + "test3 "); assert.strictEqual(array.getElementRowCol(0, 6).getValue(), "del2"); assert.strictEqual(array.getElementRowCol(0, 7).getValue(), " test123testdel3testwDEL3test2DeL4jjjdel4rrrDEL123rrrdEl4"); oParser = new parserFormula("TEXTSPLIT(C3,{\"del1\",\"del2\"})", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "test1"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "TEst2Del2#NUM!DEl2 test3 tedel3del3st3"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), ""); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), ""); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), " "); assert.strictEqual(array.getElementRowCol(0, 5).getValue(), ""); assert.strictEqual(array.getElementRowCol(0, 6).getValue(), ""); assert.strictEqual(array.getElementRowCol(0, 7).getValue(), " test"); assert.strictEqual(array.getElementRowCol(0, 8).getValue(), "\n" + "test3 "); assert.strictEqual(array.getElementRowCol(0, 9).getValue(), ""); assert.strictEqual(array.getElementRowCol(0, 10).getValue(), ""); assert.strictEqual(array.getElementRowCol(0, 11).getValue(), " test123testdel3testwDEL3test2DeL4jjjdel4rrrDEL123rrrdEl4"); oParser = new parserFormula("TEXTSPLIT(C3,{\"del1\",\"del2\"},\"del3\")", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "test1"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "TEst2Del2#NUM!DEl2 test3 te"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), ""); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "st3"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), ""); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), ""); assert.strictEqual(array.getElementRowCol(2, 3).getValue(), " "); assert.strictEqual(array.getElementRowCol(2, 4).getValue(), ""); assert.strictEqual(array.getElementRowCol(2, 5).getValue(), ""); assert.strictEqual(array.getElementRowCol(2, 6).getValue(), " test"); assert.strictEqual(array.getElementRowCol(2, 7).getValue(), "\n" + "test3 "); assert.strictEqual(array.getElementRowCol(2, 8).getValue(), ""); assert.strictEqual(array.getElementRowCol(2, 9).getValue(), ""); assert.strictEqual(array.getElementRowCol(2, 10).getValue(), " test123test"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "testwDEL3test2DeL4jjjdel4rrrDEL123rrrdEl4"); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), "#N/A"); assert.strictEqual(array.getElementRowCol(3, 2).getValue(), "#N/A"); oParser = new parserFormula("TEXTSPLIT(C3,{\"del1\",\"del2\"},\"del3\",,TRUE)", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 'test1'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 'test2'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), '#num!'); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), ' test3 te'); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), '#N/A'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), ''); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), '#N/A'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 'st3'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), ''); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), ''); assert.strictEqual(array.getElementRowCol(2, 3).getValue(), ' '); assert.strictEqual(array.getElementRowCol(2, 4).getValue(), ''); assert.strictEqual(array.getElementRowCol(2, 5).getValue(), ''); assert.strictEqual(array.getElementRowCol(2, 6).getValue(), ' test'); assert.strictEqual(array.getElementRowCol(2, 7).getValue(), "\n" + "test3 "); assert.strictEqual(array.getElementRowCol(2, 8).getValue(), ''); assert.strictEqual(array.getElementRowCol(2, 9).getValue(), ''); assert.strictEqual(array.getElementRowCol(2, 10).getValue(), ' test123test'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 'testw'); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), '#N/A'); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 'test2del4jjjdel4rrr'); assert.strictEqual(array.getElementRowCol(4, 1).getValue(), '23rrrdel4'); assert.strictEqual(array.getElementRowCol(4, 2).getValue(), '#N/A'); oParser = new parserFormula("TEXTSPLIT(C3,{\"del2\"},{\"del3\",\"del1\"},FALSE,TRUE,\"error\")", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 'test1'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), ''); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 'test2'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), '#num!'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), ' test3 te'); assert.strictEqual(array.getElementRowCol(1, 3).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), ''); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(2, 3).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 'st3'); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(3, 2).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(3, 3).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), ''); assert.strictEqual(array.getElementRowCol(4, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(4, 2).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(4, 3).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), ''); assert.strictEqual(array.getElementRowCol(5, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(5, 2).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(5, 3).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), ' '); assert.strictEqual(array.getElementRowCol(6, 1).getValue(), ''); assert.strictEqual(array.getElementRowCol(6, 2).getValue(), ''); assert.strictEqual(array.getElementRowCol(6, 3).getValue(), ' test'); assert.strictEqual(array.getElementRowCol(7, 0).getValue(), "\n" + "test3 "); assert.strictEqual(array.getElementRowCol(7, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(7, 2).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(7, 3).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(8, 0).getValue(), ''); assert.strictEqual(array.getElementRowCol(8, 1).getValue(), ''); assert.strictEqual(array.getElementRowCol(8, 2).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(8, 3).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(9, 0).getValue(), ' test123test'); assert.strictEqual(array.getElementRowCol(9, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(9, 2).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(9, 3).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(10, 0).getValue(), 'testw'); assert.strictEqual(array.getElementRowCol(10, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(10, 2).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(10, 3).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(11, 0).getValue(), 'test2del4jjjdel4rrr'); assert.strictEqual(array.getElementRowCol(11, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(11, 2).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(11, 3).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(12, 0).getValue(), '23rrrdel4'); assert.strictEqual(array.getElementRowCol(12, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(12, 2).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(12, 3).getValue(), 'error'); oParser = new parserFormula("TEXTSPLIT(C3,{\"del2\"},{\"del3\",\"del1\"},TRUE,TRUE,\"error\")", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 'test1'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 'test2'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), '#num!'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), ' test3 te'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 'st3'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), ' '); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), ' test'); assert.strictEqual(array.getElementRowCol(3, 2).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "\n" + "test3 "); assert.strictEqual(array.getElementRowCol(4, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(4, 2).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), ' test123test'); assert.strictEqual(array.getElementRowCol(5, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(5, 2).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), 'testw'); assert.strictEqual(array.getElementRowCol(6, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(6, 2).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(7, 0).getValue(), 'test2del4jjjdel4rrr'); assert.strictEqual(array.getElementRowCol(7, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(7, 2).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(8, 0).getValue(), '23rrrdel4'); assert.strictEqual(array.getElementRowCol(8, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(8, 2).getValue(), 'error'); oParser = new parserFormula("TEXTSPLIT(C3,{\"del2\",\"teST\"},{\"del3\",\"del1\"},TRUE,,\"error\")", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 'test1'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 'TEst2Del2#NUM!DEl2 test3 te'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 'st3'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), ' '); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), ' test'); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "\n" + "test3 "); assert.strictEqual(array.getElementRowCol(4, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), ' test123test'); assert.strictEqual(array.getElementRowCol(5, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), 'testwDEL3test2DeL4jjjdel4rrrDEL123rrrdEl4'); assert.strictEqual(array.getElementRowCol(6, 1).getValue(), 'error'); oParser = new parserFormula("TEXTSPLIT(C3,,\"del\",,,)", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 'test1'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), '1TEst2Del2#NUM!DEl2 test3 te'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), '3'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), '3st3'); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), '1'); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), '1'); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), '1 '); assert.strictEqual(array.getElementRowCol(7, 0).getValue(), '2'); assert.strictEqual(array.getElementRowCol(8, 0).getValue(), '2'); assert.strictEqual(array.getElementRowCol(9, 0).getValue(), '2 test'); assert.strictEqual(array.getElementRowCol(10, 0).getValue(), "1\n" + "test3 "); assert.strictEqual(array.getElementRowCol(11, 0).getValue(), '1'); assert.strictEqual(array.getElementRowCol(12, 0).getValue(), '2'); assert.strictEqual(array.getElementRowCol(13, 0).getValue(), '1 test123test'); assert.strictEqual(array.getElementRowCol(14, 0).getValue(), '3testwDEL3test2DeL4jjj'); assert.strictEqual(array.getElementRowCol(15, 0).getValue(), '4rrrDEL123rrrdEl4'); oParser = new parserFormula("TEXTSPLIT(C3,,,,,)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("TEXTSPLIT(C3,\"test\",\"\",,,)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("TEXTSPLIT(C3,,,,,)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("TEXTSPLIT(C2,\"\",\"test\",,,)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("TEXTSPLIT(C3:D4,\"del1\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "test1"); oParser = new parserFormula("TEXTSPLIT(C3,C5:D5,C6:D6,TRUE,,C11)", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 'test1'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 'TEst2Del2#NUM!DEl2 test3 te'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 'st3'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), ' '); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), ' test'); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "\n" + "test3 "); assert.strictEqual(array.getElementRowCol(4, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), ' test123test'); assert.strictEqual(array.getElementRowCol(5, 1).getValue(), 'error'); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), 'testwDEL3test2DeL4jjjdel4rrrDEL123rrrdEl4'); assert.strictEqual(array.getElementRowCol(6, 1).getValue(), 'error'); oParser = new parserFormula("TEXTSPLIT(C3,C5:D5,C6:D6,TRUE,,C11:D11)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("TEXTSPLIT(C3,C5:D5,C6:D6,{TRUE,FALSE},,C11)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "test1"); /*oParser = new parserFormula("TEXTSPLIT(C3,C5:D5,C6:D6,C59:D59,{TRUE,FALSE},C11)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "test1");*/ ws.getRange2("A2").setValue("Do. Or do not. There is no try. -Anonymous"); oParser = new parserFormula("TEXTSPLIT(A2,,\".\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "Do"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue(), " Or do not"); assert.strictEqual(oParser.calculate().getElementRowCol(2, 0).getValue(), " There is no try"); assert.strictEqual(oParser.calculate().getElementRowCol(3, 0).getValue(), " -Anonymous"); oParser = new parserFormula("TEXTSPLIT(A2,,{\".\";\"-\"})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "Do"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue(), " Or do not"); assert.strictEqual(oParser.calculate().getElementRowCol(2, 0).getValue(), " There is no try"); assert.strictEqual(oParser.calculate().getElementRowCol(3, 0).getValue(), " "); assert.strictEqual(oParser.calculate().getElementRowCol(4, 0).getValue(), "Anonymous"); oParser = new parserFormula("TEXTSPLIT(A2,,{\".\";\"d\"})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "Do"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue(), " Or "); assert.strictEqual(oParser.calculate().getElementRowCol(2, 0).getValue(), "o not"); assert.strictEqual(oParser.calculate().getElementRowCol(3, 0).getValue(), " There is no try"); assert.strictEqual(oParser.calculate().getElementRowCol(4, 0).getValue(), " -Anonymous"); ws.getRange2("C1").setValue("1"); oParser = new parserFormula("TEXTSPLIT(A2,C1,C1,C1,C1,C1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "do. or do not. there is no try. -anonymous"); oParser = new parserFormula("TEXTSPLIT(A2,,C1,C1,C1,C1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "do. or do not. there is no try. -anonymous"); oParser = new parserFormula("TEXTSPLIT(A2,,,C1,C1,C1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("TEXTSPLIT(A2,,C1,,C1,C1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "do. or do not. there is no try. -anonymous"); oParser = new parserFormula("TEXTSPLIT(A2,,C1,,,C1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "Do. Or do not. There is no try. -Anonymous"); oParser = new parserFormula("TEXTSPLIT(A2,,C1,,,)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "Do. Or do not. There is no try. -Anonymous"); }); function putStackData() { ws.getRange2("A1").setValue("2"); ws.getRange2("A2").setValue("w"); ws.getRange2("A3").setValue("test"); ws.getRange2("B1").setValue("test2"); ws.getRange2("B2").setValue("3"); ws.getRange2("B3").setValue("4"); ws.getRange2("A1").setValue("2"); ws.getRange2("A2").setValue("w"); ws.getRange2("A3").setValue("test"); ws.getRange2("B5").setValue("test11"); ws.getRange2("C5").setValue("test12"); ws.getRange2("D5").setValue("test13"); ws.getRange2("B8").setValue("test13"); ws.getRange2("B9").setValue("test14"); ws.getRange2("B10").setValue("#VALUE!"); ws.getRange2("B11").setValue("test16"); ws.getRange2("B14").setValue("f"); ws.getRange2("B15").setValue("s"); ws.getRange2("B16").setValue("d"); ws.getRange2("B17").setValue("s"); ws.getRange2("B18").setValue("d"); ws.getRange2("C14").setValue("g"); ws.getRange2("C15").setValue(""); ws.getRange2("C16").setValue(""); ws.getRange2("C17").setValue("dfg"); ws.getRange2("C18").setValue(""); ws.getRange2("D14").setValue("h"); ws.getRange2("D15").setValue("d"); ws.getRange2("D16").setValue("g"); ws.getRange2("D17").setValue("s"); ws.getRange2("D18").setValue(""); ws.getRange2("E14").setValue("g"); ws.getRange2("E15").setValue("f"); ws.getRange2("E16").setValue("f"); ws.getRange2("E17").setValue("d"); ws.getRange2("E18").setValue("g"); } QUnit.test("Test: \"VSTACK\"", function (assert) { //1. добавляем общие тесты putStackData(); oParser = new parserFormula("VSTACK(A1:B3,B5:D5,B8:B11,B14:E18)", "A1", ws); assert.ok(oParser.parse()); let array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 'test2'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), '#N/A'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 'w'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 3); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 'test'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 4); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 'test11'); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), 'test12'); assert.strictEqual(array.getElementRowCol(3, 2).getValue(), 'test13'); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 'test13'); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 'test14'); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), '#VALUE!'); assert.strictEqual(array.getElementRowCol(7, 0).getValue(), 'test16'); assert.strictEqual(array.getElementRowCol(8, 0).getValue(), 'f'); assert.strictEqual(array.getElementRowCol(8, 1).getValue(), 'g'); assert.strictEqual(array.getElementRowCol(8, 2).getValue(), 'h'); assert.strictEqual(array.getElementRowCol(8, 3).getValue(), 'g'); assert.strictEqual(array.getElementRowCol(9, 0).getValue(), 's'); assert.strictEqual(array.getElementRowCol(9, 1).getValue(), ''); assert.strictEqual(array.getElementRowCol(9, 2).getValue(), 'd'); assert.strictEqual(array.getElementRowCol(9, 3).getValue(), 'f'); assert.strictEqual(array.getElementRowCol(10, 0).getValue(), 'd'); assert.strictEqual(array.getElementRowCol(10, 1).getValue(), ''); assert.strictEqual(array.getElementRowCol(10, 2).getValue(), 'g'); assert.strictEqual(array.getElementRowCol(10, 3).getValue(), 'f'); assert.strictEqual(array.getElementRowCol(11, 0).getValue(), 's'); assert.strictEqual(array.getElementRowCol(11, 1).getValue(), 'dfg'); assert.strictEqual(array.getElementRowCol(11, 2).getValue(), 's'); assert.strictEqual(array.getElementRowCol(11, 3).getValue(), 'd'); assert.strictEqual(array.getElementRowCol(12, 0).getValue(), 'd'); assert.strictEqual(array.getElementRowCol(12, 1).getValue(), ''); assert.strictEqual(array.getElementRowCol(12, 2).getValue(), ''); assert.strictEqual(array.getElementRowCol(12, 3).getValue(), 'g'); //2. аргументы - разные типы. нужно пербрать все аргументы //2.1 аргумент - number oParser = new parserFormula("VSTACK(1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.2 аргумент - string oParser = new parserFormula("VSTACK(\"test\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "test"); //2.3 аргумент - bool oParser = new parserFormula("VSTACK(true)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "TRUE"); //2.4 аргумент - error oParser = new parserFormula("VSTACK(#VALUE!)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.5 аргумент - empty oParser = new parserFormula("VSTACK(1,,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.6 аргумент - cellsRange //2.7 аргумент - cell oParser = new parserFormula("VSTACK(B1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "test2"); //2.8 аргумент - array oParser = new parserFormula("VSTACK({1,2})", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2); }); QUnit.test("Test: \"HSTACK\"", function (assert) { //1. добавляем общие тесты putStackData(); oParser = new parserFormula("HSTACK(A1:B3,B5:D5,B8:B11,B14:E18,A1)", "A1", ws); assert.ok(oParser.parse()); let array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 'test2'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 'test11'); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 'test12'); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), 'test13'); assert.strictEqual(array.getElementRowCol(0, 5).getValue(), 'test13'); assert.strictEqual(array.getElementRowCol(0, 6).getValue(), 'f'); assert.strictEqual(array.getElementRowCol(0, 7).getValue(), 'g'); assert.strictEqual(array.getElementRowCol(0, 8).getValue(), 'h'); assert.strictEqual(array.getElementRowCol(0, 9).getValue(), 'g'); assert.strictEqual(array.getElementRowCol(0, 10).getValue(), 2); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 'w'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 3); assert.strictEqual(array.getElementRowCol(1, 5).getValue(), 'test14'); assert.strictEqual(array.getElementRowCol(1, 6).getValue(), 's'); assert.strictEqual(array.getElementRowCol(1, 7).getValue(), ''); assert.strictEqual(array.getElementRowCol(1, 8).getValue(), 'd'); assert.strictEqual(array.getElementRowCol(1, 9).getValue(), 'f'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 'test'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 4); assert.strictEqual(array.getElementRowCol(2, 5).getValue(), '#VALUE!'); assert.strictEqual(array.getElementRowCol(2, 6).getValue(), 'd'); assert.strictEqual(array.getElementRowCol(2, 7).getValue(), ''); assert.strictEqual(array.getElementRowCol(2, 8).getValue(), 'g'); assert.strictEqual(array.getElementRowCol(2, 9).getValue(), 'f'); assert.strictEqual(array.getElementRowCol(3, 5).getValue(), 'test16'); assert.strictEqual(array.getElementRowCol(3, 6).getValue(), 's'); assert.strictEqual(array.getElementRowCol(3, 7).getValue(), 'dfg'); assert.strictEqual(array.getElementRowCol(3, 8).getValue(), 's'); assert.strictEqual(array.getElementRowCol(3, 9).getValue(), 'd'); assert.strictEqual(array.getElementRowCol(4, 6).getValue(), 'd'); assert.strictEqual(array.getElementRowCol(4, 7).getValue(), ''); assert.strictEqual(array.getElementRowCol(4, 8).getValue(), ''); assert.strictEqual(array.getElementRowCol(4, 9).getValue(), 'g'); //2. аргументы - разные типы. нужно пербрать все аргументы //2.1 аргумент - number oParser = new parserFormula("HSTACK(1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.2 аргумент - string oParser = new parserFormula("HSTACK(\"test\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "test"); //2.3 аргумент - bool oParser = new parserFormula("HSTACK(true)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "TRUE"); //2.4 аргумент - error oParser = new parserFormula("HSTACK(#VALUE!)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.5 аргумент - empty oParser = new parserFormula("HSTACK(1,,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.6 аргумент - cellsRange //2.7 аргумент - cell oParser = new parserFormula("HSTACK(B1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "test2"); //2.8 аргумент - array oParser = new parserFormula("HSTACK({1,2})", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2); }); QUnit.test("Test: \"TOROW\"", function (assert) { //1. добавляем общие тесты ws.getRange2("A1").setValue("2"); ws.getRange2("A2").setValue(""); ws.getRange2("A3").setValue("test"); ws.getRange2("B1").setValue("test2"); ws.getRange2("B2").setValue("#N/A"); ws.getRange2("B3").setValue(""); oParser = new parserFormula("TOROW(A1:B3,0, FALSE)", "A1", ws); assert.ok(oParser.parse()); let array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 'test2'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), ''); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), '#N/A'); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), 'test'); assert.strictEqual(array.getElementRowCol(0, 5).getValue(), ''); oParser = new parserFormula("TOROW(A1:B3,1, FALSE)", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 'test2'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), '#N/A'); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 'test'); oParser = new parserFormula("TOROW(A1:B3,2, FALSE)", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 'test2'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), ''); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 'test'); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), ''); assert.strictEqual(array.getElementRowCol(0, 5).getValue(), ''); oParser = new parserFormula("TOROW(A1:B3,3,FALSE)", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 'test2'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 'test'); //2. аргументы - разные типы. нужно пербрать все аргументы //2.1 аргумент - number oParser = new parserFormula("TOROW(1,3,FALSE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.2 аргумент - string oParser = new parserFormula("TOROW(\"test\",3,FALSE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "test"); //2.3 аргумент - bool oParser = new parserFormula("TOROW(true)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "TRUE"); //2.4 аргумент - error oParser = new parserFormula("TOROW(#VALUE!)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.5 аргумент - empty oParser = new parserFormula("TOROW(1,,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.6 аргумент - cellsRange //2.7 аргумент - cell oParser = new parserFormula("TOROW(B1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "test2"); //2.8 аргумент - array oParser = new parserFormula("TOROW({1,2})", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2); oParser = new parserFormula("TOROW(1,{1,2,3},FALSE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); oParser = new parserFormula("TOROW(1,{1,2,3},{false,true})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); oParser = new parserFormula("TOROW(1,A1:A3,{false,true})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); oParser = new parserFormula("TOROW(1,A1:A3,A1:A3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); // for bug 69719 let sheetName = ws.getName(); ws.getRange2("C1").setValue("test3"); ws.getRange2("D1").setValue("test4"); ws.getRange2("E1").setValue("test5"); oParser = new parserFormula("TOROW("+sheetName+"!A1:A3)", "A1", ws); assert.ok(oParser.parse(), "TOROW("+sheetName+"!A1:A3)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of TOROW("+sheetName+"!A1:A3)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of TOROW("+sheetName+"!A1:A3)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "test", "Result of TOROW("+sheetName+"!A1:A3)[0,2]"); oParser = new parserFormula("TOROW("+sheetName+"!A1:E1)", "A1", ws); assert.ok(oParser.parse(), "TOROW("+sheetName+"!A1:E1)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of TOROW("+sheetName+"!A1:E1)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "test2", "Result of TOROW("+sheetName+"!A1:E1)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "test3", "Result of TOROW("+sheetName+"!A1:E1)[0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "test4", "Result of TOROW("+sheetName+"!A1:E1)[0,3]"); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), "test5", "Result of TOROW("+sheetName+"!A1:E1)[0,4]"); oParser = new parserFormula("TOROW("+sheetName+"!A1:B3)", "A1", ws); assert.ok(oParser.parse(), "TOROW("+sheetName+"!A1:B3)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of TOROW("+sheetName+"!A1:B3)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "test2", "Result of TOROW("+sheetName+"!A1:B3)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "", "Result of TOROW("+sheetName+"!A1:B3)[0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "#N/A", "Result of TOROW("+sheetName+"!A1:B3)[0,3]"); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), "test", "Result of TOROW("+sheetName+"!A1:B3)[0,4]"); assert.strictEqual(array.getElementRowCol(0, 5).getValue(), "", "Result of TOROW("+sheetName+"!A1:B3)[0,5]"); }); QUnit.test("Test: \"TOCOL\"", function (assert) { //1. добавляем общие тесты ws.getRange2("A1").setValue("2"); ws.getRange2("A2").setValue(""); ws.getRange2("A3").setValue("test"); ws.getRange2("B1").setValue("test2"); ws.getRange2("B2").setValue("#N/A"); ws.getRange2("B3").setValue(""); oParser = new parserFormula("TOCOL(A1:B3,0, FALSE)", "A1", ws); assert.ok(oParser.parse()); let array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 'test2'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), ''); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), '#N/A'); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 'test'); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), ''); oParser = new parserFormula("TOCOL(A1:B3,1, FALSE)", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 'test2'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), '#N/A'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 'test'); oParser = new parserFormula("TOCOL(A1:B3,2, FALSE)", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 'test2'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), ''); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 'test'); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), ''); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), ''); oParser = new parserFormula("TOCOL(A1:B3,3,FALSE)", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 'test2'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 'test'); //2. аргументы - разные типы. нужно пербрать все аргументы //2.1 аргумент - number oParser = new parserFormula("TOCOL(1,3,FALSE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.2 аргумент - string oParser = new parserFormula("TOCOL(\"test\",3,FALSE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "test"); //2.3 аргумент - bool oParser = new parserFormula("TOCOL(true)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "TRUE"); //2.4 аргумент - error oParser = new parserFormula("TOCOL(#VALUE!)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.5 аргумент - empty oParser = new parserFormula("TOCOL(1,,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.6 аргумент - cellsRange //2.7 аргумент - cell oParser = new parserFormula("TOCOL(B1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "test2"); //2.8 аргумент - array oParser = new parserFormula("TOCOL({1,2})", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2); oParser = new parserFormula("TOCOL(1,{1,2,3},FALSE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); oParser = new parserFormula("TOCOL(1,{1,2,3},{false,true})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); oParser = new parserFormula("TOCOL(1,A1:A3,{false,true})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); oParser = new parserFormula("TOCOL(1,A1:A3,A1:A3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); // for bug 69719 let sheetName = ws.getName(); ws.getRange2("C1").setValue("test3"); ws.getRange2("D1").setValue("test4"); ws.getRange2("E1").setValue("test5"); oParser = new parserFormula("TOCOL("+sheetName+"!A1:A3)", "A1", ws); assert.ok(oParser.parse(), "TOCOL("+sheetName+"!A1:A3)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of TOCOL("+sheetName+"!A1:A3)[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of TOCOL("+sheetName+"!A1:A3)[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "test", "Result of TOCOL("+sheetName+"!A1:A3)[2,0]"); oParser = new parserFormula("TOCOL("+sheetName+"!A1:E1)", "A1", ws); assert.ok(oParser.parse(), "TOCOL("+sheetName+"!A1:E1)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of TOCOL("+sheetName+"!A1:E1)[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "test2", "Result of TOCOL("+sheetName+"!A1:E1)[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "test3", "Result of TOCOL("+sheetName+"!A1:E1)[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "test4", "Result of TOCOL("+sheetName+"!A1:E1)[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "test5", "Result of TOCOL("+sheetName+"!A1:E1)[4,0]"); oParser = new parserFormula("TOCOL("+sheetName+"!A1:B3)", "A1", ws); assert.ok(oParser.parse(), "TOCOL("+sheetName+"!A1:E1)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of TOCOL("+sheetName+"!A1:B3)[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "test2", "Result of TOCOL("+sheetName+"!A1:B3)[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", "Result of TOCOL("+sheetName+"!A1:B3)[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#N/A", "Result of TOCOL("+sheetName+"!A1:B3)[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "test", "Result of TOCOL("+sheetName+"!A1:B3)[4,0]"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), "", "Result of TOCOL("+sheetName+"!A1:B3)[5,0]"); // assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); }); QUnit.test("Test: \"WRAPROWS\"", function (assert) { //1. добавляем общие тесты ws.getRange2("A1").setValue("2"); ws.getRange2("A2").setValue(""); ws.getRange2("A3").setValue("test"); ws.getRange2("B1").setValue("test2"); ws.getRange2("B2").setValue("#N/A"); ws.getRange2("B3").setValue(""); oParser = new parserFormula("WRAPROWS(1,A1:B5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); oParser = new parserFormula("WRAPROWS(A1:A3,2)", "A1", ws); assert.ok(oParser.parse()); let array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), ''); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 'test'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), '#N/A'); oParser = new parserFormula("WRAPROWS(A1:A3,2, \"error\")", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), ''); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 'test'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 'error'); oParser = new parserFormula("WRAPROWS(A1:B3,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2. аргументы - разные типы. нужно пербрать все аргументы //2.1 аргумент - number oParser = new parserFormula("WRAPROWS(1,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.2 аргумент - string oParser = new parserFormula("WRAPROWS(\"test\",3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "test"); //2.3 аргумент - bool oParser = new parserFormula("WRAPROWS(true,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "TRUE"); //2.4 аргумент - error oParser = new parserFormula("WRAPROWS(#VALUE!,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.5 аргумент - empty oParser = new parserFormula("WRAPROWS(,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.6 аргумент - cellsRange //2.7 аргумент - cell oParser = new parserFormula("WRAPROWS(B1, 10)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "test2"); //2.8 аргумент - array oParser = new parserFormula("WRAPROWS({2;\"\";\"test\"},2)", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), ''); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 'test'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), '#N/A'); //2.2 аргумент - string oParser = new parserFormula("WRAPROWS(1,\"test\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.3 аргумент - bool oParser = new parserFormula("WRAPROWS(1,true)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.4 аргумент - error oParser = new parserFormula("WRAPROWS(1, #VALUE!)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.5 аргумент - empty oParser = new parserFormula("WRAPROWS(1,)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); //2.6 аргумент - cellsRange //2.7 аргумент - cell oParser = new parserFormula("WRAPROWS(1,A1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); oParser = new parserFormula("WRAPROWS(1,A1:B5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.8 аргумент - array oParser = new parserFormula("WRAPROWS(1,{2;\"\";\"test\"})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2. аргументы - разные типы. нужно пербрать все аргументы //2.1 аргумент - number oParser = new parserFormula("WRAPROWS(1,3,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.2 аргумент - string oParser = new parserFormula("WRAPROWS(1,3,\"test\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.3 аргумент - bool oParser = new parserFormula("WRAPROWS(1,3,true)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.4 аргумент - error oParser = new parserFormula("WRAPROWS(1,3,#VALUE!)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.5 аргумент - empty oParser = new parserFormula("WRAPROWS(1,3,)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.6 аргумент - cellsRange //2.7 аргумент - cell oParser = new parserFormula("WRAPROWS(1,3, B1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.8 аргумент - array oParser = new parserFormula("WRAPROWS(1,3, {1,2,3})", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1); oParser = new parserFormula("WRAPROWS(1,3, B1:B2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); oParser = new parserFormula("WRAPROWS(1,0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("WRAPROWS(1,-100)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("WRAPROWS(1,)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("WRAPROWS(1,\"asd\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); }); QUnit.test("Test: \"WRAPCOLS\"", function (assert) { //1. добавляем общие тесты ws.getRange2("A1").setValue("2"); ws.getRange2("A2").setValue(""); ws.getRange2("A3").setValue("test"); ws.getRange2("A4").setValue("rwe"); ws.getRange2("B1").setValue("test2"); ws.getRange2("B2").setValue("#N/A"); ws.getRange2("B3").setValue(""); oParser = new parserFormula("WRAPCOLS(1,A1:B5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); oParser = new parserFormula("WRAPCOLS(A1:A3,2)", "A1", ws); assert.ok(oParser.parse()); let array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), ''); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 'test'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), '#N/A'); oParser = new parserFormula("WRAPCOLS(A1:A3,2, \"error\")", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), ''); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 'test'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 'error'); oParser = new parserFormula("WRAPCOLS(A1:B3,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2. аргументы - разные типы. нужно пербрать все аргументы //2.1 аргумент - number oParser = new parserFormula("WRAPCOLS(1,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.2 аргумент - string oParser = new parserFormula("WRAPCOLS(\"test\",3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "test"); //2.3 аргумент - bool oParser = new parserFormula("WRAPCOLS(true,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "TRUE"); //2.4 аргумент - error oParser = new parserFormula("WRAPCOLS(#VALUE!,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.5 аргумент - empty oParser = new parserFormula("WRAPCOLS(,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.6 аргумент - cellsRange //2.7 аргумент - cell oParser = new parserFormula("WRAPCOLS(B1, 10)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "test2"); //2.8 аргумент - array oParser = new parserFormula("WRAPCOLS({2;\"\";\"test\"},2)", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), ''); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 'test'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), '#N/A'); //2.2 аргумент - string oParser = new parserFormula("WRAPCOLS(1,\"test\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.3 аргумент - bool oParser = new parserFormula("WRAPCOLS(1,true)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.4 аргумент - error oParser = new parserFormula("WRAPCOLS(1, #VALUE!)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.5 аргумент - empty oParser = new parserFormula("WRAPCOLS(1,)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); //2.6 аргумент - cellsRange //2.7 аргумент - cell oParser = new parserFormula("WRAPCOLS(1,A1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); oParser = new parserFormula("WRAPCOLS(1,A1:B5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.8 аргумент - array oParser = new parserFormula("WRAPCOLS(1,{2;\"\";\"test\"})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2. аргументы - разные типы. нужно пербрать все аргументы //2.1 аргумент - number oParser = new parserFormula("WRAPCOLS(1,3,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.2 аргумент - string oParser = new parserFormula("WRAPCOLS(1,3,\"test\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.3 аргумент - bool oParser = new parserFormula("WRAPCOLS(1,3,true)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.4 аргумент - error oParser = new parserFormula("WRAPCOLS(1,3,#VALUE!)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.5 аргумент - empty oParser = new parserFormula("WRAPCOLS(1,3,)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.6 аргумент - cellsRange //2.7 аргумент - cell oParser = new parserFormula("WRAPCOLS(1,3, B1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.8 аргумент - array oParser = new parserFormula("WRAPCOLS(1,3, {1,2,3})", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1); oParser = new parserFormula("WRAPCOLS(1,3, B1:B2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); oParser = new parserFormula("WRAPCOLS(1,0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("WRAPCOLS(1,-100)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("WRAPCOLS(1,)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("WRAPCOLS(1,\"asd\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); }); QUnit.test("Test: \"WORKDAY\"", function (assert) { oParser = new parserFormula("WORKDAY(DATE(2006,1,1),0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 38718); oParser = new parserFormula("WORKDAY(DATE(2006,1,1),10)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 38730); oParser = new parserFormula("WORKDAY(DATE(2006,1,1),-10)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 38705); oParser = new parserFormula("WORKDAY(DATE(2006,1,1),20,{\"1-2-2006\",\"1-16-2006\"})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 38748); oParser = new parserFormula("WORKDAY(DATE(2017,10,6),1,DATE(2017,10,9))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43018); oParser = new parserFormula("WORKDAY(DATE(2017,10,7),1,DATE(2017,10,9))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43018); oParser = new parserFormula("WORKDAY(DATE(2017,9,25),-1,DATE(2017,9,10))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43000); oParser = new parserFormula("WORKDAY(DATE(2017,9,25),-1,DATE(2017,9,10))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43000); oParser = new parserFormula("WORKDAY(DATE(2017,9,20),-1,DATE(2017,9,10))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 42997); oParser = new parserFormula("WORKDAY(DATE(2017,10,2),-1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43007); oParser = new parserFormula("WORKDAY(DATE(2017,10,2),-1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43007); oParser = new parserFormula("WORKDAY(DATE(2017,10,3),-3)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43006); oParser = new parserFormula("WORKDAY(DATE(2017,10,4),-2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43010); oParser = new parserFormula("WORKDAY(DATE(2018,4,30),1,{\"5-1-2018\",\"5-3-2018\"})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43222); oParser = new parserFormula("WORKDAY(DATE(2018,4,30),2,{\"5-1-2018\",\"5-3-2018\"})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43224); oParser = new parserFormula("WORKDAY(DATE(2018,4,30),3,{\"5-1-2018\",\"5-3-2018\"})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43227); oParser = new parserFormula("WORKDAY(DATE(2018,4,30),1,{\"5-1-2018\", \"5-2-2018\",\"5-3-2018\"})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43224); oParser = new parserFormula("WORKDAY(DATE(2018,4,30),3,{\"5-1-2018\", \"5-2-2018\",\"5-3-2018\"})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43228); oParser = new parserFormula("WORKDAY(DATE(2018,4,29),1,{\"5-1-2018\", \"5-2-2018\",\"5-3-2018\"})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43220); oParser = new parserFormula("WORKDAY(DATE(2018,4,29),2,{\"5-1-2018\", \"5-2-2018\",\"5-3-2018\"})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43224); oParser = new parserFormula("WORKDAY(DATE(2018,4,29),3,{\"5-1-2018\", \"5-2-2018\",\"5-3-2018\"})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43227); oParser = new parserFormula("WORKDAY(DATE(2018,4,29),-1,{\"5-1-2018\", \"5-2-2018\",\"5-3-2018\"})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43217); oParser = new parserFormula("WORKDAY(DATE(2018,4,29),-2,{\"5-1-2018\", \"5-2-2018\",\"5-3-2018\"})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43216); oParser = new parserFormula("WORKDAY(DATE(2018,4,29),0,{\"5-1-2018\", \"5-2-2018\",\"5-3-2018\"})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43219); oParser = new parserFormula("WORKDAY({1,2,3},{1,2})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula("WORKDAY({1,2,3},1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula("WORKDAY(1,{1,2})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula("WORKDAY({1,2,3},1.123)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula("WORKDAY({1,2,3},-1.123)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("WORKDAY({1,2,3},5)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 6); oParser = new parserFormula("WORKDAY(1,15)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 20); /*oParser = new parserFormula("WORKDAY(1,50)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 69); oParser = new parserFormula("WORKDAY(1,60)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 83); oParser = new parserFormula("WORKDAY(1,61)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 86);*/ //todo ms выдаёт ошибки /*ws.getRange2( "A101" ).setValue( "1" ); ws.getRange2( "B101" ).setValue( "3.123" ); ws.getRange2( "C101" ).setValue( "-4" ); oParser = new parserFormula("WORKDAY(A101:B101,A101:B101)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("WORKDAY(A101,A101:B101)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("WORKDAY(A101:B101,A101)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("WORKDAY(A101,A101)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2);*/ }); QUnit.test("Test: \"WORKDAY.INTL\"", function (assert) { let array; ws.getRange2("D10").setValue("44980"); ws.getRange2("D11").setValue("44981"); ws.getRange2("D12").setValue("1"); oParser = new parserFormula("WORKDAY.INTL(DATE(2023,2,22),1,1,D10:D11)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 44984); oParser = new parserFormula("WORKDAY.INTL(DATE(2023,2,22),D12,1,D10:D11)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 44984); oParser = new parserFormula("WORKDAY.INTL(DATE(2023,2,22),2,1,D10:D11)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 44985); oParser = new parserFormula("WORKDAY.INTL(DATE(2012,1,1),30,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("WORKDAY.INTL(DATE(2012,1,1),90,11)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 41013); oParser = new parserFormula('TEXT(WORKDAY.INTL(DATE(2012,1,1),30,17),"m/dd/yyyy")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "2/05/2012"); oParser = new parserFormula('WORKDAY.INTL(151,8,"0000000")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 159); oParser = new parserFormula('WORKDAY.INTL(151,8,"0000000")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 159); oParser = new parserFormula('WORKDAY.INTL(159,8,"0011100")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 171); oParser = new parserFormula('WORKDAY.INTL(151,-18,"0000000")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 133); oParser = new parserFormula('WORKDAY.INTL(151,8,"1111111")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula('WORKDAY.INTL(DATE(2006,1,1),20,1,{"1/2/2006","1/16/2006"})', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 38748); oParser = new parserFormula('WORKDAY.INTL(DATE(2006,1,1),20,{"1/2/2006","1/16/2006"})', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula('WORKDAY.INTL(DATE(2006,1,1),-20,1,{"1/2/2006",,"1/16/2006"})', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 38691); // for bug 40648 oParser = new parserFormula('WORKDAY.INTL({1,2,3;2,3,4},1)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("F106:H108").bbox); assert.ok(oParser.parse(), 'WORKDAY.INTL({1,2,3;2,3,4},1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of WORKDAY.INTL({1,2,3;2,3,4},1)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, "Result of WORKDAY.INTL({1,2,3;2,3,4},1)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 4, "Result of WORKDAY.INTL({1,2,3;2,3,4},1)[0,2]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, "Result of WORKDAY.INTL({1,2,3;2,3,4},1)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, "Result of WORKDAY.INTL({1,2,3;2,3,4},1)[1,1]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 5, "Result of WORKDAY.INTL({1,2,3;2,3,4},1)[1,2]"); oParser = new parserFormula('WORKDAY.INTL(1,{1,2,3;2,3,4})', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("F106:H108").bbox); assert.ok(oParser.parse(), 'WORKDAY.INTL(1,{1,2,3;2,3,4})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of WORKDAY.INTL(1,{1,2,3;2,3,4})[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, "Result of WORKDAY.INTL(1,{1,2,3;2,3,4})[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 4, "Result of WORKDAY.INTL(1,{1,2,3;2,3,4})[0,2]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, "Result of WORKDAY.INTL(1,{1,2,3;2,3,4})[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, "Result of WORKDAY.INTL(1,{1,2,3;2,3,4})[1,1]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 5, "Result of WORKDAY.INTL(1,{1,2,3;2,3,4})[1,2]"); oParser = new parserFormula('WORKDAY.INTL(1,1,{1,2,3;2,3,4})', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("F106:H108").bbox); assert.ok(oParser.parse(), 'WORKDAY.INTL(1,1,{1,2,3;2,3,4})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of WORKDAY.INTL(1,1,{1,2,3;2,3,4})[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, "Result of WORKDAY.INTL(1,1,{1,2,3;2,3,4})[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 4, "Result of WORKDAY.INTL(1,1,{1,2,3;2,3,4})[0,2]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, "Result of WORKDAY.INTL(1,1,{1,2,3;2,3,4})[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, "Result of WORKDAY.INTL(1,1,{1,2,3;2,3,4})[1,1]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 2, "Result of WORKDAY.INTL(1,1,{1,2,3;2,3,4})[1,2]"); oParser = new parserFormula('WORKDAY.INTL({1,2,3;2,3,4},{1,2,3;2,3,4},{1,2,3;2,3,4},{1,2,3})', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("F106:H108").bbox); assert.ok(oParser.parse(), 'WORKDAY.INTL({1,2,3;2,3,4},{1,2,3;2,3,4},{1,2,3;2,3,4},{1,2,3})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 4, "Result of WORKDAY.INTL({1,2,3;2,3,4},{1,2,3;2,3,4},{1,2,3;2,3,4},{1,2,3})[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 5, "Result of WORKDAY.INTL({1,2,3;2,3,4},{1,2,3;2,3,4},{1,2,3;2,3,4},{1,2,3})[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 6, "Result of WORKDAY.INTL({1,2,3;2,3,4},{1,2,3;2,3,4},{1,2,3;2,3,4},{1,2,3})[0,2]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 5, "Result of WORKDAY.INTL({1,2,3;2,3,4},{1,2,3;2,3,4},{1,2,3;2,3,4},{1,2,3})[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 6, "Result of WORKDAY.INTL({1,2,3;2,3,4},{1,2,3;2,3,4},{1,2,3;2,3,4},{1,2,3})[1,1]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 8, "Result of WORKDAY.INTL({1,2,3;2,3,4},{1,2,3;2,3,4},{1,2,3;2,3,4},{1,2,3})[1,2]"); oParser = new parserFormula('WORKDAY.INTL(1,1,1)', "A2", ws); assert.ok(oParser.parse(), 'WORKDAY.INTL(1,1,1)'); assert.strictEqual(oParser.calculate().getValue(), 2, 'Result of WORKDAY.INTL(1,1,1)'); oParser = new parserFormula('WORKDAY.INTL(1,1,2)', "A2", ws); assert.ok(oParser.parse(), 'WORKDAY.INTL(1,1,2)'); assert.strictEqual(oParser.calculate().getValue(), 3, 'Result of WORKDAY.INTL(1,1,2)'); oParser = new parserFormula('WORKDAY.INTL(1,1,3)', "A2", ws); assert.ok(oParser.parse(), 'WORKDAY.INTL(1,1,3)'); assert.strictEqual(oParser.calculate().getValue(), 4, 'Result of WORKDAY.INTL(1,1,3)'); oParser = new parserFormula('WORKDAY.INTL(1,1,4)', "A2", ws); assert.ok(oParser.parse(), 'WORKDAY.INTL(1,1,4)'); assert.strictEqual(oParser.calculate().getValue(), 2, 'Result of WORKDAY.INTL(1,1,4)'); oParser = new parserFormula('WORKDAY.INTL(1,1,12)', "A2", ws); assert.ok(oParser.parse(), 'WORKDAY.INTL(1,1,12)'); assert.strictEqual(oParser.calculate().getValue(), 3, 'Result of WORKDAY.INTL(1,1,12)'); ws.getRange2("A10").setValue("1"); ws.getRange2("A11").setValue("2"); ws.getRange2("A12").setValue("3"); ws.getRange2("B10").setValue("2"); ws.getRange2("B11").setValue("2"); ws.getRange2("B12").setValue("2"); ws.getRange2("C10").setValue("3"); ws.getRange2("C11").setValue("3"); ws.getRange2("C12").setValue("3"); // first argument oParser = new parserFormula('WORKDAY.INTL(A10:A12,1)', "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("E10:E12").bbox); assert.ok(oParser.parse(), 'WORKDAY.INTL(A10:A12,1)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of WORKDAY.INTL(A10:A12,1)'); oParser = new parserFormula('WORKDAY.INTL({1;2;3},1)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E10:E12").bbox); assert.ok(oParser.parse(), 'WORKDAY.INTL({1;2;3},1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of WORKDAY.INTL({1;2;3},1)[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, "Result of WORKDAY.INTL({1;2;3},1)[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 4, "Result of WORKDAY.INTL({1;2;3},1)[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "", "Result of WORKDAY.INTL({1;2;3},1)[3,0]"); oParser = new parserFormula('WORKDAY.INTL(A10:C10,1)', "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("E10:E12").bbox); assert.ok(oParser.parse(), 'WORKDAY.INTL(A10:C10,1)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of WORKDAY.INTL(A10:C10,1)'); oParser = new parserFormula('WORKDAY.INTL({1,2,3},1)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E10:E12").bbox); assert.ok(oParser.parse(), 'WORKDAY.INTL({1,2,3},1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of WORKDAY.INTL({1,2,3},1)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, "Result of WORKDAY.INTL({1,2,3},1)[1,0]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 4, "Result of WORKDAY.INTL({1,2,3},1)[2,0]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "", "Result of WORKDAY.INTL({1,2,3},1)[3,0]"); // second argument oParser = new parserFormula('WORKDAY.INTL(1,A10:A12)', "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("E10:E12").bbox); assert.ok(oParser.parse(), 'WORKDAY.INTL(1,A10:A12)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of WORKDAY.INTL(1,A10:A12)'); oParser = new parserFormula('WORKDAY.INTL(1,{1;2;3})', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E10:E12").bbox); assert.ok(oParser.parse(), 'WORKDAY.INTL(1,{1;2;3})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of WORKDAY.INTL(1,{1;2;3})[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, "Result of WORKDAY.INTL(1,{1;2;3})[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 4, "Result of WORKDAY.INTL(1,{1;2;3})[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "", "Result of WORKDAY.INTL(1,{1;2;3})[3,0]"); oParser = new parserFormula('WORKDAY.INTL(1,A10:C10)', "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("E10:E12").bbox); assert.ok(oParser.parse(), 'WORKDAY.INTL(1,A10:C10)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of WORKDAY.INTL(1,A10:C10)'); oParser = new parserFormula('WORKDAY.INTL(1,{1,2,3})', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E10:E12").bbox); assert.ok(oParser.parse(), 'WORKDAY.INTL(1,{1,2,3})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of WORKDAY.INTL(1,{1,2,3})[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, "Result of WORKDAY.INTL(1,{1,2,3})[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 4, "Result of WORKDAY.INTL(1,{1,2,3})[0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "", "Result of WORKDAY.INTL(1,{1,2,3})[0,3]"); // third arugument oParser = new parserFormula('WORKDAY.INTL(1,1,A10:A12)', "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("E10:E12").bbox); assert.ok(oParser.parse(), 'WORKDAY.INTL(1,1,A10:A12)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of WORKDAY.INTL(1,1,A10:A12)[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, "Result of WORKDAY.INTL(1,1,A10:A12)[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 4, "Result of WORKDAY.INTL(1,1,A10:A12)[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "", "Result of WORKDAY.INTL(1,1,A10:A12)[3,0]"); oParser = new parserFormula('WORKDAY.INTL(1,1,{1;2;3})', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E10:E12").bbox); assert.ok(oParser.parse(), 'WORKDAY.INTL(1,1,{1;2;3})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of WORKDAY.INTL(1,1,{1;2;3})[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, "Result of WORKDAY.INTL(1,1,{1;2;3})[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 4, "Result of WORKDAY.INTL(1,1,{1;2;3})[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "", "Result of WORKDAY.INTL(1,1,{1;2;3})[3,0]"); oParser = new parserFormula('WORKDAY.INTL(1,1,A10:C10)', "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("E10:E12").bbox); assert.ok(oParser.parse(), 'WORKDAY.INTL(1,1,A10:C10)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of WORKDAY.INTL(1,1,A10:C10)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, "Result of WORKDAY.INTL(1,1,A10:C10)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 4, "Result of WORKDAY.INTL(1,1,A10:C10)[0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "", "Result of WORKDAY.INTL(1,1,A10:C10)[0,3]"); oParser = new parserFormula('WORKDAY.INTL(1,1,{1,2,3})', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E10:E12").bbox); assert.ok(oParser.parse(), 'WORKDAY.INTL(1,1,{1,2,3})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of WORKDAY.INTL(1,1,{1,2,3})[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, "Result of WORKDAY.INTL(1,1,{1,2,3})[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 4, "Result of WORKDAY.INTL(1,1,{1,2,3})[0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "", "Result of WORKDAY.INTL(1,1,{1,2,3})[0,3]"); // fourth argument oParser = new parserFormula('WORKDAY.INTL(1,1,1,A10:A12)', "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("E10:E12").bbox); assert.ok(oParser.parse(), 'WORKDAY.INTL(1,1,1,A10:A12)'); assert.strictEqual(oParser.calculate().getValue(), 4, 'Result of WORKDAY.INTL(1,1,1,A10:A12)'); oParser = new parserFormula('WORKDAY.INTL(1,1,1,{1;2;3})', "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("E10:E12").bbox); assert.ok(oParser.parse(), 'WORKDAY.INTL(1,1,1,{1;2;3})'); assert.strictEqual(oParser.calculate().getValue(), 4, 'Result of WORKDAY.INTL(1,1,1,{1;2;3})'); oParser = new parserFormula('WORKDAY.INTL(1,1,1,A10:C10)', "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("E10:E12").bbox); assert.ok(oParser.parse(), 'WORKDAY.INTL(1,1,1,A10:C10)'); assert.strictEqual(oParser.calculate().getValue(), 4, 'Result of WORKDAY.INTL(1,1,1,A10:C10)'); oParser = new parserFormula('WORKDAY.INTL(1,1,1,{1,2,3})', "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("E10:E12").bbox); assert.ok(oParser.parse(), 'WORKDAY.INTL(1,1,1,{1,2,3})'); assert.strictEqual(oParser.calculate().getValue(), 4, 'Result of WORKDAY.INTL(1,1,1,{1,2,3})'); oParser = new parserFormula('WORKDAY.INTL(A10:C11,A10:C11,A10:C11)', "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("E10:E12").bbox); assert.ok(oParser.parse(), 'WORKDAY.INTL(A10:C11,A10:C11,A10:C11)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", "Result of WORKDAY.INTL(A10:C11,A10:C11,A10:C11)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", "Result of WORKDAY.INTL(A10:C11,A10:C11,A10:C11)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#VALUE!", "Result of WORKDAY.INTL(A10:C11,A10:C11,A10:C11)[0,2]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", "Result of WORKDAY.INTL(A10:C11,A10:C11,A10:C11)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#VALUE!", "Result of WORKDAY.INTL(A10:C11,A10:C11,A10:C11)[1,1]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "#VALUE!", "Result of WORKDAY.INTL(A10:C11,A10:C11,A10:C11)[1,2]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", "Result of WORKDAY.INTL(A10:C11,A10:C11,A10:C11)[2,0]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "", "Result of WORKDAY.INTL(A10:C11,A10:C11,A10:C11)[2,1]"); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "", "Result of WORKDAY.INTL(A10:C11,A10:C11,A10:C11)[2,2]"); oParser = new parserFormula('WORKDAY.INTL(A10:C11,A10:C11,A10:A10)', "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("E10:E12").bbox); assert.ok(oParser.parse(), 'WORKDAY.INTL(A10:C11,A10:C11,A10:A10)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", "Result of WORKDAY.INTL(A10:C11,A10:C11,A10:A10)[0,0]"); }); QUnit.test("Test: \"TIME\"", function (assert) { ws.getRange2("A2").setValue("12"); ws.getRange2("A3").setValue("16"); ws.getRange2("B2").setValue("0"); ws.getRange2("B3").setValue("48"); ws.getRange2("C2").setValue("0"); ws.getRange2("C3").setValue("10"); oParser = new parserFormula("TIME(A2,B2,C2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0.5); oParser = new parserFormula("TIME(A3,B3,C3)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.7001157); oParser = new parserFormula("TIME(1,1,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.0423727); oParser = new parserFormula("TIME(1.34,1,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.0423727); oParser = new parserFormula("TIME(1.34,1.456,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.0423727); oParser = new parserFormula("TIME(1.34,1.456,1.9)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.0423727); oParser = new parserFormula("TIME(-1.34,1.456,1.9)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); testArrayFormula2(assert, "TIME", 3, 3); }); QUnit.test("Test: \"TIMEVALUE\"", function (assert) { oParser = new parserFormula("timevalue(\"10:02:34\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(Math.abs(oParser.calculate().getValue() - 0.4184490740740740) < dif); oParser = new parserFormula("timevalue(\"02-01-2006 10:15:29 AM\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(Math.abs(oParser.calculate().getValue() - 0.4274189814823330) < dif); oParser = new parserFormula("timevalue(\"22:02\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(Math.abs(oParser.calculate().getValue() - 0.9180555555555560) < dif); testArrayFormula(assert, "TIMEVALUE"); }); QUnit.test("Test: \"TYPE\"", function (assert) { ws.getRange2("A2").setValue("Smith"); oParser = new parserFormula("TYPE(A2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula('TYPE("Mr. "&A2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula('TYPE(2+A2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 16); oParser = new parserFormula('(2+A2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula('TYPE({1,2;3,4})', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 64); //TODO нужна другая функция для тестирования //testArrayFormula2(assert, "TYPE", 1, 1); }); QUnit.test("Test: \"DAYS360\"", function (assert) { oParser = new parserFormula("DAYS360(DATE(2002,2,3),DATE(2005,5,31))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1198); oParser = new parserFormula("DAYS360(DATE(2005,5,31),DATE(2002,2,3))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -1197); oParser = new parserFormula("DAYS360(DATE(2002,2,3),DATE(2005,5,31),FALSE)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1198); oParser = new parserFormula("DAYS360(DATE(2002,2,3),DATE(2005,5,31),TRUE)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1197); testArrayFormula2(assert, "DAYS360", 2, 3); }); QUnit.test("Test: \"WEEKNUM\"", function (assert) { oParser = new parserFormula("WEEKNUM(DATE(2006,1,1))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("WEEKNUM(DATE(2006,1,1),17)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("WEEKNUM(DATE(2006,1,1),1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("WEEKNUM(DATE(2006,1,1),21)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 52); oParser = new parserFormula("WEEKNUM(DATE(2006,2,1),1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5); oParser = new parserFormula("WEEKNUM(DATE(2006,2,1),2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 6); oParser = new parserFormula("WEEKNUM(DATE(2006,2,1),11)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 6); oParser = new parserFormula("WEEKNUM(DATE(2007,1,1),15)", "A2", ws);//понед assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("WEEKNUM(DATE(2008,1,1),15)", "A2", ws);//втор assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("WEEKNUM(DATE(2003,1,1),15)", "A2", ws);//сред assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("WEEKNUM(DATE(2009,1,1),15)", "A2", ws);//чет assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("WEEKNUM(DATE(2010,1,1),15)", "A2", ws);//пят assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("WEEKNUM(DATE(2011,1,1),15)", "A2", ws);//суб assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("WEEKNUM(DATE(2012,1,1),11)", "A2", ws);//вск assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("WEEKNUM(DATE(2008,1,4),11)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("WEEKNUM(DATE(2008,1,10),11)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula("WEEKNUM(DATE(2008,1,11),11)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula("WEEKNUM(DATE(2008,1,17),11)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); oParser = new parserFormula("WEEKNUM(DATE(2008,1,18),11)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); oParser = new parserFormula("WEEKNUM(DATE(2008,1,24),11)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); oParser = new parserFormula("WEEKNUM(DATE(2013,1,1),21)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("WEEKNUM(DATE(2013,1,7))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula("WEEKNUM(0, 21)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 52); oParser = new parserFormula("WEEKNUM(1, 21)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 52); oParser = new parserFormula("WEEKNUM(2, 21)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("WEEKNUM(0, 17)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("WEEKNUM(1, 17)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); testArrayFormula2(assert, "WEEKNUM", 1, 2, true, null); }); QUnit.test("Test: \"ISOWEEKNUM\"", function (assert) { // base mode ws.workbook.setDate1904(false, true); ws.getRange2("A2").setValue("3/9/2012"); oParser = new parserFormula("ISOWEEKNUM(A2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 10); oParser = new parserFormula("ISOWEEKNUM(123)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 18); oParser = new parserFormula("ISOWEEKNUM(120003)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 30); oParser = new parserFormula("ISOWEEKNUM(120003)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 30); oParser = new parserFormula("ISOWEEKNUM(-100)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("ISOWEEKNUM(1203)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 16); oParser = new parserFormula("ISOWEEKNUM(43466)", "A1", ws); assert.ok(oParser.parse(), "ISOWEEKNUM(01.01.2019)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of ISOWEEKNUM(01.01.2019)"); oParser = new parserFormula("ISOWEEKNUM(43831)", "A1", ws); assert.ok(oParser.parse(), "ISOWEEKNUM(01.01.2020)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of ISOWEEKNUM(01.01.2020)"); oParser = new parserFormula("ISOWEEKNUM(44197)", "A1", ws); assert.ok(oParser.parse(), "ISOWEEKNUM(01.01.2021)"); assert.strictEqual(oParser.calculate().getValue(), 53, "Result of ISOWEEKNUM(01.01.2021)"); oParser = new parserFormula("ISOWEEKNUM(44562)", "A1", ws); assert.ok(oParser.parse(), "ISOWEEKNUM(01.01.2022)"); assert.strictEqual(oParser.calculate().getValue(), 52, "Result of ISOWEEKNUM(01.01.2022)"); oParser = new parserFormula("ISOWEEKNUM(44563)", "A1", ws); assert.ok(oParser.parse(), "ISOWEEKNUM(02.01.2022)"); assert.strictEqual(oParser.calculate().getValue(), 52, "Result of ISOWEEKNUM(02.01.2022)"); oParser = new parserFormula("ISOWEEKNUM(44564)", "A1", ws); assert.ok(oParser.parse(), "ISOWEEKNUM(03.01.2022)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of ISOWEEKNUM(03.01.2022)"); oParser = new parserFormula("ISOWEEKNUM(44927)", "A1", ws); assert.ok(oParser.parse(), "ISOWEEKNUM(01.01.2023)"); assert.strictEqual(oParser.calculate().getValue(), 52, "Result of ISOWEEKNUM(01.01.2023)"); oParser = new parserFormula("ISOWEEKNUM(44928)", "A1", ws); assert.ok(oParser.parse(), "ISOWEEKNUM(02.01.2023)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of ISOWEEKNUM(02.01.2023)"); oParser = new parserFormula("ISOWEEKNUM(44929)", "A1", ws); assert.ok(oParser.parse(), "ISOWEEKNUM(03.01.2023)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of ISOWEEKNUM(03.01.2023)"); oParser = new parserFormula("ISOWEEKNUM(1)", "A1", ws); assert.ok(oParser.parse(), "ISOWEEKNUM(01.01.1900)"); assert.strictEqual(oParser.calculate().getValue(), 52, "Result of ISOWEEKNUM(01.01.1900)"); oParser = new parserFormula("ISOWEEKNUM(2)", "A1", ws); assert.ok(oParser.parse(), "ISOWEEKNUM(02.01.1900)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of ISOWEEKNUM(02.01.1900)"); // set 1904 mode ws.workbook.setDate1904(true, true); oParser = new parserFormula("ISOWEEKNUM(43466)", "A1", ws); assert.ok(oParser.parse(), "ISOWEEKNUM(01.01.2019)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of ISOWEEKNUM(01.01.2019)"); oParser = new parserFormula("ISOWEEKNUM(43831)", "A1", ws); assert.ok(oParser.parse(), "ISOWEEKNUM(01.01.2020)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of ISOWEEKNUM(01.01.2020)"); oParser = new parserFormula("ISOWEEKNUM(44197)", "A1", ws); assert.ok(oParser.parse(), "ISOWEEKNUM(01.01.2021)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of ISOWEEKNUM(01.01.2021)"); oParser = new parserFormula("ISOWEEKNUM(44562)", "A1", ws); assert.ok(oParser.parse(), "ISOWEEKNUM(01.01.2022)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of ISOWEEKNUM(01.01.2022)"); oParser = new parserFormula("ISOWEEKNUM(44563)", "A1", ws); assert.ok(oParser.parse(), "ISOWEEKNUM(02.01.2022)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of ISOWEEKNUM(02.01.2022)"); oParser = new parserFormula("ISOWEEKNUM(44564)", "A1", ws); assert.ok(oParser.parse(), "ISOWEEKNUM(03.01.2022)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of ISOWEEKNUM(03.01.2022)"); oParser = new parserFormula("ISOWEEKNUM(44927)", "A1", ws); assert.ok(oParser.parse(), "ISOWEEKNUM(01.01.2023)"); assert.strictEqual(oParser.calculate().getValue(), 53, "Result of ISOWEEKNUM(01.01.2023)"); oParser = new parserFormula("ISOWEEKNUM(44928)", "A1", ws); assert.ok(oParser.parse(), "ISOWEEKNUM(02.01.2023)"); assert.strictEqual(oParser.calculate().getValue(), 53, "Result of ISOWEEKNUM(02.01.2023)"); oParser = new parserFormula("ISOWEEKNUM(44929)", "A1", ws); assert.ok(oParser.parse(), "ISOWEEKNUM(03.01.2023)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of ISOWEEKNUM(03.01.2023)"); oParser = new parserFormula("ISOWEEKNUM(1)", "A1", ws); assert.ok(oParser.parse(), "ISOWEEKNUM(01.01.1900)"); assert.strictEqual(oParser.calculate().getValue(), 53, "Result of ISOWEEKNUM(01.01.1900)"); oParser = new parserFormula("ISOWEEKNUM(2)", "A1", ws); assert.ok(oParser.parse(), "ISOWEEKNUM(02.01.1900)"); assert.strictEqual(oParser.calculate().getValue(), 53, "Result of ISOWEEKNUM(02.01.1900)"); testArrayFormula2(assert, "ISOWEEKNUM", 1, 1); // return to base mode ws.workbook.setDate1904(false, true); }); QUnit.test("Test: \"WEEKDAY\"", function (assert) { let array; // base mode ws.workbook.setDate1904(false, true); ws.getRange2("A2").setValue("2/14/2008"); oParser = new parserFormula("WEEKDAY(A2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5); oParser = new parserFormula("WEEKDAY(A2, 2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); oParser = new parserFormula("WEEKDAY(A2, 3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); // ws.getRange2("B1").setValue("=DATE(2023,1,1)"); ws.getRange2("B1").setValue("2023/1/1"); ws.getRange2("B2").setValue("2023/1/2"); ws.getRange2("B3").setValue("2023/1/3"); ws.getRange2("B4").setValue("2023/1/4"); ws.getRange2("B5").setValue("2023/1/5"); ws.getRange2("B6").setValue("2023/1/6"); ws.getRange2("B7").setValue("2023/1/7"); ws.getRange2("B8").setValue("2023/1/8"); ws.getRange2("B9").setValue("2023/1/9"); ws.getRange2("B10").setValue("2023/1/10"); ws.getRange2("B11").setValue("2023/1/11"); ws.getRange2("B12").setValue("2023/1/12"); oParser = new parserFormula("WEEKDAY(B1,2)>5", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TRUE"); oParser = new parserFormula("WEEKDAY(B1,2)", "A1", ws); assert.ok(oParser.parse(), "WEEKDAY(DATE(2023,1,1),2)"); assert.strictEqual(oParser.calculate().getValue(), 7, "Result of WEEKDAY(DATE(2023,1,1),2)"); oParser = new parserFormula("WEEKDAY(B2,2)", "A1", ws); assert.ok(oParser.parse(), "WEEKDAY(DATE(2023,1,2),2)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of WEEKDAY(DATE(2023,1,2),2)"); oParser = new parserFormula("WEEKDAY(B3,2)", "A1", ws); assert.ok(oParser.parse(), "WEEKDAY(DATE(2023,1,3),2)"); assert.strictEqual(oParser.calculate().getValue(), 2, "Result of WEEKDAY(DATE(2023,1,3),2)"); oParser = new parserFormula("WEEKDAY(B4,2)", "A1", ws); assert.ok(oParser.parse(), "WEEKDAY(DATE(2023,1,4),2)"); assert.strictEqual(oParser.calculate().getValue(), 3, "Result of WEEKDAY(DATE(2023,1,4),2)"); oParser = new parserFormula("WEEKDAY(B5,2)", "A1", ws); assert.ok(oParser.parse(), "WEEKDAY(DATE(2023,1,5),2)"); assert.strictEqual(oParser.calculate().getValue(), 4, "Result of WEEKDAY(DATE(2023,1,5),2)"); oParser = new parserFormula("WEEKDAY(B6,2)", "A1", ws); assert.ok(oParser.parse(), "WEEKDAY(DATE(2023,1,6),2)"); assert.strictEqual(oParser.calculate().getValue(), 5, "Result of WEEKDAY(DATE(2023,1,6),2)"); oParser = new parserFormula("WEEKDAY(B7,2)", "A1", ws); assert.ok(oParser.parse(), "WEEKDAY(DATE(2023,1,7),2)"); assert.strictEqual(oParser.calculate().getValue(), 6, "Result of WEEKDAY(DATE(2023,1,7),2)"); oParser = new parserFormula("WEEKDAY(B8,2)", "A1", ws); assert.ok(oParser.parse(), "WEEKDAY(DATE(2023,1,8),2)"); assert.strictEqual(oParser.calculate().getValue(), 7, "Result of WEEKDAY(DATE(2023,1,8),2)"); oParser = new parserFormula("WEEKDAY(B9,2)", "A1", ws); assert.ok(oParser.parse(), "WEEKDAY(DATE(2023,1,9),2)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of WEEKDAY(DATE(2023,1,9),2)"); oParser = new parserFormula("WEEKDAY(B10,2)", "A1", ws); assert.ok(oParser.parse(), "WEEKDAY(DATE(2023,1,10),2)"); assert.strictEqual(oParser.calculate().getValue(), 2, "Result of WEEKDAY(DATE(2023,1,10),2)"); oParser = new parserFormula("WEEKDAY(B11,2)", "A1", ws); assert.ok(oParser.parse(), "WEEKDAY(DATE(2023,1,11),2)"); assert.strictEqual(oParser.calculate().getValue(), 3, "Result of WEEKDAY(DATE(2023,1,11),2)"); oParser = new parserFormula("WEEKDAY(B12,2)", "A1", ws); assert.ok(oParser.parse(), "WEEKDAY(DATE(2023,1,12),2)"); assert.strictEqual(oParser.calculate().getValue(), 4, "Result of WEEKDAY(DATE(2023,1,12),2)"); // strings oParser = new parserFormula('WEEKDAY("44927",2)', "A1", ws); assert.ok(oParser.parse(), "WEEKDAY(DATE(2023,1,1),2)"); assert.strictEqual(oParser.calculate().getValue(), 7, 'Result of WEEKDAY("44927",2)'); oParser = new parserFormula('WEEKDAY("44927","2")', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(DATE(2023,1,1),"2")'); assert.strictEqual(oParser.calculate().getValue(), 7, 'Result of WEEKDAY("44927","2")'); oParser = new parserFormula('WEEKDAY("44927+1","2")', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY("44927+1","2")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of WEEKDAY("44927+1","2")'); oParser = new parserFormula('WEEKDAY("44927s","2")', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY("44927s","2")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of WEEKDAY("44927s","2")'); oParser = new parserFormula('WEEKDAY("44927","2+1")', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(DATE(2023,1,1),"2+1")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of WEEKDAY("44927","2+1")'); oParser = new parserFormula('WEEKDAY("44927","2s")', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(DATE(2023,1,1),"2s")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of WEEKDAY("44927","2s")'); // bools oParser = new parserFormula('WEEKDAY(44927,FALSE)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(DATE(2023,1,1),FALSE)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(44927,FALSE)'); oParser = new parserFormula('WEEKDAY(44927,TRUE)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(DATE(2023,1,1),TRUE)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of WEEKDAY(44927,TRUE)'); oParser = new parserFormula('WEEKDAY(TRUE,TRUE)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(TRUE,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of WEEKDAY(TRUE,TRUE)'); oParser = new parserFormula('WEEKDAY(FALSE,TRUE)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(FALSE,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), 7, 'Result of WEEKDAY(FALSE,TRUE)'); // arrays oParser = new parserFormula('WEEKDAY({1,2,3},2)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY({1,2,3},2)'); assert.strictEqual(oParser.calculate().getValue(), 7, 'Result of WEEKDAY({1,2,3},2)'); oParser = new parserFormula('WEEKDAY({1,2,3},2)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("F106:I109").bbox); assert.ok(oParser.parse(), 'WEEKDAY({1,2,3},2)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 7, "Result of WEEKDAY({1,2,3},2).[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, "Result of WEEKDAY({1,2,3},2).[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 2, "Result of WEEKDAY({1,2,3},2).[0,2]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of WEEKDAY({1,2,3},2).[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of WEEKDAY({1,2,3},2).[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", "Result of WEEKDAY({1,2,3},2).[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#N/A", "Result of WEEKDAY({1,2,3},2).[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "#N/A", "Result of WEEKDAY({1,2,3},2).[4,0]"); } oParser = new parserFormula('WEEKDAY(1,{1,2,3})', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(1,{1,2,3})'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of WEEKDAY(1,{1,2,3})'); oParser = new parserFormula('WEEKDAY(1,{1,2,3})', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("F106:I109").bbox); assert.ok(oParser.parse(), 'WEEKDAY(1,{1,2,3})'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of WEEKDAY(1,{1,2,3}).[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 7, "Result of WEEKDAY(1,{1,2,3}).[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 6, "Result of WEEKDAY(1,{1,2,3}).[0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "", "Result of WEEKDAY(1,{1,2,3}).[0,3]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of WEEKDAY(1,{1,2,3}).[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of WEEKDAY(1,{1,2,3}).[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", "Result of WEEKDAY(1,{1,2,3}).[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#N/A", "Result of WEEKDAY(1,{1,2,3}).[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "#N/A", "Result of WEEKDAY(1,{1,2,3}).[4,0]"); } oParser = new parserFormula('WEEKDAY({1,2,3},{1,2,3})', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY({1,2,3},{1,2,3})'); oParser.setArrayFormulaRef(ws.getRange2("F106:I109").bbox); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of WEEKDAY({1,2,3},{1,2,3}).[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, "Result of WEEKDAY({1,2,3},{1,2,3}).[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 1, "Result of WEEKDAY({1,2,3},{1,2,3}).[0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "#N/A", "Result of WEEKDAY({1,2,3},{1,2,3}).[0,3]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 1, "Result of WEEKDAY({1,2,3},{1,2,3}).[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 1, "Result of WEEKDAY({1,2,3},{1,2,3}).[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 1, "Result of WEEKDAY({1,2,3},{1,2,3}).[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 1, "Result of WEEKDAY({1,2,3},{1,2,3}).[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "", "Result of WEEKDAY({1,2,3},{1,2,3}).[4,0]"); } // cellsRange ws.getRange2("C101").setValue("1"); ws.getRange2("C102").setValue("2"); ws.getRange2("C103").setValue("3"); ws.getRange2("C104").setValue("4"); oParser = new parserFormula("WEEKDAY(C101:C103,2)", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:E109").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 7, "Result of WEEKDAY(C101:C103,2).[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of WEEKDAY(C101:C103,2).[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 1, "Result of WEEKDAY(C101:C103,2).[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of WEEKDAY(C101:C103,2).[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 2, "Result of WEEKDAY(C101:C103,2).[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "", "Result of WEEKDAY(C101:C103,2).[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "#N/A", "Result of WEEKDAY(C101:C103,2).[4,0]"); } oParser = new parserFormula('WEEKDAY(C101:C103,C101:C103)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(C101:C103,C101:C103)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of WEEKDAY(C101:C103,C101:C103)'); oParser = new parserFormula("WEEKDAY(C101:C103,C101:C103)", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:E109").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of WEEKDAY(C101:C103,C101:C103).[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of WEEKDAY(C101:C103,C101:C103).[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 1, "Result of WEEKDAY(C101:C103,C101:C103).[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of WEEKDAY(C101:C103,C101:C103).[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 1, "Result of WEEKDAY(C101:C103,C101:C103).[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "", "Result of WEEKDAY(C101:C103,C101:C103).[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "#N/A", "Result of WEEKDAY(C101:C103,C101:C103).[4,0]"); } oParser = new parserFormula('WEEKDAY(1,C101:C103)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(1,C101:C103)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of WEEKDAY(1,C101:C103)'); oParser = new parserFormula("WEEKDAY(1,C101:C103)", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:E109").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of WEEKDAY(1,C101:C103).[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of WEEKDAY(1,C101:C103).[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 7, "Result of WEEKDAY(1,C101:C103).[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of WEEKDAY(1,C101:C103).[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 6, "Result of WEEKDAY(1,C101:C103).[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "", "Result of WEEKDAY(1,C101:C103).[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "#N/A", "Result of WEEKDAY(1,C101:C103).[4,0]"); } // errors oParser = new parserFormula('WEEKDAY(#N/A,2)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(#N/A,2)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of WEEKDAY(#N/A,2)'); oParser = new parserFormula('WEEKDAY(#NUM!,#N/A)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(#NUM!,#N/A)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(#NUM!,#N/A)'); oParser = new parserFormula('WEEKDAY(#DIV/0!,#N/A)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(#DIV/0!,#N/A)'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of WEEKDAY(#DIV/0!,#N/A)'); // other oParser = new parserFormula('WEEKDAY(44927,)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(DATE(2023,1,1),)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(44927,)'); oParser = new parserFormula('WEEKDAY(44927)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(DATE(2023,1,1))'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of WEEKDAY(44927)'); oParser = new parserFormula('WEEKDAY(,)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(,)'); oParser = new parserFormula('WEEKDAY(,1)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,1)'); assert.strictEqual(oParser.calculate().getValue(), 7, 'Result of WEEKDAY(,1)'); oParser = new parserFormula('WEEKDAY(,2)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,2)'); assert.strictEqual(oParser.calculate().getValue(), 6, 'Result of WEEKDAY(,2)'); oParser = new parserFormula('WEEKDAY(,3)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,3)'); assert.strictEqual(oParser.calculate().getValue(), 5, 'Result of WEEKDAY(,3)'); oParser = new parserFormula('WEEKDAY(,4)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,4)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(,4)'); oParser = new parserFormula('WEEKDAY(,5)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,5)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(,5)'); oParser = new parserFormula('WEEKDAY(,6)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,6)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(,6)'); oParser = new parserFormula('WEEKDAY(,7)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,7)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(,7)'); oParser = new parserFormula('WEEKDAY(,8)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,8)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(,8)'); oParser = new parserFormula('WEEKDAY(,9)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,9)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(,9)'); oParser = new parserFormula('WEEKDAY(,10)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,10)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(,10)'); oParser = new parserFormula('WEEKDAY(,11)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,11)'); assert.strictEqual(oParser.calculate().getValue(), 6, 'Result of WEEKDAY(,11)'); oParser = new parserFormula('WEEKDAY(,12)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,12)'); assert.strictEqual(oParser.calculate().getValue(), 5, 'Result of WEEKDAY(,12)'); oParser = new parserFormula('WEEKDAY(,13)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,13)'); assert.strictEqual(oParser.calculate().getValue(), 4, 'Result of WEEKDAY(,13)'); oParser = new parserFormula('WEEKDAY(,14)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,14)'); assert.strictEqual(oParser.calculate().getValue(), 3, 'Result of WEEKDAY(,14)'); oParser = new parserFormula('WEEKDAY(,15)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,15)'); assert.strictEqual(oParser.calculate().getValue(), 2, 'Result of WEEKDAY(,15)'); oParser = new parserFormula('WEEKDAY(,16)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,16)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of WEEKDAY(,16)'); oParser = new parserFormula('WEEKDAY(,17)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,17)'); assert.strictEqual(oParser.calculate().getValue(), 7, 'Result of WEEKDAY(,17)'); oParser = new parserFormula('WEEKDAY(,20)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,20)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(,20)'); oParser = new parserFormula('WEEKDAY(,999999999999999999)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,999999999999999999)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(,999999999999999999)'); oParser = new parserFormula('WEEKDAY(,0)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,0)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(,0)'); oParser = new parserFormula('WEEKDAY(,-1)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,-1)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(,-1)'); testArrayFormula2(assert, "WEEKDAY", 1, 2); // set 1904 mode ws.workbook.setDate1904(true, true); oParser = new parserFormula("WEEKDAY(B1,2)>5", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TRUE"); oParser = new parserFormula("WEEKDAY(B1,2)", "A1", ws); assert.ok(oParser.parse(), "WEEKDAY(B1,2)"); assert.strictEqual(oParser.calculate().getValue(), 6, "Result of WEEKDAY(B1,2)"); oParser = new parserFormula("WEEKDAY(B2,2)", "A1", ws); assert.ok(oParser.parse(), "WEEKDAY(DATE(2023,1,2),2)"); assert.strictEqual(oParser.calculate().getValue(), 7, "Result of WEEKDAY(DATE(2023,1,2),2)"); oParser = new parserFormula("WEEKDAY(B3,2)", "A1", ws); assert.ok(oParser.parse(), "WEEKDAY(DATE(2023,1,3),2)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of WEEKDAY(DATE(2023,1,3),2)"); oParser = new parserFormula("WEEKDAY(B4,2)", "A1", ws); assert.ok(oParser.parse(), "WEEKDAY(DATE(2023,1,4),2)"); assert.strictEqual(oParser.calculate().getValue(), 2, "Result of WEEKDAY(DATE(2023,1,4),2)"); oParser = new parserFormula("WEEKDAY(B5,2)", "A1", ws); assert.ok(oParser.parse(), "WEEKDAY(DATE(2023,1,5),2)"); assert.strictEqual(oParser.calculate().getValue(), 3, "Result of WEEKDAY(DATE(2023,1,5),2)"); oParser = new parserFormula("WEEKDAY(B6,2)", "A1", ws); assert.ok(oParser.parse(), "WEEKDAY(DATE(2023,1,6),2)"); assert.strictEqual(oParser.calculate().getValue(), 4, "Result of WEEKDAY(DATE(2023,1,6),2)"); oParser = new parserFormula("WEEKDAY(B7,2)", "A1", ws); assert.ok(oParser.parse(), "WEEKDAY(DATE(2023,1,7),2)"); assert.strictEqual(oParser.calculate().getValue(), 5, "Result of WEEKDAY(DATE(2023,1,7),2)"); oParser = new parserFormula("WEEKDAY(B8,2)", "A1", ws); assert.ok(oParser.parse(), "WEEKDAY(DATE(2023,1,8),2)"); assert.strictEqual(oParser.calculate().getValue(), 6, "Result of WEEKDAY(DATE(2023,1,8),2)"); oParser = new parserFormula("WEEKDAY(B9,2)", "A1", ws); assert.ok(oParser.parse(), "WEEKDAY(DATE(2023,1,9),2)"); assert.strictEqual(oParser.calculate().getValue(), 7, "Result of WEEKDAY(DATE(2023,1,9),2)"); oParser = new parserFormula("WEEKDAY(B10,2)", "A1", ws); assert.ok(oParser.parse(), "WEEKDAY(DATE(2023,1,10),2)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of WEEKDAY(DATE(2023,1,10),2)"); oParser = new parserFormula("WEEKDAY(B11,2)", "A1", ws); assert.ok(oParser.parse(), "WEEKDAY(DATE(2023,1,11),2)"); assert.strictEqual(oParser.calculate().getValue(), 2, "Result of WEEKDAY(DATE(2023,1,11),2)"); oParser = new parserFormula("WEEKDAY(B12,2)", "A1", ws); assert.ok(oParser.parse(), "WEEKDAY(DATE(2023,1,12),2)"); assert.strictEqual(oParser.calculate().getValue(), 3, "Result of WEEKDAY(DATE(2023,1,12),2)"); // other oParser = new parserFormula('WEEKDAY(44927,)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(DATE(2023,1,1),)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(44927,)'); oParser = new parserFormula('WEEKDAY(44927)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(44927)'); assert.strictEqual(oParser.calculate().getValue(), 7, 'Result of WEEKDAY(44927)'); oParser = new parserFormula('WEEKDAY(,)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(,)'); oParser = new parserFormula('WEEKDAY(,1)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,1)'); assert.strictEqual(oParser.calculate().getValue(), 6, 'Result of WEEKDAY(,1)'); oParser = new parserFormula('WEEKDAY(,2)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,2)'); assert.strictEqual(oParser.calculate().getValue(), 5, 'Result of WEEKDAY(,2)'); oParser = new parserFormula('WEEKDAY(,3)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,3)'); assert.strictEqual(oParser.calculate().getValue(), 4, 'Result of WEEKDAY(,3)'); oParser = new parserFormula('WEEKDAY(,4)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,4)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(,4)'); oParser = new parserFormula('WEEKDAY(,5)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,5)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(,5)'); oParser = new parserFormula('WEEKDAY(,6)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,6)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(,6)'); oParser = new parserFormula('WEEKDAY(,7)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,7)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(,7)'); oParser = new parserFormula('WEEKDAY(,8)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,8)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(,8)'); oParser = new parserFormula('WEEKDAY(,9)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,9)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(,9)'); oParser = new parserFormula('WEEKDAY(,10)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,10)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(,10)'); oParser = new parserFormula('WEEKDAY(,11)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,11)'); assert.strictEqual(oParser.calculate().getValue(), 5, 'Result of WEEKDAY(,11)'); oParser = new parserFormula('WEEKDAY(,12)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,12)'); assert.strictEqual(oParser.calculate().getValue(), 4, 'Result of WEEKDAY(,12)'); oParser = new parserFormula('WEEKDAY(,13)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,13)'); assert.strictEqual(oParser.calculate().getValue(), 3, 'Result of WEEKDAY(,13)'); oParser = new parserFormula('WEEKDAY(,14)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,14)'); assert.strictEqual(oParser.calculate().getValue(), 2, 'Result of WEEKDAY(,14)'); oParser = new parserFormula('WEEKDAY(,15)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,15)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of WEEKDAY(,15)'); oParser = new parserFormula('WEEKDAY(,16)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,16)'); assert.strictEqual(oParser.calculate().getValue(), 7, 'Result of WEEKDAY(,16)'); oParser = new parserFormula('WEEKDAY(,17)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,17)'); assert.strictEqual(oParser.calculate().getValue(), 6, 'Result of WEEKDAY(,17)'); oParser = new parserFormula('WEEKDAY(,20)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,20)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(,20)'); oParser = new parserFormula('WEEKDAY(,999999999999999999)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,999999999999999999)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(,999999999999999999)'); oParser = new parserFormula('WEEKDAY(,0)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,0)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(,0)'); oParser = new parserFormula('WEEKDAY(,-1)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(,-1)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of WEEKDAY(,-1)'); // arrays oParser = new parserFormula('WEEKDAY({1,2,3},2)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY({1,2,3},2)'); assert.strictEqual(oParser.calculate().getValue(), 6, 'Result of WEEKDAY({1,2,3},2)'); oParser = new parserFormula('WEEKDAY({1,2,3},2)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("F106:I109").bbox); assert.ok(oParser.parse(), 'WEEKDAY({1,2,3},2)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 6, "Result of WEEKDAY({1,2,3},2).[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 7, "Result of WEEKDAY({1,2,3},2).[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 1, "Result of WEEKDAY({1,2,3},2).[0,2]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of WEEKDAY({1,2,3},2).[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of WEEKDAY({1,2,3},2).[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", "Result of WEEKDAY({1,2,3},2).[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#N/A", "Result of WEEKDAY({1,2,3},2).[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "#N/A", "Result of WEEKDAY({1,2,3},2).[4,0]"); } oParser = new parserFormula('WEEKDAY(1,{1,2,3})', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(1,{1,2,3})'); assert.strictEqual(oParser.calculate().getValue(), 7, 'Result of WEEKDAY(1,{1,2,3})'); oParser = new parserFormula('WEEKDAY(1,{1,2,3})', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("F106:I109").bbox); assert.ok(oParser.parse(), 'WEEKDAY(1,{1,2,3})'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 7, "Result of WEEKDAY(1,{1,2,3}).[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 6, "Result of WEEKDAY(1,{1,2,3}).[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 5, "Result of WEEKDAY(1,{1,2,3}).[0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "", "Result of WEEKDAY(1,{1,2,3}).[0,3]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of WEEKDAY(1,{1,2,3}).[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of WEEKDAY(1,{1,2,3}).[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", "Result of WEEKDAY(1,{1,2,3}).[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#N/A", "Result of WEEKDAY(1,{1,2,3}).[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "#N/A", "Result of WEEKDAY(1,{1,2,3}).[4,0]"); } oParser = new parserFormula('WEEKDAY({1,2,3},{1,2,3})', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY({1,2,3},{1,2,3})'); oParser.setArrayFormulaRef(ws.getRange2("F106:I109").bbox); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 7, "Result of WEEKDAY({1,2,3},{1,2,3}).[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 7, "Result of WEEKDAY({1,2,3},{1,2,3}).[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 0, "Result of WEEKDAY({1,2,3},{1,2,3}).[0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "#N/A", "Result of WEEKDAY({1,2,3},{1,2,3}).[0,3]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 7, "Result of WEEKDAY({1,2,3},{1,2,3}).[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 7, "Result of WEEKDAY({1,2,3},{1,2,3}).[1,1]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 0, "Result of WEEKDAY({1,2,3},{1,2,3}).[1,2]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 7, "Result of WEEKDAY({1,2,3},{1,2,3}).[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 7, "Result of WEEKDAY({1,2,3},{1,2,3}).[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "", "Result of WEEKDAY({1,2,3},{1,2,3}).[4,0]"); } // cellsRange with new values ws.getRange2("E201").setValue("1"); ws.getRange2("E202").setValue("2"); ws.getRange2("E203").setValue("3"); ws.getRange2("E204").setValue("4"); oParser = new parserFormula("WEEKDAY(E201:E203,2)", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:E109").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 6, "Result of WEEKDAY(E201:E203,2).[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of WEEKDAY(E201:E203,2).[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 7, "Result of WEEKDAY(E201:E203,2).[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of WEEKDAY(E201:E203,2).[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 1, "Result of WEEKDAY(E201:E203,2).[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "", "Result of WEEKDAY(E201:E203,2).[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "#N/A", "Result of WEEKDAY(E201:E203,2).[4,0]"); } oParser = new parserFormula("WEEKDAY(E201:E203,E201:E203)", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:E109").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 7, "Result of WEEKDAY(E201:E203,E201:E203).[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of WEEKDAY(E201:E203,E201:E203).[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 7, "Result of WEEKDAY(E201:E203,E201:E203).[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of WEEKDAY(E201:E203,E201:E203).[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 0, "Result of WEEKDAY(E201:E203,E201:E203).[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "", "Result of WEEKDAY(E201:E203,E201:E203).[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "#N/A", "Result of WEEKDAY(E201:E203,E201:E203).[4,0]"); } oParser = new parserFormula('WEEKDAY(1,E201:E203)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(1,E201:E203)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of WEEKDAY(1,E201:E203)'); oParser = new parserFormula("WEEKDAY(1,E201:E203)", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:E109").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 7, "Result of WEEKDAY(1,E201:E203).[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of WEEKDAY(1,E201:E203).[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 6, "Result of WEEKDAY(1,E201:E203).[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of WEEKDAY(1,E201:E203).[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 5, "Result of WEEKDAY(1,E201:E203).[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "", "Result of WEEKDAY(1,E201:E203).[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "#N/A", "Result of WEEKDAY(1,E201:E203).[4,0]"); } // cellsRange with old values // ?? if don't redefine the values ​​in these cells after changing the mode to 1904, then the results in some arrays may be different // ws.getRange2("C101").setValue("1"); // ws.getRange2("C102").setValue("2"); // ws.getRange2("C103").setValue("3"); // ws.getRange2("C104").setValue("4"); oParser = new parserFormula("WEEKDAY(C101:C103,2)", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:E109").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 3, "Result of WEEKDAY(C101:C103,2).[0,0]"); //6 assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of WEEKDAY(C101:C103,2).[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 7, "Result of WEEKDAY(C101:C103,2).[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of WEEKDAY(C101:C103,2).[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 1, "Result of WEEKDAY(C101:C103,2).[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "", "Result of WEEKDAY(C101:C103,2).[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "#N/A", "Result of WEEKDAY(C101:C103,2).[4,0]"); } oParser = new parserFormula('WEEKDAY(C101:C103,C101:C103)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(C101:C103,C101:C103)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of WEEKDAY(C101:C103,C101:C103)'); oParser = new parserFormula("WEEKDAY(C101:C103,C101:C103)", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:E109").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#NUM!", "Result of WEEKDAY(C101:C103,C101:C103).[0,0]"); // 7 assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of WEEKDAY(C101:C103,C101:C103).[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 7, "Result of WEEKDAY(C101:C103,C101:C103).[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of WEEKDAY(C101:C103,C101:C103).[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 0, "Result of WEEKDAY(C101:C103,C101:C103).[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "", "Result of WEEKDAY(C101:C103,C101:C103).[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "#N/A", "Result of WEEKDAY(C101:C103,C101:C103).[4,0]"); } oParser = new parserFormula('WEEKDAY(1,C101:C103)', "A1", ws); assert.ok(oParser.parse(), 'WEEKDAY(1,C101:C103)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of WEEKDAY(1,C101:C103)'); oParser = new parserFormula("WEEKDAY(1,C101:C103)", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:E109").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#NUM!", "Result of WEEKDAY(1,C101:C103).[0,0]"); // 7 assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of WEEKDAY(1,C101:C103).[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 6, "Result of WEEKDAY(1,C101:C103).[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of WEEKDAY(1,C101:C103).[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 5, "Result of WEEKDAY(1,C101:C103).[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "", "Result of WEEKDAY(1,C101:C103).[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "#N/A", "Result of WEEKDAY(1,C101:C103).[4,0]"); } ws.getRange2("A1:Z500").cleanAll(); ws.workbook.setDate1904(false, true); }); QUnit.test("Test: \"WEIBULL\"", function (assert) { ws.getRange2("A2").setValue("105"); ws.getRange2("A3").setValue("20"); ws.getRange2("A4").setValue("100"); oParser = new parserFormula("WEIBULL(A2,A3,A4,TRUE)", "A20", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.929581); oParser = new parserFormula("WEIBULL(A2,A3,A4,FALSE)", "A20", ws); assert.ok(oParser.parse(), "WEIBULL(A2,A3,A4,FALSE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.035589); testArrayFormula2(assert, "WEIBULL", 4, 4); }); QUnit.test("Test: \"WEIBULL.DIST\"", function (assert) { ws.getRange2("A2").setValue("105"); ws.getRange2("A3").setValue("20"); ws.getRange2("A4").setValue("100"); oParser = new parserFormula("WEIBULL.DIST(A2,A3,A4,TRUE)", "A20", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.929581); oParser = new parserFormula("WEIBULL.DIST(A2,A3,A4,FALSE)", "A20", ws); assert.ok(oParser.parse(), "WEIBULL.DIST(A2,A3,A4,FALSE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.035589); testArrayFormula2(assert, "WEIBULL.DIST", 4, 4); }); QUnit.test("Test: \"YEARFRAC\"", function (assert) { function okWrapper(a, b) { assert.ok(Math.abs(a - b) < dif); } oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,3,26))", "A2", ws); assert.ok(oParser.parse()); okWrapper(oParser.calculate().getValue(), 0.236111111); oParser = new parserFormula("YEARFRAC(DATE(2006,3,26),DATE(2006,1,1))", "A2", ws); assert.ok(oParser.parse()); okWrapper(oParser.calculate().getValue(), 0.236111111); oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,7,1))", "A2", ws); assert.ok(oParser.parse()); okWrapper(oParser.calculate().getValue(), 0.5); oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2007,9,1))", "A2", ws); assert.ok(oParser.parse()); okWrapper(oParser.calculate().getValue(), 1.666666667); oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),0)", "A2", ws); assert.ok(oParser.parse()); okWrapper(oParser.calculate().getValue(), 0.5); oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),1)", "A2", ws); assert.ok(oParser.parse()); okWrapper(oParser.calculate().getValue(), 0.495890411); oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),2)", "A2", ws); assert.ok(oParser.parse()); okWrapper(oParser.calculate().getValue(), 0.502777778); oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),3)", "A2", ws); assert.ok(oParser.parse()); okWrapper(oParser.calculate().getValue(), 0.495890411); oParser = new parserFormula("YEARFRAC(DATE(2006,1,1),DATE(2006,7,1),4)", "A2", ws); assert.ok(oParser.parse()); okWrapper(oParser.calculate().getValue(), 0.5); oParser = new parserFormula("YEARFRAC(DATE(2004,3,1),DATE(2006,3,1),1)", "A2", ws); assert.ok(oParser.parse()); okWrapper(oParser.calculate().getValue(), 1.998175182481752); testArrayFormula2(assert, "YEARFRAC", 2, 3, true, null); }); QUnit.test("Test: \"DATEDIF\"", function (assert) { // base case oParser = new parserFormula("DATEDIF(DATE(2001,1,1),DATE(2003,1,1),\"Y\")", "A2", ws); assert.ok(oParser.parse(), "DATEDIF(DATE(2001,1,1),DATE(2003,1,1), Y)"); assert.strictEqual(oParser.calculate().getValue(), 2, "Result DATEDIF(DATE(2001,1,1),DATE(2003,1,1), Y)"); oParser = new parserFormula("DATEDIF(DATE(2001,1,1),DATE(2003,1,1),\"M\")", "A2", ws); assert.ok(oParser.parse(), "DATEDIF(DATE(2001,1,1),DATE(2003,1,1), M)"); assert.strictEqual(oParser.calculate().getValue(), 24, "Result DATEDIF(DATE(2001,1,1),DATE(2003,1,1), M)"); oParser = new parserFormula("DATEDIF(DATE(2001,1,1),DATE(2003,1,1),\"D\")", "A2", ws); assert.ok(oParser.parse(), "DATEDIF(DATE(2001,1,1),DATE(2003,1,1), D)"); assert.strictEqual(oParser.calculate().getValue(), 730, "Result DATEDIF(DATE(2001,1,1),DATE(2003,1,1), D)"); oParser = new parserFormula("DATEDIF(DATE(2001,6,1),DATE(2002,8,15),\"YD\")", "A2", ws); assert.ok(oParser.parse(), "DATEDIF(DATE(2001,6,1),DATE(2002,8,15), YD)"); assert.strictEqual(oParser.calculate().getValue(), 75, "Result DATEDIF(DATE(2001,6,1),DATE(2002,8,15), YD)"); oParser = new parserFormula("DATEDIF(DATE(2001,6,1),DATE(2002,8,15),\"MD\")", "A2", ws); assert.ok(oParser.parse(), "DATEDIF(DATE(2001,6,1),DATE(2002,8,15), MD)"); assert.strictEqual(oParser.calculate().getValue(), 14, "Result DATEDIF(DATE(2001,6,1),DATE(2002,8,15), MD)"); oParser = new parserFormula("DATEDIF(DATE(2001,6,1),DATE(2002,8,15),\"YM\")", "A2", ws); assert.ok(oParser.parse(), "DATEDIF(DATE(2001,6,1),DATE(2002,8,15), YM)"); assert.strictEqual(oParser.calculate().getValue(), 2, "Result DATEDIF(DATE(2001,6,1),DATE(2002,8,15), YM)"); // bug 54552 tests oParser = new parserFormula("DATEDIF(DATE(2020,10,2),DATE(2021,10,1),\"Y\")", "A2", ws); assert.ok(oParser.parse(), "Bug test case"); assert.strictEqual(oParser.calculate().getValue(), 0, "Bug test case"); oParser = new parserFormula("DATEDIF(DATE(2000,4,13),DATE(2022,4,12),\"Y\")", "A2", ws); assert.ok(oParser.parse(), "Bug test case 2"); assert.strictEqual(oParser.calculate().getValue(), 21, "Bug test case 2"); // strings oParser = new parserFormula("DATEDIF(\"sdy\",DATE(2022,4,12),\"Y\")", "A2", ws); assert.ok(oParser.parse(), "String first"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "String first"); oParser = new parserFormula("DATEDIF(\"12\",DATE(2022,4,12),\"Y\")", "A2", ws); assert.ok(oParser.parse(), "String number first"); assert.strictEqual(oParser.calculate().getValue(), 122, "String number first"); oParser = new parserFormula("DATEDIF(\"999999999999\",DATE(2022,4,12),\"Y\")", "A2", ws); assert.ok(oParser.parse(), "String number first"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "String number first"); oParser = new parserFormula("DATEDIF(DATE(2022,4,12),\"sdy\",\"Y\")", "A2", ws); assert.ok(oParser.parse(), "String second"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "String second"); oParser = new parserFormula("DATEDIF(DATE(2022,4,12),DATE(2032,4,12),\"string\")", "A2", ws); assert.ok(oParser.parse(), "String third"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "String third"); // numbers // TODO в ms результат: 121 oParser = new parserFormula("DATEDIF(12,DATE(2022,4,12),\"Y\")", "A2", ws); assert.ok(oParser.parse(), "Number first"); assert.strictEqual(oParser.calculate().getValue(), 122, "Number first"); oParser = new parserFormula("DATEDIF(999999999999,DATE(2022,4,12),\"Y\")", "A2", ws); assert.ok(oParser.parse(), "Number first"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Number first"); oParser = new parserFormula("DATEDIF(DATE(2022,4,12),12,\"Y\")", "A2", ws); assert.ok(oParser.parse(), "Number second"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Number second"); oParser = new parserFormula("DATEDIF(12,12,\"Y\")", "A2", ws); assert.ok(oParser.parse(), "Two equal numbers"); assert.strictEqual(oParser.calculate().getValue(), 0, "Two equal numbers"); oParser = new parserFormula("DATEDIF(12,22,\"Y\")", "A2", ws); assert.ok(oParser.parse(), "First number less than second(years)"); assert.strictEqual(oParser.calculate().getValue(), 0, "First number less than second(years)"); oParser = new parserFormula("DATEDIF(12,22,\"M\")", "A2", ws); assert.ok(oParser.parse(), "First number less than second(months)"); assert.strictEqual(oParser.calculate().getValue(), 0, "First number less than second(months)"); oParser = new parserFormula("DATEDIF(12,22,\"D\")", "A2", ws); assert.ok(oParser.parse(), "First number less than second(days)"); assert.strictEqual(oParser.calculate().getValue(), 10, "First number less than second(days)"); oParser = new parserFormula("DATEDIF(12,22,\"MD\")", "A2", ws); assert.ok(oParser.parse(), "First number less than second(MDays)"); assert.strictEqual(oParser.calculate().getValue(), 10, "First number less than second(MDays)"); oParser = new parserFormula("DATEDIF(12,22,\"YM\")", "A2", ws); assert.ok(oParser.parse(), "First number less than second(YMonths)"); assert.strictEqual(oParser.calculate().getValue(), 0, "First number less than second(YMonths)"); oParser = new parserFormula("DATEDIF(12,22,\"YD\")", "A2", ws); assert.ok(oParser.parse(), "First number less than second(YDays)"); assert.strictEqual(oParser.calculate().getValue(), 10, "First number less than second(YDays)"); oParser = new parserFormula("DATEDIF(-12,22,\"YD\")", "A2", ws); assert.ok(oParser.parse(), "DATEDIF(-12,22, YD)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "DATEDIF(-12,22, YD)"); oParser = new parserFormula("DATEDIF(-12,-22,\"YD\")", "A2", ws); assert.ok(oParser.parse(), "DATEDIF(-12,-22, YD)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "DATEDIF(-12,-22, YD)"); oParser = new parserFormula("DATEDIF(-1.2,22,\"YD\")", "A2", ws); assert.ok(oParser.parse(), "DATEDIF(-1.2,22, YD)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "DATEDIF(-1.2,22, YD)"); oParser = new parserFormula("DATEDIF(2,2.2,\"YD\")", "A2", ws); assert.ok(oParser.parse(), "DATEDIF(2,2.2, YD)"); assert.strictEqual(oParser.calculate().getValue(), 0, "DATEDIF(2,2.2, YD)"); oParser = new parserFormula("DATEDIF(1.2,2.2,\"YD\")", "A2", ws); assert.ok(oParser.parse(), "DATEDIF(1.2,2.2, YD)"); assert.strictEqual(oParser.calculate().getValue(), 1, "DATEDIF(1.2,2.2, YD)"); oParser = new parserFormula("DATEDIF(9,100,\"YM\")", "A2", ws); assert.ok(oParser.parse(), "DATEDIF(9,100, YM)"); assert.strictEqual(oParser.calculate().getValue(), 3, "DATEDIF(9,100, YM)"); // TODO в ms результат - 2 oParser = new parserFormula("DATEDIF(10,100,\"YM\")", "A2", ws); assert.ok(oParser.parse(), "DATEDIF(10,100, YM)"); assert.strictEqual(oParser.calculate().getValue(), 3, "DATEDIF(10,100, YM)"); // bool oParser = new parserFormula("DATEDIF(TRUE,DATE(2022,4,12),\"Y\")", "A2", ws); assert.ok(oParser.parse(), "Boolean true first"); assert.strictEqual(oParser.calculate().getValue(), 122, "Boolean true first"); oParser = new parserFormula("DATEDIF(FALSE,DATE(2022,4,12),\"Y\")", "A2", ws); assert.ok(oParser.parse(), "Boolean false first"); assert.strictEqual(oParser.calculate().getValue(), 122, "Boolean false first"); oParser = new parserFormula("DATEDIF(DATE(2022,4,12),TRUE,\"Y\")", "A2", ws); assert.ok(oParser.parse(), "Boolean second"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Boolean second"); // exotic dates oParser = new parserFormula("DATEDIF(DATE(4022,4,12),DATE(4023,4,12),\"Y\")", "A2", ws); assert.ok(oParser.parse(), "Exotic date"); assert.strictEqual(oParser.calculate().getValue(), 1, "Exotic date"); oParser = new parserFormula("DATEDIF(DATE(9999,30,12),DATE(99999,30,12),\"Y\")", "A2", ws); assert.ok(oParser.parse(), "Exotic date"); assert.strictEqual(oParser.calculate().getValue(), 90000, "Exotic date"); oParser = new parserFormula("DATEDIF(DATE(9999,30,12),DATE(99999,30,12),\"M\")", "A2", ws); assert.ok(oParser.parse(), "Exotic date"); assert.strictEqual(oParser.calculate().getValue(), 1080000, "Exotic date"); oParser = new parserFormula("DATEDIF(DATE(9999,30,12),DATE(99999,30,12222),\"M\")", "A2", ws); assert.ok(oParser.parse(), "Exotic date"); assert.strictEqual(oParser.calculate().getValue(), 1080401, "Exotic date"); oParser = new parserFormula("DATEDIF(DATE(9999,30,12),DATE(99999,30,12),\"D\")", "A2", ws); assert.ok(oParser.parse(), "Exotic date"); assert.strictEqual(oParser.calculate().getValue(), 32871825, "Exotic date"); oParser = new parserFormula("DATEDIF(DATE(9999,30,12),DATE(99999,30000,12),\"D\")", "A2", ws); assert.ok(oParser.parse(), "Exotic date"); assert.strictEqual(oParser.calculate().getValue(), 33784019, "Exotic date"); oParser = new parserFormula("DATEDIF(DATE(1,1,1),DATE(1,2,1),\"Y\")", "A2", ws); assert.ok(oParser.parse(), "Exotic date"); assert.strictEqual(oParser.calculate().getValue(), 0, "Exotic date"); // arrays|range ws.getRange2("B2").setValue("2"); ws.getRange2("B3").setValue("5"); ws.getRange2("B4").setValue("15"); ws.getRange2("B5").setValue("string"); ws.getRange2("B6").setValue("#N/A"); ws.getRange2("B7").setValue(); ws.getRange2("B8").setValue(""); ws.getRange2("C2").setValue("2"); ws.getRange2("C3").setValue("12"); ws.getRange2("C4").setValue("15"); ws.getRange2("C5").setValue("25"); ws.getRange2("C6").setValue("25.5"); oParser = new parserFormula("DATEDIF({223,999,250},250,\"D\")", "A2", ws); assert.ok(oParser.parse(), "Pass array to first argument and number to second argument."); assert.strictEqual(oParser.calculate().getValue(), 27, "Pass array to first argument and number to second argument."); oParser = new parserFormula("DATEDIF(B2:B2,25,\"D\")", "A2", ws); assert.ok(oParser.parse(), "Pass cellsRange to first argument and number to second argument."); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Pass array to first argument and number to second argument."); oParser = new parserFormula("DATEDIF(C2:C6,25,\"D\")", "A2", ws); assert.ok(oParser.parse(), "Pass cellsRange to first and number to second argument."); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Pass cellsRange to first and number to second argument."); // ctrl shift enter cases oParser = new parserFormula("DATEDIF(C2:C6,25,\"D\")", "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:C6").bbox); assert.ok(oParser.parse(), "Pass cellsRange to first and number to second argument."); let array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 23, "Pass cellsRange to first and number to second argument.[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 13, "Pass cellsRange to first and number to second argument.[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 10, "Pass cellsRange to first and number to second argument.[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 0, "Pass cellsRange to first and number to second argument.[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "#NUM!", "Pass cellsRange to first and number to second argument.[4,0]"); oParser = new parserFormula("DATEDIF(12,C2:C6,\"D\")", "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:C6").bbox); assert.ok(oParser.parse(), "Pass number to first and cellsRange to second argument."); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#NUM!", "Pass number to first and cellsRange to second argument.[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 0, "Pass number to first and cellsRange to second argument.[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 3, "Pass number to first and cellsRange to second argument.[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 13, "Pass number to first and cellsRange to second argument.[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 13, "Pass number to first and cellsRange to second argument.[4,0]"); oParser = new parserFormula("DATEDIF(C2:C6,C2:C6,\"D\")", "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:C6").bbox); assert.ok(oParser.parse(), "Pass cellsRange to first and cellsRange to second argument."); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 0, "Pass cellsRange to first and cellsRange to second argument.[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 0, "Pass cellsRange to first and cellsRange to second argument.[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 0, "Pass cellsRange to first and cellsRange to second argument.[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 0, "Pass cellsRange to first and cellsRange to second argument.[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 0, "Pass cellsRange to first and cellsRange to second argument.[4,0]"); oParser = new parserFormula("DATEDIF(B2:B8,DATE(10,2,2020),\"D\")", "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("B2:B8").bbox); assert.ok(oParser.parse(), "Pass cellsRange to first and date to second argument."); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 5702, "Pass cellsRange to first and date to second argument.[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 5699, "Pass cellsRange to first and date to second argument.[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 5689, "Pass cellsRange to first and date to second argument.[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#VALUE!", "Pass cellsRange to first and date to second argument.[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "#N/A", "Pass cellsRange to first and date to second argument.[4,0]"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 5704, "Pass cellsRange to first and date to second argument.[5,0]"); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), 5704, "Pass cellsRange to first and date to second argument.[6,0]"); oParser = new parserFormula("DATEDIF(B2:B8,DATE(2020,10,2),\"D\")", "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("B2:B8").bbox); assert.ok(oParser.parse(), "Pass cellsRange to first and date to second argument."); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 44104, "Pass cellsRange to first and date to second argument.[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 44101, "Pass cellsRange to first and date to second argument.[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 44091, "Pass cellsRange to first and date to second argument.[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#VALUE!", "Pass cellsRange to first and date to second argument.[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "#N/A", "Pass cellsRange to first and date to second argument.[4,0]"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 44106, "Pass cellsRange to first and date to second argument.[5,0]"); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), 44106, "Pass cellsRange to first and date to second argument.[6,0]"); oParser = new parserFormula("DATEDIF(DATE(2020,10,2),B2:B8,\"D\")", "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("B2:B8").bbox); assert.ok(oParser.parse(), "Pass date to first and cellsRange to second argument."); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#NUM!", "Pass date to first and cellsRange to second argument.[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#NUM!", "Pass date to first and cellsRange to second argument.[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#NUM!", "Pass date to first and cellsRange to second argument.[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#VALUE!", "Pass date to first and cellsRange to second argument.[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "#N/A", "Pass date to first and cellsRange to second argument.[4,0]"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), "#NUM!", "Pass date to first and cellsRange to second argument.[5,0]"); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), "#NUM!", "Pass date to first and cellsRange to second argument.[6,0]"); oParser = new parserFormula("DATEDIF(B2:B8,B2:B8,\"D\")", "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("B2:B8").bbox); assert.ok(oParser.parse(), "Pass cellsRange to first and cellsRange to second argument."); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 0, "Pass cellsRange to first and cellsRange to second argument.[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 0, "Pass cellsRange to first and cellsRange to second argument.[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 0, "Pass cellsRange to first and cellsRange to second argument.[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#VALUE!", "Pass cellsRange to first and cellsRange to second argument.[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "#N/A", "Pass cellsRange to first and cellsRange to second argument.[4,0]"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 0, "Pass cellsRange to first and cellsRange to second argument.[5,0]"); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), 0, "Pass cellsRange to first and cellsRange to second argument.[6,0]"); testArrayFormula2(assert, "DATEDIF", 3, 3); }); QUnit.test("Test: \"PRODUCT\"", function (assert) { ws.getRange2("A2").setValue("5"); ws.getRange2("A3").setValue("15"); ws.getRange2("A4").setValue("30"); oParser = new parserFormula("PRODUCT(A2:A4)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2250); oParser = new parserFormula("PRODUCT(A2:A4, 2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4500); testArrayFormula2(assert, "PRODUCT", 1, 8, null, true); }); QUnit.test("Test: \"SUMPRODUCT\"", function (assert) { oParser = new parserFormula("SUMPRODUCT({2,3})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5); oParser = new parserFormula("SUMPRODUCT({2,3},{4,5})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 23); oParser = new parserFormula("SUMPRODUCT({2,3},{4,5},{2,2})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 46); oParser = new parserFormula("SUMPRODUCT({2,3;4,5},{2,2;3,4})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 42); ws.getRange2("N44").setValue("1"); ws.getRange2("N45").setValue("2"); ws.getRange2("N46").setValue("3"); ws.getRange2("N47").setValue("4"); ws.getRange2("O44").setValue("5"); ws.getRange2("O45").setValue("6"); ws.getRange2("O46").setValue("7"); ws.getRange2("O47").setValue("8"); ws.getRange2("P44").setValue("9"); ws.getRange2("P45").setValue("10"); ws.getRange2("P46").setValue("11"); ws.getRange2("P47").setValue("12"); ws.getRange2("P48").setValue(""); ws.getRange2("P49").setValue(""); ws.getRange2("N48").setValue("0.456"); ws.getRange2("O48").setValue("0.123212"); oParser = new parserFormula("SUMPRODUCT(N44:N47,O44:O47,P44:P47)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 780); oParser = new parserFormula("SUMPRODUCT(N44:N47*O44:O47)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 70); oParser = new parserFormula("SUMPRODUCT(SUM(N44:N47*O44:O47))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 70); oParser = new parserFormula("SUMPRODUCT({1,2,TRUE,3})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 6); oParser = new parserFormula("SUMPRODUCT({1,2,FALSE,3})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 6); oParser = new parserFormula("SUMPRODUCT({TRUE,TRUE,FALSE,3})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); oParser = new parserFormula("SUMPRODUCT(P48)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("SUMPRODUCT(P48, P44:P47)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("SUMPRODUCT(P48:P49)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("SUM(SUMPRODUCT(N44:N47*O44:O47))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 70); oParser = new parserFormula("SUMPRODUCT(N44:O47*P44:P47)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 388); oParser = new parserFormula("SUM(SUMPRODUCT(N44:O47*P44:P47))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 388); oParser = new parserFormula("SUM(SUMPRODUCT(N44:O47))", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "SUM(SUMPRODUCT(N44:O47))"); assert.strictEqual(oParser.calculate().getValue(), 36); oParser = new parserFormula("SUMPRODUCT(YEAR(N45:O47))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 11400); oParser = new parserFormula("SUMPRODUCT(MONTH(N45:O47))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 6); oParser = new parserFormula("SUMPRODUCT(DAY(N45:O47))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 30); oParser = new parserFormula("SUMPRODUCT(HOUR(N45:P48))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 12); oParser = new parserFormula("SUMPRODUCT(MINUTE(N45:P48))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 113); oParser = new parserFormula("SUMPRODUCT(SECOND(N45:P48))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 64); oParser = new parserFormula("SUMPRODUCT(DAY(N44:P49))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 78); oParser = new parserFormula("SUMPRODUCT(MONTH(N44:P49))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 18); oParser = new parserFormula("SUMPRODUCT(YEAR(N44:P49))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 34200); oParser = new parserFormula("SUMPRODUCT(({1,2,3})*({TRUE,TRUE,TRUE}))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 6); /*oParser = new parserFormula( "SUMPRODUCT(({1,2,3})*({TRUE;TRUE;TRUE;TRUE}))", "A2", ws ); assert.ok( oParser.parse() ); assert.strictEqual( oParser.calculate().getValue(), 24 );*/ oParser = new parserFormula("SUMPRODUCT({TRUE,TRUE,FALSE})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("SUMPRODUCT({1,2,3,3,TRUE})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 9); oParser = new parserFormula("SUMPRODUCT({1,2,3,3,TRUE})+SUMPRODUCT({1,2,3,3,TRUE})", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "SUMPRODUCT({1,2,3,3,TRUE})+SUMPRODUCT({1,2,3,3,TRUE})"); assert.strictEqual(oParser.calculate().getValue(), 18); oParser = new parserFormula("SUMPRODUCT({1,2,3,3,TRUE})*SUMPRODUCT({1,2,3,3,TRUE})", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "SUMPRODUCT({1,2,3,3,TRUE})*SUMPRODUCT({1,2,3,3,TRUE})"); assert.strictEqual(oParser.calculate().getValue(), 81); oParser = new parserFormula("SUMPRODUCT(SUMPRODUCT({1,2,3,3,TRUE})*SUMPRODUCT({1,2,3,3,TRUE}))", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "SUMPRODUCT(SUMPRODUCT({1,2,3,3,TRUE})*SUMPRODUCT({1,2,3,3,TRUE}))"); assert.strictEqual(oParser.calculate().getValue(), 81); oParser = new parserFormula("SUM(SUMPRODUCT({1,2,3,3,TRUE})*SUMPRODUCT({1,2,3,3,TRUE}))", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "SUM(SUMPRODUCT({1,2,3,3,TRUE})*SUMPRODUCT({1,2,3,3,TRUE}))"); assert.strictEqual(oParser.calculate().getValue(), 81); oParser = new parserFormula("SUM(SUMPRODUCT({1,2,3,3,TRUE})*SUMPRODUCT({1,2,3,3,TRUE}),1,2,3)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "SUM(SUMPRODUCT({1,2,3,3,TRUE})*SUMPRODUCT({1,2,3,3,TRUE}),1,2,3)"); assert.strictEqual(oParser.calculate().getValue(), 87); oParser = new parserFormula("SUM(SUMPRODUCT(N44:O47))+SUM(SUMPRODUCT(N44:O47))", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "SUM(SUMPRODUCT(N44:O47))+SUM(SUMPRODUCT(N44:O47))"); assert.strictEqual(oParser.calculate().getValue(), 72); oParser = new parserFormula("SUM(SUMPRODUCT({1,2,3,3,TRUE})*SUMPRODUCT({1,2,3,3,TRUE}),SUMPRODUCT({1,2,3,3,TRUE}),2,SUMPRODUCT({1,2,3,3}))", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "SUM(SUMPRODUCT({1,2,3,3,TRUE})*SUMPRODUCT({1,2,3,3,TRUE}),SUMPRODUCT({1,2,3,3,TRUE}),2,SUMPRODUCT({1,2,3,3}))"); assert.strictEqual(oParser.calculate().getValue(), 101); ws.getRange2("A101").setValue("5"); ws.getRange2("A102").setValue("6"); ws.getRange2("A103").setValue("7"); ws.getRange2("A104").setValue("8"); ws.getRange2("A105").setValue("9"); ws.getRange2("B101").setValue("1"); ws.getRange2("B102").setValue("1"); ws.getRange2("B103").setValue("0"); ws.getRange2("B104").setValue("1"); ws.getRange2("B105").setValue("1"); oParser = new parserFormula("SUMPRODUCT((A101:A105)*((B101:B105)=1))", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "SUMPRODUCT((A101:A105)*((B101:B105)=1))"); assert.strictEqual(oParser.calculate().getValue(), 28); oParser = new parserFormula("SUMPRODUCT((A101:A105)*((B101:B105)=1))+SUMPRODUCT((A101:A104)*((B101:B104)=1))+SUMPRODUCT((A101:A103)*((B101:B103)=1))", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "SUMPRODUCT((A101:A105)*((B101:B105)=1))+SUMPRODUCT((A101:A104)*((B101:B104)=1))+SUMPRODUCT((A101:A103)*((B101:B103)=1))"); assert.strictEqual(oParser.calculate().getValue(), 58); oParser = new parserFormula("SUMPRODUCT(({3})*({TRUE,TRUE,TRUE,TRUE}))", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "SUMPRODUCT(({3})*({TRUE,TRUE,TRUE,TRUE}))"); assert.strictEqual(oParser.calculate().getValue(), 12); oParser = new parserFormula("SUMPRODUCT(({3;2;2;2})*({TRUE;TRUE;TRUE;TRUE}))", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "SUMPRODUCT(({3;2;2;2})*({TRUE;TRUE;TRUE;TRUE}))"); assert.strictEqual(oParser.calculate().getValue(), 9); oParser = new parserFormula("SUMPRODUCT(--ISNUMBER({5;6;7;1;2;3;4}))", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "SUMPRODUCT(--ISNUMBER({5;6;7;1;2;3;4}))"); assert.strictEqual(oParser.calculate().getValue(), 7); oParser = new parserFormula("SUMPRODUCT(--ISNUMBER(SEARCH({5;6;7;1;2;3;4},123)))", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "SUMPRODUCT(--ISNUMBER(SEARCH({5;6;7;1;2;3;4},123)))"); assert.strictEqual(oParser.calculate().getValue(), 3); // for bug 68820 ws.getRange2("B100").setValue("-2"); ws.getRange2("B101").setValue("1"); ws.getRange2("B102").setValue("-1"); ws.getRange2("B103").setValue("0"); ws.getRange2("B104").setValue("1"); ws.getRange2("B105").setValue("1"); ws.getRange2("B106").setValue("-2"); ws.getRange2("B107").setValue("0"); ws.getRange2("B108").setValue("0"); oParser = new parserFormula('SUMPRODUCT(SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0)))', "A2", ws); assert.ok(oParser.parse(), 'SUMPRODUCT(SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0)))'); assert.strictEqual(oParser.calculate().getValue(), -2, 'SUMPRODUCT(SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0)))'); oParser = new parserFormula('SUMPRODUCT(SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0))*(B100:B108>0))', "A2", ws); assert.ok(oParser.parse(), 'SUMPRODUCT(SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0))*(B100:B108>0))'); assert.strictEqual(oParser.calculate().getValue(), 3, 'SUMPRODUCT(SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0))*(B100:B108>0))'); oParser = new parserFormula('SUMPRODUCT(SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0),OFFSET(B100,ROW(B100:B108)-ROW(B100),0))*(B100:B108>0))', "A2", ws); assert.ok(oParser.parse(), 'SUMPRODUCT(SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0),OFFSET(B100,ROW(B100:B108)-ROW(B100),0))*(B100:B108>0))'); assert.strictEqual(oParser.calculate().getValue(), 6, 'SUMPRODUCT(SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0),OFFSET(B100,ROW(B100:B108)-ROW(B100),0))*(B100:B108>0))'); testArrayFormula2(assert, "SUMPRODUCT", 1, 8, null, true); }); QUnit.test("Test: \"SINH\"", function (assert) { oParser = new parserFormula("SINH(0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("SINH(1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ((Math.E - 1 / Math.E) / 2)); testArrayFormula(assert, "SINH"); }); QUnit.test("Test: \"SIGN\"", function (assert) { oParser = new parserFormula("SIGN(10)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("SIGN(4-4)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("SIGN(-0.00001)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -1); testArrayFormula(assert, "SIGN"); }); QUnit.test("Test: \"COSH\"", function (assert) { oParser = new parserFormula("COSH(0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("COSH(1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ((Math.E + 1 / Math.E) / 2)); }); QUnit.test("Test: \"IMCOSH\"", function (assert) { oParser = new parserFormula('IMCOSH("4+3i")', "A2", ws); assert.ok(oParser.parse(), 'IMCOSH("4+3i")'); assert.strictEqual(oParser.calculate().getValue(), "-27.03494560307422+3.8511533348117766i", 'IMCOSH("4+3i")'); testArrayFormula(assert, "IMCOSH", true); }); QUnit.test("Test: \"IMCOS\"", function (assert) { oParser = new parserFormula('IMCOS("1+i")', "A2", ws); assert.ok(oParser.parse(), 'IMCOS("1+i")'); assert.strictEqual(oParser.calculate().getValue(), "0.8337300251311491-0.9888977057628651i", 'IMCOS("1+i")'); testArrayFormula(assert, "IMCOS", true); }); QUnit.test("Test: \"IMCOT\"", function (assert) { oParser = new parserFormula('IMCOT("4+3i")', "A2", ws); assert.ok(oParser.parse(), 'IMCOT("4+3i")'); assert.strictEqual(oParser.calculate().getValue(), "0.004901182394304475-0.9992669278059015i", 'IMCOT("4+3i")'); testArrayFormula(assert, "IMCOT", true); }); QUnit.test("Test: \"IMCSC\"", function (assert) { oParser = new parserFormula('IMCSC("4+3i")', "A2", ws); assert.ok(oParser.parse(), 'IMCSC("4+3i")'); assert.strictEqual(oParser.calculate().getValue(), "-0.0754898329158637+0.06487747137063551i", 'IMCSC("4+3i")'); testArrayFormula(assert, "IMCSC", true); }); QUnit.test("Test: \"IMCSCH\"", function (assert) { oParser = new parserFormula('IMCSCH("4+3i")', "A2", ws); assert.ok(oParser.parse(), 'IMCSCH("4+3i")'); //assert.strictEqual( oParser.calculate().getValue(), "-0.03627588962862601-0.0051744731840193976i", 'IMCSCH("4+3i")' ); testArrayFormula(assert, "IMCSCH", true); }); QUnit.test("Test: \"IMSIN\"", function (assert) { oParser = new parserFormula('IMSIN("4+3i")', "A2", ws); assert.ok(oParser.parse(), 'IMSIN("4+3i")'); assert.strictEqual(oParser.calculate().getValue(), "-7.619231720321408-6.548120040911002i", 'IMSIN("4+3i")'); testArrayFormula(assert, "IMSIN", true); }); QUnit.test("Test: \"IMSINH\"", function (assert) { oParser = new parserFormula('IMSINH("4+3i")', "A2", ws); assert.ok(oParser.parse(), 'IMSINH("4+3i")'); assert.strictEqual(oParser.calculate().getValue(), "-27.01681325800393+3.8537380379193764i", 'IMSINH("4+3i")'); testArrayFormula(assert, "IMSINH", true); }); QUnit.test("Test: \"IMSEC\"", function (assert) { oParser = new parserFormula('IMSEC("4+3i")', "A2", ws); assert.ok(oParser.parse(), 'IMSEC("4+3i")'); assert.strictEqual(oParser.calculate().getValue(), "-0.06529402785794705-0.07522496030277323i", 'IMSEC("4+3i")'); testArrayFormula(assert, "IMSEC", true); }); QUnit.test("Test: \"IMSECH\"", function (assert) { //TODO в хроме при расчёте разница, временно убираю oParser = new parserFormula('IMSECH("4+3i")', "A2", ws); assert.ok(oParser.parse(), 'IMSECH("4+3i")'); //assert.strictEqual( oParser.calculate().getValue(), "-0.03625349691586888-0.00516434460775318i", 'IMSECH("4+3i")' ); testArrayFormula(assert, "IMSECH", true); }); QUnit.test("Test: \"IMTAN\"", function (assert) { oParser = new parserFormula('IMTAN("4+3i")', "A2", ws); assert.ok(oParser.parse(), 'IMTAN("4+3i")'); assert.strictEqual(oParser.calculate().getValue(), "0.004908258067496062+1.000709536067233i", 'IMTAN("4+3i")'); testArrayFormula(assert, "IMTAN", true); }); QUnit.test("Test: \"IMSQRT\"", function (assert) { oParser = new parserFormula('IMSQRT("1+i")', "A2", ws); assert.ok(oParser.parse(), 'IMSQRT("1+i")'); //assert.strictEqual( oParser.calculate().getValue(), "1.0986841134678098+0.4550898605622274i", 'IMSQRT("1+i")' ); testArrayFormula(assert, "IMSQRT", true); }); QUnit.test("Test: \"IMREAL\"", function (assert) { oParser = new parserFormula('IMREAL("6-9i")', "A2", ws); assert.ok(oParser.parse(), 'IMREAL("6-9i")'); assert.strictEqual(oParser.calculate().getValue(), 6, 'IMREAL("6-9i")'); testArrayFormula(assert, "IMREAL", true); }); QUnit.test("Test: \"IMLOG2\"", function (assert) { //TODO в excel результат данной формулы - "2.32192809488736+1.33780421245098i" oParser = new parserFormula('IMLOG2("3+4i")', "A2", ws); assert.ok(oParser.parse(), 'IMLOG2("3+4i")'); assert.strictEqual(oParser.calculate().getValue(), "2.321928094887362+1.3378042124509761i", 'IMLOG2("3+4i")'); oParser = new parserFormula('IMLOG2("")', "A2", ws); assert.ok(oParser.parse(), 'IMLOG2("")'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of IMLOG2("")'); oParser = new parserFormula('IMLOG2(1)', "A2", ws); assert.ok(oParser.parse(), 'IMLOG2(1)'); assert.strictEqual(oParser.calculate().getValue(), "0", 'Result of IMLOG2(1)'); oParser = new parserFormula('IMLOG2(-1)', "A2", ws); assert.ok(oParser.parse(), 'IMLOG2(-1)'); assert.strictEqual(oParser.calculate().getValue(), "4.532360141827194i", 'Result of IMLOG2(-1)'); oParser = new parserFormula('IMLOG2("i")', "A2", ws); assert.ok(oParser.parse(), 'IMLOG2("i")'); assert.strictEqual(oParser.calculate().getValue(), "2.266180070913597i", 'Result of IMLOG2("i")'); oParser = new parserFormula('IMLOG2("ii")', "A2", ws); assert.ok(oParser.parse(), 'IMLOG2("ii")'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of IMLOG2("ii")'); oParser = new parserFormula('IMLOG2("1i")', "A2", ws); assert.ok(oParser.parse(), 'IMLOG2("1i")'); assert.strictEqual(oParser.calculate().getValue(), "2.266180070913597i", 'Result of IMLOG2("1i")'); oParser = new parserFormula('IMLOG2("0.5+i")', "A2", ws); assert.ok(oParser.parse(), 'IMLOG2("0.5+i")'); assert.strictEqual(oParser.calculate().getValue(), "0.16096404744368123+1.5972779646881086i", 'Result of IMLOG2("0.5+i")'); oParser = new parserFormula('IMLOG2("1+i")', "A2", ws); assert.ok(oParser.parse(), 'IMLOG2("1+i")'); assert.strictEqual(oParser.calculate().getValue(), "0.5+1.1330900354567985i", 'Result of IMLOG2("1+i")'); testArrayFormula(assert, "IMLOG2", true); }); QUnit.test("Test: \"IMLOG10\"", function (assert) { //TODO в excel результат данной формулы - "0.698970004336019+0.402719196273373i" oParser = new parserFormula('IMLOG10("3+4i")', "A2", ws); assert.ok(oParser.parse(), 'IMLOG10("3+4i")'); assert.strictEqual(oParser.calculate().getValue(), "0.6989700043360186+0.40271919627337305i", 'IMLOG10("3+4i")'); oParser = new parserFormula('IMLOG10("")', "A2", ws); assert.ok(oParser.parse(), 'IMLOG10("")'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of IMLOG10("")'); oParser = new parserFormula('IMLOG10(1)', "A2", ws); assert.ok(oParser.parse(), 'IMLOG10(1)'); assert.strictEqual(oParser.calculate().getValue(), "0", 'Result of IMLOG10(1)'); oParser = new parserFormula('IMLOG10(-1)', "A2", ws); assert.ok(oParser.parse(), 'IMLOG10(-1)'); assert.strictEqual(oParser.calculate().getValue(), "1.364376353841841i", 'Result of IMLOG10(-1)'); oParser = new parserFormula('IMLOG10("i")', "A2", ws); assert.ok(oParser.parse(), 'IMLOG10("i")'); assert.strictEqual(oParser.calculate().getValue(), "0.6821881769209205i", 'Result of IMLOG10("i")'); oParser = new parserFormula('IMLOG10("ii")', "A2", ws); assert.ok(oParser.parse(), 'IMLOG10("ii")'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of IMLOG10("ii")'); oParser = new parserFormula('IMLOG10("1i")', "A2", ws); assert.ok(oParser.parse(), 'IMLOG10("1i")'); assert.strictEqual(oParser.calculate().getValue(), "0.6821881769209205i", 'Result of IMLOG10("1i")'); oParser = new parserFormula('IMLOG10("0.5+i")', "A2", ws); assert.ok(oParser.parse(), 'IMLOG10("0.5+i")'); assert.strictEqual(oParser.calculate().getValue(), "0.04845500650402821+0.48082857878423396i", 'Result of IMLOG10("0.5+i")'); oParser = new parserFormula('IMLOG10("1+i")', "A2", ws); assert.ok(oParser.parse(), 'IMLOG10("1+i")'); assert.strictEqual(oParser.calculate().getValue(), "0.1505149978319906+0.3410940884604603i", 'Result of IMLOG10("1+i")'); testArrayFormula(assert, "IMLOG10", true); }); QUnit.test("Test: \"IMLN\"", function (assert) { //TODO в excel результат данной формулы - "1.6094379124341+0.927295218001612i" oParser = new parserFormula('IMLN("3+4i")', "A2", ws); assert.ok(oParser.parse(), 'IMLN("3+4i")'); assert.strictEqual(oParser.calculate().getValue(), "1.6094379124341003+0.9272952180016123i", 'IMLN("3+4i")'); testArrayFormula(assert, "IMLN", true); }); QUnit.test("Test: \"IMEXP\"", function (assert) { //TODO в excel результат данной формулы - "1.46869393991589+2.28735528717884i" oParser = new parserFormula('IMEXP("1+i")', "A2", ws); assert.ok(oParser.parse(), 'IMEXP("1+i")'); assert.strictEqual(oParser.calculate().getValue(), "1.4686939399158851+2.2873552871788423i", 'IMEXP("1+i")'); testArrayFormula(assert, "IMEXP", true); }); QUnit.test("Test: \"IMCONJUGATE\"", function (assert) { oParser = new parserFormula('IMCONJUGATE("3+4i")', "A2", ws); assert.ok(oParser.parse(), 'IMCONJUGATE("3+4i")'); assert.strictEqual(oParser.calculate().getValue(), "3-4i", 'IMCONJUGATE("3+4i")'); testArrayFormula(assert, "IMCONJUGATE", true); }); QUnit.test("Test: \"IMARGUMENT\"", function (assert) { oParser = new parserFormula('IMARGUMENT("3+4i")', "A2", ws); assert.ok(oParser.parse(), 'IMARGUMENT("3+4i")'); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 0.92729522, 'IMARGUMENT("3+4i")'); testArrayFormula(assert, "IMARGUMENT", true); }); QUnit.test("Test: \"IMAGINARY\"", function (assert) { oParser = new parserFormula('IMAGINARY("3+4i")', "A2", ws); assert.ok(oParser.parse(), 'IMAGINARY("3+4i")'); assert.strictEqual(oParser.calculate().getValue(), 4, 'IMAGINARY("3+4i")'); oParser = new parserFormula('IMAGINARY("0-j")', "A2", ws); assert.ok(oParser.parse(), 'IMAGINARY("0-j")'); assert.strictEqual(oParser.calculate().getValue(), -1, 'IMAGINARY("0-j")'); oParser = new parserFormula('IMAGINARY("4")', "A2", ws); assert.ok(oParser.parse(), 'IMAGINARY("4")'); assert.strictEqual(oParser.calculate().getValue(), 0, 'IMAGINARY("4")'); testArrayFormula(assert, "IMAGINARY", true); }); QUnit.test("Test: \"IMDIV\"", function (assert) { oParser = new parserFormula('IMDIV("-238+240i","10+24i")', "A2", ws); assert.ok(oParser.parse(), 'IMDIV("-238+240i","10+24i")'); assert.strictEqual(oParser.calculate().getValue(), "5+12i", 'IMDIV("-238+240i","10+24i")'); testArrayFormula2(assert, "IMDIV", 2, 2, true, null); }); QUnit.test("Test: \"IMPOWER\"", function (assert) { testArrayFormula2(assert, "IMPOWER", 2, 2, true, null); }); QUnit.test("Test: \"IMABS\"", function (assert) { oParser = new parserFormula('IMABS("5+12i")', "A2", ws); assert.ok(oParser.parse(), 'IMABS("5+12i"'); assert.strictEqual(oParser.calculate().getValue(), 13, 'IMABS("5+12i"'); testArrayFormula(assert, "IMABS", true); }); QUnit.test("Test: \"IMSUB\"", function (assert) { oParser = new parserFormula('IMSUB("13+4i","5+3i")', "A2", ws); assert.ok(oParser.parse(), 'IMSUB("13+4i","5+3i")'); assert.strictEqual(oParser.calculate().getValue(), "8+i", 'IMSUB("13+4i","5+3i")'); testArrayFormula2(assert, "IMSUB", 2, 2, true, null); }); QUnit.test("Test: \"TAN\"", function (assert) { oParser = new parserFormula("TAN(0.785)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(5) - 0, 0.99920); oParser = new parserFormula("TAN(45*PI()/180)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(1) - 0, 1); testArrayFormula(assert, "TAN"); }); QUnit.test("Test: \"TANH\"", function (assert) { oParser = new parserFormula("TANH(0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("TANH(1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(difBetween(oParser.calculate().getValue(), ((Math.E * Math.E - 1) / (Math.E * Math.E + 1))), true); testArrayFormula(assert, "TANH"); }); QUnit.test("Test: \"TAKE\"", function (assert) { //1. добавляем общие тесты ws.getRange2("A1").setValue("1"); ws.getRange2("A2").setValue("2"); ws.getRange2("A3").setValue(""); ws.getRange2("A4").setValue("4"); ws.getRange2("A5").setValue("#N/A"); ws.getRange2("A6").setValue("f"); ws.getRange2("B1").setValue("q"); ws.getRange2("B2").setValue("w"); ws.getRange2("B3").setValue("e"); ws.getRange2("B4").setValue("test"); ws.getRange2("B5").setValue("hhh"); ws.getRange2("B6").setValue("g"); ws.getRange2("C1").setValue("r"); ws.getRange2("C2").setValue("3"); ws.getRange2("C3").setValue("5"); ws.getRange2("C4").setValue(""); ws.getRange2("C5").setValue("6"); ws.getRange2("C6").setValue("h"); ws.getRange2("D1").setValue(""); ws.getRange2("D2").setValue(""); ws.getRange2("D3").setValue(""); ws.getRange2("D4").setValue(""); ws.getRange2("D5").setValue(""); ws.getRange2("D6").setValue(""); oParser = new parserFormula("TAKE(A1:C6,1,2)", "A1", ws); assert.ok(oParser.parse()); let array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 'q'); oParser = new parserFormula("TAKE(A1:D5,100,100)", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), ''); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 4); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), '#N/A'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 'q'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 'w'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 'e'); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), 'test'); assert.strictEqual(array.getElementRowCol(4, 1).getValue(), 'hhh'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 'r'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 3); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), 5); assert.strictEqual(array.getElementRowCol(3, 2).getValue(), ''); assert.strictEqual(array.getElementRowCol(4, 2).getValue(), 6); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), ''); assert.strictEqual(array.getElementRowCol(1, 3).getValue(), ''); assert.strictEqual(array.getElementRowCol(2, 3).getValue(), ''); assert.strictEqual(array.getElementRowCol(3, 3).getValue(), ''); assert.strictEqual(array.getElementRowCol(4, 3).getValue(), ''); oParser = new parserFormula("TAKE(A1:D5,-1,-4)", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), '#N/A'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 'hhh'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 6); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), ''); oParser = new parserFormula("TAKE(A1:D5,,-2)", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 'r'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 5); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), ''); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 6); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), ''); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), ''); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), ''); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), ''); assert.strictEqual(array.getElementRowCol(4, 1).getValue(), ''); oParser = new parserFormula("TAKE(A1:D5,2,)", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 'q'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 'w'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 'r'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 3); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), ''); assert.strictEqual(array.getElementRowCol(1, 3).getValue(), ''); oParser = new parserFormula("TAKE(A1:D5,2)", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2); //2. аргументы - разные типы. нужно пербрать все аргументы //2.1 аргумент - number oParser = new parserFormula("TAKE(1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.2 аргумент - string oParser = new parserFormula("TAKE(\"test\",1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "test"); //2.3 аргумент - bool oParser = new parserFormula("TAKE(true,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "TRUE"); //2.4 аргумент - error oParser = new parserFormula("TAKE(#VALUE!,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.5 аргумент - empty oParser = new parserFormula("TAKE(,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.6 аргумент - cellsRange //2.7 аргумент - cell oParser = new parserFormula("TAKE(B1, 1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "q"); //2.8 аргумент - array oParser = new parserFormula("TAKE({2;\"\";\"test\"},3)", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), ''); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 'test'); oParser = new parserFormula("TAKE({1,2,3},2,1)", "A1", ws); assert.ok(oParser.parse(), "TAKE({1,2,3},2,1)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of TAKE({1,2,3},2,1)"); oParser = new parserFormula("TAKE({1;2;3},1,2)", "A1", ws); assert.ok(oParser.parse(), "TAKE({1;2;3},1,2)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of TAKE({1;2;3},1,2)"); //2.2 аргумент - string oParser = new parserFormula("TAKE(1,\"test\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.3 аргумент - bool oParser = new parserFormula("TAKE(1,true)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.4 аргумент - error oParser = new parserFormula("TAKE(1, #VALUE!)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.5 аргумент - empty oParser = new parserFormula("TAKE(1,)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.6 аргумент - cellsRange //2.7 аргумент - cell oParser = new parserFormula("TAKE(1,A1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); oParser = new parserFormula("TAKE(1,A1:B5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.8 аргумент - array oParser = new parserFormula("TAKE(1,{2;\"\";\"test\"})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); }); QUnit.test("Test: \"DROP\"", function (assert) { //1. добавляем общие тесты ws.getRange2("A1").setValue("1"); ws.getRange2("A2").setValue("2"); ws.getRange2("A3").setValue(""); ws.getRange2("A4").setValue("4"); ws.getRange2("A5").setValue("#N/A"); ws.getRange2("A6").setValue("f"); ws.getRange2("B1").setValue("q"); ws.getRange2("B2").setValue("w"); ws.getRange2("B3").setValue("e"); ws.getRange2("B4").setValue("test"); ws.getRange2("B5").setValue("hhh"); ws.getRange2("B6").setValue("g"); ws.getRange2("C1").setValue("r"); ws.getRange2("C2").setValue("3"); ws.getRange2("C3").setValue("5"); ws.getRange2("C4").setValue(""); ws.getRange2("C5").setValue("6"); ws.getRange2("C6").setValue("h"); ws.getRange2("D1").setValue(""); ws.getRange2("D2").setValue(""); ws.getRange2("D3").setValue(""); ws.getRange2("D4").setValue(""); ws.getRange2("D5").setValue(""); ws.getRange2("D6").setValue(""); oParser = new parserFormula("DROP(A1:C6,1,2)", "A1", ws); assert.ok(oParser.parse()); let array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 3); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 5); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), ''); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 6); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 'h'); //TODO ms calc error oParser = new parserFormula("DROP(A1:D5,100,100)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //TODO ms calc error oParser = new parserFormula("DROP(A1:D5,-1,-4)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("DROP(A1:D5,,-2)", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), ''); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 4); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), '#N/A'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 'q'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 'w'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 'e'); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), 'test'); assert.strictEqual(array.getElementRowCol(4, 1).getValue(), 'hhh'); oParser = new parserFormula("DROP(A1:D5,2,)", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), ''); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 4); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), '#N/A'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 'e'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 'test'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 'hhh'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 5); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), ''); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), 6); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), ''); assert.strictEqual(array.getElementRowCol(1, 3).getValue(), ''); assert.strictEqual(array.getElementRowCol(2, 3).getValue(), ''); oParser = new parserFormula("DROP(A1:D5,2)", "A1", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), ''); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 4); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), '#N/A'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 'e'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 'test'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 'hhh'); //2. аргументы - разные типы. нужно пербрать все аргументы //2.1 аргумент - number oParser = new parserFormula("DROP(1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.2 аргумент - string oParser = new parserFormula("DROP(\"test\",1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.3 аргумент - bool oParser = new parserFormula("DROP(true,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.4 аргумент - error oParser = new parserFormula("DROP(#VALUE!,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.5 аргумент - empty oParser = new parserFormula("DROP(,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.6 аргумент - cellsRange //2.7 аргумент - cell oParser = new parserFormula("DROP(B1, 1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.8 аргумент - array oParser = new parserFormula("DROP({2;\"\";\"test\"},3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.2 аргумент - string oParser = new parserFormula("DROP(1,\"test\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.3 аргумент - bool oParser = new parserFormula("DROP(1,true)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.4 аргумент - error oParser = new parserFormula("DROP(1, #N/A)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); //2.5 аргумент - empty oParser = new parserFormula("DROP(1,)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); //2.6 аргумент - cellsRange //2.7 аргумент - cell oParser = new parserFormula("DROP(1,A1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("DROP(1,A1:B5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); //2.8 аргумент - array oParser = new parserFormula("DROP(1,{2;\"\";\"test\"})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); }); QUnit.test("Test: \"ATAN\"", function (assert) { oParser = new parserFormula('ATAN(1)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 0.785398163); testArrayFormula(assert, "ATAN"); }); QUnit.test("Test: \"ATAN2\"", function (assert) { oParser = new parserFormula('ATAN2(1, 1)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 0.785398163); oParser = new parserFormula('ATAN2(-1, -1)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, -2.35619449); oParser = new parserFormula('ATAN2(-1, -1)*180/PI()', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -135); oParser = new parserFormula('DEGREES(ATAN2(-1, -1))', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -135); testArrayFormula2(assert, "ATAN2", 2, 2); }); QUnit.test("Test: \"ATANH\"", function (assert) { oParser = new parserFormula('ATANH(0.76159416)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 1.00000001); oParser = new parserFormula('ATANH(-0.1)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, -0.100335348); testArrayFormula(assert, "ATANH"); }); QUnit.test("Test: \"XOR\"", function (assert) { oParser = new parserFormula('XOR(3>0,2<9)', "A2", ws); assert.ok(oParser.parse(), 'XOR(3>0,2<9)'); assert.strictEqual(oParser.calculate().getValue(), "FALSE", 'XOR(3>0,2<9)'); oParser = new parserFormula('XOR(3>12,4>6)', "A2", ws); assert.ok(oParser.parse(), 'XOR(3>12,4>6)'); assert.strictEqual(oParser.calculate().getValue(), "FALSE", 'XOR(3>12,4>6)'); oParser = new parserFormula('XOR(3>12,4<6)', "A2", ws); assert.ok(oParser.parse(), 'XOR(3>12,4<6)'); assert.strictEqual(oParser.calculate().getValue(), "TRUE", 'XOR(3>12,4<6)'); //area - specific for xor function //all empty - false result ws.getRange2("A101").setValue("5"); ws.getRange2("A102").setValue("6"); ws.getRange2("A103").setValue("test1"); ws.getRange2("A104").setValue(""); ws.getRange2("A105").setValue("false"); ws.getRange2("B101").setValue("1"); ws.getRange2("B102").setValue("1"); ws.getRange2("B103").setValue("test2"); ws.getRange2("B104").setValue(""); ws.getRange2("B105").setValue("false"); ws.getRange2("B106").setValue("#VALUE!"); oParser = new parserFormula('XOR(A101:B102)', "A2", ws); assert.ok(oParser.parse(), 'XOR(A101:B102)'); assert.strictEqual(oParser.calculate().getValue(), "FALSE"); oParser = new parserFormula('XOR(A101:B103)', "A2", ws); assert.ok(oParser.parse(), 'XOR(A101:B103)'); assert.strictEqual(oParser.calculate().getValue(), "FALSE"); oParser = new parserFormula('XOR(A101:A103)', "A2", ws); assert.ok(oParser.parse(), 'XOR(A101:A103)'); assert.strictEqual(oParser.calculate().getValue(), "TRUE"); oParser = new parserFormula('XOR(A101:A104)', "A2", ws); assert.ok(oParser.parse(), 'XOR(A101:A104)'); assert.strictEqual(oParser.calculate().getValue(), "FALSE"); oParser = new parserFormula('XOR(A104:B104)', "A2", ws); assert.ok(oParser.parse(), 'XOR(A104:B104)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula('XOR(A101:B104)', "A2", ws); assert.ok(oParser.parse(), 'XOR(A101:B104)'); assert.strictEqual(oParser.calculate().getValue(), "FALSE"); oParser = new parserFormula('XOR(A101:B105)', "A2", ws); assert.ok(oParser.parse(), 'XOR(A101:B105)'); assert.strictEqual(oParser.calculate().getValue(), "FALSE"); oParser = new parserFormula('XOR(A101:A105)', "A2", ws); assert.ok(oParser.parse(), 'XOR(A101:A105)'); assert.strictEqual(oParser.calculate().getValue(), "TRUE"); oParser = new parserFormula('XOR(B101:A106)', "A2", ws); assert.ok(oParser.parse(), 'XOR(B101:A106)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); testArrayFormula2(assert, "XOR", 1, 8, null, true); }); QUnit.test("Test: \"COMBIN\"", function (assert) { oParser = new parserFormula("COMBIN(8,2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 28); oParser = new parserFormula("COMBIN(10,4)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 210); oParser = new parserFormula("COMBIN(6,5)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 6); oParser = new parserFormula("COMBIN(-6,5)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("COMBIN(3,5)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("COMBIN(6,-5)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("COMBIN(0,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("COMBIN(0,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("COMBIN(,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("COMBIN(,)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("COMBIN(1,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("COMBIN(2424,2424)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("COMBIN(2424,2423)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); // cString oParser = new parserFormula('COMBIN("22",2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 231); oParser = new parserFormula('COMBIN("22s",2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula('COMBIN("22","2")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 231); oParser = new parserFormula('COMBIN("22","2s")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula('COMBIN("22s",#NUM!)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); // cBool oParser = new parserFormula('COMBIN(22,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula('COMBIN(22,TRUE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 22); oParser = new parserFormula('COMBIN(TRUE,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula('COMBIN(TRUE,TRUE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula('COMBIN(FALSE,TRUE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula('COMBIN(TRUE,1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula('COMBIN(TRUE,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); // cArray oParser = new parserFormula("COMBIN(20,{1,2,3})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), 20); assert.strictEqual(oParser.calculate().getElementRowCol(0,1).getValue(), 190); assert.strictEqual(oParser.calculate().getElementRowCol(0,2).getValue(), 1140); assert.strictEqual(oParser.calculate().getElementRowCol(1,0).getValue(), ""); assert.strictEqual(oParser.calculate().getElementRowCol(1,1).getValue(), ""); assert.strictEqual(oParser.calculate().getElementRowCol(1,2).getValue(), ""); oParser = new parserFormula("COMBIN({12;9},{5,2,13})", "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("AD6:AF8").bbox); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), 792); assert.strictEqual(oParser.calculate().getElementRowCol(0,1).getValue(), 66); assert.strictEqual(oParser.calculate().getElementRowCol(0,2).getValue(), "#NUM!"); assert.strictEqual(oParser.calculate().getElementRowCol(1,0).getValue(), 126); assert.strictEqual(oParser.calculate().getElementRowCol(1,1).getValue(), 36); assert.strictEqual(oParser.calculate().getElementRowCol(1,2).getValue(), "#NUM!"); oParser = new parserFormula("COMBIN({12,9;10,19},10)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), 66); assert.strictEqual(oParser.calculate().getElementRowCol(0,1).getValue(), "#NUM!"); assert.strictEqual(oParser.calculate().getElementRowCol(0,2).getValue(), ""); assert.strictEqual(oParser.calculate().getElementRowCol(1,0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(1,1).getValue(), 92378); assert.strictEqual(oParser.calculate().getElementRowCol(1,2).getValue(), ""); // cellsRange ws.getRange2("R10").setValue("1"); ws.getRange2("R11").setValue("2"); ws.getRange2("R12").setValue("3"); ws.getRange2("S10").setValue("20"); ws.getRange2("S11").setValue("10"); ws.getRange2("S12").setValue("5"); oParser = new parserFormula("COMBIN(R10:S12,R10:R12)", "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("AD6:AF8").bbox); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(0,1).getValue(), 20); assert.strictEqual(oParser.calculate().getElementRowCol(0,2).getValue(), ""); assert.strictEqual(oParser.calculate().getElementRowCol(1,0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(1,1).getValue(), 45); assert.strictEqual(oParser.calculate().getElementRowCol(1,2).getValue(), ""); assert.strictEqual(oParser.calculate().getElementRowCol(2,0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(2,1).getValue(), 10); assert.strictEqual(oParser.calculate().getElementRowCol(2,2).getValue(), ""); oParser = new parserFormula("COMBIN(11,R10:R12)", "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("AD6:AF8").bbox); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), 11); assert.strictEqual(oParser.calculate().getElementRowCol(0,1).getValue(), ""); assert.strictEqual(oParser.calculate().getElementRowCol(1,0).getValue(), 55); assert.strictEqual(oParser.calculate().getElementRowCol(1,1).getValue(), ""); assert.strictEqual(oParser.calculate().getElementRowCol(2,0).getValue(), 165); assert.strictEqual(oParser.calculate().getElementRowCol(2,1).getValue(), ""); oParser = new parserFormula("COMBIN(R10:S12,2)", "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("AD6:AF8").bbox); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), "#NUM!"); assert.strictEqual(oParser.calculate().getElementRowCol(0,1).getValue(), 190); assert.strictEqual(oParser.calculate().getElementRowCol(1,0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(1,1).getValue(), 45); assert.strictEqual(oParser.calculate().getElementRowCol(2,0).getValue(), 3); assert.strictEqual(oParser.calculate().getElementRowCol(2,1).getValue(), 10); }); QUnit.test("Test: \"FACTDOUBLE\"", function (assert) { oParser = new parserFormula("FACTDOUBLE(8)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2 * 4 * 6 * 8); oParser = new parserFormula("FACTDOUBLE(9)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 9 * 7 * 5 * 3); oParser = new parserFormula("FACTDOUBLE(6.5)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 6 * 4 * 2); oParser = new parserFormula("FACTDOUBLE(-6)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("FACTDOUBLE(600)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); testArrayFormula(assert, "FACTDOUBLE", true); }); QUnit.test("Test: \"FACT\"", function (assert) { oParser = new parserFormula("FACT(5)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 120); oParser = new parserFormula("FACT(1.9)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("FACT(0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("FACT(-1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("FACT(1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); testArrayFormula(assert, "FACT"); }); QUnit.test("Test: \"GCD\"", function (assert) { oParser = new parserFormula("LCM(5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5); oParser = new parserFormula("LCM(24.6,36.2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 72); oParser = new parserFormula("LCM(-1,39,52)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("LCM(0,39,52)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("LCM(24,36,15)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 360); testArrayFormula2(assert, "LCM", 1, 8, null, true); }); QUnit.test("Test: \"RANDBETWEEN\"", function (assert) { let res; oParser = new parserFormula("RANDBETWEEN(1,6)", "A1", ws); assert.ok(oParser.parse()); res = oParser.calculate().getValue(); assert.ok(res >= 1 && res <= 6); oParser = new parserFormula("RANDBETWEEN(-10,10)", "A1", ws); assert.ok(oParser.parse()); res = oParser.calculate().getValue(); assert.ok(res >= -10 && res <= 10); oParser = new parserFormula("RANDBETWEEN(-25,-3)", "A1", ws); assert.ok(oParser.parse()); res = oParser.calculate().getValue(); assert.ok(res >= -25 && res <= -3); oParser = new parserFormula("RANDBETWEEN(1,100)", "A1", ws); assert.ok(oParser.parse()); res = oParser.calculate().getValue(); assert.ok(res >= 1 && res <= 100); oParser = new parserFormula("RANDBETWEEN(0,999999999999999999999999999)", "A1", ws); assert.ok(oParser.parse()); res = oParser.calculate().getValue(); assert.ok(res >= 9 && res <= 999999999999999999999999999n); oParser = new parserFormula("RANDBETWEEN(-1,100)", "A1", ws); assert.ok(oParser.parse()); res = oParser.calculate().getValue(); assert.ok(res >= -1 && res <= 100); oParser = new parserFormula("RANDBETWEEN(1,-1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("RANDBETWEEN(1.1,22.9)", "A1", ws); assert.ok(oParser.parse()); res = oParser.calculate().getValue(); assert.ok(res >= 2 && res <= 22); oParser = new parserFormula("RANDBETWEEN(-22.9,-1.1)", "A1", ws); assert.ok(oParser.parse()); res = oParser.calculate().getValue(); assert.ok(res >= -22 && res <= -1); oParser = new parserFormula("RANDBETWEEN(DATE(2022,1,1), DATE(2022,4,12))", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN(55, DATE(2022,4,12))"); res = oParser.calculate().getValue(); assert.ok(res >= 44562 && res <= 44663); oParser = new parserFormula("RANDBETWEEN(55, DATE(2022,4,12))", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN(55, DATE(2022,4,12))"); res = oParser.calculate().getValue(); assert.ok(res >= 55 && res <= 44663); oParser = new parserFormula("RANDBETWEEN(DATE(2022,4,12), 55)", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN(DATE(2022,4,12), 55)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result RANDBETWEEN(DATE(2022,4,12), 55)"); oParser = new parserFormula("RANDBETWEEN(1,)", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN(1,)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result RANDBETWEEN(1,) "); oParser = new parserFormula("RANDBETWEEN(,1)", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN(,1)"); res = oParser.calculate().getValue(); assert.ok(res >= 0 && res <= 1, "Result RANDBETWEEN(,1) "); oParser = new parserFormula("RANDBETWEEN(,)", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN(,)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result RANDBETWEEN(,) "); oParser = new parserFormula("RANDBETWEEN({1.5,2.5},{2.5,3.5})", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN('{1.5,2.5}',{2.5,3.5})"); let array = oParser.calculate(); res = array.getElementRowCol(0, 0).getValue(); assert.strictEqual(res, 2, "Result RANDBETWEEN({1.5,2.5},{2.5,3.5})[0,0] "); res = array.getElementRowCol(0, 1).getValue(); assert.strictEqual(res, 3, "Result RANDBETWEEN({1.5,2.5},{2.5,3.5})[0,1] "); res = array.getElementRowCol(0, 2).getValue(); assert.strictEqual(res, "", "Result RANDBETWEEN({1.5,2.5},{2.5,3.5})[0,2] "); oParser = new parserFormula("RANDBETWEEN(1,{5.5,3.5})", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN(1,{5.5,3.5})"); array = oParser.calculate(); res = array.getElementRowCol(0, 0).getValue(); assert.ok(res >= 1 && res <= 5, "Result RANDBETWEEN(1,{5.5,3.5})[0,0]"); res = array.getElementRowCol(0, 1).getValue(); assert.ok(res >= 1 && res <= 5, "Result RANDBETWEEN(1,{5.5,3.5})[0,1]"); res = array.getElementRowCol(1, 0).getValue(); assert.strictEqual(res, "", "Result RANDBETWEEN(1,{5.5,3.5})[1,0] "); res = array.getElementRowCol(2, 0).getValue(); assert.strictEqual(res, "#N/A", "Result RANDBETWEEN(1,{5.5,3.5})[2,0] "); oParser = new parserFormula("RANDBETWEEN(null, undefined)", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN(null, undefined)"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Result RANDBETWEEN(null, undefined)"); ws.getRange2("A3").setValue("1.5"); ws.getRange2("A4").setValue("2.5"); ws.getRange2("A5").setValue("13"); ws.getRange2("A6").setValue("23"); ws.getRange2("A7").setValue("25"); ws.getRange2("A8").setValue("55"); ws.getRange2("A9").setValue("-2"); ws.getRange2("A10").setValue("0.01"); ws.getRange2("A11").setValue("-0.01"); ws.getRange2("A12").setValue("#N/A"); ws.getRange2("A13").setValue("test1"); ws.getRange2("A14").setValue("TRUE"); ws.getRange2("A15").setValue(""); ws.getRange2("A16").setValue(); ws.getRange2("A17").setValue("1/1/2000"); ws.getRange2("A18").setValue("2/2/2000"); // data in cells oParser = new parserFormula("RANDBETWEEN(A3,A4)", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN(1.5,2.5) in cells"); assert.strictEqual(oParser.calculate().getValue(), 2, "Result RANDBETWEEN(1.5,2.5) in cells"); oParser = new parserFormula("RANDBETWEEN(A3,A8)", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN(1.5,55) in cells"); res = oParser.calculate().getValue(); assert.ok(res >= 2 && res <= 55, "Result RANDBETWEEN(1.5,55) in cells"); oParser = new parserFormula("RANDBETWEEN(A11,A10)", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN(-0.01,0.01) in cells"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result RANDBETWEEN(-0.01,0.01) in cells"); oParser = new parserFormula("RANDBETWEEN(A8,A7)", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN(55,25) in cells"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result RANDBETWEEN(55,25) in cells"); oParser = new parserFormula("RANDBETWEEN(A14,A14)", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN(TRUE,TRUE) in cells"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result RANDBETWEEN(TRUE,TRUE) in cells"); oParser = new parserFormula("RANDBETWEEN(A14,A7)", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN(TRUE,25) in cells"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result RANDBETWEEN(TRUE,25) in cells"); oParser = new parserFormula("RANDBETWEEN(A10,A14)", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN(0.01,TRUE) in cells"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result RANDBETWEEN(TRUE,25) in cells"); oParser = new parserFormula("RANDBETWEEN(A12,A8)", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN(N/A,55) in cells"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result RANDBETWEEN(N/A,55) in cells"); oParser = new parserFormula("RANDBETWEEN(A13,A13)", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN(test1,test1) in cells"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result RANDBETWEEN(test1,test1) in cells"); oParser = new parserFormula("RANDBETWEEN(A15,A15)", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN('','') in cells"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result RANDBETWEEN('','') in cells"); oParser = new parserFormula("RANDBETWEEN(A16,A16)", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN(,) in cells"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result RANDBETWEEN(,) in cells"); oParser = new parserFormula("RANDBETWEEN(,A15)", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN('','') in cells"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result RANDBETWEEN('','') in cells"); oParser = new parserFormula("RANDBETWEEN(A15,)", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN('','') in cells"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result RANDBETWEEN('','') in cells"); oParser = new parserFormula("RANDBETWEEN(A17,A17)", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN('1/1/2000','1/1/2000') in cells"); assert.strictEqual(oParser.calculate().getValue(), 36526, "Result RANDBETWEEN('1/1/2000','1/1/2000') in cells"); oParser = new parserFormula("RANDBETWEEN(A17,A18)", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN('1/1/2000','2/2/2000') in cells"); res = oParser.calculate().getValue(); assert.ok(res >= 36526 && res <= 36558, "Result RANDBETWEEN('1/1/2000','2/2/2000') in cells"); oParser = new parserFormula("RANDBETWEEN(A8,A18)", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN(55,'2/2/2000') in cells"); res = oParser.calculate().getValue(); assert.ok(res >= 55 && res <= 36558, "Result RANDBETWEEN(55,'2/2/2000') in cells"); oParser = new parserFormula("RANDBETWEEN(A18,A8)", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN('2/2/2000',55) in cells"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result RANDBETWEEN('2/2/2000',55) in cells"); oParser = new parserFormula("RANDBETWEEN(A3:A4,A5:A6)", "A2", ws); assert.ok(oParser.parse(), "RANDBETWEEN('{1.5,2.5}',{13,23}) in cells"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result RANDBETWEEN({1.5,2.5},{13,23}) in cells"); // special cases oParser = new parserFormula("RANDBETWEEN(1.5,2.5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2, "Result RANDBETWEEN(1.5,2.5)"); oParser = new parserFormula("RANDBETWEEN(-2.5,-1.5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -2, "Result RANDBETWEEN(-2.5,-1.5)"); oParser = new parserFormula("RANDBETWEEN(0.00000000005,0.1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1, "RANDBETWEEN(0.00000000005,0.1)"); oParser = new parserFormula("RANDBETWEEN(-0.1,-0.00000000005)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0, "RANDBETWEEN(-0.1,-0.00000000005)"); // for bug 67684 /* Sample of 10 thousand values */ ws.getRange2("A1:Z10002").cleanAll(); wb.dependencyFormulas.unlockRecal(); ws.getRange2("A10002:C10002").setValue("0"); ws.getRange2("A100").setValue("1"); ws.getRange2("A101").setValue("2"); ws.getRange2("A102:A10002").setValue("=RANDBETWEEN(A100,A101)"); // [1,2] ws.getRange2("B101").setValue("3"); ws.getRange2("B102:B10002").setValue("=RANDBETWEEN(A100,B101)"); // [1,3] ws.getRange2("C101").setValue("4"); ws.getRange2("C102:C10002").setValue("=RANDBETWEEN(A100,C101)"); // [1,4] // spreading percentages for range [1,2] oParser = new parserFormula("COUNTIF(A102:A10002,1)/100", "A1", ws); assert.ok(oParser.parse()); res = Math.round(oParser.calculate().getValue()); assert.ok(res >= 47 && res <= 53, "Spreading percentages for number 1 in COUNTIF(A102:A10002,1)/100"); oParser = new parserFormula("COUNTIF(A102:A10002,2)/100", "A1", ws); assert.ok(oParser.parse()); res = Math.round(oParser.calculate().getValue()); assert.ok(res >= 47 && res <= 53, "Spreading percentages for number 2 in COUNTIF(A102:A10002,2)/100"); // spreading percentages for range [1,3] oParser = new parserFormula("COUNTIF(B102:B10002,1)/100", "A1", ws); assert.ok(oParser.parse()); res = Math.round(oParser.calculate().getValue()); assert.ok(res >= 31 && res <= 37, "Spreading percentages for number 1 in COUNTIF(B102:B10002,1)/100"); oParser = new parserFormula("COUNTIF(B102:B10002,2)/100", "A1", ws); assert.ok(oParser.parse()); res = Math.round(oParser.calculate().getValue()); assert.ok(res >= 31 && res <= 37, "Spreading percentages for number 2 in COUNTIF(B102:B10002,2)/100"); oParser = new parserFormula("COUNTIF(B102:B10002,3)/100", "A1", ws); assert.ok(oParser.parse()); res = Math.round(oParser.calculate().getValue()); assert.ok(res >= 31 && res <= 37, "Spreading percentages for number 3 in COUNTIF(B102:B10002,3)/100"); // spreading percentages for range [1,4] oParser = new parserFormula("COUNTIF(C102:C10002,1)/100", "A1", ws); assert.ok(oParser.parse()); res = Math.round(oParser.calculate().getValue()); assert.ok(res >= 20 && res <= 29, "Spreading percentages for number 1 in COUNTIF(C102:C10002,1)/100"); oParser = new parserFormula("COUNTIF(C102:C10002,2)/100", "A1", ws); assert.ok(oParser.parse()); res = Math.round(oParser.calculate().getValue()); assert.ok(res >= 20 && res <= 29, "Spreading percentages for number 2 in COUNTIF(C102:C10002,2)/100"); oParser = new parserFormula("COUNTIF(C102:C10002,3)/100", "A1", ws); assert.ok(oParser.parse()); res = Math.round(oParser.calculate().getValue()); assert.ok(res >= 20 && res <= 29, "Spreading percentages for number 3 in COUNTIF(C102:C10002,3)/100"); oParser = new parserFormula("COUNTIF(C102:C10002,4)/100", "A1", ws); assert.ok(oParser.parse()); res = Math.round(oParser.calculate().getValue()); assert.ok(res >= 20 && res <= 29, "Spreading percentages for number 4 in COUNTIF(C102:C10002,4)/100"); ws.getRange2("A100:D10002").cleanAll(); }); QUnit.test("Test: \"RANDARRAY\"", function (assert) { ws.getRange2("A101").setValue("2"); ws.getRange2("A102").setValue("2"); ws.getRange2("A103").setValue("test1"); ws.getRange2("A104").setValue("-4"); ws.getRange2("A105").setValue("-1"); var res; oParser = new parserFormula("RANDARRAY(A101,A102)", "A1", ws); assert.ok(oParser.parse()); res = oParser.calculate().getElementRowCol(0, 0).getValue(); assert.ok(res >= 0 && res <= 1); res = oParser.calculate().getElementRowCol(1, 0).getValue(); assert.ok(res >= 0 && res <= 1); res = oParser.calculate().getElementRowCol(0, 1).getValue(); assert.ok(res >= 0 && res <= 1); res = oParser.calculate().getElementRowCol(1, 1).getValue(); assert.ok(res >= 0 && res <= 1); oParser = new parserFormula("RANDARRAY(A101,A102,A104,A105)", "A1", ws); assert.ok(oParser.parse()); res = oParser.calculate().getElementRowCol(0, 0).getValue(); assert.ok(res >= -4 && res <= -1); res = oParser.calculate().getElementRowCol(1, 0).getValue(); assert.ok(res >= -4 && res <= -1); res = oParser.calculate().getElementRowCol(0, 1).getValue(); assert.ok(res >= -4 && res <= -1); res = oParser.calculate().getElementRowCol(1, 1).getValue(); assert.ok(res >= -4 && res <= -1); oParser = new parserFormula("RANDARRAY()", "A1", ws); assert.ok(oParser.parse()); res = oParser.calculate().getElementRowCol(0, 0).getValue(); assert.ok(res >= 0 && res <= 1); oParser = new parserFormula("RANDARRAY(2,2)", "A1", ws); assert.ok(oParser.parse()); res = oParser.calculate().getElementRowCol(0, 0).getValue(); assert.ok(res >= 0 && res <= 1); res = oParser.calculate().getElementRowCol(1, 0).getValue(); assert.ok(res >= 0 && res <= 1); res = oParser.calculate().getElementRowCol(0, 1).getValue(); assert.ok(res >= 0 && res <= 1); res = oParser.calculate().getElementRowCol(1, 1).getValue(); assert.ok(res >= 0 && res <= 1); oParser = new parserFormula("RANDARRAY(2,2,-10,-5)", "A1", ws); assert.ok(oParser.parse()); res = oParser.calculate().getElementRowCol(0, 0).getValue(); assert.ok(res >= -10 && res <= -5); res = oParser.calculate().getElementRowCol(1, 0).getValue(); assert.ok(res >= -10 && res <= -5); res = oParser.calculate().getElementRowCol(0, 1).getValue(); assert.ok(res >= -10 && res <= -5); res = oParser.calculate().getElementRowCol(1, 1).getValue(); assert.ok(res >= -10 && res <= -5); oParser = new parserFormula("RANDARRAY(2,2,-10,-5, true)", "A1", ws); assert.ok(oParser.parse()); res = oParser.calculate().getElementRowCol(0, 0).getValue(); assert.ok(res >= -10 && res <= -5); res = oParser.calculate().getElementRowCol(1, 0).getValue(); assert.ok(res >= -10 && res <= -5); res = oParser.calculate().getElementRowCol(0, 1).getValue(); assert.ok(res >= -10 && res <= -5); res = oParser.calculate().getElementRowCol(1, 1).getValue(); assert.ok(res >= -10 && res <= -5); oParser = new parserFormula("RANDARRAY(2,2,,, true)", "A1", ws); assert.ok(oParser.parse()); res = oParser.calculate().getElementRowCol(0, 0).getValue(); assert.ok(res >= 0 && res <= 1); res = oParser.calculate().getElementRowCol(1, 0).getValue(); assert.ok(res >= 0 && res <= 1); res = oParser.calculate().getElementRowCol(0, 1).getValue(); assert.ok(res >= 0 && res <= 1); res = oParser.calculate().getElementRowCol(1, 1).getValue(); assert.ok(res >= 0 && res <= 1); oParser = new parserFormula("RANDARRAY(-1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("RANDARRAY(1, -1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("RANDARRAY(-1, -1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("RANDARRAY(1, 1, 5, 2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("RANDARRAY(0, 0, 5, 2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("RANDARRAY(0, 1, 5, 2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("RANDARRAY(1, 0, 5, 2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("RANDARRAY(1,1,,-2,FALSE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("RANDARRAY(1,1,2,,FALSE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("RANDARRAY(A103,1,2,,FALSE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); ws.getRange2("A101").setValue("#DIV/0!"); ws.getRange2("A102").setValue("2"); ws.getRange2("A103").setValue("3"); ws.getRange2("A104").setValue("4"); ws.getRange2("A105").setValue("5"); ws.getRange2("A105").setValue("6"); ws.getRange2("B101").setValue("-3"); ws.getRange2("B102").setValue("-5"); ws.getRange2("B103").setValue("2"); ws.getRange2("B104").setValue("1"); ws.getRange2("B105").setValue("12"); ws.getRange2("B105").setValue("13"); oParser = new parserFormula("RANDARRAY({1,123,3},{1,2,3,4},,2,A101:C101)", "A1", ws); assert.ok(oParser.parse()); res = oParser.calculate().getElementRowCol(0, 0).getValue(); assert.strictEqual(res, "#DIV/0!"); res = oParser.calculate().getElementRowCol(0, 1).getValue(); assert.ok(res >= 0 && res <= 2); res = oParser.calculate().getElementRowCol(0, 2).getValue(); assert.ok(res >= 0 && res <= 2); }); QUnit.test("Test: \"QUOTIENT\"", function (assert) { oParser = new parserFormula("QUOTIENT(1,6)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("QUOTIENT(-10,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -3); oParser = new parserFormula("QUOTIENT(5,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("QUOTIENT(5,0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!"); testArrayFormula2(assert, "QUOTIENT", 2, 2, true) }); QUnit.test("Test: \"TRUNC\"", function (assert) { let array; // https://0.30000000000000004.com/ oParser = new parserFormula("TRUNC(PI())", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); oParser = new parserFormula("TRUNC(PI(),3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3.141); oParser = new parserFormula("TRUNC(PI(),-2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("TRUNC(-PI(),2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -3.14); oParser = new parserFormula("TRUNC(8.9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 8); oParser = new parserFormula("TRUNC(-8.9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -8); oParser = new parserFormula("TRUNC(0.45)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("TRUNC(43214)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43214); oParser = new parserFormula("TRUNC(43214.43214)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43214); oParser = new parserFormula("TRUNC(43214.43214, 0.25678)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43214); oParser = new parserFormula("TRUNC(43214.43214, 1.25678)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43214.4); oParser = new parserFormula("TRUNC(-43214.43214, 1.25678)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -43214.4); oParser = new parserFormula("TRUNC(-43214.43214, -2.25678)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -43200); oParser = new parserFormula("TRUNC(43214.43214, -2.25678)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43200); oParser = new parserFormula("TRUNC(44.3244, -2.25678)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("TRUNC(444.3244, -2.25678)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 400); oParser = new parserFormula("TRUNC(0.43214, 10)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0.43214); oParser = new parserFormula("TRUNC(0.4321443214432144321443214432144321443214, 100)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0.43214432144321435); oParser = new parserFormula("TRUNC(43214, 10)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43214); oParser = new parserFormula("TRUNC(43214, -2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 43200); oParser = new parserFormula("TRUNC(43214, -10)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("TRUNC(34123.123, -2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 34100); oParser = new parserFormula("TRUNC(123.23423,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 123.2); // bool oParser = new parserFormula("TRUNC(TRUE,1)", "A1", ws); assert.ok(oParser.parse(), "TRUNC(TRUE,1)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of TRUNC(TRUE,1)"); oParser = new parserFormula("TRUNC(FALSE,1)", "A1", ws); assert.ok(oParser.parse(), "TRUNC(FALSE,1)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of TRUNC(FALSE,1)"); oParser = new parserFormula("TRUNC(123.123,TRUE)", "A1", ws); assert.ok(oParser.parse(), "TRUNC(123.123,TRUE)"); assert.strictEqual(oParser.calculate().getValue(), 123.1, "Result of TRUNC(123.123,TRUE)"); oParser = new parserFormula("TRUNC(123.123,FALSE)", "A1", ws); assert.ok(oParser.parse(), "TRUNC(123.123,FALSE)"); assert.strictEqual(oParser.calculate().getValue(), 123, "Result of TRUNC(123.123,FALSE)"); oParser = new parserFormula("TRUNC(TRUE,TRUE)", "A1", ws); assert.ok(oParser.parse(), "TRUNC(TRUE,TRUE)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of TRUNC(TRUE,TRUE)"); oParser = new parserFormula("TRUNC(FALSE,FALSE)", "A1", ws); assert.ok(oParser.parse(), "TRUNC(FALSE,FALSE)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of TRUNC(FALSE,FALSE)"); // string oParser = new parserFormula("TRUNC(\"string\",1)", "A1", ws); assert.ok(oParser.parse(), "TRUNC(string,1)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of TRUNC(string,1)"); oParser = new parserFormula("TRUNC(\"252.252\",1)", "A1", ws); assert.ok(oParser.parse(), "TRUNC('252.252',1)"); assert.strictEqual(oParser.calculate().getValue(), 252.2, "Result of TRUNC('252.252',1)"); oParser = new parserFormula("TRUNC(\"252.252s\",1)", "A1", ws); assert.ok(oParser.parse(), "TRUNC('252.252s',1)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of TRUNC('252.252s',1)"); oParser = new parserFormula("TRUNC(\"252.252\",\"1\")", "A1", ws); assert.ok(oParser.parse(), "TRUNC('252.252','1')"); assert.strictEqual(oParser.calculate().getValue(), 252.2, "Result of TRUNC('252.252','1')"); oParser = new parserFormula("TRUNC(\"252.252\",\"1s\")", "A1", ws); assert.ok(oParser.parse(), "TRUNC('252.252','1s')"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of TRUNC('252.252','1s')"); ws.getRange2("E101").setValue("123.335"); ws.getRange2("E102").setValue("2"); ws.getRange2("E103").setValue("231.13"); ws.getRange2("E104").setValue("959.00001"); ws.getRange2("E105").setValue("0.30000000000000004"); ws.getRange2("E106").setValue("1.7999999999999998"); ws.getRange2("E107").setValue("str"); ws.getRange2("E108").setValue("TRUE"); ws.getRange2("E109").setValue("#N/A"); ws.getRange2("E110").setValue(""); ws.getRange2("E111").setValue(); ws.getRange2("E112").setValue("22.22"); ws.getRange2("E112").setNumFormat("@"); // cell|cellsrange oParser = new parserFormula("TRUNC(E101,E102)", "A1", ws); assert.ok(oParser.parse(), "TRUNC('252.252','1')"); assert.strictEqual(oParser.calculate().getValue(), 123.33, "Result of TRUNC('252.252','1')"); oParser = new parserFormula("TRUNC(E101:E101,E102:E102)", "A1", ws); assert.ok(oParser.parse(), "TRUNC('252.252','1')"); assert.strictEqual(oParser.calculate().getValue(), 123.33, "Result of TRUNC('252.252','1')"); oParser = new parserFormula("TRUNC(E101:E102,E102)", "A1", ws); assert.ok(oParser.parse(), "TRUNC(E101:E102,'1')"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of TRUNC(E101:E102,'1')"); oParser = new parserFormula("TRUNC(E101,E102:E104)", "A1", ws); assert.ok(oParser.parse(), "TRUNC(E101,E102:E104)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of TRUNC(E101,E102:E104)"); oParser = new parserFormula("TRUNC(E106,E102)", "A1", ws); assert.ok(oParser.parse(), "TRUNC(E106,2)"); assert.strictEqual(oParser.calculate().getValue(), 1.79, "Result of TRUNC(E106,2)"); oParser = new parserFormula("TRUNC(E107,E102)", "A1", ws); assert.ok(oParser.parse(), "TRUNC('str',2)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of TRUNC('str',2)"); oParser = new parserFormula("TRUNC(E108,E102)", "A1", ws); assert.ok(oParser.parse(), "TRUNC('22.22','2')"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of TRUNC('22.22','2')"); oParser = new parserFormula("TRUNC(E109,E102)", "A1", ws); assert.ok(oParser.parse(), "TRUNC('22.22','2')"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of TRUNC('22.22','2')"); oParser = new parserFormula("TRUNC(E110,E102)", "A1", ws); assert.ok(oParser.parse(), "TRUNC('22.22','2')"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of TRUNC('22.22','2')"); oParser = new parserFormula("TRUNC(E111,E102)", "A1", ws); assert.ok(oParser.parse(), "TRUNC('22.22','2')"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of TRUNC('22.22','2')"); oParser = new parserFormula("TRUNC(E112,E102)", "A1", ws); assert.ok(oParser.parse(), "TRUNC('22.22','2')"); assert.strictEqual(oParser.calculate().getValue(), 22.22, "Result of TRUNC('22.22','2')"); oParser = new parserFormula("TRUNC(,2)", "A1", ws); assert.ok(oParser.parse(), "TRUNC(,2)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of TRUNC(,2)"); oParser = new parserFormula("TRUNC(2,E110)", "A1", ws); assert.ok(oParser.parse(), "TRUNC(2,'')"); assert.strictEqual(oParser.calculate().getValue(), 2, "Result of TRUNC(2,'')"); oParser = new parserFormula("TRUNC(2,E111)", "A1", ws); assert.ok(oParser.parse(), "TRUNC(2,'')"); assert.strictEqual(oParser.calculate().getValue(), 2, "Result of TRUNC(2,'')"); oParser = new parserFormula("TRUNC(2,)", "A1", ws); assert.ok(oParser.parse(), "TRUNC(2,)"); assert.strictEqual(oParser.calculate().getValue(), 2, "Result of TRUNC(2,)"); oParser = new parserFormula("TRUNC(E101:E101,E102)", "A1", ws); assert.ok(oParser.parse(), "TRUNC('252.252','1')"); assert.strictEqual(oParser.calculate().getValue(), 123.33, "Result of TRUNC('252.252','1')"); // array oParser = new parserFormula("TRUNC({2,3,5,12},2)", "A1", ws); assert.ok(oParser.parse(), "TRUNC({2,3,5,12},2)"); assert.strictEqual(oParser.calculate().getValue(), 2, "Result of TRUNC({2,3,5,12},2)"); oParser = new parserFormula("TRUNC({999.025,3,5,12},2)", "A1", ws); assert.ok(oParser.parse(), "TRUNC({999.025,3,5,12},2)"); assert.strictEqual(oParser.calculate().getValue(), 999.02, "Result of TRUNC({999.025,3,5,12},2)"); oParser = new parserFormula("TRUNC({999.025,3,5,12},{3,2,25})", "A1", ws); assert.ok(oParser.parse(), "TRUNC({999.025,3,5,12},{3,2,25})"); assert.strictEqual(oParser.calculate().getValue(), 999.025, "Result of TRUNC({999.025,3,5,12},{3,2,25})"); // err oParser = new parserFormula("TRUNC(#N/A,2)", "A1", ws); assert.ok(oParser.parse(), "TRUNC(#N/A,2)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of TRUNC(#N/A,2)"); oParser = new parserFormula("TRUNC(2,#VALUE!)", "A1", ws); assert.ok(oParser.parse(), "TRUNC(2,#VALUE!)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of TRUNC(2,#VALUE!)"); oParser = new parserFormula("TRUNC(#N/A,#VALUE!)", "A1", ws); assert.ok(oParser.parse(), "TRUNC(#N/A,#VALUE!)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of TRUNC(#N/A,#VALUE!)"); // bug cases oParser = new parserFormula("TRUNC(2.1999999999999997,1)", "A1", ws); assert.ok(oParser.parse(), "TRUNC(2.1999999999999997,1)"); assert.strictEqual(oParser.calculate().getValue(), 2.1, "Result of TRUNC(2.1999999999999997,1)"); oParser = new parserFormula("TRUNC((0.6*3),1)", "A1", ws); assert.ok(oParser.parse(), "TRUNC((0.6*3),1)"); assert.strictEqual(oParser.calculate().getValue(), 1.8, "Result of TRUNC((0.6*3),1)"); oParser = new parserFormula("TRUNC((0.4*1)+(0.6*3),1)", "A1", ws); assert.ok(oParser.parse(), "TRUNC((0.4*1)+(0.6*3),1)"); assert.strictEqual(oParser.calculate().getValue(), 2.1, "Result of TRUNC((0.4*1)+(0.6*3),1)"); // 2.2 oParser = new parserFormula("TRUNC(0.1+0.2,1)", "A1", ws); assert.ok(oParser.parse(), "TRUNC(0.1+0.2,1)"); assert.strictEqual(oParser.calculate().getValue(), 0.3, "Result of TRUNC(0.1+0.2,1)"); // for bug 41030 ws.getRange2("A1:C2").cleanAll(); oParser = new parserFormula("TRUNC({12,4},{1,2})", "A1", ws); assert.ok(oParser.parse(), "TRUNC({12,4},{1,2})"); oParser.setArrayFormulaRef(ws.getRange2("A1:C2").bbox); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 12); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 4); oParser = new parserFormula("TRUNC({12,4},{1,2,3})", "A1", ws); assert.ok(oParser.parse(), "TRUNC({12,4},{1,2,3})"); oParser.setArrayFormulaRef(ws.getRange2("A1:C2").bbox); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 12); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 4); oParser = new parserFormula("TRUNC({12,4,2},{1,2})", "A1", ws); assert.ok(oParser.parse(), "TRUNC({12,4,2},{1,2})"); oParser.setArrayFormulaRef(ws.getRange2("A1:C2").bbox); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 12); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 4); oParser = new parserFormula("TRUNC({12,4,2},{1,2,3})", "A1", ws); assert.ok(oParser.parse(), "TRUNC({12,4,2},{1,2,3})"); oParser.setArrayFormulaRef(ws.getRange2("A1:C2").bbox); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 12); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 4); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 2); oParser = new parserFormula('TRUNC({12,"Str",2},{1,2,3})', "A1", ws); assert.ok(oParser.parse(), 'TRUNC({12,"Str",2},{1,2,3})'); oParser.setArrayFormulaRef(ws.getRange2("A1:C2").bbox); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 12); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 2); oParser = new parserFormula('TRUNC({12,4,2},{1,"str",3})', "A1", ws); assert.ok(oParser.parse(), 'TRUNC({12,4,2},{1,"str",3})'); oParser.setArrayFormulaRef(ws.getRange2("A1:C2").bbox); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 12); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 2); oParser = new parserFormula('TRUNC({12,"Str",2},"str")', "A1", ws); assert.ok(oParser.parse(), 'TRUNC({12,"Str",2},"str")'); oParser.setArrayFormulaRef(ws.getRange2("A1:C2").bbox); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#VALUE!"); testArrayFormula2(assert, "TRUNC", 1, 2); }); QUnit.test("Test: \"MULTINOMIAL\"", function (assert) { oParser = new parserFormula("MULTINOMIAL(2,3,4)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), Math.fact(2 + 3 + 4) / (Math.fact(2) * Math.fact(3) * Math.fact(4))); oParser = new parserFormula("MULTINOMIAL(2,3,\"r\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("MULTINOMIAL(150,50)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); testArrayFormula2(assert, "MULTINOMIAL", 1, 8, null, true); }); QUnit.test("Test: \"MUNIT\"", function (assert) { ws.getRange2("A101").setValue("5"); ws.getRange2("B102").setValue("6"); oParser = new parserFormula("MUNIT(1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); oParser = new parserFormula("MUNIT(-1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("MUNIT(1.123)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); oParser = new parserFormula("MUNIT(2.123)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(1, 1).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue(), 0); oParser = new parserFormula("MUNIT(A101)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(1, 1).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue(), 0); oParser = new parserFormula("MUNIT(A101:B102)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("MUNIT({0,0;1,2;123,\"sdf\"})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "#VALUE!"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 1).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(2, 0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(2, 1).getValue(), "#VALUE!"); oParser = new parserFormula("MUNIT({12,2})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue(), 1); }); QUnit.test("Test: \"SUMSQ\"", function (assert) { oParser = new parserFormula("SUMSQ(2.5,-3.6,2.4)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2.5 * 2.5 + 3.6 * 3.6 + 2.4 * 2.4); oParser = new parserFormula("SUMSQ(2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); oParser = new parserFormula("SUMSQ(150,50)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 150 * 150 + 50 * 50); oParser = new parserFormula("SUMSQ(150,\"f\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); testArrayFormula2(assert, "SUMSQ", 1, 8, null, true); }); QUnit.test("Test: \"ROMAN\"", function (assert) { oParser = new parserFormula("ROMAN(499,0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "CDXCIX"); oParser = new parserFormula("ROMAN(499,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "LDVLIV"); oParser = new parserFormula("ROMAN(499,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "XDIX"); oParser = new parserFormula("ROMAN(499,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "VDIV"); oParser = new parserFormula("ROMAN(499,4)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "ID"); oParser = new parserFormula("ROMAN(2013,0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "MMXIII"); oParser = new parserFormula("ROMAN(2013,5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("ROMAN(-2013,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("ROMAN(2499,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "MMLDVLIV"); oParser = new parserFormula("ROMAN(499)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "CDXCIX"); testArrayFormula2(assert, "ROMAN", 2, 2); }); QUnit.test("Test: \"SUMXMY2\"", function (assert) { ws.getRange2("A101").setValue("5"); ws.getRange2("A102").setValue("6"); ws.getRange2("A103").setValue("test1"); ws.getRange2("A104").setValue(""); ws.getRange2("A105").setValue("false"); ws.getRange2("B101").setValue("1"); ws.getRange2("B102").setValue("1"); ws.getRange2("B103").setValue("test2"); ws.getRange2("B104").setValue(""); ws.getRange2("B105").setValue("false"); oParser = new parserFormula("SUMXMY2(A101,B101)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 16); oParser = new parserFormula("SUMXMY2(A103,B103)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("SUMXMY2(A101:A102,B101:B102)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 41); oParser = new parserFormula("SUMXMY2(A105,B105)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("SUMXMY2({2,3,9,1,8,7,5},{6,5,11,7,5,4,4})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 79); oParser = new parserFormula("SUMXMY2({2,3,9;1,8,7},{6,5,11;7,5,4})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 78); oParser = new parserFormula("SUMXMY2(7,5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); testArrayFormula2(assert, "SUMXMY2", 2, 2, null, true) }); QUnit.test("Test: \"SUMX2MY2\"", function (assert) { ws.getRange2("A101").setValue("5"); ws.getRange2("A102").setValue("6"); ws.getRange2("A103").setValue("test1"); ws.getRange2("A104").setValue(""); ws.getRange2("A105").setValue("false"); ws.getRange2("B101").setValue("1"); ws.getRange2("B102").setValue("1"); ws.getRange2("B103").setValue("test2"); ws.getRange2("B104").setValue(""); ws.getRange2("B105").setValue("false"); oParser = new parserFormula("SUMX2MY2({2,3,9,1,8,7,5},{6,5,11,7,5,4,4})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -55); oParser = new parserFormula("SUMX2MY2({2,3,9;1,8,7},{6,5,11;7,5,4})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -64); oParser = new parserFormula("SUMX2MY2(7,5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 24); oParser = new parserFormula("SUMX2MY2(A101,B101)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 24); oParser = new parserFormula("SUMX2MY2(A103,B103)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("SUMX2MY2(A101:A102,B101:B102)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 59); /*oParser = new parserFormula( "SUMX2MY2(A101:A105,B101:B105)", "A1", ws ); assert.ok( oParser.parse() ); assert.strictEqual( oParser.calculate().getValue(), 59 );*/ oParser = new parserFormula("SUMX2MY2(A105,B105)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); testArrayFormula2(assert, "SUMX2MY2", 2, 2, null, true); }); QUnit.test("Test: \"SUMX2PY2\"", function (assert) { ws.getRange2("A101").setValue("5"); ws.getRange2("A102").setValue("6"); ws.getRange2("A103").setValue("test1"); ws.getRange2("A104").setValue(""); ws.getRange2("A105").setValue("false"); ws.getRange2("B101").setValue("1"); ws.getRange2("B102").setValue("1"); ws.getRange2("B103").setValue("test2"); ws.getRange2("B104").setValue(""); ws.getRange2("B105").setValue("false"); oParser = new parserFormula("SUMX2PY2({2,3,9,1,8,7,5},{6,5,11,7,5,4,4})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 521); oParser = new parserFormula("SUMX2PY2({2,3,9;1,8,7},{6,5,11;7,5,4})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 480); oParser = new parserFormula("SUMX2PY2(7,5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 74); oParser = new parserFormula("SUMX2PY2(A101,B101)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 26); oParser = new parserFormula("SUMX2PY2(A103,B103)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("SUMX2PY2(A101:A102,B101:B102)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 63); oParser = new parserFormula("SUMX2PY2(A105,B105)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); testArrayFormula2(assert, "SUMX2PY2", 2, 2, null, true); }); QUnit.test("Test: \"SERIESSUM\"", function (assert) { ws.getRange2("A2").setValue("1"); ws.getRange2("A3").setValue(numDivFact(-1, 2)); ws.getRange2("A4").setValue(numDivFact(1, 4)); ws.getRange2("A5").setValue(numDivFact(-1, 6)); oParser = new parserFormula("SERIESSUM(PI()/4,0,2,A2:A5)", "A7", ws); assert.ok(oParser.parse()); assert.ok(Math.abs( oParser.calculate().getValue() - (1 - 1 / 2 * Math.pow(Math.PI / 4, 2) + 1 / Math.fact(4) * Math.pow(Math.PI / 4, 4) - 1 / Math.fact(6) * Math.pow(Math.PI / 4, 6))) < dif); ws.getRange2("B2").setValue("1"); ws.getRange2("B3").setValue(numDivFact(-1, 3)); ws.getRange2("B4").setValue(numDivFact(1, 5)); ws.getRange2("B5").setValue(numDivFact(-1, 7)); oParser = new parserFormula("SERIESSUM(PI()/4,1,2,B2:B5)", "B7", ws); assert.ok(oParser.parse()); assert.ok(Math.abs(oParser.calculate().getValue() - (Math.PI / 4 - 1 / Math.fact(3) * Math.pow(Math.PI / 4, 3) + 1 / Math.fact(5) * Math.pow(Math.PI / 4, 5) - 1 / Math.fact(7) * Math.pow(Math.PI / 4, 7))) < dif); //TODO нужна другая функция для тестирования //testArrayFormula2(assert, "SERIESSUM", 4, 4); }); /* * Mathematical Function * */ QUnit.test("Test: \"CEILING\"", function (assert) { oParser = new parserFormula("CEILING(2.5,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); oParser = new parserFormula("CEILING(-2.5,-2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -4); oParser = new parserFormula("CEILING(-2.5,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -2); oParser = new parserFormula("CEILING(1.5,0.1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1.5); oParser = new parserFormula("CEILING(0.234,0.01)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0.24); testArrayFormula2(assert, "CEILING", 2, 2); }); QUnit.test("Test: \"CELL\"", function (assert) { ws.getRange2("J2").setValue("1"); ws.getRange2("J3").setValue("test"); ws.getRange2("J4").setValue("test2"); ws.getRange2("J5").setValue("07/12/2000"); ws.getRange2("J6").setValue(""); oParser = new parserFormula('CELL("address",J3)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "$J$3"); oParser = new parserFormula('CELL("address",J3:O12)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "$J$3"); oParser = new parserFormula('CELL("col",J3)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 10); oParser = new parserFormula('CELL("col",J3:O12)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 10); oParser = new parserFormula('CELL("row",J3)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); oParser = new parserFormula('CELL("row",J3:O12)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); oParser = new parserFormula('CELL("color",J3)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula('CELL("color",J3:O12)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula('CELL("contents",J3)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "test"); oParser = new parserFormula('CELL("contents",J3:O12)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "test"); oParser = new parserFormula('CELL("contents",J4:O12)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "test2"); oParser = new parserFormula('CELL("contents",J5:O12)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 36719); oParser = new parserFormula('CELL("prefix",J3)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "'"); /*oParser = new parserFormula( 'CELL("prefix",J2)', "A1", ws ); assert.ok( oParser.parse() ); assert.strictEqual( oParser.calculate().getValue(), "" );*/ oParser = new parserFormula('CELL("prefix",J6:O12)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ""); // address oParser = new parserFormula('CELL("address",J2)', "A1", ws); assert.ok(oParser.parse(), "Addres. Number type in cell."); assert.strictEqual(oParser.calculate().getValue(), "$J$2", "Addres. Number type in cell."); oParser = new parserFormula('CELL("address",J3)', "A1", ws); assert.ok(oParser.parse(), "Addres. String type in cell."); assert.strictEqual(oParser.calculate().getValue(), "$J$3", "Addres. String type in cell."); oParser = new parserFormula('CELL("address",J2:J3)', "A1", ws); assert.ok(oParser.parse(), "Addres. Cells range."); assert.strictEqual(oParser.calculate().getValue(), "$J$2", "Addres. Cells range."); oParser = new parserFormula('CELL("address",H23)', "A1", ws); assert.ok(oParser.parse(), "CELL(col,H23)."); assert.strictEqual(oParser.calculate().getValue(), "$H$23", "Addres. Result of CELL(address,H23)."); oParser = new parserFormula('CELL("address",{1,2,3,4,5})', "A1", ws); assert.ok(oParser.parse(), "CELL(address,{1,2,3,4,5})."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Addres. Result of CELL(address,{1,2,3,4,5})."); oParser = new parserFormula('CELL("address",12)', "A1", ws); assert.ok(oParser.parse(), "Addres. Cells range."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Addres. Cells range."); oParser = new parserFormula('CELL("address",)', "A1", ws); assert.ok(oParser.parse(), "Addres. Cells range."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Addres. Cells range."); oParser = new parserFormula('CELL("address",J)', "A1", ws); assert.ok(oParser.parse(), "Addres. Cells range."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Addres. Cells range."); oParser = new parserFormula('CELL("address","J2")', "A1", ws); assert.ok(oParser.parse(), "Addres. Cells range."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Addres. Cells range."); // col oParser = new parserFormula('CELL("col",J2)', "A1", ws); assert.ok(oParser.parse(), "CELL(col,J2)."); assert.strictEqual(oParser.calculate().getValue(), 10, "Col. Result of CELL(col,J2)."); oParser = new parserFormula('CELL("col",J2:J4)', "A1", ws); assert.ok(oParser.parse(), "CELL(col,J2:J4)."); assert.strictEqual(oParser.calculate().getValue(), 10, "Col. Result of CELL(col,J2:J4)."); oParser = new parserFormula('CELL("col",H23)', "A1", ws); assert.ok(oParser.parse(), "CELL(col,H23)."); assert.strictEqual(oParser.calculate().getValue(), 8, "Col. Result of CELL(col,H23)."); oParser = new parserFormula('CELL("col",{1,2,3,4,5})', "A1", ws); assert.ok(oParser.parse(), "CELL(col,{1,2,3,4,5})."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Col. Result of CELL(col,{1,2,3,4,5})."); oParser = new parserFormula('CELL("col",)', "A1", ws); assert.ok(oParser.parse(), "CELL(col,)."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Col. Result of CELL(col,)."); oParser = new parserFormula('CELL("col",J)', "A1", ws); assert.ok(oParser.parse(), "CELL(col,J)."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Col. Result of CELL(col,J)."); oParser = new parserFormula('CELL("col","J2")', "A1", ws); assert.ok(oParser.parse(), "CELL(col,'J2')."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Result of CELL(col,'J2')."); // color oParser = new parserFormula('CELL("color",J2)', "A1", ws); assert.ok(oParser.parse(), "CELL(color,J2)."); assert.strictEqual(oParser.calculate().getValue(), 0, "Color. Result of CELL(color,J2)."); oParser = new parserFormula('CELL("color",J2:J4)', "A1", ws); assert.ok(oParser.parse(), "CELL(color,J2:J4)."); assert.strictEqual(oParser.calculate().getValue(), 0, "Color. Result of CELL(color,J2:J4)."); oParser = new parserFormula('CELL("color",H23)', "A1", ws); assert.ok(oParser.parse(), "CELL(color,H23)."); assert.strictEqual(oParser.calculate().getValue(), 0, "Color. Result of CELL(color,H23)."); oParser = new parserFormula('CELL("color",{1,2,3,4,5})', "A1", ws); assert.ok(oParser.parse(), "CELL(color,{1,2,3,4,5})."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Color. Result of CELL(color,{1,2,3,4,5})."); oParser = new parserFormula('CELL("color",)', "A1", ws); assert.ok(oParser.parse(), "CELL(color,)."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Color. Result of CELL(color,)."); oParser = new parserFormula('CELL("color",J)', "A1", ws); assert.ok(oParser.parse(), "CELL(color,J)."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Color. Result of CELL(color,J)."); oParser = new parserFormula('CELL("color","J2")', "A1", ws); assert.ok(oParser.parse(), "CELL(color,'J2')."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Result of CELL(color,'J2')."); // contents oParser = new parserFormula('CELL("contents",J2)', "A1", ws); assert.ok(oParser.parse(), "CELL(contents,J2)."); assert.strictEqual(oParser.calculate().getValue(), 1, "Contents. Result of CELL(contents,J2)."); oParser = new parserFormula('CELL("contents",J2:J4)', "A1", ws); assert.ok(oParser.parse(), "CELL(contents,J2:J4)."); assert.strictEqual(oParser.calculate().getValue(), 1, "Contents. Result of CELL(contents,J2:J4)."); oParser = new parserFormula('CELL("contents",J5)', "A1", ws); assert.ok(oParser.parse(), "CELL(contents,07/12/2000)"); assert.strictEqual(oParser.calculate().getValue(), 36719, "Contents. Result of CELL(contents,07/12/2000)."); oParser = new parserFormula('CELL("contents",H23)', "A1", ws); assert.ok(oParser.parse(), "CELL(contents,H23)."); assert.strictEqual(oParser.calculate().getValue(), "", "Contents. Result of CELL(contents,H23)."); oParser = new parserFormula('CELL("contents",{1,2,3,4,5})', "A1", ws); assert.ok(oParser.parse(), "CELL(contents,{1,2,3,4,5})."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Contents. Result of CELL(contents,{1,2,3,4,5})."); oParser = new parserFormula('CELL("contents",)', "A1", ws); assert.ok(oParser.parse(), "CELL(contents,)."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Contents. Result of CELL(contents,)."); oParser = new parserFormula('CELL("contents",J)', "A1", ws); assert.ok(oParser.parse(), "CELL(contents,J)."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Contents. Result of CELL(contents,J)."); oParser = new parserFormula('CELL("contents","J2")', "A1", ws); assert.ok(oParser.parse(), "CELL(contents,'J2')."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Contents. Result of CELL(contents,'J2')."); // filename let sheetName = ws.sName; oParser = new parserFormula('CELL("filename",J2)', "A1", ws); assert.ok(oParser.parse(), "CELL(filename,J2)."); assert.strictEqual(oParser.calculate().getValue(), "[TeSt.xlsx]" + sheetName, "filename. Result of CELL(filename,J2)."); oParser = new parserFormula('CELL("filename",J2:J4)', "A1", ws); assert.ok(oParser.parse(), "CELL(filename,J2:J4)."); assert.strictEqual(oParser.calculate().getValue(), "[TeSt.xlsx]" + sheetName, "filename. Result of CELL(filename,J2:J4)."); oParser = new parserFormula('CELL("filename",H23)', "A1", ws); assert.ok(oParser.parse(), "CELL(filename,H23)."); assert.strictEqual(oParser.calculate().getValue(), "[TeSt.xlsx]" + sheetName, "filename. Result of CELL(filename,H23)."); oParser = new parserFormula('CELL("filename",{1,2,3,4,5})', "A1", ws); assert.ok(oParser.parse(), "CELL(filename,{1,2,3,4,5})."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "filename. Result of CELL(filename,{1,2,3,4,5})."); oParser = new parserFormula('CELL("filename",)', "A1", ws); assert.ok(oParser.parse(), "CELL(filename,)."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "filename. Result of CELL(filename,)."); oParser = new parserFormula('CELL("filename",J)', "A1", ws); assert.ok(oParser.parse(), "CELL(filename,J)."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "filename. Result of CELL(filename,J)."); oParser = new parserFormula('CELL("filename","J2")', "A1", ws); assert.ok(oParser.parse(), "CELL(filename,'J2')."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "filename. Result of CELL(filename,'J2')."); // format // G ws.getRange2("H2").setValue("50"); // F0 ws.getRange2("H3").setValue("0"); ws.getRange2("H3").setNumFormat("0"); // ,0 ws.getRange2("H4").setValue("0"); ws.getRange2("H4").setNumFormat("#,##0"); // ,2 ws.getRange2("H54").setValue("0.00"); ws.getRange2("H54").setNumFormat("#,##0.00"); // F2 ws.getRange2("H5").setValue("0.00"); ws.getRange2("H5").setNumFormat("0.00"); // C0 ws.getRange2("H66").setValue("0"); ws.getRange2("H66").setNumFormat('#,##0;\\-#,##0'); // C0 ms ws.getRange2("H6").setValue("0"); ws.getRange2("H6").setNumFormat("$#,##0_);($#,##0)"); // C0- ws.getRange2("H77").setValue("0"); ws.getRange2("H77").setNumFormat('#,##0;[Red]\\-#,##0'); // C0- ms ws.getRange2("H7").setValue("0"); ws.getRange2("H7").setNumFormat('$#,##0_);[Red]($#,##0)'); // C2 ws.getRange2("H88").setValue("0"); ws.getRange2("H88").setNumFormat('#,##0.00;\-#,##0.00'); // C2 ms ws.getRange2("H8").setValue("0"); ws.getRange2("H8").setNumFormat('$#,##0.00_);($#,##0.00)'); // C2- ws.getRange2("H99").setValue("0"); ws.getRange2("H99").setNumFormat('#,##0.00;[Red]\-#,##0.00'); // C2- ms ws.getRange2("H9").setValue("0"); ws.getRange2("H9").setNumFormat('$#,##0.00_);[Red]($#,##0.00)'); // P0 ws.getRange2("H10").setValue("0"); ws.getRange2("H10").setNumFormat("0%"); // P2 ws.getRange2("H11").setValue("0"); ws.getRange2("H11").setNumFormat("0.00%"); // S2 ws.getRange2("H12").setValue("0"); ws.getRange2("H12").setNumFormat("0.00E+00"); // G ws.getRange2("H13").setValue("0"); ws.getRange2("H13").setNumFormat("# ?/?"); // G ws.getRange2("H113").setValue("0"); ws.getRange2("H113").setNumFormat("# ??/??"); // D1 ws.getRange2("H14").setValue("10 Apr 20"); ws.getRange2("H14").setNumFormat("dd/mm/yyyy"); // D2 ws.getRange2("H15").setValue("12-Jun"); ws.getRange2("H15").setNumFormat("[$-9]d mmm;@"); // D3 ws.getRange2("H16").setValue("June-22"); ws.getRange2("H16").setNumFormat("[$-9]mmm/yy;@"); // D4 ws.getRange2("H17").setValue("12/7/2022"); ws.getRange2("H17").setNumFormat("m/d/yy;@"); // D5 ws.getRange2("H18").setValue("05/12"); ws.getRange2("H18").setNumFormat("mm/dd;@"); // D6 ws.getRange2("H19").setValue("12:00:00 AM"); ws.getRange2("H19").setNumFormat("h:mm:ss AM/PM"); // D7 ws.getRange2("H20").setValue("12:00 AM"); ws.getRange2("H20").setNumFormat("h:mm AM/PM"); // D8 ws.getRange2("H21").setValue("12:00:00"); ws.getRange2("H21").setNumFormat("h:mm:ss;@"); // D9 ws.getRange2("H22").setValue("12:00"); ws.getRange2("H22").setNumFormat("h:mm;@"); ws.getRange2("H23").setValue("{1,2,3,4,5}"); oParser = new parserFormula('CELL("format",{0})', "A1", ws); assert.ok(oParser.parse(), "CELL(format,{0})."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "contents. Result of CELL(format,{0})."); oParser = new parserFormula('CELL("format",H23)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,{1,2,3,4,5})."); assert.strictEqual(oParser.calculate().getValue(), "G", "contents. Result of CELL(format,{1,2,3,4,5})."); oParser = new parserFormula('CELL("format",{0;1;2;3})', "A1", ws); assert.ok(oParser.parse(), "CELL(format,H3:H22)."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "contents. Result of CELL(format,{0;1;2;3})."); oParser = new parserFormula('CELL("format",)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,)."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "contents. Result of CELL(format,)."); oParser = new parserFormula('CELL("format",H3)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,H3)."); assert.strictEqual(oParser.calculate().getValue(), "F0", "contents. Result of CELL(format,0)."); // F0 oParser = new parserFormula('CELL("format",H3:H22)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,H3:H22)."); assert.strictEqual(oParser.calculate().getValue(), "F0", "contents. Result of CELL(format,0)."); // F0 oParser = new parserFormula('CELL("format",H4)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,H4)."); assert.strictEqual(oParser.calculate().getValue(), ",0", "contents. Result of CELL(format,H4)."); // ,0 oParser = new parserFormula('CELL("format",H54)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,H54)."); assert.strictEqual(oParser.calculate().getValue(), ",2", "contents. Result of CELL(format,H54)."); // ,2 oParser = new parserFormula('CELL("format",H5)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,H5)."); assert.strictEqual(oParser.calculate().getValue(), "F2", "contents. Result of CELL(format,H5)."); // F2 oParser = new parserFormula('CELL("format",H6)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,H6)."); assert.strictEqual(oParser.calculate().getValue(), "С0", "contents. Result of CELL(format,H6)."); // C0 oParser = new parserFormula('CELL("format",H7)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,H7)."); assert.strictEqual(oParser.calculate().getValue(), "С0-", "contents. Result of CELL(format,H7)."); // C0- oParser = new parserFormula('CELL("format",H8)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,H8)."); assert.strictEqual(oParser.calculate().getValue(), "С2", "contents. Result of CELL(format,H8)."); // C2 oParser = new parserFormula('CELL("format",H9)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,H9)."); assert.strictEqual(oParser.calculate().getValue(), "С2-", "contents. Result of CELL(format,H9)."); // C2- oParser = new parserFormula('CELL("format",H10)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,H10)."); assert.strictEqual(oParser.calculate().getValue(), "P0", "contents. Result of CELL(format,H10)."); // P0 oParser = new parserFormula('CELL("format",H11)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,H11)."); assert.strictEqual(oParser.calculate().getValue(), "P2", "contents. Result of CELL(format,H11)."); // P2 oParser = new parserFormula('CELL("format",H12)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,H12)."); assert.strictEqual(oParser.calculate().getValue(), "S2", "contents. Result of CELL(format,H12)."); // S2 oParser = new parserFormula('CELL("format",H13)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,H13)."); assert.strictEqual(oParser.calculate().getValue(), "G", "contents. Result of CELL(format,H13)."); // "G" oParser = new parserFormula('CELL("format",H113)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,H113)."); assert.strictEqual(oParser.calculate().getValue(), "G", "contents. Result of CELL(format,H113)."); // "G" oParser = new parserFormula('CELL("format",H2)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,50)."); assert.strictEqual(oParser.calculate().getValue(), "G", "Format. Result of CELL(format,50)."); // G oParser = new parserFormula('CELL("format",H14)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,10 Apr 20)."); assert.strictEqual(oParser.calculate().getValue(), "D1", "Format. Result of CELL(format,10 Apr 20)."); //D1 oParser = new parserFormula('CELL("format",H15)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,10 Apr 20)."); assert.strictEqual(oParser.calculate().getValue(), "D2", "Format. Result of CELL(format,10 Apr 20)."); //D2 oParser = new parserFormula('CELL("format",H16)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,10 Apr 20)."); assert.strictEqual(oParser.calculate().getValue(), "D3", "Format. Result of CELL(format,10 Apr 20)."); //D3 oParser = new parserFormula('CELL("format",H17)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,10 Apr 20)."); assert.strictEqual(oParser.calculate().getValue(), "D4", "Format. Result of CELL(format,10 Apr 20)."); //D4 oParser = new parserFormula('CELL("format",H18)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,10 Apr 20)."); assert.strictEqual(oParser.calculate().getValue(), "D5", "Format. Result of CELL(format,10 Apr 20)."); //D5 oParser = new parserFormula('CELL("format",H19)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,10 Apr 20)."); assert.strictEqual(oParser.calculate().getValue(), "D6", "Format. Result of CELL(format,10 Apr 20)."); //D6 oParser = new parserFormula('CELL("format",H20)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,10 Apr 20)."); assert.strictEqual(oParser.calculate().getValue(), "D7", "Format. Result of CELL(format,10 Apr 20)."); //D7 oParser = new parserFormula('CELL("format",H21)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,10 Apr 20)."); assert.strictEqual(oParser.calculate().getValue(), "D8", "Format. Result of CELL(format,10 Apr 20)."); //D8 oParser = new parserFormula('CELL("format",H22)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,10 Apr 20)."); assert.strictEqual(oParser.calculate().getValue(), "D9", "Format. Result of CELL(format,10 Apr 20)."); //D9 oParser = new parserFormula('CELL("format",J2)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,1)."); assert.strictEqual(oParser.calculate().getValue(), "G", "Format. Result of CELL(format,1)."); oParser = new parserFormula('CELL("format",J3)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,string)."); assert.strictEqual(oParser.calculate().getValue(), "G", "Format. Result of CELL(format,string)."); oParser = new parserFormula('CELL("format",J5)', "A1", ws); assert.ok(oParser.parse(), "CELL(format,07/12/2000)."); assert.strictEqual(oParser.calculate().getValue(), "D4", "Format. Result of CELL(format,07/12/2000)."); // parentheses oParser = new parserFormula('CELL("parentheses",J2)', "A1", ws); assert.ok(oParser.parse(), "CELL(parentheses,2)."); assert.strictEqual(oParser.calculate().getValue(), 0, "Parentheses. Result of CELL(parentheses,1)."); oParser = new parserFormula('CELL("parentheses",J6)', "A1", ws); assert.ok(oParser.parse(), "CELL(parentheses,'')."); assert.strictEqual(oParser.calculate().getValue(), 0, "Parentheses. Result of CELL(parentheses,'')."); oParser = new parserFormula('CELL("parentheses",J2:J6)', "A1", ws); assert.ok(oParser.parse(), "CELL(parentheses,J2:J6)."); assert.strictEqual(oParser.calculate().getValue(), 0, "Parentheses. Result of CELL(parentheses,J2:J6)."); oParser = new parserFormula('CELL("parentheses",H23)', "A1", ws); assert.ok(oParser.parse(), "CELL(parentheses,H23)."); assert.strictEqual(oParser.calculate().getValue(), 0, "Parentheses. Result of CELL(parentheses,H23)."); oParser = new parserFormula('CELL("parentheses",{1,2,3,4,5})', "A1", ws); assert.ok(oParser.parse(), "CELL(parentheses,{1,2,3,4,5})."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Parentheses. Result of CELL(parentheses,{1,2,3,4,5})."); oParser = new parserFormula('CELL("parentheses",)', "A1", ws); assert.ok(oParser.parse(), "CELL(parentheses,)."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Parentheses. Result of CELL(parentheses,)."); oParser = new parserFormula('CELL("parentheses",J)', "A1", ws); assert.ok(oParser.parse(), "CELL(parentheses,J)."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Parentheses. Result of CELL(parentheses,J).") oParser = new parserFormula('CELL("parentheses","J")', "A1", ws); assert.ok(oParser.parse(), "CELL(parentheses,'J')."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Parentheses. Result of CELL(parentheses,'J').") // prefix oParser = new parserFormula('CELL("prefix",J2)', "A1", ws); assert.ok(oParser.parse(), "CELL(prefix,2)."); assert.strictEqual(oParser.calculate().getValue(), "'", "Prefix. Result of CELL(prefix,1)."); oParser = new parserFormula('CELL("prefix",J6)', "A1", ws); assert.ok(oParser.parse(), "CELL(prefix,'')."); assert.strictEqual(oParser.calculate().getValue(), "", "Prefix. Result of CELL(prefix,'')."); oParser = new parserFormula('CELL("prefix",J2:J6)', "A1", ws); assert.ok(oParser.parse(), "CELL(prefix,J2:J6)."); assert.strictEqual(oParser.calculate().getValue(), "'", "Prefix. Result of CELL(prefix,J2:J6)."); oParser = new parserFormula('CELL("prefix",)', "A1", ws); assert.ok(oParser.parse(), "CELL(prefix,)."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Prefix. Result of CELL(prefix,)."); oParser = new parserFormula('CELL("prefix",J)', "A1", ws); assert.ok(oParser.parse(), "CELL(prefix,J)."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Prefix. Result of CELL(prefix,J)."); oParser = new parserFormula('CELL("prefix",H23)', "A1", ws); assert.ok(oParser.parse(), "CELL(prefix,H23)."); assert.strictEqual(oParser.calculate().getValue(), "'", "Prefix. Result of CELL(prefix,H23)."); oParser = new parserFormula('CELL("prefix",{1,2,3,4,5})', "A1", ws); assert.ok(oParser.parse(), "CELL(prefix,{1,2,3,4,5})."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Prefix. Result of CELL(prefix,{1,2,3,4,5})."); oParser = new parserFormula('CELL("prefix","J")', "A1", ws); assert.ok(oParser.parse(), "CELL(prefix,'J')."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Prefix. Result of CELL(prefix,'J')."); // protect oParser = new parserFormula('CELL("protect",J2)', "A1", ws); assert.ok(oParser.parse(), "CELL(protect,2)."); assert.strictEqual(oParser.calculate().getValue(), 1, "Protect. Result of CELL(protect,1)."); oParser = new parserFormula('CELL("protect",J6)', "A1", ws); assert.ok(oParser.parse(), "CELL(protect,'')."); assert.strictEqual(oParser.calculate().getValue(), 1, "Protect. Result of CELL(protect,'')."); oParser = new parserFormula('CELL("protect",J2:J6)', "A1", ws); assert.ok(oParser.parse(), "CELL(protect,J2:J6)."); assert.strictEqual(oParser.calculate().getValue(), 1, "Protect. Result of CELL(protect,J2:J6)."); oParser = new parserFormula('CELL("protect",H23)', "A1", ws); assert.ok(oParser.parse(), "CELL(protect,H23)."); assert.strictEqual(oParser.calculate().getValue(), 1, "Protect. Result of CELL(protect,H23)."); oParser = new parserFormula('CELL("protect",{1,2,3,4,5})', "A1", ws); assert.ok(oParser.parse(), "CELL(protect,{1,2,3,4,5})."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Protect. Result of CELL(protect,{1,2,3,4,5})."); oParser = new parserFormula('CELL("protect",)', "A1", ws); assert.ok(oParser.parse(), "CELL(protect,)."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Protect. Result of CELL(protect,)."); oParser = new parserFormula('CELL("protect",J)', "A1", ws); assert.ok(oParser.parse(), "CELL(protect,J)."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Protect. Result of CELL(protect,J).") oParser = new parserFormula('CELL("protect","J")', "A1", ws); assert.ok(oParser.parse(), "CELL(protect,'J')."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Protect. Result of CELL(protect,'J').") // row oParser = new parserFormula('CELL("row",J2)', "A1", ws); assert.ok(oParser.parse(), "CELL(row,1)."); assert.strictEqual(oParser.calculate().getValue(), 2, "Row. Result of CELL(row,1)."); oParser = new parserFormula('CELL("row",J10)', "A1", ws); assert.ok(oParser.parse(), "CELL(row,'')."); assert.strictEqual(oParser.calculate().getValue(), 10, "Row. Result of CELL(row,'')."); oParser = new parserFormula('CELL("row",B2:J5)', "A1", ws); assert.ok(oParser.parse(), "CELL(row,B2:J5)."); assert.strictEqual(oParser.calculate().getValue(), 2, "Row. Result of CELL(row,B2:J5)."); oParser = new parserFormula('CELL("row",H23)', "A1", ws); assert.ok(oParser.parse(), "CELL(row,H23)."); assert.strictEqual(oParser.calculate().getValue(), 23, "Row. Result of CELL(row,H23)."); oParser = new parserFormula('CELL("row",{1,2,3,4,5})', "A1", ws); assert.ok(oParser.parse(), "CELL(row,{1,2,3,4,5})."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Row. Result of CELL(row,{1,2,3,4,5})."); oParser = new parserFormula('CELL("row",)', "A1", ws); assert.ok(oParser.parse(), "CELL(row,)."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Row. Result of CELL(row,)."); oParser = new parserFormula('CELL("row",J)', "A1", ws); assert.ok(oParser.parse(), "CELL(row,J)."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Row. Result of CELL(row,J).") oParser = new parserFormula('CELL("row","J")', "A1", ws); assert.ok(oParser.parse(), "CELL(row,'J')."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Row. Result of CELL(row,'J').") // type oParser = new parserFormula('CELL("type",J2)', "A1", ws); assert.ok(oParser.parse(), "CELL(type,1)."); assert.strictEqual(oParser.calculate().getValue(), "v", "Type. Result of CELL(type,1)."); oParser = new parserFormula('CELL("type",J3)', "A1", ws); assert.ok(oParser.parse(), "CELL(type,string)."); assert.strictEqual(oParser.calculate().getValue(), "l", "Type. Result of CELL(type,string)."); oParser = new parserFormula('CELL("type",J6)', "A1", ws); assert.ok(oParser.parse(), "CELL(type,'')."); assert.strictEqual(oParser.calculate().getValue(), "b", "Type. Result of CELL(type,'')."); oParser = new parserFormula('CELL("type",H23)', "A1", ws); assert.ok(oParser.parse(), "CELL(type,H23)."); assert.strictEqual(oParser.calculate().getValue(), "l", "Type. Result of CELL(type,H23)."); oParser = new parserFormula('CELL("type",{1,2,3,4,5})', "A1", ws); assert.ok(oParser.parse(), "CELL(type,{1,2,3,4,5})."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Type. Result of CELL(type,{1,2,3,4,5})."); oParser = new parserFormula('CELL("type",)', "A1", ws); assert.ok(oParser.parse(), "CELL(type,)."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Type. Result of CELL(type,)."); oParser = new parserFormula('CELL("type",J)', "A1", ws); assert.ok(oParser.parse(), "CELL(type,J)."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Type. Result of CELL(type,J)."); oParser = new parserFormula('CELL("type","J")', "A1", ws); assert.ok(oParser.parse(), "CELL(type,'J')."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Type. Result of CELL(type,'J')."); // width oParser = new parserFormula('CELL("width",J2)', "A1", ws); assert.ok(oParser.parse(), "CELL(width,1)."); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), 8, "Width. Result of CELL(width,1)."); assert.strictEqual(oParser.calculate().getElementRowCol(0,1).getValue(), "TRUE", "Width. Result of CELL(width,1)."); oParser = new parserFormula('CELL("width",J3)', "A1", ws); assert.ok(oParser.parse(), "CELL(width,string)."); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), 8, "Width. Result of CELL(width,string)."); assert.strictEqual(oParser.calculate().getElementRowCol(0,1).getValue(), "TRUE", "Width. Result of CELL(width,string)."); oParser = new parserFormula('CELL("width",J6)', "A1", ws); assert.ok(oParser.parse(), "CELL(width,'')."); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), 8, "Width. Result of CELL(width,'')."); assert.strictEqual(oParser.calculate().getElementRowCol(0,1).getValue(), "TRUE", "Width. Result of CELL(width,'')."); oParser = new parserFormula('CELL("width",H23)', "A1", ws); assert.ok(oParser.parse(), "CELL(width,H23)."); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), 8, "Width. Result of CELL(width,H23)."); assert.strictEqual(oParser.calculate().getElementRowCol(0,1).getValue(), "TRUE", "Width. Result of CELL(width,H23)."); oParser = new parserFormula('CELL("width",{1,2,3,4,5})', "A1", ws); assert.ok(oParser.parse(), "CELL(width,{1,2,3,4,5})."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Width. Result of CELL(width,{1,2,3,4,5})."); oParser = new parserFormula('CELL("width",)', "A1", ws); assert.ok(oParser.parse(), "CELL(width,)."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Width. Result of CELL(width,)."); oParser = new parserFormula('CELL("width",J)', "A1", ws); assert.ok(oParser.parse(), "CELL(width,J)."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Width. Result of CELL(width,J)."); oParser = new parserFormula('CELL("width","J")', "A1", ws); assert.ok(oParser.parse(), "CELL(width,'J')."); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Width. Result of CELL(width,'J')."); oParser = new parserFormula('CELL("fiLename",J2)', "A1", ws); assert.ok(oParser.parse(), "CELL(fiLename,J2)."); assert.strictEqual(oParser.calculate().getValue(), "[TeSt.xlsx]" + sheetName, "fiLename. Result of CELL(filename,J2)."); oParser = new parserFormula('CELL("FILENAME",J2)', "A1", ws); assert.ok(oParser.parse(), "CELL(FILENAME,J2)."); assert.strictEqual(oParser.calculate().getValue(), "[TeSt.xlsx]" + sheetName, "FILENAME. Result of CELL(filename,J2)."); oParser = new parserFormula('CELL("FILENAM",J2)', "A1", ws); assert.ok(oParser.parse(), "CELL(FILENAM,J2)."); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "FILENAM. Result of CELL(filename,J2)."); }); /* * Statistical Function * */ QUnit.test("Test: \"AVEDEV\"", function (assert) { oParser = new parserFormula("AVEDEV(-3.5,1.4,6.9,-4.5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4.075); oParser = new parserFormula("AVEDEV({-3.5,1.4,6.9,-4.5})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4.075); oParser = new parserFormula("AVEDEV(-3.5,1.4,6.9,-4.5,-0.3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(difBetween(oParser.calculate().getValue(), 3.32), true); testArrayFormula2(assert, "AVEDEV", 1, 8, null, true); }); QUnit.test("Test: \"AVERAGE\"", function (assert) { oParser = new parserFormula("AVERAGE(1,2,3,4,5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); oParser = new parserFormula("AVERAGE({1,2;3,4})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2.5); oParser = new parserFormula("AVERAGE({1,2,3,4,5},6,\"7\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); oParser = new parserFormula("AVERAGE({1,\"2\",TRUE,4})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2.5); testArrayFormula2(assert, "AVERAGE", 1, 8, null, true); }); QUnit.test("Test: \"AVERAGEA\"", function (assert) { ws.getRange2("E2").setValue("TRUE"); ws.getRange2("E3").setValue("FALSE"); ws.getRange2("F2").setValue("10"); ws.getRange2("F3").setValue("7"); ws.getRange2("F4").setValue("9"); ws.getRange2("F5").setValue("2"); ws.getRange2("F6").setValue("Not available"); ws.getRange2("F7").setValue(""); oParser = new parserFormula("AVERAGEA(10,E1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 10); oParser = new parserFormula("AVERAGEA(10,E2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5.5); oParser = new parserFormula("AVERAGEA(10,E3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5); oParser = new parserFormula("AVERAGEA(F2:F6)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5.6); oParser = new parserFormula("AVERAGEA(F2:F5,F7)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 7); testArrayFormula2(assert, "AVERAGEA", 1, 8, null, true); }); QUnit.test("Test: \"AVERAGEIF\"", function (assert) { ws.getRange2("F2:F3").setValue(""); ws.getRange2("E2").setValue("10"); ws.getRange2("E3").setValue("20"); ws.getRange2("E4").setValue("28"); ws.getRange2("E5").setValue("30"); ws.getRange2("E6").setValue("1"); ws.getRange2("E7").setValue("0"); oParser = new parserFormula("AVERAGEIF(E2:E5,\">15\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 26); oParser = new parserFormula("AVERAGEIF(E2:E5,20)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 20); oParser = new parserFormula("AVERAGEIF(E2:E7,30)", "A1", ws); assert.ok(oParser.parse(), "AVERAGEIF(E2:E7,30)"); assert.strictEqual(oParser.calculate().getValue(), 30, "Result of AVERAGEIF(E2:E7,30)"); oParser = new parserFormula('AVERAGEIF(E2:E7,"1")', "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(E2:E7,"1")'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of AVERAGEIF(E2:E7,"1")'); oParser = new parserFormula('AVERAGEIF(E2:E7,"1s")', "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(E2:E7,"1s")'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of AVERAGEIF(E2:E7,"1s")'); oParser = new parserFormula("AVERAGEIF(E2:E7,TRUE)", "A1", ws); assert.ok(oParser.parse(), "AVERAGEIF(E2:E7,TRUE)"); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "Result of AVERAGEIF(E2:E7,TRUE)"); oParser = new parserFormula("AVERAGEIF(E2:E7,FALSE)", "A1", ws); assert.ok(oParser.parse(), "AVERAGEIF(E2:E7,FALSE)"); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "Result of AVERAGEIF(E2:E7,FALSE)"); let sheetName = ws.getName(); oParser = new parserFormula("AVERAGEIF(E2:E3,\"<>0\")", "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(E2:E3,\"<>0\")'); assert.strictEqual(oParser.calculate().getValue(), 15, 'Result of AVERAGEIF(E2:E3,\"<>0\")'); oParser = new parserFormula("AVERAGEIF(E2:E3,\"<>0\",E4:E5)", "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(E2:E3,\"<>0\",E4:E5)'); assert.strictEqual(oParser.calculate().getValue(), 29, 'Result of AVERAGEIF(E2:E3,\"<>0\",E4:E5)'); oParser = new parserFormula("AVERAGEIF("+sheetName+"!E2:E3,\"<>0\")", "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF('+sheetName+'!E2:E3,\"<>0\")'); assert.strictEqual(oParser.calculate().getValue(), 15, 'Result of AVERAGEIF('+sheetName+'!E2:E3,\"<>0\")'); oParser = new parserFormula("AVERAGEIF("+sheetName+"!E2:E3,\"<>0\", "+sheetName+"!E4:E5)", "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF('+sheetName+'!E2:E3,\"<>0\",'+sheetName+'!E4:E5)")'); assert.strictEqual(oParser.calculate().getValue(), 29, 'Result of AVERAGEIF('+sheetName+'!E2:E3,\"<>0\",'+sheetName+'!E4:E5)")'); // empty range check oParser = new parserFormula("AVERAGEIF(F2:F3,\"<>0\")", "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(F2:F3,\"<>0\") - empty range in the first argument'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of AVERAGEIF(F2:F3,\"<>0\")'); oParser = new parserFormula("AVERAGEIF(F2:F3,\"<>0\",F2:F3)", "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(F2:F3,\"<>0\",F2:F3) - empty range in the first and third args'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of AVERAGEIF(F2:F3,\"<>0\",F2:F3)'); oParser = new parserFormula("AVERAGEIF(F2:F3,\"<>0\",E2:E3)", "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(F2:F3,\"<>0\",E2:E3) - empty range in the first argument, normal range in third arg'); assert.strictEqual(oParser.calculate().getValue(), 15, 'Result of AVERAGEIF(F2:F3,\"<>0\",E2:E3)'); oParser = new parserFormula("AVERAGEIF(E2:E3,\"<>0\",F2:F3)", "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(E2:E3,\"<>0\",F2:F3) - normal range in the first arg, empty range in third arg'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of AVERAGEIF(E2:E3,\"<>0\",F2:F3)'); oParser = new parserFormula("AVERAGEIF("+sheetName+"!F2:F3,\"<>0\")", "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF('+sheetName+'!F2:F3,\"<>0\") - empty 3D range in the first argument'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of AVERAGEIF('+sheetName+'!F2:F3,\"<>0\")'); oParser = new parserFormula("AVERAGEIF("+sheetName+"!F2:F3,\"<>0\","+sheetName+"!E2:E3)", "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF('+sheetName+'!F2:F3,\"<>0\",'+sheetName+'!E2:E3) - empty 3D range in the first arg, normal 3Drange in third arg'); assert.strictEqual(oParser.calculate().getValue(), 15, 'Result of AVERAGEIF('+sheetName+'!F2:F3,\"<>0\",'+sheetName+'!E2:E3)'); // type check ws.getRange2("G1").setValue("str1"); ws.getRange2("G2").setValue("str2"); ws.getRange2("I1").setValue("TRUE"); ws.getRange2("I2").setValue("FALSE"); oParser = new parserFormula("AVERAGEIF(G1,\"<>0\")", "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(G1,\"<>0\") - string in the first arg'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of AVERAGEIF(G1,\"<>0\")'); oParser = new parserFormula("AVERAGEIF(G1,\"<>0\",E2)", "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(G1,\"<>0\",E2) - string in the first arg'); assert.strictEqual(oParser.calculate().getValue(), 10, 'Result of AVERAGEIF(G1,\"<>0\",E2)'); oParser = new parserFormula("AVERAGEIF(G1,\"<>0\",E2:E3)", "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(G1,\"<>0\",E2:E3) - string in the first arg'); assert.strictEqual(oParser.calculate().getValue(), 10, 'Result of AVERAGEIF(G1,\"<>0\",E2:E3)'); oParser = new parserFormula("AVERAGEIF(E2:E3,\"<>0\",G1)", "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(E2:E3,\"<>0\",G1) - string in the third arg'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of AVERAGEIF(E2:E3,\"<>0\",G1)'); oParser = new parserFormula("AVERAGEIF(I1,\"<>0\")", "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(I1,\"<>0\") - bool in the first arg'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of AVERAGEIF(I1,\"<>0\")'); oParser = new parserFormula("AVERAGEIF(I2,\"<>0\")", "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(I2,\"<>0\") - bool in the first arg'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of AVERAGEIF(I2,\"<>0\")'); oParser = new parserFormula("AVERAGEIF(I1,\"<>0\",E2)", "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(I1,\"<>0\",E2) - bool in the first arg'); assert.strictEqual(oParser.calculate().getValue(), 10, 'Result of AVERAGEIF(I1,\"<>0\",E2)'); oParser = new parserFormula("AVERAGEIF(I1,\"<>0\",E2:E3)", "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(I1,\"<>0\",E2:E3) - bool in the first arg'); assert.strictEqual(oParser.calculate().getValue(), 10, 'Result of AVERAGEIF(I1,\"<>0\",E2:E3)'); oParser = new parserFormula("AVERAGEIF(I2,\"<>0\",E2)", "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(I2,\"<>0\",E2) - bool in the first arg'); assert.strictEqual(oParser.calculate().getValue(), 10, 'Result of AVERAGEIF(I2,\"<>0\",E2)'); oParser = new parserFormula("AVERAGEIF(I2,\"<>0\",E2:E3)", "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(I2,\"<>0\",E2:E3) - bool in the first arg'); assert.strictEqual(oParser.calculate().getValue(), 10, 'Result of AVERAGEIF(I2,\"<>0\",E2:E3)'); /* exact types for arg0, arg2 check */ let calculateResult = new AscCommonExcel.CalculateResult(true); oParser = new parserFormula("AVERAGEIF({1,2,3},A2:A9,A2)", "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF({1,2,3},A2:A9,A2) - arg0 exact type check'); assert.strictEqual(oParser.calculate(null, null, null, null, calculateResult).getValue(), "#NULL!", 'Result of AVERAGEIF({1,2,3},A2:A9,A2)'); oParser = new parserFormula("AVERAGEIF(12,A2:A9,A2)", "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(12,A2:A9,A2) - arg0 exact type check'); assert.strictEqual(oParser.calculate(null, null, null, null, calculateResult).getValue(), "#NULL!", 'Result of AVERAGEIF(12,A2:A9,A2)'); oParser = new parserFormula('AVERAGEIF("str",A2:A9,A2)', "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF("str",A2:A9,A2) - arg0 exact type check'); assert.strictEqual(oParser.calculate(null, null, null, null, calculateResult).getValue(), "#NULL!", 'Result of AVERAGEIF("str",A2:A9,A2)'); oParser = new parserFormula('AVERAGEIF(TRUE,A2:A9,A2)', "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(TRUE,A2:A9,A2) - arg0 exact type check'); assert.strictEqual(oParser.calculate(null, null, null, null, calculateResult).getValue(), "#NULL!", 'Result of AVERAGEIF(TRUE,A2:A9,A2)'); oParser = new parserFormula('AVERAGEIF(#N/A,A2:A9,A2)', "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(#N/A,A2:A9,A2) - arg0 exact type check'); assert.strictEqual(oParser.calculate(null, null, null, null, calculateResult).getValue(), "#NULL!", 'Result of AVERAGEIF(#N/A,A2:A9,A2)'); oParser = new parserFormula("AVERAGEIF(A2,A2:A9,{1,2,3})", "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(A2,A2:A9,{1,2,3}) - arg2 exact type check'); assert.strictEqual(oParser.calculate(null, null, null, null, calculateResult).getValue(), "#NULL!", 'Result of AVERAGEIF(A2,A2:A9,{1,2,3})'); oParser = new parserFormula("AVERAGEIF(A2,A2:A9,12)", "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(A2,A2:A9,12) - arg2 exact type check'); assert.strictEqual(oParser.calculate(null, null, null, null, calculateResult).getValue(), "#NULL!", 'Result of AVERAGEIF(A2,A2:A9,12)'); oParser = new parserFormula('AVERAGEIF(A2,A2:A9,"str")', "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(A2,A2:A9,"str") - arg2 exact type check'); assert.strictEqual(oParser.calculate(null, null, null, null, calculateResult).getValue(), "#NULL!", 'Result of AVERAGEIF(A2,A2:A9,"str")'); oParser = new parserFormula('AVERAGEIF(A2,A2:A9,TRUE)', "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(A2,A2:A9,TRUE) - arg2 exact type check'); assert.strictEqual(oParser.calculate(null, null, null, null, calculateResult).getValue(), "#NULL!", 'Result of AVERAGEIF(A2,A2:A9,TRUE)'); oParser = new parserFormula('AVERAGEIF(A2,A2:A9,#N/A)', "A1", ws); assert.ok(oParser.parse(), 'AVERAGEIF(A2,A2:A9,#N/A) - arg2 exact type check'); assert.strictEqual(oParser.calculate(null, null, null, null, calculateResult).getValue(), "#NULL!", 'Result of AVERAGEIF(A2,A2:A9,#N/A)'); testArrayFormula2(assert, "AVERAGEIF", 2, 3, null, true); }); QUnit.test("Test: \"AVERAGEIFS\"", function (assert) { ws.getRange2("E2").setValue("Quiz"); ws.getRange2("E3").setValue("Grade"); ws.getRange2("E4").setValue("75"); ws.getRange2("E5").setValue("94"); ws.getRange2("F2").setValue("Quiz"); ws.getRange2("F3").setValue("Grade"); ws.getRange2("F4").setValue("85"); ws.getRange2("F5").setValue("80"); ws.getRange2("G2").setValue("Exam"); ws.getRange2("G3").setValue("Grade"); ws.getRange2("G4").setValue("87"); ws.getRange2("G5").setValue("88"); oParser = new parserFormula("AVERAGEIFS(E2:E5,E2:E5,\">70\",E2:E5,\"<90\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 75); oParser = new parserFormula("AVERAGEIFS(F2:F5,F2:F5,\">95\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!"); oParser = new parserFormula("AVERAGEIFS(G2:G5,G2:G5,\"<>Incomplete\",G2:G5,\">80\")", "A3", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 87.5); testArrayFormulaEqualsValues(assert, "1,3.123,-4,#N/A;2,4,5,#N/A;#N/A,#N/A,#N/A,#N/A", "AVERAGEIFS(A1:C2,A1:C2,A1:C2,A1:C2, A1:C2,A1:C2,A1:C2)"); testArrayFormulaEqualsValues(assert, "1,#DIV/0!,#DIV/0!,#N/A;#DIV/0!,#DIV/0!,#DIV/0!,#N/A;#N/A,#N/A,#N/A,#N/A", "AVERAGEIFS(A1:C2,A1:C2,A1:A1,A1:C2,A1:C2,A1:C2,A1:C2)"); testArrayFormulaEqualsValues(assert, "1,#DIV/0!,#DIV/0!,#N/A;2,#DIV/0!,#DIV/0!,#N/A;#N/A,#N/A,#N/A,#N/A", "AVERAGEIFS(A1:C2,A1:C2,A1:A2,A1:C2,A1:C2,A1:C2,A1:C2)"); }); QUnit.test("Test: \"AVERAGEIFS with multiple criteria ranges\"", function (assert) { // Setup test data with 5 columns for testing ws.getRange2("E2").setValue("10"); ws.getRange2("E3").setValue("20"); ws.getRange2("E4").setValue("30"); ws.getRange2("E5").setValue("40"); ws.getRange2("E6").setValue("50"); ws.getRange2("E7").setValue("60"); ws.getRange2("F2").setValue("Red"); ws.getRange2("F3").setValue("Blue"); ws.getRange2("F4").setValue("Green"); ws.getRange2("F5").setValue("Red"); ws.getRange2("F6").setValue("Blue"); ws.getRange2("F7").setValue("Green"); ws.getRange2("G2").setValue("Small"); ws.getRange2("G3").setValue("Medium"); ws.getRange2("G4").setValue("Large"); ws.getRange2("G5").setValue("Large"); ws.getRange2("G6").setValue("Medium"); ws.getRange2("G7").setValue("Small"); ws.getRange2("H2").setValue("2023"); ws.getRange2("H3").setValue("2023"); ws.getRange2("H4").setValue("2024"); ws.getRange2("H5").setValue("2024"); ws.getRange2("H6").setValue("2025"); ws.getRange2("H7").setValue("2025"); ws.getRange2("I2").setValue("A"); ws.getRange2("I3").setValue("B"); ws.getRange2("I4").setValue("C"); ws.getRange2("I5").setValue("A"); ws.getRange2("I6").setValue("B"); ws.getRange2("I7").setValue("C"); // Test with 11 arguments (1 average_range + 5 criteria pairs) oParser = new parserFormula("AVERAGEIFS(E2:E7, F2:F7, \"Red\", G2:G7, \"Large\", H2:H7, 2024, I2:I7, \"A\", I2:I7, \"*\")", "A1", ws); assert.ok(oParser.parse(), "AVERAGEIFS with 5 criteria pairs"); assert.strictEqual(oParser.calculate().getValue(), 40, "AVERAGEIFS with 5 criteria pairs"); // Only E5 (40) matches all criteria // Test with 11 arguments where none match all criteria oParser = new parserFormula("AVERAGEIFS(E2:E7, F2:F7, \"Red\", G2:G7, \"Small\", H2:H7, 2024, I2:I7, \"A\", I2:I7, \"Z\")", "A1", ws); assert.ok(oParser.parse(), "AVERAGEIFS with 5 criteria pairs - no match"); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "AVERAGEIFS with 5 criteria pairs - no match should return #DIV/0!"); // Test with cell references for criteria ws.getRange2("J2").setValue("Red"); ws.getRange2("J3").setValue("Large"); ws.getRange2("J4").setValue("2024"); ws.getRange2("J5").setValue("A"); oParser = new parserFormula("AVERAGEIFS(E2:E7, F2:F7, J2, G2:G7, J3, H2:H7, J4, I2:I7, J5, I2:I7, \"*\")", "A1", ws); assert.ok(oParser.parse(), "AVERAGEIFS with cell references for criteria"); assert.strictEqual(oParser.calculate().getValue(), 40, "AVERAGEIFS with cell references for criteria"); // Test with numeric criteria and comparison operators oParser = new parserFormula("AVERAGEIFS(E2:E7, H2:H7, \">2023\", E2:E7, \">=30\")", "A1", ws); assert.ok(oParser.parse(), "AVERAGEIFS with numeric criteria"); assert.strictEqual(oParser.calculate().getValue(), 45, "AVERAGEIFS with numeric criteria"); // Average of 30, 40, 50, 60 // Test with blank criteria ws.getRange2("F4").setValue(""); oParser = new parserFormula("AVERAGEIFS(E2:E7, F2:F7, \"\")", "A1", ws); assert.ok(oParser.parse(), "AVERAGEIFS with blank criteria"); assert.strictEqual(oParser.calculate().getValue(), 30, "AVERAGEIFS with blank criteria"); // Test with error handling - mismatched ranges oParser = new parserFormula("AVERAGEIFS(E2:E7, F2:F6, \"Red\")", "A1", ws); assert.ok(oParser.parse(), "AVERAGEIFS with mismatched ranges"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "AVERAGEIFS with mismatched ranges should return #VALUE!"); // Cleanup ws.getRange2("F4").setValue("Green"); // Restore original value }); QUnit.test("Test: \"AGGREGATE\"", function (assert) { ws.getRange2("A101").setValue("TEST"); ws.getRange2("A102").setValue("72"); ws.getRange2("A103").setValue("30"); ws.getRange2("A104").setValue("TEST2"); ws.getRange2("A105").setValue("31"); ws.getRange2("A106").setValue("96"); ws.getRange2("A107").setValue("32"); ws.getRange2("A108").setValue("81"); ws.getRange2("A109").setValue("33"); ws.getRange2("A110").setValue("53"); ws.getRange2("A111").setValue("34"); ws.getRange2("B101").setValue("82"); ws.getRange2("B102").setValue("65"); ws.getRange2("B103").setValue("95"); ws.getRange2("B104").setValue("63"); ws.getRange2("B105").setValue("53"); ws.getRange2("B106").setValue("71"); ws.getRange2("B107").setValue("55"); ws.getRange2("B108").setValue("83"); ws.getRange2("B109").setValue("100"); ws.getRange2("B110").setValue("91"); ws.getRange2("B111").setValue("89"); oParser = new parserFormula("AGGREGATE(4, 6, A101:A111)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 96); oParser = new parserFormula("AGGREGATE(14, 6, A101:A111, 3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 72); oParser = new parserFormula("AGGREGATE(15, 6, A101:A111)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("AGGREGATE(12, 6, A101:A111, B101:B111)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 68); oParser = new parserFormula("AGGREGATE(12, 6, A101:A111, B101:B111)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 68); oParser = new parserFormula("AGGREGATE(1,1,A101:B105)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 61.375); oParser = new parserFormula("AGGREGATE(2,1,A101:B105)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 8); oParser = new parserFormula("AGGREGATE(3,1,A101:B105)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 10); oParser = new parserFormula("AGGREGATE(4,1,A101:B105)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 95); oParser = new parserFormula("AGGREGATE(5,3,A101:B105)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 30); oParser = new parserFormula("AGGREGATE(6,1,100)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("AGGREGATE(7,3,A101:B105)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 22.87192602); oParser = new parserFormula("AGGREGATE(8,3,A101:B105)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 21.39472774); oParser = new parserFormula("AGGREGATE(9,3,A101:B105)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 491); oParser = new parserFormula("AGGREGATE(10,3,A101:B105)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 523.125); oParser = new parserFormula("AGGREGATE(11,3,A101:B105)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 457.734375); oParser = new parserFormula("AGGREGATE(12,3,A101:B105)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 64); oParser = new parserFormula("AGGREGATE(13,3,A101:B105,A101:B105)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 30); oParser = new parserFormula("AGGREGATE(14,3,A101:B105,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 82); oParser = new parserFormula("AGGREGATE(15,3,A101:B105,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 31); oParser = new parserFormula("AGGREGATE(16,3,A101:B105,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 95); oParser = new parserFormula("AGGREGATE(17,3,A101:B105,3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 74.5); oParser = new parserFormula("AGGREGATE(18,3,A101:B105,0.2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 30.8); oParser = new parserFormula("AGGREGATE(19,3,A101:B105,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 64); // for bug 38994 ws.getRange2("B101").setValue(""); ws.getRange2("B102").setValue("0"); ws.getRange2("B103").setValue("0"); ws.getRange2("B104").setValue("1"); ws.getRange2("B105").setValue("0"); ws.getRange2("B106").setValue("0"); ws.getRange2("B107").setValue("1"); ws.getRange2("C101").setValue("#DIV/0!"); ws.getRange2("C102").setValue("#DIV/0!"); ws.getRange2("C103").setValue("#DIV/0!"); ws.getRange2("C104").setValue("3"); ws.getRange2("C105").setValue("#DIV/0!"); ws.getRange2("C106").setValue("#DIV/0!"); ws.getRange2("C107").setValue("37"); ws.getRange2("D101").setValue(""); ws.getRange2("D102").setValue("1"); ws.getRange2("D103").setValue("2"); ws.getRange2("D104").setValue("3"); ws.getRange2("D105").setValue("4"); ws.getRange2("D106").setValue("5"); ws.getRange2("D107").setValue("999"); oParser = new parserFormula("AGGREGATE(15,6,ROW(B101:B107),1)", "A1", ws); assert.ok(oParser.parse(), 'AGGREGATE(15,6,ROW(B101:B107),1)'); assert.strictEqual(oParser.calculate().getValue(), 101, 'Result of AGGREGATE(15,6,ROW(B101:B107),1)'); oParser = new parserFormula("AGGREGATE(15,6,ROW(B101:B107)/(B102:B107=1),1)", "A1", ws); assert.ok(oParser.parse(), 'AGGREGATE(15,6,ROW(B101:B107)/(B102:B107=1),1)'); assert.strictEqual(oParser.calculate().getValue(), 103, 'Result of AGGREGATE(15,6,ROW(B101:B107)/(B102:B107=1),1)'); oParser = new parserFormula("AGGREGATE(15,6,C101:C107,1)", "A1", ws); assert.ok(oParser.parse(), 'AGGREGATE(15,6,C101:C107,1)'); assert.strictEqual(oParser.calculate().getValue(), 3, 'Result of AGGREGATE(15,6,C101:C107,1)'); // cross test let bbox = ws.getRange2("G101").bbox; let cellWithFormula = new window['AscCommonExcel'].CCellWithFormula(ws, bbox.r1, bbox.c1); oParser = new parserFormula('AGGREGATE(15,D101:D107,C101:C107,1)', cellWithFormula, ws); assert.ok(oParser.parse(), 'AGGREGATE(15,D101:D107,C101:C107,1)'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of AGGREGATE(15,D101:D107,C101:C107,1)'); bbox = ws.getRange2("G103").bbox; cellWithFormula = new window['AscCommonExcel'].CCellWithFormula(ws, bbox.r1, bbox.c1); oParser = new parserFormula('AGGREGATE(15,D101:D107,C101:C107,1)', cellWithFormula, ws); assert.ok(oParser.parse(), 'AGGREGATE(15,D101:D107,C101:C107,1)'); assert.strictEqual(oParser.calculate().getValue(), 3, 'Result of AGGREGATE(15,D101:D107,C101:C107,1)'); bbox = ws.getRange2("G104").bbox; cellWithFormula = new window['AscCommonExcel'].CCellWithFormula(ws, bbox.r1, bbox.c1); oParser = new parserFormula('AGGREGATE(15,D101:D107,C101:C107,1)', cellWithFormula, ws); assert.ok(oParser.parse(), 'AGGREGATE(15,D101:D107,C101:C107,1)'); assert.strictEqual(oParser.calculate().getValue(), 3, 'Result of AGGREGATE(15,D101:D107,C101:C107,1)'); bbox = ws.getRange2("G107").bbox; cellWithFormula = new window['AscCommonExcel'].CCellWithFormula(ws, bbox.r1, bbox.c1); oParser = new parserFormula('AGGREGATE(15,D101:D107,C101:C107,1)', cellWithFormula, ws); assert.ok(oParser.parse(), 'AGGREGATE(15,D101:D107,C101:C107,1)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of AGGREGATE(15,D101:D107,C101:C107,1)'); }); QUnit.test("Test: \"AND\"", function (assert) { ws.getRange2("A2").setValue("50"); ws.getRange2("A3").setValue("100"); oParser = new parserFormula("AND(A2>1,A2<100)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TRUE"); oParser = new parserFormula('AND(A21,A3<100)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "FALSE"); testArrayFormula2(assert, "AND", 1, 8, null, true); }); QUnit.test("Test: \"OR\"", function (assert) { ws.getRange2("A2").setValue("50"); ws.getRange2("A3").setValue("100"); oParser = new parserFormula("AND(A2>1,A2<100)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TRUE"); oParser = new parserFormula('AND(A2100)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "FALSE"); testArrayFormula2(assert, "OR", 1, 8, null, true); }); QUnit.test("Test: \"BINOMDIST\"", function (assert) { function binomdist(x, n, p) { x = parseInt(x); n = parseInt(n); return Math.binomCoeff(n, x) * Math.pow(p, x) * Math.pow(1 - p, n - x); } oParser = new parserFormula("BINOMDIST(6,10,0.5,FALSE)", "A1", ws); assert.ok(oParser.parse()); assert.ok(Math.abs(oParser.calculate().getValue() - binomdist(6, 10, 0.5)) < dif); oParser = new parserFormula("BINOMDIST(6,10,0.5,TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.ok(Math.abs(oParser.calculate().getValue() - (function () { var bm = 0; for (var y = 0; y <= 6; y++) { bm += binomdist(y, 10, 0.5) } return bm; })()) < dif); oParser = new parserFormula("BINOMDIST(11,10,0.5,FALSE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); testArrayFormula2(assert, "BINOMDIST", 4, 4); }); QUnit.test("Test: \"BINOM.DIST\"", function (assert) { ws.getRange2("A2").setValue("6"); ws.getRange2("A3").setValue("10"); ws.getRange2("A4").setValue("0.5"); oParser = new parserFormula("BINOM.DIST(A2,A3,A4,FALSE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.2050781); }); QUnit.test("Test: \"BINOM.DIST.RANGE\"", function (assert) { oParser = new parserFormula("BINOM.DIST.RANGE(60,0.75,48)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(3) - 0, 0.084); oParser = new parserFormula("BINOM.DIST.RANGE(60,0.75,45,50)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(3) - 0, 0.524); testArrayFormula2(assert, "BINOM.DIST.RANGE", 3, 4); }); QUnit.test("Test: \"CONFIDENCE\"", function (assert) { oParser = new parserFormula("CONFIDENCE(0.4,5,12)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(difBetween(oParser.calculate().getValue(), 1.214775614397568), true); oParser = new parserFormula("CONFIDENCE(0.75,9,7)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(difBetween(oParser.calculate().getValue(), 1.083909233527114), true); testArrayFormula2(assert, "CONFIDENCE", 3, 3); }); QUnit.test("Test: \"CONFIDENCE.NORM\"", function (assert) { ws.getRange2("A2").setValue("0.05"); ws.getRange2("A3").setValue("2.5"); ws.getRange2("A4").setValue("50"); oParser = new parserFormula("CONFIDENCE.NORM(A2,A3,A4)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.692952); }); QUnit.test("Test: \"CONFIDENCE.T\"", function (assert) { oParser = new parserFormula("CONFIDENCE.T(0.05,1,50)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 0.284196855); testArrayFormula2(assert, "CONFIDENCE.T", 3, 3); }); QUnit.test("Test: \"CORREL\"", function (assert) { oParser = new parserFormula("CORREL({2.532,5.621;2.1,3.4},{5.32,2.765;5.2,\"f\"})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(difBetween(oParser.calculate().getValue(), -0.988112020032211), true); oParser = new parserFormula("CORREL({1;2;3},{4;5;\"E\"})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(difBetween(oParser.calculate().getValue(), 1), true); oParser = new parserFormula("CORREL({1,2},{1,\"e\"})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!"); testArrayFormula2(assert, "CORREL", 2, 2, null, true) }); QUnit.test("Test: \"COUNT\"", function (assert) { ws.getRange2("E2").setValue("TRUE"); oParser = new parserFormula("COUNT({1,2,3,4,5})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5); oParser = new parserFormula("COUNT(1,2,3,4,5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5); oParser = new parserFormula("COUNT({1,2,3,4,5},6,\"7\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 7); oParser = new parserFormula("COUNT(10,E150)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("COUNT(10,E2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); ws.getRange2("S5").setValue("#DIV/0!"); ws.getRange2("S6").setValue("TRUE"); ws.getRange2("S7").setValue("qwe"); ws.getRange2("S8").setValue(""); ws.getRange2("S9").setValue("2"); oParser = new parserFormula("COUNT(S5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("COUNT(S6)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("COUNT(S7)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("COUNT(S8)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("COUNT(S5:S9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("COUNT(S6:S9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("COUNT({\"7\",true,false,4,5})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula("COUNT({\"7\", true, false, false})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("COUNT({\"7\", true, false, false; \"7\", true, false, 2})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); testArrayFormula2(assert, "COUNT", 2, 2, null, true); }); QUnit.test("Test: \"COUNTA\"", function (assert) { ws.getRange2("E2").setValue("TRUE"); oParser = new parserFormula("COUNTA({1,2,3,4,5})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5); oParser = new parserFormula("COUNTA(1,2,3,4,5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5); oParser = new parserFormula("COUNTA({1,2,3,4,5},6,\"7\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 7); oParser = new parserFormula("COUNTA(10,E150)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("COUNTA(10,E2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); ws.getRange2("S5").setValue("#DIV/0!"); ws.getRange2("S6").setValue("TRUE"); ws.getRange2("S7").setValue("qwe"); ws.getRange2("S8").setValue(""); ws.getRange2("S9").setValue("2"); oParser = new parserFormula("COUNTA(S5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("COUNTA(S6)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("COUNTA(S7)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("COUNTA(S8)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("COUNTA(S5:S9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); oParser = new parserFormula("COUNTA(S6:S9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); }); QUnit.test("Test: \"COUNTIFS\"", function (assert) { ws.getRange2("A15").setValue("Yes"); ws.getRange2("A16").setValue("Yes"); ws.getRange2("A17").setValue("Yes"); ws.getRange2("A18").setValue("No"); ws.getRange2("B15").setValue("No"); ws.getRange2("B16").setValue("Yes"); ws.getRange2("B17").setValue("Yes"); ws.getRange2("B18").setValue("Yes"); ws.getRange2("C15").setValue("No"); ws.getRange2("C16").setValue("No"); ws.getRange2("C17").setValue("Yes"); ws.getRange2("C18").setValue("Yes"); oParser = new parserFormula("COUNTIFS(A15:C15,\"=Yes\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("COUNTIFS(A15:A18,\"=Yes\",B15:B18,\"=Yes\")", "B1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula("COUNTIFS(A18:C18,\"=Yes\",A16:C16,\"=Yes\")", "C1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); ws.getRange2("D15").setValue("1"); ws.getRange2("D16").setValue("2"); ws.getRange2("D17").setValue("3"); ws.getRange2("D18").setValue("4"); ws.getRange2("D19").setValue("5"); ws.getRange2("D20").setValue("6"); ws.getRange2("E15").setValue("5/1/2011"); ws.getRange2("E16").setValue("5/2/2011"); ws.getRange2("E17").setValue("5/3/2011"); ws.getRange2("E18").setValue("5/4/2011"); ws.getRange2("E19").setValue("5/5/2011"); ws.getRange2("E20").setValue("5/6/2011"); oParser = new parserFormula("COUNTIFS(D15:D20,\"<6\",D15:D20,\">1\")", "D1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); oParser = new parserFormula("COUNTIFS(D15:D20,\"<5\",E15:E20,\"<5/3/2011\")", "E1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula("COUNTIFS(D15:D20,\"<\" & D19,E15:E20,\"<\" & E17)", "E1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); testArrayFormulaEqualsValues(assert, "1,1,1,#N/A;1,1,1,#N/A;#N/A,#N/A,#N/A,#N/A", "COUNTIFS(A1:C2,A1:C2,A1:C2,A1:C2, A1:C2,A1:C2)"); testArrayFormulaEqualsValues(assert, "1,0,0,#N/A;1,0,0,#N/A;#N/A,#N/A,#N/A,#N/A", "COUNTIFS(A1:C2,A1:A2,A1:C2,A1:C2,A1:C2,A1:C2)"); testArrayFormulaEqualsValues(assert, "#VALUE!,#VALUE!,#VALUE!,#N/A;#VALUE!,#VALUE!,#VALUE!,#N/A;#N/A,#N/A,#N/A,#N/A", "COUNTIFS(A1:C2,A1:C2,A1:A2,A1:C2,A1:A2,A1:C2)"); ws.getRange2("DS2").setValue("12"); ws.getRange2("DS3").setValue("2"); ws.getRange2("DS4").setValue("3"); ws.getRange2("DS5").setValue("4"); ws.getRange2("DS6").setValue("e"); ws.getRange2("DS10").setValue("12"); ws.getRange2("DU2").setValue("1"); ws.getRange2("DU3").setValue("2"); ws.getRange2("DU4").setValue("11"); ws.getRange2("DU5").setValue("11"); ws.getRange2("DU6").setValue("w"); ws.getRange2("DU9").setValue("12"); ws.getRange2("DU10").setValue("12"); oParser = new parserFormula('COUNTIFS(DS:DS,">3",DU:DU,">10")', "E1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula('COUNTIFS(DS:DS,">3",DU1:DU2,">10")', "E1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula('COUNTIFS(DS2:DS3,">3",DU:DU,">10")', "E1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula('COUNTIFS(DS:DS,"e",DU:DU,"w")', "E1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula('COUNTIFS(DS1:DS10,"<5",DU1:DU10,">2")', "E1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula('COUNTIFS(DS1:DS11,"<5",DU1:DU10,">2")', "E1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula('COUNTIFS(DS1:DS10,"<5",DU1:DU11,">2")', "E1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); // bool, ref, num, string, err ws.getRange2("A88").setValue("#DIV/0!"); ws.getRange2("A89").setValue("#NUM!"); ws.getRange2("A90").setValue("TRUE"); ws.getRange2("A91").setValue("TRUE"); ws.getRange2("A92").setValue("FALSE"); ws.getRange2("A93").setValue("FALSE"); ws.getRange2("A94").setValue("1"); ws.getRange2("A95").setValue("0"); ws.getRange2("A96").setValue("1s"); ws.getRange2("A97").setValue("1"); ws.getRange2("A97").setNumFormat("@"); ws.getRange2("A98").setValue(""); ws.getRange2("A99").setValue("0"); oParser = new parserFormula('COUNTIFS(A90:A99,TRUE)', "E1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula('COUNTIFS(A90:A99,A90)', "E1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula('COUNTIFS(A90:A99,FALSE)', "E1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula('COUNTIFS(A90:A99,A92)', "E1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula('COUNTIFS(A90:A99,1)', "E1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula('COUNTIFS(A90:A99,A94)', "E1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula('COUNTIFS(A90:A99,A97)', "E1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula('COUNTIFS(A90:A99,0)', "E1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula('COUNTIFS(A90:A99,A95)', "E1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula('COUNTIFS(A90:A99,"")', "E1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula('COUNTIFS(A90:A99,A98)', "E1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula('COUNTIFS(A90:A99,A88)', "E1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula('COUNTIFS(A90:A99,#DIV/0!)', "E1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula('COUNTIFS(A90:A99,#NUM!)', "E1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula('COUNTIFS(A90:A99,A89)', "E1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); // arg0 = #DIV/0! oParser = new parserFormula('COUNTIFS(A88,A88:A99)', "E1", ws); oParser.setArrayFormulaRef(ws.getRange2("AD6:AF8").bbox); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), 1, 'Result of COUNTIFS(A88,A88:A99)[0,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(1,0).getValue(), 0, 'Result of COUNTIFS(A88,A88:A99)[1,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(2,0).getValue(), 0, 'Result of COUNTIFS(A88,A88:A99)[2,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(3,0).getValue(), 0, 'Result of COUNTIFS(A88,A88:A99)[3,0]'); // arg0 = TRUE oParser = new parserFormula('COUNTIFS(A90,A88:A99)', "E1", ws); oParser.setArrayFormulaRef(ws.getRange2("AD6:AF8").bbox); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), 0, 'Result of COUNTIFS(A90,A88:A99)[0,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(1,0).getValue(), 0, 'Result of COUNTIFS(A90,A88:A99)[1,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(2,0).getValue(), 1, 'Result of COUNTIFS(A90,A88:A99)[2,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(3,0).getValue(), 1, 'Result of COUNTIFS(A90,A88:A99)[3,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(4,0).getValue(), 0, 'Result of COUNTIFS(A90,A88:A99)[4,0]'); // arg0 = 0 oParser = new parserFormula('COUNTIFS(A95,A88:A99)', "E1", ws); oParser.setArrayFormulaRef(ws.getRange2("AD6:AF8").bbox); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(4,0).getValue(), 0, 'Result of COUNTIFS(A95,A88:A99)[4,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(5,0).getValue(), 0, 'Result of COUNTIFS(A95,A88:A99)[5,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(6,0).getValue(), 0, 'Result of COUNTIFS(A95,A88:A99)[6,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(7,0).getValue(), 1, 'Result of COUNTIFS(A95,A88:A99)[7,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(8,0).getValue(), 0, 'Result of COUNTIFS(A95,A88:A99)[8,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(9,0).getValue(), 0, 'Result of COUNTIFS(A95,A88:A99)[9,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(10,0).getValue(), 1, 'Result of COUNTIFS(A95,A88:A99)[10,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(11,0).getValue(), 1, 'Result of COUNTIFS(A95,A88:A99)[11,0]'); // arg0 = cEmpty oParser = new parserFormula('COUNTIFS(A98,A88:A99)', "E1", ws); oParser.setArrayFormulaRef(ws.getRange2("AD6:AF8").bbox); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(4,0).getValue(), 0, 'Result of COUNTIFS(A98,A88:A99)[4,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(5,0).getValue(), 0, 'Result of COUNTIFS(A98,A88:A99)[5,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(6,0).getValue(), 0, 'Result of COUNTIFS(A98,A88:A99)[6,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(7,0).getValue(), 0, 'Result of COUNTIFS(A98,A88:A99)[7,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(8,0).getValue(), 0, 'Result of COUNTIFS(A98,A88:A99)[8,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(9,0).getValue(), 0, 'Result of COUNTIFS(A98,A88:A99)[9,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(10,0).getValue(), 0, 'Result of COUNTIFS(A98,A88:A99)[10,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(11,0).getValue(), 0, 'Result of COUNTIFS(A98,A88:A99)[11,0]'); // bug 58497 ws.getRange2("A100:Z300").cleanAll(); ws.getRange2("A101").setValue("str1"); ws.getRange2("A102").setValue("str2"); ws.getRange2("A103").setValue(""); ws.getRange2("A104").setValue(""); oParser = new parserFormula('COUNTIFS(A101:A104,A101:A104)', "E1", ws); assert.ok(oParser.parse(), "COUNTIFS(A101:A104,A101:A104)"); // without setArrayFormulaRef executed as .cross and as result and as a result, #VALUE comes into the second argument assert.strictEqual(oParser.calculate().getValue(), 0, "Result of COUNTIFS(A101:A104,A101:A104)"); oParser = new parserFormula('COUNTIFS(A101:A104,A101:A104&"")', "E1", ws); assert.ok(oParser.parse(), 'COUNTIFS(A101:A104,A101:A104&"")'); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), 1, 'Result of COUNTIFS(A101:A104,A101:A104&"")[0,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(1,0).getValue(), 1, 'Result of COUNTIFS(A101:A104,A101:A104&"")[1,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(2,0).getValue(), 2, 'Result of COUNTIFS(A101:A104,A101:A104&"")[2,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(3,0).getValue(), 2, 'Result of COUNTIFS(A101:A104,A101:A104&"")[3,0]'); oParser = new parserFormula('COUNTIFS(A101:A104,A101:A104)', "E1", ws); oParser.setArrayFormulaRef(ws.getRange2("AD6:AF8").bbox); assert.ok(oParser.parse(), "COUNTIFS(A101:A104,A101:A104)"); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), 1, "Result of COUNTIFS(A101:A104,A101:A104)[0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(1,0).getValue(), 1, "Result of COUNTIFS(A101:A104,A101:A104)[1,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(2,0).getValue(), 0, "Result of COUNTIFS(A101:A104,A101:A104)[2,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(3,0).getValue(), 0, "Result of COUNTIFS(A101:A104,A101:A104)[3,0]"); oParser = new parserFormula('COUNTIFS(A101:A104,A101:A104&"")', "E1", ws); oParser.setArrayFormulaRef(ws.getRange2("AD6:AF8").bbox); assert.ok(oParser.parse(), 'COUNTIFS(A101:A104,A101:A104&"")'); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), 1, 'Result of COUNTIFS(A101:A104,A101:A104&"")[0,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(1,0).getValue(), 1, 'Result of COUNTIFS(A101:A104,A101:A104&"")[1,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(2,0).getValue(), 2, 'Result of COUNTIFS(A101:A104,A101:A104&"")[2,0]'); assert.strictEqual(oParser.calculate().getElementRowCol(3,0).getValue(), 2, 'Result of COUNTIFS(A101:A104,A101:A104&"")[3,0]'); // for bug 64880 ws.getRange2("B:B").cleanAll(); ws.getRange2("B101").setValue("22"); ws.getRange2("B102").setValue("35"); ws.getRange2("B103").setValue("1"); ws.getRange2("B104").setValue("55"); ws.getRange2("B105").setValue("1"); ws.getRange2("B106").setValue("10"); ws.getRange2("C:C").cleanAll(); ws.getRange2("C101").setValue("3"); ws.getRange2("C102").setValue("0"); ws.getRange2("C103").setValue("6"); ws.getRange2("C104").setValue("5"); ws.getRange2("C105").setValue("2"); ws.getRange2("C106").setValue("1"); oParser = new parserFormula('COUNTIFS(B101:B106,">0",C101:C106,"=0")', "E1", ws); assert.ok(oParser.parse(), 'COUNTIFS(B101:B106,">0",C101:C106,"=0")'); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula('COUNTIFS(B:B,">0",C:C,"=0")', "E1", ws); assert.ok(oParser.parse(), 'COUNTIFS(B:B,">0",C:C,"=0")'); assert.strictEqual(oParser.calculate().getValue(), 1); ws.getRange2("C106").setValue("0"); oParser = new parserFormula('COUNTIFS(B101:B106,">0",C101:C106,"=0")', "E1", ws); assert.ok(oParser.parse(), 'COUNTIFS(B101:B106,">0",C101:C106,"=0")'); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula('COUNTIFS(B:B,">0",C:C,"=0")', "E1", ws); assert.ok(oParser.parse(), 'COUNTIFS(B:B,">0",C:C,"=0")'); assert.strictEqual(oParser.calculate().getValue(), 2); // for bug 66654 ws.getRange2("C200:C220").cleanAll(); ws.getRange2("C200:C210").setValue("externe"); ws.getRange2("C212:C215").setValue("interne"); ws.getRange2("C217:C220").setValue("externe"); ws.getRange2("D200:D220").cleanAll(); ws.getRange2("D200:D204").setValue("1") ws.getRange2("F200:F220").cleanAll(); ws.getRange2("F200:F202").setValue("1"); ws.getRange2("F205:F215").setValue("1"); ws.getRange2("F219:F220").setValue("1"); oParser = new parserFormula('COUNTIFS(C200:C220,"=externe")', "E1", ws); assert.ok(oParser.parse(), 'COUNTIFS(C200:C220,"=externe")',); assert.strictEqual(oParser.calculate().getValue(), 15, 'Result of COUNTIFS(C200:C220,"=externe")'); oParser = new parserFormula('COUNTIFS(C200:C220,"=externe", D200:D220, "=1")', "E1", ws); assert.ok(oParser.parse(), 'COUNTIFS(C200:C220,"=externe", D200:D220, "=1")',); assert.strictEqual(oParser.calculate().getValue(), 5, 'Result of COUNTIFS(C200:C220,"=externe", D200:D220, "=1")'); oParser = new parserFormula('COUNTIFS(C200:C220,"=externe", D200:D220, "=1", F200:F220, "=1")', "E1", ws); assert.ok(oParser.parse(), 'COUNTIFS(C200:C220,"=externe", D200:D220, "=1", F200:F220, "=1")',); assert.strictEqual(oParser.calculate().getValue(), 3, 'Result of COUNTIFS(C200:C220,"=externe", D200:D220, "=1", F200:F220, "=1")'); }); QUnit.test("Test: \"COUNTIFS with multiple criteria ranges\"", function (assert) { // Setup test data with 5 columns for testing ws.getRange2("E2").setValue("10"); ws.getRange2("E3").setValue("20"); ws.getRange2("E4").setValue("30"); ws.getRange2("E5").setValue("40"); ws.getRange2("E6").setValue("50"); ws.getRange2("E7").setValue("60"); ws.getRange2("F2").setValue("Red"); ws.getRange2("F3").setValue("Blue"); ws.getRange2("F4").setValue("Green"); ws.getRange2("F5").setValue("Red"); ws.getRange2("F6").setValue("Blue"); ws.getRange2("F7").setValue("Green"); ws.getRange2("G2").setValue("Small"); ws.getRange2("G3").setValue("Medium"); ws.getRange2("G4").setValue("Large"); ws.getRange2("G5").setValue("Large"); ws.getRange2("G6").setValue("Medium"); ws.getRange2("G7").setValue("Small"); ws.getRange2("H2").setValue("2023"); ws.getRange2("H3").setValue("2023"); ws.getRange2("H4").setValue("2024"); ws.getRange2("H5").setValue("2024"); ws.getRange2("H6").setValue("2025"); ws.getRange2("H7").setValue("2025"); ws.getRange2("I2").setValue("A"); ws.getRange2("I3").setValue("B"); ws.getRange2("I4").setValue("C"); ws.getRange2("I5").setValue("A"); ws.getRange2("I6").setValue("B"); ws.getRange2("I7").setValue("C"); // Test with 10 arguments (5 criteria pairs) oParser = new parserFormula("COUNTIFS(F2:F7, \"Red\", G2:G7, \"Large\", H2:H7, 2024, I2:I7, \"A\", I2:I7, \"*\")", "A1", ws); assert.ok(oParser.parse(), "COUNTIFS with 5 criteria pairs"); assert.strictEqual(oParser.calculate().getValue(), 1, "COUNTIFS with 5 criteria pairs"); // Only one row matches all criteria // Test with 10 arguments where none match all criteria oParser = new parserFormula("COUNTIFS(F2:F7, \"Red\", G2:G7, \"Small\", H2:H7, 2024, I2:I7, \"A\", I2:I7, \"Z\")", "A1", ws); assert.ok(oParser.parse(), "COUNTIFS with 5 criteria pairs - no match"); assert.strictEqual(oParser.calculate().getValue(), 0, "COUNTIFS with 5 criteria pairs - no match"); // Test with numeric criteria and comparison operators oParser = new parserFormula("COUNTIFS(E2:E7, \">20\", H2:H7, \">=2024\")", "A1", ws); assert.ok(oParser.parse(), "COUNTIFS with numeric criteria"); assert.strictEqual(oParser.calculate().getValue(), 4, "COUNTIFS with numeric criteria"); // Count values >20 in years >=2024 // Test with cell references for criteria ws.getRange2("J2").setValue("Red"); ws.getRange2("J3").setValue("Large"); ws.getRange2("J4").setValue("2024"); ws.getRange2("J5").setValue("A"); oParser = new parserFormula("COUNTIFS(F2:F7, J2, G2:G7, J3, H2:H7, J4, I2:I7, J5, I2:I7, \"*\")", "A1", ws); assert.ok(oParser.parse(), "COUNTIFS with cell references for criteria"); assert.strictEqual(oParser.calculate().getValue(), 1, "COUNTIFS with cell references for criteria"); // Test with wildcard criteria oParser = new parserFormula("COUNTIFS(F2:F7, \"*e*\", G2:G7, \"*arge\")", "A1", ws); assert.ok(oParser.parse(), "COUNTIFS with wildcard criteria"); assert.strictEqual(oParser.calculate().getValue(), 2, "COUNTIFS with wildcard criteria"); // Red/Green with Large // Test with multiple criteria for same range oParser = new parserFormula("COUNTIFS(H2:H7, \">2023\", H2:H7, \"<=2024\", G2:G7, \"Large\")", "A1", ws); assert.ok(oParser.parse(), "COUNTIFS with multiple criteria for same range"); assert.strictEqual(oParser.calculate().getValue(), 2, "COUNTIFS with multiple criteria for same range"); // Test with blank criteria ws.getRange2("F4").setValue(""); oParser = new parserFormula("COUNTIFS(F2:F7, \"\")", "A1", ws); assert.ok(oParser.parse(), "COUNTIFS with blank criteria"); assert.strictEqual(oParser.calculate().getValue(), 1, "COUNTIFS with blank criteria"); // Test with error handling - mismatched ranges oParser = new parserFormula("COUNTIFS(F2:F7, \"Red\", G2:G6, \"Large\")", "A1", ws); assert.ok(oParser.parse(), "COUNTIFS with mismatched ranges"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "COUNTIFS with mismatched ranges should return #VALUE!"); // Test counting specific patterns oParser = new parserFormula("COUNTIFS(G2:G7, \"*\", F2:F7, \"=Red\")", "A1", ws); assert.ok(oParser.parse(), "COUNTIFS with pattern matching"); assert.strictEqual(oParser.calculate().getValue(), 2, "COUNTIFS with pattern matching"); // Count all Red entries // Test with complex criteria combinations oParser = new parserFormula("COUNTIFS(E2:E7, \">30\", F2:F7, \"<>Red\", G2:G7, \"=Medium\", H2:H7, \">=2024\")", "A1", ws); assert.ok(oParser.parse(), "COUNTIFS with complex criteria combinations"); assert.strictEqual(oParser.calculate().getValue(), 1, "COUNTIFS with complex criteria combinations"); // Test with range of numbers oParser = new parserFormula("COUNTIFS(E2:E7, \">=20\", E2:E7, \"<=40\", H2:H7, \"2024\")", "A1", ws); assert.ok(oParser.parse(), "COUNTIFS with number range"); assert.strictEqual(oParser.calculate().getValue(), 2, "COUNTIFS with number range"); // Cleanup ws.getRange2("F4").setValue("Green"); // Restore original value }); QUnit.test("Test: \"COUNTIF\"", function (assert) { ws.getRange2("A7").setValue("3"); ws.getRange2("B7").setValue("10"); ws.getRange2("C7").setValue("7"); ws.getRange2("D7").setValue("10"); ws.getRange2("A8").setValue("apples"); ws.getRange2("B8").setValue("oranges"); ws.getRange2("C8").setValue("grapes"); ws.getRange2("D8").setValue("melons"); // Positive Cases: // Case #1: Area, String. Find equal number in Area oParser = new parserFormula("COUNTIF(A7:D7,\"=10\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #2: Area, String. Find numbers greater than value in Area oParser = new parserFormula("COUNTIF(A7:D7,\">5\")", "B1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); // Case #3: Area, String. Find numbers not equal to value in Area oParser = new parserFormula("COUNTIF(A7:D7,\"<>10\")", "C1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #4: Area, String. Find text ending with pattern using wildcard oParser = new parserFormula("COUNTIF(A8:D8,\"*es\")", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); // Case #5: Area, String. Find text matching pattern with question marks and wildcard oParser = new parserFormula("COUNTIF(A8:D8,\"??a*\")", "B2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #6: Area, String. Find text containing letter using wildcards oParser = new parserFormula("COUNTIF(A8:D8,\"*l*\")", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); wb.dependencyFormulas.unlockRecal(); ws.getRange2("CC1").setValue("1"); ws.getRange2("CC2").setValue("0"); ws.getRange2("CC3").setValue("1"); ws.getRange2("CC4").setValue("true"); ws.getRange2("CC5").setValue("=true"); ws.getRange2("CC6").setValue("=true()"); ws.getRange2("CC7").setValue("'true'"); ws.getRange2("CC8").setValue(""); // Case #7: Area, Formula. Count TRUE values using TRUE() function oParser = new parserFormula("COUNTIF(CC1:CC7, TRUE())", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); // Case #8: Area, Boolean. Count TRUE values using boolean literal oParser = new parserFormula("COUNTIF(CC1:CC7, TRUE)", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); // Case #9: Area, Number. Count cells equal to 1 oParser = new parserFormula("COUNTIF(CC1:CC7, 1)", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #10: Area, Number. Count cells equal to 0 oParser = new parserFormula("COUNTIF(CC1:CC7, 0)", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); // Case #11: Ref, String. Count text criteria in single cell (no match) ws.getRange2("CC8").setValue(">3"); oParser = new parserFormula("COUNTIF(CC8,\">3\")", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); // Case #12: Ref, String. Count text criteria in single cell with equals prefix ws.getRange2("CC8").setValue(">3"); oParser = new parserFormula("COUNTIF(CC8,\"=>3\")", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); // Case #13: Area, String. Count error values using string representation ws.getRange2("CC9").setValue("=NA()"); ws.getRange2("CC10").setValue("#N/A"); oParser = new parserFormula("COUNTIF(CC9:CC10,\"#N/A\")", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #14: Area, Formula. Count error values using NA() function oParser = new parserFormula("COUNTIF(CC9:CC10, NA())", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #15: Area, String. Count formula text (no match for function call) oParser = new parserFormula("COUNTIF(CC9:CC10,\"=NA()\")", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); // Case #16: Area, String. Count numbers greater than or equal to 1 oParser = new parserFormula("COUNTIF(CC1:CC8,\">=1\")", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #17: Area, String. Count numbers equal to 1 oParser = new parserFormula("COUNTIF(CC1:CC8,\"=1\")", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #18: Area, String. Count numbers less than 1 oParser = new parserFormula("COUNTIF(CC1:CC8,\"<1\")", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); // Case #19: Area, String. Count numbers greater than 1 oParser = new parserFormula("COUNTIF(CC1:CC8,\">1\")", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); // Case #20: Area, String. Count using dynamic criteria with cell reference oParser = new parserFormula("COUNTIF(CC1:CC8,\"=\"&CC8)", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); wb.dependencyFormulas.lockRecal(); ws.getRange2("A22").setValue("apples"); ws.getRange2("A23").setValue(""); ws.getRange2("A24").setValue("oranges"); ws.getRange2("A25").setValue("peaches"); ws.getRange2("A26").setValue(""); ws.getRange2("A27").setValue("apples"); // Case #21: Area, String. Count text ending with pattern using wildcard oParser = new parserFormula('COUNTIF(A22:A27,"*es")', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); // Case #22: Area, String. Count text with exact length ending with pattern oParser = new parserFormula('COUNTIF(A22:A27,"?????es")', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #23: Area, String. Count all non-empty text cells using wildcard oParser = new parserFormula('COUNTIF(A22:A27,"*")', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); // Case #24: Area, String. Count cells not equal to literal asterisks oParser = new parserFormula('COUNTIF(A22:A27,"<>"&"***")', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #25: Area, String. Count cells not equal to single asterisk oParser = new parserFormula('COUNTIF(A22:A27,"<>"&"*")', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #26: Area, String. Count cells not equal to single question mark oParser = new parserFormula('COUNTIF(A22:A27,"<>"&"?")', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 6); // Case #27: Area, String. Count exact date string match ws.getRange2("A1").setValue("12/1"); ws.getRange2("A2").setValue("12/1"); oParser = new parserFormula('COUNTIF(A1:A2,"12/1")', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #28: Area, String. Count date string with no match oParser = new parserFormula('COUNTIF(A1:A2,"12/1/1")', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); ws.getRange2("A100").setValue("Math"); ws.getRange2("A101").setValue("87"); ws.getRange2("A102").setValue("99"); ws.getRange2("A103").setValue("21"); ws.getRange2("A104").setValue("72"); ws.getRange2("A105").setValue("68"); ws.getRange2("B100").setValue("Physics"); ws.getRange2("B101").setValue("91"); ws.getRange2("B102").setValue("78"); ws.getRange2("B103").setValue("12"); ws.getRange2("B104").setValue("23"); ws.getRange2("B105").setValue("55"); // Case #32: Formula, String. Count values greater than 80 in XLOOKUP result (Math). For bug 62491 oParser = new parserFormula('COUNTIF(XLOOKUP(A100,A100:B100,A101:B105),">80")', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #33: Formula, String. Count values greater than 80 in XLOOKUP result (Physics) oParser = new parserFormula('COUNTIF(XLOOKUP(B100,A100:B100,A101:B105),">80")', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); ws.getRange2("A200").setValue(""); ws.getRange2("A201").setValue("123"); ws.getRange2("A202").setValue(""); ws.getRange2("A203").setValue(""); ws.getRange2("A204").setValue("#N/A"); ws.getRange2("A205").setValue(""); ws.getRange2("B200").setValue(""); ws.getRange2("B201").setValue(" "); ws.getRange2("B202").setValue(""); ws.getRange2("B203").setValue(""); ws.getRange2("B204").setValue(""); ws.getRange2("B205").setValue("asd"); ws.getRange2("B206").setValue('123'); ws.getRange2("B207").setValue('ASD'); // Case #40: Area, String. Empty cells check oParser = new parserFormula('COUNTIF(A200:B205,"<>"&"*")', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 10); // Case #41: Area, String. Find empty cells check oParser = new parserFormula('COUNTIF(A200:B205,"")', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 8); // Case #42: Area, Ref. second arg as cell oParser = new parserFormula('COUNTIF(A200:B205,B206)', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); // Case #43: Area, Ref. second arg as cell, case-sens test oParser = new parserFormula('COUNTIF(A200:B205,B207)', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); // Case #44: Area, String. second arg as cell, case-sens test oParser = new parserFormula('COUNTIF(A200:B205,"#n/A")', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); ws.getRange2("A300").setValue("a*c"); ws.getRange2("A301").setValue("aac"); ws.getRange2("A302").setValue("a123c"); ws.getRange2("A303").setValue("a**c"); ws.getRange2("A304").setValue(""); ws.getRange2("A305").setValue(""); // Case #45: Area, String. wildcard test with ~ oParser = new parserFormula('COUNTIF(A300:A305,"a~*c")', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); ws.getRange2("A311").setValue("1"); ws.getRange2("A312").setValue("2"); ws.getRange2("A313").setValue("3"); ws.getRange2("A314").setValue("4"); ws.getRange2("A315").setValue(">3"); const currentSheet = ws.getName(); // Case #46: Area3D, Ref3D. Ref3D and Ared3D test oParser = new parserFormula('COUNTIF(' + currentSheet + '!A311:A314,' + currentSheet + '!A315)', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); ws.getRange2("A306").setValue("Á"); ws.getRange2("A307").setValue("a"); ws.getRange2("A308").setValue("A"); ws.getRange2("A309").setValue("b"); ws.getRange2("A310").setValue(">a"); // Case #47: Area, Ref. diactric signs tests oParser = new parserFormula('COUNTIF(A306:A309,A310)', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); ws.getRange2("A316").setValue("a"); ws.getRange2("A317").setValue("a"); ws.getRange2("A318").setValue("a"); ws.getRange2("A319").setValue("あ"); ws.getRange2("A320").setValue(">a"); // Case #48: Area, Ref. Hieroglyphs test oParser = new parserFormula('COUNTIF(A316:A319,A320)', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); // Case #49: Area, Formula. Formula test oParser = new parserFormula('COUNTIF(A311:A314,2+1)', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); const defName3D = new Asc.asc_CDefName('COUNTIFTestName3D', ws.getName() + '!$A$315'); const defNameArea3D = new Asc.asc_CDefName('COUNTIFTestNameArea3D', ws.getName() + '!$A$311:$A$314'); wb.editDefinesNames(null, defName3D); wb.editDefinesNames(null, defNameArea3D); // Case #50: Name3D, Name3D. DefName test oParser = new parserFormula('COUNTIF(COUNTIFTestNameArea3D,COUNTIFTestName3D)', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); wb.delDefinesNames(defName3D); wb.delDefinesNames(defNameArea3D); // Case #51: Area, Area. oParser = new parserFormula('COUNTIF(A311:A314,A311:A314)', "C2", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 1, "Result of COUNTIF(A311:A314,A311:A314)[0,0]"); assert.strictEqual(array.getElementRowCol(1,0).getValue(), 1, "Result of COUNTIF(A311:A314,A311:A314)[1,0]"); assert.strictEqual(array.getElementRowCol(1,0).getValue(), 1, "Result of COUNTIF(A311:A314,A311:A314)[1,0]"); // Case #52: Area, Array. oParser = new parserFormula('COUNTIF(A311:A314,{1,2,3})', "C2", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 1, "Result of COUNTIF(A311:A314,A311:A314)[0,0]"); assert.strictEqual(array.getElementRowCol(0,1).getValue(), 1, "Result of COUNTIF(A311:A314,A311:A314)[0,1]"); assert.strictEqual(array.getElementRowCol(0,2).getValue(), 1, "Result of COUNTIF(A311:A314,A311:A314)[0,2]"); // TODO Tables // Negative Cases: // Case #1: Error, Number. Handle reference error in range oParser = new parserFormula("COUNTIF(#REF!, 1)", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#REF!"); // Case #2: Array, Number. oParser = new parserFormula("COUNTIF({1,2,3}, 1)", "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); // Case #3: Array, Number. oParser = new parserFormula('COUNTIF({"a","a","a"}, 1)', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); // Case #4: String, Number. oParser = new parserFormula('COUNTIF("a", 1)', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); // Case #5: String, String. oParser = new parserFormula('COUNTIF("a", "a")', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); // Case #6: Number, String. oParser = new parserFormula('COUNTIF(1, "a")', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); // Case #7: Number, Number. oParser = new parserFormula('COUNTIF(1, 1)', "C2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); // Bounded Cases: // Case #1: Area, String. Count errors greater than #N/A ws.getRange2("AB1").setValue("#N/A"); ws.getRange2("AB2").setValue("#DIV/0!"); ws.getRange2("AB3").setValue("#VALUE!"); ws.getRange2("AB4").setValue("5"); oParser = new parserFormula('COUNTIF(AB1:AB4,">#N/A")', "AC1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); // Case #2: Area, String. Count errors less than #DIV/0! oParser = new parserFormula('COUNTIF(AB1:AB4,"<#DIV/0!")', "AC2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); // Case #3: Area, String. Count errors not equal to #N/A oParser = new parserFormula('COUNTIF(AB1:AB4,"<>#N/A")', "AC3", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); // Case #4: Area, String. Count errors greater than or equal to #VALUE! oParser = new parserFormula('COUNTIF(AB1:AB4,">=#VALUE!")', "AC4", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #5: Area, String. Count values greater than error boundary ws.getRange2("AD1").setValue("#N/A"); ws.getRange2("AD2").setValue("10"); ws.getRange2("AD3").setValue("20"); ws.getRange2("AD4").setValue("text"); oParser = new parserFormula('COUNTIF(AD1:AD4,"<#N/A")', "AC6", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); // Case #6: Area, String. Count specific error type in mixed range ws.getRange2("AE1").setValue("#N/A"); ws.getRange2("AE2").setValue("#DIV/0!"); ws.getRange2("AE3").setValue("#N/A"); ws.getRange2("AE4").setValue("42"); oParser = new parserFormula('COUNTIF(AE1:AE4,"=#N/A")', "AC7", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #7: Area, String. Count specific error type in mixed range ws.getRange2("AF1").setValue("#VALUE!"); ws.getRange2("AF2").setValue("#DIV/0!"); ws.getRange2("AF3").setValue("#VALUE!"); ws.getRange2("AF4").setValue("42"); oParser = new parserFormula('COUNTIF(AF1:AF4,"<#N/A")', "AC7", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); // Case #8: Area, String. Count empty values. ' as Empty. Different with Ms // ws.getRange2("A321").setValue(""); // ws.getRange2("A322").setValue(""); // ws.getRange2("A323").setValue("'"); // oParser = new parserFormula('COUNTIF(A321:A323,"")', "C2", ws); // assert.ok(oParser.parse()); // assert.strictEqual(oParser.calculate().getValue(), 3); // testArrayFormula2(assert, "COUNTIF", 2, 2) }); QUnit.test("Test: \"COUNTBLANK\"", function (assert) { ws.getRange2("A22").setValue("6"); ws.getRange2("A23").setValue(""); ws.getRange2("A24").setValue("4"); ws.getRange2("B22").setValue(""); ws.getRange2("B23").setValue("27"); ws.getRange2("B24").setValue("34"); oParser = new parserFormula("COUNTBLANK(A22:B24)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula("COUNTBLANK(A22)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("COUNTBLANK(A23)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); }); QUnit.test("Test: \"COVAR\"", function (assert) { oParser = new parserFormula("COVAR({2.532,5.621;2.1,3.4},{5.32,2.765;5.2,6.7})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(difBetween(oParser.calculate().getValue(), -1.3753740625), true); oParser = new parserFormula("COVAR({1,2},{4,5})", "B1", ws); assert.ok(oParser.parse()); assert.strictEqual(difBetween(oParser.calculate().getValue(), 0.25), true); testArrayFormula2(assert, "COVAR", 2, 2, null, true) }); QUnit.test("Test: \"COVARIANCE.P\"", function (assert) { ws.getRange2("AA1").setValue("3"); ws.getRange2("AA2").setValue("2"); ws.getRange2("AA4").setValue("4"); ws.getRange2("AA5").setValue("5"); ws.getRange2("AA6").setValue("6"); ws.getRange2("BB1").setValue("9"); ws.getRange2("BB2").setValue("7"); ws.getRange2("BB4").setValue("12"); ws.getRange2("BB5").setValue("15"); ws.getRange2("BB6").setValue("17"); oParser = new parserFormula("COVARIANCE.P(AA1:AA6, BB1:BB6)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5.2); testArrayFormula2(assert, "COVARIANCE.P", 2, 2, null, true); }); QUnit.test("Test: \"COVARIANCE.S\"", function (assert) { ws.getRange2("AAA1").setValue("2"); ws.getRange2("AAA2").setValue("4"); ws.getRange2("AAA3").setValue("8"); ws.getRange2("BBB1").setValue("5"); ws.getRange2("BBB2").setValue("11"); ws.getRange2("BBB3").setValue("12"); oParser = new parserFormula("COVARIANCE.S({2,4,8},{5,11,12})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 9.666666667); oParser = new parserFormula("COVARIANCE.S(AAA1:AAA3,BBB1:BBB3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 9.666666667); testArrayFormula2(assert, "COVARIANCE.S", 2, 2, null, true); }); QUnit.test("Test: \"CRITBINOM\"", function (assert) { oParser = new parserFormula("CRITBINOM(6,0.5,0.75)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); oParser = new parserFormula("CRITBINOM(12,0.3,0.95)", "B1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 6); oParser = new parserFormula("CRITBINOM(-12,0.3,0.95)", "B1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("CRITBINOM(-12,1.3,0.95)", "B1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("CRITBINOM(-12,-1.3,0.95)", "B1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("CRITBINOM(-12,0,0.95)", "B1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("CRITBINOM(-12,0.3,1.95)", "B1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); testArrayFormula2(assert, "CRITBINOM", 3, 3); }); QUnit.test("Test: \"CONCAT\"", function (assert) { ws.getRange2("AA:BB").cleanAll(); ws.getRange2("AA1").setValue("a1"); ws.getRange2("AA2").setValue("a2"); ws.getRange2("AA4").setValue("a4"); ws.getRange2("AA5").setValue("a5"); ws.getRange2("AA6").setValue("a6"); ws.getRange2("AA7").setValue("a7"); ws.getRange2("BB:BB").cleanAll(); ws.getRange2("BB1").setValue("b1"); ws.getRange2("BB2").setValue("b2"); ws.getRange2("BB4").setValue("b4"); ws.getRange2("BB5").setValue("b5"); ws.getRange2("BB6").setValue("b6"); ws.getRange2("BB7").setValue("b7"); oParser = new parserFormula('CONCAT("The"," ","sun"," ","will"," ","come"," ","up"," ","tomorrow.")', "A3", ws); assert.ok(oParser.parse(), "CONCAT(AA:AA, BB:BB)"); assert.strictEqual(oParser.calculate().getValue(), "The sun will come up tomorrow.", "CONCAT(AA:AA, BB:BB)"); oParser = new parserFormula("CONCAT(AA:AA, BB:BB)", "A3", ws); assert.ok(oParser.parse(), "CONCAT(AA:AA, BB:BB)"); assert.strictEqual(oParser.calculate().getValue(), "a1a2a4a5a6a7b1b2b4b5b6b7", "CONCAT(AA:AA, BB:BB)"); oParser = new parserFormula("CONCAT(AA1:BB7)", "A3", ws); assert.ok(oParser.parse(), "CONCAT(AA1:BB7)"); assert.strictEqual(oParser.calculate().getValue(), "a1b1a2b2a4b4a5b5a6b6a7b7", "CONCAT(AA1:BB7)"); oParser = new parserFormula('CONCAT(TRUE,"test")', "A2", ws); assert.ok(oParser.parse(), 'CONCAT(TRUE,"test")'); assert.strictEqual(oParser.calculate().getValue(), "TRUEtest", 'CONCAT(TRUE,"test")'); testArrayFormulaEqualsValues(assert, "13.123-424513.123-424513.123-4245,13.123-424513.123-424513.123-4245,13.123-424513.123-424513.123-4245,13.123-424513.123-424513.123-4245;13.123-424513.123-424513.123-4245,13.123-424513.123-424513.123-4245,13.123-424513.123-424513.123-4245,13.123-424513.123-424513.123-4245;13.123-424513.123-424513.123-4245,13.123-424513.123-424513.123-4245,13.123-424513.123-424513.123-4245,13.123-424513.123-424513.123-4245", "CONCAT(A1:C2,A1:C2,A1:C2)") }); QUnit.test("Test: \"CONCATENATE\"", function (assert) { ws.getRange2("AA2").setValue("brook trout"); ws.getRange2("AA3").setValue("species"); ws.getRange2("AA4").setValue("32"); ws.getRange2("AB2").setValue("Andreas"); ws.getRange2("AB3").setValue("Fourth"); ws.getRange2("AC2").setValue("Hauser"); ws.getRange2("AC3").setValue("Pine"); oParser = new parserFormula('CONCATENATE("Stream population for ", AA2, " ", AA3, " is ", AA4, "/mile.")', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "Stream population for brook trout species is 32/mile."); oParser = new parserFormula('CONCATENATE(AB2, " ", AC2)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "Andreas Hauser"); oParser = new parserFormula('CONCATENATE(AC2, ", ", AB2)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "Hauser, Andreas"); oParser = new parserFormula('CONCATENATE(AB3, " & ", AC3)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "Fourth & Pine"); oParser = new parserFormula('CONCATENATE(TRUE,"test")', "A2", ws); assert.ok(oParser.parse(), 'CONCATENATE(TRUE,"test")'); assert.strictEqual(oParser.calculate().getValue(), "TRUEtest", 'CONCATENATE(TRUE,"test")'); testArrayFormula2(assert, "CONCATENATE", 1, 8); }); QUnit.test("Test: \"&\"", function (assert) { ws.getRange2("AAA101").setValue("1"); ws.getRange2("AAA102").setValue("2"); ws.getRange2("AAB101").setValue("3"); ws.getRange2("AAB102").setValue("4"); ws.getRange2("AAD101").setValue("2"); ws.getRange2("AAD102").setValue("3"); ws.getRange2("AAE101").setValue("4"); ws.getRange2("AAE102").setValue("5"); ws.getRange2("AAF101").setValue("test"); ws.getRange2("AAF102").setValue("test"); var array; oParser = new parserFormula("1&AAA101:AAB102", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("AD6:AF8").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "11"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "12"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "13"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "14"); oParser = new parserFormula("AAA101:AAB102&AAD101:AAE102", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("AD6:AF8").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "12"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "23"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "34"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "45"); oParser = new parserFormula("AAA101:AAB102&AAD101:AAF102", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("AD6:AF8").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "12"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "23"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "34"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "45"); oParser = new parserFormula("AJ2:AM5&AAA101:AAB102", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("AD6:AF8").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "1"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "2"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "3"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "4"); oParser = new parserFormula("AJ2:AM5&AAA101:AAA102", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("AD6:AF8").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "1"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "2"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "1"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "2"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "1"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "2"); oParser = new parserFormula("AAA101:AAB101&AAD101:AAF102", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("AD6:AF8").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "12"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "13"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "34"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "35"); oParser = new parserFormula("AAA101&AAD101:AAF102", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("AD6:AF8").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "12"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "13"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "14"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "15"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "1test"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "1test"); oParser = new parserFormula("1&AAD101:AAF102", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("AD6:AF8").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "12"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "13"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "14"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "15"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "1test"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "1test"); oParser = new parserFormula("AAD101:AAF102&\"test\"", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("AD6:AF8").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "2test"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "3test"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "4test"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "5test"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "testtest"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "testtest"); }); QUnit.test("Test: \"DEVSQ\"", function (assert) { ws.getRange2("A1").setValue("5.6"); ws.getRange2("A2").setValue("8.2"); ws.getRange2("A3").setValue("9.2"); let cellWithFormula = new AscCommonExcel.CCellWithFormula(ws, 0, 3); // A4 oParser = new parserFormula("DEVSQ(5.6,8.2,9.2)", cellWithFormula, ws); assert.ok(oParser.parse()); assert.strictEqual(difBetween(oParser.calculate().getValue(), 6.906666666666665), true); oParser = new parserFormula("DEVSQ({5.6,8.2,9.2})", cellWithFormula, ws); assert.ok(oParser.parse()); assert.strictEqual(difBetween(oParser.calculate().getValue(), 6.906666666666665), true); oParser = new parserFormula("DEVSQ(5.6,8.2,\"9.2\")", cellWithFormula, ws); assert.ok(oParser.parse()); assert.strictEqual(difBetween(oParser.calculate().getValue(), 3.379999999999999), true); oParser = new parserFormula("DEVSQ(" + ws.getName() + "!A1:A3)", cellWithFormula, ws); assert.ok(oParser.parse()); assert.strictEqual(difBetween(oParser.calculate().getValue(), 6.906666666666665), true); testArrayFormula2(assert, "DEVSQ", 1, 8, null, true); }); QUnit.test("Test: \"EXPONDIST\"", function (assert) { oParser = new parserFormula("EXPONDIST(0.2,10,FALSE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(difBetween(oParser.calculate().getValue(), 1.353352832366127), true); oParser = new parserFormula("EXPONDIST(2.3,1.5,TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(difBetween(oParser.calculate().getValue(), 0.968254363621932), true); testArrayFormula2(assert, "EXPONDIST", 3, 3); }); QUnit.test("Test: \"SIN(3.1415926)\"", function (assert) { oParser = new parserFormula('SIN(3.1415926)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), Math.sin(3.1415926)); testArrayFormula(assert, "SIN"); }); QUnit.test("Test: \"EXP\"", function (assert) { oParser = new parserFormula("EXP(1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 2.71828183); oParser = new parserFormula("EXP(2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 7.3890561); testArrayFormula(assert, "EXP"); }); QUnit.test("Test: \"EXPAND\"", function (assert) { let array; ws.getRange2("A1").setValue("2"); ws.getRange2("A2").setValue(""); ws.getRange2("A3").setValue("test"); ws.getRange2("B1").setValue("test2"); ws.getRange2("B2").setValue("#N/A"); ws.getRange2("B3").setValue("TRUE"); ws.getRange2("J7").setValue("7"); ws.getRange2("B101").setValue(); ws.getRange2("B102").setValue(); oParser = new parserFormula('EXPAND(B101,2,3)', "A1", ws); assert.ok(oParser.parse(), "EXPAND(B101,2,3)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", "Result of EXPAND(B101,2,3)"); oParser = new parserFormula('EXPAND(A1,2,3)', "A1", ws); assert.ok(oParser.parse(), "EXPAND(A1,2,3)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of EXPAND(A1,2,3).[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#N/A", "Result of EXPAND(A1,2,3).[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#N/A", "Result of EXPAND(A1,2,3).[0,2]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#N/A", "Result of EXPAND(A1,2,3).[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#N/A", "Result of EXPAND(A1,2,3).[1,1]"); oParser = new parserFormula('EXPAND(B101:B102,)', "A1", ws); assert.ok(oParser.parse(), "EXPAND(B101:B102,)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "", "Result of EXPAND(B101:B102,2).[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of EXPAND(B101:B102,2).[1,0]"); oParser = new parserFormula('EXPAND(B101:B102,1)', "A1", ws); assert.ok(oParser.parse(), "EXPAND(B101:B102,1)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of EXPAND(B101:B102,1)"); oParser = new parserFormula('EXPAND(B101:B102,2)', "A1", ws); assert.ok(oParser.parse(), "EXPAND(B101:B102,2)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "", "Result of EXPAND(B101:B102,2).[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of EXPAND(B101:B102,2).[1,0]"); // normal call oParser = new parserFormula('EXPAND(A1:B2,3,3,"new_val")', "A1", ws); assert.ok(oParser.parse(), "Regular function call: EXPAND(A1:B2,3,3,'new_val')"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Regular function call.[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "test2", "Regular function call.[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "new_val", "Regular function call.[0,2]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Regular function call.[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#N/A", "Regular function call.[1,1]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "new_val", "Regular function call.[1,2]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "new_val", "Regular function call.[2,0]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "new_val", "Regular function call.[2,1]"); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "new_val", "Regular function call.[2,2]"); // array_size > max_array_size oParser = new parserFormula('EXPAND(A1:A3,5000,5000,"new_val")', "A1", ws); assert.ok(oParser.parse(), "Call function with resulting array more than 1048576"); array = oParser.calculate(); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "If the resulting array is too large return #NUM!"); // ------------------------------ arg[0] ------------------------------ // // cell ref(single value) oParser = new parserFormula('EXPAND(A1,2,2,"new_val")', "A1", ws); assert.ok(oParser.parse(), "Pass a single value from cell to the first argument"); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), 2, "Pass a single value from cell to the first argument"); // cell ref(array-like value) oParser = new parserFormula('EXPAND(A1:B2,3,3,"new_val")', "A1", ws); assert.ok(oParser.parse(), "Pass an array-like value from cells to the first argument"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Pass an array-like value from cells to the first argument.[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "test2", "Pass an array-like value from cells to the first argument.[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "new_val", "Pass an array-like value from cells to the first argument.[0,2]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Pass an array-like value from cells to the first argument.[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#N/A", "Pass an array-like value from cells to the first argument.[1,1]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "new_val", "Pass an array-like value from cells to the first argument.[1,2]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "new_val", "Pass an array-like value from cells to the first argument.[2,0]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "new_val", "Pass an array-like value from cells to the first argument.[2,1]"); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "new_val", "Pass an array-like value from cells to the first argument.[2,2]"); // empty (no value) oParser = new parserFormula('EXPAND(,2,2,"new_val")', "A1", ws); assert.ok(oParser.parse(), "Pass an empty value() to the first argument"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Pass an empty value() to the first argument"); // empty ("") oParser = new parserFormula('EXPAND("",2,2,"new_val")', "A1", ws); assert.ok(oParser.parse(), "Pass an empty value('') to the first argument"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "", "Pass an empty value('') to the first argument.[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "new_val", "Pass an empty value('') to the first argument.[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "new_val", "Pass an empty value('') to the first argument.[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "new_val", "Pass an empty value('') to the first argument.[1,1]"); // string oParser = new parserFormula('EXPAND("str",2,2,"new_val")', "A1", ws); assert.ok(oParser.parse(), "Pass a string to the first argument"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "str", "Pass a string to the first argument.[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "new_val", "Pass a string to the first argument.[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "new_val", "Pass a string to the first argument.[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "new_val", "Pass a string to the first argument.[1,1]"); // bool oParser = new parserFormula('EXPAND(TRUE,2,2,"new_val")', "A1", ws); assert.ok(oParser.parse(), "Pass a boolean to the first argument"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "TRUE", "Pass a boolean to the first argument.[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "new_val", "Pass a boolean to the first argument.[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "new_val", "Pass a boolean to the first argument.[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "new_val", "Pass a boolean to the first argument.[1,1]"); // number oParser = new parserFormula('EXPAND(98,2,2,"new_val")', "A1", ws); assert.ok(oParser.parse(), "Pass a number to the first argument"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 98, "Pass a number to the first argument.[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "new_val", "Pass a number to the first argument.[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "new_val", "Pass a number to the first argument.[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "new_val", "Pass a number to the first argument.[1,1]"); // error oParser = new parserFormula('EXPAND(#N/A,2,2,"new_val")', "A1", ws); assert.ok(oParser.parse(), "Pass an error to the first argument"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Pass an error to the first argument"); // array(1,2,3) oParser = new parserFormula('EXPAND({1,2,3},3,3,"new_val")', "A1", ws); assert.ok(oParser.parse(), "Pass an array to the first argument"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Pass an array to the first argument.[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, "Pass an array to the first argument.[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 3, "Pass an array to the first argument.[0,2]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "new_val", "Pass an array to the first argument.[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "new_val", "Pass an array to the first argument.[1,1]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "new_val", "Pass an array to the first argument.[1,2]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "new_val", "Pass an array to the first argument.[2,0]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "new_val", "Pass an array to the first argument.[2,1]"); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "new_val", "Pass an array to the first argument.[2,2]"); // ------------------------------ arg[1] ------------------------------ // // empty (no value) oParser = new parserFormula('EXPAND(A1:B2,,2,"new_val")', "A1", ws); assert.ok(oParser.parse(), "Pass an empty value() to the second argument"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Pass an empty value() to the second argument.[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "test2" ,"Pass an empty value() to the second argument.[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Pass an empty value() to the second argument.[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#N/A", "Pass an empty value() to the second argument.[1,1]"); // string oParser = new parserFormula('EXPAND(A1:B2,"str",2,"new_val")', "A1", ws); assert.ok(oParser.parse(), "Pass a string with letters to the second argument"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Pass a string with letters to the second argument. Should return #VALUE"); // string (with number inside) oParser = new parserFormula('EXPAND(A1:B2,"2",2,"new_val")', "A1", ws); assert.ok(oParser.parse(), "Pass a string with numbers to the second argument"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Pass a string with numbers to the second argument.[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "test2", "Pass a string with numbers to the second argument.[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Pass a string with numbers to the second argument.[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#N/A", "Pass a string with numbers to the second argument.[1,1]"); oParser = new parserFormula('EXPAND(98,"2s",2,"new_val")', "A1", ws); assert.ok(oParser.parse(), "Pass a string with numbers to the second argument"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Pass a string with numbers to the second argument"); // bool oParser = new parserFormula('EXPAND(A1:B2,TRUE,2,"new_val")', "A1", ws); assert.ok(oParser.parse(), "Pass a boolean to the second argument"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Pass a boolean to the second argument."); // error oParser = new parserFormula('EXPAND(A1:B2,#N/A,2,"new_val")', "A1", ws); assert.ok(oParser.parse(), "Pass an error to the second argument"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Pass an error to the second argument."); // row < arr.length oParser = new parserFormula('EXPAND(A1:B3,1,4,5)', "A1", ws); assert.ok(oParser.parse(), "Pass a number to the second argument(number < rows in exist area)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "If the second argument is less than the original row length should return #VALUE!."); // array(first number < array.length) oParser = new parserFormula('EXPAND(A1:B2,{1,2,3},4,5)', "A1", ws); assert.ok(oParser.parse(), "Pass an array to the second argument(first number of array < rows in exist area)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "If the second argument is less than the original row length should return #VALUE!."); // array(first number >= arr.length) oParser = new parserFormula('EXPAND(A1:B1,{3,2,4},4,5)', "A1", ws); assert.ok(oParser.parse(), "Pass an array to the second argument(first number of array >= rows in exist area)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Pass an array to the second argument(first number of array >= rows in exist area).[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "test2", "Pass an array to the second argument(first number of array >= rows in exist area).[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 5, "Pass an array to the second argument(first number of array >= rows in exist area).[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 5, "Pass an array to the second argument(first number of array >= rows in exist area).[1,1]"); // cell ref(single value - string) oParser = new parserFormula('EXPAND(A1:B1,B1,3,5)', "A1", ws); assert.ok(oParser.parse(), "Pass a reference to value in cell(single - string) to the second argument"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Pass a reference to value in cell(single - string) to the second argument."); // cell ref(single value - number) oParser = new parserFormula('EXPAND(A1:B1,A1,3,5)', "A1", ws); assert.ok(oParser.parse(), "Pass a reference to value in cell(single - number) to the second argument"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Pass a reference to value in cell(single - number) to the second argument.[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "test2", "Pass a reference to value in cell(single - number) to the second argument.[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 5, "Pass a reference to value in cell(single - number) to the second argument.[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 5, "Pass a reference to value in cell(single - number) to the second argument.[1,1]"); // cell ref(single value - boolean) oParser = new parserFormula('EXPAND(A1:B1,TRUE,3,5)', "A1", ws); assert.ok(oParser.parse(), "Pass a reference to value in cell(single - boolean(TRUE)) to the second argument. TRUE transform in to 1 and then the function works with a number"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Pass a reference to value in cell(single - boolean(TRUE)) to the second argument.[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "test2", "Pass a reference to value in cell(single - boolean(TRUE)) to the second argument.[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Pass a reference to value in cell(single - boolean(TRUE)) to the second argument.[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Pass a reference to value in cell(single - boolean(TRUE)) to the second argument.[1,1]"); // cell ref(single value - boolean) oParser = new parserFormula('EXPAND(A1:B1,FALSE,3,5)', "A1", ws); assert.ok(oParser.parse(), "Pass a reference to value in cell(single - boolean(FALSE)) to the second argument"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Pass a reference to value in cell(single - boolean(FALSE)) to the second argument."); // cell ref(array-like cellsRange) oParser = new parserFormula('EXPAND(A1:B1,A1:B1,3,5)', "A1", ws); assert.ok(oParser.parse(), "Pass a reference to values in cells(cellsRange) to the second argument"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Pass a reference to values in cells(cellsRange) to the second argument."); // ------------------------------ arg[2] ------------------------------ // // empty (no value) oParser = new parserFormula('EXPAND(A1:B2,2,,"new_val")', "A1", ws); assert.ok(oParser.parse(), "Pass an empty value() to the third argument"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Pass an empty value() to the third argument.[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "test2", "Pass an empty value() to the third argument.[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Pass an empty value() to the third argument.[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#N/A", "Pass an empty value() to the third argument.[1,1]"); // string oParser = new parserFormula('EXPAND(A1:B2,2,"str","new_val")', "A1", ws); assert.ok(oParser.parse(), "Pass a string with letters to the third argument"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Pass a string with letters to the third argument. Should return #VALUE"); // string (with number inside) oParser = new parserFormula('EXPAND(A1:B2,2,"2","new_val")', "A1", ws); assert.ok(oParser.parse(), "Pass a string with numbers to the third argument"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Pass a string with numbers to the third argument.[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "test2", "Pass a string with numbers to the third argument.[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Pass a string with numbers to the third argument.[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#N/A", "Pass a string with numbers to the third argument.[1,1]"); // bool oParser = new parserFormula('EXPAND(A1:B2,2,TRUE,"new_val")', "A1", ws); assert.ok(oParser.parse(), "Pass a boolean value to the third argument"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Pass a boolean value to the third argument."); // error oParser = new parserFormula('EXPAND(A1:B2,2,#N/A,"new_val")', "A1", ws); assert.ok(oParser.parse(), "Pass an error to the third argument"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Pass an error to the third argument."); // column < array.length oParser = new parserFormula('EXPAND(A1:B3,4,1,5)', "A1", ws); assert.ok(oParser.parse(), "Pass a number to the third argument(number < columns in exist area)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "If the third argument is less than the original column length should return #VALUE!."); // array(first number < array.length) oParser = new parserFormula('EXPAND(A1:B2,4,{1,2,3},5)', "A1", ws); assert.ok(oParser.parse(), "Pass an array to the third argument(first number of array < columns in exist area)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "If the third argument is less than the original column length should return #VALUE!."); // arry(first number >= arr.length) oParser = new parserFormula('EXPAND(A1:B1,3,{3,2,4},5)', "A1", ws); assert.ok(oParser.parse(), "Pass an array to the third argument(first number of array >= columns in exist area)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Pass an array to the third argument(first number of array >= columns in exist area).[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "test2", "Pass an array to the third argument(first number of array >= columns in exist area).[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 5, "Pass an array to the third argument(first number of array >= columns in exist area).[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 5, "Pass an array to the third argument(first number of array >= columns in exist area).[1,1]"); // cell ref(single value - string) oParser = new parserFormula('EXPAND(A1:B1,3,B1,5)', "A1", ws); assert.ok(oParser.parse(), "Pass a reference to value in cell(single - string) to the third argument"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Pass a reference to value in cell(single - string) to the third argument."); // cell ref(single value - number) oParser = new parserFormula('EXPAND(A1:B1,3,A1,5)', "A1", ws); assert.ok(oParser.parse(), "Pass a reference to value in cell(single - number) to the third argument"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Pass a reference to value in cell(single - number) to the third argument.[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "test2", "Pass a reference to value in cell(single - number) to the third argument.[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 5, "Pass a reference to value in cell(single - number) to the third argument.[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 5, "Pass a reference to value in cell(single - number) to the third argument.[1,1]"); // cell ref(single value - boolean) oParser = new parserFormula('EXPAND(A1:B1,3,TRUE,5)', "A1", ws); assert.ok(oParser.parse(), "Pass a reference to value in cell(single - boolean) to the third argument"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Pass a reference to value in cell(single - boolean) to the third argument."); // cell ref(array-like cellsRange) oParser = new parserFormula('EXPAND(A1:B1,3,A1:B1,5)', "A1", ws); assert.ok(oParser.parse(), "Pass a reference to values in cells(cellsRange) to the third argument"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Pass a reference to values in cells(cellsRange) to the third argument."); // ------------------------------ arg[3] ------------------------------ // // empty (no value) oParser = new parserFormula('EXPAND(A1:A1,2,2)', "A1", ws); assert.ok(oParser.parse(), "Did not pass a value to the last argument"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Did not pass a value to the last argument.[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#N/A", "Did not pass a value to the last argument.[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#N/A", "Did not pass a value to the last argument.[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#N/A", "Did not pass a value to the last argument.[1,1]"); // empty ("") oParser = new parserFormula('EXPAND(A1:A1,2,2,)', "A1", ws); assert.ok(oParser.parse(), "Pass an empty value() to the last argument"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Pass an empty value() to the last argument.[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Pass an empty value() to the last argument.[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Pass an empty value() to the last argument.[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Pass an empty value() to the last argument.[1,1]"); // number oParser = new parserFormula('EXPAND(A1:A1,2,2,5)', "A1", ws); assert.ok(oParser.parse(), "Pass a number to the last argument"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Pass a number to the last argument.[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 5, "Pass a number to the last argument.[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 5, "Pass a number to the last argument.[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 5, "Pass a number to the last argument.[1,1]"); // string oParser = new parserFormula('EXPAND(A1:A1,2,2,"new_val")', "A1", ws); assert.ok(oParser.parse(), "Pass a string to the last argument"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Pass a string to the last argument.[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "new_val", "Pass a string to the last argument.[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "new_val", "Pass a string to the last argument.[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "new_val", "Pass a string to the last argument.[1,1]"); // bool oParser = new parserFormula('EXPAND(A1:A1,2,2,TRUE)', "A1", ws); assert.ok(oParser.parse(), "Pass a boolean value to the last argument"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Pass a boolean value to the last argument.[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "TRUE", "Pass a boolean value to the last argument.[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "TRUE", "Pass a boolean value to the last argument.[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "TRUE", "Pass a boolean value to the last argument.[1,1]"); // error oParser = new parserFormula('EXPAND(A1:A1,2,2,#N/A)', "A1", ws); assert.ok(oParser.parse(), "Pass an error to the last argument"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Pass an error to the last argument.[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#N/A", "Pass an error to the last argument.[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#N/A", "Pass an error to the last argument.[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#N/A", "Pass an error to the last argument.[1,1]"); // cell ref(single) oParser = new parserFormula('EXPAND(A1:A1,2,2,A3)', "A1", ws); assert.ok(oParser.parse(), "Pass a reference to value in cell(single) to the last argument"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Pass a reference to value in cell(single) to the last argument.[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue().getValue(), "test", "Pass a reference to value in cell(single) to the last argument.[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue().getValue(), "test", "Pass a reference to value in cell(single) to the last argument.[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue().getValue(), "test", "Pass a reference to value in cell(single) to the last argument.[1,1]"); // cell ref(multiple) // get the array -> get the values from array oParser = new parserFormula('EXPAND(A1:A1,2,2,A1:B1)', "A1", ws); assert.ok(oParser.parse(), "Pass a reference to value in cell(array-like) to the last argument"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Pass a reference to value in cell(single) to the last argument."); // array oParser = new parserFormula('EXPAND(A1:A1,2,2,{1,2})', "A1", ws); assert.ok(oParser.parse(), "Pass an array to the last argument"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Pass an array to the last argument."); }) QUnit.test("Test: \"FISHER\"", function (assert) { function fisher(x) { return toFixed(0.5 * Math.ln((1 + x) / (1 - x))); } oParser = new parserFormula("FISHER(-0.43)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), fisher(-.43)); oParser = new parserFormula("FISHER(0.578)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), fisher(0.578)); oParser = new parserFormula("FISHER(1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("FISHER(-1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); testArrayFormula(assert, "FISHER"); }); QUnit.test("Test: \"FISHERINV\"", function (assert) { function fisherInv(x) { return toFixed((Math.exp(2 * x) - 1) / (Math.exp(2 * x) + 1)); } oParser = new parserFormula("FISHERINV(-0.43)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), fisherInv(-.43)); oParser = new parserFormula("FISHERINV(0.578)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), fisherInv(0.578)); oParser = new parserFormula("FISHERINV(1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), fisherInv(1)); oParser = new parserFormula("FISHERINV(-1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), fisherInv(-1)); testArrayFormula(assert, "FISHERINV"); }); QUnit.test("Test: \"FORECAST\"", function (assert) { function forecast(fx, y, x) { let fSumDeltaXDeltaY = 0, fSumSqrDeltaX = 0, _x = 0, _y = 0, xLength = 0; for (let i = 0; i < x.length; i++) { _x += x[i]; _y += y[i]; xLength++; } _x /= xLength; _y /= xLength; for (let i = 0; i < x.length; i++) { let fValX = x[i]; let fValY = y[i]; fSumDeltaXDeltaY += (fValX - _x) * (fValY - _y); fSumSqrDeltaX += (fValX - _x) * (fValX - _x); } return toFixed(_y + fSumDeltaXDeltaY / fSumSqrDeltaX * (fx - _x)); } // add a sheet to check area3D type ws2 = wb.createWorksheet(0, "Sheet2"); oParser = new parserFormula("FORECAST(30,{6,7,9,15,21},{20,28,31,38,40})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), forecast(30, [6, 7, 9, 15, 21], [20, 28, 31, 38, 40])); oParser = new parserFormula("FORECAST(1,{1,2},{1,2})", "A1", ws); assert.ok(oParser.parse(), "FORECAST(1,{1,2},{1,2})"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of FORECAST(1,{1,2},{1,2})"); oParser = new parserFormula("FORECAST(1,{1,2},{1,2,3})", "A1", ws); assert.ok(oParser.parse(), "FORECAST(1,{1,2},{1,2,3})"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of FORECAST(1,{1,2},{1,2,3})"); oParser = new parserFormula("FORECAST(1,{1,2,3},{1,2})", "A1", ws); assert.ok(oParser.parse(), "FORECAST(1,{1,2,3},{1,2})"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of FORECAST(1,{1,2,3},{1,2})"); ws.getRange2("A1").setValue("1"); ws.getRange2("A2").setValue("2"); ws.getRange2("B1").setValue("3"); ws.getRange2("B2").setValue("4"); ws2.getRange2("A1").setValue("1"); ws2.getRange2("A2").setValue("2"); ws2.getRange2("B1").setValue("3"); ws2.getRange2("B2").setValue("4"); let cellWithFormula = new AscCommonExcel.CCellWithFormula(ws, 0, 2); oParser = new parserFormula("FORECAST(1,A1:A2,B1:B2)", cellWithFormula, ws); assert.ok(oParser.parse(), "FORECAST(1,A1:A2,B1:B2)"); assert.strictEqual(oParser.calculate().getValue(), -1, "Result of FORECAST(1,A1:A2,B1:B2)"); // for bug 65245 oParser = new parserFormula("FORECAST(1,Sheet2!A1:A2,Sheet2!B1:B2)", cellWithFormula, ws); assert.ok(oParser.parse(), "FORECAST(1,Sheet2!A1:A2,Sheet2!B1:B2). Bug 65245 test"); assert.strictEqual(oParser.calculate().getValue(), -1, "Result of FORECAST(1,Sheet2!A1:A2,Sheet2!B1:B2)"); // errors oParser = new parserFormula("FORECAST(#N/A,A1:A2,B1:B2)", cellWithFormula, ws); assert.ok(oParser.parse(), "FORECAST(#N/A,A1:A2,B1:B2)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of FORECAST(#N/A,A1:A2,B1:B2)"); oParser = new parserFormula("FORECAST(1,#NUM!,#N/A)", cellWithFormula, ws); assert.ok(oParser.parse(), "FORECAST(1,#NUM!,#N/A)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of FORECAST(1,#NUM!,#N/A)"); oParser = new parserFormula("FORECAST(1,A1:A2,#NUM!)", cellWithFormula, ws); assert.ok(oParser.parse(), "FORECAST(1,A1:A2,#NUM!)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of FORECAST(1,A1:A2,#NUM!)"); // strings oParser = new parserFormula('FORECAST("1",A1:A2,B1:B2)', cellWithFormula, ws); assert.ok(oParser.parse(), 'FORECAST("1",A1:A2,B1:B2)'); assert.strictEqual(oParser.calculate().getValue(), -1, 'Result of FORECAST("1",A1:A2,B1:B2)'); oParser = new parserFormula('FORECAST("1s",A1:A2,B1:B2)', cellWithFormula, ws); assert.ok(oParser.parse(), 'FORECAST("1s",A1:A2,B1:B2)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of FORECAST("1s",A1:A2,B1:B2)'); oParser = new parserFormula('FORECAST(1,{1,"2"},{1,2})', cellWithFormula, ws); assert.ok(oParser.parse(), 'FORECAST(1,{1,"2"},{1,2})'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of FORECAST(1,{1,"2"},{1,2})'); oParser = new parserFormula('FORECAST(1,{1,2},{"1",2})', cellWithFormula, ws); assert.ok(oParser.parse(), 'FORECAST(1,{1,2},{"1",2})'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of FORECAST(1,{1,2},{"1",2})'); // bools oParser = new parserFormula('FORECAST(FALSE,A1:A2,B1:B2)', cellWithFormula, ws); assert.ok(oParser.parse(), 'FORECAST(FALSE,A1:A2,B1:B2)'); assert.strictEqual(oParser.calculate().getValue(), -2, 'Result of FORECAST(FALSE,A1:A2,B1:B2)'); oParser = new parserFormula('FORECAST(TRUE,A1:A2,B1:B2)', cellWithFormula, ws); assert.ok(oParser.parse(), 'FORECAST(TRUE,A1:A2,B1:B2)'); assert.strictEqual(oParser.calculate().getValue(), -1, 'Result of FORECAST(TRUE,A1:A2,B1:B2)'); oParser = new parserFormula('FORECAST(TRUE,{TRUE,2},{TRUE,2})', cellWithFormula, ws); assert.ok(oParser.parse(), 'FORECAST(TRUE,{TRUE,2},{TRUE,2})'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of FORECAST(TRUE,{TRUE,2},{TRUE,2})'); // delete the previously created sheet wb.removeWorksheet(0); }); function putDataForForecastEts() { ws.getRange2('A4').setValue('39814'); ws.getRange2('A5').setValue('39845'); ws.getRange2('A6').setValue('39873'); ws.getRange2('A7').setValue('39904'); ws.getRange2('A8').setValue('39934'); ws.getRange2('A9').setValue('39965'); ws.getRange2('A10').setValue('39995'); ws.getRange2('A11').setValue('40026'); ws.getRange2('A12').setValue('40057'); ws.getRange2('A13').setValue('40087'); ws.getRange2('A14').setValue('40118'); ws.getRange2('A15').setValue('40148'); ws.getRange2('A16').setValue('40179'); ws.getRange2('A17').setValue('40210'); ws.getRange2('A18').setValue('40238'); ws.getRange2('A19').setValue('40269'); ws.getRange2('A20').setValue('40299'); ws.getRange2('A21').setValue('40330'); ws.getRange2('A22').setValue('40360'); ws.getRange2('A23').setValue('40391'); ws.getRange2('A24').setValue('40422'); ws.getRange2('A25').setValue('40452'); ws.getRange2('A26').setValue('40483'); ws.getRange2('A27').setValue('40513'); ws.getRange2('A28').setValue('40544'); ws.getRange2('A29').setValue('40575'); ws.getRange2('A30').setValue('40603'); ws.getRange2('A31').setValue('40634'); ws.getRange2('A32').setValue('40664'); ws.getRange2('A33').setValue('40695'); ws.getRange2('A34').setValue('40725'); ws.getRange2('A35').setValue('40756'); ws.getRange2('A36').setValue('40787'); ws.getRange2('A37').setValue('40817'); ws.getRange2('A38').setValue('40848'); ws.getRange2('A39').setValue('40878'); ws.getRange2('A40').setValue('40909'); ws.getRange2('A41').setValue('40940'); ws.getRange2('A42').setValue('40969'); ws.getRange2('A43').setValue('41000'); ws.getRange2('A44').setValue('41030'); ws.getRange2('A45').setValue('41061'); ws.getRange2('A46').setValue('41091'); ws.getRange2('A47').setValue('41122'); ws.getRange2('A48').setValue('41153'); ws.getRange2('A49').setValue('41183'); ws.getRange2('A50').setValue('41214'); ws.getRange2('A51').setValue('41244'); ws.getRange2('A52').setValue('41275'); ws.getRange2('A53').setValue('41306'); ws.getRange2('A54').setValue('41334'); ws.getRange2('A55').setValue('41365'); ws.getRange2('A56').setValue('41395'); ws.getRange2('A57').setValue('41426'); ws.getRange2('A58').setValue('41456'); ws.getRange2('A59').setValue('41487'); ws.getRange2('A60').setValue('41518'); ws.getRange2('B4').setValue('2644539'); ws.getRange2('B5').setValue('2359800'); ws.getRange2('B6').setValue('2925918'); ws.getRange2('B7').setValue('3024973'); ws.getRange2('B8').setValue('3177100'); ws.getRange2('B9').setValue('3419595'); ws.getRange2('B10').setValue('3649702'); ws.getRange2('B11').setValue('3650668'); ws.getRange2('B12').setValue('3191526'); ws.getRange2('B13').setValue('3249428'); ws.getRange2('B14').setValue('2971484'); ws.getRange2('B15').setValue('3074209'); ws.getRange2('B16').setValue('2785466'); ws.getRange2('B17').setValue('2515361'); ws.getRange2('B18').setValue('3105958'); ws.getRange2('B19').setValue('3139059'); ws.getRange2('B20').setValue('3380355'); ws.getRange2('B21').setValue('3612886'); ws.getRange2('B22').setValue('3765824'); ws.getRange2('B23').setValue('3771842'); ws.getRange2('B24').setValue('3356365'); ws.getRange2('B25').setValue('3490100'); ws.getRange2('B26').setValue('3163659'); ws.getRange2('B27').setValue('3167124'); ws.getRange2('B28').setValue('2883810'); ws.getRange2('B29').setValue('2610667'); ws.getRange2('B30').setValue('3129205'); ws.getRange2('B31').setValue('3200527'); ws.getRange2('B32').setValue('3547804'); ws.getRange2('B33').setValue('3766323'); ws.getRange2('B34').setValue('3935589'); ws.getRange2('B35').setValue('3917884'); ws.getRange2('B36').setValue('3564970'); ws.getRange2('B37').setValue('3602455'); ws.getRange2('B38').setValue('3326859'); ws.getRange2('B39').setValue('3441693'); ws.getRange2('B40').setValue('3211600'); ws.getRange2('B41').setValue('2998119'); ws.getRange2('B42').setValue('3472440'); ws.getRange2('B43').setValue('3563007'); ws.getRange2('B44').setValue('3820570'); ws.getRange2('B45').setValue('4107195'); ws.getRange2('B46').setValue('4284443'); ws.getRange2('B47').setValue('4356216'); ws.getRange2('B48').setValue('3819379'); ws.getRange2('B49').setValue('3844987'); ws.getRange2('B50').setValue('3478890'); ws.getRange2('B51').setValue('3443039'); ws.getRange2('B52').setValue('3204637'); ws.getRange2('B53').setValue('2966477'); ws.getRange2('B54').setValue('3593364'); ws.getRange2('B55').setValue('3604104'); ws.getRange2('B56').setValue('3933016'); ws.getRange2('B57').setValue('4146797'); ws.getRange2('B58').setValue('4176486'); ws.getRange2('B59').setValue('4347059'); ws.getRange2('B60').setValue('3781168'); ws.getRange2('A61').setValue('41548'); ws.getRange2('A62').setValue('41579'); ws.getRange2('A63').setValue('41609'); ws.getRange2('A64').setValue('41640'); ws.getRange2('A65').setValue('41671'); ws.getRange2('A66').setValue('41699'); ws.getRange2('A67').setValue('41730'); ws.getRange2('A68').setValue('41760'); ws.getRange2('A69').setValue('41791'); ws.getRange2('A70').setValue('41821'); ws.getRange2('A71').setValue('41852'); ws.getRange2('A72').setValue('41883'); ws.getRange2('A73').setValue('41913'); ws.getRange2('A74').setValue('41944'); ws.getRange2('A75').setValue('41974'); ws.getRange2('A76').setValue('42005'); ws.getRange2('A77').setValue('42036'); ws.getRange2('A78').setValue('42064'); ws.getRange2('A79').setValue('42095'); ws.getRange2('A80').setValue('42125'); ws.getRange2('A81').setValue('42156'); ws.getRange2('A82').setValue('42186'); ws.getRange2('A83').setValue('42217'); ws.getRange2('A84').setValue('42248'); } QUnit.test("Test: \"FORECAST.ETS\"", function (assert) { //результаты данного теста соответсвуют результатам LO, но отличаются от MS!!! putDataForForecastEts(); oParser = new parserFormula("FORECAST.ETS(A61,B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 3868499.49723621); oParser = new parserFormula("FORECAST.ETS(A62,B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 3560200.99816396); oParser = new parserFormula("FORECAST.ETS(A63,B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 3619491.6524986); oParser = new parserFormula("FORECAST.ETS(A64,B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 3397521.44972895); oParser = new parserFormula("FORECAST.ETS(A65,B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 3152698.4854144); oParser = new parserFormula("FORECAST.ETS(A66,B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 3704079.5812005); oParser = new parserFormula("FORECAST.ETS(A67,B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 3747546.50043675); oParser = new parserFormula("FORECAST.ETS(A68,B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 4042011.75785885); oParser = new parserFormula("FORECAST.ETS(A69,B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 4250095.33429725); oParser = new parserFormula("FORECAST.ETS(A70,B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 4360538.1411926); oParser = new parserFormula("FORECAST.ETS(A71,B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 4463640.2710391); oParser = new parserFormula("FORECAST.ETS(A72,B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 3963675.88150212); oParser = new parserFormula("FORECAST.ETS(A73,B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 4028087.58056954); oParser = new parserFormula("FORECAST.ETS(A74,B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 3719789.0814973); oParser = new parserFormula("FORECAST.ETS(A75,B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 3779079.73583193); oParser = new parserFormula("FORECAST.ETS(A76,B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 3557109.53306228); oParser = new parserFormula("FORECAST.ETS(A77,B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 3312286.56874774); oParser = new parserFormula("FORECAST.ETS(A78,B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 3863667.66453383); oParser = new parserFormula("FORECAST.ETS(A79,B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 3907134.58377009); oParser = new parserFormula("FORECAST.ETS(A80,B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 4201599.84119218); oParser = new parserFormula("FORECAST.ETS(A81,B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 4409683.41763059); oParser = new parserFormula("FORECAST.ETS(A82,B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 4520126.22452593); oParser = new parserFormula("FORECAST.ETS(A83,B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 4623228.35437243); oParser = new parserFormula("FORECAST.ETS(A84,B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 4123263.96483545); let sheetName = ws.getName(); ws.getRange2("A100:A102").setValue(""); ws.getRange2("B100").setValue("1"); ws.getRange2("B101").setValue("2"); ws.getRange2("B102").setValue("3"); ws.getRange2("C100").setValue("1"); ws.getRange2("C101").setValue("2"); ws.getRange2("C102").setValue("3"); ws.getRange2("D100").setValue("123"); ws.getRange2("D101").setValue("123s"); oParser = new parserFormula("FORECAST.ETS(B100:B102,B100:B102,B100:B102)", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:F106").bbox); assert.ok(oParser.parse(), "FORECAST.ETS(B100:B102,B100:B102,B100:B102)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of FORECAST.ETS(B100:B102,B100:B102,B100:B102)[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, "Result of FORECAST.ETS(B100:B102,B100:B102,B100:B102)[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 3, "Result of FORECAST.ETS(B100:B102,B100:B102,B100:B102)[2,0]"); oParser = new parserFormula("FORECAST.ETS("+sheetName+"!B100:B102,B100:B102,B100:B102)", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:F106").bbox); assert.ok(oParser.parse(), "FORECAST.ETS("+sheetName+"!B100:B102,B100:B102,B100:B102)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of FORECAST.ETS("+sheetName+"!B100:B102,B100:B102,B100:B102)[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, "Result of FORECAST.ETS("+sheetName+"!B100:B102,B100:B102,B100:B102)[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 3, "Result of FORECAST.ETS("+sheetName+"!B100:B102,B100:B102,B100:B102)[2,0]"); oParser = new parserFormula("FORECAST.ETS({1,2,3},B100:B102,B100:B102)", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:F106").bbox); assert.ok(oParser.parse(), "FORECAST.ETS({1,2,3},B100:B102,B100:B102)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of FORECAST.ETS({1,2,3},B100:B102,B100:B102)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, "Result of FORECAST.ETS({1,2,3},B100:B102,B100:B102)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 3, "Result of FORECAST.ETS({1,2,3},B100:B102,B100:B102)[0,2]"); oParser = new parserFormula("FORECAST.ETS({1;2;3},B100:B102,B100:B102)", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:F106").bbox); assert.ok(oParser.parse(), "FORECAST.ETS({1;2;3},B100:B102,B100:B102)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of FORECAST.ETS({1;2;3},B100:B102,B100:B102)[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, "Result of FORECAST.ETS({1;2;3},B100:B102,B100:B102)[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 3, "Result of FORECAST.ETS({1;2;3},B100:B102,B100:B102)[2,0]"); oParser = new parserFormula("FORECAST.ETS(123,{1;2;3},B100:B102)", "A1", ws); assert.ok(oParser.parse(), "FORECAST.ETS(123,{1;2;3},B100:B102)"); assert.strictEqual(oParser.calculate().getValue(), 123, "Result of FORECAST.ETS(123,{1;2;3},B100:B102)"); oParser = new parserFormula("FORECAST.ETS(123,{1;2;3},{1;2;3})", "A1", ws); assert.ok(oParser.parse(), "FORECAST.ETS(123,{1;2;3},{1;2;3})"); assert.strictEqual(oParser.calculate().getValue(), 123, "Result of FORECAST.ETS(123,{1;2;3},{1;2;3})"); oParser = new parserFormula("FORECAST.ETS(123,A100:A102,A100:A102)", "A1", ws); assert.ok(oParser.parse(), "FORECAST.ETS(123,A100:A102,A100:A102) - empty array in 2 and 3 arguments"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of FORECAST.ETS(123,A100:A102,A100:A102) - empty array in 2 and 3 arguments"); oParser = new parserFormula("FORECAST.ETS(123,A100:A102,B100:B102)", "A1", ws); assert.ok(oParser.parse(), "FORECAST.ETS(123,A100:A102,B100:B102) - empty array in 2 argument"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of FORECAST.ETS(123,A100:A102,B100:B102) - empty array in 2 argument"); oParser = new parserFormula("FORECAST.ETS(123,B100:B102,A100:A102)", "A1", ws); assert.ok(oParser.parse(), "FORECAST.ETS(123,B100:B102,A100:A102) - empty array in 3 argument"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of FORECAST.ETS(123,B100:B102,A100:A102) - empty array in 3 argument"); // in the editor returns #N/A oParser = new parserFormula("FORECAST.ETS(123,B100:B102,C100:C102)", "A1", ws); assert.ok(oParser.parse(), "FORECAST.ETS(123,B100:B102,C100:C102)"); assert.strictEqual(oParser.calculate().getValue(), 123, "Result of FORECAST.ETS(123,B100:B102,C100:C102)"); // base type checks oParser = new parserFormula('FORECAST.ETS("123",B100:B102,C100:C102)', "A1", ws); assert.ok(oParser.parse(), 'FORECAST.ETS("123",B100:B102,C100:C102)'); assert.strictEqual(oParser.calculate().getValue(), 123, 'Result of FORECAST.ETS("123",B100:B102,C100:C102)'); oParser = new parserFormula('FORECAST.ETS(D100,B100:B102,C100:C102)', "A1", ws); assert.ok(oParser.parse(), 'FORECAST.ETS(D100,B100:B102,C100:C102)'); assert.strictEqual(oParser.calculate().getValue(), 123, 'Result of FORECAST.ETS(D100,B100:B102,C100:C102)'); oParser = new parserFormula('FORECAST.ETS("123s",B100:B102,C100:C102)', "A1", ws); assert.ok(oParser.parse(), 'FORECAST.ETS("123s",B100:B102,C100:C102)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of FORECAST.ETS("123s",B100:B102,C100:C102)'); oParser = new parserFormula('FORECAST.ETS(D101,B100:B102,C100:C102)', "A1", ws); assert.ok(oParser.parse(), 'FORECAST.ETS(D101,B100:B102,C100:C102)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of FORECAST.ETS(D101,B100:B102,C100:C102)'); oParser = new parserFormula("FORECAST.ETS(#N/A,B100:B102,C100:C102)", "A1", ws); assert.ok(oParser.parse(), "FORECAST.ETS(#N/A,B100:B102,C100:C102)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of FORECAST.ETS(#N/A,B100:B102,C100:C102)"); oParser = new parserFormula("FORECAST.ETS(123,#N/A,C100:C102)", "A1", ws); assert.ok(oParser.parse(), "FORECAST.ETS(123,#N/A,C100:C102)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of FORECAST.ETS(123,#N/A,C100:C102)"); oParser = new parserFormula("FORECAST.ETS(123,B100:B102,#N/A)", "A1", ws); assert.ok(oParser.parse(), "FORECAST.ETS(123,B100:B102,#N/A)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of FORECAST.ETS(123,B100:B102,#N/A)"); oParser = new parserFormula("FORECAST.ETS(#N/A,#NUM!,C100:C102)", "A1", ws); assert.ok(oParser.parse(), "FORECAST.ETS(#N/A,#NUM!,C100:C102)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of FORECAST.ETS(#N/A,#NUM!,C100:C102)"); }); QUnit.test("Test: \"FORECAST.ETS.CONFINT\"", function (assert) { putDataForForecastEts(); ws.getRange2("A100:A102").setValue(""); ws.getRange2("B100").setValue("1"); ws.getRange2("B101").setValue("2"); ws.getRange2("B102").setValue("3"); ws.getRange2("C100").setValue("1"); ws.getRange2("C101").setValue("2"); ws.getRange2("C102").setValue("3"); ws.getRange2("D100").setValue("123"); ws.getRange2("D101").setValue("123s"); oParser = new parserFormula("FORECAST.ETS.CONFINT(123,A100:A102,A100:A102)", "A1", ws); assert.ok(oParser.parse(), "FORECAST.ETS.CONFINT(123,A100:A102,A100:A102) - empty array in 2 and 3 arguments"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of FORECAST.ETS.CONFINT(123,A100:A102,A100:A102) - empty array in 2 and 3 arguments"); // #DIV/0! oParser = new parserFormula("FORECAST.ETS.CONFINT(123,A100:A102,B100:B102)", "A1", ws); assert.ok(oParser.parse(), "FORECAST.ETS.CONFINT(123,A100:A102,B100:B102) - empty array in 2 argument"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of FORECAST.ETS.CONFINT(123,A100:A102,B100:B102) - empty array in 2 argument"); // #DIV/0! oParser = new parserFormula("FORECAST.ETS.CONFINT(123,B100:B102,A100:A102)", "A1", ws); assert.ok(oParser.parse(), "FORECAST.ETS.CONFINT(123,B100:B102,A100:A102) - empty array in 3 argument"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of FORECAST.ETS.CONFINT(123,B100:B102,A100:A102) - empty array in 3 argument"); // #DIV/0! oParser = new parserFormula("FORECAST.ETS.CONFINT(B100:B102,B100:B102,B100:B102)", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:F106").bbox); assert.ok(oParser.parse(), "FORECAST.ETS.CONFINT(B100:B102,B100:B102,B100:B102)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#NUM!", "Result of FORECAST.ETS.CONFINT(B100:B102,B100:B102,B100:B102)[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#NUM!", "Result of FORECAST.ETS.CONFINT(B100:B102,B100:B102,B100:B102)[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#NUM!", "Result of FORECAST.ETS.CONFINT(B100:B102,B100:B102,B100:B102)[2,0]"); oParser = new parserFormula("FORECAST.ETS.CONFINT({1;2;3},B100:B102,B100:B102)", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:F106").bbox); assert.ok(oParser.parse(), "FORECAST.ETS.CONFINT({1;2;3},B100:B102,B100:B102)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#NUM!", "Result of FORECAST.ETS.CONFINT({1;2;3},B100:B102,B100:B102)[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#NUM!", "Result of FORECAST.ETS.CONFINT({1;2;3},B100:B102,B100:B102)[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#NUM!", "Result of FORECAST.ETS.CONFINT({1;2;3},B100:B102,B100:B102)[2,0]"); // base type checks oParser = new parserFormula("FORECAST.ETS.CONFINT(123,B100:B102,C100:C102)", "A1", ws); assert.ok(oParser.parse(), "FORECAST.ETS.CONFINT(123,B100:B102,C100:C102)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of FORECAST.ETS.CONFINT(123,B100:B102,C100:C102)"); // 0 oParser = new parserFormula("FORECAST.ETS.CONFINT(0,B100:B102,C100:C102)", "A1", ws); assert.ok(oParser.parse(), "FORECAST.ETS.CONFINT(0,B100:B102,C100:C102)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of FORECAST.ETS.CONFINT(0,B100:B102,C100:C102)"); oParser = new parserFormula("FORECAST.ETS.CONFINT(-1,B100:B102,C100:C102)", "A1", ws); assert.ok(oParser.parse(), "FORECAST.ETS.CONFINT(-1,B100:B102,C100:C102)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of FORECAST.ETS.CONFINT(-1,B100:B102,C100:C102)"); oParser = new parserFormula('FORECAST.ETS.CONFINT("123s",B100:B102,C100:C102)', "A1", ws); assert.ok(oParser.parse(), 'FORECAST.ETS.CONFINT("123s",B100:B102,C100:C102)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of FORECAST.ETS.CONFINT("123s",B100:B102,C100:C102)'); oParser = new parserFormula('FORECAST.ETS.CONFINT(D101,B100:B102,C100:C102)', "A1", ws); assert.ok(oParser.parse(), 'FORECAST.ETS.CONFINT(D101,B100:B102,C100:C102)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of FORECAST.ETS.CONFINT(D101,B100:B102,C100:C102)'); oParser = new parserFormula('FORECAST.ETS.CONFINT(FALSE,B100:B102,C100:C102)', "A1", ws); assert.ok(oParser.parse(), 'FORECAST.ETS.CONFINT(FALSE,B100:B102,C100:C102)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of FORECAST.ETS.CONFINT(FALSE,B100:B102,C100:C102)'); oParser = new parserFormula('FORECAST.ETS.CONFINT(TRUE,B100:B102,C100:C102)', "A1", ws); assert.ok(oParser.parse(), 'FORECAST.ETS.CONFINT(TRUE,B100:B102,C100:C102)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of FORECAST.ETS.CONFINT(TRUE,B100:B102,C100:C102)'); oParser = new parserFormula('FORECAST.ETS.CONFINT(#N/A,B100:B102,C100:C102)', "A1", ws); assert.ok(oParser.parse(), 'FORECAST.ETS.CONFINT(#N/A,B100:B102,C100:C102)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of FORECAST.ETS.CONFINT(#N/A,B100:B102,C100:C102)'); }); QUnit.test("Test: \"FORECAST.ETS.SEASONALITY\"", function (assert) { //результаты данного теста соответсвуют результатам LO, но отличаются от MS!!! putDataForForecastEts(); oParser = new parserFormula("FORECAST.ETS.SEASONALITY(B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 12); }); QUnit.test("Test: \"FORECAST.ETS.STAT\"", function (assert) { //результаты данного теста соответсвуют результатам LO, но отличаются от MS!!! putDataForForecastEts(); oParser = new parserFormula("FORECAST.ETS.STAT(B4:B60,A4:A60,1,1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 0.65234375); }); QUnit.test("Test: \"FORECAST.LINEAR\"", function (assert) { oParser = new parserFormula("FORECAST(30,{6,7,9,15,21},{20,28,31,38,40})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(13) - 0, 10.6072530864198); }); QUnit.test("FORMULATEXT", function (assert) { wb.dependencyFormulas.unlockRecal(); ws.getRange2("S101").setValue("=TODAY()"); ws.getRange2("S102").setValue(""); ws.getRange2("S103").setValue("=1+1"); oParser = new parserFormula("FORMULATEXT(S101)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "=TODAY()"); oParser = new parserFormula("FORMULATEXT(S101:S102)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "=TODAY()"); oParser = new parserFormula("FORMULATEXT(S102)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); oParser = new parserFormula("FORMULATEXT(S100:105)", "A1", ws); assert.ok(oParser.parse()); //"#N/A" - в ms excel assert.strictEqual(oParser.calculate().getValue(), newFormulaParser ? "#N/A" : "#VALUE!"); oParser = new parserFormula("FORMULATEXT(S103)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "=1+1"); oParser = new parserFormula("FORMULATEXT(#REF!)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#REF!"); wb.dependencyFormulas.lockRecal(); testArrayFormulaEqualsValues(assert, "#N/A,#N/A,#N/A,#N/A;#N/A,#N/A,#N/A,#N/A;#N/A,#N/A,#N/A,#N/A", "FORMULATEXT(A1:C2)"); }); QUnit.test("Test: \"FREQUENCY\"", function (assert) { ws.getRange2("A202").setValue("79"); ws.getRange2("A203").setValue("85"); ws.getRange2("A204").setValue("78"); ws.getRange2("A205").setValue("85"); ws.getRange2("A206").setValue("50"); ws.getRange2("A207").setValue("81"); ws.getRange2("A208").setValue("95"); ws.getRange2("A209").setValue("88"); ws.getRange2("A210").setValue("97"); ws.getRange2("B202").setValue("70"); ws.getRange2("B203").setValue("89"); ws.getRange2("B204").setValue("79"); ws.getRange2("C202").setValue("234"); ws.getRange2("C203").setValue("4"); var a; oParser = new parserFormula("FREQUENCY(A202:A210,B202:B204)", "A201", ws); assert.ok(oParser.parse()); a = oParser.calculate(); assert.strictEqual(a.getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(a.getElementRowCol(1, 0).getValue(), 2); assert.strictEqual(a.getElementRowCol(2, 0).getValue(), 4); assert.strictEqual(a.getElementRowCol(3, 0).getValue(), 2); oParser = new parserFormula("FREQUENCY(A202:C202,A203:C203)", "A201", ws); assert.ok(oParser.parse()); a = oParser.calculate(); assert.strictEqual(a.getElementRowCol(0, 0).getValue(), 0); assert.strictEqual(a.getElementRowCol(1, 0).getValue(), 2); assert.strictEqual(a.getElementRowCol(2, 0).getValue(), 0); assert.strictEqual(a.getElementRowCol(3, 0).getValue(), 1); }); QUnit.test("Test: \"GAMMALN\"", function (assert) { oParser = new parserFormula("GAMMALN(4.5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(14) - 0, 2.45373657084244); oParser = new parserFormula("GAMMALN(-4.5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); testArrayFormula(assert, "GAMMALN"); }); QUnit.test("Test: \"GAMMALN.PRECISE\"", function (assert) { oParser = new parserFormula("GAMMALN.PRECISE(4)", "A1", ws); assert.ok(oParser.parse(), "GAMMALN.PRECISE(4)"); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 1.7917595, "GAMMALN.PRECISE(4)"); oParser = new parserFormula("GAMMALN.PRECISE(-4.5)", "A1", ws); assert.ok(oParser.parse(), "GAMMALN.PRECISE(-4.5)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "GAMMALN.PRECISE(-4.5)"); testArrayFormula2(assert, "GAMMALN.PRECISE", 1, 1); }); QUnit.test("Test: \"GEOMEAN\"", function (assert) { function geommean(x) { var s1 = 0, _x = 1, xLength = 0, _tx; for (var i = 0; i < x.length; i++) { _x *= x[i]; } return Math.pow(_x, 1 / x.length) } oParser = new parserFormula("GEOMEAN(10.5,5.3,2.9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), geommean([10.5, 5.3, 2.9])); oParser = new parserFormula("GEOMEAN(10.5,{5.3,2.9},\"12\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), geommean([10.5, 5.3, 2.9, 12])); oParser = new parserFormula("GEOMEAN(10.5,{5.3,2.9},\"12\",0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); }); QUnit.test("Test: \"HARMEAN\"", function (assert) { function harmmean(x) { var _x = 0, xLength = 0; for (var i = 0; i < x.length; i++) { _x += 1 / x[i]; xLength++; } return xLength / _x; } oParser = new parserFormula("HARMEAN(10.5,5.3,2.9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), harmmean([10.5, 5.3, 2.9])); oParser = new parserFormula("HARMEAN(10.5,{5.3,2.9},\"12\")", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), harmmean([10.5, 5.3, 2.9, 12])); oParser = new parserFormula("HARMEAN(10.5,{5.3,2.9},\"12\",0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); testArrayFormula2(assert, "HARMEAN", 1, 8, null, true); }); QUnit.test("Test: \"HYPGEOMDIST\"", function (assert) { function hypgeomdist(x, n, M, N) { return toFixed(Math.binomCoeff(M, x) * Math.binomCoeff(N - M, n - x) / Math.binomCoeff(N, n)); } oParser = new parserFormula("HYPGEOMDIST(1,4,8,20)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), hypgeomdist(1, 4, 8, 20)); oParser = new parserFormula("HYPGEOMDIST(1,4,8,20)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), hypgeomdist(1, 4, 8, 20)); oParser = new parserFormula("HYPGEOMDIST(-1,4,8,20)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("HYPGEOMDIST(5,4,8,20)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); testArrayFormula2(assert, "HYPGEOMDIST", 4, 4); }); QUnit.test("Test: \"HYPGEOM.DIST\"", function (assert) { oParser = new parserFormula("HYPGEOM.DIST(1,4,8,20,TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(4) - 0, 0.4654); oParser = new parserFormula("HYPGEOM.DIST(1,4,8,20,FALSE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(4) - 0, 0.3633); oParser = new parserFormula("HYPGEOM.DIST(2,2,3,40,0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 0.003846154); oParser = new parserFormula("HYPGEOM.DIST(2,3,3,40,5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 0.999898785); oParser = new parserFormula("HYPGEOM.DIST(1,2,3,4,5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 0.5); testArrayFormula2(assert, "HYPGEOM.DIST", 5, 5); }); QUnit.test("Test: \"HYPLINK\"", function (assert) { ws.getRange2("D101").setValue(""); ws.getRange2("D102").setValue("123"); oParser = new parserFormula('HYPERLINK("http://example.microsoft.com/report/budget report.xlsx", "Click for report")', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "Click for report"); assert.strictEqual(oParser.value.hyperlink, "http://example.microsoft.com/report/budget report.xlsx"); oParser = new parserFormula('HYPERLINK("[http://example.microsoft.com/report/budget report.xlsx]Annual!F10", D1)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 0); assert.strictEqual(oParser.value.hyperlink, "[http://example.microsoft.com/report/budget report.xlsx]Annual!F10"); oParser = new parserFormula('HYPERLINK("http://example.microsoft.com/Annual Report.docx]QrtlyProfits", "Quarterly Profit Report")', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "Quarterly Profit Report"); assert.strictEqual(oParser.value.hyperlink, 'http://example.microsoft.com/Annual Report.docx]QrtlyProfits'); oParser = new parserFormula('HYPERLINK("\\FINANCE\\Statements\\1stqtr.xlsx",D101)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue() - 0, 0); assert.strictEqual(oParser.value.hyperlink, '\\FINANCE\\Statements\\1stqtr.xlsx'); oParser = new parserFormula('HYPERLINK("http://test.com")', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "http://test.com"); assert.strictEqual(oParser.value.hyperlink, "http://test.com"); oParser = new parserFormula('HYPERLINK(D101,111)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 111); assert.strictEqual(oParser.value.hyperlink - 0, 0); oParser = new parserFormula('HYPERLINK(D102,111)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 111); assert.strictEqual(oParser.value.hyperlink, "123"); oParser = new parserFormula('HYPERLINK(D102)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "123"); assert.strictEqual(oParser.value.hyperlink - 0, 123); oParser = new parserFormula('HYPERLINK(D101,TRUE)', "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TRUE"); assert.strictEqual(oParser.value.hyperlink - 0, 0); }); QUnit.test("Test: \"HOUR\"", function (assert) { ws.getRange2("A202").setValue("0.75"); ws.getRange2("A203").setValue("7/18/2011 7:45"); ws.getRange2("A204").setValue("4/21/2012"); oParser = new parserFormula("HOUR(A202)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 18); oParser = new parserFormula("HOUR(A203)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 7); oParser = new parserFormula("HOUR(A204)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); testArrayFormula2(assert, "HOUR", 1, 1); }); QUnit.test("Test: \"INTERCEPT\"", function (assert) { function intercept(y, x) { var fSumDeltaXDeltaY = 0, fSumSqrDeltaX = 0, _x = 0, _y = 0, xLength = 0; for (var i = 0; i < x.length; i++) { _x += x[i]; _y += y[i]; xLength++; } _x /= xLength; _y /= xLength; for (var i = 0; i < x.length; i++) { var fValX = x[i]; var fValY = y[i]; fSumDeltaXDeltaY += (fValX - _x) * (fValY - _y); fSumSqrDeltaX += (fValX - _x) * (fValX - _x); } return toFixed(_y - fSumDeltaXDeltaY / fSumSqrDeltaX * _x); } oParser = new parserFormula("INTERCEPT({6,7,9,15,21},{20,28,31,38,40})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), intercept([6, 7, 9, 15, 21], [20, 28, 31, 38, 40])); testArrayFormula2(assert, "INTERCEPT", 2, 2, null, true); }); QUnit.test("Test: \"INT\"", function (assert) { ws.getRange2("A202").setValue("19.5"); oParser = new parserFormula("INT(8.9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 8); oParser = new parserFormula("INT(-8.9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -9); oParser = new parserFormula("A202-INT(A202)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0.5); testArrayFormula(assert, "INT"); }); QUnit.test("Test: \"KURT\"", function (assert) { function kurt(x) { var sumSQRDeltaX = 0, _x = 0, xLength = 0, standDev = 0, sumSQRDeltaXDivstandDev = 0; for (var i = 0; i < x.length; i++) { _x += x[i]; xLength++; } _x /= xLength; for (var i = 0; i < x.length; i++) { sumSQRDeltaX += Math.pow(x[i] - _x, 2); } standDev = Math.sqrt(sumSQRDeltaX / (xLength - 1)); for (var i = 0; i < x.length; i++) { sumSQRDeltaXDivstandDev += Math.pow((x[i] - _x) / standDev, 4); } return toFixed(xLength * (xLength + 1) / (xLength - 1) / (xLength - 2) / (xLength - 3) * sumSQRDeltaXDivstandDev - 3 * (xLength - 1) * (xLength - 1) / (xLength - 2) / (xLength - 3)) } oParser = new parserFormula("KURT(10.5,12.4,19.4,23.2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), kurt([10.5, 12.4, 19.4, 23.2])); oParser = new parserFormula("KURT(10.5,{12.4,19.4},23.2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), kurt([10.5, 12.4, 19.4, 23.2])); oParser = new parserFormula("KURT(10.5,12.4,19.4)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); testArrayFormula2(assert, "KURT", 1, 8, null, true); }); QUnit.test("Test: \"LARGE\"", function (assert) { oParser = new parserFormula("LARGE({3,5,3,5,4;4,2,4,6,7},3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5); oParser = new parserFormula("LARGE({3,5,3,5,4;4,2,4,6,7},7)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); //TODO нужна другая функция для тестирования //testArrayFormula2(assert, "LARGE", 2, 2) }); QUnit.test("Test: \"LN\"", function (assert) { oParser = new parserFormula("LN(86)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 4.4543473); oParser = new parserFormula("LN(2.7182818)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(1) - 0, 1); oParser = new parserFormula("LN(EXP(3))", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); testArrayFormula(assert, "LN"); }); QUnit.test("Test: \"LOG10\"", function (assert) { oParser = new parserFormula("LOG10(86)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(4) - 0, 1.9345); oParser = new parserFormula("LOG10(10)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("LOG10(100000)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5); oParser = new parserFormula("LOG10(10^5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5); testArrayFormula(assert, "LOG10"); }); QUnit.test("Test: \"LINEST\"", function (assert) { let array; ws.getRange2("A202").setValue("1"); ws.getRange2("A203").setValue("2"); ws.getRange2("A204").setValue("3"); ws.getRange2("B202").setValue("2"); ws.getRange2("B203").setValue("3"); ws.getRange2("B204").setValue("4"); oParser = new parserFormula("LINEST(A202:B204)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 0.54285714); oParser = new parserFormula("LINEST(A202:B204, A202:B204)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); oParser = new parserFormula("LINEST(A202:B204, A202:B204, 1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); oParser = new parserFormula("LINEST(A202:B204, A202:B204, 1, 1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); ws.getRange2("A202").setValue("1"); ws.getRange2("A203").setValue("9"); ws.getRange2("A204").setValue("5"); ws.getRange2("A205").setValue("7"); ws.getRange2("B202").setValue("0"); ws.getRange2("B203").setValue("4"); ws.getRange2("B204").setValue("2"); ws.getRange2("B205").setValue("3"); oParser = new parserFormula("LINEST(A202:A205,B202:B205,,FALSE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 2); oParser = new parserFormula("LINEST(A202:A205,B202:B205,FALSE,FALSE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 2.31034483); oParser = new parserFormula("LINEST(A202:A205,B202:B205,FALSE,TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 2.31034483); ws.getRange2("A102").setValue("1"); ws.getRange2("A103").setValue("9"); ws.getRange2("A104").setValue("5"); ws.getRange2("A105").setValue("7"); ws.getRange2("B102").setValue("0"); ws.getRange2("B103").setValue("4"); ws.getRange2("B104").setValue("2"); ws.getRange2("B105").setValue("3"); oParser = new parserFormula("LINEST(A102:A105,B102:B105,,FALSE)", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:F106").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1); } ws.getRange2("A102").setValue("2310"); ws.getRange2("A103").setValue("2333"); ws.getRange2("A104").setValue("2356"); ws.getRange2("A105").setValue("2379"); ws.getRange2("A106").setValue("2402"); ws.getRange2("A107").setValue("2425"); ws.getRange2("A108").setValue("2448"); ws.getRange2("A109").setValue("2471"); ws.getRange2("A110").setValue("2494"); ws.getRange2("A111").setValue("2517"); ws.getRange2("A112").setValue("2540"); ws.getRange2('B102').setValue('2'); ws.getRange2('B103').setValue('2'); ws.getRange2('B104').setValue('3'); ws.getRange2('B105').setValue('3'); ws.getRange2('B106').setValue('2'); ws.getRange2('B107').setValue('4'); ws.getRange2('B108').setValue('2'); ws.getRange2('B109').setValue('2'); ws.getRange2('B110').setValue('3'); ws.getRange2('B111').setValue('4'); ws.getRange2('B112').setValue('2'); ws.getRange2('C102').setValue('2'); ws.getRange2('C103').setValue('2'); ws.getRange2('C104').setValue('1.5'); ws.getRange2('C105').setValue('2'); ws.getRange2('C106').setValue('3'); ws.getRange2('C107').setValue('2'); ws.getRange2('C108').setValue('1.5'); ws.getRange2('C109').setValue('2'); ws.getRange2('C110').setValue('3'); ws.getRange2('C111').setValue('4'); ws.getRange2('C112').setValue('3'); ws.getRange2('D102').setValue('20'); ws.getRange2('D103').setValue('12'); ws.getRange2('D104').setValue('33'); ws.getRange2('D105').setValue('43'); ws.getRange2('D106').setValue('53'); ws.getRange2('D107').setValue('23'); ws.getRange2('D108').setValue('99'); ws.getRange2('D109').setValue('34'); ws.getRange2('D110').setValue('23'); ws.getRange2('D111').setValue('55'); ws.getRange2('D112').setValue('22'); ws.getRange2('E102').setValue('142000'); ws.getRange2('E103').setValue('144000'); ws.getRange2('E104').setValue('151000'); ws.getRange2('E105').setValue('150000'); ws.getRange2('E106').setValue('139000'); ws.getRange2('E107').setValue('169000'); ws.getRange2('E108').setValue('126000'); ws.getRange2('E109').setValue('142900'); ws.getRange2('E110').setValue('163000'); ws.getRange2('E111').setValue('169000'); ws.getRange2('E112').setValue('149000'); oParser = new parserFormula("LINEST(E102:E112,A102:D112,TRUE,TRUE)", "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("E120:E123").bbox); assert.ok(oParser.parse()); array = oParser.calculate(); // if (AscCommonExcel.cElementType.array === array.type) { // assert.strictEqual(array.getElementRowCol(0, 0).getValue().toFixed(7) - 0, -234.2371645); // assert.strictEqual(array.getElementRowCol(1, 0).getValue().toFixed(8) - 0, 13.26801148); // assert.strictEqual(array.getElementRowCol(2, 0).getValue().toFixed(9) - 0, 0.996747993); // assert.strictEqual(array.getElementRowCol(3, 0).getValue().toFixed(7) - 0, 459.7536742); // } ws.getRange2("A120").setValue("1"); ws.getRange2("B120").setValue("2"); oParser = new parserFormula("LINEST(A120:B120)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1); oParser = new parserFormula("LINEST({1;2})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1); oParser = new parserFormula("LINEST({1,2})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1); // for bug 65316 ws.getRange2("A150").setValue("1"); ws.getRange2("B150").setValue("2"); ws.getRange2("C150").setValue("3"); ws.getRange2("D150").setValue("4"); ws.getRange2("E150").setValue("5"); ws.getRange2("A151").setValue("5.3"); ws.getRange2("B151").setValue("6.3"); ws.getRange2("C151").setValue("4.8"); ws.getRange2("D151").setValue("3.8"); ws.getRange2("E151").setValue("3.3"); oParser = new parserFormula("LINEST(A151:E151,A150:E150)", "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:F106").bbox); assert.ok(oParser.parse(), "LINEST(A151:E151,A150:E150)"); array = oParser.calculate(); assert.ok(1, "LINEST(A151:E151,A150:E150) => y = -0.65x + 6.65"); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), -0.65, "Result of LINEST(A151:E151,A150:E150) [0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 6.65, "Result of LINEST(A151:E151,A150:E150) [0,1]"); oParser = new parserFormula("LINEST(A151:E151,A150:E150^{1;2;3})", "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:F106").bbox); assert.ok(oParser.parse(), "LINEST(A151:E151,A150:E150^{1;2;3})"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue().toFixed(2), "0.25", "Result of LINEST(A151:E151,A150:E150)^{1;2;3} [0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue().toFixed(2), "-2.43", "Result of LINEST(A151:E151,A150:E150)^{1;2;3} [0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue().toFixed(2), "6.32", "Result of LINEST(A151:E151,A150:E150)^{1;2;3} [0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue().toFixed(1), "1.2", "Result of LINEST(A151:E151,A150:E150)^{1;2;3} [0,3]"); oParser = new parserFormula("LINEST(A151:E151,A150:E150^{1,2,3})", "A2", ws); assert.ok(oParser.parse(), "LINEST(A151:E151,A150:E150^{1,2,3})"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of LINEST(A151:E151,A150:E150)^{1,2,3}"); oParser = new parserFormula("LINEST(A151:E151,{1;2;3;4;5})", "A2", ws); assert.ok(oParser.parse(), "LINEST(A151:E151,{1;2;3;4;5})"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of LINEST(A151:E151,{1;2;3;4;5})"); oParser = new parserFormula("LINEST(A151:E151,{1,2,3,4,5})", "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:F106").bbox); assert.ok(oParser.parse(), "LINEST(A151:E151,{1,2,3,4,5})"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), -0.65, "Result of LINEST(A151:E151,{1,2,3,4,5}) [0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 6.65, "Result of LINEST(A151:E151,{1,2,3,4,5}) [0,1]"); oParser = new parserFormula('LINEST(A151:E151,{"1",2,3,4,5})', "A2", ws); assert.ok(oParser.parse(), 'LINEST(A151:E151,{"1",2,3,4,5})'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of LINEST(A151:E151,{"1",2,3,4,5})'); oParser = new parserFormula('LINEST(A151:E151,{#N/A,2,3,4,5})', "A2", ws); assert.ok(oParser.parse(), 'LINEST(A151:E151,{#N/A,2,3,4,5})'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of LINEST(A151:E151,{#N/A,2,3,4,5})'); oParser = new parserFormula('LINEST(A151:E151,{"string",2,3,4,5})', "A2", ws); assert.ok(oParser.parse(), 'LINEST(A151:E151,{"string",2,3,4,5})'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of LINEST(A151:E151,{"string",2,3,4,5})'); oParser = new parserFormula('LINEST(A151:E151,{TRUE,2,3,4,5})', "A2", ws); assert.ok(oParser.parse(), 'LINEST(A151:E151,{TRUE,2,3,4,5})'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of LINEST(A151:E151,{TRUE,2,3,4,5})'); oParser = new parserFormula("LINEST({5.3,6.3,4.8,3.8,3.3},A150:E150)", "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:F106").bbox); assert.ok(oParser.parse(), "LINEST({5.3,6.3,4.8,3.8,3.3},A150:E150)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), -0.65, "Result of LINEST({5.3,6.3,4.8,3.8,3.3},A150:E150) [0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 6.65, "Result of LINEST({5.3,6.3,4.8,3.8,3.3},A150:E150) [0,1]"); oParser = new parserFormula('LINEST({"5.3",6.3,4.8,3.8,3.3},A150:E150)', "A2", ws); assert.ok(oParser.parse(), 'LINEST({"5.3",6.3,4.8,3.8,3.3},A150:E150)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of LINEST({"5.3",6.3,4.8,3.8,3.3},A150:E150)'); oParser = new parserFormula('LINEST({#N/A,6.3,4.8,3.8,3.3},A150:E150)', "A2", ws); assert.ok(oParser.parse(), 'LINEST({#N/A,6.3,4.8,3.8,3.3},A150:E150)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of LINEST({#N/A,6.3,4.8,3.8,3.3},A150:E150)'); oParser = new parserFormula('LINEST({"string",6.3,4.8,3.8,3.3},A150:E150)', "A2", ws); assert.ok(oParser.parse(), 'LINEST({"string",6.3,4.8,3.8,3.3},A150:E150)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of LINEST({"string",6.3,4.8,3.8,3.3},A150:E150)'); oParser = new parserFormula('LINEST({TRUE,6.3,4.8,3.8,3.3},A150:E150)', "A2", ws); assert.ok(oParser.parse(), 'LINEST({TRUE,6.3,4.8,3.8,3.3},A150:E150)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of LINEST({TRUE,6.3,4.8,3.8,3.3},A150:E150)'); ws.getRange2("A200").setValue("1"); ws.getRange2("A201").setValue("2"); ws.getRange2("A202").setValue("3"); ws.getRange2("B200").setValue("1"); ws.getRange2("B201").setValue("2"); ws.getRange2("B202").setValue("3"); ws.getRange2("C200").setValue("1"); ws.getRange2("C201").setValue("2"); ws.getRange2("C202").setValue("3"); // different matrix length tests oParser = new parserFormula("LINEST(A200:A201,A200:C200)", "A2", ws); assert.ok(oParser.parse(), "LINEST(A200:A201,A200:C200)"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of LINEST(A200:A201,A200:C200)"); oParser = new parserFormula("LINEST(A200:A202,A200:C200)", "A2", ws); assert.ok(oParser.parse(), "LINEST(A200:A202,A200:C200)"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of LINEST(A200:A202,A200:C200)"); oParser = new parserFormula("LINEST(A200:B201,A200:C201)", "A2", ws); assert.ok(oParser.parse(), "LINEST(A200:B201,A200:C201)"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of LINEST(A200:B201,A200:C201)"); oParser = new parserFormula("LINEST({1,2,3},{1,2})", "A2", ws); assert.ok(oParser.parse(), "LINEST({1,2,3},{1,2})"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of LINEST({1,2,3},{1,2})"); oParser = new parserFormula("LINEST({1,2,3},{1,2,3,4})", "A2", ws); assert.ok(oParser.parse(), "LINEST({1,2,3},{1,2,3,4})"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of LINEST({1,2,3},{1,2,3,4})"); oParser = new parserFormula("LINEST({1,2;1,2},{1,2})", "A2", ws); assert.ok(oParser.parse(), "LINEST({1,2;1,2},{1,2})"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of LINEST({1,2;1,2},{1,2})"); oParser = new parserFormula("LINEST(A200:B200,{1,2})", "A2", ws); assert.ok(oParser.parse(), "LINEST(A200:B200,{1,2})"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 0, "Result of LINEST(A200:B200,{1,2})[0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue(), 1, "Result of LINEST(A200:B200,{1,2})[0,1]"); }); QUnit.test("Test: \"MEDIAN\"", function (assert) { function median(x) { x.sort(fSortAscending); if (x.length % 2) { return x[(x.length - 1) / 2]; } else { return (x[x.length / 2 - 1] + x[x.length / 2]) / 2; } } oParser = new parserFormula("MEDIAN(10.5,12.4,19.4,23.2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), median([10.5, 12.4, 19.4, 23.2])); oParser = new parserFormula("MEDIAN(10.5,{12.4,19.4},23.2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), median([10.5, 12.4, 19.4, 23.2])); oParser = new parserFormula("MEDIAN(-3.5,1.4,6.9,-4.5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), median([-3.5, 1.4, 6.9, -4.5])); testArrayFormula2(assert, "MEDIAN", 1, 8, null, true); }); QUnit.test("Test: \"MODE\"", function (assert) { function mode(x) { x.sort(AscCommon.fSortAscending); if (x.length < 1) { return "#VALUE!"; } else { var nMaxIndex = 0, nMax = 1, nCount = 1, nOldVal = x[0], i; for (i = 1; i < x.length; i++) { if (x[i] == nOldVal) { nCount++; } else { nOldVal = x[i]; if (nCount > nMax) { nMax = nCount; nMaxIndex = i - 1; } nCount = 1; } } if (nCount > nMax) { nMax = nCount; nMaxIndex = i - 1; } if (nMax == 1 && nCount == 1) { return "#VALUE!"; } else if (nMax == 1) { return nOldVal; } else { return x[nMaxIndex]; } } } oParser = new parserFormula("MODE(9,1,5,1,9,5,6,6)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), mode([9, 1, 5, 1, 9, 5, 6, 6])); oParser = new parserFormula("MODE(1,9,5,1,9,5,6,6)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), mode([1, 9, 5, 1, 9, 5, 6, 6])); oParser = new parserFormula("MODE(1,9,5,5,9,5,6,6)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), mode([1, 9, 5, 5, 9, 5, 6, 6])); ws.getRange2("G2").setValue("1"); ws.getRange2("G3").setValue("1"); ws.getRange2("G4").setValue("2"); ws.getRange2("G5").setValue("2"); ws.getRange2("G6").setValue("3"); ws.getRange2("G7").setValue("test2"); ws.getRange2("G8").setValue("#N/A"); ws.getRange2("G9").setValue("TRUE"); ws.getRange2("G10").setValue("{1;1;2;2;3}"); oParser = new parserFormula("MODE(G2:G6)", "H1", ws); assert.ok(oParser.parse(), "MODE(G2:G6)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), 1); // number oParser = new parserFormula("MODE(12)", "H1", ws); assert.ok(oParser.parse(), "MODE(12)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result MODE(12)"); oParser = new parserFormula("MODE(-12)", "H1", ws); assert.ok(oParser.parse(), "MODE(-12)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result MODE.MULT(-12)"); oParser = new parserFormula("MODE(0.0000000000002)", "H1", ws); assert.ok(oParser.parse(), "MODE(0.0000000000002)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result MODE(0.0000000000002)"); oParser = new parserFormula("MODE(0.0000000000002, 0.0000000000002, 0.0000000000003)", "H1", ws); assert.ok(oParser.parse(), "MODE(0.0000000000002, 0.0000000000002, 0.0000000000003)"); assert.strictEqual(oParser.calculate().getValue(), 0.0000000000002, "Result MODE(0.0000000000002, 0.0000000000002, 0.0000000000003)"); oParser = new parserFormula("MODE(-0.0000000000002)", "H1", ws); assert.ok(oParser.parse(), "MODE(-0.0000000000002)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result MODE(-0.0000000000002)"); oParser = new parserFormula("MODE(-0.0000000000002, -0.0000000000002, -0.0000000000003)", "H1", ws); assert.ok(oParser.parse(), "MODE(-0.0000000000002, -0.0000000000002, -0.0000000000003)"); assert.strictEqual(oParser.calculate().getValue(), -0.0000000000002, "Result MODE(-0.0000000000002, -0.0000000000002, -0.0000000000003)"); oParser = new parserFormula("MODE(999999999999999999999999999999)", "H1", ws); assert.ok(oParser.parse(), "MODE(999999999999999999999999999999)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result MODE(999999999999999999999999999999)"); oParser = new parserFormula("MODE(-999999999999999999999999999999)", "H1", ws); assert.ok(oParser.parse(), "MODE(-999999999999999999999999999999)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result MODE(-999999999999999999999999999999)"); oParser = new parserFormula("MODE(G6)", "H1", ws); assert.ok(oParser.parse(), "MODE(3)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result MODE(3)"); // string oParser = new parserFormula("MODE(hello)", "H1", ws); assert.ok(oParser.parse(), "MODE(hello)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result MODE('hello')"); oParser = new parserFormula("MODE(G7)", "H1", ws); assert.ok(oParser.parse(), "MODE(test2)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result MODE(test2)"); // bool oParser = new parserFormula("MODE(TRUE)", "H1", ws); assert.ok(oParser.parse(), "MODE(TRUE)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result MODE(TRUE)"); oParser = new parserFormula("MODE(FALSE)", "H1", ws); assert.ok(oParser.parse(), "MODE(FALSE)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result MODE(FALSE)"); oParser = new parserFormula("MODE(G9)", "H1", ws); assert.ok(oParser.parse(), "MODE(TRUE)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result MODE(TRUE)"); // date oParser = new parserFormula("MODE(DATE(2001,1,1),DATE(2003,1,1), DATE(2001,1,1),DATE(2003,1,1))", "H1", ws); assert.ok(oParser.parse(), "MODE(DATE(2001,1,1),DATE(2003,1,1), DATE(2001,1,1),DATE(2003,1,1))"); assert.strictEqual(oParser.calculate().getValue(), 36892, "Result MODE(DATE(2001,1,1),DATE(2003,1,1), DATE(2001,1,1),DATE(2003,1,1))"); // array oParser = new parserFormula("MODE({2;2;3})", "H1", ws); assert.ok(oParser.parse(), "MODE({2;2;3})"); assert.strictEqual(oParser.calculate().getValue(), 2, "Result in MODE({2;2;3})"); oParser = new parserFormula("MODE({1;1;2;2;3})", "H1", ws); assert.ok(oParser.parse(), "MODE({1;1;2;2;3})"); array = oParser.calculate(); assert.strictEqual(array.getValue(), 1, "Result in MODE({1;1;2;2;3})"); oParser = new parserFormula("MODE(G10)", "H1", ws); assert.ok(oParser.parse(), "MODE({1;1;2;2;3})"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result in MODE({1;1;2;2;3})"); oParser = new parserFormula("MODE({TRUE;2;3})", "H1", ws); assert.ok(oParser.parse(), "MODE({TRUE;2;3})"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result in MODE({TRUE;2;3})"); // multiple args oParser = new parserFormula("MODE(12,12,13,13)", "H1", ws); assert.ok(oParser.parse(), "MODE(12,12,13,13)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), 12, "Result in MODE(12,12,13,13)"); oParser = new parserFormula("MODE(1,2,3,4,5,6,7,8,9,10)", "H1", ws); assert.ok(oParser.parse(), "MODE(1,2,3,4,5,6,7,8,9,10)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result MODE(1,2,3,4,5,6,7,8,9,10)"); oParser = new parserFormula("MODE(G6,G6,G5)", "H1", ws); assert.ok(oParser.parse(), "MODE(3,3,2)"); assert.strictEqual(oParser.calculate().getValue(), 3, "Result in [0,0] MODE(3,3,2)"); oParser = new parserFormula("MODE({1,2,3,4,5,6,7,8,9,10},10,10,11,11,11)", "H1", ws); assert.ok(oParser.parse(), "MODE(1,2,3,4,5,6,7,8,9,10)"); assert.strictEqual(oParser.calculate().getValue(), 10, "Result MODE({1,2,3,4,5,6,7,8,9,10},10,10,11,11,11)"); testArrayFormula2(assert, "mode", 1, 8, null, true); }); QUnit.test("Test: \"MODE.MULT \"", function (assert) { ws.getRange2("F202").setValue("1"); ws.getRange2("F203").setValue("2"); ws.getRange2("F204").setValue("3"); ws.getRange2("F205").setValue("4"); ws.getRange2("F206").setValue("3"); ws.getRange2("F207").setValue("2"); ws.getRange2("F208").setValue("1"); ws.getRange2("F209").setValue("2"); ws.getRange2("F210").setValue("3"); ws.getRange2("F211").setValue("5"); ws.getRange2("F212").setValue("6"); ws.getRange2("F213").setValue("1"); ws.getRange2("G2").setValue("1"); ws.getRange2("G3").setValue("1"); ws.getRange2("G4").setValue("2"); ws.getRange2("G5").setValue("2"); ws.getRange2("G6").setValue("3"); ws.getRange2("G7").setValue("test2"); ws.getRange2("G8").setValue("#N/A"); ws.getRange2("G9").setValue("TRUE"); ws.getRange2("G10").setValue("{1;1;2;2;3}"); // base case oParser = new parserFormula("MODE.MULT(F202:F213)", "F1", ws); assert.ok(oParser.parse()); let array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 1); assert.strictEqual(array.getElementRowCol(1,0).getValue(), 2); assert.strictEqual(array.getElementRowCol(2,0).getValue(), 3); // bug case oParser = new parserFormula("MODE.MULT(G2:G6)", "H1:H5", ws); assert.ok(oParser.parse(), "MODE.MULT(G2:G6)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 1); assert.strictEqual(array.getElementRowCol(1,0).getValue(), 2); assert.strictEqual(array.getElementRowCol(2,0).getValue(), ""); // number oParser = new parserFormula("MODE.MULT(12)", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT(12)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result MODE.MULT(12)"); oParser = new parserFormula("MODE.MULT(-12)", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT(-12)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result MODE.MULT(-12)"); oParser = new parserFormula("MODE.MULT(0.0000000000002)", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT(0.0000000000002)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result MODE.MULT(0.0000000000002)"); oParser = new parserFormula("MODE.MULT(0.0000000000002, 0.0000000000002, 0.0000000000003)", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT(0.0000000000002, 0.0000000000002, 0.0000000000003)"); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), 0.0000000000002, "Result MODE.MULT(0.0000000000002, 0.0000000000002, 0.0000000000003)"); oParser = new parserFormula("MODE.MULT(-0.0000000000002)", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT(-0.0000000000002)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result MODE.MULT(-0.0000000000002)"); oParser = new parserFormula("MODE.MULT(-0.0000000000002, -0.0000000000002, -0.0000000000003)", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT(-0.0000000000002, -0.0000000000002, -0.0000000000003)"); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), -0.0000000000002, "Result MODE.MULT(-0.0000000000002, -0.0000000000002, -0.0000000000003)"); oParser = new parserFormula("MODE.MULT(999999999999999999999999999999)", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT(999999999999999999999999999999)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result MODE.MULT(999999999999999999999999999999)"); oParser = new parserFormula("MODE.MULT(-999999999999999999999999999999)", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT(-999999999999999999999999999999)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result MODE.MULT(-999999999999999999999999999999)"); oParser = new parserFormula("MODE.MULT(G6)", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT(3)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result MODE.MULT(3)"); // string oParser = new parserFormula("MODE.MULT(hello)", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT(hello)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result MODE.MULT('hello')"); oParser = new parserFormula("MODE.MULT(G7)", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT(test2)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result MODE.MULT(test2)"); // bool oParser = new parserFormula("MODE.MULT(TRUE)", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT(TRUE)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result MODE.MULT(TRUE)"); oParser = new parserFormula("MODE.MULT(FALSE)", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT(FALSE)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result MODE.MULT(FALSE)"); oParser = new parserFormula("MODE.MULT(G9)", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT(TRUE)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result MODE.MULT(TRUE)"); // array oParser = new parserFormula("MODE.MULT({2;2;3})", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT({2;2;3})"); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), 2, "Result in [0,0] MODE.MULT({2;2;3})"); assert.strictEqual(oParser.calculate().getElementRowCol(1,0).getValue(), "", "Result in [1,0] MODE.MULT({2;2;3})"); oParser = new parserFormula("MODE.MULT({1;1;2;2;3})", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT({1;1;2;2;3})"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 1, "Result in [0,0] MODE.MULT({1;1;2;2;3})"); assert.strictEqual(array.getElementRowCol(1,0).getValue(), 2, "Result in [1,0] MODE.MULT({1;1;2;2;3})"); assert.strictEqual(array.getElementRowCol(2,0).getValue(), "", "Result in [2,0] MODE.MULT({1;1;2;2;3})"); assert.strictEqual(array.getElementRowCol(0,1).getValue(), "", "Result in [0,1] MODE.MULT({1;1;2;2;3})"); assert.strictEqual(array.getElementRowCol(1,1).getValue(), "", "Result in [1,1] MODE.MULT({1;1;2;2;3})"); assert.strictEqual(array.getElementRowCol(3,3).getValue(), "#N/A", "Result in [3,3] MODE.MULT({1;1;2;2;3})"); oParser = new parserFormula("MODE.MULT(G10)", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT({1;1;2;2;3})"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result in MODE.MULT({1;1;2;2;3})"); oParser = new parserFormula("MODE.MULT({TRUE;2;3})", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT({TRUE;2;3})"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result in [0,0] MODE.MULT({TRUE;2;3})"); // date oParser = new parserFormula("MODE.MULT(DATE(2001,1,1),DATE(2003,1,1), DATE(2001,1,1),DATE(2003,1,1))", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT(DATE(2001,1,1),DATE(2003,1,1), DATE(2001,1,1),DATE(2003,1,1))"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 36892, "Result in [0,0] MODE.MULT(DATE(2001,1,1),DATE(2003,1,1), DATE(2001,1,1),DATE(2003,1,1))"); assert.strictEqual(array.getElementRowCol(1,0).getValue(), 37622, "Result in [1,0] MODE.MULT(DATE(2001,1,1),DATE(2003,1,1), DATE(2001,1,1),DATE(2003,1,1))"); assert.strictEqual(array.getElementRowCol(0,1).getValue(), "", "Result in [0,1] MODE.MULT(DATE(2001,1,1),DATE(2003,1,1), DATE(2001,1,1),DATE(2003,1,1))"); assert.strictEqual(array.getElementRowCol(1,1).getValue(), "", "Result in [1,1] MODE.MULT(DATE(2001,1,1),DATE(2003,1,1), DATE(2001,1,1),DATE(2003,1,1))"); assert.strictEqual(array.getElementRowCol(2,2).getValue(), "#N/A", "Result in [2,2] MODE.MULT(DATE(2001,1,1),DATE(2003,1,1), DATE(2001,1,1),DATE(2003,1,1))"); // multiple args oParser = new parserFormula("MODE.MULT(12,12,13,13)", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT(12,12,13,13)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 12, "Result in [0,0] MODE.MULT(12,12,13,13)"); assert.strictEqual(array.getElementRowCol(1,0).getValue(), 13, "Result in [1,0] MODE.MULT(12,12,13,13)"); assert.strictEqual(array.getElementRowCol(0,1).getValue(), "", "Result in [0,1] MODE.MULT(12,12,13,13)"); assert.strictEqual(array.getElementRowCol(1,1).getValue(), "", "Result in [1,1] MODE.MULT(12,12,13,13)"); assert.strictEqual(array.getElementRowCol(2,2).getValue(), "#N/A", "Result in [2,2] MODE.MULT(12,12,13,13)"); oParser = new parserFormula("MODE.MULT(1,2,3,4,5,6,7,8,9,10)", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT(1,2,3,4,5,6,7,8,9,10)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result MODE.MULT(1,2,3,4,5,6,7,8,9,10)"); oParser = new parserFormula("MODE.MULT(G6,G6,G5)", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT(3,3,2)"); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), 3, "Result in [0,0] MODE.MULT(3,3,2)"); assert.strictEqual(oParser.calculate().getElementRowCol(1,0).getValue(), "", "Result in [1,0] MODE.MULT(3,3,2)"); oParser = new parserFormula("MODE.MULT({1,2,3,4,5,6,7,8,9,10},10,10,11,11,11)", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT(1,2,3,4,5,6,7,8,9,10)"); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), 10, "Result MODE.MULT({1,2,3,4,5,6,7,8,9,10},10,10,11,11,11)"); assert.strictEqual(oParser.calculate().getElementRowCol(1,0).getValue(), 11, "Result MODE.MULT({1,2,3,4,5,6,7,8,9,10},10,10,11,11,11)"); oParser = new parserFormula("MODE.MULT({1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10})", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT({1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10}"); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), 1, "Result MODE.MULT({1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10}"); assert.strictEqual(oParser.calculate().getElementRowCol(1,0).getValue(), 2, "Result MODE.MULT({1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10}"); assert.strictEqual(oParser.calculate().getElementRowCol(2,0).getValue(), 3, "Result MODE.MULT({1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10}"); assert.strictEqual(oParser.calculate().getElementRowCol(3,0).getValue(), 4, "Result MODE.MULT({1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10}"); assert.strictEqual(oParser.calculate().getElementRowCol(4,0).getValue(), 5, "Result MODE.MULT({1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10}"); assert.strictEqual(oParser.calculate().getElementRowCol(5,0).getValue(), 6, "Result MODE.MULT({1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10}"); assert.strictEqual(oParser.calculate().getElementRowCol(6,0).getValue(), 7, "Result MODE.MULT({1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10}"); assert.strictEqual(oParser.calculate().getElementRowCol(7,0).getValue(), 8, "Result MODE.MULT({1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10}"); assert.strictEqual(oParser.calculate().getElementRowCol(8,0).getValue(), 9, "Result MODE.MULT({1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10}"); assert.strictEqual(oParser.calculate().getElementRowCol(9,0).getValue(), 10, "Result MODE.MULT({1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10}"); assert.strictEqual(oParser.calculate().getElementRowCol(10,0).getValue(), "", "Result MODE.MULT({1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10}"); assert.strictEqual(oParser.calculate().getElementRowCol(0,1).getValue(), "", "Result MODE.MULT({1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10}"); oParser = new parserFormula("MODE.MULT(G2:G4,G5:G6,G2:G6,G3:G5)", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT(1,1,2,2,3,1,1,2,2,3,1,2,2)"); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), 2, "Result MODE.MULT(1,1,2,2,3,1,1,2,2,3,1,2,2)"); assert.strictEqual(oParser.calculate().getElementRowCol(0,1).getValue(), "", "Result MODE.MULT(1,1,2,2,3,1,1,2,2,3,1,2,2)"); assert.strictEqual(oParser.calculate().getElementRowCol(1,0).getValue(), "", "Result MODE.MULT(1,1,2,2,3,1,1,2,2,3,1,2,2)"); // ctrl shift enter cases oParser = new parserFormula("MODE.MULT(G2:G4,G5:G6,G2:G6,G3:G5)", "H1", ws); oParser.setArrayFormulaRef(ws.getRange2("G2:G6").bbox); assert.ok(oParser.parse(), "MODE.MULT(1,1,2,2,3,1,1,2,2,3,1,2,2)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result in [0,0] MODE.MULT(1,1,2,2,3,1,1,2,2,3,1,2,2)"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result in [1,0] MODE.MULT(1,1,2,2,3,1,1,2,2,3,1,2,2)"); // 2 assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result in [0,1] MODE.MULT(1,1,2,2,3,1,1,2,2,3,1,2,2)"); // 2 assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result in [1,1] MODE.MULT(1,1,2,2,3,1,1,2,2,3,1,2,2)"); // 2 assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "#N/A", "Result in [2,2] MODE.MULT(1,1,2,2,3,1,1,2,2,3,1,2,2)"); oParser = new parserFormula("MODE.MULT({10;11;10;11})", "H1:K8", ws); oParser.setArrayFormulaRef(ws.getRange2("H1:K8").bbox); assert.ok(oParser.parse(), "MODE.MULT({10;11;10;11})"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 10, "Result in [0,0] MODE.MULT({10;11;10;11})"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 11, "Result in [1,0] MODE.MULT({10;11;10;11})"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result in [0,1] MODE.MULT({10;11;10;11})"); // 10 assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result in [1,1] MODE.MULT({10;11;10;11})"); // 11 assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "#N/A", "Result in [2,2] MODE.MULT({10;11;10;11})"); // TODO sort test oParser = new parserFormula("MODE.MULT({1,2,5,5,5,4,4,4,7,7,7,2,2,1,1})", "H1", ws); assert.ok(oParser.parse(), "MODE.MULT({1,2,5,5,5,4,4,4,7,7,7,2,2,1,1}"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result in [0,0] MODE.MULT({1,2,5,5,5,4,4,4,7,7,7,2,2,1,1}"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, "Result in [1,0] MODE.MULT({1,2,5,5,5,4,4,4,7,7,7,2,2,1,1}"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 5, "Result in [2,0] MODE.MULT({1,2,5,5,5,4,4,4,7,7,7,2,2,1,1}"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 4, "Result in [3,0] MODE.MULT({1,2,5,5,5,4,4,4,7,7,7,2,2,1,1}"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 7, "Result in [4,0] MODE.MULT({1,2,5,5,5,4,4,4,7,7,7,2,2,1,1}"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), "", "Result in [5,0] MODE.MULT({1,2,5,5,5,4,4,4,7,7,7,2,2,1,1}"); }); QUnit.test("Test: \"MODE.SNGL \"", function (assert) { // func working the same as old MODE ws.getRange2("F202").setValue("5.6"); ws.getRange2("F203").setValue("4"); ws.getRange2("F204").setValue("4"); ws.getRange2("F205").setValue("3"); ws.getRange2("F206").setValue("2"); ws.getRange2("F207").setValue("4"); oParser = new parserFormula("MODE.SNGL(F202:F207)", "F1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); ws.getRange2("G2").setValue("1"); ws.getRange2("G3").setValue("1"); ws.getRange2("G4").setValue("2"); ws.getRange2("G5").setValue("2"); ws.getRange2("G6").setValue("3"); oParser = new parserFormula("MODE.SNGL(G2:G6)", "H1", ws); assert.ok(oParser.parse(), "MODE.SNGL(G2:G6)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), 1); // number oParser = new parserFormula("MODE.SNGL(12)", "H1", ws); assert.ok(oParser.parse(), "MODE.SNGL(12)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result MODE.SNGL(12)"); // string oParser = new parserFormula("MODE.SNGL(hello)", "H1", ws); assert.ok(oParser.parse(), "MODE.SNGL(hello)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result MODE.SNGL('hello')"); // bool oParser = new parserFormula("MODE.SNGL(TRUE)", "H1", ws); assert.ok(oParser.parse(), "MODE.SNGL(TRUE)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result MODE.SNGL(TRUE)"); // array oParser = new parserFormula("MODE.SNGL({1;1;2;2;3})", "H1", ws); assert.ok(oParser.parse(), "MODE.SNGL({1;1;2;2;3})"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result in MODE.SNGL({1;1;2;2;3})"); // multiple args oParser = new parserFormula("MODE.SNGL({1,2,3,4,5,6,7,8,9,10},10,10,11,11,11)", "H1", ws); assert.ok(oParser.parse(), "MODE.SNGL(1,2,3,4,5,6,7,8,9,10)"); assert.strictEqual(oParser.calculate().getValue(), 10, "Result MODE.SNGL({1,2,3,4,5,6,7,8,9,10},10,10,11,11,11)"); }); QUnit.test("Test: \"NUMBERVALUE\"", function (assert) { oParser = new parserFormula('NUMBERVALUE("2.500,27",",",".")', "A1", ws); assert.ok(oParser.parse(), 'NUMBERVALUE("2.500,27",",",".")'); assert.strictEqual(oParser.calculate().getValue(), 2500.27, 'NUMBERVALUE("2.500,27",",",".")'); oParser = new parserFormula('NUMBERVALUE("3.5%")', "A1", ws); assert.ok(oParser.parse(), 'NUMBERVALUE("3.5%")'); assert.strictEqual(oParser.calculate().getValue(), 0.035, 'NUMBERVALUE("3.5%")'); oParser = new parserFormula('NUMBERVALUE("3.5%%%")', "A1", ws); assert.ok(oParser.parse(), 'NUMBERVALUE("3.5%%%")'); assert.strictEqual(oParser.calculate().getValue(), 0.0000035, 'NUMBERVALUE("3.5%%%")'); oParser = new parserFormula('NUMBERVALUE(123123,6,6)', "A1", ws); assert.ok(oParser.parse(), 'NUMBERVALUE(123123,6,6)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'NUMBERVALUE(123123,6,6)'); testArrayFormula2(assert, "NUMBERVALUE", 1, 3); }); QUnit.test("Test: \"NORMDIST\"", function (assert) { function normdist(x, mue, sigma, kum) { if (sigma <= 0) { return "#NUM!"; } else if (kum == false) { return toFixed(AscCommonExcel.phi((x - mue) / sigma) / sigma); } else { return toFixed(0.5 + AscCommonExcel.gauss((x - mue) / sigma)); } } oParser = new parserFormula("NORMDIST(42,40,1.5,TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), normdist(42, 40, 1.5, true)); oParser = new parserFormula("NORMDIST(42,40,1.5,FALSE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), normdist(42, 40, 1.5, false)); oParser = new parserFormula("NORMDIST(42,40,-1.5,TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), normdist(42, 40, -1.5, true)); oParser = new parserFormula("NORMDIST(1,40,-1.5,TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), normdist(1, 40, -1.5, true)); testArrayFormula2(assert, "NORMDIST", 4, 4); }); QUnit.test("Test: \"NORM.DIST \"", function (assert) { ws.getRange2("F202").setValue("42"); ws.getRange2("F203").setValue("40"); ws.getRange2("F204").setValue("1.5"); oParser = new parserFormula("NORM.DIST(F202,F203,F204,TRUE)", "F1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.9087888); oParser = new parserFormula("NORM.DIST(F202,F203,F204,FALSE)", "F1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(5) - 0, 0.10934); }); QUnit.test("Test: \"NORMSDIST\"", function (assert) { function normsdist(x) { return toFixed(0.5 + AscCommonExcel.gauss(x)); } oParser = new parserFormula("NORMSDIST(1.333333)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), normsdist(1.333333)); oParser = new parserFormula("NORMSDIST(-1.5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), normsdist(-1.5)); testArrayFormula(assert, "NORMSDIST"); }); QUnit.test("Test: \"NORM.S.DIST\"", function (assert) { oParser = new parserFormula("NORM.S.DIST(1.333333,TRUE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 0.908788726); oParser = new parserFormula("NORM.S.DIST(1.333333,FALSE)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 0.164010148); testArrayFormula2(assert, "NORM.S.DIST", 2, 2) }); QUnit.test("Test: \"NEGBINOMDIST\"", function (assert) { function negbinomdist(x, r, p) { x = parseInt(x); r = parseInt(r); if (x < 0 || r < 1 || p < 0 || p > 1) { return "#NUM!"; } else { return toFixed(Math.binomCoeff(x + r - 1, r - 1) * Math.pow(p, r) * Math.pow(1 - p, x)); } } oParser = new parserFormula("NEGBINOMDIST(6,10,0.5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), negbinomdist(6, 10, 0.5)); oParser = new parserFormula("NEGBINOMDIST(6,10,1.5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), negbinomdist(6, 10, 1.5)); oParser = new parserFormula("NEGBINOMDIST(20,10,0.63)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), negbinomdist(20, 10, 0.63)); testArrayFormula2(assert, "NEGBINOMDIST", 3, 3); }); QUnit.test("Test: \"NEGBINOM.DIST \"", function (assert) { ws.getRange2("F202").setValue("10"); ws.getRange2("F203").setValue("5"); ws.getRange2("F204").setValue("0.25"); oParser = new parserFormula("NEGBINOM.DIST(F202,F203,F204,TRUE)", "F1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.3135141); oParser = new parserFormula("NEGBINOM.DIST(F202,F203,F204,FALSE)", "F1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.0550487); testArrayFormula2(assert, "NEGBINOM.DIST", 4, 4); }); QUnit.test("Test: \"NEGBINOMDIST \"", function (assert) { ws.getRange2("F202").setValue("10"); ws.getRange2("F203").setValue("5"); ws.getRange2("F204").setValue("0.25"); oParser = new parserFormula("NEGBINOMDIST(F202,F203,F204)", "F1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 0.05504866); }); QUnit.test("Test: \"NORMSINV\"", function (assert) { function normsinv(x) { if (x <= 0.0 || x >= 1.0) { return "#N/A"; } else { return toFixed(AscCommonExcel.gaussinv(x)); } } oParser = new parserFormula("NORMSINV(0.954)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), normsinv(0.954)); oParser = new parserFormula("NORMSINV(0.13)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), normsinv(0.13)); oParser = new parserFormula("NORMSINV(0.6782136)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), normsinv(0.6782136)); oParser = new parserFormula("NORMSINV(1.6782136)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), normsinv(1.6782136)); oParser = new parserFormula("NORMSINV(-1.6782136)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), normsinv(-1.6782136)); testArrayFormula(assert, "NORMSINV"); }); QUnit.test("Test: \"NORM.S.INV \"", function (assert) { oParser = new parserFormula("NORM.S.INV(0.908789)", "F1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 1.3333347); }); QUnit.test("Test: \"LOGINV\"", function (assert) { function loginv(x, mue, sigma) { if (sigma <= 0 || x <= 0 || x >= 1) { return "#NUM!"; } else { return toFixed(Math.exp(mue + sigma * (AscCommonExcel.gaussinv(x)))); } } oParser = new parserFormula("LOGINV(0.039084,3.5,1.2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), loginv(0.039084, 3.5, 1.2)); oParser = new parserFormula("LOGINV(0,3.5,1.2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), loginv(0, 3.5, 1.2)); oParser = new parserFormula("LOGINV(0,3.5,1.2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), loginv(10, 3.5, 1.2)); oParser = new parserFormula("LOGINV(0,3.5,1.2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), loginv(-10, 3.5, 1.2)); testArrayFormula2(assert, "LOGINV", 3, 3); }); QUnit.test("Test: \"NORMINV\"", function (assert) { function norminv(x, mue, sigma) { if (sigma <= 0.0 || x <= 0.0 || x >= 1.0) { return "#NUM!"; } else { return toFixed(AscCommonExcel.gaussinv(x) * sigma + mue); } } oParser = new parserFormula("NORMINV(0.954,40,1.5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), norminv(0.954, 40, 1.5)); oParser = new parserFormula("NORMINV(0.13,100,0.5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), norminv(0.13, 100, 0.5)); oParser = new parserFormula("NORMINV(0.6782136,6,0.005)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), norminv(0.6782136, 6, 0.005)); oParser = new parserFormula("NORMINV(-1.6782136,7,0)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), norminv(-1.6782136, 7, 0)); testArrayFormula2(assert, "NORMINV", 3, 3); }); QUnit.test("Test: \"NORM.INV \"", function (assert) { ws.getRange2("F202").setValue("0.908789"); ws.getRange2("F203").setValue("40"); ws.getRange2("F204").setValue("1.5"); oParser = new parserFormula("NORM.INV(F202,F203,F204)", "F1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 42.000002); }); QUnit.test("Test: \"PEARSON\"", function (assert) { function pearson(x, y) { var sumXDeltaYDelta = 0, sqrXDelta = 0, sqrYDelta = 0, _x = 0, _y = 0, xLength = 0; if (x.length != y.length) { return "#N/A" } for (var i = 0; i < x.length; i++) { _x += x[i] _y += y[i] xLength++; } _x /= xLength; _y /= xLength; for (var i = 0; i < x.length; i++) { sumXDeltaYDelta += (x[i] - _x) * (y[i] - _y); sqrXDelta += (x[i] - _x) * (x[i] - _x); sqrYDelta += (y[i] - _y) * (y[i] - _y); } if (sqrXDelta == 0 || sqrYDelta == 0) { return "#DIV/0!" } else { return toFixed(sumXDeltaYDelta / Math.sqrt(sqrXDelta * sqrYDelta)); } } oParser = new parserFormula("PEARSON({9,7,5,3,1},{10,6,1,5,3})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), pearson([9, 7, 5, 3, 1], [10, 6, 1, 5, 3])); testArrayFormula2(assert, "PEARSON", 2, 2, null, true) }); QUnit.test("Test: \"PERCENTILE\"", function (assert) { function percentile(A, k) { A.sort(fSortAscending) var nSize = A.length; if (A.length < 1 || nSize == 0) { return new AscCommonExcel.cError(AscCommonExcel.cErrorType.not_available).toString(); } else { if (nSize == 1) { return toFixed(A[0]); } else { var nIndex = Math.floor(k * (nSize - 1)); var fDiff = k * (nSize - 1) - Math.floor(k * (nSize - 1)); if (fDiff == 0.0) { return toFixed(A[nIndex]); } else { return toFixed(A[nIndex] + fDiff * (A[nIndex + 1] - A[nIndex])); } } } } oParser = new parserFormula("PERCENTILE({1,3,2,4},0.3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), percentile([1, 3, 2, 4], 0.3)); oParser = new parserFormula("PERCENTILE({1,3,2,4},0.75)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), percentile([1, 3, 2, 4], 0.75)); //TODO нужна другая функция для тестирования //testArrayFormula2(assert, "PERCENTILE", 2, 2, null, true); }); QUnit.test("Test: \"PERCENTILE.INC\"", function (assert) { ws.getRange2("A2").setValue("1"); ws.getRange2("A3").setValue("2"); ws.getRange2("A4").setValue("3"); ws.getRange2("A5").setValue("4"); oParser = new parserFormula("PERCENTILE.INC(A2:A5,0.3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1.9); }); QUnit.test("Test: \"PERCENTILE.EXC\"", function (assert) { ws.getRange2("A202").setValue("1"); ws.getRange2("A203").setValue("2"); ws.getRange2("A204").setValue("3"); ws.getRange2("A205").setValue("6"); ws.getRange2("A206").setValue("6"); ws.getRange2("A207").setValue("6"); ws.getRange2("A208").setValue("7"); ws.getRange2("A209").setValue("8"); ws.getRange2("A210").setValue("9"); oParser = new parserFormula("PERCENTILE.EXC(A202:A210, 0.25)", "A1", ws); assert.ok(oParser.parse(), "PERCENTILE.EXC(A202:A210, 0.25)"); assert.strictEqual(oParser.calculate().getValue(), 2.5, "PERCENTILE.EXC(A202:A210, 0.25)"); oParser = new parserFormula("PERCENTILE.EXC(A202:A210, 0)", "A1", ws); assert.ok(oParser.parse(), "PERCENTILE.EXC(A202:A210, 0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "PERCENTILE.EXC(A202:A210, 0)"); oParser = new parserFormula("PERCENTILE.EXC(A202:A210, 0.01)", "A1", ws); assert.ok(oParser.parse(), "PERCENTILE.EXC(A202:A210, 0.01)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "PERCENTILE.EXC(A202:A210, 0.01)"); oParser = new parserFormula("PERCENTILE.EXC(A202:A210, 2)", "A1", ws); assert.ok(oParser.parse(), "PERCENTILE.EXC(A202:A210, 2)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "PERCENTILE.EXC(A202:A210, 2)"); //TODO нужна другая функция для тестирования //testArrayFormula2(assert, "PERCENTILE.EXC", 2, 2, null, true) }); QUnit.test("Test: \"PERCENTRANK\"", function (assert) { function percentrank(A, x, k) { var tA = A, t, fNum = x; if (!k) { k = 3; } tA.sort(fSortAscending); var nSize = tA.length; if (tA.length < 1 || nSize == 0) { return "#N/A"; } else { if (fNum < tA[0] || fNum > tA[nSize - 1]) { return "#N/A"; } else if (nSize == 1) { return 1 } else { var fRes, nOldCount = 0, fOldVal = tA[0], i; for (i = 1; i < nSize && tA[i] < fNum; i++) { if (tA[i] != fOldVal) { nOldCount = i; fOldVal = tA[i]; } } if (tA[i] != fOldVal) { nOldCount = i; } if (fNum == tA[i]) { fRes = nOldCount / (nSize - 1); } else { if (nOldCount == 0) { fRes = 0.0; } else { var fFract = (fNum - tA[nOldCount - 1]) / (tA[nOldCount] - tA[nOldCount - 1]); fRes = (nOldCount - 1 + fFract) / (nSize - 1); } } return fRes.toString().substr(0, fRes.toString().indexOf(".") + 1 + k) - 0; } } } oParser = new parserFormula("PERCENTRANK({12,6,7,9,3,8},4)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), percentrank([12, 6, 7, 9, 3, 8], 4)); oParser = new parserFormula("PERCENTRANK({12,6,7,9,3,8},5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), percentrank([12, 6, 7, 9, 3, 8], 5)); //TODO нужен другой тест //testArrayFormula2(assert, "PERCENTRANK", 2, 3, null, true); }); QUnit.test("Test: \"PERCENTRANK.EXC\"", function (assert) { ws.getRange2("A202").setValue("1"); ws.getRange2("A203").setValue("2"); ws.getRange2("A204").setValue("3"); ws.getRange2("A205").setValue("6"); ws.getRange2("A206").setValue("6"); ws.getRange2("A207").setValue("6"); ws.getRange2("A208").setValue("7"); ws.getRange2("A209").setValue("8"); ws.getRange2("A210").setValue("9"); oParser = new parserFormula("PERCENTRANK.EXC(A202:A210, 7)", "A1", ws); assert.ok(oParser.parse(), "PERCENTRANK.EXC(A202:A210, 7)"); assert.strictEqual(oParser.calculate().getValue(), 0.7, "PERCENTRANK.EXC(A202:A210, 7)"); oParser = new parserFormula("PERCENTRANK.EXC(A202:A210, 5.43)", "A1", ws); assert.ok(oParser.parse(), "PERCENTRANK.EXC(A202:A210, 5.43)"); assert.strictEqual(oParser.calculate().getValue(), 0.381, "PERCENTRANK.EXC(A202:A210, 5.43)"); oParser = new parserFormula("PERCENTRANK.EXC(A202:A210, 5.43, 1)", "A1", ws); assert.ok(oParser.parse(), "PERCENTRANK.EXC(A202:A210, 5.43, 1)"); assert.strictEqual(oParser.calculate().getValue(), 0.3, "PERCENTRANK.EXC(A202:A210, 5.43, 1)"); //TODO нужен другой тест //testArrayFormula2(assert, "PERCENTRANK.EXC", 2, 3, null, true); }); QUnit.test("Test: \"PERCENTRANK.INC\"", function (assert) { ws.getRange2("A202").setValue("13"); ws.getRange2("A203").setValue("12"); ws.getRange2("A204").setValue("11"); ws.getRange2("A205").setValue("8"); ws.getRange2("A206").setValue("4"); ws.getRange2("A207").setValue("3"); ws.getRange2("A208").setValue("2"); ws.getRange2("A209").setValue("1"); ws.getRange2("A210").setValue("1"); ws.getRange2("A211").setValue("1"); oParser = new parserFormula("PERCENTRANK.INC(A202:A211, 2)", "A1", ws); assert.ok(oParser.parse(), "PERCENTRANK.INC(A202:A211, 2)"); assert.strictEqual(oParser.calculate().getValue(), 0.333, "PERCENTRANK.INC(A202:A211, 2)"); oParser = new parserFormula("PERCENTRANK.INC(A202:A211, 4)", "A1", ws); assert.ok(oParser.parse(), "PERCENTRANK.INC(A202:A211, 4)"); assert.strictEqual(oParser.calculate().getValue(), 0.555, "PERCENTRANK.INC(A202:A211, 4)"); oParser = new parserFormula("PERCENTRANK.INC(A202:A211, 8)", "A1", ws); assert.ok(oParser.parse(), "PERCENTRANK.INC(A202:A211, 8)"); assert.strictEqual(oParser.calculate().getValue(), 0.666, "PERCENTRANK.INC(A202:A211, 8)"); oParser = new parserFormula("PERCENTRANK.INC(A202:A211, 5)", "A1", ws); assert.ok(oParser.parse(), "PERCENTRANK.INC(A202:A211, 5)"); assert.strictEqual(oParser.calculate().getValue(), 0.583, "PERCENTRANK.INC(A202:A211, 5)"); }); QUnit.test("Test: \"PERMUT\"", function (assert) { ws.getRange2("A2").setValue("100"); ws.getRange2("A3").setValue("3"); oParser = new parserFormula("PERMUT(A2,A3)", "A1", ws); assert.ok(oParser.parse(), "PERMUT(A2,A3)"); assert.strictEqual(oParser.calculate().getValue(), 970200, "PERMUT(A2,A3)"); oParser = new parserFormula("PERMUT(3,2)", "A1", ws); assert.ok(oParser.parse(), "PERMUT(3,2)"); assert.strictEqual(oParser.calculate().getValue(), 6, "PERMUT(3,2)"); testArrayFormula2(assert, "PERMUT", 2, 2); }); QUnit.test("Test: \"PERMUTATIONA\"", function (assert) { oParser = new parserFormula("PERMUTATIONA(3,2)", "A1", ws); assert.ok(oParser.parse(), "PERMUTATIONA(3,2)"); assert.strictEqual(oParser.calculate().getValue(), 9, "PERMUTATIONA(3,2)"); oParser = new parserFormula("PERMUTATIONA(2,2)", "A1", ws); assert.ok(oParser.parse(), "PERMUTATIONA(2,2)"); assert.strictEqual(oParser.calculate().getValue(), 4, "PERMUTATIONA(2,2)"); testArrayFormula2(assert, "PERMUTATIONA", 2, 2); }); QUnit.test("Test: \"PHI\"", function (assert) { oParser = new parserFormula("PHI(0.75)", "A1", ws); assert.ok(oParser.parse(), "PHI(0.75)"); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 0.301137432, "PHI(0.75)"); testArrayFormula2(assert, "PHI", 1, 1); }); QUnit.test("Test: \"POISSON\"", function (assert) { function poisson(x, l, cumulativeFlag) { var _x = parseInt(x), _l = l, f = cumulativeFlag; if (f) { var sum = 0; for (var k = 0; k <= x; k++) { sum += Math.pow(_l, k) / Math.fact(k); } sum *= Math.exp(-_l); return toFixed(sum); } else { return toFixed(Math.exp(-_l) * Math.pow(_l, _x) / Math.fact(_x)); } } oParser = new parserFormula("POISSON(8,2,false)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), poisson(8, 2, false)); oParser = new parserFormula("POISSON(8,2,true)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), poisson(8, 2, true)); oParser = new parserFormula("POISSON(2.6,5,false)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), poisson(2, 5, false)); oParser = new parserFormula("POISSON(2,5.7,true)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), poisson(2, 5.7, true)); oParser = new parserFormula("POISSON(-6,5,true)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("POISSON(6,-5,false)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); testArrayFormula2(assert, "POISSON", 3, 3); }); QUnit.test("Test: \"POISSON.DIST\"", function (assert) { ws.getRange2("A202").setValue("2"); ws.getRange2("A203").setValue("5"); oParser = new parserFormula("POISSON.DIST(A202,A203,TRUE)", "A1", ws); assert.ok(oParser.parse(), "POISSON.DIST(A202,A203,TRUE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.124652, "POISSON.DIST(A202,A203,TRUE)"); oParser = new parserFormula("POISSON.DIST(A202,A203,FALSE)", "A1", ws); assert.ok(oParser.parse(), "POISSON.DIST(A202,A203,FALSE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.084224, "POISSON.DIST(A202,A203,FALSE)"); testArrayFormula2(assert, "POISSON.DIST", 3, 3); }); QUnit.test("Test: \"PROB\"", function (assert) { oParser = new parserFormula("PROB({0,1,2,3},{0.2,0.3,0.1,0.4},2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0.1); oParser = new parserFormula("PROB({0,1,2,3},{0.2,0.3,0.1,0.4},1,4)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0.8); }); QUnit.test("Test: \"PROB\"", function (assert) { function quartile(A, k) { var fFlag = k; A.sort(fSortAscending); var nSize = A.length; if (A.length < 1 || nSize == 0) { return "#N/A" } else { if (nSize == 1) { return toFixed(A[0]); } else { if (fFlag < 0.0 || fFlag > 4) { return "#NUM!"; } else if (fFlag == 0.0) { return toFixed(A[0]); } else if (fFlag == 1.0) { var nIndex = Math.floor(0.25 * (nSize - 1)), fDiff = 0.25 * (nSize - 1) - Math.floor(0.25 * (nSize - 1)); if (fDiff == 0.0) { return toFixed(A[nIndex]); } else { return toFixed(A[nIndex] + fDiff * (A[nIndex + 1] - A[nIndex])); } } else if (fFlag == 2.0) { if (nSize % 2 == 0) { return toFixed((A[nSize / 2 - 1] + A[nSize / 2]) / 2.0); } else { return toFixed(A[(nSize - 1) / 2]); } } else if (fFlag == 3.0) { var nIndex = Math.floor(0.75 * (nSize - 1)), fDiff = 0.75 * (nSize - 1) - Math.floor(0.75 * (nSize - 1)); if (fDiff == 0.0) { return toFixed(A[nIndex]); } else { return toFixed(A[nIndex] + fDiff * (A[nIndex + 1] - A[nIndex])); } } else { return toFixed(A[nSize - 1]); } } } } oParser = new parserFormula("QUARTILE({1,2,4,7,8,9,10,12},-1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), quartile([1, 2, 4, 7, 8, 9, 10, 12], -1)); oParser = new parserFormula("QUARTILE({1,2,4,7,8,9,10,12},0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), quartile([1, 2, 4, 7, 8, 9, 10, 12], 0)); oParser = new parserFormula("QUARTILE({1,2,4,7,8,9,10,12},1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), quartile([1, 2, 4, 7, 8, 9, 10, 12], 1)); oParser = new parserFormula("QUARTILE({1,2,4,7,8,9,10,12},2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), quartile([1, 2, 4, 7, 8, 9, 10, 12], 2)); oParser = new parserFormula("QUARTILE({1,2,4,7,8,9,10,12},3)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), quartile([1, 2, 4, 7, 8, 9, 10, 12], 3)); oParser = new parserFormula("QUARTILE({1,2,4,7,8,9,10,12},4)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), quartile([1, 2, 4, 7, 8, 9, 10, 12], 4)); oParser = new parserFormula("QUARTILE({1,2,4,7,8,9,10,12},5)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), quartile([1, 2, 4, 7, 8, 9, 10, 12], 5)); }); QUnit.test("Test: \"QUARTILE\"", function (assert) { ws.getRange2("A202").setValue("1"); ws.getRange2("A203").setValue("2"); ws.getRange2("A204").setValue("4"); ws.getRange2("A205").setValue("7"); ws.getRange2("A206").setValue("8"); ws.getRange2("A207").setValue("9"); ws.getRange2("A208").setValue("10"); ws.getRange2("A209").setValue("12"); oParser = new parserFormula("QUARTILE(A202:A209,1)", "A1", ws); assert.ok(oParser.parse(), "QUARTILE(A202:A209,1)"); assert.strictEqual(oParser.calculate().getValue(), 3.5, "QUARTILE(A202:A209,1)"); //TODO нужна другая функция для тестирования //testArrayFormula2(assert, "QUARTILE", 2, 2) }); QUnit.test("Test: \"QUARTILE.INC\"", function (assert) { ws.getRange2("A202").setValue("1"); ws.getRange2("A203").setValue("2"); ws.getRange2("A204").setValue("4"); ws.getRange2("A205").setValue("7"); ws.getRange2("A206").setValue("8"); ws.getRange2("A207").setValue("9"); ws.getRange2("A208").setValue("10"); ws.getRange2("A209").setValue("12"); oParser = new parserFormula("QUARTILE.INC(A202:A209,1)", "A1", ws); assert.ok(oParser.parse(), "QUARTILE.INC(A202:A209,1)"); assert.strictEqual(oParser.calculate().getValue(), 3.5, "QUARTILE.INC(A202:A209,1)"); }); QUnit.test("Test: \"QUARTILE.EXC\"", function (assert) { ws.getRange2("A202").setValue("6"); ws.getRange2("A203").setValue("7"); ws.getRange2("A204").setValue("15"); ws.getRange2("A205").setValue("36"); ws.getRange2("A206").setValue("39"); ws.getRange2("A207").setValue("40"); ws.getRange2("A208").setValue("41"); ws.getRange2("A209").setValue("42"); ws.getRange2("A210").setValue("43"); ws.getRange2("A211").setValue("47"); ws.getRange2("A212").setValue("49"); oParser = new parserFormula("QUARTILE.EXC(A202:A212,1)", "A1", ws); assert.ok(oParser.parse(), "QUARTILE.EXC(A202:A212,1)"); assert.strictEqual(oParser.calculate().getValue(), 15, "QUARTILE.EXC(A202:A212,1)"); oParser = new parserFormula("QUARTILE.EXC(A202:A212,3)", "A1", ws); assert.ok(oParser.parse(), "QUARTILE.EXC(A202:A212,3)"); assert.strictEqual(oParser.calculate().getValue(), 43, "QUARTILE.EXC(A202:A212,3)"); //TODO нужна другая функция для тестирования //testArrayFormula2(assert, "QUARTILE.EXC", 2, 2) }); QUnit.test("Test: \"RSQ\"", function (assert) { function rsq(x, y) { var sumXDeltaYDelta = 0, sqrXDelta = 0, sqrYDelta = 0, _x = 0, _y = 0, xLength = 0; if (x.length != y.length) { return "#N/A" } for (var i = 0; i < x.length; i++) { _x += x[i] _y += y[i] xLength++; } _x /= xLength; _y /= xLength; for (var i = 0; i < x.length; i++) { sumXDeltaYDelta += (x[i] - _x) * (y[i] - _y); sqrXDelta += (x[i] - _x) * (x[i] - _x); sqrYDelta += (y[i] - _y) * (y[i] - _y); } if (sqrXDelta == 0 || sqrYDelta == 0) { return "#DIV/0!" } else { return toFixed(Math.pow(sumXDeltaYDelta / Math.sqrt(sqrXDelta * sqrYDelta), 2)); } } oParser = new parserFormula("RSQ({9,7,5,3,1},{10,6,1,5,3})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), rsq([9, 7, 5, 3, 1], [10, 6, 1, 5, 3])); oParser = new parserFormula("RSQ({2,3,9,1,8,7,5},{6,5,11,7,5,4,4})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), rsq([2, 3, 9, 1, 8, 7, 5], [6, 5, 11, 7, 5, 4, 4])); testArrayFormula2(assert, "RSQ", 2, 2, null, true) }); QUnit.test("Test: \"SKEW\"", function (assert) { function skew(x) { var sumSQRDeltaX = 0, _x = 0, xLength = 0, standDev = 0, sumSQRDeltaXDivstandDev = 0; for (var i = 0; i < x.length; i++) { _x += x[i]; xLength++; } if (xLength <= 2) { return "#N/A" } _x /= xLength; for (var i = 0; i < x.length; i++) { sumSQRDeltaX += Math.pow(x[i] - _x, 2); } standDev = Math.sqrt(sumSQRDeltaX / (xLength - 1)); for (var i = 0; i < x.length; i++) { sumSQRDeltaXDivstandDev += Math.pow((x[i] - _x) / standDev, 3); } return toFixed(xLength / (xLength - 1) / (xLength - 2) * sumSQRDeltaXDivstandDev) } oParser = new parserFormula("SKEW(3,4,5,2,3,4,5,6,4,7)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), skew([3, 4, 5, 2, 3, 4, 5, 6, 4, 7])); oParser = new parserFormula("SKEW({2,3,9,1,8,7,5},{6,5,11,7,5,4,4})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), skew([2, 3, 9, 1, 8, 7, 5, 6, 5, 11, 7, 5, 4, 4])); testArrayFormula2(assert, "SKEW", 1, 8, null, true); }); QUnit.test("Test: \"SKEW.P\"", function (assert) { ws.getRange2("A202").setValue("3"); ws.getRange2("A203").setValue("4"); ws.getRange2("A204").setValue("5"); ws.getRange2("A205").setValue("2"); ws.getRange2("A206").setValue("3"); ws.getRange2("A207").setValue("4"); ws.getRange2("A208").setValue("5"); ws.getRange2("A209").setValue("6"); ws.getRange2("A210").setValue("4"); ws.getRange2("A211").setValue("7"); oParser = new parserFormula("SKEW.P(A202:A211)", "A1", ws); assert.ok(oParser.parse(), "SKEW.P(A202:A211)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.303193, "SKEW.P(A202:A211)"); }); QUnit.test("Test: \"SMALL\"", function (assert) { oParser = new parserFormula("SMALL({3,5,3,5,4;4,2,4,6,7},3)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); oParser = new parserFormula("SMALL({3,5,3,5,4;4,2,4,6,7},7)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5); oParser = new parserFormula("SMALL({1,TRUE,FALSE,3,4,5,32,5,4,3},9)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("SMALL({1,TRUE,FALSE,3,4,5,32,5,4,3},8)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 32); oParser = new parserFormula("SMALL({1,TRUE,10,3,4,5,32,5,4,3},10)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("SMALL({1,TRUE,10,3,4,5,32,5,4,3},1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("SMALL(3,1)", "A1", ws); assert.ok(oParser.parse(), 'SMALL(3,1)'); assert.strictEqual(oParser.calculate().getValue(), 3, 'Result of SMALL(3,1)'); oParser = new parserFormula("SMALL(1,1)", "A1", ws); assert.ok(oParser.parse(), 'SMALL(1,1)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of SMALL(1,1)'); oParser = new parserFormula("SMALL(1,2)", "A1", ws); assert.ok(oParser.parse(), 'SMALL(1,2)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of SMALL(1,2)'); oParser = new parserFormula("SMALL(#N/A,1)", "A1", ws); assert.ok(oParser.parse(), 'SMALL(#N/A,1)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of SMALL(#N/A,1)'); oParser = new parserFormula('SMALL("1",1)', "A1", ws); assert.ok(oParser.parse(), 'SMALL("1",1)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of SMALL("1",1)'); oParser = new parserFormula('SMALL(-10,1)', "A1", ws); assert.ok(oParser.parse(), 'SMALL(-10,1)'); assert.strictEqual(oParser.calculate().getValue(), -10, 'Result of SMALL(-10,1)'); //TODO нужна другая функция для тестирования //testArrayFormula2(assert, "SMALL", 2, 2) }); QUnit.test("Test: \"SLOPE\"", function (assert) { function slope(y, x) { var sumXDeltaYDelta = 0, sqrXDelta = 0, _x = 0, _y = 0, xLength = 0; if (x.length != y.length) { return "#N/A" } for (var i = 0; i < x.length; i++) { _x += x[i] _y += y[i] xLength++; } _x /= xLength; _y /= xLength; for (var i = 0; i < x.length; i++) { sumXDeltaYDelta += (x[i] - _x) * (y[i] - _y); sqrXDelta += (x[i] - _x) * (x[i] - _x); } if (sqrXDelta == 0) { return "#DIV/0!" } else { return toFixed(sumXDeltaYDelta / sqrXDelta); } } oParser = new parserFormula("SLOPE({9,7,5,3,1},{10,6,1,5,3})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), slope([9, 7, 5, 3, 1], [10, 6, 1, 5, 3])); oParser = new parserFormula("SLOPE({2,3,9,1,8,7,5},{6,5,11,7,5,4,4})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), slope([2, 3, 9, 1, 8, 7, 5], [6, 5, 11, 7, 5, 4, 4])); testArrayFormula2(assert, "SLOPE", 2, 2, null, true); }); QUnit.test("Test: \"STEYX\"", function (assert) { ws.getRange2("A203").setValue("2"); ws.getRange2("A204").setValue("3"); ws.getRange2("A205").setValue("9"); ws.getRange2("A206").setValue("1"); ws.getRange2("A207").setValue("8"); ws.getRange2("A208").setValue("7"); ws.getRange2("A209").setValue("5"); ws.getRange2("B203").setValue("6"); ws.getRange2("B204").setValue("5"); ws.getRange2("B205").setValue("11"); ws.getRange2("B206").setValue("7"); ws.getRange2("B207").setValue("5"); ws.getRange2("B208").setValue("4"); ws.getRange2("B209").setValue("4"); oParser = new parserFormula("STEYX(A203:A209,B203:B209)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 3.305719); testArrayFormula2(assert, "STEYX", 2, 2, null, true); }); QUnit.test("Test: \"STANDARDIZE\"", function (assert) { function STANDARDIZE(x, mean, sigma) { if (sigma <= 0) { return "#NUM!" } else { return toFixed((x - mean) / sigma); } } oParser = new parserFormula("STANDARDIZE(42,40,1.5)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), STANDARDIZE(42, 40, 1.5)); oParser = new parserFormula("STANDARDIZE(22,12,2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), STANDARDIZE(22, 12, 2)); oParser = new parserFormula("STANDARDIZE(22,12,-2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), STANDARDIZE(22, 12, -2)); testArrayFormula2(assert, "STANDARDIZE", 3, 3); }); QUnit.test("Test: \"STDEV\"", function (assert) { function stdev() { var average = 0, res = 0; for (var i = 0; i < arguments.length; i++) { average += arguments[i]; } average /= arguments.length; for (var i = 0; i < arguments.length; i++) { res += (arguments[i] - average) * (arguments[i] - average); } return toFixed(Math.sqrt(res / (arguments.length - 1))); } oParser = new parserFormula("STDEV(123,134,143,173,112,109)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), stdev(123, 134, 143, 173, 112, 109)); ws.getRange2("E400").setValue("\"123\""); ws.getRange2("E401").setValue("134"); ws.getRange2("E402").setValue("143"); ws.getRange2("E403").setValue("173"); ws.getRange2("E404").setValue("112"); ws.getRange2("E405").setValue("109"); oParser = new parserFormula("STDEV(E400:E405)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), stdev(134, 143, 173, 112, 109)); }); QUnit.test("Test: \"STDEV.S\"", function (assert) { ws.getRange2("A202").setValue("1345"); ws.getRange2("A203").setValue("1301"); ws.getRange2("A204").setValue("1368"); ws.getRange2("A205").setValue("1322"); ws.getRange2("A206").setValue("1310"); ws.getRange2("A207").setValue("1370"); ws.getRange2("A208").setValue("1318"); ws.getRange2("A209").setValue("1350"); ws.getRange2("A210").setValue("1303"); ws.getRange2("A211").setValue("1299"); oParser = new parserFormula("STDEV.S(A202:A211)", "A1", ws); assert.ok(oParser.parse(), "STDEV.S(A202:A211)"); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 27.46391572, "STDEV.S(A202:A211)"); }); QUnit.test("Test: \"STDEV.P\"", function (assert) { ws.getRange2("A202").setValue("1345"); ws.getRange2("A203").setValue("1301"); ws.getRange2("A204").setValue("1368"); ws.getRange2("A205").setValue("1322"); ws.getRange2("A206").setValue("1310"); ws.getRange2("A207").setValue("1370"); ws.getRange2("A208").setValue("1318"); ws.getRange2("A209").setValue("1350"); ws.getRange2("A210").setValue("1303"); ws.getRange2("A211").setValue("1299"); oParser = new parserFormula("STDEV.P(A202:A211)", "A1", ws); assert.ok(oParser.parse(), "STDEV.P(A202:A211)"); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 26.05455814, "STDEV.P(A202:A211)"); }); QUnit.test("Test: \"STDEVA\"", function (assert) { ws.getRange2("E400").setValue("\"123\""); ws.getRange2("E401").setValue("134"); ws.getRange2("E402").setValue("143"); ws.getRange2("E403").setValue("173"); ws.getRange2("E404").setValue("112"); ws.getRange2("E405").setValue("109"); function stdeva() { var average = 0, res = 0; for (var i = 0; i < arguments.length; i++) { average += arguments[i]; } average /= arguments.length; for (var i = 0; i < arguments.length; i++) { res += (arguments[i] - average) * (arguments[i] - average); } return toFixed(Math.sqrt(res / (arguments.length - 1))); } oParser = new parserFormula("STDEVA(123,134,143,173,112,109)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), stdeva(123, 134, 143, 173, 112, 109)); oParser = new parserFormula("STDEVA(123,134,143,173,112,109)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), stdeva(123, 134, 143, 173, 112, 109)); testArrayFormula2(assert, "STDEVA", 1, 8, null, true); }); QUnit.test("Test: \"SWITCH\"", function (assert) { ws.getRange2("A2").setValue("2"); ws.getRange2("A3").setValue("99"); ws.getRange2("A4").setValue("99"); ws.getRange2("A5").setValue("2"); ws.getRange2("A6").setValue("3"); oParser = new parserFormula('SWITCH(WEEKDAY(A2),1,"Sunday",2,"Monday",3,"Tuesday","No match")', "A1", ws); assert.ok(oParser.parse(), 'SWITCH(WEEKDAY(A2),1,"Sunday",2,"Monday",3,"Tuesday","No match")'); assert.strictEqual(oParser.calculate().getValue(), "Monday", 'SWITCH(WEEKDAY(A2),1,"Sunday",2,"Monday",3,"Tuesday","No match")'); oParser = new parserFormula('SWITCH(A3,1,"Sunday",2,"Monday",3,"Tuesday")', "A1", ws); assert.ok(oParser.parse(), 'SWITCH(A3,1,"Sunday",2,"Monday",3,"Tuesday")'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'SWITCH(A3,1,"Sunday",2,"Monday",3,"Tuesday")'); oParser = new parserFormula('SWITCH(A4,1,"Sunday",2,"Monday",3,"Tuesday","No match")', "A1", ws); assert.ok(oParser.parse(), 'SWITCH(A4,1,"Sunday",2,"Monday",3,"Tuesday","No match")'); assert.strictEqual(oParser.calculate().getValue(), "No match", 'SWITCH(A4,1,"Sunday",2,"Monday",3,"Tuesday","No match")'); oParser = new parserFormula('SWITCH(A5,1,"Sunday",7,"Saturday","weekday")', "A1", ws); assert.ok(oParser.parse(), 'SWITCH(A5,1,"Sunday",7,"Saturday","weekday")'); assert.strictEqual(oParser.calculate().getValue(), "weekday", 'SWITCH(A5,1,"Sunday",7,"Saturday","weekday")'); oParser = new parserFormula('SWITCH(A6,1,"Sunday",2,"Monday",3,"Tuesday","No match")', "A1", ws); assert.ok(oParser.parse(), 'SWITCH(A6,1,"Sunday",2,"Monday",3,"Tuesday","No match")'); assert.strictEqual(oParser.calculate().getValue(), "Tuesday", 'SWITCH(A6,1,"Sunday",2,"Monday",3,"Tuesday","No match")'); oParser = new parserFormula('SWITCH(122,1,"Sunday",2,"Monday",3,"Tuesday","No match")', "A1", ws); assert.ok(oParser.parse(), 'SWITCH(122,1,"Sunday",2,"Monday",3,"Tuesday","No match")'); assert.strictEqual(oParser.calculate().getValue(), "No match", 'SWITCH(122,1,"Sunday",2,"Monday",3,"Tuesday","No match")'); oParser = new parserFormula('SWITCH({1,"2asd",3},{12,2,3},{"asd",2,3,4})', "A1", ws); assert.ok(oParser.parse(), 'SWITCH({1,"2asd",3},{12,2,3},{"asd",2,3,4})'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'SWITCH({1,"2asd",3},{12,2,3},{"asd",2,3,4})'); oParser = new parserFormula('SWITCH({"asd1","2asd",3},{"asd1",1,3},"sdf")', "A1", ws); assert.ok(oParser.parse(), 'SWITCH({"asd1","2asd",3},{"asd1",1,3},"sdf")'); assert.strictEqual(oParser.calculate().getValue(), "sdf", 'SWITCH({"asd1","2asd",3},{"asd1",1,3},"sdf")'); testArrayFormulaEqualsValues(assert, "1,3.123,-4,#N/A;2,4,5,#N/A;#N/A,#N/A,#N/A,#N/A", "SWITCH(A1:C2,A1:C2,A1:C2)"); testArrayFormulaEqualsValues(assert, "1,1,1,#N/A;1,1,1,#N/A;#N/A,#N/A,#N/A,#N/A", "SWITCH(A1:C2,A1:C2,A1:A1,A1:C2,A1:C2)"); testArrayFormulaEqualsValues(assert, "1,1,1,#N/A;2,2,2,#N/A;#N/A,#N/A,#N/A,#N/A", "SWITCH(A1:C2,A1:C2,A1:A2,A1:C2,A1:A2,A1:C2)"); }); QUnit.test("Test: \"VAR\"", function (assert) { function _var(x) { var sumSQRDeltaX = 0, _x = 0, xLength = 0, standDev = 0, sumSQRDeltaXDivstandDev = 0; for (var i = 0; i < x.length; i++) { _x += x[i]; xLength++; } _x /= xLength; for (var i = 0; i < x.length; i++) { sumSQRDeltaX += Math.pow(x[i] - _x, 2); } return toFixed(sumSQRDeltaX / (xLength - 1)) } oParser = new parserFormula("VAR(10.5,12.4,19.4,23.2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), _var([10.5, 12.4, 19.4, 23.2])); oParser = new parserFormula("VAR(10.5,{12.4,19.4},23.2)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), _var([10.5, 12.4, 19.4, 23.2])); oParser = new parserFormula("VAR(10.5,12.4,19.4)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), _var([10.5, 12.4, 19.4])); oParser = new parserFormula("VAR(1)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!"); oParser = new parserFormula("VAR({1})", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!"); ws.getRange2("A202").setValue("1345"); ws.getRange2("A203").setValue(""); ws.getRange2("A204").setValue(""); oParser = new parserFormula("VAR(A202)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!"); oParser = new parserFormula("VAR(A202:A204)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!"); oParser = new parserFormula("VAR(#REF!)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#REF!"); }); QUnit.test("Test: \"VAR.P\"", function (assert) { ws.getRange2("A202").setValue("1345"); ws.getRange2("A203").setValue("1301"); ws.getRange2("A204").setValue("1368"); ws.getRange2("A205").setValue("1322"); ws.getRange2("A206").setValue("1310"); ws.getRange2("A207").setValue("1370"); ws.getRange2("A208").setValue("1318"); ws.getRange2("A209").setValue("1350"); ws.getRange2("A210").setValue("1303"); ws.getRange2("A211").setValue("1299"); oParser = new parserFormula("VAR.P(A202:A211)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 678.84); testArrayFormula2(assert, "VAR.P", 1, 8, null, true); }); QUnit.test("Test: \"VAR.S\"", function (assert) { ws.getRange2("A202").setValue("1345"); ws.getRange2("A203").setValue("1301"); ws.getRange2("A204").setValue("1368"); ws.getRange2("A205").setValue("1322"); ws.getRange2("A206").setValue("1310"); ws.getRange2("A207").setValue("1370"); ws.getRange2("A208").setValue("1318"); ws.getRange2("A209").setValue("1350"); ws.getRange2("A210").setValue("1303"); ws.getRange2("A211").setValue("1299"); oParser = new parserFormula("VAR.S(A202:A211)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 754.27); testArrayFormula2(assert, "VAR.S", 1, 8, null, true); }); QUnit.test("Test: \"VARPA\"", function (assert) { ws.getRange2("A202").setValue("1345"); ws.getRange2("A203").setValue("1301"); ws.getRange2("A204").setValue("1368"); ws.getRange2("A205").setValue("1322"); ws.getRange2("A206").setValue("1310"); ws.getRange2("A207").setValue("1370"); ws.getRange2("A208").setValue("1318"); ws.getRange2("A209").setValue("1350"); ws.getRange2("A210").setValue("1303"); ws.getRange2("A211").setValue("1299"); oParser = new parserFormula("VARPA(A202:A211)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 678.84); testArrayFormula2(assert, "VARPA", 1, 8, null, true); }); /* * Lookup and Reference */ QUnit.test("Test: \"HLOOKUP\"", function (assert) { let array; ws.getRange2("A501").setValue("Density"); ws.getRange2("A502").setValue("Bearings"); ws.getRange2("A503").setValue("Bolts"); ws.getRange2("A504").setValue(""); ws.getRange2("B501").setValue("0.457"); ws.getRange2("B502").setValue("3.55"); ws.getRange2("B503").setValue("500"); ws.getRange2("C501").setValue("0.525"); ws.getRange2("C502").setValue("3.25"); ws.getRange2("C503").setValue("400"); ws.getRange2("D501").setValue("0.616"); ws.getRange2("D502").setValue("2.93"); ws.getRange2("D503").setValue("300"); ws.getRange2("E501").setValue("0.675"); ws.getRange2("E502").setValue("2.75"); ws.getRange2("E503").setValue("250"); ws.getRange2("F501").setValue("0.746"); ws.getRange2("F502").setValue("2.57"); ws.getRange2("F503").setValue("200"); ws.getRange2("G501").setValue("0.835"); ws.getRange2("G502").setValue("2.38"); ws.getRange2("G503").setValue("15"); ws.getRange2("H501").setValue("0.946"); ws.getRange2("H502").setValue("2.17"); ws.getRange2("H503").setValue("100"); ws.getRange2("I501").setValue("1.09"); ws.getRange2("I502").setValue("1.95"); ws.getRange2("I503").setValue("50"); ws.getRange2("J501").setValue("1.29"); ws.getRange2("J502").setValue("1.71"); ws.getRange2("J503").setValue("0"); ws.getRange2("A8100").setValue("2"); ws.getRange2("B8100").setValue("4"); ws.getRange2("C8100").setValue("40"); ws.getRange2("A8101").setValue("1"); ws.getRange2("B8101").setValue("2"); ws.getRange2("C8101").setValue("3"); ws.getRange2("E8100").setValue("1"); ws.getRange2("E8101").setValue("1"); ws.getRange2("E8102").setValue("1"); ws.getRange2("F8100").setValue("2"); ws.getRange2("F8101").setValue("1"); ws.getRange2("G8100").setValue("3"); ws.getRange2("G8101").setValue("1"); ws.getRange2("A1401:M1402").cleanAll(); ws.getRange2("A1401").setValue("AnyStringValue2"); ws.getRange2("B1401").setValue("StringValue(Awesome)"); ws.getRange2("C1401").setValue("1.12"); ws.getRange2("D1401").setValue("2.24"); ws.getRange2("E1401").setValue("#VALUE!"); ws.getRange2("F1401").setValue("#NUM!"); ws.getRange2("G1401").setValue("#DIV/0!"); ws.getRange2("H1401").setValue("TRUE"); ws.getRange2("I1401").setValue("Sandra"); ws.getRange2("J1401").setValue(""); ws.getRange2("K1401").setValue("Sandra"); ws.getRange2("L1401").setValue("0"); ws.getRange2("M1401").setValue("5,2"); ws.getRange2("A1402").setValue("1"); ws.getRange2("B1402").setValue("2"); ws.getRange2("C1402").setValue("3"); ws.getRange2("D1402").setValue("4"); ws.getRange2("E1402").setValue("5"); ws.getRange2("F1402").setValue("6"); ws.getRange2("G1402").setValue("7"); ws.getRange2("H1402").setValue("8"); ws.getRange2("I1402").setValue("9"); ws.getRange2("J1402").setValue("10"); ws.getRange2("K1402").setValue("11"); ws.getRange2("L1402").setValue("12"); ws.getRange2("M1402").setValue("13"); ws.getRange2("C1101:Y1102").cleanAll(); ws.getRange2("C1101").setValue("0"); ws.getRange2("D1101").setValue("0"); ws.getRange2("E1101").setValue("2.1"); ws.getRange2("F1101").setValue("2.4"); ws.getRange2("G1101").setValue("2.4"); ws.getRange2("H1101").setValue("9"); ws.getRange2("I1101").setValue("10"); ws.getRange2("J1101").setValue("11"); ws.getRange2("K1101").setValue("11"); ws.getRange2("L1101").setValue("11"); ws.getRange2("M1101").setValue("12"); ws.getRange2("N1101").setValue("12"); ws.getRange2("O1101").setValue("12"); ws.getRange2("P1101").setValue("67"); ws.getRange2("Q1101").setValue(""); ws.getRange2("R1101").setValue("ALDEBARAN"); ws.getRange2("S1101").setValue("BLUE"); ws.getRange2("T1101").setValue("CIANO"); ws.getRange2("U1101").setValue("RED"); ws.getRange2("V1101").setValue("#N/A"); ws.getRange2("W1101").setValue("Vega"); ws.getRange2("X1101").setValue("FALSE"); ws.getRange2("Y1101").setValue("TRUE"); ws.getRange2("C1102").setValue("1"); ws.getRange2("D1102").setValue("2"); ws.getRange2("E1102").setValue("3"); ws.getRange2("F1102").setValue("4"); ws.getRange2("G1102").setValue("5"); ws.getRange2("H1102").setValue("6"); ws.getRange2("I1102").setValue("7"); ws.getRange2("J1102").setValue("8"); ws.getRange2("K1102").setValue("9"); ws.getRange2("L1102").setValue("10"); ws.getRange2("M1102").setValue("11"); ws.getRange2("N1102").setValue("12"); ws.getRange2("O1102").setValue("13"); ws.getRange2("P1102").setValue("14"); ws.getRange2("Q1102").setValue("15"); ws.getRange2("R1102").setValue("16"); ws.getRange2("S1102").setValue("17"); ws.getRange2("T1102").setValue("18"); ws.getRange2("U1102").setValue("19"); ws.getRange2("V1102").setValue("20"); ws.getRange2("W1102").setValue("21"); ws.getRange2("X1102").setValue("22"); ws.getRange2("Y1102").setValue("23"); ws.getRange2("K100:Z200").cleanAll(); ws.getRange2("K100").setValue("SCALE 1"); ws.getRange2("L100").setValue("$"); ws.getRange2("M100").setValue(""); ws.getRange2("N100").setValue("0"); ws.getRange2("O100").setValue("88"); ws.getRange2("P100").setValue("371"); ws.getRange2("Q100").setValue("515"); ws.getRange2("R100").setValue("932"); ws.getRange2("S100").setValue("1957"); ws.getRange2("T100").setValue("3111"); ws.getRange2("U100").setValue(""); ws.getRange2("V100").setValue(""); ws.getRange2("W100").setValue(""); ws.getRange2("X100").setValue(""); ws.getRange2("K101").setValue(""); ws.getRange2("L101").setValue("a"); ws.getRange2("M101").setValue(""); ws.getRange2("N101").setValue("0.19"); ws.getRange2("O101").setValue("0.2348"); ws.getRange2("P101").setValue("0.219"); ws.getRange2("Q101").setValue("0.3477"); ws.getRange2("R101").setValue("0.345"); ws.getRange2("S101").setValue("0.39"); ws.getRange2("T101").setValue("0.47"); ws.getRange2("U101").setValue("1"); ws.getRange2("V101").setValue("2"); ws.getRange2("W101").setValue("3"); ws.getRange2("X101").setValue("4"); ws.getRange2("K103").setValue("SCALE 2"); ws.getRange2("L103").setValue("$"); ws.getRange2("M103").setValue(""); ws.getRange2("N103").setValue("0"); ws.getRange2("O103").setValue("359"); ws.getRange2("P103").setValue("438"); ws.getRange2("Q103").setValue("548"); ws.getRange2("R103").setValue("721"); ws.getRange2("S103").setValue("865"); ws.getRange2("T103").setValue("1282"); ws.getRange2("U103").setValue("2307"); ws.getRange2("V103").setValue("3461"); ws.getRange2("W103").setValue(""); ws.getRange2("X103").setValue(""); ws.getRange2("Y103").setValue(""); ws.getRange2("K104").setValue(""); ws.getRange2("L104").setValue("a"); ws.getRange2("M104").setValue(""); ws.getRange2("N104").setValue(""); ws.getRange2("O104").setValue("0.19"); ws.getRange2("P104").setValue("0.29"); ws.getRange2("Q104").setValue("0.21"); ws.getRange2("R104").setValue("0.219"); ws.getRange2("S104").setValue("0.3477"); ws.getRange2("T104").setValue("0.345"); ws.getRange2("U104").setValue("0.39"); ws.getRange2("V104").setValue("0.47"); ws.getRange2("W104").setValue("1"); ws.getRange2("X104").setValue("2"); ws.getRange2("Y104").setValue("3"); ws.getRange2("E301:Q302").cleanAll(); ws.getRange2("E301").setValue("String"); ws.getRange2("F301").setValue("1"); ws.getRange2("G301").setValue("2"); ws.getRange2("H301").setValue("3"); ws.getRange2("I301").setValue("#VALUE!"); ws.getRange2("J301").setValue("#NUM!"); ws.getRange2("K301").setValue("#DIV/0!"); ws.getRange2("L301").setValue("TRUE"); ws.getRange2("M301").setValue("Sandra"); ws.getRange2("N301").setValue(""); ws.getRange2("O301").setValue(""); ws.getRange2("P301").setValue(""); ws.getRange2("Q301").setValue("5"); ws.getRange2("E302").setValue("1"); ws.getRange2("F302").setValue("2"); ws.getRange2("G302").setValue("3"); ws.getRange2("H302").setValue("4"); ws.getRange2("I302").setValue("5"); ws.getRange2("J302").setValue("6"); ws.getRange2("K302").setValue("7"); ws.getRange2("L302").setValue("8"); ws.getRange2("M302").setValue("9"); ws.getRange2("N302").setValue("10"); ws.getRange2("O302").setValue("11"); ws.getRange2("P302").setValue("12"); ws.getRange2("Q302").setValue("13"); ws.getRange2("G303").setValue("Aa"); ws.getRange2("H303").setValue("Ae"); ws.getRange2("I303").setValue("Ba"); ws.getRange2("J303").setValue("Be"); ws.getRange2("K303").setValue("CA"); ws.getRange2("L303").setValue("CE"); ws.getRange2("M303").setValue("DA"); ws.getRange2("N303").setValue("DE"); ws.getRange2("O303").setValue("Ha"); ws.getRange2("P303").setValue("HE"); ws.getRange2("Q303").setValue("Ia"); ws.getRange2("R303").setValue("Ie"); ws.getRange2("S303").setValue("Ja"); ws.getRange2("T303").setValue("Je"); ws.getRange2("U303").setValue("Ka"); ws.getRange2("V303").setValue("Ke"); ws.getRange2("AA201:AH202").setValue("W"); ws.getRange2("AA201").setValue("1"); ws.getRange2("AB201").setValue("2"); ws.getRange2("AC201").setValue("3"); ws.getRange2("AD201").setValue("4"); ws.getRange2("AE201").setValue("5"); ws.getRange2("AF201").setValue("6"); ws.getRange2("AG201").setValue("7"); ws.getRange2("AH201").setValue("8"); ws.getRange2("AC202").setValue("Looked result(3)"); ws.getRange2("AA1101").setValue("1"); ws.getRange2("AB1101").setValue("1"); ws.getRange2("AC1101").setValue("1"); ws.getRange2("AD1101").setValue("1"); ws.getRange2("AE1101").setValue("#N/A"); ws.getRange2("AF1101").setValue("1"); ws.getRange2("AG1101").setValue("1"); ws.getRange2("AH1101").setValue("1"); ws.getRange2("AI1101").setValue("1"); ws.getRange2("AJ1101").setValue("1"); ws.getRange2("AA1102").setValue("1"); ws.getRange2("AB1102").setValue("2"); ws.getRange2("AC1102").setValue("3"); ws.getRange2("AD1102").setValue("4"); ws.getRange2("AE1102").setValue("5"); ws.getRange2("AF1102").setValue("6"); ws.getRange2("AG1102").setValue("7"); ws.getRange2("AH1102").setValue("8"); ws.getRange2("AI1102").setValue("9"); ws.getRange2("AJ1102").setValue("10"); ws.getRange2("AA1111").setValue("1"); ws.getRange2("AB1111").setValue("1"); ws.getRange2("AC1111").setValue("1"); ws.getRange2("AD1111").setValue("1"); ws.getRange2("AE1111").setValue(""); ws.getRange2("AF1111").setValue("a"); ws.getRange2("AG1111").setValue("2"); ws.getRange2("AH1111").setValue("1"); ws.getRange2("AI1111").setValue("1"); ws.getRange2("AJ1111").setValue("1"); ws.getRange2("AA1112").setValue("1"); ws.getRange2("AB1112").setValue("2"); ws.getRange2("AC1112").setValue("3"); ws.getRange2("AD1112").setValue("4"); ws.getRange2("AE1112").setValue("5"); ws.getRange2("AF1112").setValue("6"); ws.getRange2("AG1112").setValue("7"); ws.getRange2("AH1112").setValue("8"); ws.getRange2("AI1112").setValue("9"); ws.getRange2("AJ1112").setValue("10"); ws.getRange2("AA1121").setValue("2"); ws.getRange2("AB1121").setValue("a"); ws.getRange2("AC1121").setValue("#N/A"); ws.getRange2("AD1121").setValue("7"); ws.getRange2("AE1121").setValue(""); ws.getRange2("AF1121").setValue("0"); ws.getRange2("AG1121").setValue("0"); ws.getRange2("AH1121").setValue("1"); ws.getRange2("AI1121").setValue("1"); ws.getRange2("AJ1121").setValue("1"); ws.getRange2("AA1122").setValue("1"); ws.getRange2("AB1122").setValue("2"); ws.getRange2("AC1122").setValue("3"); ws.getRange2("AD1122").setValue("4"); ws.getRange2("AE1122").setValue("5"); ws.getRange2("AF1122").setValue("6"); ws.getRange2("AG1122").setValue("7"); ws.getRange2("AH1122").setValue("8"); ws.getRange2("AI1122").setValue("9"); ws.getRange2("AJ1122").setValue("10"); ws.getRange2("AA1131").setValue("1"); ws.getRange2("AB1131").setValue("0"); ws.getRange2("AC1131").setValue("0"); ws.getRange2("AD1131").setValue("0"); ws.getRange2("AE1131").setValue(""); ws.getRange2("AF1131").setValue(" "); ws.getRange2("AG1131").setValue("a"); ws.getRange2("AH1131").setValue("b"); ws.getRange2("AI1131").setValue("c"); ws.getRange2("AJ1131").setValue("d"); ws.getRange2("AA1132").setValue("1"); ws.getRange2("AB1132").setValue("2"); ws.getRange2("AC1132").setValue("3"); ws.getRange2("AD1132").setValue("4"); ws.getRange2("AE1132").setValue("5"); ws.getRange2("AF1132").setValue("6"); ws.getRange2("AG1132").setValue("7"); ws.getRange2("AH1132").setValue("8"); ws.getRange2("AI1132").setValue("9"); ws.getRange2("AJ1132").setValue("10"); AscCommonExcel.g_oHLOOKUPCache.clean(); const defName3D = new Asc.asc_CDefName('HLOOKUPTestName3D', ws.getName() + '!$S$1101'); const defName3D2 = new Asc.asc_CDefName('HLOOKUPTestName3D2', ws.getName() + '!$D$1102'); const defNameArea3D = new Asc.asc_CDefName('HLOOKUPTestNameArea3D', ws.getName() + '!$C$1101:$Y$1102'); wb.editDefinesNames(null, defName3D); wb.editDefinesNames(null, defNameArea3D); wb.editDefinesNames(null, defName3D2); // Positive сases: // Case #1: Number, Array, Number oParser = new parserFormula("HLOOKUP(1,{1,2;2,3;3,4},2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #2: Number, Array, Number, Number (Number -> Boolean, TRUE) oParser = new parserFormula("HLOOKUP(1,{1,2;2,3;3,4},3,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); // Case #3: Array, Array, Number oParser = new parserFormula( "HLOOKUP({2,3,4},{1,2,3;2,3,4},2)", "A2", ws ); assert.ok(oParser.parse(), "Parse HLOOKUP({2,3,4},{1,2,3;2,3,4},2)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 3, "Result of HLOOKUP({2,3,4},{1,2,3;2,3,4},2)[0,0]"); assert.strictEqual(array.getElementRowCol(0,1).getValue(), 4, "Result of HLOOKUP({2,3,4},{1,2,3;2,3,4},2)[0,1]"); assert.strictEqual(array.getElementRowCol(0,2).getValue(), 4, "Result of HLOOKUP({2,3,4},{1,2,3;2,3,4},2)[0,2]"); // Case #4: Array, Array, Number, Boolean oParser = new parserFormula("HLOOKUP({2,3,4},{1,2;2,3;3,4},2,FALSE)", "A2", ws); assert.ok(oParser.parse(), "Parse HLOOKUP({2,3,4},{1,2;2,3;3,4},2,FALSE)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 3, "Result of HLOOKUP({2,3,4},{1,2;2,3;3,4},2,FALSE)[0,0]"); assert.strictEqual(array.getElementRowCol(0,1).getValue(), "#N/A", "Result of HLOOKUP({2,3,4},{1,2;2,3;3,4},2,FALSE)[0,1]"); assert.strictEqual(array.getElementRowCol(0,2).getValue(), "#N/A", "Result of HLOOKUP({2,3,4},{1,2;2,3;3,4},2,FALSE)[0,2]"); // Case #5: Array, Array, Array oParser = new parserFormula("HLOOKUP({2,3,4},{1,2,3;2,3,4},{1,5,6})", "A2", ws); assert.ok(oParser.parse(), "Parse HLOOKUP({2,3,4},{1,2,3;2,3,4},{1,5,6})"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 2, "Result of HLOOKUP({2,3,4},{1,2,3;2,3,4},{1,5,6})[0,0]"); assert.strictEqual(array.getElementRowCol(0,1).getValue(), 3, "Result of HLOOKUP({2,3,4},{1,2,3;2,3,4},{1,5,6})[0,1]"); assert.strictEqual(array.getElementRowCol(0,2).getValue(), 3, "Result of HLOOKUP({2,3,4},{1,2,3;2,3,4},{1,5,6})[0,2]"); // Case #6: Array, Array, Array oParser = new parserFormula("HLOOKUP({2,3,4},{1,2,3;2,3,4;6,7,8},{1,5,6})", "A2", ws ); assert.ok( oParser.parse(), "Parse HLOOKUP({2,3,4},{1,2,3;2,3,4;6,7,8},{1,5,6})"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 2, "Result of HLOOKUP({2,3,4},{1,2,3;2,3,4;6,7,8},{1,5,6})[0,0]"); assert.strictEqual(array.getElementRowCol(0,1).getValue(), 3, "Result of HLOOKUP({2,3,4},{1,2,3;2,3,4;6,7,8},{1,5,6})[0,1]"); assert.strictEqual(array.getElementRowCol(0,2).getValue(), 3, "Result of HLOOKUP({2,3,4},{1,2,3;2,3,4;6,7,8},{1,5,6})[0,2]"); // Case #7: Array, Array, Array oParser = new parserFormula("HLOOKUP({5,3,4},{1,2,3;2,3,4;6,7,8},{1,5,6})", "A2", ws ); assert.ok(oParser.parse(), "Parse HLOOKUP({5,3,4},{1,2,3;2,3,4;6,7,8},{1,5,6})"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 3, "Result of HLOOKUP({5,3,4},{1,2,3;2,3,4;6,7,8},{1,5,6})[0,0]"); assert.strictEqual(array.getElementRowCol(0,1).getValue(), 3, "Result of HLOOKUP({5,3,4},{1,2,3;2,3,4;6,7,8},{1,5,6})[0,1]"); assert.strictEqual(array.getElementRowCol(0,2).getValue(), 3, "Result of HLOOKUP({5,3,4},{1,2,3;2,3,4;6,7,8},{1,5,6})[0,2]"); // Case #8: Array, Array, Number oParser = new parserFormula("HLOOKUP({2,3,4},{1,2,6;2,3,7;3,4,8},1)", "A2", ws); assert.ok(oParser.parse(), "Parse HLOOKUP({2,3,4},{1,2,6;2,3,7;3,4,8},1)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 2, "Result of HLOOKUP({2,3,4},{1,2,6;2,3,7;3,4,8},1)[0,0]"); assert.strictEqual(array.getElementRowCol(0,1).getValue(), 2, "Result of HLOOKUP({2,3,4},{1,2,6;2,3,7;3,4,8},1)[0,1]"); assert.strictEqual(array.getElementRowCol(0,2).getValue(), 2, "Result of HLOOKUP({2,3,4},{1,2,6;2,3,7;3,4,8},1)[0,2]"); // Case #9: Number, Array, Number oParser = new parserFormula("HLOOKUP(4,{1,2,3;2,3,4;6,7,8},2)", "A2", ws ); assert.ok(oParser.parse()); assert.strictEqual( oParser.calculate().getValue(), 4 ); // Case #10: Number, Array, Number oParser = new parserFormula("HLOOKUP(4,{1,2,6;2,3,7;3,4,8},3)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); // Case #11: Empty, Array, Number. Array contains zero (Empty -> Zero) oParser = new parserFormula('HLOOKUP(,{0,1,2},1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); // Case #12: Empty, Array, Number. Array contains <= zero (Empty -> Zero) oParser = new parserFormula('HLOOKUP(,{-1,2,3},1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -1); // Case #13: Number, Array, Number. Array contains several suitable values oParser = new parserFormula('HLOOKUP(1,{0,1,"c",1,1,"b",2;1,2,3,4,5,6,7},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5); // Case #14: String, Array, Number. Array contains several suitable values, Sorted only second half oParser = new parserFormula('HLOOKUP("a",{"c","a","5","a","a","c","a";1,2,3,4,5,6,7},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5); // Case #15: Empty, Array, Number. Array contains only empty strings oParser = new parserFormula('HLOOKUP(,{"","","","","","","";1,2,3,4,5,6,7},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #16: Empty, Array, Number. Array contains only empty strings and zero in second half oParser = new parserFormula('HLOOKUP(,{"","","","",0,"","";1,2,3,4,5,6,7},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5); // Case #17: Empty, Array, Number. Array contains only empty strings and zero in fist half oParser = new parserFormula('HLOOKUP(,{"",0,"","","","","";1,2,3,4,5,6,7},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #18: Number, Array, Number. Array not contains exact match, but contains value < seachValue oParser = new parserFormula('HLOOKUP(25,{26,66,13,24,70,"","";1,2,3,4,5,6,7},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); // Case #19: Number, Array, Number, Number (Number -> Boolean, FALSE) oParser = new parserFormula("HLOOKUP(1,{1,2;2,3;3,4},3,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); // Case #20: Number, Array, Number, Boolean. Array not sorted oParser = new parserFormula("HLOOKUP(1,{5,8,3,-20,1;1,2,3,4,5},2,FALSE)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5); // Case #21: String, Array, Number, Boolean. Array not sorted oParser = new parserFormula('HLOOKUP("a",{"b","a","-c","k",1;1,2,3,4,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #22: Empty, Array, Number, Boolean. Array not sorted oParser = new parserFormula('HLOOKUP(,{0,0,1,"k",1;1,2,3,4,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); // Case #23: Number, Array, Number, Boolean. Array not sorted and contains similar values oParser = new parserFormula("HLOOKUP(1,{-1,2,5,1,1;1,2,3,4,5},2,FALSE)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); // Case #24: String, Array, Number, Boolean. Array not sorted and contains similar values oParser = new parserFormula('HLOOKUP("a",{"b","a","a","a","c";1,2,3,4,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #25: Boolean, Array, Number, Boolean. Array not sorted and contains similar values oParser = new parserFormula('HLOOKUP(FALSE,{TRUE,FALSE,FALSE,"a",FALSE;1,2,3,4,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #26: Empty, Array, Number, Boolean. Array not sorted and contains errors, similar zero values oParser = new parserFormula('HLOOKUP(,{#N/A,2,0,0,#N/A;1,2,3,4,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); // Case #27: Empty, Array, Number, Boolean. Array not sorted and contains errors, similar zero values, Booleans oParser = new parserFormula('HLOOKUP(,{FALSE,TRUE,0," ",#N/A;1,2,3,4,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); // Case #28: String, Array, Number, Boolean. Trying to find empty string oParser = new parserFormula('HLOOKUP("",{"","",0," ",#N/A;1,2,3,4,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); // Case #29: String, Array, Number, Boolean. Trying to find string with space oParser = new parserFormula('HLOOKUP(" ",{""," ",0," ",#N/A;1,2,3,4,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #30: Number, Area, Number oParser = new parserFormula("HLOOKUP(1,A501:J503,2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2.17); // Case #31: Number, Area, Number, TRUE oParser = new parserFormula("HLOOKUP(1,A501:J503,3,TRUE)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 100.00); // Case #32: Number, Area, Number, TRUE oParser = new parserFormula("HLOOKUP(2,A501:J503,2,TRUE)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1.71); // Case #33: Number, Area, Array oParser = new parserFormula("HLOOKUP(5,A8100:C8101,{1,1,1})", "A2", ws); assert.ok(oParser.parse(), "Parse HLOOKUP(5,A8100:C8101,{1,1,1})"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 4, "Result of HLOOKUP(5,A8100:C8101,{1,1,1})[0,0]"); assert.strictEqual(array.getElementRowCol(0,1).getValue(), 4, "Result of HLOOKUP(5,A8100:C8101,{1,1,1})[0,1]"); assert.strictEqual(array.getElementRowCol(0,2).getValue(), 4, "Result of HLOOKUP(5,A8100:C8101,{1,1,1})[0,2]"); // Case #34: Array, Area, Area oParser = new parserFormula("HLOOKUP({2,4,40},A8100:C8101,E8100)", "A2", ws); assert.ok(oParser.parse(), "Parse HLOOKUP({2,4,40},A8100:C8101,E8100)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 2, "Result of HLOOKUP({2,4,40},A8100:C8101,E8100)[0,0]"); assert.strictEqual(array.getElementRowCol(0,1).getValue(), 4, "Result of HLOOKUP({2,4,40},A8100:C8101,E8100)[0,1]"); assert.strictEqual(array.getElementRowCol(0,2).getValue(), 40, "Result of HLOOKUP({2,4,40},A8100:C8101,E8100)[0,2]"); // Case #35: Array, Area, Array oParser = new parserFormula("HLOOKUP({2,4,40},{1,2,3;4,5,6},{1;2;3})", "A2", ws); assert.ok(oParser.parse(), "Parse HLOOKUP({2,4,40},{1,2,3;4,5,6},{1;2;3})"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 2, "Result of HLOOKUP({2,4,40},{1,2,3;4,5,6},{1;2;3})[0,0]"); assert.strictEqual(array.getElementRowCol(0,1).getValue(), 3, "Result of HLOOKUP({2,4,40},{1,2,3;4,5,6},{1;2;3})[0,1]"); assert.strictEqual(array.getElementRowCol(0,2).getValue(), 3, "Result of HLOOKUP({2,4,40},{1,2,3;4,5,6},{1;2;3})[0,2]"); // Case #36: Number, Area, Number oParser = new parserFormula("HLOOKUP(2,A501:J503,2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1.71); // Case #37: Empty, Area, Number. Area contains zeros oParser = new parserFormula('HLOOKUP(,C1101:Y1102,2,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(,C1101:Y1102,2,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), 2, 'Result of HLOOKUP(,C1101:Y1102,2,TRUE)'); // Case #38: Number, Area, Number oParser = new parserFormula('HLOOKUP(2.4,C1101:Y1102,2,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(2.4,C1101:Y1102,2,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), 5, 'Result of HLOOKUP(2.4,C1101:Y1102,2,TRUE)'); // Case #39: String, Area, Number. Area not contains exact match, but contains < seachValue oParser = new parserFormula('HLOOKUP("VIOLET",C1101:Y1102,2,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP("VIOLET",C1101:Y1102,2,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), 21, 'Result of HLOOKUP("VIOLET",C1101:Y1102,2,TRUE)'); // Case #40: Number, Area, Number. Area not contains exact match, but contains value < seachValue oParser = new parserFormula('HLOOKUP(2.3,C1101:Y1102,2,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(2.3,C1101:Y1102,2,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), 3, 'Result of HLOOKUP(2.3,C1101:Y1102,2,TRUE)'); // Case #41: String, Area, Number. Area contains exact match oParser = new parserFormula('HLOOKUP("CIANO",C1101:Y1102,2,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP("CIANO",C1101:Y1102,2,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), 18, 'Result of HLOOKUP("CIANO",C1101:Y1102,2,TRUE)'); // Case #42: Boolean, Area, Number. Area contains exact match oParser = new parserFormula('HLOOKUP(FALSE,C1101:Y1102,2,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(FALSE,C1101:Y1102,2,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), 22, 'Result of HLOOKUP(FALSE,C1101:Y1102,2,TRUE)'); // Case #43: Number, Area, Number. For bug 63026. cEmpty tests. oParser = new parserFormula('HLOOKUP(576,K100:X101,2)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(576,K100:X101,2)'); assert.strictEqual(oParser.calculate().getValue(), 0.3477, 'Result of HLOOKUP(576,K100:X101,2)'); // Case #44: Number, Area, Number. For bug 63026. cEmpty tests. oParser = new parserFormula('HLOOKUP(576,K103:Y104,2)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(576,K103:Y104,2)'); assert.strictEqual(oParser.calculate().getValue(), 0.21, 'Result of HLOOKUP(576,K103:Y104,2)'); // Case #45.1: Ref, Area, Number. For bug 54560. oParser = new parserFormula('HLOOKUP(G303,G303:V303,1)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(G303,G303:V303,1)'); assert.strictEqual(oParser.calculate().getValue(), "Aa", 'Result of HLOOKUP(G303,G303:V303,1)'); // Case #45.2: Ref, Area, Number. For bug 54560. oParser = new parserFormula('HLOOKUP(H303,G303:V303,1)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(H303,G303:V303,1)'); assert.strictEqual(oParser.calculate().getValue(), "Ae", 'Result of HLOOKUP(H303,G303:V303,1)'); // Case #45.3: Ref, Area, Number. For bug 54560. oParser = new parserFormula('HLOOKUP(I303,G303:V303,1)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(I303,G303:V303,1)'); assert.strictEqual(oParser.calculate().getValue(), "Ba", 'Result of HLOOKUP(I303,G303:V303,1)'); // Case #45.4: Ref, Area, Number. For bug 54560. oParser = new parserFormula('HLOOKUP(J303,G303:V303,1)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(J303,G303:V303,1)'); assert.strictEqual(oParser.calculate().getValue(), "Be", 'Result of HLOOKUP(J303,G303:V303,1)'); // Case #45.5: Ref, Area, Number. For bug 54560. oParser = new parserFormula('HLOOKUP(K303,G303:V303,1)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(K303,G303:V303,1)'); assert.strictEqual(oParser.calculate().getValue(), "CA", 'Result of HLOOKUP(K303,G303:V303,1)'); // Case #45.6: Ref, Area, Number. For bug 54560. oParser = new parserFormula('HLOOKUP(L303,G303:V303,1)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(L303,G303:V303,1)'); assert.strictEqual(oParser.calculate().getValue(), "CE", 'Result of HLOOKUP(L303,G303:V303,1)'); // Case #45.7: Ref, Area, Number. For bug 54560. oParser = new parserFormula('HLOOKUP(M303,G303:V303,1)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(M303,G303:V303,1)'); assert.strictEqual(oParser.calculate().getValue(), "DA", 'Result of HLOOKUP(M303,G303:V303,1)'); // Case #45.8: Ref, Area, Number. For bug 54560. oParser = new parserFormula('HLOOKUP(N303,G303:V303,1)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(N303,G303:V303,1)'); assert.strictEqual(oParser.calculate().getValue(), "DE", 'Result of HLOOKUP(N303,G303:V303,1)'); // Case #45.9: String, Area, Number. For bug 54560. oParser = new parserFormula('HLOOKUP("Ha",G303:V303,1)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP("Ha",G303:V303,1)'); assert.strictEqual(oParser.calculate().getValue(), "Ha", 'Result of HLOOKUP("Ha",G303:V303,1)'); // Case #45.10: Ref, Area, Number. For bug 54560. oParser = new parserFormula('HLOOKUP(O303,G303:V303,1)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(O303,G303:V303,1)'); assert.strictEqual(oParser.calculate().getValue(), "Ha", 'Result of HLOOKUP(O303,G303:V303,1)'); // Case #45.11: Ref, Area, Number. For bug 54560. oParser = new parserFormula('HLOOKUP(P303,G303:V303,1)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(P303,G303:V303,1)'); assert.strictEqual(oParser.calculate().getValue(), "HE", 'Result of HLOOKUP(P303,G303:V303,1)'); // Case #45.12: Ref, Area, Number. For bug 54560. oParser = new parserFormula('HLOOKUP(Q303,G303:V303,1)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(Q303,G303:V303,1)'); assert.strictEqual(oParser.calculate().getValue(), "Ia", 'Result of HLOOKUP(Q303,G303:V303,1)'); // Case #45.13: Ref, Area, Number. For bug 54560. oParser = new parserFormula('HLOOKUP(R303,G303:V303,1)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(R303,G303:V303,1)'); assert.strictEqual(oParser.calculate().getValue(), "Ie", 'Result of HLOOKUP(R303,G303:V303,1)'); // Case #45.14: Ref, Area, Number. For bug 54560. oParser = new parserFormula('HLOOKUP(S303,G303:V303,1)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(S303,G303:V303,1)'); assert.strictEqual(oParser.calculate().getValue(), "Ja", 'Result of HLOOKUP(S303,G303:V303,1)'); // Case #45.15: Ref, Area, Number. For bug 54560. oParser = new parserFormula('HLOOKUP(T303,G303:V303,1)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(T303,G303:V303,1)'); assert.strictEqual(oParser.calculate().getValue(), "Je", 'Result of HLOOKUP(T303,G303:V303,1)'); // Case #45.16: Ref, Area, Number. For bug 54560. oParser = new parserFormula('HLOOKUP(U303,G303:V303,1)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(U303,G303:V303,1)'); assert.strictEqual(oParser.calculate().getValue(), "Ka", 'Result of HLOOKUP(U303,G303:V303,1)'); // Case #45.17: Ref, Area, Number. For bug 54560. oParser = new parserFormula('HLOOKUP(V303,G303:V303,1)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(V303,G303:V303,1)'); assert.strictEqual(oParser.calculate().getValue(), "Ke", 'Result of HLOOKUP(V303,G303:V303,1)'); // Case #46: Number, Area, Number. For bug 67099. oParser = new parserFormula('HLOOKUP(3,AA201:AH202,2)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(3,AA201:AH202,2)'); assert.strictEqual(oParser.calculate().getValue(), "Looked result(3)", 'Result of HLOOKUP(3,AA201:AH202,2)'); // Case #47: Ref, Area, Number. For bug 67099. oParser = new parserFormula('HLOOKUP(AC201,AA201:AH202,2)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(AC201,AA201:AH202,2)'); assert.strictEqual(oParser.calculate().getValue(), "Looked result(3)", 'Result of HLOOKUP(AC201,AA201:AH202,2)'); // Case #48: Number, Area, Number. Area contains same values in second half. oParser = new parserFormula('HLOOKUP(1,AA1101:AJ1102,2)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(1,AA1101:AJ1102,2)'); assert.strictEqual(oParser.calculate().getValue(), 10, 'Result of HLOOKUP(1,AA1101:AJ1102,2)'); // Case #49: Number, Area, Number. Area contains same values in first half. oParser = new parserFormula('HLOOKUP(1,AA1111:AJ1112,2)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(1,AA1111:AJ1112,2)'); assert.strictEqual(oParser.calculate().getValue(), 4, 'Result of HLOOKUP(1,AA1111:AJ1112,2)'); // Case #50: Number, Area, Number. Area contains same values in second half and has error oParser = new parserFormula('HLOOKUP(1,AA1121:AJ1122,2)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(1,AA1121:AJ1122,2)'); assert.strictEqual(oParser.calculate().getValue(), 10, 'Result of HLOOKUP(1,AA1121:AJ1122,2)'); // Case #51: Number, Area, Number. Area contains <= value in first half and exact match as first element oParser = new parserFormula('HLOOKUP(1,AA1131:AJ1132,2)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(1,AA1131:AJ1132,2)'); assert.strictEqual(oParser.calculate().getValue(), 4, 'Result of HLOOKUP(1,AA1131:AJ1132,2)'); // Case #52: Area, Area, Ref oParser = new parserFormula("HLOOKUP(A8100:C8100,A8100:C8101,F8100)", "A2", ws); assert.ok(oParser.parse(), "Parse HLOOKUP(A8100:C8100,A8100:C8101,F8100)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), 1, "Result of HLOOKUP(A8100:C8100,A8100:C8101,F8100)[0,0]"); // Case #53: Number, Area, Number oParser = new parserFormula('HLOOKUP(2.24,A1401:M1402,2,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(2.24,A1401:M1402,2,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), 4, 'Result of HLOOKUP("2.24",A1401:M1402,2,FALSE)'); // Case #54: Number, Area, Number oParser = new parserFormula('HLOOKUP("AnyStringValue2",A1401:M1402,2,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP("AnyStringValue2",A1401:M1402,2,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of HLOOKUP("AnyStringValue2",A1401:M1402,2,FALSE)'); // Case #55: Number, Area, Number oParser = new parserFormula('HLOOKUP("Sandra",A1401:M1402,2,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP("Sandra",A1401:M1402,2,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), 9, 'Result of HLOOKUP("Sandra",A1401:M1402,2,FALSE)'); // Case #56: Number, Area, Number oParser = new parserFormula('HLOOKUP(,A1401:M1402,2,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(,A1401:M1402,2,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), 12, 'Result of HLOOKUP(,A1401:M1402,2,FALSE)'); // Case #57: String, Area, Number. For bug 65016 oParser = new parserFormula('HLOOKUP("SANDRA",E301:Q302,2,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP("SANDRA",E301:Q302,2,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), 9, 'Result of HLOOKUP("SANDRA",E301:Q302,2,FALSE)'); // Case #58: Boolean, Area, Number. For bug 65016 oParser = new parserFormula('HLOOKUP(TRUE,E301:Q302,2,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(TRUE,E301:Q302,2,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), 8, 'Result of HLOOKUP(TRUE,E301:Q302,2,FALSE)'); // Case #59: Number, Area, Number. For bug 65016 oParser = new parserFormula('HLOOKUP(5,E301:Q302,2,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(5,E301:Q302,2,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), 13, 'Result of HLOOKUP(5,E301:Q302,2,FALSE)'); // Case #60: Name3D, Name3D, Name3D, Boolean oParser = new parserFormula('HLOOKUP(HLOOKUPTestName3D,HLOOKUPTestNameArea3D,HLOOKUPTestName3D2,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(HLOOKUPTestName3D,HLOOKUPTestNameArea3D,HLOOKUPTestName3D2,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), 17, 'Result of HLOOKUP(HLOOKUPTestName3D,HLOOKUPTestNameArea3D,HLOOKUPTestName3D2,FALSE)'); // Case #61: Ref3D, Area3D, Area3D, Boolean oParser = new parserFormula('HLOOKUP('+ ws.getName() + '!$S$1101,'+ ws.getName() + '!$C$1101:$Y$1102,' + ws.getName() + '!$D$1102,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP('+ ws.getName() + '!$S$1101,'+ ws.getName() + '!$C$1101:$Y$1102,' + ws.getName() + '!$D$1102,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), 17, 'Result of HLOOKUP('+ ws.getName() + '!$S$1101,'+ ws.getName() + '!$C$1101:$Y$1102,' + ws.getName() + '!$D$1102,FALSE)'); // Case #62: Formula, Name3D, Formula, Formula oParser = new parserFormula('HLOOKUP(ABS(2),HLOOKUPTestNameArea3D,ABS(2),1=1)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(ABS(2),HLOOKUPTestNameArea3D,ABS(2),1=1)'); assert.strictEqual(oParser.calculate().getValue(), 2, 'Result of HLOOKUP(ABS(2),HLOOKUPTestNameArea3D,ABS(2),1=1)'); // Case #63: String, Array, Number, Boolean. For bug 76652. oParser = new parserFormula('HLOOKUP("Aîné",{"Aine","Ainé","Aîné","Aîné";111,222,333,333},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 333); // Negative Cases: // Case #1: Array, Array, Array with wrong data oParser = new parserFormula("HLOOKUP({2,3,4},{1,2;2,3;3,4},{4,5,6})", "A2", ws); assert.ok(oParser.parse(), "Parse HLOOKUP({2,3,4},{1,2;2,3;3,4},{4,5,6})"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), "#REF!", "Result of HLOOKUP({2,3,4},{1,2;2,3;3,4},{4,5,6})[0,0]"); assert.strictEqual(array.getElementRowCol(0,1).getValue(), "#REF!", "Result of HLOOKUP({2,3,4},{1,2;2,3;3,4},{4,5,6})[0,1]"); assert.strictEqual(array.getElementRowCol(0,2).getValue(), "#REF!", "Result of HLOOKUP({2,3,4},{1,2;2,3;3,4},{4,5,6})[0,2]"); // Case #2: Number, Array, Number. Out of range arg3 oParser = new parserFormula("HLOOKUP(4,{1,2,6;2,3,7;3,4,8},5)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#REF!"); // Case #3: String, Array, Number. Array not contains search type oParser = new parserFormula('HLOOKUP("a",{1,2,6;2,3,7;3,4,8},3)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #4: Boolean, Array, Number. Array not contains search type oParser = new parserFormula('HLOOKUP(FALSE,{1,2,6;2,3,7;3,4,8},3)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #5: Error, Array, Number. Search value is Error oParser = new parserFormula('HLOOKUP(#N/A,{1,2,6;2,3,7;3,4,8},3)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #6: Empty, Array, Number. Array not contains value <= 0 (Empty -> Zero) oParser = new parserFormula('HLOOKUP(,{1,2,3},1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #7: Error, Array, Number. Array contains error. Returning Error oParser = new parserFormula('HLOOKUP(#VALUE!,{0,#N/A,2},1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); // Case #8: Empty, Array, Number. Array contains Errors, not zero oParser = new parserFormula('HLOOKUP(,{#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A;1,2,3,4,5,6,7},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #9: Boolean, Array, Number. Array contains Errors oParser = new parserFormula('HLOOKUP(FALSE,{#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A;1,2,3,4,5,6,7},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #10: Boolean, Array, Number. Array contains Empty strings oParser = new parserFormula('HLOOKUP(FALSE,{"","","","","","","";1,2,3,4,5,6,7},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #11: Boolean, Array, Number. Array contains zeros and empty, errors oParser = new parserFormula('HLOOKUP(FALSE,{"",0,"",0,0,0,#N/A;1,2,3,4,5,6,7},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #12: Boolean, Array, Number. Array contains any other data oParser = new parserFormula('HLOOKUP(TRUE,{"asdac",2,"a",5,6,7,"8";1,2,3,4,5,6,7},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #13: Number, Array, Number. Array contains only string oParser = new parserFormula('HLOOKUP("item",{123;1},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #14: String, Array, Number, Number, Boolean. Array not contains string oParser = new parserFormula('HLOOKUP("a",{5,8,3,-20,1;1,2,3,4,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #15: Error, Array, Number, Number, Boolean. Returning error = search value oParser = new parserFormula('HLOOKUP(#N/A,{5,8,3,-20,1;1,2,3,4,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #16: Error, Array, Number, Number, Boolean. Returning error = search value oParser = new parserFormula('HLOOKUP(#VALUE!,{5,8,3,-20,1;1,2,3,4,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); // Case #17: String, Array, Number, Number, Boolean. Array not contains string oParser = new parserFormula('HLOOKUP("5",{5,8,3,-20,1;1,2,3,4,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #18: String, Array, Number, Boolean. Trying to find empty string oParser = new parserFormula('HLOOKUP("",{" "," ",0," ",#N/A;1,2,3,4,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #19: Empty, Array, Number, Boolean. Array contains Booleans oParser = new parserFormula('HLOOKUP(,{FALSE,FALSE,FALSE,FALSE,FALSE;1,2,3,4,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #20: Empty, Array, Number, Boolean. Array contains Booleans and empty strings oParser = new parserFormula('HLOOKUP(,{"",FALSE,"",FALSE,"";1,2,3,4,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #21: Error, Array, Number oParser = new parserFormula('HLOOKUP(#N/A,{"",0,#N/A,#N/A,"","","";1,2,3,4,5,6,7},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #22: Number, Area, Area oParser = new parserFormula("HLOOKUP(5,A8100:C8101,E8100:G8100)", "A2", ws); assert.ok(oParser.parse(), "Parse HLOOKUP(5,A8100:C8101,E8100:G8100)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of HLOOKUP(5,A8100:C8101,E8100:G8100)"); // Case #23: Number, Area, Array oParser = new parserFormula("HLOOKUP(5,A8100:C8101,{1;2;3})", "A2", ws); assert.ok(oParser.parse(), "Parse HLOOKUP(5,A8100:C8101,{1;2;3})"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of HLOOKUP(5,A8100:C8101,{1;2;3})"); // Case #24: Number, Area, Area oParser = new parserFormula("HLOOKUP(5,A8100:C8101,E8101:G8101)", "A2", ws); assert.ok(oParser.parse(), "Parse HLOOKUP(5,A8100:C8101,E8101:G8101)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", "Result of HLOOKUP(5,A8100:C8101,E8101:G8101)[0,0]"); // Case #25: Area, Area, Area oParser = new parserFormula("HLOOKUP(A8100:C8100,A8100:C8101,E8100:G8100)", "A2", ws); assert.ok(oParser.parse(), "Parse HLOOKUP(A8100:C8100,A8100:C8101,E8100:G8100)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", "Result of HLOOKUP(A8100:C8100,A8100:C8101,E8100:G8100)"); // Case #26: Area, Area, Area oParser = new parserFormula("HLOOKUP(A8100:C8100,A8100:C8101,E8100:G8101)", "A2", ws); assert.ok(oParser.parse(), "Parse HLOOKUP(A8100:C8100,A8100:C8101,E8100:G8101)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", "Result of HLOOKUP(A8100:C8100,A8100:C8101,E8100:G8101)[0,0]"); // Case #27: Area, Area, Area oParser = new parserFormula("HLOOKUP(A8100:B8100,A8100:C8101,F8100:G8101)", "A2", ws); assert.ok(oParser.parse(), "Parse HLOOKUP(A8100:B8100,A8100:C8101,F8100:G8101)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", "Result of HLOOKUP(A8100:B8100,A8100:C8101,F8100:G8101)[0,0]"); // Case #28: Area, Area, Area oParser = new parserFormula("HLOOKUP(A8100:C8100,A8100:C8101,G8100:G8101)", "A2", ws); assert.ok(oParser.parse(), "Parse HLOOKUP(A8100:C8100,A8100:C8101,G8100:G8101)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", "Result of HLOOKUP(A8100:C8100,A8100:C8101,G8100:G8101)[0,0]"); // Case #29: Empty, Area, Number. Area not contains value <= 0 oParser = new parserFormula('HLOOKUP(,A501:J503,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #30: Ref, Area, Number. Area not contains empty string "" oParser = new parserFormula('HLOOKUP(A504,A501:J503,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #31: Error, Area, Number. Return SearchVal Error. oParser = new parserFormula('HLOOKUP(#N/A,C1101:Y1102,2,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(#N/A,C1101:Y1102,2,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of HLOOKUP(#N/A,C1101:Y1102,2,TRUE)'); // Case #32: Error, Area, Number. Return SearchVal Error. oParser = new parserFormula('HLOOKUP(#VALUE!,C1101:Y1102,2,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(#VALUE!,C1101:Y1102,2,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of HLOOKUP(#VALUE!,C1101:Y1102,2,TRUE)'); // Case #33: Number, Area, Number. Area not contains value <= searchValue oParser = new parserFormula('HLOOKUP(-1,C1101:Y1102,2,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(-1,C1101:Y1102,2,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of HLOOKUP(-1,C1101:Y1102,2,TRUE)'); // Case #34: String, Area, Number. Area not contains strings oParser = new parserFormula('HLOOKUP("2",A501:J503,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #35: Number, Area, Number oParser = new parserFormula('HLOOKUP(#DIV/0!,A1401:M1402,2,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(#DIV/0!,A1401:M1402,2,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of HLOOKUP(#DIV/0!,A1401:M1402,2,FALSE)'); // Case #36: Number, Area, Number oParser = new parserFormula('HLOOKUP("",A1401:M1402,2,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP("",A1401:M1402,2,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of HLOOKUP("",A1401:M1402,2,FALSE)'); // Case #37: Ref, Area, Number. For bug 65016. Searchval = Error, should return Error oParser = new parserFormula('HLOOKUP(K301,E301:Q302,2,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'HLOOKUP(K301,E301:Q302,2,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of HLOOKUP(K301,E301:Q302,2,FALSE)'); // Case #38: String, Area, Number. Area not contains strings oParser = new parserFormula('HLOOKUP("2",A501:J503,2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); wb.delDefinesNames(defName3D); wb.delDefinesNames(defNameArea3D); wb.delDefinesNames(defName3D2); }); QUnit.test("Test: \"VLOOKUP\"", function (assert) { let array; ws.getRange2("A501").setValue("Density"); ws.getRange2("B501").setValue("Bearings"); ws.getRange2("C501").setValue("Bolts"); ws.getRange2("D501").setValue(""); ws.getRange2("A502").setValue("0.457"); ws.getRange2("B502").setValue("3.55"); ws.getRange2("C502").setValue("500"); ws.getRange2("A503").setValue("0.525"); ws.getRange2("B503").setValue("3.25"); ws.getRange2("C503").setValue("400"); ws.getRange2("A504").setValue("0.616"); ws.getRange2("B504").setValue("2.93"); ws.getRange2("C504").setValue("300"); ws.getRange2("A505").setValue("0.675"); ws.getRange2("B505").setValue("2.75"); ws.getRange2("C505").setValue("250"); ws.getRange2("A506").setValue("0.746"); ws.getRange2("B506").setValue("2.57"); ws.getRange2("C506").setValue("200"); ws.getRange2("A507").setValue("0.835"); ws.getRange2("B507").setValue("2.38"); ws.getRange2("C507").setValue("15"); ws.getRange2("A508").setValue("0.946"); ws.getRange2("B508").setValue("2.17"); ws.getRange2("C508").setValue("100"); ws.getRange2("A509").setValue("1.09"); ws.getRange2("B509").setValue("1.95"); ws.getRange2("C509").setValue("50"); ws.getRange2("A510").setValue("1.29"); ws.getRange2("B510").setValue("1.71"); ws.getRange2("C510").setValue("0"); ws.getRange2("BA100").setValue("2"); ws.getRange2("BA101").setValue("4"); ws.getRange2("BA102").setValue("40"); ws.getRange2("BB100").setValue("1"); ws.getRange2("BB101").setValue("2"); ws.getRange2("BB102").setValue("3"); ws.getRange2("BE100").setValue("1"); ws.getRange2("BE101").setValue("1"); ws.getRange2("BF100").setValue("2"); ws.getRange2("BF101").setValue("1"); ws.getRange2("BG100").setValue("3"); ws.getRange2("BG101").setValue("1"); ws.getRange2("A1101:B1120").cleanAll(); ws.getRange2("A1101").setValue("AnyStringValue2"); ws.getRange2("A1102").setValue("StringValue(Awesome)"); ws.getRange2("A1103").setValue("1.12"); ws.getRange2("A1104").setValue("2.24"); ws.getRange2("A1105").setValue("#VALUE!"); ws.getRange2("A1106").setValue("#NUM!"); ws.getRange2("A1107").setValue("#DIV/0!"); ws.getRange2("A1108").setValue("TRUE"); ws.getRange2("A1109").setValue("Sandra"); ws.getRange2("A1110").setValue(""); ws.getRange2("A1111").setValue("Sandra"); ws.getRange2("A1112").setValue("0"); ws.getRange2("A1113").setValue("5,2"); ws.getRange2("B1101").setValue("1"); ws.getRange2("B1102").setValue("2"); ws.getRange2("B1103").setValue("3"); ws.getRange2("B1104").setValue("4"); ws.getRange2("B1105").setValue("5"); ws.getRange2("B1106").setValue("6"); ws.getRange2("B1107").setValue("7"); ws.getRange2("B1108").setValue("8"); ws.getRange2("B1109").setValue("9"); ws.getRange2("B1110").setValue("10"); ws.getRange2("B1111").setValue("11"); ws.getRange2("B1112").setValue("12"); ws.getRange2("B1113").setValue("13"); ws.getRange2("C1101:D1123").cleanAll(); ws.getRange2("C1101").setValue("0"); ws.getRange2("C1102").setValue("0"); ws.getRange2("C1103").setValue("2.1"); ws.getRange2("C1104").setValue("2.4"); ws.getRange2("C1105").setValue("2.4"); ws.getRange2("C1106").setValue("9"); ws.getRange2("C1107").setValue("10"); ws.getRange2("C1108").setValue("11"); ws.getRange2("C1109").setValue("11"); ws.getRange2("C1110").setValue("11"); ws.getRange2("C1111").setValue("12"); ws.getRange2("C1112").setValue("12"); ws.getRange2("C1113").setValue("12"); ws.getRange2("C1114").setValue("67"); ws.getRange2("C1115").setValue(""); ws.getRange2("C1116").setValue("ALDEBARAN"); ws.getRange2("C1117").setValue("BLUE"); ws.getRange2("C1118").setValue("CIANO"); ws.getRange2("C1119").setValue("RED"); ws.getRange2("C1120").setValue("#N/A"); ws.getRange2("C1121").setValue("Vega"); ws.getRange2("C1122").setValue("FALSE"); ws.getRange2("C1123").setValue("TRUE"); ws.getRange2("D1101").setValue("1"); ws.getRange2("D1102").setValue("2"); ws.getRange2("D1103").setValue("3"); ws.getRange2("D1104").setValue("4"); ws.getRange2("D1105").setValue("5"); ws.getRange2("D1106").setValue("6"); ws.getRange2("D1107").setValue("7"); ws.getRange2("D1108").setValue("8"); ws.getRange2("D1109").setValue("9"); ws.getRange2("D1110").setValue("10"); ws.getRange2("D1111").setValue("11"); ws.getRange2("D1112").setValue("12"); ws.getRange2("D1113").setValue("13"); ws.getRange2("D1114").setValue("14"); ws.getRange2("D1115").setValue("15"); ws.getRange2("D1116").setValue("16"); ws.getRange2("D1117").setValue("17"); ws.getRange2("D1118").setValue("18"); ws.getRange2("D1119").setValue("19"); ws.getRange2("D1120").setValue("20"); ws.getRange2("D1121").setValue("21"); ws.getRange2("D1122").setValue("22"); ws.getRange2("D1123").setValue("23"); ws.getRange2("K100:Z200").cleanAll(); ws.getRange2("K100").setValue("SCALE 1"); ws.getRange2("K101").setValue("$"); ws.getRange2("K102").setValue(""); ws.getRange2("K103").setValue("0"); ws.getRange2("K104").setValue("88"); ws.getRange2("K105").setValue("371"); ws.getRange2("K106").setValue("515"); ws.getRange2("K107").setValue("932"); ws.getRange2("K108").setValue("1957"); ws.getRange2("K109").setValue("3111"); ws.getRange2("K110").setValue(""); ws.getRange2("K111").setValue(""); ws.getRange2("K112").setValue(""); ws.getRange2("K113").setValue(""); ws.getRange2("L100").setValue(""); ws.getRange2("L101").setValue("a"); ws.getRange2("L102").setValue(""); ws.getRange2("L103").setValue("0.19"); ws.getRange2("L104").setValue("0.2348"); ws.getRange2("L105").setValue("0.219"); ws.getRange2("L106").setValue("0.3477"); ws.getRange2("L107").setValue("0.345"); ws.getRange2("L108").setValue("0.39"); ws.getRange2("L109").setValue("0.47"); ws.getRange2("L110").setValue("1"); ws.getRange2("L111").setValue("2"); ws.getRange2("L112").setValue("3"); ws.getRange2("L113").setValue("4"); ws.getRange2("N100").setValue("SCALE 2"); ws.getRange2("N101").setValue("$"); ws.getRange2("N102").setValue(""); ws.getRange2("N103").setValue("0"); ws.getRange2("N104").setValue("359"); ws.getRange2("N105").setValue("438"); ws.getRange2("N106").setValue("548"); ws.getRange2("N107").setValue("721"); ws.getRange2("N108").setValue("865"); ws.getRange2("N109").setValue("1282"); ws.getRange2("N110").setValue("2307"); ws.getRange2("N111").setValue("3461"); ws.getRange2("N112").setValue(""); ws.getRange2("N113").setValue(""); ws.getRange2("N114").setValue(""); ws.getRange2("O100").setValue(""); ws.getRange2("O101").setValue("a"); ws.getRange2("O102").setValue(""); ws.getRange2("O103").setValue(""); ws.getRange2("O104").setValue("0.19"); ws.getRange2("O105").setValue("0.29"); ws.getRange2("O106").setValue("0.21"); ws.getRange2("O107").setValue("0.219"); ws.getRange2("O108").setValue("0.3477"); ws.getRange2("O109").setValue("0.345"); ws.getRange2("O110").setValue("0.39"); ws.getRange2("O111").setValue("0.47"); ws.getRange2("O112").setValue("1"); ws.getRange2("O113").setValue("2"); ws.getRange2("O114").setValue("3"); ws.getRange2("AE101:AF120").cleanAll(); ws.getRange2("AE101").setValue("String"); ws.getRange2("AE102").setValue("1"); ws.getRange2("AE103").setValue("2"); ws.getRange2("AE104").setValue("3"); ws.getRange2("AE105").setValue("#VALUE!"); ws.getRange2("AE106").setValue("#NUM!"); ws.getRange2("AE107").setValue("#DIV/0!"); ws.getRange2("AE108").setValue("TRUE"); ws.getRange2("AE109").setValue("Sandra"); ws.getRange2("AE113").setValue("5"); ws.getRange2("AF101").setValue("1"); ws.getRange2("AF102").setValue("2"); ws.getRange2("AF103").setValue("3"); ws.getRange2("AF104").setValue("4"); ws.getRange2("AF105").setValue("5"); ws.getRange2("AF106").setValue("6"); ws.getRange2("AF107").setValue("7"); ws.getRange2("AF108").setValue("8"); ws.getRange2("AF109").setValue("9"); ws.getRange2("AF110").setValue("10"); ws.getRange2("AF111").setValue("11"); ws.getRange2("AF112").setValue("12"); ws.getRange2("AF113").setValue("13"); ws.getRange2("G101").setValue("Aa"); ws.getRange2("G102").setValue("Ae"); ws.getRange2("G103").setValue("Ba"); ws.getRange2("G104").setValue("Be"); ws.getRange2("G105").setValue("CA"); ws.getRange2("G106").setValue("CE"); ws.getRange2("G107").setValue("DA"); ws.getRange2("G108").setValue("DE"); ws.getRange2("G109").setValue("Ha"); ws.getRange2("G110").setValue("HE"); ws.getRange2("G111").setValue("Ia"); ws.getRange2("G112").setValue("Ie"); ws.getRange2("G113").setValue("Ja"); ws.getRange2("G114").setValue("Je"); ws.getRange2("G115").setValue("Ka"); ws.getRange2("G116").setValue("Ke"); ws.getRange2("M101:M134").setValue("W"); ws.getRange2("M127").setValue("1"); ws.getRange2("M128").setValue("2"); ws.getRange2("M129").setValue("3"); ws.getRange2("M130").setValue("4"); ws.getRange2("M131").setValue("5"); ws.getRange2("M132").setValue("6"); ws.getRange2("M133").setValue("7"); ws.getRange2("M134").setValue("8"); ws.getRange2("N129").setValue("Looked result(3)"); ws.getRange2("AA1101").setValue("1"); ws.getRange2("AA1102").setValue("1"); ws.getRange2("AA1103").setValue("1"); ws.getRange2("AA1104").setValue("1"); ws.getRange2("AA1105").setValue("#N/A"); ws.getRange2("AA1106").setValue("1"); ws.getRange2("AA1107").setValue("1"); ws.getRange2("AA1108").setValue("1"); ws.getRange2("AA1109").setValue("1"); ws.getRange2("AA1110").setValue("1"); ws.getRange2("AB1101").setValue("1"); ws.getRange2("AB1102").setValue("2"); ws.getRange2("AB1103").setValue("3"); ws.getRange2("AB1104").setValue("4"); ws.getRange2("AB1105").setValue("5"); ws.getRange2("AB1106").setValue("6"); ws.getRange2("AB1107").setValue("7"); ws.getRange2("AB1108").setValue("8"); ws.getRange2("AB1109").setValue("9"); ws.getRange2("AB1110").setValue("10"); ws.getRange2("AA1111").setValue("1"); ws.getRange2("AA1112").setValue("1"); ws.getRange2("AA1113").setValue("1"); ws.getRange2("AA1114").setValue("1"); ws.getRange2("AA1115").setValue(""); ws.getRange2("AA1116").setValue("a"); ws.getRange2("AA1117").setValue("2"); ws.getRange2("AA1118").setValue("1"); ws.getRange2("AA1119").setValue("1"); ws.getRange2("AA1120").setValue("1"); ws.getRange2("AB1111").setValue("1"); ws.getRange2("AB1112").setValue("2"); ws.getRange2("AB1113").setValue("3"); ws.getRange2("AB1114").setValue("4"); ws.getRange2("AB1115").setValue("5"); ws.getRange2("AB1116").setValue("6"); ws.getRange2("AB1117").setValue("7"); ws.getRange2("AB1118").setValue("8"); ws.getRange2("AB1119").setValue("9"); ws.getRange2("AB1120").setValue("10"); ws.getRange2("AA1121").setValue("2"); ws.getRange2("AA1122").setValue("a"); ws.getRange2("AA1123").setValue("#N/A"); ws.getRange2("AA1124").setValue("7"); ws.getRange2("AA1125").setValue(""); ws.getRange2("AA1126").setValue("0"); ws.getRange2("AA1127").setValue("0"); ws.getRange2("AA1128").setValue("1"); ws.getRange2("AA1129").setValue("1"); ws.getRange2("AA1130").setValue("1"); ws.getRange2("AB1121").setValue("1"); ws.getRange2("AB1122").setValue("2"); ws.getRange2("AB1123").setValue("3"); ws.getRange2("AB1124").setValue("4"); ws.getRange2("AB1125").setValue("5"); ws.getRange2("AB1126").setValue("6"); ws.getRange2("AB1127").setValue("7"); ws.getRange2("AB1128").setValue("8"); ws.getRange2("AB1129").setValue("9"); ws.getRange2("AB1130").setValue("10"); ws.getRange2("AA1131").setValue("1"); ws.getRange2("AA1132").setValue("0"); ws.getRange2("AA1133").setValue("0"); ws.getRange2("AA1134").setValue("0"); ws.getRange2("AA1135").setValue(""); ws.getRange2("AA1136").setValue(" "); ws.getRange2("AA1137").setValue("a"); ws.getRange2("AA1138").setValue("b"); ws.getRange2("AA1139").setValue("c"); ws.getRange2("AA1140").setValue("d"); ws.getRange2("AB1131").setValue("1"); ws.getRange2("AB1132").setValue("2"); ws.getRange2("AB1133").setValue("3"); ws.getRange2("AB1134").setValue("4"); ws.getRange2("AB1135").setValue("5"); ws.getRange2("AB1136").setValue("6"); ws.getRange2("AB1137").setValue("7"); ws.getRange2("AB1138").setValue("8"); ws.getRange2("AB1139").setValue("9"); ws.getRange2("AB1140").setValue("10"); const defName3D = new Asc.asc_CDefName('VLOOKUPTestName3D', ws.getName() + '!$C$1117'); const defName3D2 = new Asc.asc_CDefName('VLOOKUPTestName3D2', ws.getName() + '!$B$1102'); const defNameArea3D = new Asc.asc_CDefName('VLOOKUPTestNameArea3D', ws.getName() + '!$C$1101:$D$1123'); wb.editDefinesNames(null, defName3D); wb.editDefinesNames(null, defNameArea3D); wb.editDefinesNames(null, defName3D2); AscCommonExcel.g_oVLOOKUPCache.clean(); // Positive сases: // Case #1: Number, Array, Number oParser = new parserFormula("VLOOKUP(1,{1,2,3;2,3,4},2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #2: Number, Array, Number, Number (Number -> Boolean, TRUE) oParser = new parserFormula("VLOOKUP(1,{1,2,3;2,3,4},3,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); // Case #3: Array, Array, Number oParser = new parserFormula("VLOOKUP({2,3,4},{1,2,3;2,3,4},2)", "A2", ws); assert.ok(oParser.parse(), "Parse VLOOKUP({2,3,4},{1,2,3;2,3,4},2)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 3, "Result of VLOOKUP({2,3,4},{1,2,3;2,3,4},2)[0,0]"); assert.strictEqual(array.getElementRowCol(0,1).getValue(), 3, "Result of VLOOKUP({2,3,4},{1,2,3;2,3,4},2)[0,1]"); assert.strictEqual(array.getElementRowCol(0,2).getValue(), 3, "Result of VLOOKUP({2,3,4},{1,2,3;2,3,4},2)[0,2]"); // Case #4: Array, Array, Number, FALSE oParser = new parserFormula("VLOOKUP({2,3,4},{1,2,3;2,3,4},2,FALSE)", "A2", ws); assert.ok(oParser.parse(), "Parse VLOOKUP({2,3,4},{1,2,3;2,3,4},2,FALSE)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 3, "Result of VLOOKUP({2,3,4},{1,2,3;2,3,4},2,FALSE)[0,0]"); assert.strictEqual(array.getElementRowCol(0,1).getValue(), "#N/A", "Result of VLOOKUP({2,3,4},{1,2,3;2,3,4},2,FALSE)[0,1]"); assert.strictEqual(array.getElementRowCol(0,2).getValue(), "#N/A", "Result of VLOOKUP({2,3,4},{1,2,3;2,3,4},2,FALSE)[0,2]"); // Case #5: Array, Array, Array oParser = new parserFormula("VLOOKUP({2,3,4},{1,2,3;2,3,4},{1,5,6})", "A2", ws); assert.ok(oParser.parse(), "Parse VLOOKUP({2,3,4},{1,2,3;2,3,4},{1,5,6})"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 2, "Result of VLOOKUP({2,3,4},{1,2,3;2,3,4},{1,5,6})[0,0]"); assert.strictEqual(array.getElementRowCol(0,1).getValue(), 2, "Result of VLOOKUP({2,3,4},{1,2,3;2,3,4},{1,5,6})[0,1]"); assert.strictEqual(array.getElementRowCol(0,2).getValue(), 2, "Result of VLOOKUP({2,3,4},{1,2,3;2,3,4},{1,5,6})[0,2]"); // Case #6: Array, Array, Array oParser = new parserFormula("VLOOKUP({2,3,4},{1,2,3;2,3,4;6,7,8},{1,5,6})", "A2", ws); assert.ok(oParser.parse(), "Parse VLOOKUP({2,3,4},{1,2,3;2,3,4;6,7,8},{1,5,6})"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 2, "Result of VLOOKUP({2,3,4},{1,2,3;2,3,4;6,7,8},{1,5,6})[0,0]"); assert.strictEqual(array.getElementRowCol(0,1).getValue(), 2, "Result of VLOOKUP({2,3,4},{1,2,3;2,3,4;6,7,8},{1,5,6})[0,1]"); assert.strictEqual(array.getElementRowCol(0,2).getValue(), 2, "Result of VLOOKUP({2,3,4},{1,2,3;2,3,4;6,7,8},{1,5,6})[0,2]"); // Case #7: Array, Array, Array oParser = new parserFormula("VLOOKUP({5,3,4},{1,2,3;2,3,4;6,7,8},{1,5,6})", "A2", ws); assert.ok(oParser.parse(), "Parse VLOOKUP({5,3,4},{1,2,3;2,3,4;6,7,8},{1,5,6})"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 2, "Result of VLOOKUP({5,3,4},{1,2,3;2,3,4;6,7,8},{1,5,6})[0,0]"); assert.strictEqual(array.getElementRowCol(0,1).getValue(), 2, "Result of VLOOKUP({5,3,4},{1,2,3;2,3,4;6,7,8},{1,5,6})[0,1]"); assert.strictEqual(array.getElementRowCol(0,2).getValue(), 2, "Result of VLOOKUP({5,3,4},{1,2,3;2,3,4;6,7,8},{1,5,6})[0,2]"); // Case #8: Array, Array, Number oParser = new parserFormula("VLOOKUP({2,3,4},{1,2,3;2,3,4;6,7,8},1)", "A2", ws); assert.ok(oParser.parse(), "Parse VLOOKUP({2,3,4},{1,2,3;2,3,4;6,7,8},1)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 2, "Result of VLOOKUP({2,3,4},{1,2,3;2,3,4;6,7,8},1)[0,0]"); assert.strictEqual(array.getElementRowCol(0,1).getValue(), 2, "Result of VLOOKUP({2,3,4},{1,2,3;2,3,4;6,7,8},1)[0,1]"); assert.strictEqual(array.getElementRowCol(0,2).getValue(), 2, "Result of VLOOKUP({2,3,4},{1,2,3;2,3,4;6,7,8},1)[0,2]"); // Case #9: Number, Array, Number oParser = new parserFormula("VLOOKUP(4,{1,2,3;2,3,4;6,7,8},2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); // Case #10: Number, Array, Number oParser = new parserFormula("VLOOKUP(4,{1,2,3;2,3,4;6,7,8},3)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); // Case #11: Empty, Array, Number. Array contains zero (Empty -> Zero) oParser = new parserFormula('VLOOKUP(,{0;1;2},1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); // Case #12: Empty, Array, Number. Array contains <= zero (Empty -> Zero) oParser = new parserFormula('VLOOKUP(,{-1;2;3},1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -1); // Case #13: Number, Array, Number. Array contains several suitable values oParser = new parserFormula('VLOOKUP(1,{0,1;1,2;"c",3;1,4;1,5;"b",6;2,7},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5); // Case #14: String, Array, Number. Array contains several suitable values, Sorted only second half oParser = new parserFormula('VLOOKUP("a",{"c",1;"a",2;"5",3;"a",4;"a",5;"c",6;"a",7},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5); // Case #15: Empty, Array, Number. Array contains only empty strings oParser = new parserFormula('VLOOKUP(,{"",1;"",2;"",3;"",4;"",5;"",6;"",7},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #16: Empty, Array, Number. Array contains only empty strings and zero in second half oParser = new parserFormula('VLOOKUP(,{"",1;"",2;"",3;"",4;"",5;0,6;"",7},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 6); // Case #17: Empty, Array, Number. Array contains only empty strings and zero in fist half oParser = new parserFormula('VLOOKUP(,{"",1;0,2;"",3;"",4;"",5;"",6;"",7},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #18: Error, Array, Number oParser = new parserFormula('VLOOKUP(#N/A,{"",1;0,2;#N/A,3;#N/A,4;"",5;"",6;"",7},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #19: Number, Array, Number. Array not contains exact match, but contains value < seachValue oParser = new parserFormula('VLOOKUP(25,{26,1;66,2;13,3;24,4;70,5;"",6;"",7},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); // Case #20: Number, Array, Number, Number (Number -> Boolean, FALSE) oParser = new parserFormula("VLOOKUP(1,{1,2,3;2,3,4},3,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); // Case #21: Number, Array, Number, Boolean. Array not sorted oParser = new parserFormula("VLOOKUP(1,{5,1;8,2;3,3;-20,4;1,5},2,FALSE)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5); // Case #22: String, Array, Number, Boolean. Array not sorted oParser = new parserFormula('VLOOKUP("a",{"b",1;"a",2;"-c",3;"k",4;1,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #23: Empty, Array, Number, Boolean. Array not sorted oParser = new parserFormula('VLOOKUP(,{0,1;0,2;1,3;"k",4;1,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); // Case #24: Number, Array, Number, Boolean. Array not sorted and contains similar values oParser = new parserFormula("VLOOKUP(1,{-1,1;2,2;5,3;1,4;1,5},2,FALSE)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); // Case #25: String, Array, Number, Boolean. Array not sorted and contains similar values oParser = new parserFormula('VLOOKUP("a",{"b",1;"a",2;"a",3;"a",4;"c",5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #26: Boolean, Array, Number, Boolean. Array not sorted and contains similar values oParser = new parserFormula('VLOOKUP(FALSE,{TRUE,1;FALSE,2;FALSE,3;"a",4;FALSE,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #27: Empty, Array, Number, Boolean. Array not sorted and contains errors, similar zero values oParser = new parserFormula('VLOOKUP(,{#N/A,1;2,2;0,3;0,4;#N/A,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); // Case #28: Empty, Array, Number, Boolean. Array not sorted and contains errors, similar zero values, Booleans oParser = new parserFormula('VLOOKUP(,{FALSE,1;TRUE,2;0,3;" ",4;#N/A,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); // Case #29: String, Array, Number, Boolean. Trying to find empty string oParser = new parserFormula('VLOOKUP("",{"",1;" ",2;0,3;" ",4;#N/A,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); // Case #30: String, Array, Number, Boolean. Trying to find string with space oParser = new parserFormula('VLOOKUP(" ",{"",1;" ",2;0,3;" ",4;#N/A,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); // Case #31: Number, Area, Number oParser = new parserFormula("VLOOKUP(1,A502:C510,2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2.17); // Case #32: Number, Area, Number, TRUE oParser = new parserFormula("VLOOKUP(1,A502:C510,3,TRUE)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 100.00); // Case #33: Number, Area, Number, TRUE oParser = new parserFormula("VLOOKUP(2,A502:C510,2,TRUE)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1.71); // Case #34: Number, Area, Array oParser = new parserFormula("VLOOKUP(5,BA100:BB102,{1,1,1})", "A2", ws); assert.ok(oParser.parse(), "Parse VLOOKUP(5,BA100:BB102,{1,1,1})"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 4, "Result of VLOOKUP(5,BA100:BB102,{1,1,1})[0,0]"); assert.strictEqual(array.getElementRowCol(0,1).getValue(), 4, "Result of VLOOKUP(5,BA100:BB102,{1,1,1})[0,1]"); assert.strictEqual(array.getElementRowCol(0,2).getValue(), 4, "Result of VLOOKUP(5,BA100:BB102,{1,1,1})[0,2]"); // Case #35: Array, Area, Ref oParser = new parserFormula("VLOOKUP({2;4;40},BA100:BB102,BE100)", "A2", ws); assert.ok(oParser.parse(), "Parse VLOOKUP({2;4;40},BA100:BB102,BE100)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 2, "Result of VLOOKUP({2;4;40},BA100:BB102,BE100)[0,0]"); assert.strictEqual(array.getElementRowCol(1,0).getValue(), 4, "Result of VLOOKUP({2;4;40},BA100:BB102,BE100)[1,0]"); assert.strictEqual(array.getElementRowCol(2,0).getValue(), 40, "Result of VLOOKUP({2;4;40},BA100:BB102,BE100)[2,0]"); // Case #36: Array, Area, Ref oParser = new parserFormula("VLOOKUP({2;4;40},BA100:BB102,BF100)", "A2", ws); assert.ok(oParser.parse(), "Parse VLOOKUP({2;4;40},BA100:BB102,BF100)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 1, "Result of VLOOKUP({2;4;40},A100:B102,BF100)[0,0]"); assert.strictEqual(array.getElementRowCol(1,0).getValue(), 2, "Result of VLOOKUP({2;4;40},A100:B102,BF100)[1,0]"); assert.strictEqual(array.getElementRowCol(2,0).getValue(), 3, "Result of VLOOKUP({2;4;40},A100:B102,BF100)[2,0]"); // Case #37: Array, Area, Array oParser = new parserFormula("VLOOKUP({2;4;40},BA100:BB102,{1,2,3;1,1,1})", "A2", ws); assert.ok(oParser.parse(), "Parse VLOOKUP({2;4;40},BA100:BB102,{1,2,3;1,1,1})"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 2, "Result of VLOOKUP({2;4;40},BA100:BB102,{1,2,3;1,1,1})[0,0]"); assert.strictEqual(array.getElementRowCol(1,0).getValue(), 4, "Result of VLOOKUP({2;4;40},BA100:BB102,{1,2,3;1,1,1})[1,0]"); assert.strictEqual(array.getElementRowCol(2,0).getValue(), 40, "Result of VLOOKUP({2;4;40},BA100:BB102,{1,2,3;1,1,1})[2,0]"); // Case #38: Number, Area, Number oParser = new parserFormula("VLOOKUP(2,A502:C510,2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1.71); // Case #39: Empty, Area, Number. Area contains zeros oParser = new parserFormula('VLOOKUP(,D1101:C1123,2,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(,D1101:C1123,2,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), 2, 'Result of VLOOKUP(,D1101:C1123,2,TRUE)'); // Case #40: Number, Area, Number oParser = new parserFormula('VLOOKUP(2.4,D1101:C1123,2,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(2.4,D1101:C1123,2,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), 5, 'Result of VLOOKUP(2.4,D1101:C1123,2,TRUE)'); // Case #41: String, Area, Number. Area not contains exact match, but contains < seachValue oParser = new parserFormula('VLOOKUP("VIOLET",D1101:C1123,2,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP("VIOLET",D1101:C1123,2,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), 21, 'Result of VLOOKUP("VIOLET",D1101:C1123,2,TRUE)'); // Case #42: Number, Area, Number. Area not contains exact match, but contains value < seachValue oParser = new parserFormula('VLOOKUP(2.3,D1101:C1123,2,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(2.3,D1101:C1123,2,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), 3, 'Result of VLOOKUP(2.3,D1101:C1123,2,TRUE)'); // Case #43: String, Area, Number. Area contains exact match oParser = new parserFormula('VLOOKUP("cIaNo",D1101:C1123,2,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP("cIaNo",D1101:C1123,2,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), 18, 'Result of VLOOKUP("cIaNo",D1101:C1123,2,TRUE)'); // Case #44: Boolean, Area, Number. Area contains exact match oParser = new parserFormula('VLOOKUP(FALSE,D1101:C1123,2,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(FALSE,D1101:C1123,2,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), 22, 'Result of VLOOKUP(FALSE,D1101:C1123,2,TRUE)'); // Case #45: Number, Area, Number. For bug 63026. cEmpty tests. oParser = new parserFormula('VLOOKUP(576,K100:L113,2)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(576,K100:L113,2)'); assert.strictEqual(oParser.calculate().getValue(), 0.3477, 'Result of VLOOKUP(576,K100:L113,2)'); // Case #46: Number, Area, Number. For bug 63026. cEmpty tests. oParser = new parserFormula('VLOOKUP(576,N100:O114,2)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(576,N100:O114,2)'); assert.strictEqual(oParser.calculate().getValue(), 0.21, 'Result of VLOOKUP(576,N100:O114,2)'); // Case #47.1: Ref, Area, Number. For bug 54560. oParser = new parserFormula('VLOOKUP(G101,G101:G116,1)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(G101,G101:G116,1)'); assert.strictEqual(oParser.calculate().getValue(), "Aa", 'Result of VLOOKUP(G101,G101:G116,1)'); // Case #47.2: Ref, Area, Number. For bug 54560. oParser = new parserFormula('VLOOKUP(G102,G101:G116,1)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(G102,G101:G116,1)'); assert.strictEqual(oParser.calculate().getValue(), "Ae", 'Result of VLOOKUP(A102,G101:G116,1)'); // Case #47.3: Ref, Area, Number. For bug 54560. oParser = new parserFormula('VLOOKUP(G103,G101:G116,1)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(G103,G101:G116,1)'); assert.strictEqual(oParser.calculate().getValue(), "Ba", 'Result of VLOOKUP(A103,G101:G116,1)'); // Case #47.4: Ref, Area, Number. For bug 54560. oParser = new parserFormula('VLOOKUP(G104,G101:G116,1)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(G104,G101:G116,1)'); assert.strictEqual(oParser.calculate().getValue(), "Be", 'Result of VLOOKUP(A104,G101:G116,1)'); // Case #47.5: Ref, Area, Number. For bug 54560. oParser = new parserFormula('VLOOKUP(G105,G101:G116,1)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(G105,G101:G116,1)'); assert.strictEqual(oParser.calculate().getValue(), "CA", 'Result of VLOOKUP(A105,G101:G116,1)'); // Case #47.6: Ref, Area, Number. For bug 54560. oParser = new parserFormula('VLOOKUP(G106,G101:G116,1)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(G106,G101:G116,1)'); assert.strictEqual(oParser.calculate().getValue(), "CE", 'Result of VLOOKUP(A106,G101:G116,1)'); // Case #47.7: Ref, Area, Number. For bug 54560. oParser = new parserFormula('VLOOKUP(G107,G101:G116,1)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(G107,G101:G116,1)'); assert.strictEqual(oParser.calculate().getValue(), "DA", 'Result of VLOOKUP(A107,G101:G116,1)'); // Case #47.8: Ref, Area, Number. For bug 54560. oParser = new parserFormula('VLOOKUP(G108,G101:G116,1)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(G108,G101:G116,1)'); assert.strictEqual(oParser.calculate().getValue(), "DE", 'Result of VLOOKUP(A108,G101:G116,1)'); // Case #47.9: String, Area, Number. For bug 54560. oParser = new parserFormula('VLOOKUP("Ha",G101:G116,1)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP("Ha",G101:G116,1)'); assert.strictEqual(oParser.calculate().getValue(), "Ha", 'Result of VLOOKUP(A109,G101:G116,1)'); // Case #47.10: Ref, Area, Number. For bug 54560. oParser = new parserFormula('VLOOKUP(G109,G101:G116,1)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(G109,G101:G116,1)'); assert.strictEqual(oParser.calculate().getValue(), "Ha", 'Result of VLOOKUP(A109,G101:G116,1)'); // Case #47.11: Ref, Area, Number. For bug 54560. oParser = new parserFormula('VLOOKUP(G110,G101:G116,1)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(G110,G101:G116,1)'); assert.strictEqual(oParser.calculate().getValue(), "HE", 'Result of VLOOKUP(A110,G101:G116,1)'); // Case #47.12: Ref, Area, Number. For bug 54560. oParser = new parserFormula('VLOOKUP(G111,G101:G116,1)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(G111,G101:G116,1)'); assert.strictEqual(oParser.calculate().getValue(), "Ia", 'Result of VLOOKUP(A111,G101:G116,1)'); // Case #47.13: Ref, Area, Number. For bug 54560. oParser = new parserFormula('VLOOKUP(G112,G101:G116,1)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(G112,G101:G116,1)'); assert.strictEqual(oParser.calculate().getValue(), "Ie", 'Result of VLOOKUP(A112,G101:G116,1)'); // Case #47.14: Ref, Area, Number. For bug 54560. oParser = new parserFormula('VLOOKUP(G113,G101:G116,1)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(G113,G101:G116,1)'); assert.strictEqual(oParser.calculate().getValue(), "Ja", 'Result of VLOOKUP(A113,G101:G116,1)'); // Case #47.15: Ref, Area, Number. For bug 54560. oParser = new parserFormula('VLOOKUP(G114,G101:G116,1)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(G114,G101:G116,1)'); assert.strictEqual(oParser.calculate().getValue(), "Je", 'Result of VLOOKUP(A114,G101:G116,1)'); // Case #47.16: Ref, Area, Number. For bug 54560. oParser = new parserFormula('VLOOKUP(G115,G101:G116,1)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(G115,G101:G116,1)'); assert.strictEqual(oParser.calculate().getValue(), "Ka", 'Result of VLOOKUP(A115,G101:G116,1)'); // Case #47.17: Ref, Area, Number. For bug 54560. oParser = new parserFormula('VLOOKUP(G116,G101:G116,1)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(G116,G101:G116,1)'); assert.strictEqual(oParser.calculate().getValue(), "Ke", 'Result of VLOOKUP(A116,G101:G116,1)'); // Case #48: Number, Area, Number. For bug 67099. oParser = new parserFormula('VLOOKUP(3,M101:N134,2)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(3,M101:N134,2)'); assert.strictEqual(oParser.calculate().getValue(), "Looked result(3)", 'Result of VLOOKUP(3,M101:N134,2)'); // Case #49: Area, Area, Number. For bug 67099. oParser = new parserFormula('VLOOKUP(M129,M101:N134,2)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(M129,M101:N134,2)'); assert.strictEqual(oParser.calculate().getValue(), "Looked result(3)", 'Result of VLOOKUP(M129,M101:N134,2)'); // Case #50: Number, Area, Number. Area contains same values in second half. oParser = new parserFormula('VLOOKUP(1,AA1101:AB1110,2)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(1,AA1101:AB1110,2)'); assert.strictEqual(oParser.calculate().getValue(), 10, 'Result of VLOOKUP(1,AA1101:AB1110,2)'); // Case #51: Number, Area, Number. Area contains same values in first half. oParser = new parserFormula('VLOOKUP(1,AA1111:AB1120,2)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(1,AA1111:AB1120,2)'); assert.strictEqual(oParser.calculate().getValue(), 4, 'Result of VLOOKUP(1,AA1111:AB1120,2)'); // Case #52: Number, Area, Number. Area contains same values in second half and has error oParser = new parserFormula('VLOOKUP(1,AA1121:AB1130,2)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(1,AA1121:AB1130,2)'); assert.strictEqual(oParser.calculate().getValue(), 10, 'Result of VLOOKUP(1,AA1121:AB1130,2)'); // Case #53: Number, Area, Number. Area contains <= value in first half and exact match as first element oParser = new parserFormula('VLOOKUP(1,AA1131:AB1140,2)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(1,AA1131:AB1140,2)'); assert.strictEqual(oParser.calculate().getValue(), 4, 'Result of VLOOKUP(1,AA1131:AB1140,2)'); // Case #54: Number, Area, Number oParser = new parserFormula('VLOOKUP(2.24,A1101:B1113,2,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(2.24,A1101:B1113,2,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), 4, 'Result of VLOOKUP("2.24",A1101:B1113,2,FALSE)'); // Case #55: Number, Area, Number oParser = new parserFormula('VLOOKUP("AnyStringValue2",A1101:B1113,2,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP("AnyStringValue2",A1101:B1113,2,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of VLOOKUP("AnyStringValue2",A1101:B1113,2,FALSE)'); // Case #56: Number, Area, Number oParser = new parserFormula('VLOOKUP("Sandra",A1101:B1113,2,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP("Sandra",A1101:B1113,2,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), 9, 'Result of VLOOKUP("Sandra",A1101:B1113,2,FALSE)'); // Case #57: Number, Area, Number oParser = new parserFormula('VLOOKUP(,A1101:B1113,2,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(,A1101:B1113,2,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), 12, 'Result of VLOOKUP(,A1101:B1113,2,FALSE)'); // Case #58: String, Area, Number. For bug 65016 oParser = new parserFormula('VLOOKUP("SANDRA",AE101:AF113,2,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP("SANDRA",AE101:AF113,2,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), 9, 'Result of VLOOKUP("SANDRA",AE101:AF113,2,FALSE)'); // Case #59: Boolean, Area, Number. For bug 65016 oParser = new parserFormula('VLOOKUP(TRUE,AE101:AF113,2,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(TRUE,AE101:AF113,2,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), 8, 'Result of VLOOKUP(TRUE,AE101:AF113,2,FALSE)'); // Case #60: Number, Area, Number. For bug 65016 oParser = new parserFormula('VLOOKUP(5,AE101:AF113,2,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(5,AE101:AF113,2,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), 13, 'Result of VLOOKUP(5,AE101:AF113,2,FALSE)'); // Case #61: Name3D, Name3D, Name3D, Boolean oParser = new parserFormula('VLOOKUP(VLOOKUPTestName3D,VLOOKUPTestNameArea3D,2,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(VLOOKUPTestName3D,VLOOKUPTestNameArea3D,VLOOKUPTestName3D2,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), 17, 'Result of VLOOKUP(VLOOKUPTestName3D,VLOOKUPTestNameArea3D,2,FALSE)'); // Case #62: Ref3D, Area3D, Area3D, Area3D oParser = new parserFormula('VLOOKUP(' + ws.getName() + '!$C$1117,' + ws.getName() + '!$C$1101:$D$1123,'+ ws.getName() + '!$B$1102,'+ ws.getName() + '!$C$1122)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(' + ws.getName() + '!$C$1117,' + ws.getName() + '!$C$1101:$D$1123,'+ ws.getName() + '!$B$1102,'+ ws.getName() + '!$C$1122)'); assert.strictEqual(oParser.calculate().getValue(), 17, 'Result of VLOOKUP(' + ws.getName() + '!$C$1117,' + ws.getName() + '!$C$1101:$D$1123,'+ ws.getName() + '!$B$1102,'+ ws.getName() + '!$C$1122)'); // Case #63: Formula, Name3D, Formula, Formula oParser = new parserFormula('VLOOKUP(ABS(2),VLOOKUPTestNameArea3D,ABS(2),1=1)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(ABS(2),VLOOKUPTestNameArea3D,ABS(2),1=1)'); assert.strictEqual(oParser.calculate().getValue(), 2, 'Result of VLOOKUP(ABS(2),VLOOKUPTestNameArea3D,ABS(2),1=1)'); ws.getRange2("A601").setValue("a"); ws.getRange2("A602").setValue("b"); ws.getRange2("A603").setValue("c"); ws.getRange2("A604").setValue("d"); ws.getRange2("A605").setValue("e"); ws.getRange2("A606").setValue("f"); ws.getRange2("A607").setValue("g"); ws.getRange2("A608").setValue("i"); ws.getRange2("A609").setValue("h"); ws.getRange2("A610").setValue("j"); ws.getRange2("B601").setValue("1"); ws.getRange2("B602").setValue("2"); ws.getRange2("B603").setValue("3"); ws.getRange2("B604").setValue("4"); ws.getRange2("B605").setValue("5"); ws.getRange2("B606").setValue("6"); ws.getRange2("B607").setValue("7"); ws.getRange2("B608").setValue("8"); ws.getRange2("B609").setValue("9"); ws.getRange2("B610").setValue("10"); ws.getRange2("A611").setValue("=B611+1"); ws.getRange2("B611").setValue('=VLOOKUP("a",A601:B610,2,FALSE)'); wb.dependencyFormulas.unlockRecal(); // Case #63: Formula. Tests for bug 77578 oParser = new parserFormula("B611+A611", "A2", ws); assert.ok(oParser.parse(), "Parse B611+A611"); assert.strictEqual(oParser.calculate().getValue(), 3); // Case #64: Formula. Tests for bug 77705 ws.insertRowsBefore(610,1) assert.strictEqual(ws.getRange2("A612").getValue(), "2"); wb.dependencyFormulas.lockRecal(); // Case #65: Formula. ws.getRange2("A702").setValue("1"); ws.getRange2("A703").setValue("2"); ws.getRange2("A704").setValue("3"); ws.getRange2("B702").setValue("a1"); ws.getRange2("B703").setValue("a2"); ws.getRange2("B704").setValue("a3"); ws.getRange2("A706").setValue("=VLOOKUP(D706,A702:B704,2,FALSE)"); ws.getRange2("A707").setValue("=CONCAT(A706,A708)"); ws.getRange2("A708").setValue("=VLOOKUP(D708,A710:B712,2,FALSE)"); ws.getRange2("B706").setValue("a"); ws.getRange2("B707").setValue("b"); ws.getRange2("B708").setValue("c"); ws.getRange2("A710").setValue("4"); ws.getRange2("A711").setValue("5"); ws.getRange2("A712").setValue("6"); ws.getRange2("B710").setValue("a4"); ws.getRange2("B711").setValue("a5"); ws.getRange2("B712").setValue("a6"); ws.getRange2("D701").setValue("=VLOOKUP(A707,A702:B712,2,FALSE)"); ws.getRange2("D706").setValue("=1+E707"); ws.getRange2("D708").setValue("=4+E707"); ws.getRange2("E707").setValue("1"); wb.dependencyFormulas.unlockRecal(); assert.strictEqual(ws.getRange2("D701").getValue(), "b"); ws.getRange2("E707").setValue("2"); assert.strictEqual(ws.getRange2("D701").getValue(), "b"); ws.getRange2("E707").setValue("3"); assert.strictEqual(ws.getRange2("D701").getValue(), "#N/A"); wb.dependencyFormulas.lockRecal(); // Case #66: Iterative recursion test ws.getRange2("A801").setValue("0"); ws.getRange2("A802").setValue("=B802+D801"); ws.getRange2("A803").setValue("=B803+D802"); ws.getRange2("B801").setValue("=1+$C$801"); ws.getRange2("B802").setValue("=1+$C$801"); ws.getRange2("B803").setValue("=1+$C$801"); ws.getRange2("C801").setValue("3"); ws.getRange2("D801").setValue("=VLOOKUP(A801,A801:A803,1,FALSE)"); ws.getRange2("D802").setValue("=VLOOKUP(A802,A801:A803,1,FALSE)"); ws.getRange2("D803").setValue("=VLOOKUP(A803,A801:A803,1,FALSE)"); wb.dependencyFormulas.unlockRecal(); const api = ws.workbook.oApi; const oCalcSettings = api.asc_GetCalcSettings(); oCalcSettings.asc_setIterativeCalc(false); // Different with MS // assert.strictEqual(ws.getRange2("A803").getValue(), "8"); // assert.strictEqual(ws.getRange2("B803").getValue(), "4"); // assert.strictEqual(ws.getRange2("D803").getValue(), "8"); ws.getRange2("C801").setValue("2"); assert.strictEqual(ws.getRange2("A803").getValue(), "6"); assert.strictEqual(ws.getRange2("B803").getValue(), "3"); assert.strictEqual(ws.getRange2("D803").getValue(), "6"); wb.dependencyFormulas.lockRecal(); oCalcSettings.asc_setIterativeCalc(true); oCalcSettings.asc_setMaxIterations(2); wb.dependencyFormulas.unlockRecal(); ws.getRange2("C801").setValue("3"); assert.strictEqual(ws.getRange2("A803").getValue(), "8"); assert.strictEqual(ws.getRange2("B803").getValue(), "4"); assert.strictEqual(ws.getRange2("D803").getValue(), "8"); oCalcSettings.asc_setIterativeCalc(false); wb.dependencyFormulas.lockRecal(); //Case #67: Test for TypedMapCache ws.getRange2("AR901").setValue("a"); ws.getRange2("AR902").setValue("a"); ws.getRange2("AR903").setValue("a"); ws.getRange2("AR904").setValue("a"); ws.getRange2("AR905").setValue("a"); ws.getRange2("AS901").setValue("1"); ws.getRange2("AS902").setValue("2"); ws.getRange2("AS903").setValue("3"); ws.getRange2("AS904").setValue("4"); ws.getRange2("AS905").setValue("5"); wb.dependencyFormulas.unlockRecal(); ws.getRange2("AT902").setValue('=VLOOKUP(AT903,AR901:AS903,2,FALSE'); ws.getRange2("AT901").setValue('=VLOOKUP(AT903,AR903:AS905,2,FALSE'); ws.getRange2("AT903").setValue('a') wb.dependencyFormulas.lockRecal(); assert.strictEqual(ws.getRange2("AT901").getValue(), "3"); assert.strictEqual(ws.getRange2("AT902").getValue(), "1"); // Negative Cases: // Case #1: Array, Array, Array with wrong data oParser = new parserFormula("VLOOKUP({2,3,4},{1,2,3;2,3,4},{4,5,6})", "A2", ws); assert.ok(oParser.parse(), "Parse VLOOKUP({2,3,4},{1,2,3;2,3,4},{4,5,6})"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), "#REF!", "Result of VLOOKUP({2,3,4},{1,2,3;2,3,4},{4,5,6})[0,0]"); assert.strictEqual(array.getElementRowCol(0,1).getValue(), "#REF!", "Result of VLOOKUP({2,3,4},{1,2,3;2,3,4},{4,5,6})[0,1]"); assert.strictEqual(array.getElementRowCol(0,2).getValue(), "#REF!", "Result of VLOOKUP({2,3,4},{1,2,3;2,3,4},{4,5,6})[0,2]"); // Case #2: Number, Array, Number. Out of range arg3 oParser = new parserFormula("VLOOKUP(4,{1,2,3;2,3,4;6,7,8},5)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#REF!"); // Case #3: String, Array, Number. Array not contains search type oParser = new parserFormula('VLOOKUP("a",{1,2,3;2,3,4;6,7,8},3)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #4: Boolean, Array, Number. Array not contains search type oParser = new parserFormula('VLOOKUP(FALSE,{1,2,3;2,3,4;6,7,8},3)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #5: Error, Array, Number. Search value is Error oParser = new parserFormula('VLOOKUP(#N/A,{1,2,3;2,3,4;6,7,8},3)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #6: Empty, Array, Number. Array not contains value <= 0 (Empty -> Zero) oParser = new parserFormula('VLOOKUP(,{1;2;3},1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #7: Error, Array, Number. Array contains error. Returning Error oParser = new parserFormula('VLOOKUP(#VALUE!,{0;#N/A;2},1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); // Case #8: Empty, Array, Number. Array contains Errors, not zero oParser = new parserFormula('VLOOKUP(,{#N/A,1;#N/A,2;#N/A,3;#N/A,4;#N/A,5;#N/A,6;#N/A,7},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #9: Boolean, Array, Number. Array contains Errors oParser = new parserFormula('VLOOKUP(FALSE,{#N/A,1;#N/A,2;#N/A,3;#N/A,4;#N/A,5;#N/A,6;#N/A,7},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #10: Boolean, Array, Number. Array contains Empty strings oParser = new parserFormula('VLOOKUP(FALSE,{"",1;"",2;"",3;"",4;"",5;"",6;"",7},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #11: Boolean, Array, Number. Array contains zeros and empty, errors oParser = new parserFormula('VLOOKUP(FALSE,{"",1;0,2;"",3;0,4;0,5;0,6;#N/A,7},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #12: Boolean, Array, Number. Array contains any other data oParser = new parserFormula('VLOOKUP(TRUE,{"asdac",1;2,2;"a",3;5,4;6,5;7,6;"8",7},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #13: Number, Array, Number. Array contains only string oParser = new parserFormula('VLOOKUP("item",{123, 1},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #14: String, Array, Number, Number, Boolean. Array not contains string oParser = new parserFormula('VLOOKUP("a",{5,1;8,2;3,3;-20,4;1,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #15: Error, Array, Number, Number, Boolean. Returning error = search value oParser = new parserFormula('VLOOKUP(#N/A,{5,1;8,2;3,3;-20,4;1,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #16: Error, Array, Number, Number, Boolean. Returning error = search value oParser = new parserFormula('VLOOKUP(#VALUE!,{5,1;8,2;3,3;-20,4;1,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); // Case #17: String, Array, Number, Number, Boolean. Array not contains string oParser = new parserFormula('VLOOKUP("5",{5,1;8,2;3,3;-20,4;1,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #18: String, Array, Number, Boolean. Trying to find empty string oParser = new parserFormula('VLOOKUP("",{" ",1;" ",2;0,3;" ",4;#N/A,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #19: Empty, Array, Number, Boolean. Array contains Booleans oParser = new parserFormula('VLOOKUP(,{FALSE,1;FALSE,2;FALSE,3;FALSE,4;FALSE,5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #20: Empty, Array, Number, Boolean. Array contains Booleans and empty strings oParser = new parserFormula('VLOOKUP(,{"",1;FALSE,2;"",3;FALSE,4;"",5},2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #21: Number, Area, Area oParser = new parserFormula("VLOOKUP(5,A100:B102,E100:G100)", "A2", ws); assert.ok(oParser.parse(), "Parse VLOOKUP(5,A100:B102,E100:G100)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of VLOOKUP(5,A100:B102,E1:G1)"); // Case #22: Number, Area, Array oParser = new parserFormula("VLOOKUP(5,BA100:BB102,{1,2,3})", "A2", ws); assert.ok(oParser.parse(), "Parse VLOOKUP(5,BA100:BB102,{1,2,3})"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of VLOOKUP(5,BA100:BB102,{1,2,3})"); // Case #23: Number, Area, Area oParser = new parserFormula("VLOOKUP(5,BA100:BB102,BE101:BG101)", "A2", ws); assert.ok(oParser.parse(), "Parse VLOOKUP(5,BA100:BB102,BE101:BG101)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", "Result of VLOOKUP(5,BA100:BB102,BE101:BG101)[0,0]"); // Case #24: Area, Area, Ref oParser = new parserFormula("VLOOKUP(BA100:BA102,BA100:BB102,BE100)", "A2", ws); assert.ok(oParser.parse(), "Parse VLOOKUP(BA100:BA102,BA100:BB102,BE100)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", "Result of VLOOKUP(BA100:BA102,BA100:BB102,BE100)[0,0]"); // Case #25: Area, Area, Ref oParser = new parserFormula("VLOOKUP(BA100:BA102,BA100:BB102,BF100)", "A2", ws); assert.ok(oParser.parse(), "Parse VLOOKUP(BA100:BA102,BA100:BB102,BF100)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", "Result of VLOOKUP(A100:A102,A100:B102,F100)[0,0]"); // Case #26: Area, Area, Area oParser = new parserFormula("VLOOKUP(BA100:BA102,BA100:BB102,BE100:BG100)", "A2", ws); assert.ok(oParser.parse(), "Parse VLOOKUP(BA100:BA102,BA100:BB102,BE100:BG100)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", "Result of VLOOKUP(BA100:BA102,BA100:BB102,BE100:BG100)"); // Case #27: Area, Area, Area oParser = new parserFormula("VLOOKUP(BA100:BA102,BA100:BB102,BE100:BG101)", "A2", ws); assert.ok(oParser.parse(), "Parse VLOOKUP(BA100:BA102,BA100:BB102,BE100:BG101)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", "Result of VLOOKUP(BA100:BA102,BA100:BB102,BE100:BG101)[0,0]"); // Case #28: Area, Area, Area oParser = new parserFormula("VLOOKUP(BA100:BA101,BA100:BB102,BF100:BG101)", "A2", ws); assert.ok(oParser.parse(), "Parse VLOOKUP(BA100:BA101,BA100:BB102,BF100:BG101)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", "Result of VLOOKUP(BA100:BA101,BA100:BB102,BF100:BG101)[0,0]"); // Case #29: Area, Area, Area oParser = new parserFormula("VLOOKUP(BA100:BA102,BA100:BB102,BG100:BG101)", "A2", ws); assert.ok(oParser.parse(), "Parse VLOOKUP(BA100:BA102,BA100:BB102,BG100:BG101)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", "Result of VLOOKUP(BA100:BA102,BA100:BB102,BG100:BG101)[0,0]"); // Case #30: Empty, Area, Number. Area not contains value <= 0 oParser = new parserFormula('VLOOKUP(,A502:C510,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #31: Ref, Area, Number. Area not contains empty string "" oParser = new parserFormula('VLOOKUP(D501,A502:C510,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #32: Error, Area, Number. Return SearchVal Error. oParser = new parserFormula('VLOOKUP(#N/A,D1101:C1123,2,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(#N/A,D1101:C1123,2,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of VLOOKUP(#N/A,D1101:C1123,2,TRUE)'); // Case #33: Error, Area, Number. Return SearchVal Error. oParser = new parserFormula('VLOOKUP(#VALUE!,D1101:C1123,2,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(#VALUE!,D1101:C1123,2,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of VLOOKUP(#VALUE!,D1101:C1123,2,TRUE)'); // Case #34: Number, Area, Number. Area not contains value <= searchValue oParser = new parserFormula('VLOOKUP(-1,D1101:C1123,2,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(-1,D1101:C1123,2,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of VLOOKUP(-1,D1101:C1123,2,TRUE)'); // Case #35: String, Area, Number. Area not contains strings oParser = new parserFormula('VLOOKUP("2",A502:C510,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #36: Number, Area, Number oParser = new parserFormula('VLOOKUP(#DIV/0!,A1101:B1113,2,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(#DIV/0!,A1101:B1113,2,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of VLOOKUP(#DIV/0!,A1101:B1113,2,FALSE)'); // Case #37: Number, Area, Number oParser = new parserFormula('VLOOKUP("",A1101:B1113,2,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP("",A1101:B1113,2,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of VLOOKUP("",A1101:B1113,2,FALSE)'); // Case #38: Ref, Area, Number. For bug 65016. Searchval = Error, should return Error oParser = new parserFormula('VLOOKUP(AE107,AE101:AF113,2,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'VLOOKUP(AE107,AE101:AF113,2,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of VLOOKUP(AA107,AE101:AF113,2,FALSE)'); // Case #39: String, Area, Number. Area not contains strings oParser = new parserFormula('VLOOKUP("2",A502:C510,2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); wb.delDefinesNames(defName3D); wb.delDefinesNames(defNameArea3D); wb.delDefinesNames(defName3D2); }); QUnit.test("Test: \"LOOKUP\"", function (assert) { let array; ws.getRange2("A1000").setValue("4.14"); ws.getRange2("A1001").setValue("4.19"); ws.getRange2("A1002").setValue("5.17"); ws.getRange2("A1003").setValue("5.77"); ws.getRange2("A1004").setValue("6.39"); ws.getRange2("B1000").setValue("red"); ws.getRange2("B1001").setValue("orange"); ws.getRange2("B1002").setValue("yellow"); ws.getRange2("B1003").setValue("green"); ws.getRange2("B1004").setValue("blue"); ws.getRange2("C1020").setValue("4.14"); ws.getRange2("D1020").setValue("4.19"); ws.getRange2("E1020").setValue("5.17"); ws.getRange2("F1020").setValue("5.77"); ws.getRange2("G1020").setValue("6.39"); ws.getRange2("H1020").setValue("7.99"); ws.getRange2("C1021").setValue("red"); ws.getRange2("D1021").setValue("orange"); ws.getRange2("E1021").setValue("yellow"); ws.getRange2("F1021").setValue("green"); ws.getRange2("G1021").setValue("blue"); ws.getRange2("H1021").setValue("black"); ws.getRange2("A1040").setValue("0"); ws.getRange2("A1041").setValue("1"); ws.getRange2("A1042").setValue(""); ws.getRange2("A1043").setValue("3"); ws.getRange2("A1044").setValue("3"); ws.getRange2("A1045").setValue("3"); ws.getRange2("A1046").setValue("TRUE"); ws.getRange2("A1047").setValue("FALSE"); ws.getRange2("B1041").setValue("a"); ws.getRange2("B1042").setValue("b"); ws.getRange2("B1043").setValue("c"); ws.getRange2("B1044").setValue("d"); ws.getRange2("B1045").setValue("e"); ws.getRange2("B1046").setValue("f"); ws.getRange2("B1047").setValue("g"); ws.getRange2("B1048").setValue("h"); ws.getRange2("B1049").setValue("i"); ws.getRange2("C1041").setValue("1"); ws.getRange2("C1042").setValue("2"); ws.getRange2("C1043").setValue("3"); ws.getRange2("C1044").setValue("4"); ws.getRange2("C1045").setValue("5"); ws.getRange2("C1046").setValue("6"); ws.getRange2("C1047").setValue("7"); ws.getRange2("C1048").setValue("8"); ws.getRange2("C1049").setValue("9"); ws.getRange2("G1070").setValue("0"); ws.getRange2("G1071").setValue("1"); ws.getRange2("G1072").setValue("2"); ws.getRange2("G1073").setValue("3"); ws.getRange2("G1074").setValue("3"); ws.getRange2("G1075").setValue("TRUE"); ws.getRange2("G1076").setValue("FALSE"); ws.getRange2("H1070").setValue("a"); ws.getRange2("H1071").setValue("b"); ws.getRange2("H1072").setValue("c"); ws.getRange2("H1073").setValue("d"); ws.getRange2("H1074").setValue("e"); ws.getRange2("H1075").setValue("f"); ws.getRange2("H1076").setValue("g"); ws.getRange2("C1090").setValue("2"); ws.getRange2("D1090").setValue(""); ws.getRange2("E1090").setValue("4"); ws.getRange2("F1090").setValue("5"); ws.getRange2("G1090").setValue(""); ws.getRange2("H1090").setValue(""); ws.getRange2("I1090").setValue("6"); ws.getRange2("J1090").setValue(""); ws.getRange2("K1090").setValue("7"); ws.getRange2("C1091").setValue("a"); ws.getRange2("D1091").setValue("b"); ws.getRange2("E1091").setValue("c"); ws.getRange2("F1091").setValue("d"); ws.getRange2("G1091").setValue("e"); ws.getRange2("H1091").setValue("f"); ws.getRange2("I1091").setValue("g"); ws.getRange2("J1091").setValue("h"); ws.getRange2("K1091").setValue("i"); ws.getRange2("A1110").setValue("1"); ws.getRange2("A1111").setValue("2"); ws.getRange2("A1112").setValue("3"); ws.getRange2("A1113").setValue("4"); ws.getRange2("A1114").setValue("5"); ws.getRange2("B1110").setValue("2"); ws.getRange2("B1111").setValue("4"); ws.getRange2("B1112").setValue("6"); ws.getRange2("B1113").setValue("8"); ws.getRange2("B1114").setValue("11"); ws.getRange2("C1110").setValue("3"); ws.getRange2("C1111").setValue("6"); ws.getRange2("C1112").setValue("9"); ws.getRange2("C1113").setValue("12"); ws.getRange2("C1114").setValue("16"); ws.getRange2("D1110").setValue("4"); ws.getRange2("D1111").setValue("8"); ws.getRange2("D1112").setValue("12"); ws.getRange2("D1113").setValue("16"); ws.getRange2("D1114").setValue("20"); ws.getRange2("E1110").setValue("5"); ws.getRange2("E1111").setValue("10"); ws.getRange2("E1112").setValue("14"); ws.getRange2("E1113").setValue("20"); ws.getRange2("E1114").setValue("25"); ws.getRange2("A1130").setValue("a"); ws.getRange2("A1131").setValue("b"); ws.getRange2("A1132").setValue("c"); ws.getRange2("A1133").setValue("d"); ws.getRange2("B1130").setValue("b"); ws.getRange2("C1130").setValue("c"); ws.getRange2("D1130").setValue("d"); ws.getRange2("A1150").setValue("1"); ws.getRange2("A1151").setValue("1"); ws.getRange2("A1152").setValue("#DIV/0!"); ws.getRange2("A1153").setValue("#DIV/0!"); ws.getRange2("A1154").setValue("#DIV/0!"); ws.getRange2("A1155").setValue("#DIV/0!"); ws.getRange2("A1156").setValue("#DIV/0!"); ws.getRange2("B1150").setValue("1"); ws.getRange2("B1151").setValue("2"); ws.getRange2("B1152").setValue("3"); ws.getRange2("B1153").setValue("4"); ws.getRange2("B1154").setValue("5"); ws.getRange2("B1155").setValue("6"); ws.getRange2("B1156").setValue("7"); ws.getRange2("C1150").setValue("1"); ws.getRange2("C1151").setValue("1"); ws.getRange2("C1152").setValue("0"); ws.getRange2("C1153").setValue("0"); ws.getRange2("C1154").setValue("0"); ws.getRange2("C1155").setValue("0"); ws.getRange2("C1156").setValue("0"); ws.getRange2("C1150").setValue("10"); ws.getRange2("C1151").setValue("1"); ws.getRange2("C1152").setValue("2"); ws.getRange2("C1153").setValue("3"); ws.getRange2("C1154").setValue("4"); ws.getRange2("C1155").setValue("5"); ws.getRange2("C1156").setValue("10"); ws.getRange2("A1180").setValue("2"); ws.getRange2("A1181").setValue("1"); ws.getRange2("A1185").setValue("1"); ws.getRange2("A1186").setValue("3"); ws.getRange2("B1180").setValue("0"); ws.getRange2("B1181").setValue("1"); ws.getRange2("B1182").setValue("2"); ws.getRange2("B1183").setValue("3"); ws.getRange2("B1184").setValue("4"); ws.getRange2("B1185").setValue("5"); ws.getRange2("B1186").setValue("6"); ws.getRange2("B1187").setValue("7"); ws.getRange2("B1188").setValue("8"); ws.getRange2("B1189").setValue("9"); ws.getRange2("B1190").setValue("10"); ws.getRange2("A1200").setValue("2"); ws.getRange2("A1201").setValue("4"); ws.getRange2("A1202").setValue("40"); ws.getRange2("B1200").setValue("1"); ws.getRange2("C1200").setValue("2"); ws.getRange2("D1200").setValue("3"); let currentSheet = ws.getName(); ws.getRange2("E1210").setValue("3"); ws.getRange2("A1210:A1220").setValue("4000"); ws.getRange2("A1215").setValue("3"); ws.getRange2("B1210:B1220").setValue("1000"); ws.getRange2("B1210").setValue("1"); ws.getRange2("B1215").setValue("55"); ws.getRange2("A1300:B1350").cleanAll(); ws.getRange2("A1300").setValue("0"); ws.getRange2("A1301").setValue("0"); ws.getRange2("A1302").setValue("2.1"); ws.getRange2("A1303").setValue("2.4"); ws.getRange2("A1304").setValue("2.4"); ws.getRange2("A1305").setValue("9"); ws.getRange2("A1306").setValue("10"); ws.getRange2("A1307").setValue("11"); ws.getRange2("A1308").setValue("11"); ws.getRange2("A1309").setValue("11"); ws.getRange2("A1310").setValue("12"); ws.getRange2("A1311").setValue("12"); ws.getRange2("A1312").setValue("12"); ws.getRange2("A1313").setValue("67"); ws.getRange2("A1314").setValue(""); ws.getRange2("A1315").setValue("ALDEBARAN"); ws.getRange2("A1316").setValue("BLUE"); ws.getRange2("A1317").setValue("CIANO"); ws.getRange2("A1318").setValue("RED"); ws.getRange2("A1319").setValue("#N/A"); ws.getRange2("A1320").setValue("Vega"); ws.getRange2("A1321").setValue("FALSE"); ws.getRange2("A1322").setValue("TRUE"); ws.getRange2("A1323").setValue("BLUE"); ws.getRange2("B1300").setValue("1"); ws.getRange2("B1301").setValue("2"); ws.getRange2("B1302").setValue("3"); ws.getRange2("B1303").setValue("4"); ws.getRange2("B1304").setValue("5"); ws.getRange2("B1305").setValue("6"); ws.getRange2("B1306").setValue("7"); ws.getRange2("B1307").setValue("8"); ws.getRange2("B1308").setValue("9"); ws.getRange2("B1309").setValue("10"); ws.getRange2("B1310").setValue("11"); ws.getRange2("B1311").setValue("12"); ws.getRange2("B1312").setValue("13"); ws.getRange2("B1313").setValue("14"); ws.getRange2("B1314").setValue("15"); ws.getRange2("B1315").setValue("16"); ws.getRange2("B1316").setValue("17"); ws.getRange2("B1317").setValue("18"); ws.getRange2("B1318").setValue("19"); ws.getRange2("B1319").setValue("20"); ws.getRange2("B1320").setValue("21"); ws.getRange2("B1321").setValue("22"); ws.getRange2("B1322").setValue("23"); const defName3D = new Asc.asc_CDefName('LOOKUPTestName3D', ws.getName() + '!$A$1323'); const defNameArea3D = new Asc.asc_CDefName('LOOKUPTestNameArea3D', ws.getName() + '!$A$1300:$B$1322'); wb.editDefinesNames(null, defName3D); wb.editDefinesNames(null, defNameArea3D); AscCommonExcel.g_oLOOKUPCache.clean(); // Positive Cases: // Case #1: Number, Array, Array. Bug 65722 - lookup value in large sorted array with mixed types oParser = new parserFormula('LOOKUP(20,{0,1,49.75,55.75,61.75,67.75,72.75,78.75,84.75,89.75,94.75,97.75},{"KP";"NB";4;3.7;3.3;3;2.7;2.3;2;1.7;1.3;1})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(20,{0,1,49.75,55.75,61.75,67.75,72.75,78.75,84.75,89.75,94.75,97.75},{"KP";"NB";4;3.7;3.3;3;2.7;2.3;2;1.7;1.3;1})'); assert.strictEqual(oParser.calculate().getValue(), "NB", 'Result of LOOKUP(20,{0,1,49.75,55.75,61.75,67.75,72.75,78.75,84.75,89.75,94.75,97.75},{"KP";"NB";4;3.7;3.3;3;2.7;2.3;2;1.7;1.3;1})'); // Case #2: Number, Array, Array. Lookup value in shorter sorted array oParser = new parserFormula('LOOKUP(20,{0,1,49.75,55.75},{"KP";"NB";4;3.7;3.3;3;2.7})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(20,{0,1,49.75,55.75},{"KP";"NB";4;3.7;3.3;3;2.7})'); assert.strictEqual(oParser.calculate().getValue(), "NB", 'Result of LOOKUP(20,{0,1,49.75,55.75},{"KP";"NB";4;3.7;3.3;3;2.7})'); // Case #3: Number, Array, Array. Lookup value in minimal sorted array oParser = new parserFormula('LOOKUP(20,{0,1,49.75},{"KP";"NB";4})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(20,{0,1,49.75},{"KP";"NB";4})'); assert.strictEqual(oParser.calculate().getValue(), "NB", 'Result of LOOKUP(20,{0,1,49.75},{"KP";"NB";4})'); // Case #4: Number, Array, Array. Lookup array shorter than result array oParser = new parserFormula('LOOKUP(20,{0,1},{"KP";"NB";4;3.7;3.3;3;2.7})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(20,{0,1},{"KP";"NB";4;3.7;3.3;3;2.7})'); assert.strictEqual(oParser.calculate().getValue(), "NB", 'Result of LOOKUP(20,{0,1},{"KP";"NB";4;3.7;3.3;3;2.7})'); // Case #5: String, Array. Bug 67640 - array mode lookup by first row, return from last row oParser = new parserFormula('LOOKUP("C",{"a","b","c","d";1,2,3,4})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP("C",{"a","b","c","d";1,2,3,4})'); assert.strictEqual(oParser.calculate().getValue(), 3, 'Result of LOOKUP("C",{"a","b","c","d";1,2,3,4})'); // Case #6: String, Array. Lookup string value greater than available, returns last match oParser = new parserFormula('LOOKUP("bump",{"a",1;"b",2;"c",3})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP("bump",{"a",1;"b",2;"c",3})'); assert.strictEqual(oParser.calculate().getValue(), 2, 'Result of LOOKUP("bump",{"a",1;"b",2;"c",3})'); // Case #7: Number, Array. Lookup in 2D array by first row, return from last row oParser = new parserFormula('LOOKUP(20,{0,1,2;3,4,5;11,12,13;14,15,16})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(20,{0,1,2;3,4,5;11,12,13;14,15,16})'); assert.strictEqual(oParser.calculate().getValue(), 16, 'Result of LOOKUP(20,{0,1,2;3,4,5;11,12,13;14,15,16})'); // Case #8: Number, Array. Array mode lookup by first column, return from last column oParser = new parserFormula('LOOKUP(20,{0,1;49.75,55.75;12,13})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(20,{0,1;49.75,55.75;12,13})'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of LOOKUP(20,{0,1;49.75,55.75;12,13})'); // Case #9: Number, Array. Lookup by first column with mixed types, return string from last column oParser = new parserFormula('LOOKUP(20,{0,1;2,55.75;12,13;15,"ds"})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(20,{0,1;2,55.75;12,13;15,"ds"})'); assert.strictEqual(oParser.calculate().getValue(), "ds", 'Result of LOOKUP(20,{0,1;2,55.75;12,13;15,"ds"})'); // Case #10: Number, Array, Array. 2D lookup array with single row result array oParser = new parserFormula('LOOKUP(20,{0,1;1,1},{"KP","NB","sd"})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(20,{0,1;1,1},{"KP","NB","sd"})'); assert.strictEqual(oParser.calculate().getValue(), "NB", 'Result of LOOKUP(20,{0,1;1,1},{"KP","NB","sd"})'); // Case #11: Number, Array, Number. Bug 67743 - exact match found in 2D array oParser = new parserFormula('LOOKUP(10,{10,11,12;2,3,4},2)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(10,{10,11,12;2,3,4},2)'); assert.strictEqual(oParser.calculate().getValue(), 2, 'Result of LOOKUP(10,{10,11,12;2,3,4},2)'); // Case #12: Boolean, Array, Array. TRUE lookup in boolean array oParser = new parserFormula('LOOKUP(TRUE,{FALSE,TRUE},{0,1})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(TRUE,{FALSE,TRUE},{0,1})'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of LOOKUP(TRUE,{FALSE,TRUE},{0,1})'); // Case #13: Boolean, Array, Array. TRUE lookup when only FALSE exists oParser = new parserFormula('LOOKUP(TRUE,{FALSE,FALSE},{1,2})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(TRUE,{FALSE,FALSE},{1,2})'); assert.strictEqual(oParser.calculate().getValue(), 2, 'Result of LOOKUP(TRUE,{FALSE,FALSE},{1,2})'); // Case #14: Number, Array, Array. Lookup with negative numbers in sorted array oParser = new parserFormula('LOOKUP(0,{-10,-5,0,5,10},{"A","B","C","D","E"})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(0,{-10,-5,0,5,10},{"A","B","C","D","E"})'); assert.strictEqual(oParser.calculate().getValue(), "C", 'Result of LOOKUP(0,{-10,-5,0,5,10},{"A","B","C","D","E"})'); // Case #15: Number, Array, Array. Lookup with decimal precision oParser = new parserFormula('LOOKUP(3.14159,{1.1,2.2,3.14,4.4},{10,20,30,40})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(3.14159,{1.1,2.2,3.14,4.4},{10,20,30,40})'); assert.strictEqual(oParser.calculate().getValue(), 30, 'Result of LOOKUP(3.14159,{1.1,2.2,3.14,4.4},{10,20,30,40})'); // Case #16: Number, Array, Array. Lookup with single element arrays oParser = new parserFormula('LOOKUP(5,{5},{"found"})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(5,{5},{"found"})'); assert.strictEqual(oParser.calculate().getValue(), "found", 'Result of LOOKUP(5,{5},{"found"})'); // Case #17: Number, Array, Array. Lookup with mixed numeric types (integers and decimals) oParser = new parserFormula('LOOKUP(2.5,{1,2,3,4},{100,200,300,400})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(2.5,{1,2,3,4},{100,200,300,400})'); assert.strictEqual(oParser.calculate().getValue(), 200, 'Result of LOOKUP(2.5,{1,2,3,4},{100,200,300,400})'); // Case #18: String, Array. Lookup in 2D array with strings by first column, return from last column oParser = new parserFormula('LOOKUP("M",{"A","apple";"M","mango";"Z","zebra"})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP("M",{"A","apple";"M","mango";"Z","zebra"})'); assert.strictEqual(oParser.calculate().getValue(), "mango", 'Result of LOOKUP("M",{"A","apple";"M","mango";"Z","zebra"})'); // Case #19: Number, Array, Array. Lookup with zero in array oParser = new parserFormula('LOOKUP(0,{-1,0,1},{"negative","zero","positive"})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(0,{-1,0,1},{"negative","zero","positive"})'); assert.strictEqual(oParser.calculate().getValue(), "zero", 'Result of LOOKUP(0,{-1,0,1},{"negative","zero","positive"})'); // Case #20: Number, Array, Array. Lookup with large numbers oParser = new parserFormula('LOOKUP(1000000,{100,1000,10000,100000,1000000},{1,2,3,4,5})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(1000000,{100,1000,10000,100000,1000000},{1,2,3,4,5})'); assert.strictEqual(oParser.calculate().getValue(), 5, 'Result of LOOKUP(1000000,{100,1000,10000,100000,1000000},{1,2,3,4,5})'); // Case #21: String, Array, Array. Lookup with special characters in strings oParser = new parserFormula('LOOKUP("@",{"!","#","@","$"},{1,2,3,4})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP("@",{"!","#","@","$"},{1,2,3,4})'); assert.strictEqual(oParser.calculate().getValue(), 3, 'Result of LOOKUP("@",{"!","#","@","$"},{1,2,3,4})'); // Case #22: Number, Array. Lookup in 3D-like array structure (multiple rows, single lookup) oParser = new parserFormula('LOOKUP(15,{5,10,15,20;100,200,300,400;1000,2000,3000,4000})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(15,{5,10,15,20;100,200,300,400;1000,2000,3000,4000})'); assert.strictEqual(oParser.calculate().getValue(), 3000, 'Result of LOOKUP(15,{5,10,15,20;100,200,300,400;1000,2000,3000,4000})'); // Case #23: Number, Array, Array. Lookup with fractional numbers in scientific notation oParser = new parserFormula('LOOKUP(0.001,{0.0001,0.001,0.01,0.1},{1,2,3,4})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(0.001,{0.0001,0.001,0.01,0.1},{1,2,3,4})'); assert.strictEqual(oParser.calculate().getValue(), 2, 'Result of LOOKUP(0.001,{0.0001,0.001,0.01,0.1},{1,2,3,4})'); // Case #24: Boolean, Array, Array. FALSE lookup in mixed boolean array oParser = new parserFormula('LOOKUP(FALSE,{FALSE,TRUE,TRUE},{10,20,30})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(FALSE,{FALSE,TRUE,TRUE},{10,20,30})'); assert.strictEqual(oParser.calculate().getValue(), 10, 'Result of LOOKUP(FALSE,{FALSE,TRUE,TRUE},{10,20,30})'); // Case #25: String, Array, Array. Lookup with empty string in array oParser = new parserFormula('LOOKUP("",{"","a","b"},{"empty","first","second"})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP("",{"","a","b"},{"empty","first","second"})'); assert.strictEqual(oParser.calculate().getValue(), "empty", 'Result of LOOKUP("",{"","a","b"},{"empty","first","second"})'); // Case #26: Number, Array, Array. Lookup with mismatched array sizes oParser = new parserFormula('LOOKUP(2,{1,2,3},{10,20})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(2,{1,2,3},{10,20})'); assert.strictEqual(oParser.calculate().getValue(), 20, 'Result of LOOKUP(2,{1,2,3},{10,20})'); // Case #27: Number, Array, Array. Unsorted lookup array oParser = new parserFormula('LOOKUP(3,{5,1,3,2},{50,10,30,20})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(3,{5,1,3,2},{50,10,30,20})'); assert.strictEqual(oParser.calculate().getValue(), 30, 'Result of LOOKUP(3,{5,1,3,2},{50,10,30,20})'); // Case #28: Number, Array, Array. Lookup with error values in lookup array oParser = new parserFormula('LOOKUP(2,{1,#DIV/0!,3},{10,20,30})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(2,{1,#DIV/0!,3},{10,20,30})'); assert.strictEqual(oParser.calculate().getValue(), 10, 'Result of LOOKUP(2,{1,#DIV/0!,3},{10,20,30})'); // Case #29: Number, Array, Array. Lookup with very large array where value not found, returns last match oParser = new parserFormula('LOOKUP(999,{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},{10,20,30,40,50,60,70,80,90,100,110,120,130,140,150})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(999,{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},{10,20,30,40,50,60,70,80,90,100,110,120,130,140,150})'); assert.strictEqual(oParser.calculate().getValue(), 150, 'Result of LOOKUP(999,{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},{10,20,30,40,50,60,70,80,90,100,110,120,130,140,150})'); // Case #30: Number, Array, Array. Lookup with duplicate values in lookup array, returns last match oParser = new parserFormula('LOOKUP(2,{1,2,2,3},{10,20,25,30})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(2,{1,2,2,3},{10,20,25,30})'); assert.strictEqual(oParser.calculate().getValue(), 25, 'Result of LOOKUP(2,{1,2,2,3},{10,20,25,30})'); // Case #31: Number, Array. Lookup in single-element array smaller than lookup value oParser = new parserFormula('LOOKUP(10,{5})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(10,{5})'); assert.strictEqual(oParser.calculate().getValue(), 5, 'Result of LOOKUP(10,{5})'); // Case #32: Number, Area, Area. Lookup decimal value in sorted numeric Area oParser = new parserFormula("LOOKUP(4.19, A1000:A1004, B1000:B1004)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "orange"); // Case #33: Number, Area, Area. Lookup value between sorted decimals, returns closest match oParser = new parserFormula("LOOKUP(5.75, A1000:A1004, B1000:B1004)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().getValue(), "yellow"); // Case #34: Number, Area, Area. Lookup value greater than max, returns last match oParser = new parserFormula("LOOKUP(7.66, A1000:A1004, B1000:B1004)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().getValue(), "blue"); // Case #35: Number, Area, Area. Horizontal lookup in sorted Area oParser = new parserFormula("LOOKUP(4.19,C1020:H1020,C1021:H1021)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().getValue(), "orange"); // Case #36: Number, Area, Area. Horizontal lookup with approximate match oParser = new parserFormula("LOOKUP(5.75,C1020:H1020,C1021:H1021)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().getValue(), "yellow"); // Case #37: Number, Area, Area. Horizontal lookup greater than max value oParser = new parserFormula("LOOKUP(7.66,C1020:H1020,C1021:H1021)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().getValue(), "blue"); // Case #38: Number, Area, Area. Exact match in horizontal Area oParser = new parserFormula("LOOKUP(5.17,C1020:H1020,C1021:H1021)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().getValue(), "yellow"); // Case #39: Number, Area, Area. Lookup value greater than all in horizontal Area oParser = new parserFormula("LOOKUP(9,C1020:H1020,C1021:H1021)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().getValue(), "black"); // Case #40: Number, Area, Area. Exact match with integer value oParser = new parserFormula("LOOKUP(1,A1041:A1044,B1041:B1044)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().getValue(), "a"); // Case #41: Area, Area, Area. Single cell range lookup oParser = new parserFormula("LOOKUP(A1041:A1041,A1041:A1044,B1041:B1044)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(A1041:A1041,A1041:A1044,B1041:B1044)"); array = oParser.calculate(); assert.strictEqual(array.getValue().getValue(), "a", "Result of LOOKUP(A1041:A1041,A1041:A1044,B1041:B1044)"); // Case #42: Area, Area, Boolean. Single cell range with boolean result oParser = new parserFormula("LOOKUP(A1041:A1041,A1041:A1044,TRUE)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(A1041:A1041,A1041:A1044,TRUE)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), "TRUE", "Result of LOOKUP(A1041:A1041,A1041:A1044,TRUE)"); // Case #43: Area, Area, Number. Single cell range with numeric result oParser = new parserFormula("LOOKUP(A1041:A1041,A1041:A1044,1)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(A1041:A1041,A1041:A1044,1)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), 1, "Result of LOOKUP(A1041:A1041,A1041:A1044,1)"); // Case #44: Area, Area, Area. Single cell ranges with matching positions oParser = new parserFormula("LOOKUP(A1041:A1041,A1041:A1044,A1041:A1041)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(A1041:A1041,A1041:A1044,A1041:A1041)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), 1, "Result of LOOKUP(A1041:A1041,A1041:A1044,A1041:A1041)"); // Case #45: Area, Area, Area. Single cell ranges with empty result oParser = new parserFormula("LOOKUP(A1041:A1041,A1041:A1044,A1042:A1042)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(A1041:A1041,A1041:A1044,A1042:A1042)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), "", "Result of LOOKUP(A1041:A1041,A1041:A1044,A1042:A1042)"); // Case #46: Area, Area, Area. Single cell ranges with numeric result oParser = new parserFormula("LOOKUP(A1041:A1041,A1041:A1044,A1043:A1043)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(A1041:A1041,A1041:A1044,A1043:A1043)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), 3, "Result of LOOKUP(A1041:A1041,A1041:A1044,A1043:A1043)"); // Case #47: Ref, Area, Area. Single cell lookup with range result oParser = new parserFormula("LOOKUP(A1041,A1041:A1044,A1041)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(1,A1041:A1044,1)"); assert.strictEqual(oParser.calculate().getValue().getValue(), 1, "Result of LOOKUP(1,A1041:A1044,1)"); // Case #48: Array, Area, Area. Array lookup returning multiple results oParser = new parserFormula("LOOKUP({2,13,14,15},A1041:A1044,B1041:B1044)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP({2,13,14,15},A1041:A1044,B1041:B1044)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue().getValue(), "a", "Result of LOOKUP({2,13,14,15},A1041:A1044,B1041:B1044)"); assert.strictEqual(array.getElementRowCol(0,1).getValue().getValue(), "d", "Result of LOOKUP({2,13,14,15},A1041:A1044,B1041:B1044)"); assert.strictEqual(array.getElementRowCol(0,2).getValue().getValue(), "d", "Result of LOOKUP({2,13,14,15},A1041:A1044,B1041:B1044)"); assert.strictEqual(array.getElementRowCol(0,3).getValue().getValue(), "d", "Result of LOOKUP({2,13,14,15},A1041:A1044,B1041:B1044)"); // Case #49: Array, Area, Area. Array lookup with exact matches oParser = new parserFormula("LOOKUP({3,13,14,15},A1041:A1044,B1041:B1044)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP({3,13,14,15},A1041:A1044,B1041:B1044)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue().getValue(), "d", "Result of LOOKUP({3,13,14,15},A1041:A1044,B1041:B1044)"); assert.strictEqual(array.getElementRowCol(0,1).getValue().getValue(), "d", "Result of LOOKUP({3,13,14,15},A1041:A1044,B1041:B1044)"); assert.strictEqual(array.getElementRowCol(0,2).getValue().getValue(), "d", "Result of LOOKUP({3,13,14,15},A1041:A1044,B1041:B1044)"); assert.strictEqual(array.getElementRowCol(0,3).getValue().getValue(), "d", "Result of LOOKUP({3,13,14,15},A1041:A1044,B1041:B1044)"); // Case #50: Array, Area, Area. Array lookup with values greater than max oParser = new parserFormula("LOOKUP({12,13,14,15},A1041:A1044,B1041:B1044)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP({12,13,14,15},A1041:A1044,B1041:B1044)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue().getValue(), "d", "Result of LOOKUP({12,13,14,15},A1041:A1044,B1041:B1044)"); assert.strictEqual(array.getElementRowCol(0,1).getValue().getValue(), "d", "Result of LOOKUP({12,13,14,15},A1041:A1044,B1041:B1044)"); assert.strictEqual(array.getElementRowCol(0,2).getValue().getValue(), "d", "Result of LOOKUP({12,13,14,15},A1041:A1044,B1041:B1044)"); assert.strictEqual(array.getElementRowCol(0,3).getValue().getValue(), "d", "Result of LOOKUP({12,13,14,15},A1041:A1044,B1041:B1044)"); // Case #51: Array, Area, Area. Array lookup with zero value oParser = new parserFormula("LOOKUP({0},A1040:A1044,A1040:A1044)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP({0},A1040:A1044,A1040:A1044)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue().getValue(), 0, "Result of LOOKUP({0},A1040:A1044,A1040:A1044)"); // Case #52: Array, Array, Array. Array lookup with exact match oParser = new parserFormula("LOOKUP({2},{0,1,2,3,4},{10,11,12,13,14})", "A2", ws); assert.ok(oParser.parse(), "LOOKUP({2},{0,1,2,3,4},{10,11,12,13,14})"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 12, "Result of LOOKUP({2},{0,1,2,3,4},{10,11,12,13,14})"); // Case #53: Number, Area, Area. Lookup with extended range oParser = new parserFormula("LOOKUP(3,A1041:A1045,B1041:B1045)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(3,A1041:A1045,B1041:B1045)"); assert.strictEqual(oParser.calculate().getValue().getValue(), "e", "Result of LOOKUP(3,A1041:A1045,B1041:B1045)"); // Case #54: Ref, Area, Area. Range reference lookup oParser = new parserFormula("LOOKUP(A1043,A1041:A1045,B1041:B1045)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(A1043,A1041:A1045,B1041:B1045)"); assert.strictEqual(oParser.calculate().getValue().getValue(), "e", "Result of LOOKUP(3,A1041:A1045,B1041:B1045)"); // Case #55: Boolean, Area, Area. TRUE lookup in mixed range oParser = new parserFormula("LOOKUP(TRUE,A1041:A1047,B1041:B1047)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(TRUE,A1041:A1047,B1041:B1047)"); assert.strictEqual(oParser.calculate().getValue().getValue(), "f", "Result of LOOKUP(TRUE,A1041:A1047,B1041:B1047)"); // Case #56: Ref, Area, Area. Range reference with TRUE value oParser = new parserFormula("LOOKUP(A1046,A1041:A1047,B1041:B1047)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(TRUE,A1041:A1047,B1041:B1047)"); assert.strictEqual(oParser.calculate().getValue().getValue(), "f", "Result of LOOKUP(TRUE,A1041:A1047,B1041:B1047)"); // Case #57: Boolean, Area, Area. TRUE lookup in different range oParser = new parserFormula("LOOKUP(TRUE,G1070:G1076,H1070:H1076)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(TRUE,G1070:G1076,H1070:H1076)"); assert.strictEqual(oParser.calculate().getValue().getValue(), "f", "Result of LOOKUP(TRUE,G1070:G1076,H1070:H1076)"); // Case #58: Ref, Area, Area. Range reference with TRUE in different location oParser = new parserFormula("LOOKUP(G1075,G1070:G1076,H1070:H1076)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(TRUE,G1070:G1076,H1070:H1076)"); assert.strictEqual(oParser.calculate().getValue().getValue(), "f", "Result of LOOKUP(TRUE,G1070:G1076,H1070:H1076)"); // Case #59: Number, Area, Area. Lookup in sparse range with empty cells oParser = new parserFormula("LOOKUP(3,C1090:K1090,C1091:K1091)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().getValue(), "a"); // Case #60: Number, Area, Area. Lookup exact match in sparse range oParser = new parserFormula("LOOKUP(2,C1090:K1090,C1091:K1091)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().getValue(), "a"); // Case #61: Number, Area, Area. Lookup max value in sparse range oParser = new parserFormula("LOOKUP(7,C1090:K1090,C1091:K1091)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().getValue(), "i"); // Case #62: Number, Area, Area. Lookup value greater than max in sparse range oParser = new parserFormula("LOOKUP(10,C1090:K1090,C1091:K1091)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().getValue(), "i"); // Case #63: Number, Area. 2D range lookup by first row, return from last row oParser = new parserFormula("LOOKUP(3,A1110:E1112)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(3,A1110:E1112)"); assert.strictEqual(oParser.calculate().getValue().getValue(), 9, "Result of LOOKUP(3,A1110:E1112)"); // Case #64: Ref, Area. Range reference in 2D lookup oParser = new parserFormula("LOOKUP(A1112,A1110:E1112)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(A1112,A1110:E1112)"); assert.strictEqual(oParser.calculate().getValue().getValue(), 9, "Result of LOOKUP(3,A1110:E1112)"); // Case #65: Number, Area. Lookup value greater than available in 2D range oParser = new parserFormula("LOOKUP(6,A1110:E1112)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(6,A1110:E1112)"); assert.strictEqual(oParser.calculate().getValue().getValue(), 14, "Result of LOOKUP(6,A1110:E1112)"); // Case #66: Number, Area. 2D range lookup by first column, return from last column oParser = new parserFormula("LOOKUP(2,A1110:C1114)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(2,A1110:C1114)"); assert.strictEqual(oParser.calculate().getValue().getValue(), 6, "Result of LOOKUP(2,A1110:C1114)"); // Case #67: Ref, Area. Range reference in 2D column lookup oParser = new parserFormula("LOOKUP(B1110,A1110:C1114)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(B1110,A1110:C1114)"); assert.strictEqual(oParser.calculate().getValue().getValue(), 6, "Result of LOOKUP(2,A1110:C1114)"); // Case #68: Number, Area. Lookup value greater than max in 2D column range oParser = new parserFormula("LOOKUP(6,A1110:C1114)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(6,A1110:C1114)"); assert.strictEqual(oParser.calculate().getValue().getValue(), 16, "Result of LOOKUP(6,A1110:C1114)"); // Case #69: Number, Area. 2D range lookup with wider result area oParser = new parserFormula("LOOKUP(2,A1110:E1114)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(2,A1110:E1114)"); assert.strictEqual(oParser.calculate().getValue().getValue(), 10, "Result of LOOKUP(2,A1110:E1114)"); // Case #70: Number, Area. Another 2D range lookup with wider result area oParser = new parserFormula("LOOKUP(3,A1110:E1114)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(3,A1110:E1114)"); assert.strictEqual(oParser.calculate().getValue().getValue(), 14, "Result of LOOKUP(3,A1110:E1114)"); // Case #71: Number, Array, Area. Array lookup with horizontal range result oParser = new parserFormula("LOOKUP(1,{1,0,0,1},A1130:D1130)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(1,{1,0,0,1},A1130:D1130)"); assert.strictEqual(oParser.calculate().getValue(), "d", "Result of LOOKUP(1,{1,0,0,1},A1130:D1130)"); // Case #72: Number, Array, Area. Array lookup with vertical array and horizontal range oParser = new parserFormula("LOOKUP(1,{1;0;0;1},A1130:D1130)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(1,{1;0;0;1},A1130:D1130)"); assert.strictEqual(oParser.calculate().getValue(), "d", "Result of LOOKUP(1,{1;0;0;1},A1130:D1130)"); // Case #73: Number, Array, Area. Array lookup with vertical range result oParser = new parserFormula("LOOKUP(1,{1;0;0;1},A1130:A1133)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(1,{1;0;0;1},A1130:A1133)"); assert.strictEqual(oParser.calculate().getValue(), "d", "Result of LOOKUP(1,{1;0;0;1},A1130:A1133)"); // Case #74: Number, Array, Area. Array lookup with horizontal array and vertical range oParser = new parserFormula("LOOKUP(1,{1,0,0,1},A1130:A1133)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(1,{1,0,0,1},A1130:A1133)"); assert.strictEqual(oParser.calculate().getValue(), "d", "Result of LOOKUP(1,{1,0,0,1},A1130:A1133)"); // Case #75: Number, Area, Area. Lookup with error values in range oParser = new parserFormula("LOOKUP(1,A1150:A1156,B1150:B1156)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(1,A1150:A1156,B1150:B1156)"); oParser.setArrayFormulaRef(ws.getRange2("A2").bbox); assert.strictEqual(oParser.calculate().getValue().getValue(), 2, "Result of LOOKUP(1,A1150:A1156,B1150:B1156)"); // Case #76: Number, Area, Area. Lookup in range with first and last value test oParser = new parserFormula("LOOKUP(3,C1150:C1156,B1150:B1156)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(3,C1150:C1156,B1150:B1156) - first and last value test"); oParser.setArrayFormulaRef(ws.getRange2("A2").bbox); assert.strictEqual(oParser.calculate().getValue().getValue(), 4, "Result of LOOKUP(3,C1150:C1156,B1150:B1156)"); // Case #77: String, String, Array. Single value lookup with array result oParser = new parserFormula('LOOKUP("b","a",{1,2,3,4,5})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP("b","a",{1,2,3,4,5})'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of LOOKUP("b","a",{1,2,3,4,5})'); // Case #78: String, String, Number. Single value lookup with numeric result oParser = new parserFormula('LOOKUP("b","a",-1)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP("b","a",-1)'); assert.strictEqual(oParser.calculate().getValue(), -1, 'Result of LOOKUP("b","a",-1)'); // Case #79: Boolean, Boolean, Boolean. Boolean lookup with boolean result oParser = new parserFormula('LOOKUP(FALSE,FALSE,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(FALSE,FALSE,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), "TRUE", 'Result of LOOKUP(FALSE,FALSE,TRUE)'); // Case #80: Boolean, Boolean, String. Boolean lookup with string result oParser = new parserFormula('LOOKUP(TRUE,FALSE,"a")', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(TRUE,FALSE,"a")'); assert.strictEqual(oParser.calculate().getValue(), "a", 'Result of LOOKUP(TRUE,FALSE,"a")'); // Case #81: Number, Number, String. Numeric lookup with single value and string result oParser = new parserFormula('LOOKUP(3,1,"a")', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(3,1,"a")'); assert.strictEqual(oParser.calculate().getValue(), "a", 'Result of LOOKUP(3,1,"a")'); // Case #82: Number, Number, String. Exact match numeric lookup oParser = new parserFormula('LOOKUP(3,3,"a")', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(3,3,"a")'); assert.strictEqual(oParser.calculate().getValue(), "a", 'Result of LOOKUP(3,3,"a")'); // Case #83: Empty, Formula, Area. Bug 65306 - lookup with empty value and CODE function ws.getRange2("N1160").setValue("янв"); ws.getRange2("O1160").setValue("0") oParser = new parserFormula("LOOKUP(,-CODE(N1160:O1160),N1160:O1160)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(,-CODE(N1160:O1160),N1160:O1160)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of LOOKUP(,-CODE(N1160:O1160),N1160:O1160)"); // Case #84: Number, Area, Area. Bug 62730 - lookup with range arithmetic in lookup array oParser = new parserFormula('LOOKUP(1,A1180:A1190+A1180:A1190,B1180:B1190)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(1,A1180:A1190+A1180:A1190,B1180:B1190)'); assert.strictEqual(oParser.calculate().getValue(), 4, 'Result of LOOKUP(1,A1180:A1190+A1180:A1190,B1180:B1190)'); // Case #85: Number, Area, Area. Bug 62730 - lookup with range arithmetic, different value oParser = new parserFormula('LOOKUP(2,A1180:A1190+A1180:A1190,B1180:B1190)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(2,A1180:A1190+A1180:A1190,B1180:B1190)'); assert.strictEqual(oParser.calculate().getValue(), 5, 'Result of LOOKUP(2,A1180:A1190+A1180:A1190,B1180:B1190)'); // Case #86: Number, Area, Area. Bug 62730 - lookup with arithmetic in both ranges oParser = new parserFormula('LOOKUP(1,A1180:A1190+A1180:A1190,B1180:B1190+B1180:B1190)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(1,A1180:A1190+A1180:A1190,B1180:B1190+B1180:B1190)'); assert.strictEqual(oParser.calculate().getValue(), 8, 'Result of LOOKUP(1,A1180:A1190+A1180:A1190,B1180:B1190+B1180:B1190)'); // Case #87: Number, Area, Area. Bug 62730 - lookup with arithmetic and compatible range sizes oParser = new parserFormula('LOOKUP(1,A1180:A1190+A1180:A1190,B1180:B1187+B1180:B1185)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(1,A1180:A1190+A1180:A1190,B1180:B1187+B1180:B1185)'); assert.strictEqual(oParser.calculate().getValue(), 8, 'Result of LOOKUP(1,A1180:A1190+A1180:A1190,B1180:B1187+B1180:B1185)'); // Case #88: Number, Area, Array. Bug 67743 - lookup with range arithmetic and array result oParser = new parserFormula('LOOKUP(3,A1200:A1202+{1},{1})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(3,A1200:A1202+{1},{1})'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of LOOKUP(3,A1200:A1202+{1},{1})'); // Case #89: Number, Area, Array. Lookup with range and array result oParser = new parserFormula('LOOKUP(5,A1200:A1202,{1,2})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(5,A1200:A1202,{1,2})'); assert.strictEqual(oParser.calculate().getValue(), 2, 'Result of LOOKUP(5,A1200:A1202,{1,2})'); // Case #90: Number, Area, Area. Lookup with range arithmetic and range result oParser = new parserFormula('LOOKUP(5,A1200:A1202+{1},A1200:A1201)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(5,A1200:A1202+{1},A1200:A1201)'); assert.strictEqual(oParser.calculate().getValue(), 4, 'Result of LOOKUP(5,A1200:A1202+{1},A1200:A1201)'); // Case #91: Number, Area, Area. Lookup with range arithmetic and horizontal result oParser = new parserFormula('LOOKUP(5,A1200:A1202+{1},A1200:D1200)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(5,A1200:A1202+{1},A1200:D1200)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of LOOKUP(5,A1200:A1202+{1},A1200:D1200)'); // Case #92: Ref3D, Area, Area. Bug 69527 - lookup with sheet reference in lookup value oParser = new parserFormula('LOOKUP(' + currentSheet + '!E1210,A1210:A1220,B1210:B1220)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(' + currentSheet + '!E1210,A1210:A1220,B1210:B1220)'); assert.strictEqual(oParser.calculate().getValue().getValue(), 55, 'Result of LOOKUP(' + currentSheet + '!E1210,A1210:A1220,B1210:B1220)'); // Case #93: Ref, Ref3D, Area. Bug 69527 - lookup with sheet reference in lookup array oParser = new parserFormula('LOOKUP(E1210,' + currentSheet + '!A1215,B1210:B1220)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(E1210,' + currentSheet + '!A1215,B1210:B1220)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of LOOKUP(E1210,' + currentSheet + '!A1215,B1210:B1220)'); // Case #94: Ref, Area, Ref3D. Bug 69527 - lookup with sheet reference in result array oParser = new parserFormula('LOOKUP(E1210,A1210:A1220,' + currentSheet + '!A1215)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(E1210,A1210:A1220,' + currentSheet + '!A1215)'); assert.strictEqual(oParser.calculate().getValue().getValue(), 3, 'Result of LOOKUP(E1210,A1210:A1220,' + currentSheet + '!A1215)'); // Case #95: Number, Area. 2D range lookup with mixed data types oParser = new parserFormula('LOOKUP(2.3,A1300:B1322)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(2.3,A1300:B1322)'); assert.strictEqual(oParser.calculate().getValue().getValue(), 3, 'Result of LOOKUP(2.3,A1300:B1322)'); // Case #96: String, Area. String lookup in 2D range with mixed types oParser = new parserFormula('LOOKUP("CIANO",A1300:B1322)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP("CIANO",A1300:B1322)'); assert.strictEqual(oParser.calculate().getValue().getValue(), 18, 'Result of LOOKUP("CIANO",A1300:B1322)'); // Case #97: Boolean, Area. FALSE lookup in 2D range with mixed types oParser = new parserFormula('LOOKUP(FALSE,A1300:B1322)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(FALSE,A1300:B1322)'); assert.strictEqual(oParser.calculate().getValue().getValue(), 22, 'Result of LOOKUP(FALSE,A1300:B1322)'); // Case #98: Boolean, Area3D. FALSE lookup in 2D range with mixed types oParser = new parserFormula('LOOKUP(FALSE,' + currentSheet + '!A1300:B1322)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(FALSE,' + currentSheet + '!A1300:B1322)'); assert.strictEqual(oParser.calculate().getValue().getValue(), 22, 'Result of LOOKUP(FALSE,' + currentSheet + '!A1300:B1322)'); // Case #99: Boolean, Name3D. FALSE lookup in 3D Named range with mixed types oParser = new parserFormula('LOOKUP(FALSE,LOOKUPTestNameArea3D)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(FALSE,LOOKUPTestNameArea3D)'); assert.strictEqual(oParser.calculate().getValue().getValue(), 22, 'Result of LOOKUP(FALSE,LOOKUPTestNameArea3D)'); // Case #100: Name3D, Name3D. lookup Name in 3DNameArea with mixed types oParser = new parserFormula('LOOKUP(LOOKUPTestName3D,LOOKUPTestNameArea3D)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(LOOKUPTestName3D,LOOKUPTestNameArea3D)'); assert.strictEqual(oParser.calculate().getValue().getValue(), 17, 'Result of LOOKUP(LOOKUPTestName3D,LOOKUPTestNameArea3D)'); // Case #101: Ref3D, Name3D. lookup Name in 3DNameArea with mixed types oParser = new parserFormula('LOOKUP(' + currentSheet + '!$A$1323,LOOKUPTestNameArea3D)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(' + currentSheet + '!$A$1323,LOOKUPTestNameArea3D)'); assert.strictEqual(oParser.calculate().getValue().getValue(), 17, 'Result of LOOKUP(LOOKUP(' + currentSheet + '!$A$1323,LOOKUPTestNameArea3D))'); // Case #102: Formula, Name3D. lookup Name in 3DNameArea with mixed types oParser = new parserFormula('LOOKUP(1+1,LOOKUPTestNameArea3D)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(1+1,LOOKUPTestNameArea3D))'); assert.strictEqual(oParser.calculate().getValue().getValue(), 2, 'Result of LOOKUP(1+1,LOOKUPTestNameArea3D)'); // Case #103: Formula, Name3D. lookup Name in 3DNameArea with mixed types oParser = new parserFormula('LOOKUP(ABS(2),LOOKUPTestNameArea3D)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(ABS(2),LOOKUPTestNameArea3D))'); assert.strictEqual(oParser.calculate().getValue().getValue(), 2, 'Result of LOOKUP(ABS(2),LOOKUPTestNameArea3D)'); // Negative Cases: // Case #1: Number, Array, Array. Result array shorter than lookup array, returns #N/A oParser = new parserFormula('LOOKUP(50,{0,1,2,3,49.75,55.75},{"KP";"NB"})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(50,{0,1,2,3,49.75,55.75},{"KP";"NB"})'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of LOOKUP(50,{0,1,2,3,49.75,55.75},{"KP";"NB"})'); // Case #2: Number, Number, Array. Single value lookup with 2D result array, returns #N/A oParser = new parserFormula('LOOKUP(1,1,{"KP","NB";1,2})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(1,1,{"KP","NB";1,2})'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of LOOKUP(1,1,{"KP","NB";1,2})'); // Case #3: Number, Array, Array. 1D lookup array with 2D result array, returns #N/A oParser = new parserFormula('LOOKUP(20,{0,1,49.75,55.75},{"KP","NB";1,2})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(20,{0,1,49.75,55.75},{"KP","NB";1,2})'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of LOOKUP(20,{0,1,49.75,55.75},{"KP","NB";1,2})'); // Case #4: Number, Array, Array. 2D lookup array with 2D result array, returns #N/A oParser = new parserFormula('LOOKUP(2,{1,2;1,2},{"KP","NB";1,2})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(2,{1,2;1,2},{"KP","NB";1,2})'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of LOOKUP(2,{1,2;1,2},{"KP","NB";1,2})'); // Case #5: Number, Array, Array. Single row lookup array with 2D result array, returns #N/A oParser = new parserFormula('LOOKUP(20,{-1,20},{"KP","NB";"sd","sf"})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(20,{-1,20},{"KP","NB";"sd","sf"})'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of LOOKUP(20,{-1,20},{"KP","NB";"sd","sf"})'); // Case #6: Number, Array, Array. 2D lookup array with 2D result array, returns #N/A oParser = new parserFormula('LOOKUP(20,{0,1;1,1},{"KP","NB";"sd","sf"})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(20,{0,1;1,1},{"KP","NB";"sd","sf"})'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of LOOKUP(20,{0,1;1,1},{"KP","NB";"sd","sf"})'); // Case #7: Number, Array, Number. Bug 67743 - no exact match in 2D array, returns #N/A oParser = new parserFormula('LOOKUP(11,{10,11,12;2,3,4},2)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(11,{10,11,12;2,3,4},2)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of LOOKUP(11,{10,11,12;2,3,4},2)'); // Case #8: Number, Array, Array. Lookup value smaller than minimum in array, returns #N/A oParser = new parserFormula('LOOKUP(-5,{0,1,2,3},{10,20,30,40})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(-5,{0,1,2,3},{10,20,30,40})'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of LOOKUP(-5,{0,1,2,3},{10,20,30,40})'); // Case #9: String, Array, Array. String lookup smaller than minimum, returns #N/A oParser = new parserFormula('LOOKUP("A",{"B","C","D"},{"second","third","fourth"})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP("A",{"B","C","D"},{"second","third","fourth"})'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of LOOKUP("A",{"B","C","D"},{"second","third","fourth"})'); // Case #10: Number, Array, Array. Lookup with error values in result array, returns error oParser = new parserFormula('LOOKUP(2,{1,2,3},{10,#VALUE!,30})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(2,{1,2,3},{10,#VALUE!,30})'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of LOOKUP(2,{1,2,3},{10,#VALUE!,30})'); // Case #11: Number, Array, Array. Lookup with mismatched array sizes, index beyond result array, returns #N/A oParser = new parserFormula('LOOKUP(5,{1,2,3},{10,20})', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(5,{1,2,3},{10,20})'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of LOOKUP(5,{1,2,3},{10,20})'); // Case #12: Number, Area, Area. Lookup value smaller than minimum, returns #N/A oParser = new parserFormula("LOOKUP(0, A1000:A1004, B1000:B1004)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #13: Number, Area, Area. Horizontal lookup value smaller than minimum, returns #N/A oParser = new parserFormula("LOOKUP(0,C1020:H1020,C1021:H1021)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #14: Empty, Area, Area. Empty lookup value in range, returns #N/A oParser = new parserFormula("LOOKUP(,A1041:A1044,B1041:B1044)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #15: Area, Area, Area. Multi-cell range as lookup value, returns #VALUE! oParser = new parserFormula("LOOKUP(A1041:A1042,A1041:A1044,B1041:B1044)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(A1041:A1042,A1041:A1044,B1041:B1044)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", "Result of LOOKUP(A1041:A1042,A1041:A1044,B1041:B1044)"); // Case #16: Area, Area, String. Range lookup with undefined variable, returns #NAME? oParser = new parserFormula("LOOKUP(A1041:A1041,A1041:A1044,a)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(A1041:A1041,A1041:A1044,a)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#NAME?", "Result of LOOKUP(A1041:A1041,A1041:A1044,a)"); // Case #17: Ref, Area, Empty. Range lookup with empty result parameter, returns #VALUE! oParser = new parserFormula("LOOKUP(A1041,A1041:A1044,)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(1,A1041:A1044,)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of LOOKUP(1,A1041:A1044,)"); // Case #18: Ref, Ref, Empty. Single cell lookup with empty result parameter, returns #VALUE! oParser = new parserFormula("LOOKUP(A1041,A1041,)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(1,A1041,)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of LOOKUP(1,A1041,)"); // Case #19: Ref, Ref, Empty. Different single cell lookup with empty result parameter, returns #VALUE! oParser = new parserFormula("LOOKUP(A1041,A1044,)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(1,A1044,)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of LOOKUP(1,A1044,)"); // Case #20: Boolean, Area, Area. FALSE lookup in mixed range, returns #N/A oParser = new parserFormula("LOOKUP(FALSE,A1041:A1047,B1041:B1047)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(FALSE,A1041:A1047,B1041:B1047)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of LOOKUP(FALSE,A1041:A1047,B1041:B1047)"); // Case #21: Ref, Area, Area. Range reference with FALSE value, returns #N/A oParser = new parserFormula("LOOKUP(A1047,A1041:A1047,B1041:B1047)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(FALSE,A1041:A1047,B1041:B1047)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of LOOKUP(FALSE,A1041:A1047,B1041:B1047)"); // Case #22: Boolean, Area, Area. FALSE lookup in different range, returns #N/A oParser = new parserFormula("LOOKUP(FALSE,G1070:G1076,H1070:H1076)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(FALSE,G1070:G1076,H1070:H1076)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of LOOKUP(FALSE,G1070:G1076,H1070:H1076)"); // Case #23: Ref, Area, Area. Range reference with FALSE in different location, returns #N/A oParser = new parserFormula("LOOKUP(G1076,G1070:G1076,H1070:H1076)", "A2", ws); assert.ok(oParser.parse(), "LOOKUP(FALSE,G1070:G1076,H1070:H1076)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of LOOKUP(FALSE,G1070:G1076,H1070:H1076)"); // Case #24: Number, Area, Area. Lookup value smaller than minimum in sparse range, returns #N/A oParser = new parserFormula("LOOKUP(1,C1090:K1090,C1091:K1091)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // Case #25: Number, Area, Area. Bug 62730 - lookup with arithmetic and incompatible range sizes, returns #N/A oParser = new parserFormula('LOOKUP(1,A1180:A1190+A1180:A1190,B1180:B1187+B1180:B1181)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(1,A1180:A1190+A1180:A1190,B1180:B1187+B1180:B1181)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of LOOKUP(1,A1180:A1190+A1180:A1190,B1180:B1187+B1180:B1181)'); // Case #26: Number, Area, Area. Bug 67743 - lookup with range arithmetic and incompatible result range, returns #N/A oParser = new parserFormula('LOOKUP(5,A1200:A1202+{1},A1200:D1201)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(5,A1200:A1202+{1},A1200:D1201)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of LOOKUP(5,A1200:A1202+{1},A1200:D1201)'); // Case #27: Number, Number, String. Lookup value greater than single lookup value, returns #VALUE! oParser = new parserFormula('LOOKUP(3,4,"a")', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(3,4,"a")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of LOOKUP(3,4,"a")'); // Case #28: Number, String, Number. Lookup with string in lookup array, returns #VALUE! oParser = new parserFormula('LOOKUP(3,"a",1)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(3,"a",1)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of LOOKUP(3,"a",1)'); // Case #29: Number, Area. Lookup value smaller than minimum in 2D range, returns #N/A oParser = new parserFormula('LOOKUP(-1,A1300:B1322)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(-1,A1300:B1322)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of LOOKUP(-1,A1300:B1322)'); // Case #30: Error, Area. Error value lookup in 2D range, returns #N/A oParser = new parserFormula('LOOKUP(#N/A,A1300:B1322)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP(#N/A,A1300:B1322)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of LOOKUP(#N/A,A1300:B1322)'); // Case #31: String, Area. 2D range lookup number as string oParser = new parserFormula('LOOKUP("2.3",A1300:B1322)', "A2", ws); assert.ok(oParser.parse(), 'LOOKUP("2.3",A1300:B1322)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of LOOKUP(2.3,A1300:B1322)'); wb.delDefinesNames(defName3D); wb.delDefinesNames(defNameArea3D); }); QUnit.test("Test: \"XLOOKUP\"", function (assert) { ws.getRange2("A551").setValue("6"); ws.getRange2("A552").setValue("2"); ws.getRange2("A553").setValue("test"); ws.getRange2("A554").setValue("5"); ws.getRange2("A555").setValue("4"); ws.getRange2("A556").setValue("12"); ws.getRange2("A557").setValue("16"); ws.getRange2("A558").setValue("14"); ws.getRange2("A559").setValue("99"); ws.getRange2("A560").setValue("tt"); ws.getRange2("A561").setValue("t4"); ws.getRange2("B551").setValue("a"); ws.getRange2("B552").setValue("b"); ws.getRange2("B553").setValue("c"); ws.getRange2("B554").setValue("d"); ws.getRange2("B555").setValue("e"); ws.getRange2("B556").setValue("f"); ws.getRange2("B557").setValue("g"); ws.getRange2("B558").setValue("l"); ws.getRange2("B559").setValue("n"); ws.getRange2("B560").setValue("u"); ws.getRange2("B561").setValue("p"); ws.getRange2("C551").setValue("a1"); ws.getRange2("C552").setValue("b1"); ws.getRange2("C553").setValue("test2"); ws.getRange2("C554").setValue("c2"); ws.getRange2("C555").setValue("d2"); ws.getRange2("C556").setValue("h3"); ws.getRange2("C557").setValue("j5"); ws.getRange2("C558").setValue("u2"); ws.getRange2("C559").setValue("m1"); ws.getRange2("C560").setValue("k"); ws.getRange2("C561").setValue("l"); ws.getRange2("C565").setValue("99"); ws.getRange2("A203").setValue("Mark"); ws.getRange2("A204").setValue("Ned"); ws.getRange2("A205").setValue("Hans"); ws.getRange2("A206").setValue("Martha"); ws.getRange2("A207").setValue("Greg"); ws.getRange2("A208").setValue("Scott"); ws.getRange2("A209").setValue("Jenna"); ws.getRange2("A210").setValue("Donna"); ws.getRange2("B202").setValue("Math"); ws.getRange2("B203").setValue("87"); ws.getRange2("B204").setValue("67"); ws.getRange2("B205").setValue("16"); ws.getRange2("B206").setValue("68"); ws.getRange2("B207").setValue("21"); ws.getRange2("B208").setValue("72"); ws.getRange2("B209").setValue("19"); ws.getRange2("B210").setValue("14"); ws.getRange2("C202").setValue("Physics"); ws.getRange2("C203").setValue("91"); ws.getRange2("C204").setValue("71"); ws.getRange2("C205").setValue("32"); ws.getRange2("C206").setValue("82"); ws.getRange2("C207").setValue("94"); ws.getRange2("C208").setValue("38"); ws.getRange2("C209").setValue("40"); ws.getRange2("C210").setValue("69"); ws.getRange2("A300").setValue("String"); ws.getRange2("A301").setValue("1"); ws.getRange2("A302").setValue("2"); ws.getRange2("A303").setValue("3"); ws.getRange2("A304").setValue("#VALUE!"); ws.getRange2("A305").setValue("#NUM!"); ws.getRange2("A306").setValue("#DIV/0!"); ws.getRange2("A307").setValue("TRUE"); ws.getRange2("A308").setValue("Sandra"); ws.getRange2("A309").setValue(""); ws.getRange2("A310").setValue(""); ws.getRange2("A311").setValue("5"); ws.getRange2("B300").setValue("1"); ws.getRange2("B301").setValue("2"); ws.getRange2("B302").setValue("3"); ws.getRange2("B303").setValue("4"); ws.getRange2("B304").setValue("5"); ws.getRange2("B305").setValue("6"); ws.getRange2("B306").setValue("7"); ws.getRange2("B307").setValue("8"); ws.getRange2("B308").setValue("9"); ws.getRange2("B309").setValue("10"); ws.getRange2("B310").setValue("11"); ws.getRange2("B311").setValue("12"); ws.getRange2("A1101:B1123").cleanAll(); ws.getRange2("A1101").setValue("0"); ws.getRange2("A1102").setValue("0"); ws.getRange2("A1103").setValue("2.1"); ws.getRange2("A1104").setValue("2.4"); ws.getRange2("A1105").setValue("2.4"); ws.getRange2("A1106").setValue("9"); ws.getRange2("A1107").setValue("10"); ws.getRange2("A1108").setValue("11"); ws.getRange2("A1109").setValue("11"); ws.getRange2("A1110").setValue("11"); ws.getRange2("A1111").setValue("12"); ws.getRange2("A1112").setValue("12"); ws.getRange2("A1113").setValue("12"); ws.getRange2("A1114").setValue("67"); ws.getRange2("A1115").setValue(""); ws.getRange2("A1116").setValue("ALDEBARAN"); ws.getRange2("A1117").setValue("BLUE"); ws.getRange2("A1118").setValue("CIANO"); ws.getRange2("A1119").setValue("RED"); ws.getRange2("A1120").setValue("#N/A"); ws.getRange2("A1121").setValue("Vega"); ws.getRange2("A1122").setValue("FALSE"); ws.getRange2("A1123").setValue("TRUE"); ws.getRange2("B1101").setValue("1"); ws.getRange2("B1102").setValue("2"); ws.getRange2("B1103").setValue("3"); ws.getRange2("B1104").setValue("4"); ws.getRange2("B1105").setValue("5"); ws.getRange2("B1106").setValue("6"); ws.getRange2("B1107").setValue("7"); ws.getRange2("B1108").setValue("8"); ws.getRange2("B1109").setValue("9"); ws.getRange2("B1110").setValue("10"); ws.getRange2("B1111").setValue("11"); ws.getRange2("B1112").setValue("12"); ws.getRange2("B1113").setValue("13"); ws.getRange2("B1114").setValue("14"); ws.getRange2("B1115").setValue("15"); ws.getRange2("B1116").setValue("16"); ws.getRange2("B1117").setValue("17"); ws.getRange2("B1118").setValue("18"); ws.getRange2("B1119").setValue("19"); ws.getRange2("B1120").setValue("20"); ws.getRange2("B1121").setValue("21"); ws.getRange2("B1122").setValue("22"); ws.getRange2("B1123").setValue("23"); ws.getRange2("A700:G710").setValue("1"); ws.getRange2("A701").setValue("2"); ws.getRange2("B701:G701").setValue("3"); ws.getRange2("A1201:B1223").cleanAll(); ws.getRange2("A1201").setValue("a"); ws.getRange2("A1202").setValue("1"); ws.getRange2("A1203").setValue("a"); ws.getRange2("A1204").setValue("a"); ws.getRange2("A1205").setValue("1"); ws.getRange2("A1206").setValue("a"); ws.getRange2("A1207").setValue("a"); ws.getRange2("A1208").setValue("a"); ws.getRange2("A1209").setValue("a"); ws.getRange2("A1210").setValue("a"); ws.getRange2("B1201").setValue("1"); ws.getRange2("B1202").setValue("2"); ws.getRange2("B1203").setValue("3"); ws.getRange2("B1204").setValue("4"); ws.getRange2("B1205").setValue("5"); ws.getRange2("B1206").setValue("6"); ws.getRange2("B1207").setValue("7"); ws.getRange2("B1208").setValue("8"); ws.getRange2("B1209").setValue("9"); ws.getRange2("B1210").setValue("10"); ws.getRange2("A1301:B1310").cleanAll(); ws.getRange2("A1301").setValue("a"); ws.getRange2("A1302").setValue("a"); ws.getRange2("A1303").setValue("a"); ws.getRange2("A1304").setValue("a"); ws.getRange2("A1305").setValue("#N/A"); ws.getRange2("A1306").setValue("a"); ws.getRange2("A1307").setValue("a"); ws.getRange2("A1308").setValue("a"); ws.getRange2("A1309").setValue("a"); ws.getRange2("A1310").setValue("a"); ws.getRange2("B1301").setValue("1"); ws.getRange2("B1302").setValue("2"); ws.getRange2("B1303").setValue("3"); ws.getRange2("B1304").setValue("4"); ws.getRange2("B1305").setValue("5"); ws.getRange2("B1306").setValue("6"); ws.getRange2("B1307").setValue("7"); ws.getRange2("B1308").setValue("8"); ws.getRange2("B1309").setValue("9"); ws.getRange2("B1310").setValue("10"); ws.getRange2("A1401:B1410").cleanAll(); ws.getRange2("A1401").setValue("a"); ws.getRange2("A1402").setValue("b"); ws.getRange2("A1403").setValue("a"); ws.getRange2("A1404").setValue("a"); ws.getRange2("A1405").setValue("#N/A"); ws.getRange2("A1406").setValue("a"); ws.getRange2("A1407").setValue("a"); ws.getRange2("A1408").setValue("a"); ws.getRange2("A1409").setValue("a"); ws.getRange2("A1410").setValue("a"); ws.getRange2("B1401").setValue("1"); ws.getRange2("B1402").setValue("2"); ws.getRange2("B1403").setValue("3"); ws.getRange2("B1404").setValue("4"); ws.getRange2("B1405").setValue("5"); ws.getRange2("B1406").setValue("6"); ws.getRange2("B1407").setValue("7"); ws.getRange2("B1408").setValue("8"); ws.getRange2("B1409").setValue("9"); ws.getRange2("B1410").setValue("10"); ws.getRange2("A1501:B1510").cleanAll(); ws.getRange2("A1501").setValue("1"); ws.getRange2("A1502").setValue("1"); ws.getRange2("A1503").setValue("1"); ws.getRange2("A1504").setValue("1"); ws.getRange2("A1505").setValue("#N/A"); ws.getRange2("A1506").setValue("1"); ws.getRange2("A1507").setValue("1"); ws.getRange2("A1508").setValue("1"); ws.getRange2("A1509").setValue("1"); ws.getRange2("A1510").setValue("1"); ws.getRange2("B1501").setValue("1"); ws.getRange2("B1502").setValue("2"); ws.getRange2("B1503").setValue("3"); ws.getRange2("B1504").setValue("4"); ws.getRange2("B1505").setValue("5"); ws.getRange2("B1506").setValue("6"); ws.getRange2("B1507").setValue("7"); ws.getRange2("B1508").setValue("8"); ws.getRange2("B1509").setValue("9"); ws.getRange2("B1510").setValue("10"); const defName3D = new Asc.asc_CDefName('XLOOKUPTestName3D', ws.getName() + '!$A$1118'); const defNameArea3D = new Asc.asc_CDefName('XLOOKUPTestNameArea3D', ws.getName() + '!$A$1101:$A$1123'); const defNameArea3DResult = new Asc.asc_CDefName('XLOOKUPTestNameArea3DResult', ws.getName() + '!$B$1101:$B$1123'); const defName3D2 = new Asc.asc_CDefName('XLOOKUPTestName3D2', ws.getName() + '!$B$1101') wb.editDefinesNames(null, defName3D); wb.editDefinesNames(null, defNameArea3D); wb.editDefinesNames(null, defNameArea3DResult); wb.editDefinesNames(null, defName3D2); AscCommonExcel.g_oVLOOKUPCache.clean(); // Positive Cases: // Case #1: Number, Array, Array. Exact match number oParser = new parserFormula('XLOOKUP(2,{1,2,3,4},{10,20,30,40})', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 20); // Case #2: Number, Array, Array, , Number. Exact match number oParser = new parserFormula('XLOOKUP(2,{1,2,3,4},{10,20,30,40},,0)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 20); // Case #3: Number, Array, Array, , Number. Search for nearest smaller value (match_mode = -1) oParser = new parserFormula('XLOOKUP(2.5,{1,2,3,4},{10,20,30,40},,-1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 20); // Case #4: Number, Array, Array, , Number. Search for nearest larger value (match_mode = 1) oParser = new parserFormula('XLOOKUP(2.5,{1,2,3,4},{10,20,30,40},,1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 30); // Case #5: Number, Array, Array, , , Number. Search from last element (search_mode = -1) oParser = new parserFormula('XLOOKUP(2,{1,2,3,2},{10,20,30,40},,,-1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 40); // Case #6: Number, Array, Array, , , Number. Search from frist element (search_mode = 1) oParser = new parserFormula('XLOOKUP(2,{1,2,3,2},{10,20,30,40},,,1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 20); // Case #7: Number, Array, Array, , , Number. Wildcard search (match_mode = 2) oParser = new parserFormula('XLOOKUP(2,{1,2,3,2},{10,20,30,40},,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 20); // Case #8: String, Array, Array. Exact match string oParser = new parserFormula('XLOOKUP("b",{"a","b","c","d"},{"apple","banana","cherry","date"})', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "banana"); // Case #9: String, Array, Array. Search for nearest smaller value (match_mode = -1) oParser = new parserFormula('XLOOKUP("b",{"a","a","c","d"},{"apple","apple2","cherry","date"},,-1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "apple"); // Case #10: Number, Array, Array, , Number. Search for nearest larger value (match_mode = 1) oParser = new parserFormula('XLOOKUP("b",{"a","a","c","d"},{"apple","apple2","cherry","date"},,-1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "apple"); // Case #11: Boolean, Array, Array. Exact match boolean oParser = new parserFormula('XLOOKUP(FALSE,{"a","b",FALSE,"d"},{1,2,3,4})', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 3); // Case #12: Number, Array, Array, String. Search with if_not_found parameter oParser = new parserFormula('XLOOKUP(5,{1,2,3,4},{10,20,30,40},"Not Found")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "Not Found"); // Case #13: String, Array, Array, , Number. Wildcard search (match_mode = 2) oParser = new parserFormula('XLOOKUP("a*",{"apple","banana","apricot"},{"fruit1","fruit2","fruit3"},,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "fruit1"); // Case #14: String, Array, Array, , Number, Number. Wildcard with search_mode oParser = new parserFormula('XLOOKUP("*le",{"apple","table","simple"},{"fruit","furniture","adjective"},,2,1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "fruit"); // Case #15: String, Array, Array, , Number. Search with partial wildcard oParser = new parserFormula('XLOOKUP("te?t",{"test","text","tent"},{"word1","word2","word3"},,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "word1"); // Case #16: String, Array, Array. Search with empty values oParser = new parserFormula('XLOOKUP("",{"","a","b"},{0,1,2})', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 0); // Case #17: String, Array, Array. Search in mixed array (numbers and text) oParser = new parserFormula('XLOOKUP("test",{1,"test",3,"hello"},{10,20,30,40})', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 20); // Case #18: String, Array, Array. Search with duplicate values (first match) oParser = new parserFormula('XLOOKUP("x",{"x","y","x","z"},{"first","second","third","fourth"})', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "first"); // Case #19: String, String, String. if searchValue = second arg, return third oParser = new parserFormula('XLOOKUP("123","123",22)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 22); // Case #20: Number, Array, Array, , Number, Number. BinarySearch oParser = new parserFormula('XLOOKUP(1,{1,2,3,4},{1,2,3,4},,0,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 1); // Case #21: Number, Array, Array, , Number, Number. Reversed binarySearch oParser = new parserFormula('XLOOKUP(1,{4,3,2,1},{1,2,3,4},,0,-2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 4); // Case #22: String, Array, Array, , Number, Number. BinarySearch oParser = new parserFormula('XLOOKUP("1",{"1","2","3","4"},{1,2,3,4})', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 1); // Case #23: Number, Array, Array, , Number, Number. BinarySearch oParser = new parserFormula('XLOOKUP(1,{0,2,3,4},{1,2,3,4},,-1,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 1); // Case #24: Number, Array, Array, , Number, Number. Reversed BinarySearch oParser = new parserFormula('XLOOKUP(1,{4,3,2,0},{1,2,3,4},,-1,-2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 4); // Case #25: Number, Array, Array, , Number, Number. Reversed BinarySearch oParser = new parserFormula('XLOOKUP(1,{4,3,2,0},{1,2,3,4},,1,-2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 3); // Case #26: String, Array, Array, , Number, Number. BinarySearch. Mixed values, exact match. oParser = new parserFormula('XLOOKUP("a",{1,2,3,4,5,6,7,8,"a",10},{1,2,3,4,5,6,7,8,9,10},,0,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 9); // Case #27: String, Array, Array, , Number, Number. Reversed BinarySearch. Mixed values, exact match. oParser = new parserFormula('XLOOKUP("a",{10,"a",9,8,7,6,5,4,3,2},{1,2,3,4,5,6,7,8,9,10},,0,-2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 2); // Case #28: String, Array, Array, , Number, Number. BinarySearch. Mixed values, arg4 = 1. oParser = new parserFormula('XLOOKUP("c",{1,"c",3,4,"a",6,"b","c","b",10},{1,2,3,4,5,6,7,8,9,10},,1,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 8); // Case #29: String, Array, Array, , Number, Number. BinarySearch. Mixed values, arg4 = -1. oParser = new parserFormula('XLOOKUP("c",{1,"c",3,4,"a",6,"b","d","b",10},{1,2,3,4,5,6,7,8,9,10},,-1,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 7); // Case #30: String, Array, Array, , Number, Number. Reversed BinarySearch. Mixed values, arg4 = -1. oParser = new parserFormula('XLOOKUP("c",{1,"c",3,4,"a",6,"b","d","b",10},{1,2,3,4,5,6,7,8,9,10},,-1,-2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 2); // Case #31: String, Array, Array, , Number, Number. Reversed BinarySearch. Mixed values, arg4 = -1. oParser = new parserFormula('XLOOKUP("c",{1,"d",3,4,"a",6,"b","d","b",10},{1,2,3,4,5,6,7,8,9,10},,-1,-2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 3); // Case #32: String, Array, Array, , Number, Number. Reversed BinarySearch. Mixed values, arg4 = 1. oParser = new parserFormula('XLOOKUP("c",{1,"d",3,4,"a",6,"b","d","b",10},{1,2,3,4,5,6,7,8,9,10},,1,-2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 2); // Case #33: Number, Area, Area. Basic lookup returning single value oParser = new parserFormula("XLOOKUP(14,A551:A561,C551:C561)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "u2"); // Case #34: Ref, Area, Area. Lookup with cell reference returning array values oParser = new parserFormula("XLOOKUP(C565,A551:A561,B551:C561)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate(), 0, 0), "n"); assert.strictEqual(_getValue(oParser.calculate(), 0, 1), "m1"); // Case #35: Number, Area, Area, String. Lookup with if_not_found parameter (should return "not found") oParser = new parserFormula('XLOOKUP(1,A551:A561,B551:C561,"not found")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "not found"); // Case #36: Number, Area, Area, Number, Number, Number. Lookup with match_mode=1 (exact match or next smallest item) oParser = new parserFormula('XLOOKUP(10,A551:A561,B551:C561,0,1,1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate(), 0, 0), "f"); assert.strictEqual(_getValue(oParser.calculate(), 0, 1), "h3"); // Case #37: Number, Area, Area, Number, Number, Number. Lookup with match_mode=-1 (exact match or next largest item) oParser = new parserFormula('XLOOKUP(10,A551:A561,B551:C561,0,-1,1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate(), 0, 0), "a"); assert.strictEqual(_getValue(oParser.calculate(), 0, 1), "a1"); // Case #38: Number, Area, Area, Number, Number. Lookup with match_mode=0 (exact match only, should return 0 as if_not_found) oParser = new parserFormula('XLOOKUP(10,A551:A561,B551:C561,0,0)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 0); // Case #39: String, Area, Area, , Number, Number. oParser = new parserFormula('XLOOKUP("test",A551:A561,B551:C561,,-1,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate(), 0, 0), "n"); // Case #40: String, Area, Area, , Number, Number. oParser = new parserFormula('XLOOKUP("tt",A551:A561,B551:C561,,-1,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate(), 0, 0), "u"); // Case #41: String, Area, Area, , Number. Wildcard lookup "t???" with match_mode=2 (? matches single character) oParser = new parserFormula('XLOOKUP("t???",A551:A561,B551:C561,,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate(), 0, 0), "c"); // Case #42: String, Area, Area, , Number, Number. Wildcard lookup "t???" with match_mode=2, search_mode=1 oParser = new parserFormula('XLOOKUP("t???",A551:A561,B551:C561,,2,-1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate(), 0, 0), "c"); // Case #43: String, Area, Area, , Number. Wildcard lookup "t?" with match_mode=2 (single ? wildcard) oParser = new parserFormula('XLOOKUP("t?",A551:A561,B551:C561,,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate(), 0, 0), "u"); // Case #44: String, Area, Area, , Number. Wildcard lookup "t*" with match_mode=2 (* matches any characters) oParser = new parserFormula('XLOOKUP("t*",A551:A561,B551:C561,,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate(), 0, 0), "c"); assert.strictEqual(_getValue(oParser.calculate(), 0, 1), "test2"); // Case #45: Number, Area, Area oParser = new parserFormula('XLOOKUP(19,B203:B210,A203:A210)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(19,B203:B210,A203:A210)'); assert.strictEqual(_getValue(oParser.calculate()), "Jenna", 'Result of XLOOKUP(19,B203:B210,A203:A210)'); // Case #46: Number, Formula, Area oParser = new parserFormula('XLOOKUP(19,XLOOKUP(B202,B202:C202,B203:C210),A203:A210)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(19,XLOOKUP(B202,B202:C202,B202:C210),A203:A210)'); assert.strictEqual(_getValue(oParser.calculate()), "Jenna", 'Result of XLOOKUP(19,XLOOKUP(B202,B202:C202,B202:C210),A203:A210)'); // Case #47: Number, Array, Area oParser = new parserFormula('XLOOKUP(19,{87;67;16;68;21;72;19;14},A203:A210)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(19,{87;67;16;68;21;72;19;14},A203:A210)'); assert.strictEqual(_getValue(oParser.calculate()), "Jenna", 'Result of XLOOKUP(19,{87;67;16;68;21;72;19;14},A203:A210)'); // Case #48: Number, Area, Area, String, Number. XLOOKUP returning range reference (should return cellsRange type). For bug 70550. oParser = new parserFormula('XLOOKUP(2,A100:A110,A100:G110,"",1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(2,A100:A110,A100:G110,"",1)'); assert.strictEqual(oParser.calculate().type, AscCommonExcel.cElementType.cellsRange, 'Result of XLOOKUP(2,A100:A110,A100:G110,"",1)'); // Case #49: XLOOKUP inside ISREF function. Testing if XLOOKUP result is a reference (should return TRUE). For bug 70550. oParser = new parserFormula('ISREF(XLOOKUP(2,A700:A710,A700:G710,"",1))', "A2", ws); assert.ok(oParser.parse(), 'ISREF(XLOOKUP(2,A700:A710,A700:G710,"",1))'); assert.strictEqual(oParser.calculate().getValue(), "TRUE", 'Result of ISREF(XLOOKUP(2,A700:A710,A700:G710,"",1))'); // Case #50: XLOOKUP in range operation with SUM. Using XLOOKUP result as range reference in SUM function. For bug 70550. oParser = new parserFormula('SUM(XLOOKUP(2,A700:A710,A700:G710,"",1):XLOOKUP(2,A700:A710,A700:G710,"",1))', "A2", ws); assert.ok(oParser.parse(), 'SUM(XLOOKUP(2,A700:A710,A700:G710,"",1):XLOOKUP(2,A700:A710,A700:G710,"",1))'); assert.strictEqual(oParser.calculate().getValue(), 20, 'Result of SUM(XLOOKUP(2,A700:A710,A700:G710,"",1):XLOOKUP(2,A700:A710,A700:G710,"",1))'); // Case #51: Number, Area, Area, , Number, Number. Number lookup with match_mode=1 and search_mode=2 (next smallest) oParser = new parserFormula('XLOOKUP(2.3,A1101:A1123,B1101:B1123,,1,2)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(2.3,A1101:A1123,B1101:B1123,,1,2)'); assert.strictEqual(_getValue(oParser.calculate()), 4, 'Result of XLOOKUP(2.3,A1101:A1123,B1101:B1123,,1,2)'); // Case #52: Number, Area, Area, , Number, Number. Number lookup with match_mode=-1 and search_mode=2 (next largest) oParser = new parserFormula('XLOOKUP(2.3,A1101:A1123,B1101:B1123,,-1,2)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(2.3,A1101:A1123,B1101:B1123,,-1,2)'); assert.strictEqual(_getValue(oParser.calculate()), 3, 'Result of XLOOKUP(2.3,A1101:A1123,B1101:B1123,,-1,2)'); // Case #53: Number, Area, Area, , Number, Number. Number lookup with match_mode=1 and search_mode=1 (linear search) oParser = new parserFormula('XLOOKUP(2.4,A1101:A1123,B1101:B1123,,1,1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(2.4,A1101:A1123,B1101:B1123,,1,1)'); assert.strictEqual(_getValue(oParser.calculate()), 4, 'Result of XLOOKUP(2.4,A1101:A1123,B1101:B1123,,1,1)'); // Case #54: Number, Area, Area, , Number, Number. Number lookup with match_mode=-1 and search_mode=1 (linear search) oParser = new parserFormula('XLOOKUP(2.4,A1101:A1123,B1101:B1123,,-1,1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(2.4,A1101:A1123,B1101:B1123,,-1,1)'); assert.strictEqual(_getValue(oParser.calculate()), 4, 'Result of XLOOKUP(2.4,A1101:A1123,B1101:B1123,,-1,1)'); // Case #55: String, Area, Area, , Number, Number. String lookup with match_mode=1 and search_mode=2. Case sensitivity check oParser = new parserFormula('XLOOKUP("cIano",A1101:A1123,B1101:B1123,,1,2)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("cIano",A1101:A1123,B1101:B1123,,1,2)'); assert.strictEqual(_getValue(oParser.calculate()), 18, 'Result of XLOOKUP("cIano",A1101:A1123,B1101:B1123,,1,2)'); // Case #56: String, Area, Area, , Number, Number. String lookup with match_mode=-1 and search_mode=2 oParser = new parserFormula('XLOOKUP("cIano",A1101:A1123,B1101:B1123,,-1,2)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("cIano",A1101:A1123,B1101:B1123,,-1,2)'); assert.strictEqual(_getValue(oParser.calculate()), 18, 'Result of XLOOKUP("cIano",A1101:A1123,B1101:B1123,,-1,2)'); // Case #57: Number, Area, Area, , Number, Number. Negative number lookup with match_mode=1 and search_mode=2 oParser = new parserFormula('XLOOKUP(-1,A1101:A1123,B1101:B1123,,1,2)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(-1,A1101:A1123,B1101:B1123,,1,2)'); assert.strictEqual(_getValue(oParser.calculate()), 1, 'Result of XLOOKUP(-1,A1101:A1123,B1101:B1123,,1,2)'); // Case #58: Boolean, Area, Area, , Number, Number. Boolean FALSE lookup with match_mode=1 and search_mode=1 oParser = new parserFormula('XLOOKUP(FALSE,A1101:A1123,B1101:B1123,,1,1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(FALSE,A1101:A1123,B1101:B1123,,1,1)'); assert.strictEqual(_getValue(oParser.calculate()), 22, 'Result of XLOOKUP(FALSE,A1101:A1123,B1101:B1123,,1,1)'); // Case #59: String, Area, Area, , Number, Number. String lookup "VIOLET" with match_mode=1 and search_mode=2 oParser = new parserFormula('XLOOKUP("VIOLET",A1101:A1123,B1101:B1123,,1,2)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("VIOLET",A1101:A1123,B1101:B1123,,1,2)'); assert.strictEqual(_getValue(oParser.calculate()), 22, 'Result of XLOOKUP("VIOLET",A1101:A1123,B1101:B1123,,1,2)'); // Case #60: String, Area, Area, , Number, Number. String lookup "VIOLET" with match_mode=-1 and search_mode=2 oParser = new parserFormula('XLOOKUP("VIOLET",A1101:A1123,B1101:B1123,,-1,2)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("VIOLET",A1101:A1123,B1101:B1123,,-1,2)'); assert.strictEqual(_getValue(oParser.calculate()), 21, 'Result of XLOOKUP("VIOLET",A1101:A1123,B1101:B1123,,-1,2)'); // Case #61: String, Area, Area, , Number, Number. String lookup "VIOLET" with match_mode=1 and search_mode=1 oParser = new parserFormula('XLOOKUP("VIOLET",A1101:A1123,B1101:B1123,,1,1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("VIOLET",A1101:A1123,B1101:B1123,,1,1)'); assert.strictEqual(_getValue(oParser.calculate()), 22, 'Result of XLOOKUP("VIOLET",A1101:A1123,B1101:B1123,,1,1)'); // Case #62: String, Area, Area, , Number, Number. String lookup "VIOLET" with match_mode=-1 and search_mode=1 oParser = new parserFormula('XLOOKUP("VIOLET",A1101:A1123,B1101:B1123,,-1,1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("VIOLET",A1101:A1123,B1101:B1123,,-1,1)'); assert.strictEqual(_getValue(oParser.calculate()), 21, 'Result of XLOOKUP("VIOLET",A1101:A1123,B1101:B1123,,-1,1)'); // Case #63: String, Area, Area, , Number, Number. String lookup "VIOLET" with match_mode=-1 and search_mode=-1 oParser = new parserFormula('XLOOKUP("VIOLET",A1101:A1123,B1101:B1123,,-1,-1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("VIOLET",A1101:A1123,B1101:B1123,,-1,-1)'); assert.strictEqual(_getValue(oParser.calculate()), 21, 'Result of XLOOKUP("VIOLET",A1101:A1123,B1101:B1123,,-1,-1)'); // Case #64: String, Area, Area, , Number, Number. String lookup "VIOLET" with match_mode=1 and search_mode=-1 oParser = new parserFormula('XLOOKUP("VIOLET",A1101:A1123,B1101:B1123,,1,-1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("VIOLET",A1101:A1123,B1101:B1123,,1,-1)'); assert.strictEqual(_getValue(oParser.calculate()), 22, 'Result of XLOOKUP("VIOLET",A1101:A1123,B1101:B1123,,1,-1)'); // Case #65: Number, Area, Area, , Number, Number. Number match_mode=-1 and search_mode=-1 (reverse search) oParser = new parserFormula('XLOOKUP(1,A1201:A1210,B1201:B1210,, -1, -1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(1,A1201:A1210,B1201:B1210,, -1, -1)'); assert.strictEqual(_getValue(oParser.calculate()), 5, 'Result of XLOOKUP(1,A1201:A1210,B1201:B1210,, -1, -1)'); // Case #66: Number, Area, Area, , Number, Number. Number match_mode=-1 and search_mode=-1 (reverse search) oParser = new parserFormula('XLOOKUP(2,A1201:A1210,B1201:B1210,, -1, -1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(2,A1201:A1210,B1201:B1210,, -1, -1)'); assert.strictEqual(_getValue(oParser.calculate()), 5, 'Result of XLOOKUP(2,A1201:A1210,B1201:B1210,, -1, -1)'); // Case #67: Number, Area, Area, , Number, Number. Number match_mode=1 and search_mode=-1 (reverse linear search) oParser = new parserFormula('XLOOKUP(2,A1201:A1210,B1201:B1210,, 1, -1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(2,A1201:A1210,B1201:B1210,, 1, -1)'); assert.strictEqual(_getValue(oParser.calculate()), 10, 'Result of XLOOKUP(2,A1201:A1210,B1201:B1210,, 1, -1)'); // Case #68: Number, Area, Area, , Number, Number. Number match_mode=1 and search_mode=1 (linear search) oParser = new parserFormula('XLOOKUP(2,A1201:A1210,B1201:B1210,, 1, 1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(2,A1201:A1210,B1201:B1210,, 1, 1)'); assert.strictEqual(_getValue(oParser.calculate()), 1, 'Result of XLOOKUP(2,A1201:A1210,B1201:B1210,, 1, 1)'); // Case #69: Number, Area, Area, , Number, Number. Number match_mode=0 and search_mode=1 (exact match) oParser = new parserFormula('XLOOKUP(1,A1201:A1210,B1201:B1210,, 0, 1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(1,A1201:A1210,B1201:B1210,, 0, 1)'); assert.strictEqual(_getValue(oParser.calculate()), 2, 'Result of XLOOKUP(1,A1201:A1210,B1201:B1210,, 0, 1)'); // Case #70: Number, Area, Area, , Number, Number. Number match_mode=1 and search_mode=-2 (binary search descending) oParser = new parserFormula('XLOOKUP(1,A1201:A1210,B1201:B1210,, 1, -2)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(1,A1201:A1210,B1201:B1210,, 1, -2)'); assert.strictEqual(_getValue(oParser.calculate()), 5, 'Result of XLOOKUP(1,A1201:A1210,B1201:B1210,, 1, -2)'); // Case #71: Number, Area, Area, , Number, Number. Number match_mode=1 and search_mode=2 (binary search ascending) oParser = new parserFormula('XLOOKUP(1,A1201:A1210,B1201:B1210,, 1, 2)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(1,A1201:A1210,B1201:B1210,, 1, 2)'); assert.strictEqual(_getValue(oParser.calculate()), 2, 'Result of XLOOKUP(1,A1201:A1210,B1201:B1210,, 1, 2)'); // Case #72: String, Area, Area, , Number, Number. match_mode=1 and search_mode=-2 (binary search descending) oParser = new parserFormula('XLOOKUP("a",A1201:A1210,B1201:B1210,, 1, -2)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("a",A1201:A1210,B1201:B1210,, 1, -2)'); assert.strictEqual(_getValue(oParser.calculate()), 1, 'Result of XLOOKUP("a",A1201:A1210,B1201:B1210,, 1, -2)'); // Case #73: String, Area, Area, , Number, Number. match_mode=1 and search_mode=2 (binary search ascending) oParser = new parserFormula('XLOOKUP("a",A1201:A1210,B1201:B1210,, 1, 2)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("a",A1201:A1210,B1201:B1210,, 1, 2)'); assert.strictEqual(_getValue(oParser.calculate()), 6, 'Result of XLOOKUP("a",A1201:A1210,B1201:B1210,, 1, 2)'); // Case #74: String, Area, Area, , Number, Number. match_mode=1 and search_mode=1 (linear search) oParser = new parserFormula('XLOOKUP("a",A1201:A1210,B1201:B1210,, 1, 1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("a",A1201:A1210,B1201:B1210,, 1, 1)'); assert.strictEqual(_getValue(oParser.calculate()), 1, 'Result of XLOOKUP("a",A1201:A1210,B1201:B1210,, 1, 1)'); // Case #75: String, Area, Area, , Number, Number. match_mode=1 and search_mode=-1 (reverse linear search) oParser = new parserFormula('XLOOKUP("a",A1201:A1210,B1201:B1210,, 1, -1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("a",A1201:A1210,B1201:B1210,, 1, -1)'); assert.strictEqual(_getValue(oParser.calculate()), 10, 'Result of XLOOKUP("a",A1201:A1210,B1201:B1210,, 1, -1)'); // Case #76: Number, Area, Area, , Number, Number. match_mode=1 and search_mode=1 (linear search) oParser = new parserFormula('XLOOKUP(2,A1301:A1310,B1301:B1310,, 1, 1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(2,A1301:A1310,B1301:B1310,, 1, 1)'); assert.strictEqual(_getValue(oParser.calculate()), 1, 'Result of XLOOKUP(2,A1301:A1310,B1301:B1310,, 1, 1)'); // Case #77: String, Area, Area, , Number, Number. match_mode=1 and search_mode=1 (linear search) oParser = new parserFormula('XLOOKUP("b",A1301:A1310,B1301:B1310,, 1, 1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("b",A1301:A1310,B1301:B1310,, 1, 1'); assert.strictEqual(_getValue(oParser.calculate()), 5, 'Result of XLOOKUP("b",A1301:A1310,B1301:B1310,, 1, 1'); // Case #78: String, Area, Area, , Number, Number. match_mode=1 and search_mode=-1 (reverse linear search) oParser = new parserFormula('XLOOKUP("b",A1301:A1310,B1301:B1310,, 1, -1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("b",A1301:A1310,B1301:B1310,, 1, -1'); assert.strictEqual(_getValue(oParser.calculate()), 5, 'Result of XLOOKUP("b",A1301:A1310,B1301:B1310,, 1, -1'); // Case #79: String, Area, Area, , Number, Number. match_mode=1 and search_mode=2 (binary search ascending) oParser = new parserFormula('XLOOKUP("b",A1301:A1310,B1301:B1310,, 1, 2)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("b",A1301:A1310,B1301:B1310,, 1, 2'); assert.strictEqual(_getValue(oParser.calculate()), 5, 'Result of XLOOKUP("b",A1301:A1310,B1301:B1310,, 1, 2'); // Case #80: String, Area, Area, , Number, Number. match_mode=1 and search_mode=-2 (binary search descending) oParser = new parserFormula('XLOOKUP("b",A1301:A1310,B1301:B1310,, 1, -2)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("b",A1301:A1310,B1301:B1310,, 1, -2'); assert.strictEqual(_getValue(oParser.calculate()), 5, 'Result of XLOOKUP("b",A1301:A1310,B1301:B1310,, 1, -2'); // Case #81: String, Area, Area, , Number, Number. match_mode=1 and search_mode=-2 (binary search descending) oParser = new parserFormula('XLOOKUP("b",A1401:A1410,B1401:B1410,, 1, -2)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("b",A1401:A1410,B1401:B1410,, 1, -2'); assert.strictEqual(_getValue(oParser.calculate()), 5, 'Result of XLOOKUP("b",A1401:A1410,B1401:B1410,, 1, -2'); // Case #82: String, Area, Area, , Number, Number. match_mode=1 and search_mode=2 (binary search ascending) oParser = new parserFormula('XLOOKUP("b",A1401:A1410,B1401:B1410,, 1, 2)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("b",A1401:A1410,B1401:B1410,, 1, 2'); assert.strictEqual(_getValue(oParser.calculate()), 2, 'Result of XLOOKUP("b",A1401:A1410,B1401:B1410,, 1, 2'); // Case #83: Number, Area, Area, , Number, Number. match_mode=1 and search_mode=2 (binary search ascending) oParser = new parserFormula('XLOOKUP(1,A1401:A1410,B1401:B1410,, 1, 2)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(1,A1401:A1410,B1401:B1410,, 1, 2'); assert.strictEqual(_getValue(oParser.calculate()), 1, 'Result of XLOOKUP(1,A1401:A1410,B1401:B1410,, 1, 2'); // Case #84: Number, Area, Area, , Number, Number. match_mode=1 and search_mode=-2 (binary search descending) oParser = new parserFormula('XLOOKUP(1,A1401:A1410,B1401:B1410,, 1, -2)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(1,A1401:A1410,B1401:B1410,, 1, -2'); assert.strictEqual(_getValue(oParser.calculate()), 10, 'Result of XLOOKUP(1,A1401:A1410,B1401:B1410,, 1, -2'); // Case #85: String, Area, Area, , Number, Number. match_mode=-1 and search_mode=-2 (binary search descending) oParser = new parserFormula('XLOOKUP("a",A1501:A1510,B1501:B1510,, -1, -2)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("a",A1501:A1510,B1501:B1510,, -1, -2)'); assert.strictEqual(_getValue(oParser.calculate()), 6, 'XLOOKUP("a",A1501:A1510,B1501:B1510,, -1, -2)'); // Case #86: String, Area, Area, , Number, Number. match_mode=1 and search_mode=-2 (binary search descending) oParser = new parserFormula('XLOOKUP("a",A1501:A1510,B1501:B1510,, 1, -2)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("a",A1501:A1510,B1501:B1510,, 1, -2)'); assert.strictEqual(_getValue(oParser.calculate()), 5, 'XLOOKUP("a",A1501:A1510,B1501:B1510,, 1, -2)'); // Case #87: String, Area, Area, , Number, Number. match_mode=1 and search_mode=1 (linear search) oParser = new parserFormula('XLOOKUP("a",A1501:A1510,B1501:B1510,, 1, 1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("a",A1501:A1510,B1501:B1510,, 1, 1)'); assert.strictEqual(_getValue(oParser.calculate()), 5, 'XLOOKUP("a",A1501:A1510,B1501:B1510,, 1, 1)'); // Case #88: String, Area, Area, , Number, Number. match_mode=-1 and search_mode=1 (linear search) oParser = new parserFormula('XLOOKUP("a",A1501:A1510,B1501:B1510,, -1, 1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("a",A1501:A1510,B1501:B1510,, -1, 1)'); assert.strictEqual(_getValue(oParser.calculate()), 1, 'XLOOKUP("a",A1501:A1510,B1501:B1510,, -1, 1)'); // Case #89: Ref, Ref, Number. if searchValue = second arg, return third oParser = new parserFormula('XLOOKUP(A1501,A1501,22)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 22); // Case #90: Name3D, Name3D, Name3D oParser = new parserFormula('XLOOKUP(XLOOKUPTestName3D,XLOOKUPTestNameArea3D,XLOOKUPTestNameArea3DResult)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 18); // Case #91: Name3D, Name3D, Name3D, Name3D. Name3D, Name3D oParser = new parserFormula('XLOOKUP(XLOOKUPTestName3D,XLOOKUPTestNameArea3D,XLOOKUPTestNameArea3DResult,XLOOKUPTestName3D2,XLOOKUPTestName3D2,XLOOKUPTestName3D2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 18); // Case #92: Name3D, Name3D, Ref3D oParser = new parserFormula('XLOOKUP(XLOOKUPTestName3D,XLOOKUPTestNameArea3D,' + ws.getName() + '!$B$1101:$B$1123)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 18); // Case #93: Name3D, Ref3D, Ref3D oParser = new parserFormula('XLOOKUP(XLOOKUPTestName3D,' + ws.getName() + '!$A$1101:$A$1123,' + ws.getName() + '!$B$1101:$B$1123)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 18); // Case #94: Ref3D, Ref3D, Ref3D oParser = new parserFormula('XLOOKUP(' + ws.getName() + '!$A$1118,' + ws.getName() + '!$A$1101:$A$1123,' + ws.getName() + '!$B$1101:$B$1123)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 18); // Case #95: Ref3D, Ref3D, Ref3D, Ref3D, Ref3D, Ref3D oParser = new parserFormula('XLOOKUP(' + ws.getName() + '!$A$1118,' + ws.getName() + '!$A$1101:$A$1123,' + ws.getName() + '!$B$1101:$B$1123,' + ws.getName() + '!$B$1101,' + ws.getName() + '!$B$1101,' + ws.getName() + '!$B$1101)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 18); // Case #96: Formula, Ref3D, Ref3D oParser = new parserFormula('XLOOKUP(ABS(2.4),' + ws.getName() + '!$A$1101:$A$1123,' + ws.getName() + '!$B$1101:$B$1123)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 4); // Case #97: Formula, Ref3D, Ref3D, Formula, Formula, Formula oParser = new parserFormula('XLOOKUP(ABS(2.4),' + ws.getName() + '!$A$1101:$A$1123,' + ws.getName() + '!$B$1101:$B$1123,ABS(1),ABS(2),ABS(-1))', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 4); // TODO DYNAMIC ARRAYS in TESTS // Case #98: Number, Array, Array, Array, Array, Array. 4,5,6 args as arrays // oParser = new parserFormula('XLOOKUP(2,{1,2,3},{10,20,30},{1},{1},{1})', "A2", ws); // assert.ok(oParser.parse()); // assert.strictEqual(_getValue(oParser.calculate()), 20); // Case #99: Number, Array, Array, String, Number, Number. if_not_found empty string oParser = new parserFormula('XLOOKUP(7,{4,5,6},{1,2,3},"",1,1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), ""); // Case #100: String, Array, Array, , Number, Number. Wildcard with ~ oParser = new parserFormula('XLOOKUP("t~*st",{"test","thst","t*st","teest"},{1,2,3,4},,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 3); // Case #101: String, Array, Array, , Number, Number. Wildcard oParser = new parserFormula('XLOOKUP("?????",{"test","thst","t*st","teest"},{1,2,3,4},,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 4); // Case #102: String, Array, Array, , Number, Number. Wildcard oParser = new parserFormula('XLOOKUP("t*est",{"test2","t ass&^=d asd12312_%$!##****32 sdfsdfsdfsest","test123","teees t"},{1,2,3,4},,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 2); // Case #103: String, Array, Array, , Number, Number. Wildcard oParser = new parserFormula('XLOOKUP("t*est",{"test2","t ass&^=d asd12312_%$!##****32 sdfsdfsdfsest","test123","teees t"},{1,2,3,4},,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 2); // Case #104: String, Array, Array, , Number, Number. Wildcard oParser = new parserFormula('XLOOKUP("t*est",{"t*est","t ass&^=d asd12312_%$!##****32 sdfsdfsdfsest","test123","teees t"},{1,2,3,4},,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), 1); // Negative Cases: // Case #1: Number, Array, Array. Mismatched array sizes (should return #VALUE!) oParser = new parserFormula('XLOOKUP(2,{1,2,3},{10,20})', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "#VALUE!"); // Case #2: Number, Array, Array, , Number. Invalid match_mode value (should return #VALUE!) oParser = new parserFormula('XLOOKUP(2,{1,2,3},{10,20,30},,5)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "#VALUE!"); // Case #3: Number, Array, Array, , , Number. Invalid search_mode value (should return #VALUE!) oParser = new parserFormula('XLOOKUP(2,{1,2,3},{10,20,30},,,3)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "#VALUE!"); // Case #4: Error, Array, Array. Search for error, returning error oParser = new parserFormula('XLOOKUP(#N/A,{"a",1,2,3},{1,2,3,4})', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "#N/A"); // Case #5: String, Array, Array, , Number, Number. BinarySearch. Mixed values, arg4 = 1. Bad order oParser = new parserFormula('XLOOKUP("c",{1,"d",3,4,1,6,2,3,"b",10},{1,2,3,4,5,6,7,8,9,10},,1,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "#N/A"); // Case #6: Number, Area, Area. Basic lookup with no match (should return #N/A) oParser = new parserFormula('XLOOKUP(10,A551:A561,B551:C561)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "#N/A"); // Case #7: String, Area, Area, , Number. Wildcard "t*" with match_mode=0 (exact match, should return #N/A) oParser = new parserFormula('XLOOKUP("t*",A551:A561,B551:C561,,0)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "#N/A"); // Case #8: String, Area, Area, , Number. Wildcard "t?" with match_mode=0 (exact match, should return #N/A) oParser = new parserFormula('XLOOKUP("t?",A551:A561,B551:C561,,0)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "#N/A"); // Case #9: Number, Area, Area, , Number, Number. Lookup with match_mode=-1 and search_mode=-2 (should return #N/A) oParser = new parserFormula('XLOOKUP(10,A551:A561,B551:C561,,-1,-2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "#N/A"); // Case #10: Number, Area, Area, , , Number. Lookup with search_mode=-2 (binary search descending, should return #N/A) oParser = new parserFormula('XLOOKUP(10,A551:A561,B551:C561,,,-2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "#N/A"); // Case #11: Number, Area, Area, , , Number. Lookup with search_mode=2 (binary search ascending, should return #N/A) oParser = new parserFormula('XLOOKUP(10,A551:A561,B551:C561,,,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "#N/A"); // Case #12: Ref, Area, Area, Number, Number , Number oParser = new parserFormula('XLOOKUP(A304,A300:A311,B300:B311,-2,0,1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(A304,A300:A311,B300:B311,-2,0,1)'); assert.strictEqual(_getValue(oParser.calculate()), "#VALUE!", 'Result of XLOOKUP(A304,A300:A311,B300:B311,-2,0,1)'); // Case #13: Ref, Area, Area, Number, Number , Number oParser = new parserFormula('XLOOKUP(A305,A300:A311,B300:B311,-2,0,1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(A305,A300:A311,B300:B311,-2,0,1)'); assert.strictEqual(_getValue(oParser.calculate()), "#NUM!", 'Result of XLOOKUP(A305,A300:A311,B300:B311,-2,0,1)'); // Case #14: Ref, Area, Area, Number, Number , Number oParser = new parserFormula('XLOOKUP(A306,A300:A311,B300:B311,-2,0,1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(A306,A300:A311,B300:B311,-2,0,1)'); assert.strictEqual(_getValue(oParser.calculate()), "#DIV/0!", 'Result of XLOOKUP(A306,A300:A311,B300:B311,-2,0,1)'); // Case #15: Number, Area, Area, , Number, Number. Number lookup with match_mode=0 (exact match only, should return #N/A) oParser = new parserFormula('XLOOKUP(2.3,A1101:A1123,B1101:B1123,,0, 1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(2.3,A1101:A1123,B1101:B1123,,0, 1)'); assert.strictEqual(_getValue(oParser.calculate()), "#N/A", 'Result of XLOOKUP(2.3,A1101:A1123,B1101:B1123,,1,0)'); // Case #16: Error, Area, Area, , Number, Number. Error value #N/A lookup (should return #N/A) oParser = new parserFormula('XLOOKUP(#N/A,A1101:A1123,B1101:B1123,,1,1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(#N/A,A1101:A1123,B1101:B1123,,1,1)'); assert.strictEqual(_getValue(oParser.calculate()), "#N/A", 'Result of XLOOKUP(#N/A,A1101:A1123,B1101:B1123,,1,1)'); // Case #17: String, Area, Area, , Number, Number. String lookup with match_mode=0 (exact match only, should return #N/A) oParser = new parserFormula('XLOOKUP("VIOLET",A1101:A1123,B1101:B1123,,0, 1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("VIOLET",A1101:A1123,B1101:B1123,,0, 1)'); assert.strictEqual(_getValue(oParser.calculate()), "#N/A", 'Result of XLOOKUP("VIOLET",A1101:A1123,B1101:B1123,,1,0)'); // Case #18: Number, Area, Area, , Number, Number. Number match_mode=-1 and search_mode=-1 (should return #N/A) oParser = new parserFormula('XLOOKUP(0,A1201:A1210,B1201:B1210,, -1, -1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(0,A1201:A1210,B1201:B1210,, -1, -1)'); assert.strictEqual(_getValue(oParser.calculate()), "#N/A", 'Result of XLOOKUP(0,A1201:A1210,B1201:B1210,, -1, -1)'); // Case #19: String, Area, Area, , Number, Number. match_mode=0 and search_mode=1 (exact match, should return #N/A) oParser = new parserFormula('XLOOKUP("VIOLET",A1201:A1210,B1201:B1210,, 0, 1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("VIOLET",A1201:A1210,B1201:B1210,, 0, 1)'); assert.strictEqual(_getValue(oParser.calculate()), "#N/A", 'Result of XLOOKUP("VIOLET",A1201:A1210,B1201:B1210,, 0, 1)'); // Case #20: String, Area, Area, , Number, Number. match_mode=0 (exact match only, should return #N/A) oParser = new parserFormula('XLOOKUP("VIOLET",A1201:A1223,B1201:B1223,,0, 1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("VIOLET",A1201:A1223,B1201:B1223,,0, 1)'); assert.strictEqual(_getValue(oParser.calculate()), "#N/A", 'Result of XLOOKUP("VIOLET",A1201:A1223,B1201:B1223,,1,0)'); // Case #21: String, Area, Area, , Number, Number. match_mode=0 and search_mode=1 (exact match, should return #N/A) oParser = new parserFormula('XLOOKUP("VIOLET",A1301:A1310,B1301:B1310,, 0, 1)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP("VIOLET",A1301:A1310,B1301:B1310,, 0, 1)'); assert.strictEqual(_getValue(oParser.calculate()), "#N/A", 'Result of XLOOKUP("VIOLET",A1301:A1310,B1301:B1310,, 0, 1)'); // Case #22: Number, Area, Area, , Number, Number. match_mode=-1 and search_mode=-2 (should return #N/A) oParser = new parserFormula('XLOOKUP(1,A1401:A1410,B1401:B1410,, -1, -2)', "A2", ws); assert.ok(oParser.parse(), 'XLOOKUP(1,A1401:A1410,B1401:B1410,, -1, -2)'); assert.strictEqual(_getValue(oParser.calculate()), "#N/A", 'XLOOKUP(1,A1401:A1410,B1401:B1410,, -1, -2)'); // Case #23: Number, Array, Array, String, String, String. bad 4,5,6 args oParser = new parserFormula('XLOOKUP(2,{1,2,3},{10,20,30},"a","b","c")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "#VALUE!"); // Case #24: Number, Array, Array, Number, Number, Number. bad 4,5,6 args oParser = new parserFormula('XLOOKUP(2,{1,2,3},{10,20,30},20,10,30)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "#VALUE!"); // Case #25: Number, Array, Array, Name, Name, Name. bad 4,5,6 args, not existed Name oParser = new parserFormula('XLOOKUP(2,{1,2,3},{10,20,30},AWESOMEBADARG,AWESOMEBADARG,AWESOMEBADARG)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "#NAME?"); // Case #26: String, Array, Array, , Number, Number. Sizes mismatch oParser = new parserFormula('XLOOKUP("a",A1501:A1555,B1501:B1510,, -1, 1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "#VALUE!"); // Case #26: String, Array, Array, , Number, Number. Sizes mismatch oParser = new parserFormula('XLOOKUP("a",A1501:A1510,B1501:B1515,, -1, 1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(_getValue(oParser.calculate()), "#VALUE!"); wb.delDefinesNames(defName3D); wb.delDefinesNames(defNameArea3D); wb.delDefinesNames(defNameArea3DResult); wb.delDefinesNames(defName3D2); }); QUnit.test("Test: \"MATCH\"", function (assert) { AscCommonExcel.bIsSupportDynamicArrays = false; ws.getRange2("A551").setValue("28"); ws.getRange2("A552").setValue("29"); ws.getRange2("A553").setValue("31"); ws.getRange2("A554").setValue("45"); ws.getRange2("A555").setValue("89"); ws.getRange2("B551").setValue("89"); ws.getRange2("B552").setValue("45"); ws.getRange2("B553").setValue("31"); ws.getRange2("B554").setValue("29"); ws.getRange2("B555").setValue("28"); ws.getRange2("C551").setValue("89"); ws.getRange2("C552").setValue("45"); ws.getRange2("C553").setValue("31"); ws.getRange2("C554").setValue("29"); ws.getRange2("C555").setValue("28"); oParser = new parserFormula("MATCH(30,A551:A555,-1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "MATCH_1"); oParser = new parserFormula("MATCH(30,A551:A555,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2, "MATCH_2"); oParser = new parserFormula("MATCH(30,A551:A555,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "MATCH_3"); oParser = new parserFormula("MATCH(30,B551:B555)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "MATCH_4"); oParser = new parserFormula("MATCH(30,B551:B555,-1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3, "MATCH_5"); oParser = new parserFormula("MATCH(30,B551:B555,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "MATCH_6"); oParser = new parserFormula("MATCH(31,C551:C555,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3, "MATCH_7"); oParser = new parserFormula("MATCH(\"b\",{\"a\";\"b\";\"c\"},0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2, "MATCH_8"); ws.getRange2("F3").setValue(""); ws.getRange2("F106").setValue("1"); ws.getRange2("F107").setValue(""); ws.getRange2("F108").setValue(""); ws.getRange2("F109").setValue(""); ws.getRange2("F110").setValue("2"); ws.getRange2("F111").setValue("123"); ws.getRange2("F112").setValue("4"); ws.getRange2("F113").setValue("5"); ws.getRange2("F114").setValue("6"); ws.getRange2("F115").setValue("0"); ws.getRange2("F116").setValue(""); ws.getRange2("F117").setValue("0"); oParser = new parserFormula("MATCH(F3,F106:F114,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "MATCH_9"); oParser = new parserFormula("MATCH(F3,F106:F117,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 10, "MATCH_10"); oParser = new parserFormula("MATCH(0,F106:F114,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "MATCH_11"); oParser = new parserFormula("MATCH(0,F106:F117,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 10, "MATCH_12"); oParser = new parserFormula("MATCH(6,F106:F117,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 9, "MATCH_13"); oParser = new parserFormula("MATCH(6,F106:F117,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5, "MATCH_14"); oParser = new parserFormula("MATCH(6,F106:F117,-1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "MATCH_15"); oParser = new parserFormula("MATCH({6,2,3},F106:F117,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5, "MATCH_16"); // bug 62332 ws.getRange2("B200").setValue("P/N"); ws.getRange2("B201").setValue("V-PS-TE-AW"); ws.getRange2("B202").setValue("VA-ARM-PLL-D-A"); ws.getRange2("B203").setValue("VA-ARM-PLL-U-A"); ws.getRange2("B204").setValue("VA-ARM-U-P-SSS-C"); ws.getRange2("B205").setValue("#N/A"); ws.getRange2("B206").setValue(""); ws.getRange2("C300").setValue("P/N"); ws.getRange2("C301").setValue("V-PS-TE-AW"); ws.getRange2("C302").setValue("VA-ARM-PLL-D-A"); ws.getRange2("C303").setValue("VA-ARM-PLL-U-A"); ws.getRange2("C304").setValue("VA-ARM-U-P-SSS-C"); ws.getRange2("C305").setValue("#N/A"); ws.getRange2("C306").setValue(""); let bbox = ws.getRange2("D200").bbox; let cellWithFormula = new window['AscCommonExcel'].CCellWithFormula(ws, bbox.r1, bbox.c1); oParser = new parserFormula("MATCH(B200:B206,C300:C306,0)", cellWithFormula, ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1, "MATCH_17"); bbox = ws.getRange2("D201").bbox; cellWithFormula = new window['AscCommonExcel'].CCellWithFormula(ws, bbox.r1, bbox.c1); oParser = new parserFormula("MATCH(B200:B206,C300:C306,0)", cellWithFormula, ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2, "MATCH_18"); bbox = ws.getRange2("D202").bbox; cellWithFormula = new window['AscCommonExcel'].CCellWithFormula(ws, bbox.r1, bbox.c1); oParser = new parserFormula("MATCH(B200:B206,C300:C306,0)", cellWithFormula, ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3, "MATCH_19"); oParser = new parserFormula("MATCH(B200:B206,C300:C306,0)", "D202", ws); oParser.setArrayFormulaRef(ws.getRange2("A100").bbox); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(1,0).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(2,0).getValue(), 3); assert.strictEqual(oParser.calculate().getElementRowCol(3,0).getValue(), 4); assert.strictEqual(oParser.calculate().getElementRowCol(4,0).getValue(), 5); assert.strictEqual(oParser.calculate().getElementRowCol(5,0).getValue(), "#N/A"); assert.strictEqual(oParser.calculate().getElementRowCol(6,0).getValue(), 7); oParser = new parserFormula("MATCH(B200:B206,C300:C306,0)", "D202", ws); oParser.setArrayFormulaRef(ws.getRange2("D200").bbox); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(1,0).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(2,0).getValue(), 3); assert.strictEqual(oParser.calculate().getElementRowCol(3,0).getValue(), 4); assert.strictEqual(oParser.calculate().getElementRowCol(4,0).getValue(), 5); assert.strictEqual(oParser.calculate().getElementRowCol(5,0).getValue(), "#N/A"); assert.strictEqual(oParser.calculate().getElementRowCol(6,0).getValue(), 7); oParser = new parserFormula('MATCH("str","str",0)', "A2", ws); assert.ok(oParser.parse(), 'MATCH("str","str",0)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of MATCH("str","str",0)'); oParser = new parserFormula('MATCH("str",{"str"},0)', "A2", ws); assert.ok(oParser.parse(), 'MATCH("str",{"str"},0)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of MATCH("str",{"str"},0)'); oParser = new parserFormula('MATCH(1,1,-1)', "A2", ws); assert.ok(oParser.parse(), 'MATCH(1,1,-1)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of MATCH(1,1,-1)'); oParser = new parserFormula('MATCH(1,1,0)', "A2", ws); assert.ok(oParser.parse(), 'MATCH(1,1,0)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of MATCH(1,1,0)'); oParser = new parserFormula('MATCH(1,1,1)', "A2", ws); assert.ok(oParser.parse(), 'MATCH(1,1,1)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of MATCH(1,1,1)'); oParser = new parserFormula('MATCH(1,{1},1)', "A2", ws); assert.ok(oParser.parse(), 'MATCH(1,{1},1)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of MATCH(1,{1},1)'); oParser = new parserFormula('MATCH(1,{2,1,1},0)', "A2", ws); assert.ok(oParser.parse(), 'MATCH(1,{2,1,1},0)'); assert.strictEqual(oParser.calculate().getValue(), 2, 'Result of MATCH(1,{2,1,1},0)'); oParser = new parserFormula('MATCH(TRUE,TRUE,0)', "A2", ws); assert.ok(oParser.parse(), 'MATCH(TRUE,TRUE,0)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of MATCH(TRUE,TRUE,0)'); oParser = new parserFormula('MATCH(TRUE,{TRUE},0)', "A2", ws); assert.ok(oParser.parse(), 'MATCH(TRUE,{TRUE},0)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of MATCH(TRUE,{TRUE},0)'); oParser = new parserFormula("MATCH({6,2,3},F106:F117,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 5, "MATCH_16"); oParser = new parserFormula("MATCH(#REF!,{123,2})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "#REF!"); oParser = new parserFormula("MATCH({6,2,3},#VALUE!)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "#VALUE!"); ws.getRange2("B300").setValue("#REF!"); oParser = new parserFormula("MATCH(B300,{1,2,3})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "#REF!"); //TODO excel по-другому работает /*oParser = new parserFormula( "MATCH(123,F106:F117,1)", "A2", ws ); assert.ok( oParser.parse() ); assert.strictEqual( oParser.calculate().getValue(), 6 );*/ }); QUnit.test("Test: \"XMATCH\"", function (assert) { let array; ws.getRange2("B101").setValue(); ws.getRange2("B102").setValue(); ws.getRange2("B103").setValue(); ws.getRange2("B101:B103").cleanAll(); oParser = new parserFormula("XMATCH(B101,B102,2,-2)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,2,-2)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of XMATCH(B101,B102,2,-2)"); oParser = new parserFormula("XMATCH(B101,B102,2,-1)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,2,-1)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(B101,B102,2,-1)"); oParser = new parserFormula("XMATCH(B101,B102,2,0)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of XMATCH(B101,B102,2,0)"); oParser = new parserFormula("XMATCH(B101,B102,2,1)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,2,1)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(B101,B102,2,1)"); oParser = new parserFormula("XMATCH(B101,B102,2,2)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,2,2)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of XMATCH(B101,B102,2,2)"); oParser = new parserFormula("XMATCH(B101,B102,1,-2)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,1,-2)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(B101,B102,1,-2)"); oParser = new parserFormula("XMATCH(B101,B102,1,-1)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,1,-1)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(B101,B102,1,-1)"); oParser = new parserFormula("XMATCH(B101,B102,1,0)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,1,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of XMATCH(B101,B102,1,0)"); oParser = new parserFormula("XMATCH(B101,B102,1,1)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,1,1)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(B101,B102,1,1)"); oParser = new parserFormula("XMATCH(B101,B102,1,2)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,1,2)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(B101,B102,1,2)"); oParser = new parserFormula("XMATCH(B101,B102,0,-2)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,0,-2)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(B101,B102,0,-2)"); oParser = new parserFormula("XMATCH(B101,B102,0,-1)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,0,-1)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(B101,B102,0,-1)"); oParser = new parserFormula("XMATCH(B101,B102,0,0)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,0,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of XMATCH(B101,B102,0,0)"); oParser = new parserFormula("XMATCH(B101,B102,0,1)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,0,1)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(B101,B102,0,1)"); oParser = new parserFormula("XMATCH(B101,B102,0,2)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,0,2)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(B101,B102,0,2)"); oParser = new parserFormula("XMATCH(B101,B102,-1,-2)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,-1,-2)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(B101,B102,-1,-2)"); oParser = new parserFormula("XMATCH(B101,B102,-1,-1)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,-1,-1)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(B101,B102,-1,-1)"); oParser = new parserFormula("XMATCH(B101,B102,-1,0)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,-1,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of XMATCH(B101,B102,-1,0)"); oParser = new parserFormula("XMATCH(B101,B102,-1,1)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,-1,1)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(B101,B102,-1,1)"); oParser = new parserFormula("XMATCH(B101,B102,-1,2)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,-1,2)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(B101,B102,-1,2)"); oParser = new parserFormula("XMATCH(3,{3,2,21,1,1,2,3},0,-1)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(3,{3,2,21,1,1,2,3},0,-1)"); assert.strictEqual(oParser.calculate().getValue(), 7, "Result of XMATCH(3,{3,2,21,1,1,2,3},0,-1)"); oParser = new parserFormula("XMATCH(3,{3,2,21,1,1,2,3},0,1)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(3,{3,2,21,1,1,2,3},0,1)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(3,{3,2,21,1,1,2,3},0,1)"); oParser = new parserFormula("XMATCH(1,{3,2,21,1,21,2,3},0,-1)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(1,{3,2,21,1,21,2,3},0,-1)"); assert.strictEqual(oParser.calculate().getValue(), 4, "Result of XMATCH(1,{3,2,21,1,21,2,3},0,-1)"); oParser = new parserFormula("XMATCH(1,{3,2,21,1,21,2,3},0,1)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(1,{3,2,21,1,21,2,3},0,1)"); assert.strictEqual(oParser.calculate().getValue(), 4, "Result of XMATCH(1,{3,2,21,1,21,2,3},0,1)"); oParser = new parserFormula("XMATCH(1,{1,1,1,1},0,1)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(1,{1,1,1,1},0,1)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(1,{1,1,1,1},0,1)"); oParser = new parserFormula("XMATCH(1,{1,1,1,1},0,-1)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(1,{1,1,1,1},0,-1)"); assert.strictEqual(oParser.calculate().getValue(), 4, "Result of XMATCH(1,{1,1,1,1},0,-1)"); oParser = new parserFormula("XMATCH(1,{1},0,-1)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(1,{1},0,-1)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(1,{1},0,-1)"); oParser = new parserFormula("XMATCH(1,{2},-1,-1)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(1,{2},-1,-1)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XMATCH(1,{2},-1,-1)"); oParser = new parserFormula("XMATCH(1,{2},1,-1)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(1,{2},1,-1)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(1,{2},1,-1)"); oParser = new parserFormula("XMATCH(1,{2,2,2,2,2,2},-1,-1)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(1,{2,2,2,2,2,2},-1,-1)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XMATCH(1,{2,2,2,2,2,2},-1,-1)"); oParser = new parserFormula("XMATCH(1,{2,2,2,2,2,2},1,-1)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(1,{2,2,2,2,2,2},1,-1)"); assert.strictEqual(oParser.calculate().getValue(), 6, "Result of XMATCH(1,{2,2,2,2,2,2},1,-1)"); oParser = new parserFormula("XMATCH(1,{3,3,3,3,2,3},1,-1)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(1,{3,3,3,3,2,3},1,-1)"); assert.strictEqual(oParser.calculate().getValue(), 5, "Result of XMATCH(1,{3,3,3,3,2,3},1,-1)"); oParser = new parserFormula("XMATCH(1,{3,3,3,3,2,3},1,1)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(1,{3,3,3,3,2,3},1,1)"); assert.strictEqual(oParser.calculate().getValue(), 5, "Result of XMATCH(1,{3,3,3,3,2,3},1,1)"); oParser = new parserFormula("XMATCH(1,{2,2,2,2,2,2},1,1)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(1,{2,2,2,2,2,2},1,1)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(1,{2,2,2,2,2,2},1,1)"); oParser = new parserFormula("XMATCH(1,{2,2,2,1,2,2},2,-1)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(1,{2,2,2,1,2,2},2,-1)"); assert.strictEqual(oParser.calculate().getValue(), 4, "Result of XMATCH(1,{2,2,2,1,2,2},2,-1)"); oParser = new parserFormula('XMATCH(1,{3,3,"str",3,"22s",3},1,-1)', "A2", ws); assert.ok(oParser.parse(), 'XMATCH(1,{3,3,"str",3,"22s",3},1,-1)'); assert.strictEqual(oParser.calculate().getValue(), 6, 'Result of XMATCH(1,{3,3,"str",3,"22s",3},1,-1)'); oParser = new parserFormula('XMATCH(1,{3,3,"str",3,"22s",3},1,1)', "A2", ws); assert.ok(oParser.parse(), 'XMATCH(1,{3,3,"str",3,"22s",3},1,1)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of XMATCH(1,{3,3,"str",3,"22s",3},1,1)'); oParser = new parserFormula('XMATCH(1,{3,3,"str",3,"22s",3},-1,-1)', "A2", ws); assert.ok(oParser.parse(), 'XMATCH(1,{3,3,"str",3,"22s",3},-1,-1)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of XMATCH(1,{3,3,"str",3,"22s",3},-1,-1)'); oParser = new parserFormula('XMATCH("apple",{"banana","grape","lemon","watermelon"},1,1)', "A2", ws); assert.ok(oParser.parse(), 'XMATCH("apple",{"banana","grape","lemon","watermelon"},1,1)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of XMATCH("apple",{"banana","grape","lemon","watermelon"},1,1)'); oParser = new parserFormula('XMATCH("apple",{"banana","grape","lemon","watermelon","app"},-1,1)', "A2", ws); assert.ok(oParser.parse(), 'XMATCH("apple",{"banana","grape","lemon","watermelon","app"},-1,1)'); assert.strictEqual(oParser.calculate().getValue(), 5, 'Result of XMATCH("apple",{"banana","grape","lemon","watermelon","app"},-1,1)'); oParser = new parserFormula('XMATCH("apple",{"banana","grape","apple1","apple2","apple1","app","apple2","aple3"},1,1)', "A2", ws); assert.ok(oParser.parse(), 'XMATCH("apple",{"banana","grape","apple1","apple2","apple1","app","apple2","aple3"},1,1)'); assert.strictEqual(oParser.calculate().getValue(), 3, 'Result of XMATCH("apple",{"banana","grape","apple1","apple2","apple1","app","apple2","aple3"},1,1)'); oParser = new parserFormula('XMATCH("apple",{"banana","grape","apple1","apple2","apple1","app","apple2","aple3"},1,-1)', "A2", ws); assert.ok(oParser.parse(), 'XMATCH("apple",{"banana","grape","apple1","apple2","apple1","app","apple2","aple3"},1,-1)'); assert.strictEqual(oParser.calculate().getValue(), 5, 'Result of XMATCH("apple",{"banana","grape","apple1","apple2","apple1","app","apple2","aple3"},1,-1)'); oParser = new parserFormula('XMATCH(TRUE,{1,3,-1,2,"str","TRUE","FALSE","app"},-1)', "A2", ws); assert.ok(oParser.parse(), 'XMATCH(TRUE,{1,3,-1,2,"str","TRUE","FALSE","app"},-1)'); // ??? js: "str" > "TRUE", ms: "str" < "TRUE" oParser = new parserFormula('XMATCH(FALSE,{1,3,-1,2,"str","TRUE","FALSE","app"},-1)', "A2", ws); assert.ok(oParser.parse(), 'XMATCH(FALSE,{1,3,-1,2,"str","TRUE","FALSE","app"},-1)'); assert.strictEqual(oParser.calculate().getValue(), 5, 'Result of XMATCH(FALSE,{1,3,-1,2,"str","TRUE","FALSE","app"},-1)'); // 6 // ??? js: "str" > "ZZZ", ms: "str" < "ZZZ" oParser = new parserFormula('XMATCH(FALSE,{"ZZZ",3,-1,2,"str","TRUE","FALSE","app"},-1)', "A2", ws); assert.ok(oParser.parse(), 'XMATCH(FALSE,{"ZZZ",3,-1,2,"str","TRUE","FALSE","app"},-1)'); assert.strictEqual(oParser.calculate().getValue(), 5, 'Result of XMATCH(FALSE,{"ZZZ",3,-1,2,"str","TRUE","FALSE","app"},-1)'); // 1 oParser = new parserFormula('XMATCH(FALSE,{"zzz",3,-1,2,"str","TRUE","FALSE","app","zzz"},-1,-1)', "A2", ws); assert.ok(oParser.parse(), 'XMATCH(FALSE,{"zzz",3,-1,2,"str","TRUE","FALSE","app","zzz"},-1,-1)'); assert.strictEqual(oParser.calculate().getValue(), 9, 'Result of XMATCH(FALSE,{"zzz",3,-1,2,"str","TRUE","FALSE","app","zzz"},-1,-1)'); oParser = new parserFormula('XMATCH(FALSE,{"ZZZ",3,-1,2,"str","TRUE","FALSE","app"},1)', "A2", ws); assert.ok(oParser.parse(), 'XMATCH(FALSE,{"ZZZ",3,-1,2,"str","TRUE","FALSE","app"},1)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of XMATCH(FALSE,{"ZZZ",3,-1,2,"str","TRUE","FALSE","app"},1)'); oParser = new parserFormula('XMATCH(1,{2,2,2,1,2,2,2},0,2)', "A2", ws); assert.ok(oParser.parse(), 'XMATCH(1,{2,2,2,1,2,2,2},0,2)'); assert.strictEqual(oParser.calculate().getValue(), 4, 'Result of XMATCH(1,{2,2,2,1,2,2,2},0,2)'); oParser = new parserFormula('XMATCH(1,{2,2,2,1,2,2},0,2)', "A2", ws); assert.ok(oParser.parse(), 'XMATCH(1,{2,2,2,1,2,2},0,2)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of XMATCH(1,{2,2,2,1,2,2},0,2)'); oParser = new parserFormula('XMATCH(1,{2,2,2,1,2,2},1,2)', "A2", ws); assert.ok(oParser.parse(), 'XMATCH(1,{2,2,2,1,2,2},1,2)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of XMATCH(1,{2,2,2,1,2,2},1,2)'); oParser = new parserFormula('XMATCH(1,{2,2,2,1,2,2},-1,2)', "A2", ws); assert.ok(oParser.parse(), 'XMATCH(1,{2,2,2,1,2,2},-1,2)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of XMATCH(1,{2,2,2,1,2,2},-1,2)'); oParser = new parserFormula('XMATCH(1,{2,2,2,1,2,2},0,-2)', "A2", ws); assert.ok(oParser.parse(), 'XMATCH(1,{2,2,2,1,2,2},0,-2)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of XMATCH(1,{2,2,2,1,2,2},0,-2)'); oParser = new parserFormula('XMATCH(1,{2,2,2,1,2,2},1,-2)', "A2", ws); assert.ok(oParser.parse(), 'XMATCH(1,{2,2,2,1,2,2},1,-2)'); assert.strictEqual(oParser.calculate().getValue(), 5, 'Result of XMATCH(1,{2,2,2,1,2,2},1,-2)'); // 6 oParser = new parserFormula('XMATCH(1,{2,2,2,1,2,2},-1,-2)', "A2", ws); assert.ok(oParser.parse(), 'XMATCH(1,{2,2,2,1,2,2},-1,-2)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of XMATCH(1,{2,2,2,1,2,2},-1,-2)'); oParser = new parserFormula("XMATCH(,,-2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("XMATCH(,,-1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("XMATCH(,,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("XMATCH(,,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("XMATCH(,,2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("XMATCH(,,3)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("XMATCH(B101,B102)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(B101,B102)"); oParser = new parserFormula("XMATCH(B101,B102,-2)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,-2)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of XMATCH(B101,B102,-2)"); oParser = new parserFormula("XMATCH(B101,B102,-1)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,-1)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(B101,B102,-1)"); oParser = new parserFormula("XMATCH(B101,B102,0)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,0)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(B101,B102,0)"); oParser = new parserFormula("XMATCH(B101,B102,1)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,1)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(B101,B102,1)"); oParser = new parserFormula("XMATCH(B101,B102,2)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,2)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(B101,B102,2)"); oParser = new parserFormula("XMATCH(B101,B102,2)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,2)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(B101,B102,2)"); oParser = new parserFormula("XMATCH(B101,B102,3)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(B101,B102,3)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of XMATCH(B101,B102,3)"); oParser = new parserFormula("XMATCH(#DIV/0!,#NUM!)", "A2", ws); assert.ok(oParser.parse(), "XMATCH(#DIV/0!,#NUM!)"); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "Result of XMATCH(#DIV/0!,#NUM!)"); // ---------------------- arrays of numbers ---------------------- // ws.getRange2("B50").setValue("9"); ws.getRange2("B51").setValue("12"); ws.getRange2("B52").setValue("11"); ws.getRange2("B53").setValue("9"); ws.getRange2("B54").setValue("9"); ws.getRange2("B55").setValue("12"); ws.getRange2("B56").setValue("7"); ws.getRange2("B57").setValue("9"); ws.getRange2("B58").setValue("12"); ws.getRange2("B59").setValue("9"); oParser = new parserFormula("XMATCH(2,B50:B59)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(2,B50:B59)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XMATCH(2,B50:B59)"); oParser = new parserFormula("XMATCH(\"12\",B50:B59)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH('12',B50:B59)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XMATCH('12',B50:B59)"); oParser = new parserFormula("XMATCH(9,B50:B59)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(9,B50:B59)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(9,B50:B59)"); oParser = new parserFormula("XMATCH(9,B50:B59,0,-1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(9,B50:B59)"); assert.strictEqual(oParser.calculate().getValue(), 10, "Result of XMATCH(9,B50:B59,0,-1)"); oParser = new parserFormula("XMATCH(10,B50:B59,1,1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(10,B50:B59,1,1)"); assert.strictEqual(oParser.calculate().getValue(), 3, "Result of XMATCH(10,B50:B59,1,1)"); oParser = new parserFormula("XMATCH(10,B50:B59,-1,1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(10,B50:B59,-1,1)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(10,B50:B59,-1,1)"); oParser = new parserFormula("XMATCH(9,B50:B59,2)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(9,B50:B59,2)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(9,B50:B59,2)"); oParser = new parserFormula("XMATCH(10,B50:B59,-1,-1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(10,B50:B59,-1,-1)"); assert.strictEqual(oParser.calculate().getValue(), 10, "Result of XMATCH(10,B50:B59,-1,-1)"); oParser = new parserFormula("XMATCH(10,B50:B59,0,2)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(10,B50:B59,0,2)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XMATCH(10,B50:B59,0,2)"); oParser = new parserFormula("XMATCH(10,B50:B59,1,2)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(10,B50:B59,1,2)"); assert.strictEqual(oParser.calculate().getValue(), 9, "Result of XMATCH(10,B50:B59,1,2)"); oParser = new parserFormula("XMATCH(10,B50:B59,-1,2)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(10,B50:B59,-1,2)"); assert.strictEqual(oParser.calculate().getValue(), 8, "Result of XMATCH(10,B50:B59,-1,2)"); oParser = new parserFormula("XMATCH(10,B50:B59,0,-2)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(10,B50:B59,0,-2)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XMATCH(10,B50:B59,0,-2)"); // TODO excel выдает другой результат (3) oParser = new parserFormula("XMATCH(10,B50:B59,1,-2)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(10,B50:B59,1,-2)"); assert.strictEqual(oParser.calculate().getValue(), 2, "Result of XMATCH(10,B50:B59,1,-2)"); oParser = new parserFormula("XMATCH(10,B50:B59,-1,-2)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(10,B50:B59,-1,-2)"); assert.strictEqual(oParser.calculate().getValue(), 4, "Result of XMATCH(10,B50:B59,-1,-2)"); oParser = new parserFormula("XMATCH(10,B50:B59,2,-2)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(10,B50:B59,2,-2)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of XMATCH(10,B50:B59,2,-2)"); // sort by asc ws.getRange2("C50").setValue("1"); ws.getRange2("C51").setValue("2"); ws.getRange2("C52").setValue("2"); ws.getRange2("C53").setValue("2"); ws.getRange2("C54").setValue("3"); ws.getRange2("C55").setValue("5"); ws.getRange2("C56").setValue("6"); ws.getRange2("C57").setValue("7"); ws.getRange2("C58").setValue("9"); ws.getRange2("C59").setValue("11"); // sort by desc ws.getRange2("D50").setValue("11"); ws.getRange2("D51").setValue("9"); ws.getRange2("D52").setValue("7"); ws.getRange2("D53").setValue("6"); ws.getRange2("D54").setValue("5"); ws.getRange2("D55").setValue("4"); ws.getRange2("D56").setValue("2"); ws.getRange2("D57").setValue("2"); ws.getRange2("D58").setValue("2"); ws.getRange2("D59").setValue("1"); // binary search tests oParser = new parserFormula("XMATCH(1,C50:C59,0,2)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(1,C50:C59,0,2)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(1,C50:C59,0,2)"); oParser = new parserFormula("XMATCH(3,C50:C59,0,2)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(3,C50:C59,0,2)"); assert.strictEqual(oParser.calculate().getValue(), 5, "Result of XMATCH(3,C50:C59,0,2)"); // TODO ms выдает другой результат (6) oParser = new parserFormula("XMATCH(4,C50:C59,1,2)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(4,C50:C59,1,2)"); assert.strictEqual(oParser.calculate().getValue(), 8, "Result of XMATCH(4,C50:C59,1,2)"); // TODO ms выдает другой результат (5) oParser = new parserFormula("XMATCH(4,C50:C59,-1,2)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(4,C50:C59,-1,2)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XMATCH(4,C50:C59,-1,2)"); oParser = new parserFormula("XMATCH(3,C50:C59,0,-2)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(3,C50:C59,0,-2)"); assert.strictEqual(oParser.calculate().getValue(), 5, "Result of XMATCH(3,C50:C59,0,-2)"); oParser = new parserFormula("XMATCH(-4,C50:C59,1,-2)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(-4,C50:C59,1,-2)"); assert.strictEqual(oParser.calculate().getValue(), 8, "Result of XMATCH(-4,C50:C59,1,-2)"); // TODO ms выдает другой результат (1) oParser = new parserFormula("XMATCH(4,C50:C59,-1,-2)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(4,C50:C59,-1,-2)"); assert.strictEqual(oParser.calculate().getValue(), 2, "Result of XMATCH(4,C50:C59,-1,-2)"); // ---------------------- arrays of strings ---------------------- // ws.getRange2("E50").setValue("idas"); ws.getRange2("E51").setValue("zxc"); ws.getRange2("E52").setValue("f"); ws.getRange2("E53").setValue("_d"); ws.getRange2("E54").setValue("edasd"); ws.getRange2("E55").setValue("SiM`Gl23"); ws.getRange2("E56").setValue("g"); ws.getRange2("E57").setValue("bbbbbbbb"); ws.getRange2("E58").setValue("SDY"); ws.getRange2("E59").setValue("1d23dd"); ws.getRange2("E60").setValue("b"); oParser = new parserFormula("XMATCH(i,E50:E59)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(i,E50:E59)"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Result of XMATCH(i,E50:E59)"); oParser = new parserFormula("XMATCH(E52,E50:E59)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(E52,E50:E59)"); assert.strictEqual(oParser.calculate().getValue(), 3, "Result of XMATCH(E52,E50:E59)"); oParser = new parserFormula("XMATCH(E60,E50:E59, 1, 1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(E60,E50:E59, 1, 1)"); assert.strictEqual(oParser.calculate().getValue(), 8, "Result of XMATCH(E60,E50:E59, 1, 1)"); // TODO ms и js выдают разные результаты при подобных сравнениях строк. К примеру "_d" считается меньше чем "1d23dd" тогда как у нас в редакторе по-другому(как в js) oParser = new parserFormula("XMATCH(E60,E50:E59,-1,1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(E60,E50:E59,-1,1)"); assert.strictEqual(oParser.calculate().getValue(), 4, "Result of XMATCH(E60,E50:E59,-1,1)"); // 10 oParser = new parserFormula("XMATCH(E60,E50:E59,1,-1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(E60,E50:E59,1,-1)"); assert.strictEqual(oParser.calculate().getValue(), 8, "Result of XMATCH(E60,E50:E59,1,-1)"); oParser = new parserFormula("XMATCH(E60,E50:E59,-1,-1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(E60,E50:E59,-1,-1)"); assert.strictEqual(oParser.calculate().getValue(), 4, "Result of XMATCH(E60,E50:E59,-1,-1)"); // 10 oParser = new parserFormula("XMATCH(E60,E50:E59,1,1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(E60,E50:E59,1,1)"); assert.strictEqual(oParser.calculate().getValue(), 8, "Result of XMATCH(E60,E50:E59,1,1)"); oParser = new parserFormula("XMATCH(B101,E50:E59,-1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(B101,E50:E59,-1)"); assert.strictEqual(oParser.calculate().getValue(), 2, "Result of XMATCH(B101,E50:E59,-1)"); oParser = new parserFormula("XMATCH(B101,E50:E59,-1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(B101,E50:E59,-1)"); assert.strictEqual(oParser.calculate().getValue(), 2, "Result of XMATCH(B101,E50:E59,-1)") oParser = new parserFormula("XMATCH(B101,E50:E59,0)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(B101,E50:E59,0)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XMATCH(B101,E50:E59,0)"); oParser = new parserFormula("XMATCH(B101,E50:E59,1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(B101,E50:E59,1)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XMATCH(B101,E50:E59,1)"); oParser = new parserFormula('XMATCH(12,{13,"b",92,#NUM!,13},1)', "A2", ws); assert.ok(oParser.parse(), 'Call: XMATCH(12,{13,"b",92,#NUM!,13},1)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of XMATCH(12,{13,"b",92,#NUM!,13},1)'); oParser = new parserFormula('XMATCH(12,{13,"b",92,#NUM!,13},1,-1)', "A2", ws); assert.ok(oParser.parse(), 'Call: XMATCH(12,{13,"b",92,#NUM!,13},1,-1)'); assert.strictEqual(oParser.calculate().getValue(), 5, 'Result of XMATCH(12,{13,"b",92,#NUM!,13},1,-1)'); oParser = new parserFormula('XMATCH(13,{12,"b",-92,#NUM!,12},-1)', "A2", ws); assert.ok(oParser.parse(), 'Call: XMATCH(13,{12,"b",-92,#NUM!,12},-1)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of XMATCH(13,{12,"b",-92,#NUM!,12},-1)'); oParser = new parserFormula('XMATCH(13,{12,"b",-92,#NUM!,12},-1,-1)', "A2", ws); assert.ok(oParser.parse(), 'Call: XMATCH(13,{12,"b",-92,#NUM!,12},-1,-1)'); assert.strictEqual(oParser.calculate().getValue(), 5, 'Result of XMATCH(13,{12,"b",-92,#NUM!,12},-1,-1)'); oParser = new parserFormula('XMATCH(1,{"a","b",-2,-2,-2,"a"},1)', "A2", ws); assert.ok(oParser.parse(), 'Call: XMATCH(1,{"a","b",-2,-2,-2,"a"},1)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of XMATCH(1,{"a","b",-2,-2,-2,"a"},1)'); oParser = new parserFormula('XMATCH(1,{"a","b",-2,-2,-2,"a"},1,-1)', "A2", ws); assert.ok(oParser.parse(), 'Call: XMATCH(1,{"a","b",-2,-2,-2,"a"},1,-1)'); assert.strictEqual(oParser.calculate().getValue(), 6, 'Result of XMATCH(1,{"a","b",-2,-2,-2,"a"},1,-1)'); oParser = new parserFormula('XMATCH(1,{"a","b",2,2,TRUE,"c"},-1)', "A2", ws); assert.ok(oParser.parse(), 'Call: XMATCH(1,{"a","b",2,2,TRUE,"c"},-1)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of XMATCH(1,{"a","b",2,2,TRUE,"c"},-1)'); oParser = new parserFormula('XMATCH("a",{"z","b",-2,-2,TRUE,"z"},-1)', "A2", ws); assert.ok(oParser.parse(), 'Call: XMATCH("a",{"z","b",-2,-2,TRUE,"z"},-1)'); assert.strictEqual(oParser.calculate().getValue(), 3, 'Result of XMATCH("a",{"z","b",-2,-2,TRUE,"z"},-1)'); oParser = new parserFormula('XMATCH("a",{"z","b",-2,-2,TRUE,"z"},-1,-1)', "A2", ws); assert.ok(oParser.parse(), 'Call: XMATCH("a",{"z","b",-2,-2,TRUE,"z"},-1,-1)'); assert.strictEqual(oParser.calculate().getValue(), 4, 'Result of XMATCH("a",{"z","b",-2,-2,TRUE,"z"},-1,-1)'); oParser = new parserFormula('XMATCH("z",{"a","b",FALSE,FALSE,TRUE,"a"},1)', "A2", ws); assert.ok(oParser.parse(), 'Call: XMATCH("z",{"a","b",FALSE,FALSE,TRUE,"a"},1)'); assert.strictEqual(oParser.calculate().getValue(), 3, 'Result of XMATCH("z",{"a","b",FALSE,FALSE,TRUE,"a"},1)'); oParser = new parserFormula('XMATCH("z",{"a","b",FALSE,FALSE,TRUE,"a"},1,-1)', "A2", ws); assert.ok(oParser.parse(), 'Call: XMATCH("z",{"a","b",FALSE,FALSE,TRUE,"a"},1,-1)'); assert.strictEqual(oParser.calculate().getValue(), 4, 'Result of XMATCH("z",{"a","b",FALSE,FALSE,TRUE,"a"},1,-1)'); oParser = new parserFormula('XMATCH(FALSE,{"z","b",92,#NUM!,"z"},-1)', "A2", ws); assert.ok(oParser.parse(), 'Call: XMATCH(FALSE,{"z","b",92,#NUM!,"z"},-1)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of XMATCH(FALSE,{"z","b",92,#NUM!,"z"},-1)'); oParser = new parserFormula('XMATCH(FALSE,{"z","b",92,#NUM!,"z"},-1,-1)', "A2", ws); assert.ok(oParser.parse(), 'Call: XMATCH(FALSE,{"z","b",92,#NUM!,"z"},-1,-1)'); assert.strictEqual(oParser.calculate().getValue(), 5, 'Result of XMATCH(FALSE,{"z","b",92,#NUM!,"z"},-1,-1)'); oParser = new parserFormula('XMATCH(FALSE,{"z","b",92,#NUM!,TRUE,"z"},1)', "A2", ws); assert.ok(oParser.parse(), 'Call: XMATCH(FALSE,{"z","b",92,#NUM!,TRUE,"z"},1)'); assert.strictEqual(oParser.calculate().getValue(), 5, 'Result of XMATCH(FALSE,{"z","b",92,#NUM!,TRUE,"z"},1)'); oParser = new parserFormula('XMATCH(TRUE,{"z","b",#VALUE!,92,#NUM!,FALSE,"z"},1)', "A2", ws); assert.ok(oParser.parse(), 'Call: XMATCH(TRUE,{"z","b",#VALUE!,92,#NUM!,FALSE,"z"},1)'); assert.strictEqual(oParser.calculate().getValue(), 3, 'Result of XMATCH(TRUE,{"z","b",#VALUE!,92,#NUM!,FALSE,"z"},1)'); oParser = new parserFormula('XMATCH(TRUE,{"z","b",#VALUE!,92,#NUM!,FALSE,"z"},1,-1)', "A2", ws); assert.ok(oParser.parse(), 'Call: XMATCH(TRUE,{"z","b",#VALUE!,92,#NUM!,FALSE,"z"},1,-1)'); assert.strictEqual(oParser.calculate().getValue(), 5, 'Result of XMATCH(TRUE,{"z","b",#VALUE!,92,#NUM!,FALSE,"z"},1,-1)'); // numbers, strings, booleans and errors ws.getRange2("E101").setValue("TRUE"); ws.getRange2("E102").setValue("z"); ws.getRange2("E103").setValue("b"); ws.getRange2("E104").setValue("#VALUE!"); ws.getRange2("E105").setValue("2"); ws.getRange2("E106").setValue("FALSE"); ws.getRange2("E107").setValue("#NUM!"); oParser = new parserFormula("XMATCH(B101,E101:E107,1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(B101,E101:E107,1)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XMATCH(B101,E101:E107,1)"); oParser = new parserFormula("XMATCH(B101,E101:E107,0)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(B101,E101:E107,0)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XMATCH(B101,E101:E107,0)"); oParser = new parserFormula("XMATCH(B101,E101:E107,-1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(B101,E101:E107,-1)"); assert.strictEqual(oParser.calculate().getValue(), 4, "Result of XMATCH(B101,E101:E107,-1)"); oParser = new parserFormula("XMATCH(B101,E101:E107,-1,-1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(B101,E101:E107,-1,-1)"); assert.strictEqual(oParser.calculate().getValue(), 4, "Result of XMATCH(B101,E101:E107,-1,-1)"); // numbers, strings, booleans ws.getRange2("E111").setValue("TRUE"); ws.getRange2("E112").setValue("z"); ws.getRange2("E113").setValue("a"); ws.getRange2("E114").setValue("99"); ws.getRange2("E115").setValue("2"); ws.getRange2("E116").setValue("FALSE"); ws.getRange2("E117").setValue("TRUE"); oParser = new parserFormula("XMATCH(B101,E111:E111,1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(B101,E111:E117,1)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XMATCH(B101,E111:E117,1)"); oParser = new parserFormula("XMATCH(B101,E111:E117,0)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(B101,E111:E117,0)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XMATCH(B101,E111:E117,0)"); oParser = new parserFormula("XMATCH(B101,E111:E117,-1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(B101,E111:E117,-1)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(B101,E111:E117,-1)"); oParser = new parserFormula("XMATCH(B101,E111:E117,-1,-1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(B101,E111:E117,-1,-1)"); assert.strictEqual(oParser.calculate().getValue(), 7, "Result of XMATCH(B101,E111:E117,-1,-1)"); // numbers, strings ws.getRange2("E121").setValue("x"); ws.getRange2("E122").setValue("z"); ws.getRange2("E123").setValue("a"); ws.getRange2("E124").setValue("99"); ws.getRange2("E125").setValue("2"); ws.getRange2("E126").setValue("-98908"); ws.getRange2("E127").setValue("z"); oParser = new parserFormula("XMATCH(B101,E121:E127,-1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(B101,E121:E127,-1)"); assert.strictEqual(oParser.calculate().getValue(), 2, "Result of XMATCH(B101,E121:E127,-1)"); oParser = new parserFormula("XMATCH(B101,E121:E127,-1,-1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(B101,E121:E127,-1,-1)"); assert.strictEqual(oParser.calculate().getValue(), 7, "Result of XMATCH(B101,E121:E127,-1,-1)"); // numbers ws.getRange2("E131").setValue("99"); ws.getRange2("E132").setValue("12"); ws.getRange2("E133").setValue("-123"); ws.getRange2("E134").setValue("13"); ws.getRange2("E135").setValue("99"); ws.getRange2("E136").setValue("-98908"); ws.getRange2("E137").setValue("0"); oParser = new parserFormula("XMATCH(B101,E131:E137,-1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(B101,E131:E137,-1)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(B101,E131:E137,-1)"); oParser = new parserFormula("XMATCH(B101,E131:E137,-1,-1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(B101,E131:E137,-1,-1)"); assert.strictEqual(oParser.calculate().getValue(), 5, "Result of XMATCH(B101,E131:E137,-1,-1)"); // sort by asc ws.getRange2("F50").setValue("a"); ws.getRange2("F51").setValue("b"); ws.getRange2("F52").setValue("c"); ws.getRange2("F53").setValue("d"); ws.getRange2("F54").setValue("e"); ws.getRange2("F55").setValue("f"); ws.getRange2("F56").setValue("g"); ws.getRange2("F57").setValue("h"); ws.getRange2("F58").setValue("i"); ws.getRange2("F59").setValue("j"); // sort by desc ws.getRange2("G50").setValue("j"); ws.getRange2("G51").setValue("i"); ws.getRange2("G52").setValue("h"); ws.getRange2("G53").setValue("g"); ws.getRange2("G54").setValue("f"); ws.getRange2("G55").setValue("e"); ws.getRange2("G56").setValue("d"); ws.getRange2("G57").setValue("c"); ws.getRange2("G58").setValue("b"); ws.getRange2("G59").setValue("a"); ws.getRange2("H50").setValue("Apple"); ws.getRange2("H51").setValue("Grape"); ws.getRange2("H52").setValue("Banana"); ws.getRange2("H53").setValue("Orange"); ws.getRange2("H54").setValue("Lemon"); ws.getRange2("H55").setValue("Cherry"); ws.getRange2("H55").setValue("Zucchini"); ws.getRange2("H56").setValue("Grape"); ws.getRange2("H57").setValue("*n*"); ws.getRange2("H58").setValue("Grap?"); ws.getRange2("H59").setValue("*a*"); ws.getRange2("H60").setValue("*"); ws.getRange2("H61").setValue("?"); oParser = new parserFormula("XMATCH(H59,H50:H56, 2, 1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(*a*,H50:H56, 2, 1)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(*a*,H50:H56, 2, 1)"); oParser = new parserFormula("XMATCH(H59,H50:H56, 2, -1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(*a*,H50:H56, 2, -1)"); assert.strictEqual(oParser.calculate().getValue(), 7, "Result of XMATCH(*a*,H50:H56, 2, -1)"); oParser = new parserFormula("XMATCH(H58,H50:H56, 2, 1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(Grap?,H50:H56, 2, 1)"); assert.strictEqual(oParser.calculate().getValue(), 2, "Result of XMATCH(Grap?,H50:H56, 2, 1)"); oParser = new parserFormula("XMATCH(H58,H50:H56, 2, -1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(Grap?,H50:H56, 2, -1)"); assert.strictEqual(oParser.calculate().getValue(), 7, "Result of XMATCH(Grap?,H50:H56, 2, -1)"); // ---------------------- array of mixed data ---------------------- // ws.getRange2("I50").setValue("FALSE"); ws.getRange2("I51").setValue("dsgG"); ws.getRange2("I52").setValue("TRUE"); ws.getRange2("I53").setValue("12"); ws.getRange2("I54").setValue(); ws.getRange2("I55").setValue("#N/A"); ws.getRange2("I56").setValue("-1212"); ws.getRange2("I57").setValue("00009"); ws.getRange2("I58").setValue("b"); ws.getRange2("I59").setValue("a"); ws.getRange2("I60").setValue("10"); ws.getRange2("I61").setValue("7/18/2011 7:45"); ws.getRange2("I62").setValue("7/18/2011 7:40"); ws.getRange2("I63").setValue("=TODAY()"); ws.getRange2("I64").setValue("=1+1"); oParser = new parserFormula("XMATCH(I61,I50:I64)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(I61,I50:I64)"); assert.strictEqual(oParser.calculate().getValue(), 12, "Result of XMATCH(I61,I50:I64)"); oParser = new parserFormula("XMATCH(I62,I50:I61,1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(I62,I50:I61,1)"); assert.strictEqual(oParser.calculate().getValue(), 12, "Result of XMATCH(I62,I50:I61,1)"); oParser = new parserFormula("XMATCH(I62,I50:I61,-1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(I62,I50:I61,-1)"); assert.strictEqual(oParser.calculate().getValue(), 4, "Result of XMATCH(I62,I50:I61,-1)"); oParser = new parserFormula("XMATCH(I62,I50:I61,0,2)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(I62,I50:I61,1)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XMATCH(I62,I50:I61,1)"); oParser = new parserFormula("XMATCH(I62,I50:I61,1,2)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(I62,I50:I61,1)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XMATCH(I62,I50:I61,1)"); oParser = new parserFormula("XMATCH(I62,I50:I61,-1,2)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(I62,I50:I61,1)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XMATCH(I62,I50:I61,1)"); oParser = new parserFormula("XMATCH(12,I50:I59)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(12,I50:I59)"); assert.strictEqual(oParser.calculate().getValue(), 4, "Result of XMATCH(12,I50:I59)"); oParser = new parserFormula("XMATCH(I52,I50:I59)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(TRUE,I50:I59)"); assert.strictEqual(oParser.calculate().getValue(), 3, "Result of XMATCH(TRUE,I50:I59)"); oParser = new parserFormula("XMATCH(I60,I50:I59,1,1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(10,I50:I59,1,1)"); assert.strictEqual(oParser.calculate().getValue(), 4, "Result of XMATCH(10,I50:I59,1,1)"); oParser = new parserFormula("XMATCH(I60,I50:I59,-1,1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(10,I50:I59,-1,1)"); assert.strictEqual(oParser.calculate().getValue(), 8, "Result of XMATCH(10,I50:I59,-1,1)"); oParser = new parserFormula("XMATCH(I60,I50:I59,1,-1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(10,I50:I59,1,-1)"); assert.strictEqual(oParser.calculate().getValue(), 4, "Result of XMATCH(10,I50:I59,1,-1)"); oParser = new parserFormula("XMATCH(I60,I50:I59,-1,-1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(10,I50:I59,-1,-1)"); assert.strictEqual(oParser.calculate().getValue(), 8, "Result of XMATCH(10,I50:I59,-1,-1)"); oParser = new parserFormula("XMATCH(H61,I50:I59,2,1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH('?',I50:I59,2,1)"); assert.strictEqual(oParser.calculate().getValue(), 9, "Result of XMATCH('?',I50:I59,2,1)"); oParser = new parserFormula("XMATCH(H61,I50:I59,2,-1)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH('?',I50:I59,2,-1)"); assert.strictEqual(oParser.calculate().getValue(), 10, "Result of XMATCH('?',I50:I59,2,-1)"); oParser = new parserFormula("XMATCH(I60,I50:I59,0,2)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(10,I50:I59,0,2)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XMATCH(10,I50:I59,0,2)"); oParser = new parserFormula("XMATCH(I60,I50:I59,1,2)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(10,I50:I59,1,2)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XMATCH(10,I50:I59,1,2)"); oParser = new parserFormula("XMATCH(I60,I50:I59,-1,2)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(10,I50:I59,-1,2)"); assert.strictEqual(oParser.calculate().getValue(), 8, "Result of XMATCH(10,I50:I59,-1,2)"); oParser = new parserFormula("XMATCH(I60,I50:I59,0,-2)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(10,I50:I59,0,-2)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XMATCH(10,I50:I59,0,-2)"); oParser = new parserFormula("XMATCH(I60,I50:I59,1,-2)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(10,I50:I59,1,-2)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XMATCH(10,I50:I59,1,-2)"); oParser = new parserFormula("XMATCH(I60,I50:I59,-1,-2)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(10,I50:I59,-1,-2)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XMATCH(10,I50:I59,-1,-2)"); oParser = new parserFormula("XMATCH(2,{1,2,3})", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(2,{1,2,3})"); assert.strictEqual(oParser.calculate().getValue(), 2, "Result of XMATCH(2,{1,2,3})"); oParser = new parserFormula("XMATCH(TRUE,{1,2,TRUE})", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(TRUE,{1,2,TRUE})"); assert.strictEqual(oParser.calculate().getValue(), 3, "Result of XMATCH(TRUE,{1,2,TRUE})"); oParser = new parserFormula("XMATCH(\"\",{1,2,TRUE,\"\"})", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(\"\",{1,2,TRUE,\"\"})"); assert.strictEqual(oParser.calculate().getValue(), 4, "Result of XMATCH(\"\",{1,2,TRUE,\"\"})"); oParser = new parserFormula("XMATCH(\"str\",{1,2,\"str\"})", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(\"str\",{1,2,\"str\"})"); assert.strictEqual(oParser.calculate().getValue(), 3, "Result of XMATCH(\"str\",{1,2,\"str\"})"); oParser = new parserFormula("XMATCH(I50,I50,0,0)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(I50,I50,0,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of XMATCH(I50,I50,0,0)"); oParser = new parserFormula("XMATCH(I50,I50,0)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(I50,I50,0)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(I50,I50,0)"); oParser = new parserFormula("XMATCH(I59,\"a\",0)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(I59,\"a\",0)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(I59,\"a\",0)"); // TODO ms возвращает массив c длиной искомого значения oParser = new parserFormula("XMATCH(I50:I55,I50:I59,0)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(I50:I55,I50:I59,0)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH(I50:I55,I50:I59,0)"); // TODO ms возвращает массив c длиной искомого значения oParser = new parserFormula("XMATCH({12,2,9},I50:I59,0)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH({12,2,9},I50:I59,0)"); assert.strictEqual(oParser.calculate().getValue(), 4, "Result of XMATCH({12,2,9},I50:I59,0)"); // TODO ms возвращает массив c длиной искомого значения oParser = new parserFormula("XMATCH({2,2,2},{2,2,3,4,5,2})", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH({2,2,2},{2,2,3,4,5,2})"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of XMATCH({2,2,2},{2,2,3,4,5,2})"); oParser = new parserFormula("XMATCH(,I50:I59,-1,2)", "A2", ws); assert.ok(oParser.parse(), "Call: XMATCH(,I50:I59,-1,2)"); assert.strictEqual(oParser.calculate().getValue(), 5, "Result of XMATCH(,I50:I59,-1,2)"); }); QUnit.test("Test: \"INDEX\"", function (assert) { let array; ws.getRange2("A651").setValue("1"); ws.getRange2("A652").setValue("2"); ws.getRange2("A653").setValue("3"); ws.getRange2("A654").setValue("4"); ws.getRange2("A655").setValue("5"); ws.getRange2("B651").setValue("6"); ws.getRange2("B652").setValue("7"); ws.getRange2("B653").setValue("8"); ws.getRange2("B654").setValue("9"); ws.getRange2("B655").setValue("10"); ws.getRange2("C651").setValue("11"); ws.getRange2("C652").setValue("12"); ws.getRange2("C653").setValue("13"); ws.getRange2("C654").setValue("14"); ws.getRange2("C655").setValue("15"); oParser = new parserFormula("INDEX({\"Apples\",\"Lemons\";\"Bananas\",\"Pears\"},2,2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "Pears"); oParser = new parserFormula("INDEX({\"Apples\",\"Lemons\";\"Bananas\",\"Pears\"},1,2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "Lemons"); oParser = new parserFormula("INDEX(\"Apples\",2,2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#REF!"); oParser = new parserFormula("INDEX({\"Apples\",\"Lemons\"},,2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "Lemons"); //данная функция возвращает area а далее уже в функции simplifyRefType находится резальтат // - пересечение а ячейкой, где располагается формула oParser = new parserFormula("INDEX(A651:C655,,2)", "A2", ws); assert.ok(oParser.parse()); var parent = AscCommonExcel.g_oRangeCache.getAscRange(oParser.parent); assert.strictEqual(oParser.simplifyRefType(oParser.calculate(), ws, parent.r1, parent.c1).getValue(), "#VALUE!"); oParser = new parserFormula("INDEX(A651:C655,,2)", "D651", ws); assert.ok(oParser.parse()); parent = AscCommonExcel.g_oRangeCache.getAscRange(oParser.parent); assert.strictEqual(oParser.simplifyRefType(oParser.calculate(), ws, parent.r1, parent.c1).getValue(), 6); oParser = new parserFormula("INDEX(A651:C655,,2)", "D652", ws); assert.ok(oParser.parse()); parent = AscCommonExcel.g_oRangeCache.getAscRange(oParser.parent); assert.strictEqual(oParser.simplifyRefType(oParser.calculate(), ws, parent.r1, parent.c1).getValue(), 7); oParser = new parserFormula("INDEX(A651:C655,,3)", "E652", ws); assert.ok(oParser.parse()); parent = AscCommonExcel.g_oRangeCache.getAscRange(oParser.parent); assert.strictEqual(oParser.simplifyRefType(oParser.calculate(), ws, parent.r1, parent.c1).getValue(), 12); oParser = new parserFormula("INDEX(A651:C655,,4)", "E652", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#REF!"); oParser = new parserFormula("INDEX(A651:C655,,14)", "E652", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#REF!"); oParser = new parserFormula("INDEX(A651:C655,3,2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().getValue(), 8); oParser = new parserFormula("INDEX(A651:C655,10,2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#REF!"); oParser = new parserFormula("INDEX(A651:C651,1,3)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().getValue(), 11); oParser = new parserFormula("INDEX(A651:C651,1,2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().getValue(), 6); oParser = new parserFormula("INDEX(A651:C651,0,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().getValue(), 1); oParser = new parserFormula("INDEX(A651:C651,1,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().getValue(), 1); oParser = new parserFormula("INDEX(A651:C651,2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().getValue(), 6); oParser = new parserFormula("INDEX(A651:C651,3)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().getValue(), 11); oParser = new parserFormula("INDEX(A651:C651,4)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#REF!"); oParser = new parserFormula("INDEX(A651:C652,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#REF!"); oParser = new parserFormula("INDEX(A651:C652,2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#REF!"); oParser = new parserFormula("INDEX(A651:C652,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#REF!"); oParser = new parserFormula("INDEX(A651:C651,1,1,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().getValue(), 1); oParser = new parserFormula("INDEX(A651:C651,1,1,2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#REF!"); oParser = new parserFormula("INDEX(A651:A655,A651,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().getValue(), 1); // val from arr oParser = new parserFormula('INDEX({"",1,2,3,4,5},1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ""); oParser = new parserFormula('INDEX({"",1,2,3,4,5},2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula('INDEX({"",1,2,3,4,5},5)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); oParser = new parserFormula('INDEX({1,2,3,4,5},,1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula('INDEX({1,2,3,4,5},,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula('INDEX({1,2,3,4,5},,10)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#REF!"); oParser = new parserFormula('INDEX({"";1;2;3;4;5},1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ""); oParser = new parserFormula('INDEX({"";1;2;3;4;5},5)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); // arr oParser = new parserFormula('INDEX({"";1;2;3;4;5},,1)', "A2", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "", 'Result of INDEX({"";1;2;3;4;5},,1)[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 1, 'Result of INDEX({"";1;2;3;4;5},,1)[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 2, 'Result of INDEX({"";1;2;3;4;5},,1)[2,0]'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 3, 'Result of INDEX({"";1;2;3;4;5},,1)[3,0]'); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 4, 'Result of INDEX({"";1;2;3;4;5},,1)[4,0]'); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 5, 'Result of INDEX({"";1;2;3;4;5},,1)[5,0]'); oParser = new parserFormula('INDEX({"";1;2;3;4;5},,)', "A2", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "", 'Result of INDEX({"";1;2;3;4;5},,)[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 1, 'Result of INDEX({"";1;2;3;4;5},,)[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 2, 'Result of INDEX({"";1;2;3;4;5},,)[2,0]'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 3, 'Result of INDEX({"";1;2;3;4;5},,)[3,0]'); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 4, 'Result of INDEX({"";1;2;3;4;5},,)[4,0]'); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 5, 'Result of INDEX({"";1;2;3;4;5},,)[5,0]'); oParser = new parserFormula('INDEX({"";1;2;3;4;5},,55)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#REF!"); // arr two dimensional oParser = new parserFormula('INDEX({"Apples","Lemons";"Apple","Lemon"},,)', "A2", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "Apples", 'Result of INDEX({"Apples","Lemons";"Apple","Lemon"},,)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "Lemons", 'Result of INDEX({"Apples","Lemons";"Apple","Lemon"},,)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "Apple", 'Result of INDEX({"Apples","Lemons";"Apple","Lemon"},,)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "Lemon", 'Result of INDEX({"Apples","Lemons";"Apple","Lemon"},,)[1,1]'); oParser = new parserFormula('INDEX({"Apples","Lemons";"Apple","Lemon"},1,)', "A2", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "Apples", 'Result of INDEX({"Apples","Lemons";"Apple","Lemon"},1,)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "Lemons", 'Result of INDEX({"Apples","Lemons";"Apple","Lemon"},1,)[0,1]'); oParser = new parserFormula('INDEX({"Apples","Lemons";"Apple","Lemon"},2,)', "A2", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "Apple", 'Result of INDEX({"Apples","Lemons";"Apple","Lemon"},2,)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "Lemon", 'Result of INDEX({"Apples","Lemons";"Apple","Lemon"},2,)[0,1]'); oParser = new parserFormula('INDEX({"Apples","Lemons";"Apple","Lemon"},,1)', "A2", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "Apples", 'Result of INDEX({"Apples","Lemons";"Apple","Lemon"},,1)[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "Apple", 'Result of INDEX({"Apples","Lemons";"Apple","Lemon"},,1)[1,0]'); oParser = new parserFormula('INDEX({"Apples","Lemons";"Apple","Lemon"},3,2)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#REF!"); ws.getRange2("A100").setValue("1") ws.getRange2("B100").setValue("2") ws.getRange2("A101").setValue("3") ws.getRange2("B101").setValue("4") // the behavior with array and range is different in these case(when arg2 is ommited) oParser = new parserFormula('INDEX({1,2;3,4},)', "A2", ws); assert.ok(oParser.parse()); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of INDEX({1,2;3,4},)[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, 'Result of INDEX({1,2;3,4},)[1,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, 'Result of INDEX({1,2;3,4},)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, 'Result of INDEX({1,2;3,4},)[1,1]'); oParser = new parserFormula('INDEX({"";1;2;3;4;5},#REF!)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#REF!"); oParser = new parserFormula('INDEX({1,2;3,4},1,#VALUE!)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula('INDEX({1,2;3,4},1,#NUM!)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula('INDEX(A100:B101,)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#REF!"); }); QUnit.test("Test: \"INDIRECT\"", function (assert) { ws.getRange2("A22").setValue("B22"); ws.getRange2("B22").setValue("1.333"); ws.getRange2("A23").setValue("B23"); ws.getRange2("B23").setValue("45"); ws.getRange2("A24").setValue("George"); ws.getRange2("B24").setValue("10"); ws.getRange2("A25").setValue("25"); ws.getRange2("B25").setValue("62"); oParser = new parserFormula("INDIRECT(A22)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().getValue(), 1.333); oParser = new parserFormula("INDIRECT(A23)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().getValue(), 45); ws.getRange2("A100:A102").cleanAll(); oParser = new parserFormula("INDIRECT(A100:A102)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#REF!"); /*oParser = new parserFormula( "INDIRECT(A24)", "A2", ws ); assert.ok( oParser.parse() ); assert.strictEqual( oParser.calculate().getValue().getValue(), 10 );*/ oParser = new parserFormula('INDIRECT("B"&A25)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().getValue(), 62); }); QUnit.test("Test: \"OFFSET\"", function (assert) { ws.getRange2("C150").setValue("1"); ws.getRange2("D150").setValue("2"); ws.getRange2("E150").setValue("3"); ws.getRange2("C151").setValue("2"); ws.getRange2("D151").setValue("3"); ws.getRange2("E151").setValue("4"); ws.getRange2("C152").setValue("3"); ws.getRange2("D152").setValue("4"); ws.getRange2("E152").setValue("5"); oParser = new parserFormula("OFFSET(C3,2,3,1,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().toString(), "F5"); oParser = new parserFormula("SUM(OFFSET(C151:E155,-1,0,3,3))", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 27); oParser = new parserFormula("OFFSET(B3, -2, 0, 1, 1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().toString(), "B1"); oParser = new parserFormula("OFFSET(B3, 0, 0, -1, 1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().toString(), "B3"); oParser = new parserFormula("OFFSET(B3, 0, 0, -1, -1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().toString(), "B3"); oParser = new parserFormula("OFFSET(B3, 0, 0,,)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().toString(), "B3"); oParser = new parserFormula("OFFSET(B3, 0, 0, 1,)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().toString(), "B3"); oParser = new parserFormula("OFFSET(B3, 0, 0, -2, -2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().toString(), "A2:B3"); oParser = new parserFormula("OFFSET(B3, 0, 0, -1, -2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().toString(), "A3:B3"); oParser = new parserFormula("OFFSET(B3, 0, 0, 0, -2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().toString(), "#REF!"); oParser = new parserFormula("OFFSET(B3, 0, 0, 2, 0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().toString(), "#REF!"); oParser = new parserFormula("OFFSET(C3:D4, 0, 0, 2, 2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().toString(), "C3:D4"); oParser = new parserFormula("OFFSET(C3:D4, 0, 0, 3, 3)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().toString(), "C3:E5"); oParser = new parserFormula("OFFSET(C3:D4, 2, 2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().toString(), "E5:F6"); oParser = new parserFormula("OFFSET(C3:D4,2,2,3,3)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().toString(), "E5:G7"); oParser = new parserFormula("OFFSET(C3:E6, 0, 0, 3, 3)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().toString(), "C3:E5"); oParser = new parserFormula("OFFSET(C3:D4, 0, 0, -2, -2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().toString(), "B2:C3"); oParser = new parserFormula("OFFSET(C3:D4, 0, 0, -3, -3)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().toString(), "A1:C3"); oParser = new parserFormula("OFFSET(C3:E6, 0, 0, -3, -3)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().toString(), "A1:C3"); oParser = new parserFormula("OFFSET(F10:M17, 0, 0, -7,-5)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().toString(), "B4:F10"); }); /* * Financial */ QUnit.test("Test: \"FV\"", function (assert) { function fv(rate, nper, pmt, pv, type) { var res; if (type === undefined || type === null) { type = 0; } if (pv === undefined || pv === null) { pv = 0; } if (rate != 0) { res = -1 * (pv * Math.pow(1 + rate, nper) + pmt * (1 + rate * type) * (Math.pow(1 + rate, nper) - 1) / rate); } else { res = -1 * (pv + pmt * nper); } return res; } oParser = new parserFormula("FV(0.06/12,10,-200,-500,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), fv(0.06 / 12, 10, -200, -500, 1)); oParser = new parserFormula("FV(0.12/12,12,-1000)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), fv(0.12 / 12, 12, -1000)); oParser = new parserFormula("FV(0.11/12,35,-2000,,1)", "A2", ws); assert.ok(oParser.parse()); assert.ok(Math.abs(oParser.calculate().getValue() - fv(0.11 / 12, 35, -2000, null, 1)) < dif); oParser = new parserFormula("FV(0.06/12,12,-100,-1000,1)", "A2", ws); assert.ok(oParser.parse()); assert.ok(Math.abs(oParser.calculate().getValue() - fv(0.06 / 12, 12, -100, -1000, 1)) < dif); testArrayFormula2(assert, "FV", 3, 5); }); QUnit.test("Test: \"PMT\"", function (assert) { function pmt(rate, nper, pv, fv, type) { var res; if (type === undefined || type === null) { type = 0; } if (fv === undefined || fv === null) { fv = 0; } if (rate != 0) { res = -1 * (pv * Math.pow(1 + rate, nper) + fv) / ((1 + rate * type) * (Math.pow(1 + rate, nper) - 1) / rate); } else { res = -1 * (pv + fv) / nper; } return res; } oParser = new parserFormula("PMT(0.08/12,10,10000)", "A2", ws); assert.ok(oParser.parse()); assert.ok(Math.abs(oParser.calculate().getValue() - pmt(0.08 / 12, 10, 10000)) < dif); oParser = new parserFormula("PMT(0.08/12,10,10000,0,1)", "A2", ws); assert.ok(oParser.parse()); assert.ok(Math.abs(oParser.calculate().getValue() - pmt(0.08 / 12, 10, 10000, 0, 1)) < dif); testArrayFormula2(assert, "PMT", 3, 5); }); QUnit.test("Test: \"NPER\"", function (assert) { function nper(rate, pmt, pv, fv, type) { if (rate === undefined || rate === null) { rate = 0; } if (pmt === undefined || pmt === null) { pmt = 0; } if (pv === undefined || pv === null) { pv = 0; } if (type === undefined || type === null) { type = 0; } if (fv === undefined || fv === null) { fv = 0; } let res; if (rate != 0) { res = (-fv * rate + pmt * (1 + rate * type)) / (rate * pv + pmt * (1 + rate * type)) res = Math.log(res) / Math.log(1 + rate) } else { res = -(pv + fv) / pmt; } return res; } oParser = new parserFormula("NPER(0.12/12,-100,-1000,10000,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), nper(0.12 / 12, -100, -1000, 10000, 1)); oParser = new parserFormula("NPER(0.12/12,-100,-1000)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), nper(0.12 / 12, -100, -1000)); // bug 70050 oParser = new parserFormula("NPER(0,-393977.5252,14351946.04,,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), nper(0,-393977.5252,14351946.04,0,1)); oParser = new parserFormula("NPER(0,393977.5252,14351946.04,,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), nper(0,393977.5252,14351946.04,0,1)); testArrayFormula2(assert, "NPER", 3, 5); }); QUnit.test("Test: \"PV\"", function (assert) { function pv(rate, nper, pmt, fv, type) { if (rate != 0) { return -1 * (fv + pmt * (1 + rate * type) * ((Math.pow((1 + rate), nper) - 1) / rate)) / Math.pow(1 + rate, nper) } else { return -1 * (fv + pmt * nper); } } oParser = new parserFormula("PV(0.08/12,12*20,500,,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), pv(0.08 / 12, 12 * 20, 500, 0, 0)); oParser = new parserFormula("PV(0,12*20,500,,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), pv(0, 12 * 20, 500, 0, 0)); testArrayFormula2(assert, "PV", 3, 5); }); QUnit.test("Test: \"NPV\"", function (assert) { //TODO в хроме при расчёте разница, временно убираю oParser = new parserFormula("NPV(0.1,-10000,3000,4200,6800)", "A2", ws); assert.ok(oParser.parse()); //assert.strictEqual( oParser.calculate().getValue(), 1188.4434123352216 ); }); QUnit.test("Test: \"EFFECT\"", function (assert) { function effect(nr, np) { if (nr <= 0 || np < 1) { return "#NUM!"; } return Math.pow((1 + nr / np), np) - 1; } oParser = new parserFormula("EFFECT(0.0525,4)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), effect(0.0525, 4)); oParser = new parserFormula("EFFECT(0.0525,-4)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), effect(0.0525, -4)); oParser = new parserFormula("EFFECT(0.0525,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), effect(0.0525, 1)); oParser = new parserFormula("EFFECT(-1,54)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), effect(-1, 54)); testArrayFormula2(assert, "EFFECT", 2, 2, true) }); QUnit.test("Test: \"ISPMT\"", function (assert) { function ISPMT(rate, per, nper, pv) { return pv * rate * (per / nper - 1.0) } oParser = new parserFormula("ISPMT(0.1/12,1,3*12,8000000)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ISPMT(0.1 / 12, 1, 3 * 12, 8000000)); oParser = new parserFormula("ISPMT(0.1,1,3,8000000)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ISPMT(0.1, 1, 3, 8000000)); testArrayFormula2(assert, "ISPMT", 4, 4); }); QUnit.test("Test: \"ISFORMULA\"", function (assert) { ws.getRange2("C150").setValue("=TODAY()"); ws.getRange2("C151").setValue("7"); ws.getRange2("C152").setValue("Hello, world!"); ws.getRange2("C153").setValue("=3/0"); oParser = new parserFormula("ISFORMULA(C150)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().toString(), "TRUE"); oParser = new parserFormula("ISFORMULA(C151)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().toString(), "FALSE"); oParser = new parserFormula("ISFORMULA(C152)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().toString(), "FALSE"); oParser = new parserFormula("ISFORMULA(C153)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().toString(), "TRUE"); testArrayFormulaEqualsValues(assert, "FALSE,FALSE,FALSE,#N/A;FALSE,FALSE,FALSE,#N/A;#N/A,#N/A,#N/A,#N/A", "ISFORMULA(A1:C2)"); testArrayFormulaEqualsValues(assert, "FALSE,FALSE,#N/A,#N/A;FALSE,FALSE,#N/A,#N/A;FALSE,FALSE,#N/A,#N/A", "ISFORMULA(A1:B1)"); testArrayFormulaEqualsValues(assert, "FALSE,FALSE,FALSE,FALSE;FALSE,FALSE,FALSE,FALSE;FALSE,FALSE,FALSE,FALSE", "ISFORMULA(A1)"); }); QUnit.test("Test: \"IFNA\"", function (assert) { oParser = new parserFormula('IFNA(MATCH(30,B1:B5,0),"Not found")', "A2", ws); assert.ok(oParser.parse(), 'IFNA(MATCH(30,B1:B5,0),"Not found")'); assert.strictEqual(oParser.calculate().getValue(), "Not found", 'IFNA(MATCH(30,B1:B5,0),"Not found")'); }); QUnit.test("Test: \"IFERROR\"", function (assert) { ws.getRange2("A2").setValue("210"); ws.getRange2("A3").setValue("55"); ws.getRange2("A4").setValue(""); ws.getRange2("B2").setValue("35"); ws.getRange2("B3").setValue("0"); ws.getRange2("B4").setValue("23"); oParser = new parserFormula('IFERROR(A2/B2,"Error in calculation")', "A22", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 6); oParser = new parserFormula('IFERROR(A3/B3,"Error in calculation")', "A22", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 'Error in calculation'); oParser = new parserFormula('IFERROR(A4/B4,"Error in calculation")', "A22", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); //testArrayFormula2(assert, "IFERROR", 2, 2); }); QUnit.test("Test: \"XNPV\"", function (assert) { function xnpv(rate, valueArray, dateArray) { var res = 0, r = rate; var d1 = dateArray[0]; for (var i = 0; i < dateArray.length; i++) { res += valueArray[i] / (Math.pow((1 + r), (dateArray[i] - d1) / 365)) } return res; } ws.getRange2("A701").setValue("39448"); ws.getRange2("A702").setValue("39508"); ws.getRange2("A703").setValue("39751"); ws.getRange2("A704").setValue("39859"); ws.getRange2("A705").setValue("39904"); oParser = new parserFormula("XNPV(0.09,{-10000,2750,4250,3250,2750},A701:A705)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), xnpv(0.09, [-10000, 2750, 4250, 3250, 2750], [39448, 39508, 39751, 39859, 39904])); ws.getRange2("A705").setValue("43191"); oParser = new parserFormula("XNPV(0.09,{-10000,2750,4250,3250,2750},A701:A705)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), xnpv(0.09, [-10000, 2750, 4250, 3250, 2750], [39448, 39508, 39751, 39859, 43191])); }); QUnit.test("Test: \"IRR\"", function (assert) { function irr(costArr, x) { if (!x) { x = 0.1 } var nC = 0, g_Eps = 1e-7, fEps = 1.0, fZ = 0, fN = 0, xN = 0, nIM = 100, nMC = 0, arr0 = costArr[0], arrI, wasNegative = false, wasPositive = false; if (arr0 < 0) { wasNegative = true; } else if (arr0 > 0) { wasPositive = true; } while (fEps > g_Eps && nMC < nIM) { nC = 0; fZ = 0; fN = 0; fZ += costArr[0] / Math.pow(1.0 + x, nC); fN += -nC * costArr[0] / Math.pow(1 + x, nC + 1); nC++; for (var i = 1; i < costArr.length; i++) { arrI = costArr[i]; fZ += arrI / Math.pow(1.0 + x, nC); fN += -nC * arrI / Math.pow(1 + x, nC + 1); if (arrI < 0) { wasNegative = true; } else if (arrI > 0) { wasPositive = true } nC++ } xN = x - fZ / fN; nMC++; fEps = Math.abs(xN - x); x = xN; } if (!(wasNegative && wasPositive)) { return "#NUM!"; } if (fEps < g_Eps) { return x; } else { return "#NUM!"; } } //TODO в хроме при расчёте разница, временно убираю oParser = new parserFormula("IRR({-70000,12000,15000,18000,21000})", "A2", ws); assert.ok(oParser.parse()); //assert.strictEqual( oParser.calculate().getValue(), -0.021244848273410923 ); ws.getRange2("A705").setValue("43191"); //TODO в хроме при расчёте разница, временно убираю oParser = new parserFormula("IRR({-70000,12000,15000,18000,21000,26000})", "A2", ws); assert.ok(oParser.parse()); //assert.strictEqual( oParser.calculate().getValue(), 0.08663094803653171 ); oParser = new parserFormula("IRR({-70000,12000,15000},-0.1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -0.44350694133450463); oParser = new parserFormula("IRR({-70000},-0.1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); // for bug 78419 const defName = new Asc.asc_CDefName('TestName', ws.getName() + '!$A$200:$B$200'); wb.editDefinesNames(null, defName); ws.getRange2("B100").setValue("-123"); ws.getRange2("C100:E100").setValue("123"); ws.getRange2("A200").setValue("-123"); // TestName ws.getRange2("B200").setValue("1234"); // TestName let wsName = ws.getName(); oParser = new parserFormula("IRR("+ wsName +"!B100:E100)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7), '0.8392868', "Result of IRR(SheetName!B100:E100) - area3D check"); oParser = new parserFormula("IRR({-1,2,3,4}, "+ wsName +"!B100:E100)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7), '2.2842779', "Result of IRR({-1,2,3,4},SheetName!B100:E100) - array,area3D check"); oParser = new parserFormula("IRR("+ wsName +"!B100:E100, "+ wsName +"!B100:E100)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7), '0.8392868', "Result of IRR(SheetName!B100:E100, SheetName!B100:E100) - area3D,area3D check"); oParser = new parserFormula("IRR(TestName)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7), '9.0325203', "Result of IRR(TestName) - defname check"); oParser = new parserFormula("IRR({-1,2,3,4},TestName)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7), '2.2842779', "Result of IRR({-1,2,3,4},TestName) - array,defname check"); oParser = new parserFormula("IRR("+ wsName +"!B100:E100,TestName)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7), '0.8392868', "Result of IRR("+ wsName +"!B100:E100,TestName) - area3D,defname check"); oParser = new parserFormula("IRR(TestName,"+ wsName +"!B100:E100)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7), '9.0325203', "Result of IRR(TestName,"+ wsName +"!B100:E100) - defname,area3d check"); oParser = new parserFormula("IRR(TestName, TestName)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7), '9.0325203', "Result of IRR(TestName, TestName) - defname check"); ws.getRange2("B100:E100").cleanAll(); ws.getRange2("A200:B200").cleanAll(); wb.delDefinesNames(defName); //TODO пересмотреть тест для этой функции //testArrayFormula2(assert, "IRR", 1, 2, true) }); QUnit.test("Test: \"ACCRINT\"", function (assert) { oParser = new parserFormula("ACCRINT(DATE(2006,3,1),DATE(2006,9,1),DATE(2006,5,1),0.1,1100,2,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 18.333333333333332); oParser = new parserFormula("ACCRINT(DATE(2006,3,1),DATE(2006,9,1),DATE(2006,5,1),0.1,,2,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 16.666666666666664); oParser = new parserFormula("ACCRINT(DATE(2008,3,1),DATE(2008,8,31),DATE(2010,5,1),0.1,1000,2,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 216.94444444444444); oParser = new parserFormula("ACCRINT(DATE(2008,3,1),DATE(2008,8,31),DATE(2010,5,1),0.1,1000,2,0,TRUE)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 216.94444444444444); oParser = new parserFormula("ACCRINT(DATE(2008,3,1),DATE(2008,8,31),DATE(2010,5,1),0.1,1000,2,0,FALSE)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 216.66666666666666); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,2,0,FALSE)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 711.11); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,2,0,TRUE)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89); oParser = new parserFormula("ACCRINT(2500,2700,2800,0.1,1000,2,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 82.50); oParser = new parserFormula("ACCRINT(2500,2700,2800,0.1,1000,2,0,FALSE)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 82.50); oParser = new parserFormula("ACCRINT(2500,2700,2800,0.1,1000,2,0,TRUE)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 82.50); ws.getRange2("A100").setValue("39508"); ws.getRange2("A101").setValue("39691"); ws.getRange2("A102").setValue("39769"); ws.getRange2("A103").setValue("1"); ws.getRange2("A104").setValue("1000"); ws.getRange2("A105").setValue("2"); ws.getRange2("A106").setValue("0"); ws.getRange2("A107").setValue("TRUE"); ws.getRange2("A108").setValue("FALSE"); ws.getRange2("A109").setValue("0"); ws.getRange2("A110").setValue("1"); ws.getRange2("A111").setValue("1s2p"); ws.getRange2("A220").setValue("0"); ws.getRange2("A220").setNumFormat("@"); ws.getRange2("A221").setValue("1"); ws.getRange2("A221").setNumFormat("@"); // normal case // arg[0] oParser = new parserFormula("ACCRINT(TRUE,39691,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(TRUE,39691,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(TRUE,39691,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(FALSE,39691,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(FALSE,39691,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(FALSE,39691,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(1,39691,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(1,39691,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of ACCRINT(1,39691,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(0,39691,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(0,39691,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(0,39691,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(0.75,39691,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(0.75,39691,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(0.75,39691,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(-1,39691,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(-1,39691,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(-1,39691,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(-0.75,39691,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(-0.75,39691,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(-0.75,39691,39769,1,1000,2,0)"); oParser = new parserFormula('ACCRINT("str",39691,39769,1,1000,2,0)', "A2", ws); assert.ok(oParser.parse(), 'ACCRINT("str",39691,39769,1,1000,2,0)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT('str',39691,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(,39691,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(,39691,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of ACCRINT(,39691,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT({1},39691,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT({1},39691,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of ACCRINT({1},39691,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT({1000;1200},39691,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT({1000;1200},11000,5000,8,0,2)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 106136.11, "Result of ACCRINT({1000;1200},39691,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT({39508;1000;1200;1400},39691,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT({39508},39691,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT({39508},39691,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT({-1},39691,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT({-1},39691,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT({-1},39691,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT({TRUE;2500},39691,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT({TRUE;2500},39691,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT({TRUE;2500},39691,39769,1,1000,2,0))"); oParser = new parserFormula("ACCRINT(A100:A102,39691,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(TRUE,39691,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,39691,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(A100:A100,39691,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(TRUE,39691,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,39691,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(A100,39691,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(TRUE,39691,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,39691,39769,1,1000,2,0)"); // arg[1] oParser = new parserFormula("ACCRINT(39508,TRUE,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,TRUE,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,TRUE,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,FALSE,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,FALSE,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,FALSE,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,0,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,0,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,0,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,1,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,1,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 711.11, "Result of ACCRINT(39508,1,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,0.75,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,0.75,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,0.75,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,-1,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,-1,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,-1,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,-0.75,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,-0.75,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,-0.75,39769,1,1000,2,0)"); oParser = new parserFormula('ACCRINT(39508,"str",39769,1,1000,2,0)', "A2", ws); assert.ok(oParser.parse(), 'ACCRINT(39508,"str",39769,1,1000,2,0)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,'str',39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of ACCRINT(39508,,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,{1},39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,{1},39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 711.11, "Result of ACCRINT(39508,{1},39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,{-1},39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,{-1},39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,{-1},39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,{1000;1200},39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,{1000;1200},39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 711.11, "Result of ACCRINT(39508,{1000;1200},39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,{39691;1000;1200;1400},39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,{39691;1000;1200;1400},39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,{39691;1000;1200;1400},39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,{TRUE;2500},39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,{TRUE;2500},39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,{TRUE;2500},39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,A100:A102,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,A100:A102,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,A100:A102,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,A101:A101,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,A100:A100,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,A100:A100,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,A101,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(TRUE,39691,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,39691,39769,1,1000,2,0)"); // arg[2] oParser = new parserFormula("ACCRINT(39508,39691,TRUE,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,TRUE,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,39691,TRUE,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,FALSE,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,FALSE,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,39691,FALSE,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,0,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,0,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,0,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,1,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,1,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,1,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,-1,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,-1,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,-1,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,0.75,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,0.75,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,0.75,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,-0.75,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,-0.75,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,-0.75,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,100000,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,100000,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 165622.22, "Result of ACCRINT(39508,39691,100000,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,999999999999999999999,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,999999999999999999999,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,999999999999999999999,1,1000,2,0)"); oParser = new parserFormula('ACCRINT(39508,39691,"str",1,1000,2,0)', "A2", ws); assert.ok(oParser.parse(), 'ACCRINT(39508,39691,"str",1,1000,2,0)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,39691,'str',1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of ACCRINT(39508,39691,,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,{1},1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,{1},1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,{1},1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,{-1},1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,{-1},1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,{-1},1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,{100000;1200},1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,{100000;1200},1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 165622.22, "Result of ACCRINT(39508,39691,{100000;1200},1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,{39769;1000;1200},1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,{30769;1000;1200},1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,39691,{39769;1000;1200},1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,{TRUE;2500},1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,{TRUE;2500},1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,39691,{TRUE;2500},1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,A101,A100:A102,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,A100:A102,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,A100:A102,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,A101,A102:A102,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,A100:A100,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,A100:A100,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,A101,A102,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(TRUE,39691,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,39691,39769,1,1000,2,0)"); // arg[3] oParser = new parserFormula("ACCRINT(39508,39691,39769,TRUE,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,TRUE,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,39691,39769,TRUE,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,FALSE,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,FALSE,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,39691,39769,FALSE,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,0,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,0,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,39769,0,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,39691,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,-1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,-1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,39769,-1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,0.75,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,0.75,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 535.42, "Result of ACCRINT(39508,39691,39769,0.75,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,-0.75,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,-0.75,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,39769,-0.75,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,100000,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,100000,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 71388888.89, "Result of ACCRINT(39508,39691,39769,100000,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,999999999999999999999,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,999999999999999999999,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), 7.138888888888889e+23, "Result of ACCRINT(39508,39691,39769,999999999999999999999,1000,2,0)"); oParser = new parserFormula('ACCRINT(39508,39691,39769,"str",1000,2,0)', "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,'str',1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,39691,39769,'str',1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of ACCRINT(39508,39691,39769,,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,{1},1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,{1},1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,39691,39769,{1},1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,{-1},1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,{-1},1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,39769,{-1},1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,{1000;1200},1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,{1000;1200},1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713888.89, "Result of ACCRINT(39508,39691,39769,{1000;1200},1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,{TRUE;2500},1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,{TRUE;2500},1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,39691,39769,{TRUE;2500},1000,2,0)"); oParser = new parserFormula("ACCRINT(A100,A101,A102,A101:A104,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(A100,A101,A102,A101:A104,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(A100,A101,A102,A101:A104,1000,2,0)"); oParser = new parserFormula("ACCRINT(A100,A101,A102,A103:A103,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(A100,A101,A100:A100,A103:A103,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(A100,A101,A100:A100,A103:A103,1000,2,0)"); oParser = new parserFormula("ACCRINT(A100,A101,A102,A103,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(TRUE,39691,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(A100,A101,A100,A103,1000,2,0)"); // arg[4] oParser = new parserFormula("ACCRINT(39508,39691,39769,1,TRUE,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,TRUE,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,39691,39769,1,TRUE,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,FALSE,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,FALSE,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,39691,39769,1,FALSE,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,0,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,0,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,39769,1,0,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(4) - 0, 0.7139, "Result of ACCRINT(39508,39691,39769,1,1,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,-1,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,-1,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,39769,1,-1,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,0.75,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,0.75,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.535417, "Result of ACCRINT(39508,39691,39769,1,0.75,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,-0.75,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,-0.75,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,39769,1,-0.75,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,100000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,100000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 71388.89, "Result of ACCRINT(39508,39691,39769,1,100000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,999999999999999999999,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,999999999999999999999,2,0)"); assert.strictEqual(oParser.calculate().getValue(), 713888888888888900000, "Result of ACCRINT(39508,39691,39769,1,999999999999999999999,2,0)"); // 7.13889E+20 oParser = new parserFormula('ACCRINT(39508,39691,39769,1,"str",2,0)', "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,'str',2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,39691,39769,1,'str',2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,39691,39769,1,,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,{1},2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,{1},2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(4) - 0, 0.7139, "Result of ACCRINT(39508,39691,39769,1,{1},2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,{-1},2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,{-1},2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,39769,1,{-1},2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,{1000;1200},2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,{1000;1200},2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,39691,39769,1,{1000;1200},2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,{TRUE;2500},2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,{TRUE;2500},2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,39691,39769,1,{TRUE;2500},2,0)"); oParser = new parserFormula("ACCRINT(A100,A101,A102,A103,A100:A104,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(A100,A101,A102,A103,A100:A104,2,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(A100,A101,A102,A103,A100:A104,2,0)"); oParser = new parserFormula("ACCRINT(A100,A101,A102,A103,A104:A104,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(A100,A101,A102,A103,A104:A104,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(A100,A101,A102,A103,A104:A104,2,0)"); oParser = new parserFormula("ACCRINT(A100,A101,A102,A103,A104,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(A100,A101,A102,A103,A104,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(A100,A101,A102,A103,A104,2,0)"); // arg[5] oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,TRUE,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,TRUE,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,39691,39769,1,1000,TRUE,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,FALSE,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,FALSE,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,39691,39769,1,1000,FALSE,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,0,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,0,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,39769,1,1000,0,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,1,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,1,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,39691,39769,1,1000,1,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,39691,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,4,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,4,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,39691,39769,1,1000,4,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,8,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,8,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,39769,1,1000,8,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,-1,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,-1,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,39769,1,1000,-1,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,0.75,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,0.75,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,39769,1,1000,0.75,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,-0.75,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,-0.75,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,39769,1,1000,-0.75,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,100000,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,100000,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,39769,1,1000,100000,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,999999999999999999999,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,999999999999999999999,0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,39769,1,1000,999999999999999999999,0)"); oParser = new parserFormula('ACCRINT(39508,39691,39769,1,1000,"str",0)', "A2", ws); assert.ok(oParser.parse(), 'ACCRINT(39508,39691,39769,1,1000,"str",0)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,39691,39769,1,1000,'str',0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,,0)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of ACCRINT(39508,39691,39769,1,1000,,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,{1},0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,{1},0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,39691,39769,1,1000,{1},0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,{-1},0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,{-1},0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,39769,1,1000,{-1},0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,{1000;1200},0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,{1000;1200},0)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,39769,1,1000,{1000;1200},0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,{TRUE;2500},0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,{TRUE;2500},0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,39691,39769,1,1000,{TRUE;2500},0)"); oParser = new parserFormula("ACCRINT(A100,A101,A102,A103,A104,A101:A105,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(A100,A101,A102,A103,A104,A101:A105,0)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(A100,A101,A102,A103,A104,A101:A105,0)"); oParser = new parserFormula("ACCRINT(A100,A101,A102,A103,A104,A105:A105,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(A100,A101,A102,A103,A104,A105:A105,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(A100,A101,A102,A103,A104,A105:A105,0"); oParser = new parserFormula("ACCRINT(A100,A101,A102,A103,A104,A105,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(A100,A101,A102,A103,A104,A105,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(A100,A101,A102,A103,A104,A105,0)"); // arg[6] oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,1,TRUE)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,1,TRUE)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,39691,39769,1,1000,1,TRUE)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,1,FALSE)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,1,FALSE)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,39691,39769,1,1000,1,FALSE)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,1,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,1,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,39691,39769,1,1000,1,0)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,1,-1)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,1,-1)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,39769,1,1000,1,-1)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,1,0.75)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,1,0.75)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,39691,39769,1,1000,1,0.75)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,1,-0.75)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,1,-0.75)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,39769,1,1000,1,-0.75)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,1,100000)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,1,100000)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,39769,1,1000,1,100000)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,1,999999999999999999999)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,1,999999999999999999999)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,39769,1,1000,1,999999999999999999999)"); oParser = new parserFormula('ACCRINT(39508,39691,39769,1,1000,1,"str")', "A2", ws); assert.ok(oParser.parse(), 'ACCRINT(39508,39691,39769,1,1000,1,"str")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,39691,39769,1,1000,1,'str')"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,1,,)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,1,,)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,39691,39769,1,1000,1,,)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,1,{0})", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,1,{0})"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,39691,39769,1,1000,1,{0})"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,1,{-1})", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,1,{-1})"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,39769,1,1000,1,{-1})"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,1,{1000;1200})", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,1,{1000;1200})"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(39508,39691,39769,1,1000,1,{1000;1200})"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,1,{TRUE;2500})", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,1,{TRUE;2500})"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,39691,39769,1,1000,1,{TRUE;2500})"); oParser = new parserFormula("ACCRINT(A100,A101,A102,A103,A104,A105,A101:A106)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(A100,A101,A102,A103,A104,A105,A101:A106)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(A100,A101,A102,A103,A104,A105,A101:A106)"); oParser = new parserFormula("ACCRINT(A100,A101,A102,A103,A104,A105,A106:A106)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(A100,A101,A102,A103,A104,A105,A106:A106)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(A100,A101,A102,A103,A104,A105,A106:A106)"); oParser = new parserFormula("ACCRINT(A100,A101,A102,A103,A104,A105,A106)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(A100,A101,A102,A103,A104,A105,A106)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(A100,A101,A102,A103,A104,A105,A106)"); // arg[7] oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,1,0;TRUE)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,1,0;TRUE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,39691,39769,1,1000,1,0;TRUE)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,1,0;FALSE)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,1,0;FALSE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 711.11, "Result of ACCRINT(39508,39691,39769,1,1000,1,0;FALSE)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,1,0;)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,1,0;)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,39691,39769,1,1000,1,0;)"); oParser = new parserFormula('ACCRINT(39508,39691,39769,1,1000,1,0;"str")', "A2", ws); assert.ok(oParser.parse(), 'ACCRINT(39508,39691,39769,1,1000,1,0;"str")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(39508,39691,39769,1,1000,1,0;'str')"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,1,0;1)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,1,0;1)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,39691,39769,1,1000,1,0;1)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,1,0;-1)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,1,0;-1)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,39691,39769,1,1000,1,0;-1)"); oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,1,0,{TRUE;2500})", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,1,0,{TRUE;2500})"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,39691,39769,1,1000,1,0,{TRUE;2500})"); oParser = new parserFormula("ACCRINT(A100,A101,A102,A103,A104,A105,A106,A101:A107)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(A100,A101,A102,A103,A104,A105,A106,A101:A107)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(A100,A101,A102,A103,A104,A105,A106,A101:A107)"); oParser = new parserFormula("ACCRINT(A100,A101,A102,A103,A104,A105,A106,A107:A107)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(A100,A101,A102,A103,A104,A105,A106,A107:A107)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(A100,A101,A102,A103,A104,A105,A106,A107:A107)"); oParser = new parserFormula("ACCRINT(A100,A101,A102,A103,A104,A105,A106,A107)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(A100,A101,A102,A103,A104,A105,A106,A107)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(A100,A101,A102,A103,A104,A105,A106,A107)"); oParser = new parserFormula("ACCRINT(A100,A101,A102,A103,A104,A105,A106,A107:A107)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(A100,A101,A102,A103,A104,A105,A106,A107:A107)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(A100,A101,A102,A103,A104,A105,A106,A107:A107)"); oParser = new parserFormula("ACCRINT(A100,A101,A102,A103,A104,A105,A106,A107:A108)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(A100,A101,A102,A103,A104,A105,A106,A107:A108)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(A100,A101,A102,A103,A104,A105,A106,A107:A108)"); oParser = new parserFormula("ACCRINT(A100,A101,A102,A103,A104,A105,A106)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(A100,A101,A102,A103,A104,A105,A106)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(A100,A101,A102,A103,A104,A105,A106)"); oParser = new parserFormula("ACCRINT(A100,A101,A102,A103,A104,A105,A106,FALSE)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(A100,A101,A102,A103,A104,A105,A106,FALSE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 711.11, "Result of ACCRINT(A100,A101,A102,A103,A104,A105,A106,FALSE)"); oParser = new parserFormula("ACCRINT(A100,A101,A102,A103,A104,A105,A106,TRUE)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(A100,A101,A102,A103,A104,A105,A106,TRUE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(A100,A101,A102,A103,A104,A105,A106,TRUE)"); oParser = new parserFormula("ACCRINT(A100,A101,A102,A103,A104,A105,A106,A109)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(A100,A101,A102,A103,A104,A105,A106,A109)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 711.11, "Result of ACCRINT(A100,A101,A102,A103,A104,A105,A106,A109)"); oParser = new parserFormula("ACCRINT(A100,A101,A102,A103,A104,A105,A106,A110)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(A100,A101,A102,A103,A104,A105,A106,A110)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(A100,A101,A102,A103,A104,A105,A106,A110)"); oParser = new parserFormula("ACCRINT(A100,A101,A102,A103,A104,A105,A106,A111)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(A100,A101,A102,A103,A104,A105,A106,A111)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of ACCRINT(A100,A101,A102,A103,A104,A105,A106,A111)"); oParser = new parserFormula("ACCRINT(A100,A101,A102,A103,A104,A105,A106,A220)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(A100,A101,A102,A103,A104,A105,A106,A220)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 711.11, "Result of ACCRINT(A100,A101,A102,A103,A104,A105,A106,A220)"); oParser = new parserFormula("ACCRINT(A100,A101,A102,A103,A104,A105,A106,A221)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(A100,A101,A102,A103,A104,A105,A106,A221)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(A100,A101,A102,A103,A104,A105,A106,A221)"); // in these cases (arg[1] >= arg[2]) while loop is not executed and the result is correct oParser = new parserFormula("ACCRINT(44562,44621,44576,0.05,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2022,1,1),DATE(2022,3,1),DATE(2022,1,15),0.05,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(3) - 0, 1.944, "Result of ACCRINT(DATE(2022,1,1),DATE(2022,3,1),DATE(2022,1,15),0.05,1000,2,0)"); oParser = new parserFormula("ACCRINT(44562,44621,44576,0.05,1000,2,1)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2022,1,1),DATE(2022,3,1),DATE(2022,1,15),0.05,1000,2,1)"); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 1.933701657, "Result of ACCRINT(DATE(2022,1,1),DATE(2022,3,1),DATE(2022,1,15),0.05,1000,2,1)"); oParser = new parserFormula("ACCRINT(44562,44621,44576,0.05,1000,2,2)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2022,1,1),DATE(2022,3,1),DATE(2022,1,15),0.05,1000,2,2)"); assert.strictEqual(oParser.calculate().getValue().toFixed(3) - 0, 1.944, "Result of ACCRINT(DATE(2022,1,1),DATE(2022,3,1),DATE(2022,1,15),0.05,1000,2,2)"); oParser = new parserFormula("ACCRINT(44562,44621,44576,0.05,1000,2,3)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2022,1,1),DATE(2022,3,1),DATE(2022,1,15),0.05,1000,2,3)"); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 1.917808219, "Result of ACCRINT(DATE(2022,1,1),DATE(2022,3,1),DATE(2022,1,15),0.05,1000,2,3)"); oParser = new parserFormula("ACCRINT(44562,44621,44576,0.05,1000,2,4)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2022,1,1),DATE(2022,3,1),DATE(2022,1,15),0.05,1000,2,4)"); assert.strictEqual(oParser.calculate().getValue().toFixed(3) - 0, 1.944, "Result of ACCRINT(DATE(2022,1,1),DATE(2022,3,1),DATE(2022,1,15),0.05,1000,2,4)"); // bug cases // TODO fix the calculation of the coupon period when receiving the date 1900,1,29(60) oParser = new parserFormula("ACCRINT(58,39691,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(58,39691,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of ACCRINT(58,39691,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(59,39691,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(59,39691,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 108713.89, "Result of ACCRINT(59,39691,39769,1,1000,2,0)"); oParser = new parserFormula("ACCRINT(60,39691,39769,1,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(60,39691,39769,1,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 108713.89, "Result of ACCRINT(60,39691,39769,1,1000,2,0)"); // 108719.44 oParser = new parserFormula("ACCRINT(60,39691,39769,1,1000,2,0,TRUE)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(60,39691,39769,1,1000,2,0,TRUE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 108713.89, "Result of ACCRINT(60,39691,39769,1,1000,2,0,TRUE)"); // 108719.44 oParser = new parserFormula("ACCRINT(60,39691,39769,1,1000,2,0,FALSE)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(60,39691,39769,1,1000,2,0,FALSE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 1213.89, "Result of ACCRINT(60,39691,39769,1,1000,2,0,FALSE)"); // 1219.44 oParser = new parserFormula("ACCRINT(60,39691,39769,1,1000,2,1,FALSE)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(60,39691,39769,1,1000,2,1,FALSE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 1198.37, "Result of ACCRINT(60,39691,39769,1,1000,2,1,FALSE)"); // 1209.25 oParser = new parserFormula("ACCRINT(60,39691,39769,1,1000,2,2,FALSE)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(60,39691,39769,1,1000,2,2,FALSE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 1213.95, "Result of ACCRINT(60,39691,39769,1,1000,2,2,FALSE)"); // 1238.89 oParser = new parserFormula("ACCRINT(60,39691,39769,1,1000,2,3,FALSE)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(60,39691,39769,1,1000,2,3,FALSE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 1208.22, "Result of ACCRINT(60,39691,39769,1,1000,2,3,FALSE)"); // 1221.92 oParser = new parserFormula("ACCRINT(60,39691,39769,1,1000,2,4,FALSE)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(60,39691,39769,1,1000,2,4,FALSE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 1208.42, "Result of ACCRINT(60,39691,39769,1,1000,2,4,FALSE)"); // 1213.92 oParser = new parserFormula("ACCRINT(DATE(2020,1,1),DATE(2020,7,1),DATE(2020,12,31),0.1,100,1)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2020,1,1),DATE(2020,7,1),DATE(2020,12,31),0.1,100,1)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 10, "Result of ACCRINT(DATE(2020,1,1),DATE(2020,7,1),DATE(2020,12,31),0.1,100,1)"); oParser = new parserFormula("ACCRINT(DATE(2020,1,1),DATE(2020,7,1),DATE(2020,12,31),0.1,100,1,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2020,1,1),DATE(2020,7,1),DATE(2020,12,31),0.1,100,1,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 10, "Result of ACCRINT(DATE(2020,1,1),DATE(2020,7,1),DATE(2020,12,31),0.1,100,1,0)"); oParser = new parserFormula("ACCRINT(DATE(2020,1,1),DATE(2020,7,1),DATE(2020,12,31),0.1,100,1,1)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2020,1,1),DATE(2020,7,1),DATE(2020,12,31),0.1,100,1,1)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 10.01, "Result of ACCRINT(DATE(2020,1,1),DATE(2020,7,1),DATE(2020,12,31),0.1,100,1,1)"); // 9.97 oParser = new parserFormula("ACCRINT(DATE(2020,1,1),DATE(2020,7,1),DATE(2020,12,31),0.1,100,1,2)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2020,1,1),DATE(2020,7,1),DATE(2020,12,31),0.1,100,1,2)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 9.94, "Result of ACCRINT(DATE(2020,1,1),DATE(2020,7,1),DATE(2020,12,31),0.1,100,1,2)"); // 10.14 oParser = new parserFormula("ACCRINT(DATE(2020,1,1),DATE(2020,7,1),DATE(2020,12,31),0.1,100,1,3)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2020,1,1),DATE(2020,7,1),DATE(2020,12,31),0.1,100,1,3)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 10.03, "Result of ACCRINT(DATE(2020,1,1),DATE(2020,7,1),DATE(2020,12,31),0.1,100,1,3)"); // 10 oParser = new parserFormula("ACCRINT(DATE(2020,1,1),DATE(2020,7,1),DATE(2020,12,31),0.1,100,1,4)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2020,1,1),DATE(2020,7,1),DATE(2020,12,31),0.1,100,1,4)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 9.97, "Result of ACCRINT(DATE(2020,1,1),DATE(2020,7,1),DATE(2020,12,31),0.1,100,1,4)"); // 9.97 oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,1,1)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,1,1)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 724.66, "Result of ACCRINT(39508,39691,39769,1,1000,1,1)"); // 709.24 oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,1,{1})", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,1,{1})"); assert.strictEqual(oParser.calculate().getValue().toFixed() - 0, 725, "Result of ACCRINT(39508,39691,39769,1,1000,1,{1})"); // 709.24 oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,1,2)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,1,2)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 713.89, "Result of ACCRINT(39508,39691,39769,1,1000,1,2)"); // 725 oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,1,3)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,1,3)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 726.03, "Result of ACCRINT(39508,39691,39769,1,1000,1,3)"); // 715.07 oParser = new parserFormula("ACCRINT(39508,39691,39769,1,1000,1,4)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(39508,39691,39769,1,1000,1,4)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 711.11, "Result of ACCRINT(39508,39691,39769,1,1000,1,4)"); // 708.36 oParser = new parserFormula("ACCRINT(44562,44576,44621,0.05,1000,2,0)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2022,1,1),DATE(2022,1,15),DATE(2022,3,1),0.05,1000,2,0)"); assert.strictEqual(oParser.calculate().getValue().toFixed(3) - 0, 8.333, "Result of ACCRINT(DATE(2022,1,1),DATE(2022,1,15),DATE(2022,3,1),0.05,1000,2,0)"); oParser = new parserFormula("ACCRINT(44562,44576,44621,0.05,1000,2,1)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2022,1,1),DATE(2022,1,15),DATE(2022,3,1),0.05,1000,2,1)"); assert.strictEqual(oParser.calculate().getValue().toFixed(3) - 0, 8.696, "Result of ACCRINT(DATE(2022,1,1),DATE(2022,1,15),DATE(2022,3,1),0.05,1000,2,1)"); // 8.016 oParser = new parserFormula("ACCRINT(44562,44576,44621,0.05,1000,2,2)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2022,1,1),DATE(2022,1,15),DATE(2022,3,1),0.05,1000,2,2)"); assert.strictEqual(oParser.calculate().getValue().toFixed(3) - 0, 8.291, "Result of ACCRINT(DATE(2022,1,1),DATE(2022,1,15),DATE(2022,3,1),0.05,1000,2,2)"); // 8.194 oParser = new parserFormula("ACCRINT(44562,44576,44621,0.05,1000,2,3)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2022,1,1),DATE(2022,1,15),DATE(2022,3,1),0.05,1000,2,3)"); assert.strictEqual(oParser.calculate().getValue().toFixed(3) - 0, 8.562, "Result of ACCRINT(DATE(2022,1,1),DATE(2022,1,15),DATE(2022,3,1),0.05,1000,2,3)"); // 8.082 oParser = new parserFormula("ACCRINT(44562,44576,44621,0.05,1000,2,4)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2022,1,1),DATE(2022,1,15),DATE(2022,3,1),0.05,1000,2,4)"); assert.strictEqual(oParser.calculate().getValue().toFixed(3) - 0, 8.333, "Result of ACCRINT(DATE(2022,1,1),DATE(2022,1,15),DATE(2022,3,1),0.05,1000,2,4)"); // oParser = new parserFormula("ACCRINT(60,DATE(2022,3,1),DATE(2022,1,15),0.05,1000,2,0,FALSE)", "A2", ws); // assert.ok(oParser.parse(), "ACCRINT(60,44621,44567,0.05,1000,2,0,FALSE)"); // assert.strictEqual(oParser.calculate().getValue(), 0, "Result of ACCRINT(60,44621,44567,0.05,1000,2,0,FALSE)"); // oParser = new parserFormula("ACCRINT(60,DATE(2022,3,1),DATE(2022,1,15),0.05,1000,2,0,TRUE)", "A2", ws); // assert.ok(oParser.parse(), "ACCRINT(60,44261,44567,0.05,1000,2,0,TRUE)"); // assert.strictEqual(oParser.calculate().getValue(), 0, "Result of ACCRINT(60,44261,44567,0.05,1000,2,0,TRUE)"); oParser = new parserFormula("ACCRINT(61,DATE(2022,3,1),DATE(2022,1,15),0.05,1000,2,0,FALSE)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(61,44261,44567,0.05,1000,2,0,FALSE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(3) - 0, 18.611, "Result of ACCRINT(61,44261,44567,0.05,1000,2,0,FALSE)"); oParser = new parserFormula("ACCRINT(61,DATE(2022,3,1),DATE(2022,1,15),0.05,1000,2,0,TRUE)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(61,44261,44567,0.05,1000,2,0,TRUE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(3) - 0, 6093.611, "Result of ACCRINT(61,44261,44567,0.05,1000,2,0,TRUE)"); oParser = new parserFormula("ACCRINT(DATE(2012,8,1),DATE(2013,3,1),DATE(2012,8,30),0.05,100,2,1)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2012,8,1),DATE(2013,3,1),DATE(2012,8,30),0.05,100,2,1)"); assert.strictEqual(oParser.calculate().getValue().toFixed(3) - 0, 0.394, "Result of ACCRINT(DATE(2012,8,1),DATE(2013,3,1),DATE(2012,8,30),0.05,100,2,1)"); oParser = new parserFormula("ACCRINT(DATE(2012,8,1),DATE(2013,3,1),DATE(2012,8,31),0.05,100,2,1)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2012,8,1),DATE(2013,3,1),DATE(2012,8,31),0.05,100,2,1)"); assert.strictEqual(oParser.calculate().getValue().toFixed(3) - 0, 0.407, "Result of ACCRINT(DATE(2012,8,1),DATE(2013,3,1),DATE(2012,8,31),0.05,100,2,1)"); oParser = new parserFormula("ACCRINT(DATE(2012,8,1),DATE(2013,3,1),DATE(2012,9,1),0.05,100,2,1)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2012,8,1),DATE(2013,3,1),DATE(2012,9,1),0.05,100,2,1)"); assert.strictEqual(oParser.calculate().getValue().toFixed(3) - 0, 0.421, "Result of ACCRINT(DATE(2012,8,1),DATE(2013,3,1),DATE(2012,9,1),0.05,100,2,1)"); oParser = new parserFormula("ACCRINT(1,DATE(2013,3,1),DATE(2012,9,1),0.05,100,2,1)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(1,DATE(2013,3,1),DATE(2012,9,1),0.05,100,2,1)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of ACCRINT(1,DATE(2013,3,1),DATE(2012,9,1),0.05,100,2,1)"); ws.getRange2("A150").setValue("DATE(2014,2,1)"); ws.getRange2("A151").setValue("DATE(2014,3,1)"); oParser = new parserFormula("ACCRINT(DATE(2000,9,1),DATE(2014,3,1),DATE(2014,2,1),0.05,100,2,1,TRUE)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2000,9,1),DATE(2014,3,1),DATE(2014,2,1),0.05,100,2,1,TRUE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 67.07, "Result of ACCRINT(DATE(2000,9,1),DATE(2014,3,1),DATE(2014,2,1),0.05,100,2,1,TRUE)"); oParser = new parserFormula("ACCRINT(DATE(2000,9,1),DATE(2014,3,1),DATE(2014,2,1),0.05,100,2,1,FALSE)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2000,9,1),DATE(2014,3,1),DATE(2014,2,1),0.05,100,2,1,FALSE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 2.07, "Result of ACCRINT(DATE(2000,9,1),DATE(2014,3,1),DATE(2014,2,1),0.05,100,2,1,FALSE)"); oParser = new parserFormula("ACCRINT(DATE(2008,4,5),DATE(2008,8,31),DATE(2008,5,1),0.1,1000,2,0,TRUE)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2008,4,5),DATE(2008,8,31),DATE(2008,5,1),0.1,1000,2,0,TRUE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 7.22, "Result of ACCRINT(DATE(2008,4,5),DATE(2008,8,31),DATE(2008,5,1),0.1,1000,2,0,TRUE)"); oParser = new parserFormula("ACCRINT(DATE(2008,4,5),1,DATE(2008,5,1),0.1,1000,2,0,TRUE)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2008,4,5),1,DATE(2008,5,1),0.1,1000,2,0,TRUE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 7.22, "Result of ACCRINT(DATE(2008,4,5),1,DATE(2008,5,1),0.1,1000,2,0,TRUE)"); oParser = new parserFormula("ACCRINT(DATE(2008,4,5),500,DATE(2008,5,1),0.1,1000,2,0,TRUE)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2008,4,5),500,DATE(2008,5,1),0.1,1000,2,0,TRUE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 7.22, "Result of ACCRINT(DATE(2008,4,5),500,DATE(2008,5,1),0.1,1000,2,0,TRUE)"); oParser = new parserFormula("ACCRINT(DATE(2008,4,5),50000,DATE(2008,5,1),0.1,1000,2,0,TRUE)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2008,4,5),50000,DATE(2008,5,1),0.1,1000,2,0,TRUE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 7.22, "Result of ACCRINT(DATE(2008,4,5),50000,DATE(2008,5,1),0.1,1000,2,0,TRUE)"); oParser = new parserFormula("ACCRINT(DATE(2008,4,5),DATE(9999,12,31)+1,DATE(2008,5,1),0.1,1000,2,0,TRUE)", "A2", ws); assert.ok(oParser.parse(), "ACCRINT(DATE(2008,4,5),DATE(9999,12,31)+1,DATE(2008,5,1),0.1,1000,2,0,TRUE)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of ACCRINT(DATE(2008,4,5),DATE(9999,12,31)+1,DATE(2008,5,1),0.1,1000,2,0,TRUE)"); testArrayFormula2(assert, "ACCRINT", 6, 8, true); }); QUnit.test("Test: \"ACCRINTM\"", function (assert) { oParser = new parserFormula("ACCRINTM(DATE(2006,3,1),DATE(2006,5,1),0.1,1100,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 18.333333333333332); oParser = new parserFormula("ACCRINTM(DATE(2006,3,1),DATE(2006,5,1),0.1,,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 16.666666666666664); oParser = new parserFormula("ACCRINTM(DATE(2006,3,1),DATE(2006,5,1),0.1,)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 16.666666666666664); testArrayFormula2(assert, "ACCRINTM", 4, 5, true) }); QUnit.test("Test: \"AMORDEGRC\"", function (assert) { oParser = new parserFormula("AMORDEGRC(2400,DATE(2008,8,19),DATE(2008,12,31),300,1,0.15,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 776); oParser = new parserFormula("AMORDEGRC(2400,DATE(2008,8,19),DATE(2008,12,31),300,1,0.50,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("AMORDEGRC(2400,DATE(2008,8,19),DATE(2008,12,31),300,1,0.20,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 819); oParser = new parserFormula("AMORDEGRC(2400,DATE(2008,8,19),DATE(2008,12,31),300,1,0.33,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 972); testArrayFormula2(assert, "AMORDEGRC", 6, 7, true); }); QUnit.test("Test: \"AMORLINC\"", function (assert) { oParser = new parserFormula("AMORLINC(2400,DATE(2008,8,19),DATE(2008,12,31),300,1,0.15,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 360); oParser = new parserFormula("AMORLINC(2400,DATE(2008,8,19),DATE(2008,12,31),300,1,0.70,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1484); testArrayFormula2(assert, "AMORLINC", 6, 7, true); }); QUnit.test("Test: \"CUMIPMT\"", function (assert) { function cumipmt(fRate, nNumPeriods, fVal, nStartPer, nEndPer, nPayType) { var fRmz, fZinsZ; if (nStartPer < 1 || nEndPer < nStartPer || fRate <= 0.0 || nEndPer > nNumPeriods || nNumPeriods <= 0 || fVal <= 0.0 || (nPayType != 0 && nPayType != 1)) { return "#NUM!" } fRmz = _getPMT(fRate, nNumPeriods, fVal, 0.0, nPayType); fZinsZ = 0.0; if (nStartPer == 1) { if (nPayType <= 0) { fZinsZ = -fVal; } nStartPer++; } for (var i = nStartPer; i <= nEndPer; i++) { if (nPayType > 0) { fZinsZ += _getFV(fRate, i - 2, fRmz, fVal, 1) - fRmz; } else { fZinsZ += _getFV(fRate, i - 1, fRmz, fVal, 0); } } fZinsZ *= fRate; return fZinsZ; } oParser = new parserFormula("CUMIPMT(0.09/12,30*12,125000,1,1,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), cumipmt(0.09 / 12, 30 * 12, 125000, 1, 1, 0)); oParser = new parserFormula("CUMIPMT(0.09/12,30*12,125000,13,24,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), cumipmt(0.09 / 12, 30 * 12, 125000, 13, 24, 0)); testArrayFormula2(assert, "CUMIPMT", 6, 6, true); }); QUnit.test("Test: \"CUMPRINC\"", function (assert) { function cumpring(fRate, nNumPeriods, fVal, nStartPer, nEndPer, nPayType) { var fRmz, fKapZ; if (nStartPer < 1 || nEndPer < nStartPer || nEndPer < 1 || fRate <= 0 || nNumPeriods <= 0 || fVal <= 0 || (nPayType != 0 && nPayType != 1)) { return "#NUM!" } fRmz = _getPMT(fRate, nNumPeriods, fVal, 0.0, nPayType); fKapZ = 0.0; var nStart = nStartPer; var nEnd = nEndPer; if (nStart == 1) { if (nPayType <= 0) { fKapZ = fRmz + fVal * fRate; } else { fKapZ = fRmz; } nStart++; } for (var i = nStart; i <= nEnd; i++) { if (nPayType > 0) { fKapZ += fRmz - (_getFV(fRate, i - 2, fRmz, fVal, 1) - fRmz) * fRate; } else { fKapZ += fRmz - _getFV(fRate, i - 1, fRmz, fVal, 0) * fRate; } } return fKapZ } oParser = new parserFormula("CUMPRINC(0.09/12,30*12,125000,1,1,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), cumpring(0.09 / 12, 30 * 12, 125000, 1, 1, 0)); oParser = new parserFormula("CUMPRINC(0.09/12,30*12,-125000,1,1,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), cumpring(0.09 / 12, 30 * 12, -125000, 1, 1, 0)); oParser = new parserFormula("CUMPRINC(0.09/12,30*12,125000,13,24,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), cumpring(0.09 / 12, 30 * 12, 125000, 13, 24, 0)); testArrayFormula2(assert, "CUMPRINC", 6, 6, true); }); QUnit.test("Test: \"NOMINAL\"", function (assert) { function nominal(rate, np) { if (rate <= 0 || np < 1) { return "#NUM!" } return (Math.pow(rate + 1, 1 / np) - 1) * np; } oParser = new parserFormula("NOMINAL(0.053543,4)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), nominal(0.053543, 4)); oParser = new parserFormula("NOMINAL(0.053543,-4)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), nominal(0.053543, -4)); testArrayFormula2(assert, "NOMINAL", 2, 2, true); }); QUnit.test("Test: \"NOT\"", function (assert) { testArrayFormula2(assert, "NOT", 1, 1); }); QUnit.test("Test: \"FVSCHEDULE\"", function (assert) { function fvschedule(rate, shedList) { for (var i = 0; i < shedList.length; i++) { rate *= 1 + shedList[i] } return rate; } oParser = new parserFormula("FVSCHEDULE(1,{0.09,0.11,0.1})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), fvschedule(1, [0.09, 0.11, 0.1])); //testArrayFormula2(assert, "FVSCHEDULE", 2, 2, true, true); }); QUnit.test("Test: \"DISC\"", function (assert) { function disc(settlement, maturity, pr, redemption, basis) { if (settlement >= maturity || pr <= 0 || redemption <= 0 || basis < 0 || basis > 4) { return "#NUM!" } return (1.0 - pr / redemption) / AscCommonExcel.yearFrac(settlement, maturity, basis); } oParser = new parserFormula("DISC(DATE(2007,1,25),DATE(2007,6,15),97.975,100,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), disc(new cDate(2007, 0, 25), new cDate(2007, 5, 15), 97.975, 100, 1)); testArrayFormula2(assert, "DISC", 4, 5, true); }); QUnit.test("Test: \"DOLLARDE\"", function (assert) { function dollarde(fractionalDollar, fraction) { if (fraction < 0) { return "#NUM!"; } else if (fraction == 0) { return "#DIV/0!"; } var fInt = Math.floor(fractionalDollar), res = fractionalDollar - fInt; res /= fraction; res *= Math.pow(10, Math.ceil(Math.log(fraction) / Math.log(10))); res += fInt; return res; } oParser = new parserFormula("DOLLARDE(1.02,16)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), dollarde(1.02, 16)); oParser = new parserFormula("DOLLARDE(1.1,32)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), dollarde(1.1, 32)); testArrayFormula2(assert, "DOLLARDE", 2, 2, true); }); QUnit.test("Test: \"DOLLARFR\"", function (assert) { function dollarde(fractionalDollar, fraction) { if (fraction < 0) { return "#NUM!"; } else if (fraction == 0) { return "#DIV/0!"; } var fInt = Math.floor(fractionalDollar), res = fractionalDollar - fInt; res *= fraction; res *= Math.pow(10.0, -Math.ceil(Math.log(fraction) / Math.log(10))); res += fInt; return res; } oParser = new parserFormula("DOLLARFR(1.125,16)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), dollarde(1.125, 16)); oParser = new parserFormula("DOLLARFR(1.125,32)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), dollarde(1.125, 32)); testArrayFormula2(assert, "DOLLARFR", 2, 2, true); }); QUnit.test("Test: \"RECEIVED\"", function (assert) { function received(settlement, maturity, investment, discount, basis) { if (settlement >= maturity || investment <= 0 || discount <= 0 || basis < 0 || basis > 4) { return "#NUM!" } return investment / (1 - (discount * AscCommonExcel.yearFrac(settlement, maturity, basis))) } oParser = new parserFormula("RECEIVED(DATE(2008,2,15),DATE(2008,5,15),1000000,0.0575,2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), received(new cDate(2008, 1, 15), new cDate(2008, 4, 15), 1000000, 0.0575, 2)); testArrayFormula2(assert, "RECEIVED", 4, 5, true); }); QUnit.test("Test: \"RATE\"", function (assert) { function RateIteration(fNper, fPayment, fPv, fFv, fPayType, fGuess) { function approxEqual(a, b) { if (a == b) { return true; } var x = a - b; return (x < 0.0 ? -x : x) < ((a < 0.0 ? -a : a) * (1.0 / (16777216.0 * 16777216.0))); } var bValid = true, bFound = false, fX, fXnew, fTerm, fTermDerivation, fGeoSeries, fGeoSeriesDerivation; var nIterationsMax = 150, nCount = 0, fEpsilonSmall = 1.0E-14, SCdEpsilon = 1.0E-7; fFv = fFv - fPayment * fPayType; fPv = fPv + fPayment * fPayType; if (fNper == Math.round(fNper)) { fX = fGuess.fGuess; var fPowN, fPowNminus1; while (!bFound && nCount < nIterationsMax) { fPowNminus1 = Math.pow(1.0 + fX, fNper - 1.0); fPowN = fPowNminus1 * (1.0 + fX); if (approxEqual(Math.abs(fX), 0.0)) { fGeoSeries = fNper; fGeoSeriesDerivation = fNper * (fNper - 1.0) / 2.0; } else { fGeoSeries = (fPowN - 1.0) / fX; fGeoSeriesDerivation = fNper * fPowNminus1 / fX - fGeoSeries / fX; } fTerm = fFv + fPv * fPowN + fPayment * fGeoSeries; fTermDerivation = fPv * fNper * fPowNminus1 + fPayment * fGeoSeriesDerivation; if (Math.abs(fTerm) < fEpsilonSmall) { bFound = true; } else { if (approxEqual(Math.abs(fTermDerivation), 0.0)) { fXnew = fX + 1.1 * SCdEpsilon; } else { fXnew = fX - fTerm / fTermDerivation; } nCount++; bFound = (Math.abs(fXnew - fX) < SCdEpsilon); fX = fXnew; } } bValid = (fX >= -1.0); } else { fX = (fGuess.fGuest < -1.0) ? -1.0 : fGuess.fGuest; while (bValid && !bFound && nCount < nIterationsMax) { if (approxEqual(Math.abs(fX), 0.0)) { fGeoSeries = fNper; fGeoSeriesDerivation = fNper * (fNper - 1.0) / 2.0; } else { fGeoSeries = (Math.pow(1.0 + fX, fNper) - 1.0) / fX; fGeoSeriesDerivation = fNper * Math.pow(1.0 + fX, fNper - 1.0) / fX - fGeoSeries / fX; } fTerm = fFv + fPv * pow(1.0 + fX, fNper) + fPayment * fGeoSeries; fTermDerivation = fPv * fNper * Math.pow(1.0 + fX, fNper - 1.0) + fPayment * fGeoSeriesDerivation; if (Math.abs(fTerm) < fEpsilonSmall) { bFound = true; } else { if (approxEqual(Math.abs(fTermDerivation), 0.0)) { fXnew = fX + 1.1 * SCdEpsilon; } else { fXnew = fX - fTerm / fTermDerivation; } nCount++; bFound = (Math.abs(fXnew - fX) < SCdEpsilon); fX = fXnew; bValid = (fX >= -1.0); } } } fGuess.fGuess = fX; return bValid && bFound; } function rate(nper, pmt, pv, fv, type, quess) { if (fv === undefined) { fv = 0; } if (type === undefined) { type = 0; } if (quess === undefined) { quess = 0.1; } var res = {fGuess: 0}; if (RateIteration(nper, pmt, pv, fv, type, res)) { return res.fGuess; } return "#VALUE!" } oParser = new parserFormula("RATE(4*12,-200,8000)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(difBetween(oParser.calculate().getValue(), rate(4 * 12, -200, 8000)), true); oParser = new parserFormula("RATE(4*12,-200,8000)*12", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(difBetween(oParser.calculate().getValue(), rate(4 * 12, -200, 8000) * 12), true); testArrayFormula2(assert, "RATE", 3, 6, true); }); QUnit.test("Test: \"RRI\"", function (assert) { oParser = new parserFormula("RRI(96, 10000, 11000)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.0009933); oParser = new parserFormula("RRI(0, 10000, 11000)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("RRI(-10, 10000, 11000)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("RRI(10, 10000, -11000)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("RRI(1, 1, -1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -2); testArrayFormula2(assert, "RRI", 3, 3); }); QUnit.test("Test: \"INTRATE\"", function (assert) { function intrate(settlement, maturity, investment, redemption, basis) { if (settlement >= maturity || investment <= 0 || redemption <= 0 || basis < 0 || basis > 4) { return "#NUM!" } return ((redemption / investment) - 1) / AscCommonExcel.yearFrac(settlement, maturity, basis) } oParser = new parserFormula("INTRATE(DATE(2008,2,15),DATE(2008,5,15),1000000,1014420,2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), intrate(new cDate(2008, 1, 15), new cDate(2008, 4, 15), 1000000, 1014420, 2)); testArrayFormula2(assert, "INTRATE", 4, 5, true); }); QUnit.test("Test: \"TBILLEQ\"", function (assert) { function tbilleq(settlement, maturity, discount) { maturity = cDate.prototype.getDateFromExcel(maturity.getExcelDate() + 1); var d1 = settlement, d2 = maturity; var date1 = d1.getDate(), month1 = d1.getMonth(), year1 = d1.getFullYear(), date2 = d2.getDate(), month2 = d2.getMonth(), year2 = d2.getFullYear(); var nDiff = GetDiffDate360(date1, month1, year1, date2, month2, year2, true); if (settlement >= maturity || discount <= 0 || nDiff > 360) { return "#NUM!"; } return (365 * discount) / (360 - discount * nDiff); } oParser = new parserFormula("TBILLEQ(DATE(2008,3,31),DATE(2008,6,1),0.0914)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), tbilleq(new cDate(Date.UTC(2008, 2, 31)), new cDate(Date.UTC(2008, 5, 1)), 0.0914)); testArrayFormula2(assert, "TBILLEQ", 3, 3, true); }); QUnit.test("Test: \"TBILLPRICE\"", function (assert) { function tbillprice(settlement, maturity, discount) { maturity = cDate.prototype.getDateFromExcel(maturity.getExcelDate() + 1) var d1 = settlement var d2 = maturity var fFraction = AscCommonExcel.yearFrac(d1, d2, 0); if (fFraction - Math.floor(fFraction) == 0) { return "#NUM!"; } return 100 * (1 - discount * fFraction); } oParser = new parserFormula("TBILLPRICE(DATE(2008,3,31),DATE(2008,6,1),0.09)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), tbillprice(new cDate(Date.UTC(2008, 2, 31)), new cDate(Date.UTC(2008, 5, 1)), 0.09)); testArrayFormula2(assert, "TBILLPRICE", 3, 3, true); }); QUnit.test("Test: \"TBILLYIELD\"", function (assert) { let array; function tbillyield(settlement, maturity, pr) { var d1 = settlement; var d2 = maturity; var date1 = d1.getDate(), month1 = d1.getMonth(), year1 = d1.getFullYear(), date2 = d2.getDate(), month2 = d2.getMonth(), year2 = d2.getFullYear(); var nDiff = GetDiffDate360(date1, month1, year1, date2, month2, year2, true); nDiff++; if (settlement >= maturity || pr <= 0 || nDiff > 360) { return "#NUM!"; } return ((100 - pr) / pr) * (360 / nDiff); } oParser = new parserFormula("TBILLYIELD(DATE(2008,3,31),DATE(2008,6,1),98.45)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), tbillyield(new cDate(2008, 2, 31), new cDate(2008, 5, 1), 98.45)); // errs oParser = new parserFormula('TBILLYIELD(#N/A,2,2)', "A2", ws); assert.ok(oParser.parse(), 'TBILLYIELD(#N/A,2,2)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of TBILLYIELD(#N/A,2,2)'); oParser = new parserFormula('TBILLYIELD(1,#DIV/0!,2)', "A2", ws); assert.ok(oParser.parse(), 'TBILLYIELD(1,#DIV/0!,2)'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of TBILLYIELD(1,#DIV/0!,2)'); oParser = new parserFormula('TBILLYIELD(1,2,#NUM!)', "A2", ws); assert.ok(oParser.parse(), 'TBILLYIELD(1,2,#NUM!)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of TBILLYIELD(1,2,#NUM!)'); oParser = new parserFormula('TBILLYIELD(#N/A,2,#NUM!)', "A2", ws); assert.ok(oParser.parse(), 'TBILLYIELD(#N/A,2,#NUM!)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of TBILLYIELD(#N/A,2,#NUM!)'); // string oParser = new parserFormula('TBILLYIELD("1","2","2")', "A2", ws); assert.ok(oParser.parse(), 'TBILLYIELD("1","2","2")'); assert.strictEqual(oParser.calculate().getValue(), 17640, 'Result of TBILLYIELD("1","2","2")'); oParser = new parserFormula('TBILLYIELD("1s","2","2")', "A2", ws); assert.ok(oParser.parse(), 'TBILLYIELD("1s","2","2")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of TBILLYIELD("1s","2","2")'); oParser = new parserFormula('TBILLYIELD("1","2s","2")', "A2", ws); assert.ok(oParser.parse(), 'TBILLYIELD("1","2s","2")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of TBILLYIELD("1","2s","2")'); oParser = new parserFormula('TBILLYIELD("1","2","2s")', "A2", ws); assert.ok(oParser.parse(), 'TBILLYIELD("1","2","2s")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of TBILLYIELD("1","2","2s")'); // bool oParser = new parserFormula('TBILLYIELD(FALSE,2,2)', "A2", ws); assert.ok(oParser.parse(), 'TBILLYIELD(FALSE,2,2)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of TBILLYIELD(FALSE,2,2)'); oParser = new parserFormula('TBILLYIELD(TRUE,2,2)', "A2", ws); assert.ok(oParser.parse(), 'TBILLYIELD(TRUE,2,2)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of TBILLYIELD(TRUE,2,2)'); oParser = new parserFormula('TBILLYIELD(1,TRUE,2)', "A2", ws); assert.ok(oParser.parse(), 'TBILLYIELD(1,TRUE,2)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of TBILLYIELD(1,TRUE,2)'); oParser = new parserFormula('TBILLYIELD(1,2,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'TBILLYIELD(1,2,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of TBILLYIELD(1,2,TRUE)'); // array oParser = new parserFormula('TBILLYIELD(1,{1,2,3;2,3,4},{1,2,3;2,3,4})', "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("E106:H109").bbox); assert.ok(oParser.parse(), 'TBILLYIELD(1,{1,2,3;2,3,4},{1,2,3;2,3,4})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#NUM!", "Result of TBILLYIELD(1,{1,2,3;2,3,4},{1,2,3;2,3,4}) [0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 17640, "Result of TBILLYIELD(1,{1,2,3;2,3,4},{1,2,3;2,3,4}) [1,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 17640, "Result of TBILLYIELD(1,{1,2,3;2,3,4},{1,2,3;2,3,4}) [0,1]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 5820, "Result of TBILLYIELD(1,{1,2,3;2,3,4},{1,2,3;2,3,4}) [1,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 5820, "Result of TBILLYIELD(1,{1,2,3;2,3,4},{1,2,3;2,3,4}) [0,1]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 2880, "Result of TBILLYIELD(1,{1,2,3;2,3,4},{1,2,3;2,3,4}) [1,1]"); oParser = new parserFormula('TBILLYIELD(,2,2)', "A2", ws); assert.ok(oParser.parse(), 'TBILLYIELD(,2,2)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of TBILLYIELD(,2,2)'); oParser = new parserFormula('TBILLYIELD(1,,2)', "A2", ws); assert.ok(oParser.parse(), 'TBILLYIELD(1,,2)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of TBILLYIELD(1,,2)'); oParser = new parserFormula('TBILLYIELD(1,,)', "A2", ws); assert.ok(oParser.parse(), 'TBILLYIELD(1,,)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of TBILLYIELD(1,,)'); oParser = new parserFormula('TBILLYIELD(1,2,2)', "A2", ws); assert.ok(oParser.parse(), 'TBILLYIELD(1,2,2)'); assert.strictEqual(oParser.calculate().getValue(), 17640, 'Result of TBILLYIELD(1,2,2)'); oParser = new parserFormula('TBILLYIELD(1,3,2)', "A2", ws); assert.ok(oParser.parse(), 'TBILLYIELD(1,3,2)'); assert.strictEqual(oParser.calculate().getValue(), 8820, 'Result of TBILLYIELD(1,3,2)'); oParser = new parserFormula('TBILLYIELD(1,4,2)', "A2", ws); assert.ok(oParser.parse(), 'TBILLYIELD(1,4,2)'); assert.strictEqual(oParser.calculate().getValue(), 5880, 'Result of TBILLYIELD(1,4,2)'); oParser = new parserFormula('TBILLYIELD(1,5,2)', "A2", ws); assert.ok(oParser.parse(), 'TBILLYIELD(1,5,2)'); assert.strictEqual(oParser.calculate().getValue(), 4410, 'Result of TBILLYIELD(1,5,2)'); oParser = new parserFormula('TBILLYIELD(1,32,2)', "A2", ws); assert.ok(oParser.parse(), 'TBILLYIELD(1,32,2)'); assert.strictEqual(oParser.calculate().getValue().toFixed(4), "569.0323", 'Result of TBILLYIELD(1,32,2)'); oParser = new parserFormula('TBILLYIELD(1,33,2)', "A2", ws); assert.ok(oParser.parse(), 'TBILLYIELD(1,33,2)'); assert.strictEqual(oParser.calculate().getValue().toFixed(2), "551.25", 'Result of TBILLYIELD(1,33,2)'); oParser = new parserFormula('TBILLYIELD(1,59,2)', "A2", ws); assert.ok(oParser.parse(), 'TBILLYIELD(1,59,2)'); assert.strictEqual(oParser.calculate().getValue().toFixed(4), "304.1379", 'Result of TBILLYIELD(1,59,2)'); // oParser = new parserFormula('TBILLYIELD(1,60,2)', "A2", ws); // assert.ok(oParser.parse(), 'TBILLYIELD(1,60,2)'); // assert.strictEqual(oParser.calculate().getValue().toFixed(4), "298.9831", 'Result of TBILLYIELD(1,60,2)'); // oParser = new parserFormula('TBILLYIELD(1,61,2)', "A2", ws); // assert.ok(oParser.parse(), 'TBILLYIELD(1,61,2)'); // assert.strictEqual(oParser.calculate().getValue().toFixed(4), 294, 'Result of TBILLYIELD(1,61,2)'); // days between - 101 // oParser = new parserFormula('TBILLYIELD(500,601,2)', "A2", ws); // assert.ok(oParser.parse(), 'TBILLYIELD(500,601,2)'); // assert.strictEqual(oParser.calculate().getValue().toFixed(4), 174.6535, 'Result of TBILLYIELD(500,601,2)'); }); QUnit.test("Test: \"COUPDAYBS\"", function (assert) { function coupdaybs(settlement, maturity, frequency, basis) { basis = (basis !== undefined ? basis : 0); return _getcoupdaybs(settlement, maturity, frequency, basis) } oParser = new parserFormula("COUPDAYBS(DATE(2007,1,25),DATE(2008,11,15),2,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 71); oParser = new parserFormula("COUPDAYBS(DATE(2007,1,25),DATE(2008,11,15),2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), coupdaybs(new cDate(2007, 0, 25), new cDate(2008, 10, 15), 2)); testArrayFormula2(assert, "COUPDAYBS", 3, 4, true); }); QUnit.test("Test: \"COUPDAYS\"", function (assert) { function coupdays(settlement, maturity, frequency, basis) { basis = (basis !== undefined ? basis : 0); return _getcoupdays(settlement, maturity, frequency, basis) } oParser = new parserFormula("COUPDAYS(DATE(2007,1,25),DATE(2008,11,15),2,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), coupdays(new cDate(2007, 0, 25), new cDate(2008, 10, 15), 2, 1)); oParser = new parserFormula("COUPDAYS(DATE(2007,1,25),DATE(2008,11,15),2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), coupdays(new cDate(2007, 0, 25), new cDate(2008, 10, 15), 2)); testArrayFormula2(assert, "COUPDAYS", 3, 4, true); }); QUnit.test("Test: \"COUPDAYSNC\"", function (assert) { function coupdaysnc(settlement, maturity, frequency, basis) { basis = (basis !== undefined ? basis : 0); if ((basis != 0) && (basis != 4)) { _lcl_GetCoupncd(settlement, maturity, frequency); return _diffDate(settlement, maturity, basis); } return _getcoupdays(new cDate(settlement), new cDate(maturity), frequency, basis) - _getcoupdaybs(new cDate(settlement), new cDate(maturity), frequency, basis); } oParser = new parserFormula("COUPDAYSNC(DATE(2007,1,25),DATE(2008,11,15),2,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 110); oParser = new parserFormula("COUPDAYSNC(DATE(2007,1,25),DATE(2008,11,15),2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), coupdaysnc(new cDate(2007, 0, 25), new cDate(2008, 10, 15), 2)); testArrayFormula2(assert, "COUPDAYSNC", 3, 4, true); }); QUnit.test("Test: \"COUPNCD\"", function (assert) { function coupncd(settlement, maturity, frequency, basis) { basis = (basis !== undefined ? basis : 0); _lcl_GetCoupncd(settlement, maturity, frequency); return maturity.getExcelDate(); } let array; oParser = new parserFormula("COUPNCD(DATE(2007,1,25),DATE(2008,11,15),2,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), coupncd(new cDate(Date.UTC(2007, 0, 25)), new cDate(Date.UTC(2008, 10, 15)), 2, 1)); oParser = new parserFormula('COUPNCD(DATE(2012,8,31),DATE(2013,3,1),2)', "A2", ws); assert.ok(oParser.parse(), 'COUPNCD(DATE(2012,8,31),DATE(2013,3,1),2)'); assert.strictEqual(oParser.calculate().getValue(), 41153, 'Result of COUPNCD(DATE(2012,8,31),DATE(2013,3,1),2)'); oParser = new parserFormula('COUPNCD(DATE(2012,9,1),DATE(2013,3,1),2)', "A2", ws); assert.ok(oParser.parse(), 'COUPNCD(DATE(2012,9,1),DATE(2013,3,1),2)'); assert.strictEqual(oParser.calculate().getValue(), 41334, 'Result of COUPNCD(DATE(2012,9,1),DATE(2013,3,1),2)'); oParser = new parserFormula('COUPNCD(59,DATE(2013,3,1),2)', "A2", ws); assert.ok(oParser.parse(), 'COUPNCD(59,DATE(2013,3,1),2)'); assert.strictEqual(oParser.calculate().getValue(), 61, 'Result of COUPNCD(59,DATE(2013,3,1),2)'); oParser = new parserFormula('COUPNCD(60,DATE(2013,3,1),2)', "A2", ws); assert.ok(oParser.parse(), 'COUPNCD(60,DATE(2013,3,1),2)'); assert.strictEqual(oParser.calculate().getValue(), 61, 'Result of COUPNCD(60,DATE(2013,3,1),2)'); oParser = new parserFormula('COUPNCD(61,DATE(2013,3,1),2)', "A2", ws); assert.ok(oParser.parse(), 'COUPNCD(61,DATE(2013,3,1),2)'); assert.strictEqual(oParser.calculate().getValue(), 245, 'Result of COUPNCD(61,DATE(2013,3,1),2)'); oParser = new parserFormula("COUPNCD(#N/A,3743,2)", "A2", ws); assert.ok(oParser.parse(), "COUPNCD(#N/A,3743,2)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of COUPNCD(#N/A,3743,2)"); oParser = new parserFormula("COUPNCD(#N/A,#DIV/0!,2)", "A2", ws); assert.ok(oParser.parse(), "COUPNCD(#N/A,#DIV/0!,2)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of COUPNCD(#N/A,#DIV/0!,2)"); oParser = new parserFormula("COUPNCD(200,#DIV/0!,#N/A)", "A2", ws); assert.ok(oParser.parse(), "COUPNCD(200,#DIV/0!,#N/A)"); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "Result of COUPNCD(200,#DIV/0!,#N/A)"); oParser = new parserFormula("COUPNCD(200,37437,#N/A)", "A2", ws); assert.ok(oParser.parse(), "COUPNCD(200,37437,#N/A)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of COUPNCD(200,37437,#N/A)"); oParser = new parserFormula('COUPNCD("1","2","1")', "A2", ws); assert.ok(oParser.parse(), 'COUPNCD("1","2","1")'); assert.strictEqual(oParser.calculate().getValue(), 2, 'Result of COUPNCD("1","2","1")'); oParser = new parserFormula('COUPNCD("1s",2,1)', "A2", ws); assert.ok(oParser.parse(), 'COUPNCD("1s",2,1)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of COUPNCD("1s",2,1)'); oParser = new parserFormula('COUPNCD("1","2s","1")', "A2", ws); assert.ok(oParser.parse(), 'COUPNCD("1","2s","1")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of COUPNCD("1","2s","1")'); oParser = new parserFormula('COUPNCD("1","2","1s")', "A2", ws); assert.ok(oParser.parse(), 'COUPNCD("1","2","1s")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of COUPNCD("1","2","1s")'); oParser = new parserFormula('COUPNCD(61,61,1)', "A2", ws); assert.ok(oParser.parse(), 'COUPNCD(61,61,1)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of COUPNCD(61,61,1)'); oParser = new parserFormula('COUPNCD(61,61,2)', "A2", ws); assert.ok(oParser.parse(), 'COUPNCD(61,61,2)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of COUPNCD(61,61,2)'); oParser = new parserFormula('COUPNCD(61,61,4)', "A2", ws); assert.ok(oParser.parse(), 'COUPNCD(61,61,4)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of COUPNCD(61,61,4)'); oParser = new parserFormula('COUPNCD(61,61,4)', "A2", ws); assert.ok(oParser.parse(), 'COUPNCD(61,61,4)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of COUPNCD(61,61,4)'); oParser = new parserFormula('COUPNCD(,9222,1)', "A2", ws); assert.ok(oParser.parse(), 'COUPNCD(,9222,1)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of COUPNCD(,9222,1)'); oParser = new parserFormula('COUPNCD(0,9222,1)', "A2", ws); assert.ok(oParser.parse(), 'COUPNCD(0,9222,1)'); assert.strictEqual(oParser.calculate().getValue(), 91, 'Result of COUPNCD(0,9222,1)'); oParser = new parserFormula('COUPNCD(0,,1)', "A2", ws); assert.ok(oParser.parse(), 'COUPNCD(0,,1)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of COUPNCD(0,,1)'); oParser = new parserFormula('COUPNCD(0,1,1)', "A2", ws); assert.ok(oParser.parse(), 'COUPNCD(0,1,1)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of COUPNCD(0,1,1)'); oParser = new parserFormula('COUPNCD(1060,9222,)', "A2", ws); assert.ok(oParser.parse(), 'COUPNCD(1060,9222,)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of COUPNCD(1060,9222,)'); oParser = new parserFormula('COUPNCD(1060,9222,{0,1,2,3,4})', "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("T9:X15").bbox); assert.ok(oParser.parse(), 'COUPNCD(1060,9222,{0,1,2,3,4})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#NUM!", 'Result of COUPNCD(1060,9222,{0,1,2,3,4})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1186, 'Result of COUPNCD(1060,9222,{0,1,2,3,4})[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 1186, 'Result of COUPNCD(1060,9222,{0,1,2,3,4})[0,2]'); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "#NUM!", 'Result of COUPNCD(1060,9222,{0,1,2,3,4})[0,3]'); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), 1096, 'Result of COUPNCD(1060,9222,{0,1,2,3,4})[0,4]'); testArrayFormula2(assert, "COUPNCD", 3, 4, true); }); QUnit.test("Test: \"COUPNUM\"", function (assert) { oParser = new parserFormula("COUPNUM(DATE(2007,1,25),DATE(2008,11,15),2,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), _coupnum(new cDate(2007, 0, 25), new cDate(2008, 10, 15), 2, 1)); testArrayFormula2(assert, "COUPNUM", 3, 4, true); }); QUnit.test("Test: \"COUPPCD\"", function (assert) { function couppcd(settlement, maturity, frequency, basis) { basis = (basis !== undefined ? basis : 0); _lcl_GetCouppcd(settlement, maturity, frequency); return maturity.getExcelDate(); } oParser = new parserFormula("COUPPCD(DATE(2007,1,25),DATE(2008,11,15),2,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), couppcd(new cDate(Date.UTC(2007, 0, 25)), new cDate(Date.UTC(2008, 10, 15)), 2, 1)); oParser = new parserFormula("COUPPCD({1},39691,2)", "A2", ws); assert.ok(oParser.parse(), "COUPPCD({1},39691,2)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of COUPPCD({1},39691,2)"); // oParser = new parserFormula("COUPPCD(59,39691,2)", "A2", ws); // assert.ok(oParser.parse(), "COUPPCD(59,39691,2)"); // assert.strictEqual(oParser.calculate().getValue(), 59, "Result of COUPPCD(59,39691,2)"); // problem with date 29/1/1900(59) oParser = new parserFormula("COUPPCD(60,44261,2)", "A2", ws); assert.ok(oParser.parse(), "COUPPCD(60,44261,2)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of COUPPCD(60,44261,2)"); oParser = new parserFormula("COUPPCD(91,37530,2)", "A2", ws); assert.ok(oParser.parse(), "COUPPCD(91,37530,2)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of COUPPCD(91,37530,2)"); oParser = new parserFormula("COUPPCD(91,37529,2)", "A2", ws); assert.ok(oParser.parse(), "COUPPCD(91,37529,2)"); assert.strictEqual(oParser.calculate().getValue(), 91, "Result of COUPPCD(91,37529,2)"); oParser = new parserFormula("COUPPCD(59,37438,2)", "A2", ws); assert.ok(oParser.parse(), "COUPPCD(59,37438,2)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of COUPPCD(59,37438,2)"); oParser = new parserFormula("COUPPCD(59,37437,2)", "A2", ws); assert.ok(oParser.parse(), "COUPPCD(59,37437,2)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of COUPPCD(59,37437,2)"); oParser = new parserFormula("COUPPCD(182,3743,2)", "A2", ws); assert.ok(oParser.parse(), "COUPPCD(182,3743,2)"); assert.strictEqual(oParser.calculate().getValue(), 91, "Result of COUPPCD(182,3743,2)"); oParser = new parserFormula("COUPPCD(181,37437,2)", "A2", ws); assert.ok(oParser.parse(), "COUPPCD(181,37437,2)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of COUPPCD(181,37437,2)"); oParser = new parserFormula("COUPPCD(DATE(2012,8,31),DATE(2013,3,1),2)", "A2", ws); assert.ok(oParser.parse(), "COUPPCD(DATE(2012,8,31),DATE(2013,3,1),2)"); assert.strictEqual(oParser.calculate().getValue(), 40969, "Result of COUPPCD(DATE(2012,8,31),DATE(2013,3,1),2)"); oParser = new parserFormula("COUPPCD(DATE(2012,9,1),DATE(2013,3,1),2)", "A2", ws); assert.ok(oParser.parse(), "COUPPCD(DATE(2012,9,1),DATE(2013,3,1),2)"); assert.strictEqual(oParser.calculate().getValue(), 41153, "Result of COUPPCD(DATE(2012,9,1),DATE(2013,3,1),2)"); oParser = new parserFormula("COUPPCD(#N/A,3743,2)", "A2", ws); assert.ok(oParser.parse(), "COUPPCD(#N/A,3743,2)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of COUPPCD(#N/A,3743,2)"); oParser = new parserFormula("COUPPCD(#N/A,#DIV/0!,2)", "A2", ws); assert.ok(oParser.parse(), "COUPPCD(#N/A,#DIV/0!,2)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of COUPPCD(#N/A,#DIV/0!,2)"); oParser = new parserFormula("COUPPCD(200,#DIV/0!,#N/A)", "A2", ws); assert.ok(oParser.parse(), "COUPPCD(200,#DIV/0!,#N/A)"); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", "Result of COUPPCD(200,#DIV/0!,#N/A)"); oParser = new parserFormula("COUPPCD(200,37437,#N/A)", "A2", ws); assert.ok(oParser.parse(), "COUPPCD(200,37437,#N/A)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of COUPPCD(200,37437,#N/A)"); oParser = new parserFormula('COUPPCD("200",37437,2)', "A2", ws); assert.ok(oParser.parse(), 'COUPPCD("200",37437,2)'); assert.strictEqual(oParser.calculate().getValue(), 182, 'Result of COUPPCD("200",37437,2)'); oParser = new parserFormula('COUPPCD("200s",37437,2)', "A2", ws); assert.ok(oParser.parse(), 'COUPPCD("200s",37437,2)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of COUPPCD("200s",37437,2)'); oParser = new parserFormula('COUPPCD("200","37437s",2)', "A2", ws); assert.ok(oParser.parse(), 'COUPPCD("200","37437s",2)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of COUPPCD("200","37437s",2)'); oParser = new parserFormula('COUPPCD("200","37437","2s")', "A2", ws); assert.ok(oParser.parse(), 'COUPPCD("200","37437","2s")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of COUPPCD("200","37437","2s")'); oParser = new parserFormula('COUPPCD(200,37437,0)', "A2", ws); assert.ok(oParser.parse(), 'COUPPCD(200,37437,0)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of COUPPCD(200,37437,0)'); oParser = new parserFormula('COUPPCD(200,37437,2,0)', "A2", ws); assert.ok(oParser.parse(), 'COUPPCD(200,37437,2,0)'); assert.strictEqual(oParser.calculate().getValue(), 182, 'Result of COUPPCD(200,37437,2,0)'); oParser = new parserFormula('COUPPCD(200,37437,2,1)', "A2", ws); assert.ok(oParser.parse(), 'COUPPCD(200,37437,2,1)'); assert.strictEqual(oParser.calculate().getValue(), 182, 'Result of COUPPCD(200,37437,2,1)'); oParser = new parserFormula('COUPPCD(200,37437,2,2)', "A2", ws); assert.ok(oParser.parse(), 'COUPPCD(200,37437,2,2)'); assert.strictEqual(oParser.calculate().getValue(), 182, 'Result of COUPPCD(200,37437,2,2)'); oParser = new parserFormula('COUPPCD(200,37437,2,3)', "A2", ws); assert.ok(oParser.parse(), 'COUPPCD(200,37437,2,3)'); assert.strictEqual(oParser.calculate().getValue(), 182, 'Result of COUPPCD(200,37437,2,3)'); oParser = new parserFormula('COUPPCD(200,37437,2,4)', "A2", ws); assert.ok(oParser.parse(), 'COUPPCD(200,37437,2,4)'); assert.strictEqual(oParser.calculate().getValue(), 182, 'Result of COUPPCD(200,37437,2,4)'); oParser = new parserFormula('COUPPCD(200,37437,2,5)', "A2", ws); assert.ok(oParser.parse(), 'COUPPCD(200,37437,2,5)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of COUPPCD(200,37437,2,5)'); testArrayFormula2(assert, "COUPPCD", 3, 4, true); }); QUnit.test("Test: \"CONVERT\"", function (assert) { oParser = new parserFormula('CONVERT(68, "F", "C")', "A2", ws); assert.ok(oParser.parse(), 'CONVERT(68, "F", "C")'); assert.strictEqual(oParser.calculate().getValue(), 20, 'CONVERT(68, "F", "C")'); oParser = new parserFormula('CONVERT(2.5, "ft", "sec")', "A2", ws); assert.ok(oParser.parse(), 'CONVERT(2.5, "ft", "sec")'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'CONVERT(2.5, "ft", "sec")'); oParser = new parserFormula('CONVERT(CONVERT(100,"ft","m"),"ft","m")', "A2", ws); assert.ok(oParser.parse(), 'CONVERT(CONVERT(100,"ft","m"),"ft","m")'); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 9.290304, 'CONVERT(CONVERT(100,"ft","m"),"ft","m")'); oParser = new parserFormula('CONVERT(7,"bit","byte")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(3) - 0, 0.875); oParser = new parserFormula('CONVERT(7,"admkn","kn")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(14) - 0, 6.99999939524838); oParser = new parserFormula('CONVERT(7,"admkn","m/s")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 3.6011108); oParser = new parserFormula('CONVERT(7,"admkn","mph")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 8.0554554); oParser = new parserFormula('CONVERT(7,"m/h","m/sec")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.0019444); oParser = new parserFormula('CONVERT(7,"m/hr","mph")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.0043496); oParser = new parserFormula('CONVERT(7,"m","mi")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.0043496); oParser = new parserFormula('CONVERT(7,"m","Pica")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 19842.5196850); oParser = new parserFormula('CONVERT(7,"m","pica")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 1653.5433071); oParser = new parserFormula('CONVERT(7,"Nmi","pica")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 3062362.2047251); oParser = new parserFormula('CONVERT(7,"yr","day")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2556.75); oParser = new parserFormula('CONVERT(7,"yr","min")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3681720); oParser = new parserFormula('CONVERT(7,"day","min")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 10080); oParser = new parserFormula('CONVERT(7,"hr","sec")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 25200); oParser = new parserFormula('CONVERT(7,"min","sec")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 420); oParser = new parserFormula('CONVERT(7,"Pa","mmHg")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.0525043); oParser = new parserFormula('CONVERT(7,"Pa","psi")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.0010153); oParser = new parserFormula('CONVERT(7,"Pa","Torr")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.0525045); oParser = new parserFormula('CONVERT(7,"g","sg")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.0004797); oParser = new parserFormula('CONVERT(7,"g","lbm")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.0154324); oParser = new parserFormula('CONVERT(1, "lbm", "kg")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(7) - 0, 0.4535924); oParser = new parserFormula('CONVERT(1, "lbm", "mg")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(0) - 0, 453592); oParser = new parserFormula('CONVERT(1, "klbm", "mg")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); // for bug 63740 oParser = new parserFormula('CONVERT(1,"m","mm")', "A2", ws); assert.ok(oParser.parse(), 'CONVERT(1,"m","mm")'); assert.strictEqual(oParser.calculate().getValue(), 1000, 'Result of CONVERT(1,"m","mm")'); oParser = new parserFormula('CONVERT(1,"m2","mm2")', "A2", ws); assert.ok(oParser.parse(), 'CONVERT(1,"m2","mm2")'); assert.strictEqual(oParser.calculate().getValue(), 1000000, 'Result of CONVERT(1,"m2","mm"2)'); oParser = new parserFormula('CONVERT(1,"m3","mm3")', "A2", ws); assert.ok(oParser.parse(), 'CONVERT(1,"m3","mm3")'); assert.strictEqual(oParser.calculate().getValue().toFixed(), "1000000000", 'Result of CONVERT(1,"m3","mm3")'); oParser = new parserFormula('CONVERT(1,"m","cm")', "A2", ws); assert.ok(oParser.parse(), 'CONVERT(1,"m","cm")'); assert.strictEqual(oParser.calculate().getValue(), 100, 'Result of CONVERT(1,"m","cm")'); oParser = new parserFormula('CONVERT(1,"m2","cm2")', "A2", ws); assert.ok(oParser.parse(), 'CONVERT(1,"m2","cm2")'); assert.strictEqual(oParser.calculate().getValue(), 10000, 'Result of CONVERT(1,"m2","cm"2)'); oParser = new parserFormula('CONVERT(1,"m3","cm3")', "A2", ws); assert.ok(oParser.parse(), 'CONVERT(1,"m3","cm3")'); assert.strictEqual(oParser.calculate().getValue().toFixed(), "1000000", 'Result of CONVERT(1,"m3","cm3")'); oParser = new parserFormula('CONVERT(1,"cm","m")', "A2", ws); assert.ok(oParser.parse(), 'CONVERT(1,"cm","m")'); assert.strictEqual(oParser.calculate().getValue(), 0.01, 'Result of CONVERT(1,"cm","m")'); oParser = new parserFormula('CONVERT(1,"cm2","m2")', "A2", ws); assert.ok(oParser.parse(), 'CONVERT(1,"cm2","m2")'); assert.strictEqual(oParser.calculate().getValue(), 0.0001, 'Result of CONVERT(1,"cm2","m2")'); oParser = new parserFormula('CONVERT(1,"cm3","m3")', "A2", ws); assert.ok(oParser.parse(), 'CONVERT(1,"cm3","m3")'); assert.strictEqual(oParser.calculate().getValue().toFixed(6), "0.000001", 'Result of CONVERT(1,"cm3","m3")'); oParser = new parserFormula('CONVERT(1,"m","m")', "A2", ws); assert.ok(oParser.parse(), 'CONVERT(1,"m","m")'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of CONVERT(1,"m","m")'); oParser = new parserFormula('CONVERT(1,"m2","m2")', "A2", ws); assert.ok(oParser.parse(), 'CONVERT(1,"m2","m2")'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of CONVERT(1,"m2","m2")'); oParser = new parserFormula('CONVERT(1,"m3","m3")', "A2", ws); assert.ok(oParser.parse(), 'CONVERT(1,"m3","m3")'); assert.strictEqual(oParser.calculate().getValue(), 1, 'Result of CONVERT(1,"m3","m3")'); oParser = new parserFormula('CONVERT(1,"m^1","cm^1")', "A2", ws); assert.ok(oParser.parse(), 'CONVERT(1,"m^1","cm^1")'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of CONVERT(1,"m^1","cm^1")'); oParser = new parserFormula('CONVERT(1,"m^2","cm^2")', "A2", ws); assert.ok(oParser.parse(), 'CONVERT(1,"m^2","cm^2")'); assert.strictEqual(oParser.calculate().getValue(), 10000, 'Result of CONVERT(1,"m^2","cm^2")'); oParser = new parserFormula('CONVERT(1,"m^3","cm^3")', "A2", ws); assert.ok(oParser.parse(), 'CONVERT(1,"m^3","cm^3")'); assert.strictEqual(oParser.calculate().getValue().toFixed(), "1000000", 'Result of CONVERT(1,"m^3","cm^3")'); testArrayFormula2(assert, "CONVERT", 3, 3, true); }); QUnit.test("Test: \"PRICE\"", function (assert) { oParser = new parserFormula("PRICE(DATE(2008,2,15),DATE(2017,11,15),0.0575,0.065,100,2,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), _getprice(new cDate(Date.UTC(2008, 1, 15)), new cDate(Date.UTC(2017, 10, 15)), 0.0575, 0.065, 100, 2, 0)); testArrayFormula2(assert, "PRICE", 6, 7, true); }); QUnit.test("Test: \"PRICEDISC\"", function (assert) { function pricedisc(settl, matur, discount, redemption, basis) { return redemption * (1.0 - discount * _getdiffdate(settl, matur, basis)); } oParser = new parserFormula("PRICEDISC(DATE(2008,2,16),DATE(2008,3,1),0.0525,100,2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), pricedisc(new cDate(2008, 1, 16), new cDate(2008, 2, 1), 0.0525, 100, 2)); testArrayFormula2(assert, "PMT", 4, 5, true); }); QUnit.test("Test: \"PRICEMAT\"", function (assert) { function pricemat(settl, matur, iss, rate, yld, basis) { var fIssMat = _yearFrac(new cDate(iss), new cDate(matur), basis); var fIssSet = _yearFrac(new cDate(iss), new cDate(settl), basis); var fSetMat = _yearFrac(new cDate(settl), new cDate(matur), basis); var res = 1.0 + fIssMat * rate; res /= 1.0 + fSetMat * yld; res -= fIssSet * rate; res *= 100.0; return res; } oParser = new parserFormula("PRICEMAT(DATE(2008,2,15),DATE(2008,4,13),DATE(2007,11,11),0.061,0.061,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), pricemat(new cDate(2008, 1, 15), new cDate(2008, 3, 13), new cDate(2007, 10, 11), 0.061, 0.061, 0)); testArrayFormula2(assert, "PRICEMAT", 5, 6, true); }); QUnit.test("Test: \"YIELD\"", function (assert) { oParser = new parserFormula("YIELD(DATE(2008,2,15),DATE(2016,11,15),0.0575,95.04287,100,2,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), _getYield(new cDate(Date.UTC(2008, 1, 15)), new cDate(Date.UTC(2016, 10, 15)), 0.0575, 95.04287, 100, 2, 0)); testArrayFormula2(assert, "YIELD", 6, 7, true); }); QUnit.test("Test: \"YIELDDISC\"", function (assert) { function yielddisc(settlement, maturity, pr, redemption, basis) { var fRet = (redemption / pr) - 1.0; fRet /= _yearFrac(settlement, maturity, basis); return fRet; } oParser = new parserFormula("YIELDDISC(DATE(2008,2,16),DATE(2008,3,1),99.795,100,2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), yielddisc(new cDate(2008, 1, 16), new cDate(2008, 2, 1), 99.795, 100, 2)); testArrayFormula2(assert, "YIELDDISC", 4, 5, true); }); QUnit.test("Test: \"YIELDMAT\"", function (assert) { oParser = new parserFormula("YIELDMAT(DATE(2008,3,15),DATE(2008,11,3),DATE(2007,11,8),0.0625,100.0123,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), _getyieldmat(new cDate(2008, 2, 15), new cDate(2008, 10, 3), new cDate(2007, 10, 8), 0.0625, 100.0123, 0)); testArrayFormula2(assert, "YIELDMAT", 5, 6, true); }); QUnit.test("Test: \"ODD\"", function (assert) { oParser = new parserFormula("ODD(1.5)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); oParser = new parserFormula("ODD(3)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); oParser = new parserFormula("ODD(2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); oParser = new parserFormula("ODD(-1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -1); oParser = new parserFormula("ODD(-2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -3); testArrayFormula(assert, "ODD"); }); QUnit.test("Test: \"ODDLPRICE\"", function (assert) { function oddlprice(settlement, maturity, last_interest, rate, yld, redemption, frequency, basis) { var fDCi = _yearFrac(last_interest, maturity, basis) * frequency; var fDSCi = _yearFrac(settlement, maturity, basis) * frequency; var fAi = _yearFrac(last_interest, settlement, basis) * frequency; var res = redemption + fDCi * 100.0 * rate / frequency; res /= fDSCi * yld / frequency + 1.0; res -= fAi * 100.0 * rate / frequency; return res; } oParser = new parserFormula("ODDLPRICE(DATE(2008,11,11),DATE(2021,3,1),DATE(2008,10,15),0.0785,0.0625,100,2,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), oddlprice(new cDate(Date.UTC(2008, 10, 11)), new cDate(Date.UTC(2021, 2, 1)), new cDate(Date.UTC(2008, 9, 15)), 0.0785, 0.0625, 100, 2, 1)); testArrayFormula2(assert, "ODDLPRICE", 7, 8, true); }); QUnit.test("Test: \"ODDLYIELD\"", function (assert) { function oddlyield(settlement, maturity, last_interest, rate, pr, redemption, frequency, basis) { var fDCi = _yearFrac(last_interest, maturity, basis) * frequency; var fDSCi = _yearFrac(settlement, maturity, basis) * frequency; var fAi = _yearFrac(last_interest, settlement, basis) * frequency; var res = redemption + fDCi * 100.0 * rate / frequency; res /= pr + fAi * 100.0 * rate / frequency; res--; res *= frequency / fDSCi; return res; } oParser = new parserFormula("ODDLYIELD(DATE(2008,11,11),DATE(2021,3,1),DATE(2008,10,15),0.0575,84.5,100,2,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), oddlyield(new cDate(2008, 10, 11), new cDate(2021, 2, 1), new cDate(2008, 9, 15), 0.0575, 84.5, 100, 2, 0)); testArrayFormula2(assert, "ODDLYIELD", 7, 8, true); }); QUnit.test("Test: \"DURATION\"", function (assert) { oParser = new parserFormula("DURATION(DATE(2008,1,1),DATE(2016,1,1),0.08,0.09,2,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), _duration(new cDate(Date.UTC(2008, 0, 1)), new cDate(Date.UTC(2016, 0, 1)), 0.08, 0.09, 2, 1)); oParser = new parserFormula("DURATION(DATE(2008,1,1),DATE(2016,1,1),-0.08,0.09,2,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), _duration(new cDate(Date.UTC(2008, 0, 1)), new cDate(Date.UTC(2016, 0, 1)), -0.08, 0.09, 2, 1)); oParser = new parserFormula("DURATION(DATE(2008,1,1),DATE(2016,1,1),-0.08,0.09,5,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), _duration(new cDate(Date.UTC(2008, 0, 1)), new cDate(Date.UTC(2016, 0, 1)), -0.08, 0.09, 5, 1)); testArrayFormula2(assert, "DURATION", 5, 6, true); }); QUnit.test("Test: \"MDURATION\"", function (assert) { function mduration(settl, matur, coupon, yld, frequency, basis) { return _duration(settl, matur, coupon, yld, frequency, basis) / (1 + yld / frequency); } oParser = new parserFormula("MDURATION(DATE(2008,1,1),DATE(2016,1,1),0.08,0.09,2,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), mduration(new cDate(Date.UTC(2008, 0, 1)), new cDate(Date.UTC(2016, 0, 1)), 0.08, 0.09, 2, 1)); testArrayFormula2(assert, "MDURATION", 5, 6, true); }); QUnit.test("Test: \"MDETERM\"", function (assert) { ws.getRange2("A2").setValue("1"); ws.getRange2("A3").setValue("1"); ws.getRange2("A4").setValue("1"); ws.getRange2("A5").setValue("7"); ws.getRange2("B2").setValue("3"); ws.getRange2("B3").setValue("3"); ws.getRange2("B4").setValue("1"); ws.getRange2("B5").setValue("3"); ws.getRange2("C2").setValue("8"); ws.getRange2("C3").setValue("6"); ws.getRange2("C4").setValue("1"); ws.getRange2("C5").setValue("10"); ws.getRange2("D2").setValue("5"); ws.getRange2("D3").setValue("1"); ws.getRange2("D4").setValue("0"); ws.getRange2("D5").setValue("2"); oParser = new parserFormula("MDETERM(A2:D5)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 88); oParser = new parserFormula("MDETERM({3,6,1;1,1,0;3,10,2})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("MDETERM({3,6;1,1})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -3); oParser = new parserFormula("MDETERM({1,3,8,5;1,3,6,1})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("MDETERM({1,2;10,11})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -9); let ws2 = wb.createWorksheet(0, "Sheet2"); let ws2Name = ws2.getName(); ws2.getRange2("A1").setValue("1"); ws2.getRange2("A2").setValue("2"); ws2.getRange2("B1").setValue("3"); ws2.getRange2("B2").setValue("4"); oParser = new parserFormula("MDETERM("+ws2Name+"!A1:B2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), -2); }); QUnit.test("Test: \"SYD\"", function (assert) { function syd(cost, salvage, life, per) { if (life == -1 || life == 0) { return "#NUM!"; } var res = 2; res *= cost - salvage; res *= life + 1 - per; res /= (life + 1) * life; return res < 0 ? "#NUM!" : res; } oParser = new parserFormula("SYD(30000,7500,10,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), syd(30000, 7500, 10, 1)); oParser = new parserFormula("SYD(30000,7500,-1,10)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), syd(30000, 7500, -1, 10)); oParser = new parserFormula("SYD(30000,7500,-10,10)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), syd(30000, 7500, -10, 10)); testArrayFormula2(assert, "SYD", 4, 4); }); QUnit.test("Test: \"PPMT\"", function (assert) { function ppmt(rate, per, nper, pv, fv, type) { if (fv == undefined) { fv = 0; } if (type == undefined) { type = 0; } var fRmz = _getPMT(rate, nper, pv, fv, type); return fRmz - _getIPMT(rate, per, pv, type, fRmz); } oParser = new parserFormula("PPMT(0.1/12,1,2*12,2000)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ppmt(0.1 / 12, 1, 2 * 12, 2000)); oParser = new parserFormula("PPMT(0.08,10,10,200000)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ppmt(0.08, 10, 10, 200000)); testArrayFormula2(assert, "PPMT", 4, 6); }); QUnit.test("Test: \"MIRR\"", function (assert) { function mirr(valueArray, fRate1_invest, fRate1_reinvest) { fRate1_invest = fRate1_invest + 1; fRate1_reinvest = fRate1_reinvest + 1; var fNPV_reinvest = 0, fPow_reinvest = 1, fNPV_invest = 0, fPow_invest = 1, fCellValue, wasNegative = false, wasPositive = false; for (var i = 0; i < valueArray.length; i++) { fCellValue = valueArray[i]; if (fCellValue > 0) { wasPositive = true; fNPV_reinvest += fCellValue * fPow_reinvest; } else if (fCellValue < 0) { wasNegative = true; fNPV_invest += fCellValue * fPow_invest; } fPow_reinvest /= fRate1_reinvest; fPow_invest /= fRate1_invest; } if (!(wasNegative && wasPositive)) { return "#DIV/0!"; } var fResult = -fNPV_reinvest / fNPV_invest; fResult *= Math.pow(fRate1_reinvest, valueArray.length - 1); fResult = Math.pow(fResult, 1 / (valueArray.length - 1)); return fResult - 1; } oParser = new parserFormula("MIRR({-120000,39000,30000,21000,37000,46000},0.1,0.12)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), mirr([-120000, 39000, 30000, 21000, 37000, 46000], 0.1, 0.12)); oParser = new parserFormula("MIRR({-120000,39000,30000,21000},0.1,0.12)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), mirr([-120000, 39000, 30000, 21000], 0.1, 0.12)); oParser = new parserFormula("MIRR({-120000,39000,30000,21000,37000,46000},0.1,0.14)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), mirr([-120000, 39000, 30000, 21000, 37000, 46000], 0.1, 0.14)); //testArrayFormula2(assert, "MIRR", 3, 3, null, true); }); QUnit.test("Test: \"IPMT\"", function (assert) { function ipmt(rate, per, nper, pv, fv, type) { if (fv == undefined) { fv = 0; } if (type == undefined) { type = 0; } var res = AscCommonExcel.getPMT(rate, nper, pv, fv, type); res = AscCommonExcel.getIPMT(rate, per, pv, type, res); return res; } oParser = new parserFormula("IPMT(0.1/12,1*3,3,8000)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ipmt(0.1 / 12, 1 * 3, 3, 8000)); oParser = new parserFormula("IPMT(0.1,3,3,8000)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ipmt(0.1, 3, 3, 8000)); testArrayFormula2(assert, "IPMT", 4, 6); }); QUnit.test("Test: \"DB\"", function (assert) { function db(cost, salvage, life, period, month) { if (salvage >= cost) { return this.value = new AscCommonExcel.cNumber(0); } if (month < 1 || month > 12 || salvage < 0 || life <= 0 || period < 0 || life + 1 < period || cost < 0) { return "#NUM!"; } var nAbRate = 1 - Math.pow(salvage / cost, 1 / life); nAbRate = Math.floor((nAbRate * 1000) + 0.5) / 1000; var nErsteAbRate = cost * nAbRate * month / 12; var res = 0; if (Math.floor(period) == 1) { res = nErsteAbRate; } else { var nSummAbRate = nErsteAbRate, nMin = life; if (nMin > period) { nMin = period; } var iMax = Math.floor(nMin); for (var i = 2; i <= iMax; i++) { res = (cost - nSummAbRate) * nAbRate; nSummAbRate += res; } if (period > life) { res = ((cost - nSummAbRate) * nAbRate * (12 - month)) / 12; } } return res } oParser = new parserFormula("DB(1000000,100000,6,1,7)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), db(1000000, 100000, 6, 1, 7)); oParser = new parserFormula("DB(1000000,100000,6,2,7)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), db(1000000, 100000, 6, 2, 7)); oParser = new parserFormula("DB(1000000,100000,6,3,7)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), db(1000000, 100000, 6, 3, 7)); oParser = new parserFormula("DB(1000000,100000,6,4,7)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), db(1000000, 100000, 6, 4, 7)); oParser = new parserFormula("DB(1000000,100000,6,5,7)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), db(1000000, 100000, 6, 5, 7)); oParser = new parserFormula("DB(1000000,100000,6,6,7)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), db(1000000, 100000, 6, 6, 7)); oParser = new parserFormula("DB(1000000,100000,6,7,7)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), db(1000000, 100000, 6, 7, 7)); testArrayFormula2(assert, "DB", 4, 5); }); QUnit.test("Test: \"DDB\"", function (assert) { function ddb(cost, salvage, life, period, factor) { if (factor === undefined || factor === null) { factor = 2; } return _getDDB(cost, salvage, life, period, factor); } oParser = new parserFormula("DDB(2400,300,10*365,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ddb(2400, 300, 10 * 365, 1)); oParser = new parserFormula("DDB(2400,300,10*12,1,2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ddb(2400, 300, 10 * 12, 1, 2)); oParser = new parserFormula("DDB(2400,300,10,1,2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ddb(2400, 300, 10, 1, 2)); oParser = new parserFormula("DDB(2400,300,10,2,1.5)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ddb(2400, 300, 10, 2, 1.5)); oParser = new parserFormula("DDB(2400,300,10,10)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), ddb(2400, 300, 10, 10)); //TODO format $ ws.getRange2("A102").setValue("2400"); ws.getRange2("A103").setValue("300"); ws.getRange2("A104").setValue("10"); oParser = new parserFormula("DDB(A102,A103,A104*365,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 1.32); oParser = new parserFormula("DDB(A102,A103,A104*12,1,2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 40); oParser = new parserFormula("DDB(A102,A103,A104,1,2)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 480); oParser = new parserFormula("DDB(A102,A103,A104,2,1.5)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(0) - 0, 306); oParser = new parserFormula("DDB(A102,A103,A104,10)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 22.12); oParser = new parserFormula("DDB(A102,A103,0,10)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); testArrayFormula2(assert, "DDB", 4, 5); }); QUnit.test("Test: \"SLN\"", function (assert) { function sln(cost, salvage, life) { if (life == 0) { return "#NUM!"; } return (cost - salvage) / life; } oParser = new parserFormula("SLN(30000,7500,10)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), sln(30000, 7500, 10)); testArrayFormula2(assert, "SLN", 3, 3); }); QUnit.test("Test: \"XIRR\"", function (assert) { function lcl_sca_XirrResult(rValues, rDates, fRate) { var D_0 = rDates[0]; var r = fRate + 1; var fResult = rValues[0]; for (var i = 1, nCount = rValues.length; i < nCount; ++i) { fResult += rValues[i] / Math.pow(r, (rDates[i] - D_0) / 365); } return fResult; } function lcl_sca_XirrResult_Deriv1(rValues, rDates, fRate) { var D_0 = rDates[0]; var r = fRate + 1; var fResult = 0; for (var i = 1, nCount = rValues.length; i < nCount; ++i) { var E_i = (rDates[i] - D_0) / 365; fResult -= E_i * rValues[i] / Math.pow(r, E_i + 1); } return fResult; } function xirr(valueArray, dateArray, rate) { var res = rate if (res <= -1) { return "#NUM!" } var fMaxEps = 1e-6, maxIter = 100; var newRate, eps, xirrRes, bContLoop; do { xirrRes = lcl_sca_XirrResult(valueArray, dateArray, res); newRate = res - xirrRes / lcl_sca_XirrResult_Deriv1(valueArray, dateArray, res); eps = Math.abs(newRate - res); res = newRate; bContLoop = (eps > fMaxEps) && (Math.abs(xirrRes) > fMaxEps); } while (--maxIter && bContLoop); if (bContLoop) { return "#NUM!"; } return res; } ws.getRange2("F100").setValue("1/1/2008"); ws.getRange2("G100").setValue("3/1/2008"); ws.getRange2("H100").setValue("10/30/2008"); ws.getRange2("I100").setValue("2/15/2009"); ws.getRange2("J100").setValue("4/1/2009"); oParser = new parserFormula("XIRR({-10000,2750,4250,3250,2750},F100:J100,0.1)", "A2", ws); assert.ok(oParser.parse()); assert.ok(difBetween(oParser.calculate().getValue(), 0.3733625335188316)); ws.getRange2("F100").setValue(0); assert.ok(oParser.parse()); assert.ok(difBetween(oParser.calculate().getValue(), 0.0024114950175866895)); ws.getRange2("A200").setValue("-10000"); ws.getRange2("A201").setValue("2750"); ws.getRange2("A202").setValue("4250"); ws.getRange2("A203").setValue("3250"); ws.getRange2("A204").setValue("2750"); ws.getRange2("B200").setValue("1111"); ws.getRange2("B201").setValue("1113"); ws.getRange2("B202").setValue("1213"); ws.getRange2("B203").setValue("1313"); ws.getRange2("B204").setValue("1399"); ws.getRange2("A100:A104").setValue(""); ws.getRange2("B100:B104").setValue(""); oParser = new parserFormula("XIRR(A100:A104,B100:B104)", "A2", ws); assert.ok(oParser.parse(), "XIRR(A100:A104,B100:B104)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of XIRR(A100:A104,B100:B104) - empty cellRanges check"); oParser = new parserFormula("XIRR(A100:A104,B200:B204)", "A2", ws); assert.ok(oParser.parse(), "XIRR(A100:A104,B200:B204)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of XIRR(A100:A104,B200:B204) - first argument is empty cellRange"); oParser = new parserFormula("XIRR(A200:A204,B100:B104)", "A2", ws); assert.ok(oParser.parse(), "XIRR(A200:A204,B100:B104)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of XIRR(A200:A204,B100:B104) - second argument is empty cellRange"); oParser = new parserFormula("XIRR(A200:A204,B200:B204)", "A2", ws); assert.ok(oParser.parse(), "XIRR(A200:A204,B200:B204)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2), "1.03", "Result of XIRR(A200:A204,B200:B204)"); oParser = new parserFormula("XIRR(,)", "A2", ws); assert.ok(oParser.parse(), "XIRR(,)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XIRR(,)"); oParser = new parserFormula("XIRR(12,)", "A2", ws); assert.ok(oParser.parse(), "XIRR(12,)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XIRR(12,)"); oParser = new parserFormula("XIRR(,12)", "A2", ws); assert.ok(oParser.parse(), "XIRR(,12)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XIRR(,12)"); oParser = new parserFormula("XIRR(,,)", "A2", ws); assert.ok(oParser.parse(), "XIRR(,,)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XIRR(,,)"); oParser = new parserFormula("XIRR(12,,)", "A2", ws); assert.ok(oParser.parse(), "XIRR(12,,)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XIRR(12,,)"); oParser = new parserFormula("XIRR(,,12)", "A2", ws); assert.ok(oParser.parse(), "XIRR(,,12)"); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of XIRR(,,12)"); oParser = new parserFormula('XIRR("str",12)', "A2", ws); assert.ok(oParser.parse(), 'XIRR("str",12)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of XIRR("str",12)'); oParser = new parserFormula('XIRR(12,"str")', "A2", ws); assert.ok(oParser.parse(), 'XIRR(12,"str")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of XIRR(12,"str")'); oParser = new parserFormula('XIRR(#DIV/0!,)', "A2", ws); assert.ok(oParser.parse(), 'XIRR(#DIV/0!,)'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of XIRR(#DIV/0!,)'); oParser = new parserFormula('XIRR(A200:A204,#DIV/0!)', "A2", ws); assert.ok(oParser.parse(), 'XIRR(A200:A204,#DIV/0!)'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of XIRR(A200:A204,#DIV/0!)'); oParser = new parserFormula('XIRR(A200:A204,A200:A204,#DIV/0!)', "A2", ws); assert.ok(oParser.parse(), 'XIRR(A200:A204,A200:A204,#DIV/0!)'); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!", 'Result of XIRR(A200:A204,A200:A204,#DIV/0!)'); let wsName = ws.getName(); oParser = new parserFormula('XIRR('+ wsName + '!A200:A204,'+ wsName + '!B200:B204)', "A2", ws); assert.ok(oParser.parse(), 'XIRR(SheetName!A200:A204,SheetName!B200:B204)'); assert.strictEqual(oParser.calculate().getValue().toFixed(2), "1.03", 'Result of XIRR(SheetName!A200:A204,SheetName!B200:B204)'); oParser = new parserFormula('XIRR(A200:A204,'+ wsName + '!B200:B204)', "A2", ws); assert.ok(oParser.parse(), 'XIRR(A200:A204,SheetName!B200:B204)'); assert.strictEqual(oParser.calculate().getValue().toFixed(2), "1.03", 'Result of XIRR(A200:A204,SheetName!B200:B204)'); oParser = new parserFormula('XIRR('+ wsName + '!A200:A204,B200:B204)', "A2", ws); assert.ok(oParser.parse(), 'XIRR(SheetName!A200:A204,B200:B204)'); assert.strictEqual(oParser.calculate().getValue().toFixed(2), "1.03", 'Result of XIRR(SheetName!A200:A204,B200:B204)'); ws.getRange2("A200:B204").cleanAll(); }); QUnit.test("Test: \"VDB\"", function (assert) { function _getVDB(cost, salvage, life, life1, startperiod, factor) { var end; var fVdb = 0, nLoopEnd = end = Math.ceil(startperiod), fTerm, fLia = 0, fRestwert = cost - salvage, bNowLia = false, fGda; for (var i = 1; i <= nLoopEnd; i++) { if (!bNowLia) { fGda = _getDDB(cost, salvage, life, i, factor); fLia = fRestwert / (life1 - (i - 1)); if (fLia > fGda) { fTerm = fLia; bNowLia = true; } else { fTerm = fGda; fRestwert -= fGda; } } else { fTerm = fLia; } if (i == nLoopEnd) { fTerm *= (startperiod + 1.0 - end); } fVdb += fTerm; } return fVdb; } function vdb(cost, salvage, life, startPeriod, endPeriod, factor, flag) { if (factor === undefined || factor === null) { factor = 2; } if (flag === undefined || flag === null) { flag = false; } var start = Math.floor(startPeriod), end = Math.ceil(endPeriod), loopStart = start, loopEnd = end; var res = 0; if (flag) { for (var i = loopStart + 1; i <= loopEnd; i++) { var ddb = _getDDB(cost, salvage, life, i, factor); if (i == loopStart + 1) { ddb *= (Math.min(endPeriod, start + 1) - startPeriod); } else if (i == loopEnd) { ddb *= (endPeriod + 1 - end); } res += ddb; } } else { var life1 = life; if (!Math.approxEqual(startPeriod, Math.floor(startPeriod))) { if (factor > 1) { if (startPeriod > life / 2 || Math.approxEqual(startPeriod, life / 2)) { var fPart = startPeriod - life / 2; startPeriod = life / 2; endPeriod -= fPart; life1 += 1; } } } cost -= _getVDB(cost, salvage, life, life1, startPeriod, factor); res = _getVDB(cost, salvage, life, life - startPeriod, endPeriod - startPeriod, factor); } return res; } oParser = new parserFormula("VDB(2400,300,10*365,0,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), vdb(2400, 300, 10 * 365, 0, 1)); oParser = new parserFormula("VDB(2400,300,10*12,0,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), vdb(2400, 300, 10 * 12, 0, 1)); oParser = new parserFormula("VDB(2400,300,10*12,6,18)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), vdb(2400, 300, 10 * 12, 6, 18)); oParser = new parserFormula("VDB(0,0,0,0,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!"); oParser = new parserFormula("VDB(100,0,5,3,4,2,{1,2,3})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 8.64); oParser = new parserFormula('VDB(100,0,5,3,4,2,1)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 8.64); oParser = new parserFormula('VDB(100,0,5,3,4,2,FALSE)', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 10.8); oParser = new parserFormula('VDB(100,0,5,3,4,2,"test")', "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); // bug case oParser = new parserFormula("VDB(100,300,8,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100,300,8,0,1)"); assert.strictEqual(oParser.calculate().getValue(), -200, "Result of VDB(100,300,8,0,1)"); oParser = new parserFormula("VDB(0,10000,8,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(0,10000,8,0,1)"); assert.strictEqual(oParser.calculate().getValue(), -10000, "Result of VDB(0,10000,8,0,1)"); oParser = new parserFormula("VDB(100,200,8,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100,200,8,0,1)"); assert.strictEqual(oParser.calculate().getValue(), -100, "Result of VDB(100,200,8,0,1)"); oParser = new parserFormula("VDB(100,200,8,0,0.75)", "A2", ws); assert.ok(oParser.parse(), "VDB(100,200,8,0,0.75)"); assert.strictEqual(oParser.calculate().getValue(), -75, "Result of VDB(100,200,8,0,0.75)"); oParser = new parserFormula("VDB(100,200,8,0.70,0.75)", "A2", ws); assert.ok(oParser.parse(), "VDB(100,200,8,0.70,0.75)"); assert.strictEqual(oParser.calculate().getValue().toFixed() - 0, -5, "Result of VDB(100,200,8,0.70,0.75)"); oParser = new parserFormula("VDB(100,200,8,1,0.75)", "A2", ws); assert.ok(oParser.parse(), "VDB(100,200,8,0.70,0.75)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of VDB(100,200,8,0.70,0.75)"); oParser = new parserFormula("VDB(100,200,8,0.70,8)", "A2", ws); assert.ok(oParser.parse(), "VDB(100,200,8,0.70,8)"); assert.strictEqual(oParser.calculate().getValue(), -100, "Result of VDB(100,200,8,0.70,8)"); oParser = new parserFormula("VDB(100,200,8,1,2)", "A2", ws); assert.ok(oParser.parse(), "VDB(100,200,8,1,2)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of VDB(100,200,8,1,2)"); oParser = new parserFormula("VDB(100,200,8,1,8)", "A2", ws); assert.ok(oParser.parse(), "VDB(100,200,8,1,8)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of VDB(100,200,8,1,8)"); oParser = new parserFormula("VDB(100,200,8,0,8,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100,200,8,0,8,1)"); assert.strictEqual(oParser.calculate().getValue(), -100, "Result of VDB(100,200,8,0,8,1)"); oParser = new parserFormula("VDB(100,200,8,0,8,-1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100,200,8,0,8,-1)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of VDB(100,200,8,0,8,-1)"); oParser = new parserFormula("VDB(100,200,8,0,8,10000000)", "A2", ws); assert.ok(oParser.parse(), "VDB(100,200,8,0,8,10000000)"); assert.strictEqual(oParser.calculate().getValue(), -100, "Result of VDB(100,200,8,0,8,10000000)"); oParser = new parserFormula("VDB(100,200,8,0,8,0.75)", "A2", ws); assert.ok(oParser.parse(), "VDB(100,200,8,0,8,0.75)"); assert.strictEqual(oParser.calculate().getValue(), -100, "Result of VDB(100,200,8,0,8,0.75)"); oParser = new parserFormula("VDB(100,200,8,0,1,5,TRUE)", "A2", ws); assert.ok(oParser.parse(), "VDB(100,200,8,0,1,5,TRUE)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of VDB(100,200,8,0,1,5,TRUE)"); oParser = new parserFormula("VDB(100,200,8,0,1,1,FALSE)", "A2", ws); assert.ok(oParser.parse(), "VDB(100,200,8,0,1,1,FALSE)"); assert.strictEqual(oParser.calculate().getValue(), -100, "Result of VDB(100,200,8,0,1,1,FALSE)"); oParser = new parserFormula("VDB(100,200,8,0,1,1,0)", "A2", ws); assert.ok(oParser.parse(), "VDB(100,200,8,0,1,1,0)"); assert.strictEqual(oParser.calculate().getValue(), -100, "Result of VDB(100,200,8,0,1,1,0)"); oParser = new parserFormula("VDB(100,200,8,0,1,1,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100,200,8,0,1,1,1)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of VDB(100,200,8,0,1,1,1)"); oParser = new parserFormula("VDB(100,200,8,0,1,1,123)", "A2", ws); assert.ok(oParser.parse(), "VDB(100,200,8,0,1,1,123)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of VDB(100,200,8,0,1,1,123)"); // normal case oParser = new parserFormula("VDB(,11000,8,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(,11000,8,0,1)"); assert.strictEqual(oParser.calculate().getValue(), -11000, "Result of VDB(,11000,8,0,1)"); oParser = new parserFormula("VDB({1},11000,8,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB({1},11000,8,0,1)"); assert.strictEqual(oParser.calculate().getValue(), -10999, "Result of VDB({1},11000,8,0,1)"); oParser = new parserFormula("VDB({100000;15000},11000,8,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB({100000;15000},11000,8,0,1)"); assert.strictEqual(oParser.calculate().getValue(), 25000, "Result of VDB({100000;15000},11000,8,0,1)"); oParser = new parserFormula("VDB(100000,,8,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,,8,0,1)"); assert.strictEqual(oParser.calculate().getValue(), 25000, "Result of VDB(100000,,8,0,1)"); oParser = new parserFormula("VDB(100000,{1},8,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,{1},8,0,1)"); assert.strictEqual(oParser.calculate().getValue(), 25000, "Result of VDB(100000,{1},8,0,1)"); oParser = new parserFormula("VDB(100000,{1},8,1,5)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,{1},8,1,5)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 51269.53, "Result of VDB(100000,{1},8,1,5)"); oParser = new parserFormula("VDB(100000,{11000;25000;30000},8,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,{11000;25000;30000},8,0,1)"); assert.strictEqual(oParser.calculate().getValue(), 25000, "Result of VDB(100000,{11000;25000;30000},8,0,1)"); oParser = new parserFormula("VDB(100000,11000,8,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1)"); assert.strictEqual(oParser.calculate().getValue(), 25000, "Result of VDB(100000,11000,8,0,1)"); oParser = new parserFormula("VDB(100000,11000,8,0,2)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,2)"); assert.strictEqual(oParser.calculate().getValue(), 43750, "VDB(100000,11000,8,0,2)"); oParser = new parserFormula("VDB(100000,11000,8,0,3)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,3)"); assert.strictEqual(oParser.calculate().getValue(), 57812.50, "VDB(100000,11000,8,0,3)"); oParser = new parserFormula("VDB(100000,11000,8,0,4)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,4)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 68359.38, "VDB(100000,11000,8,0,4)"); oParser = new parserFormula("VDB(100000,11000,8,0,5)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,5)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 76269.53, "VDB(100000,11000,8,0,5)"); oParser = new parserFormula("VDB(100000,11000,8,0,6)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,6)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 82202.15, "VDB(100000,11000,8,0,6)"); oParser = new parserFormula("VDB(100000,11000,8,0,7)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,7)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 86651.61, "VDB(100000,11000,8,0,7)"); oParser = new parserFormula("VDB(100000,11000,8,0,8)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,8)"); assert.strictEqual(oParser.calculate().getValue(), 89000, "VDB(100000,11000,8,0,8)"); oParser = new parserFormula("VDB(100000,11000,8,0,9)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,9)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "VDB(100000,11000,8,0,9)"); oParser = new parserFormula("VDB(100000,11000,8,1,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,1,1)"); assert.strictEqual(oParser.calculate().getValue(), 0, "VDB(100000,11000,8,1,1)"); oParser = new parserFormula("VDB(100000,11000,8,1,2)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,1,2)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 18750, "VDB(100000,11000,8,1,2)"); oParser = new parserFormula("VDB(100000,11000,8,1,3)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,1,3)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 32812.5, "VDB(100000,11000,8,1,3)"); oParser = new parserFormula("VDB(100000,11000,8,1,4)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,1,4)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 43359.38, "VDB(100000,11000,8,1,4)"); oParser = new parserFormula("VDB(100000,11000,8,2,5)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,2,5)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 32519.53, "VDB(100000,11000,8,2,5)"); oParser = new parserFormula("VDB(100000,11000,8,3,4)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,3,4)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 10546.88, "VDB(100000,11000,8,3,4)"); oParser = new parserFormula("VDB(100000,11000,8,7,8)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,7,8)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 2348.39, "VDB(100000,11000,8,7,8)"); oParser = new parserFormula("VDB(100000,11000,8,0,1,,)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,,)"); assert.strictEqual(oParser.calculate().getValue(), 11125, "Result of VDB(100000,11000,8,0,1,,)"); oParser = new parserFormula("VDB(100000,11000,8,0,1,)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,)"); assert.strictEqual(oParser.calculate().getValue(), 11125, "Result of VDB(100000,11000,8,0,1,)"); oParser = new parserFormula("VDB(TRUE,11000,8,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(TRUE,11000,8,0,1)"); assert.strictEqual(oParser.calculate().getValue(), -10999, "Result of VDB(TRUE,11000,8,0,1)"); oParser = new parserFormula("VDB(FALSE,11000,8,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(FALSE,11000,8,0,1)"); assert.strictEqual(oParser.calculate().getValue(), -11000, "Result of VDB(FALSE,11000,8,0,1)"); oParser = new parserFormula("VDB(100000,TRUE,8,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,TRUE,8,0,1)"); assert.strictEqual(oParser.calculate().getValue(), 25000, "Result of VDB(100000,TRUE,8,0,1)"); oParser = new parserFormula("VDB(100000,FALSE,8,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,FALSE,8,0,1)"); assert.strictEqual(oParser.calculate().getValue(), 25000, "Result of VDB(100000,FALSE,8,0,1)"); oParser = new parserFormula("VDB(TRUE,TRUE,8,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(TRUE,TRUE,8,0,1)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of VDB(TRUE,TRUE,8,0,1)"); oParser = new parserFormula("VDB(TRUE,FALSE,8,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(TRUE,FALSE,8,0,1)"); assert.strictEqual(oParser.calculate().getValue(), 0.25, "Result of VDB(TRUE,FALSE,8,0,1)"); oParser = new parserFormula("VDB(FALSE,TRUE,8,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(FALSE,TRUE,8,0,1)"); assert.strictEqual(oParser.calculate().getValue(), -1, "Result of VDB(FALSE,TRUE,8,0,1)"); oParser = new parserFormula("VDB(FALSE,FALSE,8,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(FALSE,FALSE,8,0,1)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of VDB(FALSE,FALSE,8,0,1)"); // arg[2] oParser = new parserFormula("VDB(100000,11000,TRUE,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,TRUE,0,1)"); assert.strictEqual(oParser.calculate().getValue(), 89000, "Result of VDB(100000,11000,TRUE,0,1)"); oParser = new parserFormula("VDB(100000,11000,FALSE,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,FALSE,0,1)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of VDB(100000,11000,FALSE,0,1)"); oParser = new parserFormula("VDB(100000,11000,-1,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,-1,0,1)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of VDB(100000,11000,-1,0,1)"); oParser = new parserFormula("VDB(100000,11000,0.75,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,0.75,0,1)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of VDB(100000,11000,0.75,0,1)"); oParser = new parserFormula("VDB(100000,11000,9999999999999999999999999999,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,9999999999999999999999999999,0,1)"); assert.strictEqual(oParser.calculate().getValue(), 8.9e-24, "Result of VDB(100000,11000,9999999999999999999999999999,0,1)"); // 2E-23 oParser = new parserFormula("VDB(100000,11000,9999999999999999999999999999,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,9999999999999999999999999999,0,1)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 0, "Result of VDB(100000,11000,9999999999999999999999999999,0,1)"); oParser = new parserFormula("VDB(100000,11000,string,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,string,0,1)"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Result of VDB(100000,11000,string,0,1)"); oParser = new parserFormula("VDB(100000,11000,{2},0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,{2},0,1)"); assert.strictEqual(oParser.calculate().getValue(), 89000, "Result of VDB(100000,11000,{2},0,1)"); oParser = new parserFormula("VDB(100000,11000,{9;5;8},0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,{9;5;8},0,1)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 22222.22, "Result of VDB(100000,11000,{9;5;8},0,1)"); // arg[3] oParser = new parserFormula("VDB(100000,11000,8,TRUE,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,TRUE,1)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of VDB(100000,11000,8,TRUE,1)"); oParser = new parserFormula("VDB(100000,11000,8,FALSE,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,FALSE,1)"); assert.strictEqual(oParser.calculate().getValue(), 25000, "Result of VDB(100000,11000,8,FALSE,1)"); oParser = new parserFormula("VDB(100000,11000,8,string,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,string,1)"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Result of VDB(100000,11000,8,string,1)"); oParser = new parserFormula("VDB(100000,11000,8,{1},5)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,{1},5)"); assert.strictEqual(oParser.calculate().getValue(), 51269.53125, "Result of VDB(100000,11000,8,{1},5)"); oParser = new parserFormula("VDB(100000,11000,8,{1;2;3;4;5},5)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,{1;2;3;4;5},5)"); assert.strictEqual(oParser.calculate().getValue(), 51269.53125, "Result of VDB(100000,11000,8,{1;2;3;4;5},5)"); oParser = new parserFormula("VDB(100000,11000,8,{5;4;3;2;1},5)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,{5;4;3;2;1},5)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of VDB(100000,11000,8,{5;4;3;2;1},5)"); // arg[4] oParser = new parserFormula("VDB(100000,11000,8,0,TRUE)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,TRUE)"); assert.strictEqual(oParser.calculate().getValue(), 25000, "Result of VDB(100000,11000,8,0,TRUE)"); oParser = new parserFormula("VDB(100000,11000,8,0,FALSE)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,FALSE)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of VDB(100000,11000,8,0,FALSE)"); oParser = new parserFormula("VDB(100000,11000,8,0,string)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,string,1)"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Result of VDB(100000,11000,8,string,1)"); oParser = new parserFormula("VDB(100000,11000,8,0,{1})", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,{1})"); assert.strictEqual(oParser.calculate().getValue(), 25000, "Result of VDB(100000,11000,8,0,{1})"); oParser = new parserFormula("VDB(100000,11000,8,0,{1;2;3;4;5})", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,{1;2;3;4;5})"); assert.strictEqual(oParser.calculate().getValue(), 25000, "Result of VDB(100000,11000,8,0,{1;2;3;4;5})"); oParser = new parserFormula("VDB(100000,11000,8,0,{5;4;3;2;1})", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,{5;4;3;2;1})"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 76269.53, "Result of VDB(100000,11000,8,0,{5;4;3;2;1})"); // arg[5] oParser = new parserFormula("VDB(100000,11000,8,0,1,2)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,2)"); assert.strictEqual(oParser.calculate().getValue(), 25000, "Result of VDB(100000,11000,8,0,1,2)"); oParser = new parserFormula("VDB(100000,11000,8,0,1,3)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,3)"); assert.strictEqual(oParser.calculate().getValue(), 37500, "Result of VDB(100000,11000,8,0,1,3)"); oParser = new parserFormula("VDB(100000,11000,8,0,1,10)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,10)"); assert.strictEqual(oParser.calculate().getValue(), 89000, "Result of VDB(100000,11000,8,0,1,10)"); oParser = new parserFormula("VDB(100000,11000,8,0,1,10000)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,10000)"); assert.strictEqual(oParser.calculate().getValue(), 89000, "Result of VDB(100000,11000,8,0,1,10000)"); oParser = new parserFormula("VDB(100000,11000,8,0,1,-1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,-1)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", "Result of VDB(100000,11000,8,0,1,-1)"); oParser = new parserFormula("VDB(100000,11000,8,0,1,0.75)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,0.75)"); assert.strictEqual(oParser.calculate().getValue(), 11125, "Result of VDB(100000,11000,8,0,1,0.75)"); oParser = new parserFormula("VDB(100000,11000,8,0,1,0.00000075)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,0.00000075)"); assert.strictEqual(oParser.calculate().getValue(), 11125, "Result of VDB(100000,11000,8,0,1,0.00000075)"); oParser = new parserFormula("VDB(100000,11000,8,0,1,1.25)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,1.25)"); assert.strictEqual(oParser.calculate().getValue(), 15625, "Result of VDB(100000,11000,8,0,1,1.25)"); oParser = new parserFormula("VDB(100000,11000,8,0,1,TRUE)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,TRUE)"); assert.strictEqual(oParser.calculate().getValue(), 12500, "Result of VDB(100000,11000,8,0,1,TRUE)"); oParser = new parserFormula("VDB(100000,11000,8,0,1,FALSE)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,FALSE)"); assert.strictEqual(oParser.calculate().getValue(), 11125, "Result of VDB(100000,11000,8,0,1,FALSE)"); oParser = new parserFormula("VDB(100000,11000,8,0,1,format)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,format)"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Result of VDB(100000,11000,8,0,1,format)"); oParser = new parserFormula("VDB(100000,11000,8,0,1,{1})", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,{1})"); assert.strictEqual(oParser.calculate().getValue(), 12500, "Result of VDB(100000,11000,8,0,1,{1})"); oParser = new parserFormula("VDB(100000,11000,8,0,1,{5;2;3;4;5})", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,{5;2;3;4;5})"); assert.strictEqual(oParser.calculate().getValue(), 62500, "Result of VDB(100000,11000,8,0,1,{5;2;3;4;5})"); // arg[6] oParser = new parserFormula("VDB(100000,11000,8,0,1,2,0)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,2,0)"); assert.strictEqual(oParser.calculate().getValue(), 25000, "Result of VDB(100000,11000,8,0,1,2,0)"); oParser = new parserFormula("VDB(100000,11000,8,0,1,2,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,2,1)"); assert.strictEqual(oParser.calculate().getValue(), 25000, "Result of VDB(100000,11000,8,0,1,2,1)"); oParser = new parserFormula("VDB(100000,11000,8,0,1,2,2)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,2,2)"); assert.strictEqual(oParser.calculate().getValue(), 25000, "Result of VDB(100000,11000,8,0,1,2,2)"); oParser = new parserFormula("VDB(100000,11000,8,0,1,2,10)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,2,10)"); assert.strictEqual(oParser.calculate().getValue(), 25000, "Result of VDB(100000,11000,8,0,1,2,10)"); oParser = new parserFormula("VDB(100000,11000,8,0,1,2,9999999999999999999999999)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,2,9999999999999999999999999)"); assert.strictEqual(oParser.calculate().getValue(), 25000, "Result of VDB(100000,11000,8,0,1,2,9999999999999999999999999)"); oParser = new parserFormula("VDB(100000,11000,8,0,1,2,-1)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,2,-1)"); assert.strictEqual(oParser.calculate().getValue(), 25000, "Result of VDB(100000,11000,8,0,1,2,-1)"); oParser = new parserFormula("VDB(100000,11000,8,0,1,2,0.75)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,2,0.75)"); assert.strictEqual(oParser.calculate().getValue(), 25000, "Result of VDB(100000,11000,8,0,1,2,0.75)"); oParser = new parserFormula("VDB(100000,11000,8,0,1,2,1.25)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,2,1.25)"); assert.strictEqual(oParser.calculate().getValue(), 25000, "Result of VDB(100000,11000,8,0,1,2,1.25)"); oParser = new parserFormula("VDB(100000,11000,8,0,5,2,TRUE)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,5,2,TRUE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 76269.53, "Result of VDB(100000,11000,8,0,5,2,TRUE)"); oParser = new parserFormula("VDB(100000,11000,8,0,5,2,FALSE)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,5,2,FALSE)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 76269.53, "Result of VDB(100000,11000,8,0,5,2,FALSE)"); oParser = new parserFormula("VDB(100000,11000,8,0,1,2,format)", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,2,format)"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Result of VDB(100000,11000,8,0,1,2,format)"); oParser = new parserFormula("VDB(100000,11000,8,0,1,2,{1})", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,2,{1})"); assert.strictEqual(oParser.calculate().getValue(), 25000, "Result of VDB(100000,11000,8,0,1,2,{1})"); oParser = new parserFormula("VDB(100000,11000,8,0,1,2,{-1})", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,2,{-1})"); assert.strictEqual(oParser.calculate().getValue(), 25000, "Result of VDB(100000,11000,8,0,1,2,{-1})"); oParser = new parserFormula("VDB(100000,11000,8,0,1,2,{5;2;3;4;5})", "A2", ws); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,2,{5;2;3;4;5})"); assert.strictEqual(oParser.calculate().getValue(), 25000, "Result of VDB(100000,11000,8,0,1,2,{5;2;3;4;5})"); oParser = new parserFormula("VDB(TRUE,TRUE,TRUE,TRUE,TRUE)", "A2", ws); assert.ok(oParser.parse(), "VDB(TRUE,TRUE,TRUE,TRUE,TRUE)"); assert.strictEqual(oParser.calculate().getValue(), 0, "Result of VDB(TRUE,TRUE,TRUE,TRUE,TRUE)"); oParser = new parserFormula("VDB({100000},{11000},{8},{0},{1},{2},{-1})", "A2", ws); assert.ok(oParser.parse(), "VDB({100000},{11000},{8},{0},{1},{2},{-1})"); assert.strictEqual(oParser.calculate().getValue(), 25000, "Result of VDB({100000},{11000},{8},{0},{1},{2},{-1})"); oParser = new parserFormula("VDB({100000,25000},{11000,25000},{8,5,8},{0,1,2},{1,0,-1},{2,1,3},{-1,0,1})", "A2", ws); assert.ok(oParser.parse(), "VDB({100000,25000},{11000,25000},{8,5,8},{0,1,2},{1,0,-1},{2,1,3},{-1,0,1})"); assert.strictEqual(oParser.calculate().getValue(), 25000, "Result of VDB({100000,25000},{11000,25000},{8,5,8},{0,1,2},{1,0,-1},{2,1,3},{-1,0,1})"); ws.getRange2("F2").setValue("100000"); ws.getRange2("F3").setValue("11000"); ws.getRange2("F4").setValue(""); ws.getRange2("F5").setValue("11000"); ws.getRange2("F6").setValue("25000"); ws.getRange2("F7").setValue(""); ws.getRange2("F8").setValue("8"); ws.getRange2("F9").setValue("0"); ws.getRange2("F10").setValue("1"); ws.getRange2("F11").setValue(""); ws.getRange2("F12").setValue("12"); ws.getRange2("F13").setValue("test2"); ws.getRange2("F14").setValue("TRUE"); ws.getRange2("F15").setValue("#N/A"); oParser = new parserFormula("VDB(F2:F4,11000,8,0,1)", "A2", ws); assert.ok(oParser.parse(), "VDB(F2:F4,11000,8,0,1)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of VDB(F2:F4,11000,8,0,1)"); // cellsRange (arg0) oParser = new parserFormula("VDB(F2:F4,11000,8,0,1)", "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("F2:F4").bbox); assert.ok(oParser.parse(), "VDB(F2:F4,11000,8,0,1)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 25000, "Result in [0,0] VDB(F2:F4,11000,8,0,1)"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 0, "Result in [1,0] VDB(F2:F4,11000,8,0,1)"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), -11000, "Result in [2,0] VDB(F2:F4,11000,8,0,1)"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "", "Result in [3,0] VDB(F2:F4,11000,8,0,1)"); assert.strictEqual(array.getElementRowCol(3, 3).getValue(), "#N/A", "Result in [3,3] VDB(F2:F4,11000,8,0,1)"); // cellsRange (arg1) oParser = new parserFormula("VDB(100000,F5:F7,8,1,5)", "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("F5:F7").bbox); assert.ok(oParser.parse(), "VDB(100000,F5:F7,8,0,1)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue().toFixed(2) - 0, 51269.53, "Result in [0,0] VDB(100000,F5:F7,8,0,1)"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 50000, "Result in [1,0] VDB(100000,F5:F7,8,0,1)"); assert.strictEqual(array.getElementRowCol(2, 0).getValue().toFixed(2) - 0, 51269.53, "Result in [2,0] VDB(100000,F5:F7,8,0,1)"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "", "Result in [3,0] VDB(100000,F5:F7,8,0,1)"); assert.strictEqual(array.getElementRowCol(3, 3).getValue(), "#N/A", "Result in [3,3] VDB(100000,F5:F7,8,0,1)"); // cellsRange (arg2) oParser = new parserFormula("VDB(100000,11000,F8:F15,0,1)", "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("F8:F15").bbox); assert.ok(oParser.parse(), "VDB(100000,11000,F8:F15,0,1)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 25000, "Result in [0,0] VDB(100000,11000,F8:F15,0,1)"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#NUM!", "Result in [1,0] VDB(100000,11000,F8:F15,0,1)"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 89000, "Result in [2,0] VDB(100000,11000,F8:F15,0,1)"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#NUM!", "Result in [3,0] VDB(100000,11000,F8:F15,0,1)"); assert.strictEqual(array.getElementRowCol(4, 0).getValue().toFixed(3) - 0, 16666.667, "Result in [4,0] VDB(100000,11000,F8:F15,0,1)"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), "#VALUE!", "Result in [5,0] VDB(100000,11000,F8:F15,0,1)"); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), 89000, "Result in [6,0] VDB(100000,11000,F8:F15,0,1)"); assert.strictEqual(array.getElementRowCol(3, 3).getValue(), "#N/A", "Result in [3,3] VDB(100000,11000,F8:F15,0,1)"); // cellsRange (arg3) oParser = new parserFormula("VDB(100000,11000,8,F9:F15,1)", "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("F9:F15").bbox); assert.ok(oParser.parse(), "VDB(100000,11000,8,F9:F15,1)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 25000, "Result in [0,0] VDB(100000,11000,8,F9:F15,1)"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 0, "Result in [1,0] VDB(100000,11000,8,F9:F15,1)"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 25000, "Result in [2,0] VDB(100000,11000,8,F9:F15,1)"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#NUM!", "Result in [3,0] VDB(100000,11000,8,F9:F15,1)"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "#VALUE!", "Result in [4,0] VDB(100000,11000,8,F9:F15,1)"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 0, "Result in [5,0] VDB(100000,11000,8,F9:F15,1)"); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), "#N/A", "Result in [6,0] VDB(100000,11000,8,F9:F15,1)"); assert.strictEqual(array.getElementRowCol(5, 5).getValue(), "#N/A", "Result in [5,5] VDB(100000,11000,8,F9:F15,1)"); // cellsRange (arg4) oParser = new parserFormula("VDB(100000,11000,8,0,F9:F15)", "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("F9:F15").bbox); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,F9:F15)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 0, "Result in [0,0] VDB(100000,11000,8,0,F9:F15)"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 25000, "Result in [1,0] VDB(100000,11000,8,0,F9:F15)"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 0, "Result in [2,0] VDB(100000,11000,8,0,F9:F15)"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#NUM!", "Result in [3,0] VDB(100000,11000,8,0,F9:F15)"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "#VALUE!", "Result in [4,0] VDB(100000,11000,8,0,F9:F15)"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 25000, "Result in [5,0] VDB(100000,11000,8,0,F9:F15)"); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), "#N/A", "Result in [6,0] VDB(100000,11000,8,0,F9:F15)"); assert.strictEqual(array.getElementRowCol(5, 5).getValue(), "#N/A", "Result in [5,5] VDB(100000,11000,8,0,F9:F15)"); // cellsRange (arg5) oParser = new parserFormula("VDB(100000,11000,8,0,1,F9:F15)", "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("F9:F15").bbox); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,F9:F15)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 11125, "Result in [0,0] VDB(100000,11000,8,0,1,F9:F15)"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 12500, "Result in [1,0] VDB(100000,11000,8,0,1,F9:F15)"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 11125, "Result in [2,0] VDB(100000,11000,8,0,1,F9:F15)"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 89000, "Result in [3,0] VDB(100000,11000,8,0,1,F9:F15)"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "#VALUE!", "Result in [4,0] VDB(100000,11000,8,0,1,F9:F15)"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 12500, "Result in [5,0] VDB(100000,11000,8,0,1,F9:F15)"); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), "#N/A", "Result in [6,0] VDB(100000,11000,8,0,1,F9:F15)"); assert.strictEqual(array.getElementRowCol(7, 0).getValue(), "", "Result in [7,0] VDB(100000,11000,8,0,1,F9:F15)"); assert.strictEqual(array.getElementRowCol(8, 0).getValue(), "#N/A", "Result in [8,0] VDB(100000,11000,8,0,1,F9:F15)"); assert.strictEqual(array.getElementRowCol(5, 5).getValue(), "#N/A", "Result in [5,5] VDB(100000,11000,8,0,1,F9:F15)"); // cellsRange (arg6) oParser = new parserFormula("VDB(100000,11000,8,0,1,2,F9:F15)", "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("F9:F15").bbox); assert.ok(oParser.parse(), "VDB(100000,11000,8,0,1,2,F9:F15)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 25000, "Result in [0,0] VDB(100000,11000,8,0,1,2,F9:F15)"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 25000, "Result in [1,0] VDB(100000,11000,8,0,1,2,F9:F15)"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 25000, "Result in [2,0] VDB(100000,11000,8,0,1,2,F9:F15)"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 25000, "Result in [3,0] VDB(100000,11000,8,0,1,2,F9:F15)"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "#VALUE!", "Result in [4,0] VDB(100000,11000,8,0,1,2,F9:F15)"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 25000, "Result in [5,0] VDB(100000,11000,8,0,1,2,F9:F15)"); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), "#N/A", "Result in [6,0] VDB(100000,11000,8,0,1,2,F9:F15)"); assert.strictEqual(array.getElementRowCol(7, 0).getValue(), "", "Result in [7,0] VDB(100000,11000,8,0,1,2,F9:F15)"); assert.strictEqual(array.getElementRowCol(8, 0).getValue(), "#N/A", "Result in [8,0] VDB(100000,11000,8,0,1,2,F9:F15)"); assert.strictEqual(array.getElementRowCol(5, 5).getValue(), "#N/A", "Result in [5,5] VDB(100000,11000,8,0,1,2,F9:F15)"); // cellsRange (all) oParser = new parserFormula("VDB(F2:F4,F5:F7,F8:F15,F9:F15,F9:F15)", "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("F2:F15").bbox); assert.ok(oParser.parse(), "VDB(F2:F4,F5:F7,F8:F15,F9:F15,F9:F15)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 0, "Result in [0,0] VDB(F2:F4,F5:F7,F8:F15,F9:F15,F9:F15)"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#NUM!", "Result in [1,0] VDB(F2:F4,F5:F7,F8:F15,F9:F15,F9:F15)"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 0, "Result in [2,0] VDB(F2:F4,F5:F7,F8:F15,F9:F15,F9:F15)"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "", "Result in [3,0] VDB(F2:F4,F5:F7,F8:F15,F9:F15,F9:F15)"); assert.strictEqual(array.getElementRowCol(5, 5).getValue(), "#N/A", "Result in [5,5] VDB(F2:F4,F5:F7,F8:F15,F9:F15,F9:F15)"); oParser = new parserFormula("VDB(F2:F4,F5:F7,F8:F15,F9:F15,F9:F15,F9:F15,F9:F15)", "A2", ws); oParser.setArrayFormulaRef(ws.getRange2("F2:F15").bbox); assert.ok(oParser.parse(), "VDB(F2:F4,F5:F7,F8:F15,F9:F15,F9:F15,F9:F15,F9:F15)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 0, "Result in [0,0] VDB(F2:F4,F5:F7,F8:F15,F9:F15,F9:F15,F9:F15,F9:F15)"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#NUM!", "Result in [1,0] VDB(F2:F4,F5:F7,F8:F15,F9:F15,F9:F15,F9:F15,F9:F15)"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 0, "Result in [2,0] VDB(F2:F4,F5:F7,F8:F15,F9:F15,F9:F15,F9:F15,F9:F15)"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "", "Result in [3,0] VDB(F2:F4,F5:F7,F8:F15,F9:F15,F9:F15,F9:F15,F9:F15)"); assert.strictEqual(array.getElementRowCol(5, 5).getValue(), "#N/A", "Result in [5,5] VDB(F2:F4,F5:F7,F8:F15,F9:F15,F9:F15,F9:F15,F9:F15)"); testArrayFormula2(assert, "VDB", 5, 7); }); QUnit.test("Test: \"ODDFPRICE\"", function (assert) { oParser = new parserFormula("ODDFPRICE(DATE(1999,2,28),DATE(2016,1,1),DATE(1998,2,28),DATE(2015,1,1),7%,0,100,2,1)", "A2", ws); assert.ok(oParser.parse()); assert.ok(difBetween(oParser.calculate().getValue(), 217.878453038674)); oParser = new parserFormula("ODDFPRICE(DATE(2008,11,11),DATE(2021,3,1),DATE(2008,10,15),DATE(2009,3,1),0.0785,0.0625,100,2,1)", "A2", ws); assert.ok(oParser.parse()); assert.ok(difBetween(oParser.calculate().getValue(), 113.597717474079)); oParser = new parserFormula("ODDFPRICE(DATE(1990,6,1),DATE(1995,12,31),DATE(1990,1,1),DATE(1990,12,31),6%,5%,1000,1,1)", "A2", ws); assert.ok(oParser.parse()); assert.ok(difBetween(oParser.calculate().getValue(), 790.11323221867)); testArrayFormula2(assert, "ODDFPRICE", 8, 9, true); }); QUnit.test("Test: \"ODDFYIELD\"", function (assert) { ws.getRange2("A10:Z100").cleanAll(); oParser = new parserFormula("ODDFYIELD(DATE(1990,6,1),DATE(1995,12,31),DATE(1990,1,1),DATE(1990,12,31),6%,790,100,1,1)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "ODDFYIELD(DATE(1990,6,1),DATE(1995,12,31),DATE(1990,1,1),DATE(1990,12,31),6%,790,100,1,1)"); assert.ok(difBetween(oParser.calculate().getValue(), -0.2889178784774840)); oParser = new parserFormula("ODDFYIELD(DATE(2008,11,11),DATE(2021,3,1),DATE(2008,10,15),DATE(2009,3,1),0.0575,84.5,100,2,0)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "ODDFYIELD(DATE(2008,11,11),DATE(2021,3,1),DATE(2008,10,15),DATE(2009,3,1),0.0575,84.5,100,2,0)"); assert.ok(difBetween(oParser.calculate().getValue(), 0.0772455415972989)); oParser = new parserFormula("ODDFYIELD(DATE(2008,12,11),DATE(2021,4,1),DATE(2008,10,15),DATE(2009,4,1),6%,100,100,4,1)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "ODDFYIELD(DATE(2008,12,11),DATE(2021,4,1),DATE(2008,10,15),DATE(2009,4,1),6%,100,100,4,1)"); assert.ok(difBetween(oParser.calculate().getValue(), 0.0599769985558904)); // for bug 21211 ws.getRange2("A12").setValue("November 11, 2008"); ws.getRange2("A13").setValue("March 1, 2021"); ws.getRange2("A14").setValue("October 15, 2008"); ws.getRange2("A15").setValue("March 1, 2009"); ws.getRange2("A16").setValue("5.75%"); ws.getRange2("A17").setValue("84.50"); ws.getRange2("A18").setValue("100"); ws.getRange2("A19").setValue("2"); ws.getRange2("A20").setValue("0"); oParser = new parserFormula("ODDFYIELD(A12, A13, A14, A15, A16, A17, A18, A19, A20)", "A2", ws); assert.ok(oParser.parse(), 'ODDFYIELD(A12, A13, A14, A15, A16, A17, A18, A19, A20)'); assert.ok(oParser.calculate().getValue(), 0.08, 'Result of ODDFYIELD(A12, A13, A14, A15, A16, A17, A18, A19, A20)'); testArrayFormula2(assert, "ODDFYIELD", 8, 9, true); }); /* * Engineering * */ QUnit.test("Test: \"BIN2DEC\"", function (assert) { oParser = new parserFormula("BIN2DEC(101010)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2DEC(101010)"); assert.strictEqual(oParser.calculate().getValue(), 42); oParser = new parserFormula("BIN2DEC(\"101010\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2DEC(\"101010\")"); assert.strictEqual(oParser.calculate().getValue(), 42); oParser = new parserFormula("BIN2DEC(111111111)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2DEC(111111111)"); assert.strictEqual(oParser.calculate().getValue(), 511); oParser = new parserFormula("BIN2DEC(1000000000)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2DEC(1000000000)"); assert.strictEqual(oParser.calculate().getValue(), -512); oParser = new parserFormula("BIN2DEC(1111111111)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2DEC(1111111111)"); assert.strictEqual(oParser.calculate().getValue(), -1); oParser = new parserFormula("BIN2DEC(1234567890)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2DEC(1234567890)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("BIN2DEC(\"Hello World!\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2DEC(\"Hello World!\")"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); testArrayFormula2(assert, "BIN2DEC", 1, 1, true); }); QUnit.test("Test: \"BIN2HEX\"", function (assert) { oParser = new parserFormula("BIN2HEX(101010)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2HEX(101010)"); assert.strictEqual(oParser.calculate().getValue(), "2A"); oParser = new parserFormula("BIN2HEX(\"101010\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2HEX(\"101010\")"); assert.strictEqual(oParser.calculate().getValue(), "2A"); oParser = new parserFormula("BIN2HEX(111111111)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2HEX(111111111)"); assert.strictEqual(oParser.calculate().getValue(), "1FF"); oParser = new parserFormula("BIN2HEX(1000000000)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2HEX(1000000000)"); assert.strictEqual(oParser.calculate().getValue(), "FFFFFFFE00"); oParser = new parserFormula("BIN2HEX(1111111111)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2HEX(1111111111)"); assert.strictEqual(oParser.calculate().getValue(), "FFFFFFFFFF"); oParser = new parserFormula("BIN2HEX(101010,2)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2HEX(101010,2)"); assert.strictEqual(oParser.calculate().getValue(), "2A"); oParser = new parserFormula("BIN2HEX(101010,4)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2HEX(101010,4)"); assert.strictEqual(oParser.calculate().getValue(), "002A"); oParser = new parserFormula("BIN2HEX(101010,4.5)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2HEX(101010,4.5)"); assert.strictEqual(oParser.calculate().getValue(), "002A"); oParser = new parserFormula("BIN2HEX(1234567890)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2HEX(1234567890)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("BIN2HEX(\"Hello World!\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2HEX(\"Hello World!\")"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("BIN2HEX(101010101010)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2HEX(101010101010)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("BIN2HEX(101010,1)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2HEX(101010,1)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("BIN2HEX(101010,-4)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2HEX(101010,-4)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("BIN2HEX(101010, \"Hello World!\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2HEX(101010,\"Hello World!\")"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); testArrayFormula2(assert, "BIN2HEX", 1, 2, true) }); QUnit.test("Test: \"BIN2OCT\"", function (assert) { oParser = new parserFormula("BIN2OCT(101010)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2OCT(101010)"); assert.strictEqual(oParser.calculate().getValue(), "52"); oParser = new parserFormula("BIN2OCT(\"101010\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2OCT(\"101010\")"); assert.strictEqual(oParser.calculate().getValue(), "52"); oParser = new parserFormula("BIN2OCT(111111111)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2OCT(111111111)"); assert.strictEqual(oParser.calculate().getValue(), "777"); oParser = new parserFormula("BIN2OCT(1000000000)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2OCT(1000000000)"); assert.strictEqual(oParser.calculate().getValue(), "7777777000"); oParser = new parserFormula("BIN2OCT(1111111111)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2OCT(1111111111)"); assert.strictEqual(oParser.calculate().getValue(), "7777777777"); oParser = new parserFormula("BIN2OCT(101010, 2)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2OCT(101010,2)"); assert.strictEqual(oParser.calculate().getValue(), "52"); oParser = new parserFormula("BIN2OCT(101010, 4)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2OCT(101010,4)"); assert.strictEqual(oParser.calculate().getValue(), "0052"); oParser = new parserFormula("BIN2OCT(101010, 4.5)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2OCT(101010,4.5)"); assert.strictEqual(oParser.calculate().getValue(), "0052"); oParser = new parserFormula("BIN2OCT(\"Hello World!\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2OCT(\"Hello World!\")"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("BIN2OCT(1234567890)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2OCT(1234567890)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("BIN2OCT(101010101010)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2OCT(101010101010)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("BIN2OCT(101010, 1)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2OCT(101010,1)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("BIN2OCT(101010, -4)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2OCT(101010,-4)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("BIN2OCT(101010, \"Hello World!\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "BIN2OCT(101010,\"Hello World!\")"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); testArrayFormula2(assert, "BIN2OCT", 1, 2, true); }); QUnit.test("Test: \"DEC2BIN\"", function (assert) { oParser = new parserFormula("DEC2BIN(42)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2BIN(42)"); assert.strictEqual(oParser.calculate().getValue(), "101010"); oParser = new parserFormula("DEC2BIN(\"42\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2BIN(\"42\")"); assert.strictEqual(oParser.calculate().getValue(), "101010"); oParser = new parserFormula("DEC2BIN(-512)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2BIN(-512)"); assert.strictEqual(oParser.calculate().getValue(), "1000000000"); oParser = new parserFormula("DEC2BIN(-511)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2BIN(-511)"); assert.strictEqual(oParser.calculate().getValue(), "1000000001"); oParser = new parserFormula("DEC2BIN(-1)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2BIN(-1)"); assert.strictEqual(oParser.calculate().getValue(), "1111111111"); oParser = new parserFormula("DEC2BIN(0)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2BIN(0)"); assert.strictEqual(oParser.calculate().getValue(), "0"); oParser = new parserFormula("DEC2BIN(1)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2BIN(1)"); assert.strictEqual(oParser.calculate().getValue(), "1"); oParser = new parserFormula("DEC2BIN(510)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2BIN(510)"); assert.strictEqual(oParser.calculate().getValue(), "111111110"); oParser = new parserFormula("DEC2BIN(511)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2BIN(511)"); assert.strictEqual(oParser.calculate().getValue(), "111111111"); oParser = new parserFormula("DEC2BIN(42, 6)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2BIN(42,6)"); assert.strictEqual(oParser.calculate().getValue(), "101010"); oParser = new parserFormula("DEC2BIN(42, 8)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2BIN(42,8)"); assert.strictEqual(oParser.calculate().getValue(), "00101010"); oParser = new parserFormula("DEC2BIN(\"Hello World!\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2BIN(\"Hello World!\")"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("DEC2BIN(\"2a\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2BIN(\"2a\")"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("DEC2BIN(-513)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2BIN(-513)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("DEC2BIN(512)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2BIN(512)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("DEC2BIN(42, -8)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2BIN(42,-8)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); testArrayFormula2(assert, "DEC2BIN", 1, 2, true) }); QUnit.test("Test: \"DEC2HEX\"", function (assert) { oParser = new parserFormula("DEC2HEX(42)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2HEX(42)"); assert.strictEqual(oParser.calculate().getValue(), "2A"); oParser = new parserFormula("DEC2HEX(\"42\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2HEX(\"42\")"); assert.strictEqual(oParser.calculate().getValue(), "2A"); oParser = new parserFormula("DEC2HEX(-549755813888)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2HEX(-549755813888)"); assert.strictEqual(oParser.calculate().getValue(), "8000000000"); oParser = new parserFormula("DEC2HEX(-549755813887)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2HEX(-549755813887)"); assert.strictEqual(oParser.calculate().getValue(), "8000000001"); oParser = new parserFormula("DEC2HEX(-1)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2HEX(-1)"); assert.strictEqual(oParser.calculate().getValue(), "FFFFFFFFFF"); oParser = new parserFormula("DEC2HEX(0)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2HEX(0)"); assert.strictEqual(oParser.calculate().getValue(), "0"); oParser = new parserFormula("DEC2HEX(1)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2HEX(1)"); assert.strictEqual(oParser.calculate().getValue(), "1"); oParser = new parserFormula("DEC2HEX(549755813886)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2HEX(549755813886)"); assert.strictEqual(oParser.calculate().getValue(), "7FFFFFFFFE"); oParser = new parserFormula("DEC2HEX(549755813887)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2HEX(549755813887)"); assert.strictEqual(oParser.calculate().getValue(), "7FFFFFFFFF"); oParser = new parserFormula("DEC2HEX(42, 2)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2HEX(42,2)"); assert.strictEqual(oParser.calculate().getValue(), "2A"); oParser = new parserFormula("DEC2HEX(42, 4)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2HEX(42,4)"); assert.strictEqual(oParser.calculate().getValue(), "002A"); oParser = new parserFormula("DEC2HEX(\"Hello World!\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2HEX(\"Hello World!\")"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("DEC2HEX(\"2a\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2HEX(\"2a\")"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); testArrayFormula2(assert, "DEC2HEX", 1, 2, true); }); QUnit.test("Test: \"DEC2OCT\"", function (assert) { oParser = new parserFormula("DEC2OCT(42)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2OCT(42)"); assert.strictEqual(oParser.calculate().getValue(), "52"); oParser = new parserFormula("DEC2OCT(\"42\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2OCT(\"42\")"); assert.strictEqual(oParser.calculate().getValue(), "52"); oParser = new parserFormula("DEC2OCT(-536870912)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2OCT(-536870912)"); assert.strictEqual(oParser.calculate().getValue(), "4000000000"); oParser = new parserFormula("DEC2OCT(-536870911)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2OCT(-536870911)"); assert.strictEqual(oParser.calculate().getValue(), "4000000001"); oParser = new parserFormula("DEC2OCT(-1)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2OCT(-1)"); assert.strictEqual(oParser.calculate().getValue(), "7777777777"); oParser = new parserFormula("DEC2OCT(0)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2OCT(0)"); assert.strictEqual(oParser.calculate().getValue(), "0"); oParser = new parserFormula("DEC2OCT(-0)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2OCT(-0)"); assert.strictEqual(oParser.calculate().getValue(), "0"); oParser = new parserFormula("DEC2OCT(1)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2OCT(1)"); assert.strictEqual(oParser.calculate().getValue(), "1"); oParser = new parserFormula("DEC2OCT(536870910)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2OCT(536870910)"); assert.strictEqual(oParser.calculate().getValue(), "3777777776"); oParser = new parserFormula("DEC2OCT(536870911)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2OCT(536870911)"); assert.strictEqual(oParser.calculate().getValue(), "3777777777"); oParser = new parserFormula("DEC2OCT(42, 2)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2OCT(42,2)"); assert.strictEqual(oParser.calculate().getValue(), "52"); oParser = new parserFormula("DEC2OCT(42, 4)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2OCT(42,4)"); assert.strictEqual(oParser.calculate().getValue(), "0052"); oParser = new parserFormula("DEC2OCT(\"Hello World!\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2OCT(\"Hello World!\")"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("DEC2OCT(\"2a\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2OCT(\"2a\")"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("DEC2OCT(-536870913)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2OCT(-536870913)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("DEC2OCT(536870912)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2OCT(536870912)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("DEC2OCT(42, 1)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "DEC2OCT(42,1)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); testArrayFormula2(assert, "DEC2OCT", 1, 2, true); }); QUnit.test("Test: \"HEX2BIN\"", function (assert) { oParser = new parserFormula("HEX2BIN(\"2a\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2BIN(\"2a\")"); assert.strictEqual(oParser.calculate().getValue(), "101010"); oParser = new parserFormula("HEX2BIN(\"fffffffe00\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2BIN(\"fffffffe00\")"); assert.strictEqual(oParser.calculate().getValue(), "1000000000"); oParser = new parserFormula("HEX2BIN(\"fffffffe01\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2BIN(\"fffffffe01\")"); assert.strictEqual(oParser.calculate().getValue(), "1000000001"); oParser = new parserFormula("HEX2BIN(\"ffffffffff\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2BIN(\"ffffffffff\")"); assert.strictEqual(oParser.calculate().getValue(), "1111111111"); oParser = new parserFormula("HEX2BIN(0)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2BIN(0)"); assert.strictEqual(oParser.calculate().getValue(), "0"); oParser = new parserFormula("HEX2BIN(1)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2BIN(1)"); assert.strictEqual(oParser.calculate().getValue(), "1"); oParser = new parserFormula("HEX2BIN(\"1fe\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2BIN(\"1fe\")"); assert.strictEqual(oParser.calculate().getValue(), "111111110"); oParser = new parserFormula("HEX2BIN(\"1ff\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2BIN(\"1ff\")"); assert.strictEqual(oParser.calculate().getValue(), "111111111"); oParser = new parserFormula("HEX2BIN(\"2a\",6)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2BIN(\"2a\",6)"); assert.strictEqual(oParser.calculate().getValue(), "101010"); oParser = new parserFormula("HEX2BIN(\"2a\",8)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2BIN(\"2a\",8)"); assert.strictEqual(oParser.calculate().getValue(), "00101010"); oParser = new parserFormula("HEX2BIN(\"Hello World!\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2BIN(\"Hello World!\")"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("HEX2BIN(\"fffffffdff\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2BIN(\"fffffffdff\")"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("HEX2BIN(\"200\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2BIN(\"200\")"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("HEX2BIN(\"2a\", 5)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2BIN(\"2a\",5)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("HEX2BIN(\"2a\", -8)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2BIN(\"2a\",-8)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("HEX2BIN(\"2a\", \"Hello World!\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2BIN(\"2a\",\"Hello World!\")"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); testArrayFormula2(assert, "HEX2BIN", 1, 2, true); }); QUnit.test("Test: \"HEX2DEC\"", function (assert) { oParser = new parserFormula("HEX2DEC(\"2a\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2DEC(\"2a\")"); assert.strictEqual(oParser.calculate().getValue(), 42); oParser = new parserFormula("HEX2DEC(\"8000000000\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2DEC(\"8000000000\")"); assert.strictEqual(oParser.calculate().getValue(), -549755813888); oParser = new parserFormula("HEX2DEC(\"ffffffffff\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2DEC(\"ffffffffff\")"); assert.strictEqual(oParser.calculate().getValue(), -1); oParser = new parserFormula("HEX2DEC(\"0\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2DEC(\"0\")"); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("HEX2DEC(\"1\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2DEC(\"1\")"); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("HEX2DEC(0)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2DEC(0)"); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("HEX2DEC(1)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2DEC(1)"); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("HEX2DEC(\"7fffffffff\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2DEC(\"7fffffffff\")"); assert.strictEqual(oParser.calculate().getValue(), 549755813887); testArrayFormula2(assert, "HEX2DEC", 1, 1, true); }); QUnit.test("Test: \"HEX2OCT\"", function (assert) { oParser = new parserFormula("HEX2OCT(\"2a\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2OCT(\"2a\")"); assert.strictEqual(oParser.calculate().getValue(), "52"); oParser = new parserFormula("HEX2OCT(\"ffe0000000\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2OCT(\"ffe0000000\")"); assert.strictEqual(oParser.calculate().getValue(), "4000000000"); oParser = new parserFormula("HEX2OCT(\"ffe0000001\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2OCT(\"ffe0000001\")"); assert.strictEqual(oParser.calculate().getValue(), "4000000001"); oParser = new parserFormula("HEX2OCT(0)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2OCT(0)"); assert.strictEqual(oParser.calculate().getValue(), "0"); oParser = new parserFormula("HEX2OCT(1)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2OCT(1)"); assert.strictEqual(oParser.calculate().getValue(), "1"); oParser = new parserFormula("HEX2OCT(\"1ffffffe\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2OCT(\"1ffffffe\")"); assert.strictEqual(oParser.calculate().getValue(), "3777777776"); oParser = new parserFormula("HEX2OCT(\"1fffffff\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2OCT(\"1fffffff\")"); assert.strictEqual(oParser.calculate().getValue(), "3777777777"); oParser = new parserFormula("HEX2OCT(\"2a\",2)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2OCT(\"2a\",2)"); assert.strictEqual(oParser.calculate().getValue(), "52"); oParser = new parserFormula("HEX2OCT(\"2a\",4)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2OCT(\"2a\",4)"); assert.strictEqual(oParser.calculate().getValue(), "0052"); oParser = new parserFormula("HEX2OCT(\"Hello World!\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2OCT(\"Hello World!\")"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("HEX2OCT(\"ffdfffffff\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2OCT(\"ffdfffffff\")"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("HEX2OCT(\"2a\", 1)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "HEX2OCT(\"2a\",1)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); testArrayFormula2(assert, "HEX2OCT", 1, 2, true); }); QUnit.test("Test: \"OCT2BIN\"", function (assert) { oParser = new parserFormula("OCT2BIN(\"52\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2BIN(\"52\")"); assert.strictEqual(oParser.calculate().getValue(), "101010"); oParser = new parserFormula("OCT2BIN(\"7777777000\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2BIN(\"7777777000\")"); assert.strictEqual(oParser.calculate().getValue(), "1000000000"); oParser = new parserFormula("OCT2BIN(\"7777777001\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2BIN(\"7777777001\")"); assert.strictEqual(oParser.calculate().getValue(), "1000000001"); oParser = new parserFormula("OCT2BIN(\"7777777777\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2BIN(\"7777777777\")"); assert.strictEqual(oParser.calculate().getValue(), "1111111111"); oParser = new parserFormula("OCT2BIN(\"0\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2BIN(\"0\")"); assert.strictEqual(oParser.calculate().getValue(), "0"); oParser = new parserFormula("OCT2BIN(\"1\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2BIN(\"1\")"); assert.strictEqual(oParser.calculate().getValue(), "1"); oParser = new parserFormula("OCT2BIN(\"776\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2BIN(\"776\")"); assert.strictEqual(oParser.calculate().getValue(), "111111110"); oParser = new parserFormula("OCT2BIN(\"777\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2BIN(\"777\")"); assert.strictEqual(oParser.calculate().getValue(), "111111111"); oParser = new parserFormula("OCT2BIN(\"52\", 6)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2BIN(\"52\",6)"); assert.strictEqual(oParser.calculate().getValue(), "101010"); oParser = new parserFormula("OCT2BIN(\"52\", 8)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2BIN(\"52\",8)"); assert.strictEqual(oParser.calculate().getValue(), "00101010"); oParser = new parserFormula("OCT2BIN(\"Hello World!\", 8)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2BIN(\"Hello World!\",8)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("OCT2BIN(\"52\",\"Hello World!\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2BIN(\"52\",\"Hello World!\")"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); testArrayFormula2(assert, "OCT2BIN", 1, 2, true) }); QUnit.test("Test: \"OCT2DEC\"", function (assert) { oParser = new parserFormula("OCT2DEC(\"52\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2DEC(\"52\")"); assert.strictEqual(oParser.calculate().getValue(), 42); oParser = new parserFormula("OCT2DEC(\"4000000000\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2DEC(\"4000000000\")"); assert.strictEqual(oParser.calculate().getValue(), -536870912); oParser = new parserFormula("OCT2DEC(\"7777777777\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2DEC(\"7777777777\")"); assert.strictEqual(oParser.calculate().getValue(), -1); oParser = new parserFormula("OCT2DEC(\"0\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2DEC(\"0\")"); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("OCT2DEC(\"1\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2DEC(\"1\")"); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("OCT2DEC(\"3777777776\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2DEC(\"3777777776\")"); assert.strictEqual(oParser.calculate().getValue(), 536870910); oParser = new parserFormula("OCT2DEC(\"3777777777\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2DEC(\"3777777777\")"); assert.strictEqual(oParser.calculate().getValue(), 536870911); oParser = new parserFormula("OCT2DEC(\"3777777777\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2DEC(\"3777777777\")"); assert.strictEqual(oParser.calculate().getValue(), 536870911); testArrayFormula2(assert, "OCT2DEC", 1, 1, true); }); QUnit.test("Test: \"OCT2HEX\"", function (assert) { oParser = new parserFormula("OCT2HEX(\"52\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2HEX(\"52\")"); assert.strictEqual(oParser.calculate().getValue(), "2A"); oParser = new parserFormula("OCT2HEX(\"4000000000\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2HEX(\"4000000000\")"); assert.strictEqual(oParser.calculate().getValue(), "FFE0000000"); oParser = new parserFormula("OCT2HEX(\"4000000001\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2HEX(\"4000000001\")"); assert.strictEqual(oParser.calculate().getValue(), "FFE0000001"); oParser = new parserFormula("OCT2HEX(\"7777777777\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2HEX(\"7777777777\")"); assert.strictEqual(oParser.calculate().getValue(), "FFFFFFFFFF"); oParser = new parserFormula("OCT2HEX(\"0\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2HEX(\"0\")"); assert.strictEqual(oParser.calculate().getValue(), "0"); oParser = new parserFormula("OCT2HEX(\"1\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2HEX(\"1\")"); assert.strictEqual(oParser.calculate().getValue(), "1"); oParser = new parserFormula("OCT2HEX(\"3777777776\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2HEX(\"3777777776\")"); assert.strictEqual(oParser.calculate().getValue(), "1FFFFFFE"); oParser = new parserFormula("OCT2HEX(\"3777777777\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2HEX(\"3777777777\")"); assert.strictEqual(oParser.calculate().getValue(), "1FFFFFFF"); oParser = new parserFormula("OCT2HEX(\"52\", 2)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2HEX(\"52\",2)"); assert.strictEqual(oParser.calculate().getValue(), "2A"); oParser = new parserFormula("OCT2HEX(\"52\", 4)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2HEX(\"52\",4)"); assert.strictEqual(oParser.calculate().getValue(), "002A"); oParser = new parserFormula("OCT2HEX(\"Hello World!\", 4)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2HEX(\"Hello World!\",4)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("OCT2HEX(\"52\", -4)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2HEX(\"52\",-4)"); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("OCT2HEX(\"52\", \"Hello World!\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "OCT2HEX(\"52\",\"Hello World!\")"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); testArrayFormula2(assert, "OCT2HEX", 1, 2, true) }); QUnit.test("Test: \"COMPLEX\"", function (assert) { oParser = new parserFormula("COMPLEX(-3.5,19.6)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "COMPLEX(-3.5,19.6)"); assert.strictEqual(oParser.calculate().getValue(), "-3.5+19.6i"); oParser = new parserFormula("COMPLEX(3.5,-19.6,\"j\")", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "COMPLEX(3.5,-19.6,\"j\")"); assert.strictEqual(oParser.calculate().getValue(), "3.5-19.6j"); oParser = new parserFormula("COMPLEX(3.5,0)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "COMPLEX(3.5,0)"); assert.strictEqual(oParser.calculate().getValue(), "3.5"); oParser = new parserFormula("COMPLEX(0,2.4)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "COMPLEX(0,2.4)"); assert.strictEqual(oParser.calculate().getValue(), "2.4i"); oParser = new parserFormula("COMPLEX(0,0)", "A2", ws); assert.ok(oParser.parse()); assert.ok(oParser.assemble() == "COMPLEX(0,0)"); assert.strictEqual(oParser.calculate().getValue(), "0"); testArrayFormula2(assert, "COMPLEX", 2, 3, true); }); QUnit.test("Test: \"DELTA\"", function (assert) { oParser = new parserFormula("DELTA(10.5,10.5)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("DELTA(10.5,10.6)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("DELTA(10.5)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("DELTA(0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); testArrayFormula2(assert, "DELTA", 1, 2, true); }); QUnit.test("Test: \"ERF\"", function (assert) { oParser = new parserFormula("ERF(1.234,4.5432)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(14) - 0, 0.08096058291050978.toFixed(14) - 0); oParser = new parserFormula("ERF(1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(14) - 0, 0.8427007929497149.toFixed(14) - 0); oParser = new parserFormula("ERF(0,1.345)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(14) - 0, 0.9428441710878559.toFixed(14) - 0); oParser = new parserFormula("ERF(1.234)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(14) - 0, 0.9190394169576684.toFixed(14) - 0); testArrayFormula2(assert, "ERF", 1, 2, true); }); QUnit.test("Test: \"GESTEP\"", function (assert) { oParser = new parserFormula("GESTEP(5, 4)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("GESTEP(5, 5)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("GESTEP(-4, -5)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("GESTEP(-1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); testArrayFormula2(assert, "GESTEP", 1, 2, true); }); QUnit.test("Test: \"ERF.PRECISE\"", function (assert) { oParser = new parserFormula("ERF.PRECISE(1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(14) - 0, 0.8427007929497149.toFixed(14) - 0); oParser = new parserFormula("ERF.PRECISE(1.234)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(14) - 0, 0.9190394169576684.toFixed(14) - 0); oParser = new parserFormula("ERF.PRECISE(0.745)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 0.70792892); oParser = new parserFormula("ERF.PRECISE(1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 0.84270079); testArrayFormula2(assert, "ERF.PRECISE", 1, 1, true); }); QUnit.test("Test: \"ERFC\"", function (assert) { oParser = new parserFormula("ERFC(1.234)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(14) - 0, 0.08096058304233157.toFixed(14) - 0); oParser = new parserFormula("ERFC(1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(14) - 0, 0.15729920705028513.toFixed(14) - 0); oParser = new parserFormula("ERFC(0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("ERFC(-1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(14) - 0, 1.8427007929497148.toFixed(14) - 0); testArrayFormula2(assert, "ERFC", 1, 1, true); }); QUnit.test("Test: \"ERFC.PRECISE\"", function (assert) { oParser = new parserFormula("ERFC.PRECISE(1.234)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(14) - 0, 0.08096058304233157.toFixed(14) - 0); oParser = new parserFormula("ERFC.PRECISE(1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(14) - 0, 0.15729920705028513.toFixed(14) - 0); oParser = new parserFormula("ERFC.PRECISE(0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula("ERFC.PRECISE(-1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(14) - 0, 1.8427007929497148.toFixed(14) - 0); }); QUnit.test("Test: \"BITAND\"", function (assert) { oParser = new parserFormula('BITAND(1,5)', "AA2", ws); assert.ok(oParser.parse(), 'BITAND(1,5)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'BITAND(1,5)'); oParser = new parserFormula('BITAND(13,25)', "AA2", ws); assert.ok(oParser.parse(), 'BITAND(13,25)'); assert.strictEqual(oParser.calculate().getValue(), 9, 'BITAND(13,25)'); testArrayFormula2(assert, "BITAND", 2, 2); }); QUnit.test("Test: \"BITOR\"", function (assert) { oParser = new parserFormula('BITOR(23,10)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 31); testArrayFormula2(assert, "BITOR", 2, 2); }); QUnit.test("Test: \"BITXOR\"", function (assert) { oParser = new parserFormula('BITXOR(5,3)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 6); testArrayFormula2(assert, "BITXOR", 2, 2); }); QUnit.test("Test: \"BITRSHIFT\"", function (assert) { oParser = new parserFormula('BITRSHIFT(13,2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); testArrayFormula2(assert, "BITRSHIFT", 2, 2); }); QUnit.test("Test: \"BITLSHIFT\"", function (assert) { oParser = new parserFormula('BITLSHIFT(4,2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 16); testArrayFormula2(assert, "BITLSHIFT", 2, 2); }); function putDataForDatabase() { ws.getRange2("A1").setValue("Tree"); ws.getRange2("A2").setValue("Apple"); ws.getRange2("A3").setValue("Pear"); ws.getRange2("A4").setValue("Tree"); ws.getRange2("A5").setValue("Apple"); ws.getRange2("A6").setValue("Pear"); ws.getRange2("A7").setValue("Cherry"); ws.getRange2("A8").setValue("Apple"); ws.getRange2("A9").setValue("Pear"); ws.getRange2("A10").setValue("Apple"); ws.getRange2("B1").setValue("Height"); ws.getRange2("B2").setValue(">10"); ws.getRange2("B3").setValue(""); ws.getRange2("B4").setValue("Height"); ws.getRange2("B5").setValue("18"); ws.getRange2("B6").setValue("12"); ws.getRange2("B7").setValue("13"); ws.getRange2("B8").setValue("14"); ws.getRange2("B9").setValue("9"); ws.getRange2("B10").setValue("8"); ws.getRange2("C1").setValue("Age"); ws.getRange2("C2").setValue(""); ws.getRange2("C3").setValue(""); ws.getRange2("C4").setValue("Age"); ws.getRange2("C5").setValue("20"); ws.getRange2("C6").setValue("12"); ws.getRange2("C7").setValue("14"); ws.getRange2("C8").setValue("15"); ws.getRange2("C9").setValue("8"); ws.getRange2("C10").setValue("9"); ws.getRange2("C1").setValue("Age"); ws.getRange2("C2").setValue(""); ws.getRange2("C3").setValue(""); ws.getRange2("C4").setValue("Age"); ws.getRange2("C5").setValue("20"); ws.getRange2("C6").setValue("12"); ws.getRange2("C7").setValue("14"); ws.getRange2("C8").setValue("15"); ws.getRange2("C9").setValue("8"); ws.getRange2("C10").setValue("9"); ws.getRange2("D1").setValue("Yield"); ws.getRange2("D2").setValue(""); ws.getRange2("D3").setValue(""); ws.getRange2("D4").setValue("Yield"); ws.getRange2("D5").setValue("14"); ws.getRange2("D6").setValue("10"); ws.getRange2("D7").setValue("9"); ws.getRange2("D8").setValue("10"); ws.getRange2("D9").setValue("8"); ws.getRange2("D10").setValue("6"); ws.getRange2("E1").setValue("Profit"); ws.getRange2("E2").setValue(""); ws.getRange2("E3").setValue(""); ws.getRange2("E4").setValue("Profit"); ws.getRange2("E5").setValue("105"); ws.getRange2("E6").setValue("96"); ws.getRange2("E7").setValue("105"); ws.getRange2("E8").setValue("75"); ws.getRange2("E9").setValue("76.8"); ws.getRange2("E10").setValue("45"); ws.getRange2("F1").setValue("Height"); ws.getRange2("F2").setValue("<16"); ws.getRange2("F3").setValue(""); } //database formulas QUnit.test("Test: \"DAVERAGE\"", function (assert) { putDataForDatabase(); oParser = new parserFormula('DAVERAGE(A4:E10, "Yield", A1:B2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 12); oParser = new parserFormula('DAVERAGE(A4:E10, 3, A4:E10)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 13); ws.getRange2("G1").setValue("Profit"); ws.getRange2("G2").setValue("555"); oParser = new parserFormula('DAVERAGE(A4:E10, "Age",G1:G2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!"); ws.getRange2("G1").setValue("noname"); oParser = new parserFormula('DAVERAGE(A4:E10, "Age",G1:G2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 13); }); QUnit.test("Test: \"DCOUNT\"", function (assert) { putDataForDatabase(); oParser = new parserFormula('DCOUNT(A4:E10, "Age", A1:F2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula('DCOUNT(A4:E10,, A1:F2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula('DCOUNT(A4:E10,"", A1:F2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); ws.getRange2("G1").setValue("Profit"); ws.getRange2("G2").setValue("555"); oParser = new parserFormula('DCOUNT(A4:E10, "Age",G1:G2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); ws.getRange2("G1").setValue("noname"); oParser = new parserFormula('DCOUNT(A4:E10, "Age",G1:G2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 6); }); QUnit.test("Test: \"DCOUNTA\"", function (assert) { putDataForDatabase(); oParser = new parserFormula('DCOUNTA(A4:E10, "Profit", A1:F2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula('DCOUNTA(A4:E10,, A1:F2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula('DCOUNTA(A4:E10,"", A1:F2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); ws.getRange2("G1").setValue("Profit"); ws.getRange2("G2").setValue("555"); oParser = new parserFormula('DCOUNTA(A4:E10, "Age",G1:G2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); ws.getRange2("G1").setValue("noname"); oParser = new parserFormula('DCOUNTA(A4:E10, "Age",G1:G2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 6); }); QUnit.test("Test: \"DGET\"", function (assert) { putDataForDatabase(); oParser = new parserFormula('DGET(A4:E10, "Yield", A1:A3)', "AA2", ws); assert.ok(oParser.parse(), 'DGET(A4:E10, "Yield", A1:A3)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'DGET(A4:E10, "Yield", A1:A3)'); oParser = new parserFormula('DGET(A4:E10, "Yield", A1:F2)', "AA2", ws); assert.ok(oParser.parse(), 'DGET(A4:E10, "Yield", A1:F2)'); assert.strictEqual(oParser.calculate().getValue(), 10, 'DGET(A4:E10, "Yield", A1:F2)'); ws.getRange2("G1").setValue("Profit"); ws.getRange2("G2").setValue("555"); oParser = new parserFormula('DGET(A4:E10, "Age",G1:G2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); ws.getRange2("G1").setValue("noname"); oParser = new parserFormula('DGET(A4:E10, "Age",G1:G2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); }); QUnit.test("Test: \"DMAX\"", function (assert) { putDataForDatabase(); oParser = new parserFormula('DMAX(A4:E10, "Profit", A1:F3)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 96); ws.getRange2("G1").setValue("Profit"); ws.getRange2("G2").setValue("555"); oParser = new parserFormula('DMAX(A4:E10, "Age",G1:G2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); ws.getRange2("G1").setValue("noname"); oParser = new parserFormula('DMAX(A4:E10, "Age",G1:G2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 20); }); QUnit.test("Test: \"DMIN\"", function (assert) { putDataForDatabase(); oParser = new parserFormula('DMIN(A4:E10, "Profit", A1:F3)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 75); ws.getRange2("G1").setValue("Profit"); ws.getRange2("G2").setValue("555"); oParser = new parserFormula('DMIN(A4:E10, "Age",G1:G2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); ws.getRange2("G1").setValue("noname"); oParser = new parserFormula('DMIN(A4:E10, "Age",G1:G2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 8); }); QUnit.test("Test: \"DPRODUCT\"", function (assert) { putDataForDatabase(); oParser = new parserFormula('DPRODUCT(A4:E10, "Yield", A1:F3)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 800); ws.getRange2("G1").setValue("Profit"); ws.getRange2("G2").setValue("555"); oParser = new parserFormula('DPRODUCT(A4:E10, "Age",G1:G2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); ws.getRange2("G1").setValue("noname"); oParser = new parserFormula('DPRODUCT(A4:E10, "Age",G1:G2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3628800); }); QUnit.test("Test: \"DSTDEV\"", function (assert) { putDataForDatabase(); oParser = new parserFormula('DSTDEV(A4:E10, "Yield", A1:F3)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(4) - 0, 1.1547); ws.getRange2("G1").setValue("Profit"); ws.getRange2("G2").setValue("555"); oParser = new parserFormula('DSTDEV(A4:E10, "Age",G1:G2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!"); ws.getRange2("G1").setValue("noname"); oParser = new parserFormula('DSTDEV(A4:E10, "Age",G1:G2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4.381780460041329); }); QUnit.test("Test: \"DSTDEVP\"", function (assert) { putDataForDatabase(); oParser = new parserFormula('DSTDEVP(A4:E10, "Yield", A1:F3)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(6) - 0, 0.942809); ws.getRange2("G1").setValue("Profit"); ws.getRange2("G2").setValue("555"); oParser = new parserFormula('DSTDEVP(A4:E10, "Age",G1:G2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!"); ws.getRange2("G1").setValue("noname"); oParser = new parserFormula('DSTDEV(A4:E10, "Age",G1:G2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4.381780460041329); }); QUnit.test("Test: \"STDEVPA\"", function (assert) { ws.getRange2("A103").setValue("1345"); ws.getRange2("A104").setValue("1301"); ws.getRange2("A105").setValue("1368"); ws.getRange2("A106").setValue("1322"); ws.getRange2("A107").setValue("1310"); ws.getRange2("A108").setValue("1370"); ws.getRange2("A109").setValue("1318"); ws.getRange2("A110").setValue("1350"); ws.getRange2("A111").setValue("1303"); ws.getRange2("A112").setValue("1299"); oParser = new parserFormula('STDEVPA(A103:A112)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(5) - 0, 26.05456); testArrayFormula2(assert, "STDEVPA", 1, 8, null, true); }); QUnit.test("Test: \"STDEVP\"", function (assert) { ws.getRange2("A103").setValue("1345"); ws.getRange2("A104").setValue("1301"); ws.getRange2("A105").setValue("1368"); ws.getRange2("A106").setValue("1322"); ws.getRange2("A107").setValue("1310"); ws.getRange2("A108").setValue("1370"); ws.getRange2("A109").setValue("1318"); ws.getRange2("A110").setValue("1350"); ws.getRange2("A111").setValue("1303"); ws.getRange2("A112").setValue("1299"); oParser = new parserFormula('STDEVP(A103:A112)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(5) - 0, 26.05456); testArrayFormula2(assert, "STDEVP", 1, 8, null, true); }); QUnit.test("Test: \"STDEV\"", function (assert) { ws.getRange2("A103").setValue("1345"); ws.getRange2("A104").setValue("1301"); ws.getRange2("A105").setValue("1368"); ws.getRange2("A106").setValue("1322"); ws.getRange2("A107").setValue("1310"); ws.getRange2("A108").setValue("1370"); ws.getRange2("A109").setValue("1318"); ws.getRange2("A110").setValue("1350"); ws.getRange2("A111").setValue("1303"); ws.getRange2("A112").setValue("1299"); oParser = new parserFormula('STDEV(A103:A112)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(5) - 0, 27.46392); testArrayFormula2(assert, "STDEV", 1, 8, null, true); }); QUnit.test("Test: \"DSUM\"", function (assert) { putDataForDatabase(); oParser = new parserFormula('DSUM(A4:E10,"Profit",A1:A2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 225); oParser = new parserFormula('DSUM(A4:E10,"Profit", A1:F3)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 247.8); oParser = new parserFormula('DSUM(A4:E10, "Age",A1:F2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 15); oParser = new parserFormula('DSUM(A4:E10, "Age","test")', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula('DSUM(A4:E10, "Age",E2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); ws.getRange2("G1").setValue("Profit"); ws.getRange2("G2").setValue("555"); oParser = new parserFormula('DSUM(A4:E10, "Age",G1:G2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); ws.getRange2("G1").setValue("noname"); oParser = new parserFormula('DSUM(A4:E10, "Age",G1:G2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 78); }); QUnit.test("Test: \"DVAR\"", function (assert) { putDataForDatabase(); oParser = new parserFormula('DVAR(A4:E10, "Yield", A1:A3)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(1) - 0, 8.8); ws.getRange2("G1").setValue("Profit"); ws.getRange2("G2").setValue("555"); oParser = new parserFormula('DSTDEVP(A4:E10, "Age",G1:G2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!"); ws.getRange2("G1").setValue("noname"); oParser = new parserFormula('DVAR(A4:E10, "Age",G1:G2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 19.2); }); QUnit.test("Test: \"DVARP\"", function (assert) { putDataForDatabase(); oParser = new parserFormula('DVARP(A4:E10, "Yield", A1:A3)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 7.04); ws.getRange2("G1").setValue("Profit"); ws.getRange2("G2").setValue("555"); oParser = new parserFormula('DSTDEVP(A4:E10, "Age",G1:G2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#DIV/0!"); ws.getRange2("G1").setValue("noname"); oParser = new parserFormula('DVARP(A4:E10, "Age",G1:G2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 16); }); QUnit.test("Test: \"UNICODE\"", function (assert) { oParser = new parserFormula('UNICODE(" ")', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 32); oParser = new parserFormula('UNICODE("B")', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 66); oParser = new parserFormula('UNICODE(0)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 48); oParser = new parserFormula('UNICODE(1)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 49); oParser = new parserFormula('UNICODE("true")', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 116); oParser = new parserFormula('UNICODE(#N/A)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); }); QUnit.test("Test: \"UNICHAR\"", function (assert) { oParser = new parserFormula('UNICHAR(66)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "B"); oParser = new parserFormula('UNICHAR(32)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), " "); oParser = new parserFormula('UNICHAR(0)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula('UNICHAR(48)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "0"); oParser = new parserFormula('UNICHAR(49)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "1"); }); QUnit.test("Test: \"UPPER\"", function (assert) { ws.getRange2("A2").setValue("total"); ws.getRange2("A3").setValue("Yield"); oParser = new parserFormula('UPPER(A2)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TOTAL"); oParser = new parserFormula('UPPER(A3)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "YIELD"); testArrayFormula2(assert, "UPPER", 1, 1); }); QUnit.test("Test: \"UNIQUE \"", function (assert) { ws.getRange2("A101").setValue("1"); ws.getRange2("A102").setValue("2"); ws.getRange2("A103").setValue("2"); ws.getRange2("A104").setValue("-1"); ws.getRange2("A105").setValue("-1"); ws.getRange2("A106").setValue("ds"); ws.getRange2("A107").setValue("ds"); ws.getRange2("A108").setValue("#NUM!"); ws.getRange2("A109").setValue("#NUM!"); ws.getRange2("B101").setValue("1"); ws.getRange2("B102").setValue("2"); ws.getRange2("B103").setValue("2"); ws.getRange2("B104").setValue("4"); ws.getRange2("B105").setValue("5"); ws.getRange2("B106").setValue("7"); ws.getRange2("B107").setValue("7"); ws.getRange2("B108").setValue("8"); ws.getRange2("B109").setValue("8"); ws.getRange2("C101").setValue("2"); ws.getRange2("C102").setValue("2"); ws.getRange2("C103").setValue("2"); ws.getRange2("C104").setValue("1"); ws.getRange2("C105").setValue("1"); ws.getRange2("C106").setValue("2"); ws.getRange2("C107").setValue("3"); ws.getRange2("C108").setValue("8"); ws.getRange2("C109").setValue("8"); ws.getRange2("D101").setValue("2"); ws.getRange2("D102").setValue("2"); ws.getRange2("D103").setValue("2"); ws.getRange2("D104").setValue("1"); ws.getRange2("D105").setValue("1"); ws.getRange2("D106").setValue("2"); ws.getRange2("D107").setValue("3"); ws.getRange2("D108").setValue("8"); ws.getRange2("D109").setValue("8"); oParser = new parserFormula("UNIQUE(A101:A109)", "F1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(2, 0).getValue(), -1); assert.strictEqual(oParser.calculate().getElementRowCol(3, 0).getValue(), "ds"); assert.strictEqual(oParser.calculate().getElementRowCol(4, 0).getValue(), "#NUM!"); oParser = new parserFormula("UNIQUE(A101:A109)", "F1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(2, 0).getValue(), -1); assert.strictEqual(oParser.calculate().getElementRowCol(3, 0).getValue(), "ds"); assert.strictEqual(oParser.calculate().getElementRowCol(4, 0).getValue(), "#NUM!"); oParser = new parserFormula("UNIQUE(A101:D101)", "F1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(0, 2).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(0, 3).getValue(), 2); oParser = new parserFormula("UNIQUE(A101:D101, true)", "F1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue(), 2); oParser = new parserFormula("UNIQUE(A101:D101, true, true)", "F1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); ws.getRange2("F102").setValue("test"); ws.getRange2("F103").setValue("#VALUE!"); ws.getRange2("F104").setValue("test"); ws.getRange2("F105").setValue("#VALUE!"); ws.getRange2("F106").setValue("2"); ws.getRange2("F107").setValue("-3"); ws.getRange2("G102").setValue("2"); ws.getRange2("G103").setValue("yyy"); ws.getRange2("G104").setValue("4"); ws.getRange2("G105").setValue("yyy"); ws.getRange2("G106").setValue("asd"); ws.getRange2("G107").setValue("7"); ws.getRange2("H102").setValue("test"); ws.getRange2("H103").setValue("#VALUE!"); ws.getRange2("H104").setValue("test"); ws.getRange2("H105").setValue("#VALUE!"); ws.getRange2("H106").setValue("2"); ws.getRange2("H107").setValue("-3"); ws.getRange2("I102").setValue("2"); ws.getRange2("I103").setValue("123"); ws.getRange2("I104").setValue("4"); ws.getRange2("I105").setValue("123"); ws.getRange2("I106").setValue("6"); ws.getRange2("I107").setValue("4"); oParser = new parserFormula("UNIQUE(F102:I107)", "F1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 2).getValue(), "test"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 2).getValue(), "#VALUE!"); assert.strictEqual(oParser.calculate().getElementRowCol(2, 2).getValue(), "test"); assert.strictEqual(oParser.calculate().getElementRowCol(3, 2).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(4, 2).getValue(), -3); oParser = new parserFormula("UNIQUE(F102:I107, true)", "F1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 2).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(1, 2).getValue(), 123); assert.strictEqual(oParser.calculate().getElementRowCol(2, 2).getValue(), 4); assert.strictEqual(oParser.calculate().getElementRowCol(3, 2).getValue(), 123); assert.strictEqual(oParser.calculate().getElementRowCol(4, 2).getValue(), 6); assert.strictEqual(oParser.calculate().getElementRowCol(5, 2).getValue(), 4); oParser = new parserFormula("UNIQUE(F102:I107, false, true)", "F1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), "test"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 1).getValue(), 4); assert.strictEqual(oParser.calculate().getElementRowCol(2, 2).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(3, 3).getValue(), 4); oParser = new parserFormula("UNIQUE(F102:I107, true, true)", "F1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue(), 2); assert.strictEqual(oParser.calculate().getElementRowCol(1, 1).getValue(), 123); assert.strictEqual(oParser.calculate().getElementRowCol(2, 1).getValue(), 4); assert.strictEqual(oParser.calculate().getElementRowCol(3, 1).getValue(), 123); assert.strictEqual(oParser.calculate().getElementRowCol(4, 1).getValue(), 6); assert.strictEqual(oParser.calculate().getElementRowCol(5, 1).getValue(), 4); ws.getRange2("A120").setValue("1"); ws.getRange2("B120").setValue("2"); oParser = new parserFormula("UNIQUE(A120:B120)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1); oParser = new parserFormula("UNIQUE({1;2})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1); oParser = new parserFormula("UNIQUE({1,2})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1); }); QUnit.test("Test: \"GROWTH\"", function (assert) { ws.getRange2("A102").setValue("11"); ws.getRange2("A103").setValue("12"); ws.getRange2("A104").setValue("13"); ws.getRange2("A105").setValue("14"); ws.getRange2("A106").setValue("15"); ws.getRange2("A107").setValue("16"); ws.getRange2("B102").setValue("33100"); ws.getRange2("B103").setValue("47300"); ws.getRange2("B104").setValue("69000"); ws.getRange2("B105").setValue("102000"); ws.getRange2("B106").setValue("150000"); ws.getRange2("B107").setValue("220000"); ws.getRange2("C102").setValue("32618"); ws.getRange2("C103").setValue("47729"); ws.getRange2("C104").setValue("69841"); ws.getRange2("C105").setValue("102197"); ws.getRange2("C106").setValue("149542"); ws.getRange2("C107").setValue("218822"); ws.getRange2("A109").setValue("17"); ws.getRange2("A110").setValue("18"); oParser = new parserFormula("GROWTH(B102:B107,A102:A107,A109:A110)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(4) - 0, 320196.7184); oParser = new parserFormula("GROWTH(B102:B107,A102:A107)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(5) - 0, 32618.20377); oParser = new parserFormula("GROWTH(A102:C102,A103:C104,A105:C106,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 11.00782679); oParser = new parserFormula("GROWTH(A102:C102,A103:C104,A105:C106,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 11.00782679); oParser = new parserFormula("GROWTH(A103:C103,A104:C105,A106:C107,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 12.00187209); oParser = new parserFormula("GROWTH(A103:C103,A104:C105,A106:C107,10)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 12.00187209); oParser = new parserFormula("GROWTH(A103:C103,A104:C105,A106:C107,0)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1.0017632); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(3) - 0, 12047829814.167); assert.strictEqual(oParser.calculate().getElementRowCol(0, 2).getValue().toFixed(3) - 0, 10705900594.962); oParser = new parserFormula("GROWTH({1,2,3},A104:C105,A106:C107,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1.00038318); oParser = new parserFormula("GROWTH({1,2,3},A104:C105,A106:C107,A106:C107)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula("GROWTH(A103:C103,A104:C105,A106:C107,1)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 12.00187209); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(3) - 0, 676231620.297); assert.strictEqual(oParser.calculate().getElementRowCol(0, 2).getValue().toFixed(3) - 0, 612512904.254) ws.getRange2("A120").setValue("1"); ws.getRange2("B120").setValue("2"); oParser = new parserFormula("GROWTH(A120:B120)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1); oParser = new parserFormula("GROWTH({1;2})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1); oParser = new parserFormula("GROWTH({1,2})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1); ws.getRange2("A200").setValue("1"); ws.getRange2("A201").setValue("2"); ws.getRange2("A202").setValue("3"); ws.getRange2("B200").setValue("1"); ws.getRange2("B201").setValue("2"); ws.getRange2("B202").setValue("3"); ws.getRange2("C200").setValue("1"); ws.getRange2("C201").setValue("2"); ws.getRange2("C202").setValue("3"); // different matrix length tests oParser = new parserFormula("GROWTH(A200:A201,A200:C200)", "A2", ws); assert.ok(oParser.parse(), "GROWTH(A200:A201,A200:C200)"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of GROWTH(A200:A201,A200:C200)"); oParser = new parserFormula("GROWTH(A200:A202,A200:C200)", "A2", ws); assert.ok(oParser.parse(), "GROWTH(A200:A202,A200:C200)"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of GROWTH(A200:A202,A200:C200)"); oParser = new parserFormula("GROWTH(A200:B201,A200:C201)", "A2", ws); assert.ok(oParser.parse(), "GROWTH(A200:B201,A200:C201)"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of GROWTH(A200:B201,A200:C201)"); oParser = new parserFormula("GROWTH({1,2,3},{1,2})", "A2", ws); assert.ok(oParser.parse(), "GROWTH({1,2,3},{1,2})"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of GROWTH({1,2,3},{1,2})"); oParser = new parserFormula("GROWTH({1,2,3},{1,2,3,4})", "A2", ws); assert.ok(oParser.parse(), "GROWTH({1,2,3},{1,2,3,4})"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of GROWTH({1,2,3},{1,2,3,4})"); oParser = new parserFormula("GROWTH({1,2;1,2},{1,2})", "A2", ws); assert.ok(oParser.parse(), "GROWTH({1,2;1,2},{1,2})"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of GROWTH({1,2;1,2},{1,2})"); oParser = new parserFormula("GROWTH(A200:B200,{1,2})", "A2", ws); assert.ok(oParser.parse(), "GROWTH(A200:B200,{1,2})"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1, "Result of GROWTH(A200:B200,{1,2})[0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue(), 1, "Result of GROWTH(A200:B200,{1,2})[0,1]"); // identical X-trend tests oParser = new parserFormula("GROWTH({1,1},{0,0})", "A2", ws); assert.ok(oParser.parse(), "GROWTH({1,1},{0,0})"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1, "Result of GROWTH({1,1},{0,0}) [0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(4) - 0, 1, "Result of GROWTH({1,1},{0,0}) [0,1]"); oParser = new parserFormula("GROWTH({123,123},{123,123})", "A2", ws); assert.ok(oParser.parse(), "GROWTH({123,123},{123,123})"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 123, "Result of GROWTH({123,123},{123,123}) [0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(4) - 0, 123, "Result of GROWTH({123,123},{123,123}) [0,1]"); oParser = new parserFormula("GROWTH({2,8},{1,1})", "A2", ws); assert.ok(oParser.parse(), "GROWTH({2,8},{1,1})"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 4, "Result of GROWTH({2,8},{1,1}) [0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(4) - 0, 4, "Result of GROWTH({2,8},{1,1}) [0,1]"); oParser = new parserFormula("GROWTH({2,8;1,1},{1,1;1,1})", "A2", ws); assert.ok(oParser.parse(), "GROWTH({2,8;1,1},{1,1;1,1})"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 2, "Result of GROWTH({2,8;1,1},{1,1;1,1}) [0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(4) - 0, 2, "Result of GROWTH({2,8;1,1},{1,1;1,1}) [0,1]"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue().toFixed(8) - 0, 2, "Result of GROWTH({2,8;1,1},{1,1;1,1}) [1,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 1).getValue().toFixed(4) - 0, 2, "Result of GROWTH({2,8;1,1},{1,1;1,1}) [1,1]"); oParser = new parserFormula("GROWTH({2,8;2,2;10,10},{1,1;1,1;1,1})", "A2", ws); assert.ok(oParser.parse(), "GROWTH({2,8;2,2;10,10},{1,1;1,1;1,1})"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 4.30886938, "Result of GROWTH({2,8;2,2;10,10},{1,1;1,1;1,1}) [0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(8) - 0, 4.30886938, "Result of GROWTH({2,8;2,2;10,10},{1,1;1,1;1,1}) [0,1]"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue().toFixed(8) - 0, 4.30886938, "Result of GROWTH({2,8;2,2;10,10},{1,1;1,1;1,1}) [1,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 1).getValue().toFixed(8) - 0, 4.30886938, "Result of GROWTH({2,8;2,2;10,10},{1,1;1,1;1,1}) [1,1]"); assert.strictEqual(oParser.calculate().getElementRowCol(2, 0).getValue().toFixed(8) - 0, 4.30886938, "Result of GROWTH({2,8;2,2;10,10},{1,1;1,1;1,1}) [2,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(2, 1).getValue().toFixed(8) - 0, 4.30886938, "Result of GROWTH({2,8;2,2;10,10},{1,1;1,1;1,1}) [2,1]"); }); QUnit.test("Test: \"LOGEST\"", function (assert) { ws.getRange2("A101").setValue("1"); ws.getRange2("A102").setValue("2"); ws.getRange2("A103").setValue("3"); ws.getRange2("A104").setValue("4"); ws.getRange2("A105").setValue("5"); ws.getRange2("A106").setValue("6"); ws.getRange2("A107").setValue("7"); ws.getRange2("A108").setValue("8"); ws.getRange2("A109").setValue("9"); ws.getRange2("A110").setValue("10"); ws.getRange2("A111").setValue("11"); ws.getRange2("A112").setValue("12"); ws.getRange2("B101").setValue("133890"); ws.getRange2("B102").setValue("135000"); ws.getRange2("B103").setValue("135790"); ws.getRange2("B104").setValue("137300"); ws.getRange2("B105").setValue("138130"); ws.getRange2("B106").setValue("139100"); ws.getRange2("B107").setValue("139900"); ws.getRange2("B108").setValue("141120"); ws.getRange2("B109").setValue("141890"); ws.getRange2("B110").setValue("143230"); ws.getRange2("B111").setValue("144000"); ws.getRange2("B112").setValue("145290"); ws.getRange2("A115").setValue("13"); ws.getRange2("A116").setValue("14"); ws.getRange2("A117").setValue("15"); ws.getRange2("A118").setValue("16"); ws.getRange2("A119").setValue("17"); oParser = new parserFormula("LOGEST(B101:B112,A101:A112)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1.00732561); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(4) - 0, 133044.8167); oParser = new parserFormula("LOGEST(B101:B112,A101:A112,,false)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1.00732561); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(4) - 0, 133044.8167); //todo необходимо перепроверить остальные значения в данном случае oParser = new parserFormula("LOGEST(B101:B112,A101:A112,,true)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1.00732561); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(4) - 0, 133044.8167); oParser = new parserFormula("LOGEST(B101:B112,A101:A112,true,true)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1.00732561); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(4) - 0, 133044.8167); //todo необходимо перепроверить остальные значения в данном случае oParser = new parserFormula("LOGEST(B101:B112,A101:A112,false,true)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 4.15001464); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(4) - 0, 1); oParser = new parserFormula("LOGEST(A101:B105,A106:B110,FALSE,TRUE)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1.0000838); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(4) - 0, 1); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue().toFixed(8) - 0, 0.00000264); assert.strictEqual(oParser.calculate().getElementRowCol(2, 0).getValue().toFixed(4) - 0, 0.9911); assert.strictEqual(oParser.calculate().getElementRowCol(3, 0).getValue().toFixed(4) - 0, 1005.3131); assert.strictEqual(oParser.calculate().getElementRowCol(4, 0).getValue().toFixed(4) - 0, 698.5684); oParser = new parserFormula("LOGEST(A101:B105,A106:B110,,)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1.00007701); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(4) - 0, 2.6063); oParser = new parserFormula("LOGEST(A101:B105,A106:B110,false,false)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1.0000838); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(4) - 0, 1); //todo необходимо перепроверить остальные значения в данном случае oParser = new parserFormula("LOGEST(A101:B105,A106:B110,true,true)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1.00007701); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(4) - 0, 2.6063); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue().toFixed(8) - 0, 0.00000205); assert.strictEqual(oParser.calculate().getElementRowCol(2, 0).getValue().toFixed(4) - 0, 0.9944); assert.strictEqual(oParser.calculate().getElementRowCol(3, 0).getValue().toFixed(4) - 0, 1416.4887); assert.strictEqual(oParser.calculate().getElementRowCol(4, 0).getValue().toFixed(4) - 0, 294.9627); ws.getRange2("A120").setValue("1"); ws.getRange2("B120").setValue("2"); oParser = new parserFormula("LOGEST(A120:B120)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 2); oParser = new parserFormula("LOGEST({1;2})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 2); oParser = new parserFormula("LOGEST({1,2})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 2); ws.getRange2("A200").setValue("1"); ws.getRange2("A201").setValue("2"); ws.getRange2("A202").setValue("3"); ws.getRange2("B200").setValue("1"); ws.getRange2("B201").setValue("2"); ws.getRange2("B202").setValue("3"); ws.getRange2("C200").setValue("1"); ws.getRange2("C201").setValue("2"); ws.getRange2("C202").setValue("3"); // different matrix length tests oParser = new parserFormula("LOGEST(A200:A201,A200:C200)", "A2", ws); assert.ok(oParser.parse(), "LOGEST(A200:A201,A200:C200)"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of LOGEST(A200:A201,A200:C200)"); oParser = new parserFormula("LOGEST(A200:A202,A200:C200)", "A2", ws); assert.ok(oParser.parse(), "LOGEST(A200:A202,A200:C200)"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of LOGEST(A200:A202,A200:C200)"); oParser = new parserFormula("LOGEST(A200:B201,A200:C201)", "A2", ws); assert.ok(oParser.parse(), "LOGEST(A200:B201,A200:C201)"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of LOGEST(A200:B201,A200:C201)"); oParser = new parserFormula("LOGEST({1,2,3},{1,2})", "A2", ws); assert.ok(oParser.parse(), "LOGEST({1,2,3},{1,2})"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of LOGEST({1,2,3},{1,2})"); oParser = new parserFormula("LOGEST({1,2,3},{1,2,3,4})", "A2", ws); assert.ok(oParser.parse(), "LOGEST({1,2,3},{1,2,3,4})"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of LOGEST({1,2,3},{1,2,3,4})"); oParser = new parserFormula("LOGEST({1,2;1,2},{1,2})", "A2", ws); assert.ok(oParser.parse(), "LOGEST({1,2;1,2},{1,2})"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of LOGEST({1,2;1,2},{1,2})"); oParser = new parserFormula("LOGEST(A200:B200,{1,2})", "A2", ws); assert.ok(oParser.parse(), "LOGEST(A200:B200,{1,2})"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1, "Result of LOGEST(A200:B200,{1,2})[0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue(), 1, "Result of LOGEST(A200:B200,{1,2})[0,1]"); // identical X-trend tests oParser = new parserFormula("LOGEST({1,1},{0,0})", "A2", ws); assert.ok(oParser.parse(), "LOGEST({1,1},{0,0})"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1, "Result of LOGEST({1,1},{0,0}) [0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(4) - 0, 1, "Result of LOGEST({1,1},{0,0}) [0,1]"); oParser = new parserFormula("LOGEST({123,123},{123,123})", "A2", ws); assert.ok(oParser.parse(), "LOGEST({123,123},{123,123})"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1, "Result of LOGEST({123,123},{123,123}) [0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(4) - 0, 123, "Result of LOGEST({123,123},{123,123}) [0,1]"); oParser = new parserFormula("LOGEST({2,8},{1,1})", "A2", ws); assert.ok(oParser.parse(), "LOGEST({2,8},{1,1})"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1, "Result of LOGEST({2,8},{1,1}) [0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(4) - 0, 4, "Result of LOGEST({2,8},{1,1}) [0,1]"); oParser = new parserFormula("LOGEST({2,8},{1,1},FALSE)", "A2", ws); assert.ok(oParser.parse(), "LOGEST({2,8},{1,1},FALSE)"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 4, "Result of LOGEST({2,8},{1,1},FALSE) [0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(4) - 0, 1, "Result of LOGEST({2,8},{1,1},FALSE) [0,1]"); oParser = new parserFormula("LOGEST({2,8},{1,1},FALSE,TRUE)", "A2", ws); assert.ok(oParser.parse(), "LOGEST({2,8},{1,1},FALSE,TRUE)"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 4, "Result of LOGEST({2,8},{1,1},FALSE,TRUE) [0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue(), 1, "Result of LOGEST({2,8},{1,1},FALSE,TRUE) [0,1]"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue().toFixed(5)-0, 0.69315, "Result of LOGEST({2,8},{1,1},FALSE,TRUE) [1,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 1).getValue(), "#N/A", "Result of LOGEST({2,8},{1,1},FALSE,TRUE) [1,1]"); assert.strictEqual(oParser.calculate().getElementRowCol(2, 0).getValue().toFixed(5)-0, 0.8, "Result of LOGEST({2,8},{1,1},FALSE,TRUE) [2,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(2, 1).getValue().toFixed(5)-0, 0.98026, "Result of LOGEST({2,8},{1,1},FALSE,TRUE) [2,1]"); assert.strictEqual(oParser.calculate().getElementRowCol(3, 0).getValue().toFixed(5)-0, 4, "Result of LOGEST({2,8},{1,1},FALSE,TRUE) [3,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(3, 1).getValue(), 1, "Result of LOGEST({2,8},{1,1},FALSE,TRUE) [3,1]"); assert.strictEqual(oParser.calculate().getElementRowCol(4, 0).getValue().toFixed(5)-0, 3.84362, "Result of LOGEST({2,8},{1,1},FALSE,TRUE) [4,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(4, 1).getValue().toFixed(5)-0, 0.96091, "Result of LOGEST({2,8},{1,1},FALSE,TRUE) [4,1]"); oParser = new parserFormula("LOGEST({2,8},{1,1},TRUE,TRUE)", "A2", ws); assert.ok(oParser.parse(), "LOGEST({2,8},{1,1},TRUE,TRUE)"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1, "Result of LOGEST({2,8},{1,1},TRUE,TRUE) [0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue(), 4, "Result of LOGEST({2,8},{1,1},TRUE,TRUE) [0,1]"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue(), 0, "Result of LOGEST({2,8},{1,1},TRUE,TRUE) [1,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 1).getValue(), 0, "Result of LOGEST({2,8},{1,1},TRUE,TRUE) [1,1]"); assert.strictEqual(oParser.calculate().getElementRowCol(2, 0).getValue(), 1, "Result of LOGEST({2,8},{1,1},TRUE,TRUE) [2,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(2, 1).getValue(), 0, "Result of LOGEST({2,8},{1,1},TRUE,TRUE) [2,1]"); assert.strictEqual(oParser.calculate().getElementRowCol(3, 0).getValue(), "#N/A", "Result of LOGEST({2,8},{1,1},TRUE,TRUE) [3,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(3, 1).getValue(), 0, "Result of LOGEST({2,8},{1,1},TRUE,TRUE) [3,1]"); assert.strictEqual(oParser.calculate().getElementRowCol(4, 0).getValue(), 0, "Result of LOGEST({2,8},{1,1},TRUE,TRUE) [4,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(4, 1).getValue(), 0, "Result of LOGEST({2,8},{1,1},TRUE,TRUE) [4,1]"); oParser = new parserFormula("LOGEST({2,8;1,1},{1,1;1,1})", "A2", ws); assert.ok(oParser.parse(), "LOGEST({2,8;1,1},{1,1;1,1})"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1, "Result of LOGEST({2,8;1,1},{1,1;1,1}) [0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(4) - 0, 2, "Result of LOGEST({2,8;1,1},{1,1;1,1}) [0,1]"); oParser = new parserFormula("LOGEST({2,8;1,1},{1,1;1,1},FALSE)", "A2", ws); assert.ok(oParser.parse(), "LOGEST({2,8;1,1},{1,1;1,1},FALSE)"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 2, "Result of LOGEST({2,8;1,1},{1,1;1,1},FALSE) [0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(4) - 0, 1, "Result of LOGEST({2,8;1,1},{1,1;1,1},FALSE) [0,1]"); oParser = new parserFormula("LOGEST({2,8;2,2;10,10},{1,1;1,1;1,1})", "A2", ws); assert.ok(oParser.parse(), "LOGEST({2,8;2,2;10,10},{1,1;1,1;1,1})"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1, "Result of LOGEST({2,8;2,2;10,10},{1,1;1,1;1,1}) [0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(8) - 0, 4.30886938, "Result of LOGEST({2,8;2,2;10,10},{1,1;1,1;1,1}) [0,1]"); oParser = new parserFormula("LOGEST({2,8;2,2;10,10},{1,1;1,1;1,1},FALSE)", "A2", ws); assert.ok(oParser.parse(), "LOGEST({2,8;2,2;10,10},{1,1;1,1;1,1},FALSE)"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 4.30886938, "Result of LOGEST({2,8;2,2;10,10},{1,1;1,1;1,1},FALSE) [0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(8) - 0, 1, "Result of LOGEST({2,8;2,2;10,10},{1,1;1,1;1,1},FALSE) [0,1]"); }); QUnit.test("Test: \"TREND\"", function (assert) { ws.getRange2("A2").setValue("11"); ws.getRange2("A3").setValue("12"); ws.getRange2("A4").setValue("13"); ws.getRange2("A5").setValue("14"); ws.getRange2("A6").setValue("15"); ws.getRange2("A7").setValue("16"); ws.getRange2("B2").setValue("33100"); ws.getRange2("B3").setValue("47300"); ws.getRange2("B4").setValue("69000"); ws.getRange2("B5").setValue("102000"); ws.getRange2("B6").setValue("150000"); ws.getRange2("B7").setValue("220000"); ws.getRange2("C2").setValue("32618"); ws.getRange2("C3").setValue("47729"); ws.getRange2("C4").setValue("69841"); ws.getRange2("C5").setValue("102197"); ws.getRange2("C6").setValue("149542"); ws.getRange2("C7").setValue("218822"); ws.getRange2("A9").setValue("17"); ws.getRange2("A10").setValue("18"); oParser = new parserFormula("TREND(B2:B7,A2:A7,A9:A10)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(2) - 0, 231126.67); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue().toFixed(2) - 0, 267572.38); oParser = new parserFormula("TREND(B2:B7,A2:A7)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(2) - 0, 12452.38); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue().toFixed(2) - 0, 48898.1); assert.strictEqual(oParser.calculate().getElementRowCol(2, 0).getValue().toFixed(2) - 0, 85343.81); assert.strictEqual(oParser.calculate().getElementRowCol(3, 0).getValue().toFixed(2) - 0, 121789.52); assert.strictEqual(oParser.calculate().getElementRowCol(4, 0).getValue().toFixed(2) - 0, 158235.24); assert.strictEqual(oParser.calculate().getElementRowCol(5, 0).getValue().toFixed(2) - 0, 194680.95); oParser = new parserFormula("TREND(A2:C2,A3:C4,A5:C6,1)", "A2", ws); assert.ok(oParser.parse(), "TREND(A2:C2,A3:C4,A5:C6,1)"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(2) - 0, 15.74, "Result of TREND(A2:C2,A3:C4,A5:C6,1)[0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(2) - 0, 67013.18, "Result of TREND(A2:C2,A3:C4,A5:C6,1)[0,1]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 2).getValue().toFixed(2) - 0, 69861.01, "Result of TREND(A2:C2,A3:C4,A5:C6,1)[0,2]"); oParser = new parserFormula("TREND(A3:C3,A4:C5,A6:C7,1)", "A2", ws); assert.ok(oParser.parse(), "TREND(A3:C3,A4:C5,A6:C7,1)"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(2) - 0, 13.24, "Result of TREND(A3:C3,A4:C5,A6:C7,1)[0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(2) - 0, 102576.47, "Result of TREND(A3:C3,A4:C5,A6:C7,1)[0,1]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 2).getValue().toFixed(2) - 0, 102191.92, "Result of TREND(A3:C3,A4:C5,A6:C7,1)[0,2]"); oParser = new parserFormula("TREND(A3:C3,A4:C5,A6:C7,0)", "A2", ws); assert.ok(oParser.parse(), "TREND(A3:C3,A4:C5,A6:C7,0)"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(2) - 0, 9.41, "Result of TREND(A3:C3,A4:C5,A6:C7,0)[0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(2) - 0, 102580.9, "Result of TREND(A3:C3,A4:C5,A6:C7,0)[0,1]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 2).getValue().toFixed(2) - 0, 102196.32, "Result of TREND(A3:C3,A4:C5,A6:C7,0)[0,2]"); oParser = new parserFormula("TREND({1,2,3},A4:C5,A6:C7,1)", "A2", ws); assert.ok(oParser.parse(), "TREND({1,2,3},A4:C5,A6:C7,1)"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(2) - 0, 1, "Result of TREND({1,2,3},A4:C5,A6:C7,1)[0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(2) - 0, 4.82, "Result of TREND({1,2,3},A4:C5,A6:C7,1)[0,1]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 2).getValue().toFixed(2) - 0, 5.29, "Result of TREND({1,2,3},A4:C5,A6:C7,1)[0,2]"); ws.getRange2("A20").setValue("1"); ws.getRange2("B20").setValue("2"); oParser = new parserFormula("TREND(A20:B20)", "A2", ws); assert.ok(oParser.parse(), "TREND(A20:B20)"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(2) - 0, 1, "Result of TREND(A20:B20)[0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(2) - 0, 2, "Result of TREND(A20:B20)[0,1]"); oParser = new parserFormula("TREND({1;2})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(2) - 0, 1, "Result of TREND({1;2})[0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue().toFixed(2) - 0, 2, "Result of TREND({1;2})[1,0]"); oParser = new parserFormula("TREND({1,2})", "A2", ws); assert.ok(oParser.parse(), "TREND({1,2})"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(2) - 0, 1, "Result of TREND({1,2})[0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(2) - 0, 2, "Result of TREND({1,2})[0,1]"); ws.getRange2("A20").setValue("1"); ws.getRange2("A21").setValue("2"); ws.getRange2("A22").setValue("3"); ws.getRange2("B20").setValue("1"); ws.getRange2("B21").setValue("2"); ws.getRange2("B22").setValue("3"); ws.getRange2("C20").setValue("1"); ws.getRange2("C21").setValue("2"); ws.getRange2("C22").setValue("3"); // different matrix length tests oParser = new parserFormula("TREND(A20:A21,A20:C20)", "A2", ws); assert.ok(oParser.parse(), "TREND(A20:A21,A20:C20)"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of TREND(A20:A21,A20:C20)"); oParser = new parserFormula("TREND(A20:A22,A20:C20)", "A2", ws); assert.ok(oParser.parse(), "TREND(A20:A22,A20:C20)"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of TREND(A20:A22,A20:C20)"); oParser = new parserFormula("TREND(A20:B21,A20:C21)", "A2", ws); assert.ok(oParser.parse(), "TREND(A20:B21,A20:C21)"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of TREND(A20:B21,A20:C21)"); oParser = new parserFormula("TREND({1,2,3},{1,2})", "A2", ws); assert.ok(oParser.parse(), "TREND({1,2,3},{1,2})"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of TREND({1,2,3},{1,2})"); oParser = new parserFormula("TREND({1,2,3},{1,2,3,4})", "A2", ws); assert.ok(oParser.parse(), "TREND({1,2,3},{1,2,3,4})"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of TREND({1,2,3},{1,2,3,4})"); oParser = new parserFormula("TREND({1,2;1,2},{1,2})", "A2", ws); assert.ok(oParser.parse(), "TREND({1,2;1,2},{1,2})"); assert.strictEqual(oParser.calculate().getValue(), "#REF!", "Result of TREND({1,2;1,2},{1,2})"); oParser = new parserFormula("TREND(A20:B20,{1,2})", "A2", ws); assert.ok(oParser.parse(), "TREND(A20:B20,{1,2})"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue(), 1, "Result of TREND(A20:B20,{1,2})[0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue(), 1, "Result of TREND(A20:B20,{1,2})[0,1]"); // identical X-trend tests oParser = new parserFormula("TREND({1,1},{0,0})", "A2", ws); assert.ok(oParser.parse(), "TREND({1,1},{0,0})"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 1, "Result of TREND({1,1},{0,0}) [0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(4) - 0, 1, "Result of TREND({1,1},{0,0}) [0,1]"); oParser = new parserFormula("TREND({123,123},{123,123})", "A2", ws); assert.ok(oParser.parse(), "TREND({123,123},{123,123})"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 123, "Result of TREND({123,123},{123,123}) [0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(4) - 0, 123, "Result of TREND({123,123},{123,123}) [0,1]"); oParser = new parserFormula("TREND({2,8},{1,1})", "A2", ws); assert.ok(oParser.parse(), "TREND({2,8},{1,1})"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 5, "Result of TREND({2,8},{1,1}) [0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(4) - 0, 5, "Result of TREND({2,8},{1,1}) [0,1]"); oParser = new parserFormula("TREND({2,8;1,1},{1,1;1,1})", "A2", ws); assert.ok(oParser.parse(), "TREND({2,8;1,1},{1,1;1,1})"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(8) - 0, 3, "Result of TREND({2,8;1,1},{1,1;1,1}) [0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(4) - 0, 3, "Result of TREND({2,8;1,1},{1,1;1,1}) [0,1]"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue().toFixed(8) - 0, 3, "Result of TREND({2,8;1,1},{1,1;1,1}) [1,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 1).getValue().toFixed(4) - 0, 3, "Result of TREND({2,8;1,1},{1,1;1,1}) [1,1]"); oParser = new parserFormula("TREND({2,8;2,2;10,10},{1,1;1,1;1,1})", "A2", ws); assert.ok(oParser.parse(), "TREND({2,8;2,2;10,10},{1,1;1,1;1,1})"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 0).getValue().toFixed(2) - 0, 5.67, "Result of TREND({2,8;2,2;10,10},{1,1;1,1;1,1}) [0,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(0, 1).getValue().toFixed(2) - 0, 5.67, "Result of TREND({2,8;2,2;10,10},{1,1;1,1;1,1}) [0,1]"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 0).getValue().toFixed(2) - 0, 5.67, "Result of TREND({2,8;2,2;10,10},{1,1;1,1;1,1}) [1,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(1, 1).getValue().toFixed(2) - 0, 5.67, "Result of TREND({2,8;2,2;10,10},{1,1;1,1;1,1}) [1,1]"); assert.strictEqual(oParser.calculate().getElementRowCol(2, 0).getValue().toFixed(2) - 0, 5.67, "Result of TREND({2,8;2,2;10,10},{1,1;1,1;1,1}) [2,0]"); assert.strictEqual(oParser.calculate().getElementRowCol(2, 1).getValue().toFixed(2) - 0, 5.67, "Result of TREND({2,8;2,2;10,10},{1,1;1,1;1,1}) [2,1]"); }); QUnit.test("Test: \"PDURATION\"", function (assert) { oParser = new parserFormula("PDURATION(2.5%,2000,2200)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 3.86); oParser = new parserFormula("PDURATION(0.025/12,1000,1200)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(1) - 0, 87.6); oParser = new parserFormula("PDURATION(0.025,1000,1200)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 7.38); oParser = new parserFormula("PDURATION(-0.025,1000,1200)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("PDURATION(0.025,-1000,1200)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("PDURATION(0.025,1000,-1200)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula("PDURATION({0.025},{1000},{1200})", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 7.38); oParser = new parserFormula("PDURATION(\"TEST\",1000,-1200)", "A2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); testArrayFormula2(assert, "PDURATION", 3, 3); }); QUnit.test("Test: \"IFS\"", function (assert) { oParser = new parserFormula('IFS(1,"TEST")', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TEST"); oParser = new parserFormula('IFS(0,"TEST",1,"TEST2")', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TEST2"); oParser = new parserFormula('IFS(2<1,">3")', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); oParser = new parserFormula('IFS(2<1,">3",2>1)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); oParser = new parserFormula('IFS(2<1,"TEST",2<1,2,4>3,"TEST2")', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TEST2"); oParser = new parserFormula('IFS(1=1,"correct",#VALUE!,1)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "correct"); oParser = new parserFormula('IFS(1<>1,"correct",#VALUE!,1)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!"); oParser = new parserFormula('IFS(1<>1,"correct",#N/A,1)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); oParser = new parserFormula('IFS(1<>1,"correct",1=1, #N/A)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); oParser = new parserFormula('IFS(1<>1,"correct",1=1, #N/A, #VALUE!, #VALUE!)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); oParser = new parserFormula('IFS(1=1,"correct",1=2,1/0)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "correct"); testArrayFormulaEqualsValues(assert, "1,3.123,-4,#N/A;2,4,5,#N/A;#N/A,#N/A,#N/A,#N/A", "IFS(A1:C2,A1:C2,A1:C2,A1:C2, A1:C2,A1:C2)"); }); QUnit.test("Test: \"IF\"", function (assert) { oParser = new parserFormula('IF(1,"TEST")', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "TEST"); oParser = new parserFormula('IF(0,"TEST")', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "FALSE"); ws.getRange2("A101").setValue("1"); oParser = new parserFormula('IF(A101=1,"Yes","No")', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "Yes"); oParser = new parserFormula('IF(A101=2,"Yes","No")', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "No"); oParser = new parserFormula('IF(1,#N/A,#NUM!)', "AA2", ws); assert.ok(oParser.parse(), 'IF(1,#N/A,#NUM!)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); oParser = new parserFormula('IF(0,#N/A,#NUM!)', "AA2", ws); assert.ok(oParser.parse(), 'IF(0,#N/A,#NUM!)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula('IF(1,#NUM!,#N/A)', "AA2", ws); assert.ok(oParser.parse(), 'IF(1,#NUM!,#N/A)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); oParser = new parserFormula('IF(0,#NUM!,#N/A)', "AA2", ws); assert.ok(oParser.parse(), 'IF(0,#NUM!,#N/A)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A"); ws.getRange2("A1").setValue("0"); ws.getRange2("A2").setValue("1"); ws.getRange2("A3").setValue("2"); ws.getRange2("A4").setValue("3"); oParser = new parserFormula('IF(A1:A3>0, "Positive", "Non-positive")', "AA2", ws); assert.ok(oParser.parse(), 'IF(A1:A3>0, "Positive", "Non-positive")'); oParser.setArrayFormulaRef(ws.getRange2("C10:E12").bbox); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), "Non-positive"); assert.strictEqual(array.getElementRowCol(1,0).getValue(), "Positive"); assert.strictEqual(array.getElementRowCol(2,0).getValue(), "Positive"); oParser = new parserFormula('IF(A1:A3>=0, "Positive", "Non-positive")', "AA2", ws); assert.ok(oParser.parse(), 'IF(A1:A3>=0, "Positive", "Non-positive")'); oParser.setArrayFormulaRef(ws.getRange2("C10:E12").bbox); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), "Positive"); assert.strictEqual(array.getElementRowCol(1,0).getValue(), "Positive"); assert.strictEqual(array.getElementRowCol(2,0).getValue(), "Positive"); oParser = new parserFormula('IF(A1:A3<0, "Positive", "Non-positive")', "AA2", ws); assert.ok(oParser.parse(), 'IF(A1:A3<0, "Positive", "Non-positive")'); oParser.setArrayFormulaRef(ws.getRange2("C10:E12").bbox); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), "Non-positive"); assert.strictEqual(array.getElementRowCol(1,0).getValue(), "Non-positive"); assert.strictEqual(array.getElementRowCol(2,0).getValue(), "Non-positive"); oParser = new parserFormula('IF(A1:A3<=0, "Positive", "Non-positive")', "AA2", ws); assert.ok(oParser.parse(), 'IF(A1:A3<=0, "Positive", "Non-positive")'); oParser.setArrayFormulaRef(ws.getRange2("C10:E12").bbox); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), "Positive"); assert.strictEqual(array.getElementRowCol(1,0).getValue(), "Non-positive"); assert.strictEqual(array.getElementRowCol(2,0).getValue(), "Non-positive"); oParser = new parserFormula('IF(A1:A3<>0, "Positive", "Non-positive")', "AA2", ws); assert.ok(oParser.parse(), 'IF(A1:A3<>0, "Positive", "Non-positive")'); oParser.setArrayFormulaRef(ws.getRange2("C10:E12").bbox); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), "Non-positive"); assert.strictEqual(array.getElementRowCol(1,0).getValue(), "Positive"); assert.strictEqual(array.getElementRowCol(2,0).getValue(), "Positive"); oParser = new parserFormula('IF(A1:A3="", "Empty", "Filled")', "AA2", ws); assert.ok(oParser.parse(), 'IF(A1:A3="", "Empty", "Filled")'); oParser.setArrayFormulaRef(ws.getRange2("C10:E12").bbox); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), "Filled"); assert.strictEqual(array.getElementRowCol(1,0).getValue(), "Filled"); assert.strictEqual(array.getElementRowCol(2,0).getValue(), "Filled"); oParser = new parserFormula('IF(A1:A3="Yes", 1, 0)', "AA2", ws); assert.ok(oParser.parse(), 'IIF(A1:A3="Yes", 1, 0)'); oParser.setArrayFormulaRef(ws.getRange2("C10:E12").bbox); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 0); assert.strictEqual(array.getElementRowCol(1,0).getValue(), 0); assert.strictEqual(array.getElementRowCol(2,0).getValue(), 0); oParser = new parserFormula('IF(TRUE, A1:A3, A1:A2)', "AA2", ws); assert.ok(oParser.parse(), 'IF(TRUE, A1:A3, A1:A2)'); oParser.setArrayFormulaRef(ws.getRange2("C10:E12").bbox); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 0); assert.strictEqual(array.getElementRowCol(1,0).getValue(), 1); assert.strictEqual(array.getElementRowCol(2,0).getValue(), 2); oParser = new parserFormula('IF(FALSE, A1:A3, A1:A2)', "AA2", ws); assert.ok(oParser.parse(), 'IF(FALSE, A1:A3, A1:A2)'); oParser.setArrayFormulaRef(ws.getRange2("C10:E12").bbox); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 0); assert.strictEqual(array.getElementRowCol(1,0).getValue(), 1); assert.strictEqual(array.getElementRowCol(2,0).getValue(), "#N/A"); oParser = new parserFormula('IF({1,0,1}, {"A","B","C"}, {"X","Y","Z"})', "AA2", ws); assert.ok(oParser.parse(), 'IF({1,0,1}, {"A","B","C"}, {"X","Y","Z"})'); oParser.setArrayFormulaRef(ws.getRange2("C10:E12").bbox); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), "A"); assert.strictEqual(array.getElementRowCol(0,1).getValue(), "Y"); assert.strictEqual(array.getElementRowCol(0,2).getValue(), "C"); oParser = new parserFormula('IF({TRUE,FALSE,TRUE}, {10,20,30}, {100,200,300})', "AA2", ws); assert.ok(oParser.parse(), 'IF({TRUE,FALSE,TRUE}, {10,20,30}, {100,200,300})'); oParser.setArrayFormulaRef(ws.getRange2("C10:E12").bbox); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 10); assert.strictEqual(array.getElementRowCol(0,1).getValue(), 200); assert.strictEqual(array.getElementRowCol(0,2).getValue(), 30); }); QUnit.test("Test: \"COLUMN\"", function (assert) { oParser = new parserFormula('COLUMN(B6)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); oParser = new parserFormula('COLUMN(C16)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); oParser = new parserFormula('COLUMN()', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula('COLUMN()+COLUMN()', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); testArrayFormulaEqualsValues(assert, "5,6,7,8;5,6,7,8;5,6,7,8", "COLUMN()"); testArrayFormulaEqualsValues(assert, "1,2,3,#N/A;1,2,3,#N/A;1,2,3,#N/A", "COLUMN(A1:C2)"); testArrayFormulaEqualsValues(assert, "1,2,#N/A,#N/A;1,2,#N/A,#N/A;1,2,#N/A,#N/A", "COLUMN(A1:B1)"); testArrayFormulaEqualsValues(assert, "1,1,1,1;1,1,1,1;1,1,1,1", "COLUMN(A1)"); }); QUnit.test("Test: \"COLUMNS\"", function (assert) { oParser = new parserFormula('COLUMNS(C1:E4)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); oParser = new parserFormula('COLUMNS({1,2,3;4,5,6})', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 3); //TODO нужна другая функция для тестирования //testArrayFormula2(assert, "COLUMNS", 1, 1); }); QUnit.test("Test: \"ROW\"", function (assert) { oParser = new parserFormula('ROW(B6)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 6); oParser = new parserFormula('ROW(C16)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 16); oParser = new parserFormula('ROW()', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 1); oParser = new parserFormula('ROW()+ROW()', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); testArrayFormulaEqualsValues(assert, "6,6,6,6;7,7,7,7;8,8,8,8", "ROW()"); testArrayFormulaEqualsValues(assert, "1,1,1,1;2,2,2,2;#N/A,#N/A,#N/A,#N/A", "ROW(A1:C2)"); testArrayFormulaEqualsValues(assert, "1,1,1,1;1,1,1,1;1,1,1,1", "ROW(A1:B1)"); testArrayFormulaEqualsValues(assert, "1,1,1,1;1,1,1,1;1,1,1,1", "ROW(A1)"); }); QUnit.test("Test: \"ROWS\"", function (assert) { oParser = new parserFormula('ROWS(C1:E4)', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 4); oParser = new parserFormula('ROWS({1,2,3;4,5,6})', "AA2", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 2); //TODO нужна другая функция для тестирования //testArrayFormula2(assert, "COLUMNS", 1, 1); }); QUnit.test("Test: \"SUBTOTAL\"", function (assert) { let array; ws.getRange2("A102").setValue("120"); ws.getRange2("A103").setValue("10"); ws.getRange2("A104").setValue("150"); ws.getRange2("A105").setValue("23"); ws.getRange2("A106").setValue("1"); ws.getRange2("B100").setValue("#N/A"); oParser = new parserFormula("SUBTOTAL(-1,A102:A105)", "A2", ws); assert.ok(oParser.parse(), "SUBTOTAL(-1,A102:A105)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "SUBTOTAL(-1,A102:A105)"); oParser = new parserFormula("SUBTOTAL(0,A102:A105)", "A2", ws); assert.ok(oParser.parse(), "SUBTOTAL(0,A102:A105)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "SUBTOTAL(0,A102:A105)"); oParser = new parserFormula("SUBTOTAL(1,A102:A105)", "A2", ws); assert.ok(oParser.parse(), "SUBTOTAL(1,A102:A105)"); assert.strictEqual(oParser.calculate().getValue().toFixed(2) - 0, 75.75, "SUBTOTAL(1,A102:A105)"); oParser = new parserFormula("SUBTOTAL(2,A102:A105)", "A2", ws); assert.ok(oParser.parse(), "SUBTOTAL(2,A102:A105)"); assert.strictEqual(oParser.calculate().getValue(), 4, "SUBTOTAL(2,A102:A105)"); oParser = new parserFormula("SUBTOTAL(3,A102:A105)", "A2", ws); assert.ok(oParser.parse(), "SUBTOTAL(3,A102:A105)"); assert.strictEqual(oParser.calculate().getValue(), 4, "SUBTOTAL(3,A102:A105)"); oParser = new parserFormula("SUBTOTAL(4,A102:A105)", "A2", ws); assert.ok(oParser.parse(), "SUBTOTAL(4,A102:A105)"); assert.strictEqual(oParser.calculate().getValue(), 150, "SUBTOTAL(4,A102:A105)"); oParser = new parserFormula("SUBTOTAL(5,A102:A105)", "A2", ws); assert.ok(oParser.parse(), "SUBTOTAL(5,A102:A105)"); assert.strictEqual(oParser.calculate().getValue(), 10, "SUBTOTAL(5,A102:A105)"); oParser = new parserFormula("SUBTOTAL(6,A102:A105)", "A2", ws); assert.ok(oParser.parse(), "SUBTOTAL(6,A102:A105)"); assert.strictEqual(oParser.calculate().getValue(), 4140000, "SUBTOTAL(6,A102:A105)"); oParser = new parserFormula("SUBTOTAL(7,A102:A105)", "A2", ws); assert.ok(oParser.parse(), "SUBTOTAL(7,A102:A105)"); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 69.70592992, "SUBTOTAL(7,A102:A105)"); oParser = new parserFormula("SUBTOTAL(8,A102:A105)", "A2", ws); assert.ok(oParser.parse(), "SUBTOTAL(8,A102:A105)"); assert.strictEqual(oParser.calculate().getValue().toFixed(8) - 0, 60.36710611, "SUBTOTAL(8,A102:A105)"); oParser = new parserFormula("SUBTOTAL(9,A102:A105)", "A2", ws); assert.ok(oParser.parse(), "SUBTOTAL(9,A102:A105)"); assert.strictEqual(oParser.calculate().getValue(), 303, "SUBTOTAL(9,A102:A105)"); oParser = new parserFormula("SUBTOTAL(99,A102:A105)", "A2", ws); assert.ok(oParser.parse(), "SUBTOTAL(99,A102:A105)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "SUBTOTAL(99,A102:A105)"); oParser = new parserFormula('SUBTOTAL("str",A102:A105)', "A2", ws); assert.ok(oParser.parse(), 'SUBTOTAL("str",A102:A105)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'SUBTOTAL("str",A102:A105)'); oParser = new parserFormula('SUBTOTAL(B100,A102:A105)', "A2", ws); assert.ok(oParser.parse(), 'SUBTOTAL(B100,A102:A105)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'SUBTOTAL(B100,A102:A105)'); oParser = new parserFormula("SUBTOTAL(2,A102,A102)", "A2", ws); assert.ok(oParser.parse(), "SUBTOTAL(2,A102,A102)"); assert.strictEqual(oParser.calculate().getValue(), 2, "Two refs in SUBTOTAL(2,A102,A102)"); oParser = new parserFormula("SUBTOTAL(2,A102,A102,A102)", "A2", ws); assert.ok(oParser.parse(), "SUBTOTAL(2,A102,A102,A102)"); assert.strictEqual(oParser.calculate().getValue(), 3, "Three refs in SUBTOTAL(2,A102,A102,A102)"); oParser = new parserFormula("SUBTOTAL(2,A102,A102,A102,A102)", "A2", ws); assert.ok(oParser.parse(), "SUBTOTAL(2,A102,A102,A102,A102)"); assert.strictEqual(oParser.calculate().getValue(), 4, "Four refs in SUBTOTAL(2,A102,A102,A102,A102)"); oParser = new parserFormula("SUBTOTAL(9,A102,A102,A102,A102)", "A2", ws); assert.ok(oParser.parse(), "SUBTOTAL(9,A102,A102,A102,A102)"); assert.strictEqual(oParser.calculate().getValue(), 480, "Four refs in SUBTOTAL(9,A102,A102,A102,A102)"); oParser = new parserFormula("SUBTOTAL(9,A102:A105,A102:A105)", "A2", ws); assert.ok(oParser.parse(), "SUBTOTAL(9,A102:A105,A102:A105)"); assert.strictEqual(oParser.calculate().getValue(), 606, "Two refs in SUBTOTAL(9,A102:A105,A102:A105)"); oParser = new parserFormula("SUBTOTAL(9,A102:A105,A102:A105,A102:A105)", "A2", ws); assert.ok(oParser.parse(), "SUBTOTAL(9,A102:A105,A102:A105,A102:A105)"); assert.strictEqual(oParser.calculate().getValue(), 909, "Three refs in SUBTOTAL(9,A102:A105,A102:A105,A102:A105)"); oParser = new parserFormula("SUBTOTAL(9,A102:A105,A102:A105,A102:A105,A102:A105)", "A2", ws); assert.ok(oParser.parse(), "SUBTOTAL(9,A102:A105,A102:A105,A102:A105,A102:A105)"); assert.strictEqual(oParser.calculate().getValue(), 1212, "Four refs in SUBTOTAL(9,A102:A105,A102:A105,A102:A105,A102:A105)"); oParser = new parserFormula("SUBTOTAL(9,A102:A105,A102:A105,A102:A105,A102:A105,A102:A105)", "A2", ws); assert.ok(oParser.parse(), "SUBTOTAL(9,A102:A105,A102:A105,A102:A105,A102:A105,A102:A105)"); assert.strictEqual(oParser.calculate().getValue(), 1515, "Five refs in SUBTOTAL(9,A102:A105,A102:A105,A102:A105,A102:A105,A102:A105)"); oParser = new parserFormula("SUBTOTAL(9,A102,A102:A105)", "A2", ws); assert.ok(oParser.parse(), "SUBTOTAL(9,A102,A102:A105)"); assert.strictEqual(oParser.calculate().getValue(), 423, "SUBTOTAL(9,A102,A102:A105)"); oParser = new parserFormula("SUBTOTAL(9,A102,A102:A105,A106)", "A2", ws); assert.ok(oParser.parse(), "SUBTOTAL(9,A102,A102:A105,A106)"); assert.strictEqual(oParser.calculate().getValue(), 424, "SUBTOTAL(9,A102,A102:A106)"); oParser = new parserFormula("SUBTOTAL(9,A102,A102:A105,A106,A102:A105)", "A2", ws); assert.ok(oParser.parse(), "SUBTOTAL(9,A102,A102:A105,A106,A102:A105)"); assert.strictEqual(oParser.calculate().getValue(), 727, "SUBTOTAL(9,A102,A102:A106,A102:A105)"); oParser = new parserFormula("SUBTOTAL(9,A102,A102:A105,A106,A102:A105,A106)", "A2", ws); assert.ok(oParser.parse(), "SUBTOTAL(9,A102,A102:A105,A106,A102:A105,A106)"); assert.strictEqual(oParser.calculate().getValue(), 728, "SUBTOTAL(9,A102,A102:A106,A102:A105,A106)"); // for bug 68820 ws.getRange2("B100").setValue("-2"); ws.getRange2("B101").setValue("1"); ws.getRange2("B102").setValue("-1"); ws.getRange2("B103").setValue("0"); ws.getRange2("B104").setValue("1"); ws.getRange2("B105").setValue("1"); ws.getRange2("B106").setValue("-2"); ws.getRange2("B107").setValue("0"); ws.getRange2("B108").setValue("0"); ws.getRange2("B109").setValue("1"); ws.getRange2("B110").setValue("1"); oParser = new parserFormula('SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0))', "A2", ws); assert.ok(oParser.parse(), 'SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0))'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), -2, 'SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0))'); assert.strictEqual(array.getElementRowCol(1,0).getValue(), 1, 'SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0))'); assert.strictEqual(array.getElementRowCol(2,0).getValue(), -1, 'SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0))'); assert.strictEqual(array.getElementRowCol(3,0).getValue(), 0, 'SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0))'); assert.strictEqual(array.getElementRowCol(4,0).getValue(), 1, 'SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0))'); assert.strictEqual(array.getElementRowCol(5,0).getValue(), 1, 'SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0))'); assert.strictEqual(array.getElementRowCol(6,0).getValue(), -2, 'SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0))'); assert.strictEqual(array.getElementRowCol(7,0).getValue(), 0, 'SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0))'); assert.strictEqual(array.getElementRowCol(8,0).getValue(), 0, 'SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0))'); oParser = new parserFormula('SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0),B109:B110)', "A2", ws); assert.ok(oParser.parse(), 'SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0),B109:B110)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 0, 'SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0),B109:B110)'); assert.strictEqual(array.getElementRowCol(1,0).getValue(), 3, 'SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0),B109:B110)'); assert.strictEqual(array.getElementRowCol(2,0).getValue(), 1, 'SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0),B109:B110)'); assert.strictEqual(array.getElementRowCol(3,0).getValue(), 2, 'SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0),B109:B110)'); assert.strictEqual(array.getElementRowCol(4,0).getValue(), 3, 'SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0),B109:B110)'); assert.strictEqual(array.getElementRowCol(5,0).getValue(), 3, 'SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0),B109:B110)'); assert.strictEqual(array.getElementRowCol(6,0).getValue(), 0, 'SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0),B109:B110)'); assert.strictEqual(array.getElementRowCol(7,0).getValue(), 2, 'SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0),B109:B110)'); assert.strictEqual(array.getElementRowCol(8,0).getValue(), 2, 'SUBTOTAL(9,OFFSET(B100,ROW(B100:B108)-ROW(B100),0),B109:B110)'); }); QUnit.test("Test: \"SUBTOTAL with multiple ranges\"", function (assert) { // Setup test data with 5 columns for testing ws.getRange2("E2").setValue("10"); ws.getRange2("E3").setValue("20"); ws.getRange2("E4").setValue("30"); ws.getRange2("E5").setValue("40"); ws.getRange2("E6").setValue("50"); ws.getRange2("E7").setValue("60"); ws.getRange2("F2").setValue("Red"); ws.getRange2("F3").setValue("Blue"); ws.getRange2("F4").setValue("Green"); ws.getRange2("F5").setValue("Red"); ws.getRange2("F6").setValue("Blue"); ws.getRange2("F7").setValue("Green"); ws.getRange2("G2").setValue("Small"); ws.getRange2("G3").setValue("Medium"); ws.getRange2("G4").setValue("Large"); ws.getRange2("G5").setValue("Large"); ws.getRange2("G6").setValue("Medium"); ws.getRange2("G7").setValue("Small"); ws.getRange2("H2").setValue("15"); ws.getRange2("H3").setValue("25"); ws.getRange2("H4").setValue("35"); ws.getRange2("H5").setValue("45"); ws.getRange2("H6").setValue("55"); ws.getRange2("H7").setValue("65"); // Test SUBTOTAL with multiple ranges // Function 2 (COUNT) with multiple ranges oParser = new parserFormula("SUBTOTAL(2, E2:E4, F2:F4, G2:G4, H2:H4, E5:E7, F5:F7, G5:G7, H5:H7)", "A1", ws); assert.ok(oParser.parse(), "SUBTOTAL COUNT with multiple ranges"); assert.strictEqual(oParser.calculate().getValue(), 12, "SUBTOTAL COUNT with multiple ranges"); // Function 3 (COUNTA) with multiple ranges oParser = new parserFormula("SUBTOTAL(3, E2:E4, F2:F4, G2:G4, H2:H4, E5:E7, F5:F7, G5:G7, H5:H7)", "A1", ws); assert.ok(oParser.parse(), "SUBTOTAL COUNTA with multiple ranges"); assert.strictEqual(oParser.calculate().getValue(), 24, "SUBTOTAL COUNTA with multiple ranges"); // Function 4 (MAX) with multiple ranges oParser = new parserFormula("SUBTOTAL(4, E2:E4, F2:F4, G2:G4, H2:H4, E5:E7, F5:F7, G5:G7, H5:H7)", "A1", ws); assert.ok(oParser.parse(), "SUBTOTAL MAX with multiple ranges"); assert.strictEqual(oParser.calculate().getValue(), 65, "SUBTOTAL MAX with multiple ranges"); // Function 5 (MIN) with multiple ranges oParser = new parserFormula("SUBTOTAL(5, E2:E4, F2:F4, G2:G4, H2:H4, E5:E7, F5:F7, G5:G7, H5:H7)", "A1", ws); assert.ok(oParser.parse(), "SUBTOTAL MIN with multiple ranges"); assert.strictEqual(oParser.calculate().getValue(), 10, "SUBTOTAL MIN with multiple ranges"); }); QUnit.test("Test: \"MID\"", function (assert) { ws.getRange2("A101").setValue("Fluid Flow"); oParser = new parserFormula("MID(A101,1,5)", "A2", ws); assert.ok(oParser.parse(), "MID(A101,1,5)"); assert.strictEqual(oParser.calculate().getValue(), "Fluid", "MID(A101,1,5)"); oParser = new parserFormula("MID(A101,7,20)", "A2", ws); assert.ok(oParser.parse(), "MID(A101,7,20)"); assert.strictEqual(oParser.calculate().getValue(), "Flow", "MID(A101,7,20)"); oParser = new parserFormula("MID(A101,20,5)", "A2", ws); assert.ok(oParser.parse(), "MID(A101,20,5)"); assert.strictEqual(oParser.calculate().getValue(), "", "MID(A101,20,5))"); oParser = new parserFormula("MID(TRUE,2,5)", "A2", ws); assert.ok(oParser.parse(), "MID(TRUE,2,5)"); assert.strictEqual(oParser.calculate().getValue(), "RUE", "MID(TRUE,2,5)"); testArrayFormula2(assert, "MID", 3, 3); }); QUnit.test("Test: \"MIDB\"", function (assert) { ws.getRange2("A101").setValue("Fluid Flow"); oParser = new parserFormula("MIDB(A101,1,5)", "A2", ws); assert.ok(oParser.parse(), "MIDB(A101,1,5)"); assert.strictEqual(oParser.calculate().getValue(), "Fluid", "MIDB(A101,1,5)"); oParser = new parserFormula("MIDB(A101,7,20)", "A2", ws); assert.ok(oParser.parse(), "MIDB(A101,7,20)"); assert.strictEqual(oParser.calculate().getValue(), "Flow", "MIDB(A101,7,20)"); oParser = new parserFormula("MIDB(A101,20,5)", "A2", ws); assert.ok(oParser.parse(), "MIDB(A101,20,5)"); assert.strictEqual(oParser.calculate().getValue(), "", "MIDB(A101,20,5))"); oParser = new parserFormula("MIDB(TRUE,2,5)", "A2", ws); assert.ok(oParser.parse(), "MIDB(TRUE,2,5)"); assert.strictEqual(oParser.calculate().getValue(), "RUE", "MIDB(TRUE,2,5)"); }); QUnit.test("Test: \"MINUTE\"", function (assert) { ws.getRange2("A202").setValue("12:45:00 PM"); ws.getRange2("A203").setValue("7/18/2011 7:45"); ws.getRange2("A204").setValue("4/21/2012"); oParser = new parserFormula("MINUTE(A202)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 45); oParser = new parserFormula("MINUTE(A203)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 45); oParser = new parserFormula("MINUTE(A204)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); ws.getRange2("A205").setValue("06/30/2020 20:00"); ws.getRange2("A206").setValue("06/30/2020 21:15"); ws.getRange2("A207").setValue("06/30/2020 23:15"); oParser = new parserFormula("MINUTE(A206-A205)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 15); oParser = new parserFormula("MINUTE(A207-A205)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 15); oParser = new parserFormula("MINUTE(A207-A206)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 0); oParser = new parserFormula("MINUTE(A207+A206)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 30); oParser = new parserFormula("MINUTE(123.1231231 - 1.12334343)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), 59); oParser = new parserFormula("MINUTE(1.12334343 - 123.1231231)", "A1", ws); assert.ok(oParser.parse()); assert.strictEqual(oParser.calculate().getValue(), "#NUM!"); }); QUnit.test("Test: \"MINVERSE\"", function (assert) { // 2x2 matrix ws.getRange2("A202").setValue("1"); ws.getRange2("A203").setValue("3"); ws.getRange2("B202").setValue("2"); ws.getRange2("B203").setValue("4"); // 3x3 matrix + 4x4 matrix + 5x5 matrix ws.getRange2("A204").setValue("2"); ws.getRange2("A205").setValue("6"); ws.getRange2("A206").setValue("5"); ws.getRange2("A207").setValue("3"); ws.getRange2("A208").setValue("125"); ws.getRange2("B204").setValue("5"); ws.getRange2("B205").setValue("3"); ws.getRange2("B206").setValue("-2"); ws.getRange2("B207").setValue("2"); ws.getRange2("B208").setValue("-1.5"); ws.getRange2("C204").setValue("7"); ws.getRange2("C205").setValue("4"); ws.getRange2("C206").setValue("-3"); ws.getRange2("C207").setValue("4"); ws.getRange2("C208").setValue("-1"); ws.getRange2("D204").setValue("12"); ws.getRange2("D205").setValue("-2"); ws.getRange2("D206").setValue("7"); ws.getRange2("D207").setValue("5"); ws.getRange2("D208").setValue("2.5"); ws.getRange2("E204").setValue("14.5"); ws.getRange2("E205").setValue("-3"); ws.getRange2("E206").setValue("35"); ws.getRange2("E207").setValue("309"); ws.getRange2("E208").setValue("-25"); // false matrixes ws.getRange2("J17").setValue(""); ws.getRange2("J18").setValue("10"); ws.getRange2("J19").setValue(""); ws.getRange2("J20").setValue(""); ws.getRange2("J21").setValue("TRUE"); ws.getRange2("J22").setValue("#N/A"); ws.getRange2("J23").setValue("{2;3;4;5}"); ws.getRange2("J24").setValue("20"); ws.getRange2("J24").setNumFormat("@"); ws.getRange2("J25").setValue("1"); ws.getRange2("J26").setValue("2"); ws.getRange2("H25").setValue("4"); ws.getRange2("H26").setValue("8"); oParser = new parserFormula("MINVERSE(A202:B203)", "A2", ws); assert.ok(oParser.parse(), "MINVERSE(A202:B203)"); let array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), -2, "Result [0,0] MINVERSE(A202:B203)"); assert.strictEqual(array.getElementRowCol(0,1).getValue(), 1, "Result [0,1] MINVERSE(A202:B203)"); assert.strictEqual(array.getElementRowCol(1,0).getValue(), 1.5, "Result [1,0] MINVERSE(A202:B203)"); assert.strictEqual(array.getElementRowCol(1,1).getValue(), -0.5, "Result [1,1] MINVERSE(A202:B203)"); oParser = new parserFormula("MINVERSE(A204:C206)", "A2", ws); assert.ok(oParser.parse(), "MINVERSE(A204:C206)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 1, "Result [0,0] MINVERSE(A204:C206)"); assert.strictEqual(array.getElementRowCol(1,0).getValue(), -38, "Result [1,0] MINVERSE(A204:C206)"); assert.strictEqual(array.getElementRowCol(2,0).getValue(), 27, "Result [2,0] MINVERSE(A204:C206)"); assert.strictEqual(array.getElementRowCol(0,1).getValue(), -1, "Result [0,1] MINVERSE(A204:C206)"); assert.strictEqual(array.getElementRowCol(1,1).getValue(), 41, "Result [1,1] MINVERSE(A204:C206)"); assert.strictEqual(array.getElementRowCol(2,1).getValue(), -29, "Result [2,1] MINVERSE(A204:C206)"); assert.strictEqual(array.getElementRowCol(0,2).getValue(), 1, "Result [0,2] MINVERSE(A204:C206)"); assert.strictEqual(array.getElementRowCol(1,2).getValue(), -34, "Result [1,2] MINVERSE(A204:C206)"); assert.strictEqual(array.getElementRowCol(2,2).getValue(), 24, "Result [2,2] MINVERSE(A204:C206)"); oParser = new parserFormula("MINVERSE(A204:D207)", "A2", ws); assert.ok(oParser.parse(), "MINVERSE(A204:D207)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue().toFixed(5) - 0, -0.04108, "Result [0,0] MINVERSE(A204:D207)"); assert.strictEqual(array.getElementRowCol(1,0).getValue().toFixed(5) - 0, 0.47025, "Result [1,0] MINVERSE(A204:D207)"); assert.strictEqual(array.getElementRowCol(2,0).getValue().toFixed(5) - 0, -0.26629, "Result [2,0] MINVERSE(A204:D207)"); assert.strictEqual(array.getElementRowCol(3,0).getValue().toFixed(5) - 0, 0.04958, "Result [3,0] MINVERSE(A204:D207)"); assert.strictEqual(array.getElementRowCol(0,1).getValue().toFixed(5) - 0, 0.10057, "Result [0,1] MINVERSE(A204:D207)"); assert.strictEqual(array.getElementRowCol(1,1).getValue().toFixed(5) - 0, 0.33144, "Result [1,1] MINVERSE(A204:D207)"); assert.strictEqual(array.getElementRowCol(2,1).getValue().toFixed(5) - 0, -0.17564, "Result [2,1] MINVERSE(A204:D207)"); assert.strictEqual(array.getElementRowCol(3,1).getValue().toFixed(5) - 0, -0.05241, "Result [3,1] MINVERSE(A204:D207)"); assert.strictEqual(array.getElementRowCol(0,2).getValue().toFixed(5) - 0, 0.07790, "Result [0,2] MINVERSE(A204:D207)"); assert.strictEqual(array.getElementRowCol(1,2).getValue().toFixed(5) - 0, 0.07365, "Result [1,2] MINVERSE(A204:D207)"); assert.strictEqual(array.getElementRowCol(2,2).getValue().toFixed(5) - 0, -0.15014, "Result [2,2] MINVERSE(A204:D207)"); assert.strictEqual(array.getElementRowCol(3,2).getValue().toFixed(5) - 0, 0.04391, "Result [3,2] MINVERSE(A204:D207)"); assert.strictEqual(array.getElementRowCol(0,3).getValue().toFixed(5) - 0, 0.02975, "Result [0,3] MINVERSE(A204:D207)"); assert.strictEqual(array.getElementRowCol(1,3).getValue().toFixed(5) - 0, -1.09915, "Result [1,3] MINVERSE(A204:D207)"); assert.strictEqual(array.getElementRowCol(2,3).getValue().toFixed(5) - 0, 0.77904, "Result [2,3] MINVERSE(A204:D207)"); assert.strictEqual(array.getElementRowCol(3,3).getValue().toFixed(5) - 0, -0.00142, "Result [3,3] MINVERSE(A204:D207)"); oParser = new parserFormula("MINVERSE(A204:E208)", "A2", ws); assert.ok(oParser.parse(), "MINVERSE(A204:E208)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue().toFixed(5) - 0, -0.00516, "Result [0,0] MINVERSE(A204:E208)"); assert.strictEqual(array.getElementRowCol(1,0).getValue().toFixed(5) - 0, -0.60923, "Result [1,0] MINVERSE(A204:E208)"); assert.strictEqual(array.getElementRowCol(2,0).getValue().toFixed(5) - 0, 0.49022, "Result [2,0] MINVERSE(A204:E208)"); assert.strictEqual(array.getElementRowCol(3,0).getValue().toFixed(5) - 0, 0.05601, "Result [3,0] MINVERSE(A204:E208)"); assert.strictEqual(array.getElementRowCol(4,0).getValue().toFixed(5) - 0, -0.00326, "Result [4,0] MINVERSE(A204:E208)"); assert.strictEqual(array.getElementRowCol(0,1).getValue().toFixed(5) - 0, 0.02070, "Result [0,1] MINVERSE(A204:E208)"); assert.strictEqual(array.getElementRowCol(1,1).getValue().toFixed(5) - 0, 2.73184, "Result [1,1] MINVERSE(A204:E208)"); assert.strictEqual(array.getElementRowCol(2,1).getValue().toFixed(5) - 0, -1.85786, "Result [2,1] MINVERSE(A204:E208)"); assert.strictEqual(array.getElementRowCol(3,1).getValue().toFixed(5) - 0, -0.06672, "Result [3,1] MINVERSE(A204:E208)"); assert.strictEqual(array.getElementRowCol(4,1).getValue().toFixed(5) - 0, 0.00725, "Result [4,1] MINVERSE(A204:E208)"); assert.strictEqual(array.getElementRowCol(0,2).getValue().toFixed(5) - 0, 0.01274, "Result [0,2] MINVERSE(A204:E208)"); assert.strictEqual(array.getElementRowCol(1,2).getValue().toFixed(5) - 0, 2.03215, "Result [1,2] MINVERSE(A204:E208)"); assert.strictEqual(array.getElementRowCol(2,2).getValue().toFixed(5) - 0, -1.52268, "Result [2,2] MINVERSE(A204:E208)"); assert.strictEqual(array.getElementRowCol(3,2).getValue().toFixed(5) - 0, 0.03223, "Result [3,2] MINVERSE(A204:E208)"); assert.strictEqual(array.getElementRowCol(4,2).getValue().toFixed(5) - 0, 0.00591, "Result [4,2] MINVERSE(A204:E208)"); assert.strictEqual(array.getElementRowCol(0,3).getValue().toFixed(5) - 0, -0.00047, "Result [0,3] MINVERSE(A204:E208)"); assert.strictEqual(array.getElementRowCol(1,3).getValue().toFixed(5) - 0, -0.19109, "Result [1,3] MINVERSE(A204:E208)"); assert.strictEqual(array.getElementRowCol(2,3).getValue().toFixed(5) - 0, 0.14266, "Result [2,3] MINVERSE(A204:E208)"); assert.strictEqual(array.getElementRowCol(3,3).getValue().toFixed(5) - 0, -0.00683, "Result [3,3] MINVERSE(A204:E208)"); assert.strictEqual(array.getElementRowCol(4,3).getValue().toFixed(5) - 0, 0.00274, "Result [4,3] MINVERSE(A204:E208)"); assert.strictEqual(array.getElementRowCol(0,4).getValue().toFixed(5) - 0, 0.00659, "Result [0,4] MINVERSE(A204:E208)"); assert.strictEqual(array.getElementRowCol(1,4).getValue().toFixed(5) - 0, -0.19808, "Result [1,4] MINVERSE(A204:E208)"); assert.strictEqual(array.getElementRowCol(2,4).getValue().toFixed(5) - 0, 0.13882, "Result [2,4] MINVERSE(A204:E208)"); assert.strictEqual(array.getElementRowCol(3,4).getValue().toFixed(5) - 0, 0.00118, "Result [3,4] MINVERSE(A204:E208)"); assert.strictEqual(array.getElementRowCol(4,4).getValue().toFixed(5) - 0, -0.0006, "Result [4,4] MINVERSE(A204:E208)"); oParser = new parserFormula("MINVERSE({10,0;0,10})", "A2", ws); assert.ok(oParser.parse(), "MINVERSE({10,0;0,10})"); assert.strictEqual(oParser.calculate().getElementRowCol(0,0).getValue(), 0.1, "Result [0,0] MINVERSE({10,0;0,10})"); assert.strictEqual(oParser.calculate().getElementRowCol(0,1).getValue(), 0, "Result [0,1] MINVERSE({10,0;0,10})"); // died on this test assert.strictEqual(oParser.calculate().getElementRowCol(1,0).getValue(), 0, "Result [1,0] MINVERSE({10,0;0,10})"); assert.strictEqual(oParser.calculate().getElementRowCol(1,1).getValue(), 0.1, "Result [1,1] MINVERSE({10,0;0,10})"); oParser = new parserFormula("MINVERSE(TRUE)", "A2", ws); assert.ok(oParser.parse(), "MINVERSE(TRUE)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result MINVERSE(TRUE)"); oParser = new parserFormula("MINVERSE(10)", "A2", ws); assert.ok(oParser.parse(), "MINVERSE(10)"); assert.strictEqual(oParser.calculate().getValue(), 0.1, "Result MINVERSE(10)"); oParser = new parserFormula("MINVERSE(10,10,10,10)", "A2", ws); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "Result MINVERSE(10,10,10,10)"); oParser = new parserFormula("MINVERSE(str)", "A2", ws); assert.ok(oParser.parse(), "MINVERSE(str)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result MINVERSE(str)"); oParser = new parserFormula("MINVERSE({10})", "A2", ws); assert.ok(oParser.parse(), "MINVERSE({10})"); assert.strictEqual(oParser.calculate().getValue(), 0.1, "Result MINVERSE({10})"); oParser = new parserFormula("MINVERSE(J24)", "A2", ws); assert.ok(oParser.parse(), "MINVERSE(J24)"); assert.strictEqual(oParser.calculate().getValue(), 0.05, "Result MINVERSE('20')"); oParser = new parserFormula("MINVERSE(J17:J20)", "A2", ws); assert.ok(oParser.parse(), "MINVERSE(J17:J20)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result MINVERSE(J17:J20)"); oParser = new parserFormula("MINVERSE(J18:J18)", "A2", ws); assert.ok(oParser.parse(), "MINVERSE(J18:J18)"); assert.strictEqual(oParser.calculate().getValue(), 0.1, "Result MINVERSE(J18:J18)"); oParser = new parserFormula("MINVERSE(J25:H26)", "A2", ws); assert.ok(oParser.parse(), "MINVERSE(J25:H26)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", "Result MINVERSE(J25:H26)"); oParser = new parserFormula("MINVERSE(J17:J24)", "A2", ws); assert.ok(oParser.parse(), "MINVERSE(J25:H26)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", "Result MINVERSE(J25:H26)"); }); QUnit.test("Test: \"FIND\"", function (assert) { ws.getRange2("A101:F101").cleanAll(); ws.getRange2("A101").setValue("Miriam McGovern"); oParser = new parserFormula('FIND("M",A101)', "A2", ws); assert.ok(oParser.parse(), 'FIND("M",A101)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'FIND("M",A101)'); oParser = new parserFormula('FIND("m",A101)', "A2", ws); assert.ok(oParser.parse(), 'FIND("m",A101)'); assert.strictEqual(oParser.calculate().getValue(), 6, 'FIND("m",A101)'); oParser = new parserFormula('FIND("M",A101,3)', "A2", ws); assert.ok(oParser.parse(), 'FIND("M",A101,3)'); assert.strictEqual(oParser.calculate().getValue(), 8, 'FIND("M",A101,3)'); oParser = new parserFormula('FIND("U",TRUE)', "A2", ws); assert.ok(oParser.parse(), 'FIND("T",TRUE)'); assert.strictEqual(oParser.calculate().getValue(), 3, 'FIND("T",TRUE)'); // for bug 68343 ws.getRange2("B101").setValue("31° 57' 14.6\" S BT 3 18° 54' 20.3\" E"); oParser = new parserFormula('FIND(""" S",B101,1)', "A2", ws); assert.ok(oParser.parse(), 'FIND(""" S",B101,1)'); assert.strictEqual(oParser.calculate().getValue(), 13, 'FIND(""" S",B101,1)'); oParser = new parserFormula('FIND(" S",B101,1)', "A2", ws); assert.ok(oParser.parse(), 'FIND(" S",B101,1)'); assert.strictEqual(oParser.calculate().getValue(), 14, 'FIND(" S",B101,1)'); ws.getRange2("C101").setValue("6\" S"); oParser = new parserFormula('FIND(""" S",C101,1)', "A2", ws); assert.ok(oParser.parse(), 'FIND(""" S",C101,1)'); assert.strictEqual(oParser.calculate().getValue(), 2, 'FIND(""" S",C101,1)'); oParser = new parserFormula('FIND(" S",C101,1)', "A2", ws); assert.ok(oParser.parse(), 'FIND(" S",C101,1)'); assert.strictEqual(oParser.calculate().getValue(), 3, 'FIND(" S",C101,1)'); ws.getRange2("D101").setValue("testtest \" String\"abcdString"); oParser = new parserFormula('FIND(""" String",D101,1)', "A2", ws); assert.ok(oParser.parse(), 'FIND(""" String",D101,1)'); assert.strictEqual(oParser.calculate().getValue(), 10, 'FIND(""" String",D101,1)'); oParser = new parserFormula('FIND(" String",D101,1)', "A2", ws); assert.ok(oParser.parse(), 'FIND(" String",D101,1)'); assert.strictEqual(oParser.calculate().getValue(), 11, 'FIND(" String",D101,1)'); testArrayFormula2(assert, "FIND", 2, 3); }); QUnit.test("Test: \"FINDB\"", function (assert) { ws.getRange2("A101").setValue("Miriam McGovern"); oParser = new parserFormula('FINDB("M",A101)', "A2", ws); assert.ok(oParser.parse(), 'FINDB("M",A101)'); assert.strictEqual(oParser.calculate().getValue(), 1, 'FINDB("M",A101)'); oParser = new parserFormula('FINDB("m",A101)', "A2", ws); assert.ok(oParser.parse(), 'FINDB("m",A101)'); assert.strictEqual(oParser.calculate().getValue(), 6, 'FINDB("m",A101)'); oParser = new parserFormula('FINDB("M",A101,3)', "A2", ws); assert.ok(oParser.parse(), 'FINDB("M",A101,3)'); assert.strictEqual(oParser.calculate().getValue(), 8, 'FINDB("M",A101,3)'); oParser = new parserFormula('FINDB("U",TRUE)', "A2", ws); assert.ok(oParser.parse(), 'FINDB("T",TRUE)'); assert.strictEqual(oParser.calculate().getValue(), 3, 'FINDB("T",TRUE)'); }); QUnit.test("Test: \">\"", function (assert) { oParser = new parserFormula('1.123>1.5', "A2", ws); assert.ok(oParser.parse(), '1.123>1.5'); assert.strictEqual(oParser.calculate().getValue(), "FALSE", '1.123>1.5'); oParser = new parserFormula('1.555>1.5', "A2", ws); assert.ok(oParser.parse(), '1.555>1.5'); assert.strictEqual(oParser.calculate().getValue(), "TRUE", '1.555>1.5'); }); QUnit.test("Test: \"<\"", function (assert) { oParser = new parserFormula('1.123<1.5', "A2", ws); assert.ok(oParser.parse(), '1.123<1.5'); assert.strictEqual(oParser.calculate().getValue(), "TRUE", '1.123<1.5'); oParser = new parserFormula('1.555<1.5', "A2", ws); assert.ok(oParser.parse(), '1.555<1.5'); assert.strictEqual(oParser.calculate().getValue(), "FALSE", '1.555<1.5'); }); QUnit.test("Test: \"=\"", function (assert) { oParser = new parserFormula('1.123=1.5', "A2", ws); assert.ok(oParser.parse(), '1.123=1.5'); assert.strictEqual(oParser.calculate().getValue(), "FALSE", '1.123=1.5'); oParser = new parserFormula('1.555=1.555', "A2", ws); assert.ok(oParser.parse(), '1.555=1.555'); assert.strictEqual(oParser.calculate().getValue(), "TRUE", '1.555=1.555'); }); QUnit.test("Test: \"<>\"", function (assert) { oParser = new parserFormula('1.123<>1.5', "A2", ws); assert.ok(oParser.parse(), '1.123<>1.5'); assert.strictEqual(oParser.calculate().getValue(), "TRUE", '1.123<>1.5'); oParser = new parserFormula('1.555<>1.555', "A2", ws); assert.ok(oParser.parse(), '1.555<>1.555'); assert.strictEqual(oParser.calculate().getValue(), "FALSE", '1.555<>1.555'); }); QUnit.test("Test: \">=\"", function (assert) { oParser = new parserFormula('1.123>=1.5', "A2", ws); assert.ok(oParser.parse(), '1.123>=1.5'); assert.strictEqual(oParser.calculate().getValue(), "FALSE", '1.123>=1.5'); oParser = new parserFormula('1.555>=1.555', "A2", ws); assert.ok(oParser.parse(), '1.555>=1.555'); assert.strictEqual(oParser.calculate().getValue(), "TRUE", '1.555>=1.555'); oParser = new parserFormula('1.557>=1.555', "A2", ws); assert.ok(oParser.parse(), '1.557>=1.555'); assert.strictEqual(oParser.calculate().getValue(), "TRUE", '1.557>=1.555'); }); QUnit.test("Test: \"<=\"", function (assert) { oParser = new parserFormula('1.123<=1.5', "A2", ws); assert.ok(oParser.parse(), '1.123<=1.5'); assert.strictEqual(oParser.calculate().getValue(), "TRUE", '1.123<=1.5'); oParser = new parserFormula('1.555<=1.555', "A2", ws); assert.ok(oParser.parse(), '1.555<=1.555'); assert.strictEqual(oParser.calculate().getValue(), "TRUE", '1.555<=1.555'); oParser = new parserFormula('1.557<=1.555', "A2", ws); assert.ok(oParser.parse(), '1.557<=1.555'); assert.strictEqual(oParser.calculate().getValue(), "FALSE", '1.557<=1.555'); }); QUnit.test("Test: \"ADDRESS\"", function (assert) { oParser = new parserFormula("ADDRESS(2,3,2)", "A2", ws); assert.ok(oParser.parse(), "ADDRESS(2,3,2)"); assert.strictEqual(oParser.calculate().getValue(), "C$2", "ADDRESS(2,3,2)"); oParser = new parserFormula("ADDRESS(2,3,2,FALSE)", "A2", ws); assert.ok(oParser.parse(), "ADDRESS(2,3,2,FALSE)"); assert.strictEqual(oParser.calculate().getValue(), "R2C[3]", "ADDRESS(2,3,2,FALSE)"); oParser = new parserFormula('ADDRESS(2,3,1,FALSE,"[Book1]Sheet1")', "A2", ws); assert.ok(oParser.parse(), 'ADDRESS(2,3,1,FALSE,"[Book1]Sheet1")'); assert.strictEqual(oParser.calculate().getValue(), "'[Book1]Sheet1'!R2C3", 'ADDRESS(2,3,1,FALSE,"[Book1]Sheet1")'); oParser = new parserFormula('ADDRESS(2,3,1,FALSE,"EXCEL SHEET")', "A2", ws); assert.ok(oParser.parse(), 'ADDRESS(2,3,1,FALSE,"EXCEL SHEET")'); assert.strictEqual(oParser.calculate().getValue(), "'EXCEL SHEET'!R2C3", 'ADDRESS(2,3,1,FALSE,"EXCEL SHEET")'); ws.getRange2("A101").setValue(""); oParser = new parserFormula("ADDRESS(2,3,2,1,A101)", "A2", ws); assert.ok(oParser.parse(), "ADDRESS(2,3,2,1,A101"); assert.strictEqual(oParser.calculate().getValue(), "!C$2", "ADDRESS(2,3,2,1,A101"); ws.getRange2("A101").setValue("'"); oParser = new parserFormula("ADDRESS(2,3,2,1,A101)", "A2", ws); assert.ok(oParser.parse(), "ADDRESS(2,3,2,1,A101"); assert.strictEqual(oParser.calculate().getValue(), "!C$2", "ADDRESS(2,3,2,1,A101"); oParser = new parserFormula('ADDRESS(2,3,2,1,"")', "A2", ws); assert.ok(oParser.parse(), 'ADDRESS(2,3,2,1,"")'); assert.strictEqual(oParser.calculate().getValue(), "!C$2", 'ADDRESS(2,3,2,1,"")'); oParser = new parserFormula("ADDRESS(2,3,2,1,\"'\")", "A2", ws); assert.ok(oParser.parse(), "ADDRESS(2,3,2,1,\"'\")"); assert.strictEqual(oParser.calculate().getValue(), "''''!C$2", "ADDRESS(2,3,2,1,\"'\")"); oParser = new parserFormula("ADDRESS(2,3,,,1)", "A2", ws); assert.ok(oParser.parse(), "ADDRESS(2,3,,,1)"); assert.strictEqual(oParser.calculate().getValue(), "'1'!$C$2", "ADDRESS(2,3,,,1)"); oParser = new parserFormula("ADDRESS(2,3,1,,1)", "A2", ws); assert.ok(oParser.parse(), "ADDRESS(2,3,1,,1)"); assert.strictEqual(oParser.calculate().getValue(), "'1'!$C$2", "ADDRESS(2,3,1,,1)"); oParser = new parserFormula("ADDRESS(2,3,2,,1)", "A2", ws); assert.ok(oParser.parse(), "ADDRESS(2,3,2,,1)"); assert.strictEqual(oParser.calculate().getValue(), "'1'!C$2", "ADDRESS(2,3,2,,1)"); oParser = new parserFormula("ADDRESS(2,3,,TRUE,1)", "A2", ws); assert.ok(oParser.parse(), "ADDRESS(2,3,,TRUE,1)"); assert.strictEqual(oParser.calculate().getValue(), "'1'!$C$2", "ADDRESS(2,3,,TRUE,1)"); oParser = new parserFormula("ADDRESS(2,3,,FALSE,1)", "A2", ws); assert.ok(oParser.parse(), "ADDRESS(2,3,,FALSE,1)"); assert.strictEqual(oParser.calculate().getValue(), "'1'!R2C3", "ADDRESS(2,3,,FALSE,1)"); oParser = new parserFormula("ADDRESS(2,3,,FALSE,1)", "A2", ws); assert.ok(oParser.parse(), "ADDRESS(2,3,,FALSE,1)"); assert.strictEqual(oParser.calculate().getValue(), "'1'!R2C3", "ADDRESS(2,3,,FALSE,1)"); oParser = new parserFormula("ADDRESS(1,7,,)", "A2", ws); assert.ok(oParser.parse(), "ADDRESS(1,7,,)"); assert.strictEqual(oParser.calculate().getValue(), "$G$1", "ADDRESS(1,7,,)"); oParser = new parserFormula("ADDRESS(1,7,,,)", "A2", ws); assert.ok(oParser.parse(), "ADDRESS(1,7,,,)"); assert.strictEqual(oParser.calculate().getValue(), "$G$1", "ADDRESS(1,7,,,)"); oParser = new parserFormula("ADDRESS(2.123,3.3213,2)", "A2", ws); assert.ok(oParser.parse(), "ADDRESS(2.123,3.3213,2)"); assert.strictEqual(oParser.calculate().getValue(), "C$2", "ADDRESS(2.123,3.3213,2)"); testArrayFormula2(assert, "ADDRESS", 2, 5); }); QUnit.test("Test: \"SEQUENCE\"", function (assert) { ws.getRange2("G10").setValue(""); ws.getRange2("G11").setValue(); ws.getRange2("G12").setValue("10"); ws.getRange2("G13").setValue("-10"); ws.getRange2("G14").setValue("TRUE"); ws.getRange2("G15").setValue("FALSE"); ws.getRange2("G16").setValue("2s"); ws.getRange2("G17").setValue("#N/A"); ws.getRange2("G18").setValue("{2;3;4;5}"); // vertical test ws.getRange2("G19").setValue("1"); ws.getRange2("G20").setValue("2"); ws.getRange2("G21").setValue("3"); ws.getRange2("G22").setValue("4"); // horizontal test ws.getRange2("H19").setValue("1"); ws.getRange2("I19").setValue("2"); ws.getRange2("J19").setValue("3"); ws.getRange2("K19").setValue("4"); ws.getRange2("C102").setValue("1"); ws.getRange2("D102").setValue("2"); ws.getRange2("E102").setValue("3"); ws.getRange2("F102").setValue("4"); ws.getRange2("E103").setValue(""); ws.getRange2("F103").setValue(""); // cellsRange oParser = new parserFormula('SEQUENCE(G19:G22)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(G19:G22)'); let array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(G19:G22)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SEQUENCE(G19:G22)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 1, "Result of SEQUENCE(G19:G22)[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 1, "Result of SEQUENCE(G19:G22)[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 1, "Result of SEQUENCE(G19:G22)[3,0]"); oParser = new parserFormula('SEQUENCE(C102:F102,C102:D102,E102:F103)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(C102:F102,C102:D102,E102:F103)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 3, "Result of SEQUENCE(C102:F102,C102:D102,E102:F103)[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 0, "Result of SEQUENCE(C102:F102,C102:D102,E102:F103)[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", "Result of SEQUENCE(C102:F102,C102:D102,E102:F103)[2,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 4, "Result of SEQUENCE(C102:F102,C102:D102,E102:F103)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 0, "Result of SEQUENCE(C102:F102,C102:D102,E102:F103)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "", "Result of SEQUENCE(C102:F102,C102:D102,E102:F103)[2,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#N/A", "Result of SEQUENCE(C102:F102,C102:D102,E102:F103)[0,2]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "#N/A", "Result of SEQUENCE(C102:F102,C102:D102,E102:F103)[1,2]"); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "", "Result of SEQUENCE(C102:F102,C102:D102,E102:F103)[2,2]"); oParser = new parserFormula('SEQUENCE(G19:G22, G19:G20, G21:G22)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(G19:G22, G19:G20, G21:G22)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 3, "Result of SEQUENCE(G19:G22, G19:G20, G21:G22)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SEQUENCE(G19:G22, G19:G20, G21:G22)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 4, "Result of SEQUENCE(G19:G22, G19:G20, G21:G22)[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", "Result of SEQUENCE(G19:G22, G19:G20, G21:G22)[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#N/A", "Result of SEQUENCE(G19:G22, G19:G20, G21:G22)[3,0]"); oParser = new parserFormula('SEQUENCE(H19:K19, H19:I19, J19:K19)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(H19:K19, H19:I19, J19:K19)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 3, "Result of SEQUENCE(H19:K19, H19:I19, J19:K19)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 4, "Result of SEQUENCE(H19:K19, H19:I19, J19:K19)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#N/A", "Result of SEQUENCE(H19:K19, H19:I19, J19:K19)[0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "#N/A", "Result of SEQUENCE(H19:K19, H19:I19, J19:K19)[0,3]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of SEQUENCE(H19:K19, H19:I19, J19:K19)[1,0]"); oParser = new parserFormula('SEQUENCE(H19:K19, H19:I19, J19)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(H19:K19, H19:I19, J19)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 3, "Result of SEQUENCE(H19:K19, H19:I19, J19)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, "Result of SEQUENCE(H19:K19, H19:I19, J19)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#N/A", "Result of SEQUENCE(H19:K19, H19:I19, J19)[0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "#N/A", "Result of SEQUENCE(H19:K19, H19:I19, J19)[0,3]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of SEQUENCE(H19:K19, H19:I19, J19)[1,0]"); oParser = new parserFormula('SEQUENCE(G10)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(G10)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of SEQUENCE(G10)"); // #CALC! oParser = new parserFormula('SEQUENCE(G11)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(G11)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of SEQUENCE(G11)"); // #CALC! oParser = new parserFormula('SEQUENCE(G10,2)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(G10,2)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of SEQUENCE(G10,2)"); // #CALC! oParser = new parserFormula('SEQUENCE(G11,2)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(G11,2)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of SEQUENCE(G11,2)"); // #CALC! oParser = new parserFormula("SEQUENCE(G12)", "A2", ws); assert.ok(oParser.parse(), "SEQUENCE(G12)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(10)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SEQUENCE(10)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, "Result of SEQUENCE(10)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SEQUENCE(10)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 3, "Result of SEQUENCE(10)[2,0]"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 6, "Result of SEQUENCE(10)[5,0]"); assert.strictEqual(array.getElementRowCol(9, 0).getValue(), 10, "Result of SEQUENCE(10)[9,0]"); oParser = new parserFormula('SEQUENCE(G13)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(G13)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of SEQUENCE(G13)"); oParser = new parserFormula('SEQUENCE(G14)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(G14)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(G14)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SEQUENCE(G14)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of SEQUENCE(G14)[1,0]"); oParser = new parserFormula('SEQUENCE(G15)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(G15)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of SEQUENCE(G15)"); // #CALC! oParser = new parserFormula('SEQUENCE(G16)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(G16)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of SEQUENCE(G16)"); oParser = new parserFormula('SEQUENCE(G17)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(G17)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of SEQUENCE(G17)"); oParser = new parserFormula('SEQUENCE(G18)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(G18)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of SEQUENCE(G18)"); // arg[0] tests (rows) oParser = new parserFormula("SEQUENCE(2)", "A2", ws); assert.ok(oParser.parse(), "SEQUENCE(2)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(2)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SEQUENCE(2)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, "Result of SEQUENCE(2)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SEQUENCE(2)[1,1]"); oParser = new parserFormula("SEQUENCE(0.9)", "A2", ws); assert.ok(oParser.parse(), "SEQUENCE(0.9)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of SEQUENCE(0.9)"); // #CALC! oParser = new parserFormula("SEQUENCE(2.9)", "A2", ws); assert.ok(oParser.parse(), "SEQUENCE(2.9)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(2.9)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SEQUENCE(2.9)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, "Result of SEQUENCE(2.9)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SEQUENCE(2.9)[1,1]"); oParser = new parserFormula("SEQUENCE(,2)", "A2", ws); assert.ok(oParser.parse(), "SEQUENCE(,2)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(,2)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, "Result of SEQUENCE(,2)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of SEQUENCE(,2)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SEQUENCE(,2)[1,1]"); oParser = new parserFormula("SEQUENCE(-2)", "A2", ws); assert.ok(oParser.parse(), "SEQUENCE(-2)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!"); oParser = new parserFormula('SEQUENCE("2")', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE("2")'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE('2')[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SEQUENCE('2')[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, "Result of SEQUENCE('2')[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SEQUENCE('2')[1,1]"); oParser = new parserFormula('SEQUENCE("2s")', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE("2s")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of SEQUENCE('2s')"); oParser = new parserFormula('SEQUENCE(TRUE)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(TRUE)"); oParser = new parserFormula('SEQUENCE(FALSE)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(FALSE)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of SEQUENCE(FALSE)"); // #CALC! oParser = new parserFormula("SEQUENCE(,)", "A2", ws); assert.ok(oParser.parse(), "SEQUENCE(,)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(,)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SEQUENCE(,)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of SEQUENCE(,)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SEQUENCE(,)[1,1]"); oParser = new parserFormula("SEQUENCE(,,)", "A2", ws); assert.ok(oParser.parse(), "SEQUENCE(,,)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(,,)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SEQUENCE(,,)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of SEQUENCE(,,)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SEQUENCE(,,)[1,1]"); oParser = new parserFormula("SEQUENCE(,,,)", "A2", ws); assert.ok(oParser.parse(), "SEQUENCE(,,,)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(,,,)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SEQUENCE(,,,)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of SEQUENCE(,,,)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SEQUENCE(,,,)[1,1]"); oParser = new parserFormula("SEQUENCE(,,,2)", "A2", ws); assert.ok(oParser.parse(), "SEQUENCE(,,,2)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(,,,2)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SEQUENCE(,,,2)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of SEQUENCE(,,,2)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SEQUENCE(,,,2)[1,1]"); // arg[1] tests (columns) oParser = new parserFormula("SEQUENCE(2,3)", "A2", ws); assert.ok(oParser.parse(), "SEQUENCE(2,3)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(2,3)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, "Result of SEQUENCE(2,3)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 3, "Result of SEQUENCE(2,3)[0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "", "Result of SEQUENCE(2,3)[0,3]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 4, "Result of SEQUENCE(2,3)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 5, "Result of SEQUENCE(2,3)[1,1]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 6, "Result of SEQUENCE(2,3)[1,2]"); assert.strictEqual(array.getElementRowCol(1, 3).getValue(), "", "Result of SEQUENCE(2,3)[1,3]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", "Result of SEQUENCE(2,3)[2,0]"); oParser = new parserFormula("SEQUENCE(1,1)", "A2", ws); assert.ok(oParser.parse(), "SEQUENCE(1,1)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(1,1)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SEQUENCE(1,1)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#N/A", "Result of SEQUENCE(1,1)[0,2]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of SEQUENCE(1,1)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SEQUENCE(1,1)[1,1]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "#N/A", "Result of SEQUENCE(1,1)[1,2]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", "Result of SEQUENCE(1,1)[2,0]"); oParser = new parserFormula("SEQUENCE(1,2)", "A2", ws); assert.ok(oParser.parse(), "SEQUENCE(1,2)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(1,2)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, "Result of SEQUENCE(1,2)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "", "Result of SEQUENCE(1,2)[0,2]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of SEQUENCE(1,2)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SEQUENCE(1,2)[1,1]"); oParser = new parserFormula('SEQUENCE(2,"2")', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,"2")'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(2,'2')[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, "Result of SEQUENCE(2,'2')[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "", "Result of SEQUENCE(2,'2')[0,2]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, "Result of SEQUENCE(2,'2')[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, "Result of SEQUENCE(2,'2')[1,1]"); oParser = new parserFormula('SEQUENCE(2,"2s")', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,"2s")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of SEQUENCE(2,'2s')"); oParser = new parserFormula('SEQUENCE(2,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(2,TRUE)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SEQUENCE(2,TRUE)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, "Result of SEQUENCE(2,TRUE)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SEQUENCE(2,TRUE)[1,1]"); oParser = new parserFormula('SEQUENCE(2,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of SEQUENCE(2,FALSE)"); // #CALC! oParser = new parserFormula('SEQUENCE(2,G10)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,G10)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of SEQUENCE(2,G10)"); // #CALC! oParser = new parserFormula('SEQUENCE(2,G11)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,G11)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of SEQUENCE(2,G11)"); // #CALC! oParser = new parserFormula("SEQUENCE(2,G12)", "A2", ws); assert.ok(oParser.parse(), "SEQUENCE(2,G12)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(2,10)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, "Result of SEQUENCE(2,10)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 3, "Result of SEQUENCE(2,10)[0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 4, "Result of SEQUENCE(2,10)[0,3]"); assert.strictEqual(array.getElementRowCol(0, 5).getValue(), 6, "Result of SEQUENCE(2,10)[0,5]"); assert.strictEqual(array.getElementRowCol(0, 9).getValue(), 10, "Result of SEQUENCE(2,10)[0,9]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 11, "Result of SEQUENCE(2,10)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 12, "Result of SEQUENCE(2,10)[1,1]"); assert.strictEqual(array.getElementRowCol(1, 5).getValue(), 16, "Result of SEQUENCE(2,10)[1,5]"); assert.strictEqual(array.getElementRowCol(1, 9).getValue(), 20, "Result of SEQUENCE(2,10)[1,9]"); oParser = new parserFormula('SEQUENCE(2,G13)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,G13)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of SEQUENCE(2,G13)"); oParser = new parserFormula('SEQUENCE(2,G14)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,G14)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(2,TRUE)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SEQUENCE(2,TRUE)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, "Result of SEQUENCE(2,TRUE)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SEQUENCE(2,TRUE)[1,1]"); oParser = new parserFormula('SEQUENCE(2,G15)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,G15)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of SEQUENCE(2,G15)"); // #CALC! oParser = new parserFormula('SEQUENCE(G16)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(G16)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of SEQUENCE(G16)"); oParser = new parserFormula('SEQUENCE(G17)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(G17)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of SEQUENCE(G17)"); oParser = new parserFormula('SEQUENCE(G18)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(G18)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of SEQUENCE(G18)"); // arg[2] tests (start) oParser = new parserFormula("SEQUENCE(2,2,)", "A2", ws); assert.ok(oParser.parse(), "SEQUENCE(2,2,)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(2,2,)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, "Result of SEQUENCE(2,2,)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, "Result of SEQUENCE(2,2,)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, "Result of SEQUENCE(2,2,)[1,1]"); oParser = new parserFormula("SEQUENCE(2,2,2)", "A2", ws); assert.ok(oParser.parse(), "SEQUENCE(2,2,2)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of SEQUENCE(2,2,2)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, "Result of SEQUENCE(2,2,2)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 4, "Result of SEQUENCE(2,2,2)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 5, "Result of SEQUENCE(2,2,2)[1,1]"); oParser = new parserFormula('SEQUENCE(2,2,"2")', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,"2")'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of SEQUENCE(2,2,2)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, "Result of SEQUENCE(2,2,2)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 4, "Result of SEQUENCE(2,2,2)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 5, "Result of SEQUENCE(2,2,2)[1,1]"); oParser = new parserFormula('SEQUENCE(2,2,"2s")', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,"2s")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of SEQUENCE(2,2,'2s')"); oParser = new parserFormula('SEQUENCE(2,2,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(2,2,TRUE)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, "Result of SEQUENCE(2,2,TRUE)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, "Result of SEQUENCE(2,2,TRUE)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, "Result of SEQUENCE(2,2,TRUE)[1,1]"); oParser = new parserFormula('SEQUENCE(2,2,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,FALSE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 0, "Result of SEQUENCE(2,2,FALSE)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, "Result of SEQUENCE(2,2,FALSE)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, "Result of SEQUENCE(2,2,FALSE)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 3, "Result of SEQUENCE(2,2,FALSE)[1,1]"); oParser = new parserFormula('SEQUENCE(2,2,G10)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,G10)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 0, "Result of SEQUENCE(2,2,G10)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, "Result of SEQUENCE(2,2,G10)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, "Result of SEQUENCE(2,2,G10)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 3, "Result of SEQUENCE(2,2,G10)[1,1]"); oParser = new parserFormula('SEQUENCE(2,2,G11)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,G11)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 0, "Result of SEQUENCE(2,2,G11)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, "Result of SEQUENCE(2,2,G11)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, "Result of SEQUENCE(2,2,G11)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 3, "Result of SEQUENCE(2,2,G11)[1,1]"); oParser = new parserFormula('SEQUENCE(2,2,G12)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,G12)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 10, "Result of SEQUENCE(2,2,G12)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 11, "Result of SEQUENCE(2,2,G12)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 12, "Result of SEQUENCE(2,2,G12)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 13, "Result of SEQUENCE(2,2,G12)[1,1]"); oParser = new parserFormula('SEQUENCE(2,2,G13)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,G13)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), -10, "Result of SEQUENCE(2,2,G13)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), -9, "Result of SEQUENCE(2,2,G13)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), -8, "Result of SEQUENCE(2,2,G13)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), -7, "Result of SEQUENCE(2,2,G13)[1,1]"); oParser = new parserFormula('SEQUENCE(2,2,G14)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,G14)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(2,2,G14)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, "Result of SEQUENCE(2,2,G14)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, "Result of SEQUENCE(2,2,G14)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, "Result of SEQUENCE(2,2,G14)[1,1]"); oParser = new parserFormula('SEQUENCE(2,2,G15)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,G15)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 0, "Result of SEQUENCE(2,2,G15)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, "Result of SEQUENCE(2,2,G15)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, "Result of SEQUENCE(2,2,G15)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 3, "Result of SEQUENCE(2,2,G15)[1,1]"); oParser = new parserFormula('SEQUENCE(2,2,G16)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,G16)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of SEQUENCE(2,2,G16)"); oParser = new parserFormula('SEQUENCE(2,2,G17)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,G17)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of SEQUENCE(2,2,G17)"); oParser = new parserFormula('SEQUENCE(2,2,G18)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,G18)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of SEQUENCE(2,2,G18)"); // arg[3] tests (step) oParser = new parserFormula("SEQUENCE(2,2,2,)", "A2", ws); assert.ok(oParser.parse(), "SEQUENCE(2,2,2,)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of SEQUENCE(2,2,2,)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, "Result of SEQUENCE(2,2,2,)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 4, "Result of SEQUENCE(2,2,2,)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 5, "Result of SEQUENCE(2,2,2,)[1,1]"); oParser = new parserFormula("SEQUENCE(2,2,0,-2)", "A2", ws); assert.ok(oParser.parse(), "SEQUENCE(2,2,0,-2)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 0, "Result of SEQUENCE(2,2,0,-2)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), -2, "Result of SEQUENCE(2,2,0,-2)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), -4, "Result of SEQUENCE(2,2,0,-2)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), -6, "Result of SEQUENCE(2,2,0,-2)[1,1]"); oParser = new parserFormula('SEQUENCE(2,2,0,"2")', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,0,"2")'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 0, "Result of SEQUENCE(2,2,0,'2')[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, "Result of SEQUENCE(2,2,0,'2')[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 4, "Result of SEQUENCE(2,2,0,'2')[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 6, "Result of SEQUENCE(2,2,0,'2')[1,1]"); oParser = new parserFormula('SEQUENCE(2,2,0,"2s")', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,0,"2s")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of SEQUENCE(2,2,0,'2s')"); oParser = new parserFormula('SEQUENCE(2,2,2,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,2,TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of SEQUENCE(2,2,2,TRUE)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, "Result of SEQUENCE(2,2,2,TRUE)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 4, "Result of SEQUENCE(2,2,2,TRUE)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 5, "Result of SEQUENCE(2,2,2,TRUE)[1,1]"); oParser = new parserFormula('SEQUENCE(2,2,2,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,2,FALSE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of SEQUENCE(2,2,2,FALSE)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, "Result of SEQUENCE(2,2,2,FALSE)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, "Result of SEQUENCE(2,2,2,FALSE)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 2, "Result of SEQUENCE(2,2,2,FALSE)[1,1]"); oParser = new parserFormula('SEQUENCE(2,2,2,G10)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,2,G10)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of SEQUENCE(2,2,2,G10)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, "Result of SEQUENCE(2,2,2,G10)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, "Result of SEQUENCE(2,2,2,G10)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 2, "Result of SEQUENCE(2,2,2,G10)[1,1]"); oParser = new parserFormula('SEQUENCE(2,2,2,G11)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,2,G11)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of SEQUENCE(2,2,2,G11)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, "Result of SEQUENCE(2,2,2,G11)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, "Result of SEQUENCE(2,2,2,G11)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 2, "Result of SEQUENCE(2,2,2,G11)[1,1]"); oParser = new parserFormula('SEQUENCE(2,2,2,G12)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,2,G12)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of SEQUENCE(2,2,2,G12)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 12, "Result of SEQUENCE(2,2,2,G12)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 22, "Result of SEQUENCE(2,2,2,G12)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 32, "Result of SEQUENCE(2,2,2,G12)[1,1]"); oParser = new parserFormula('SEQUENCE(2,2,2,G13)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,2,G13)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of SEQUENCE(2,2,2,G13)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), -8, "Result of SEQUENCE(2,2,2,G13)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), -18, "Result of SEQUENCE(2,2,2,G13)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), -28, "Result of SEQUENCE(2,2,2,G13)[1,1]"); oParser = new parserFormula('SEQUENCE(2,2,2,G14)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,2,G14)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of SEQUENCE(2,2,2,G14)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, "Result of SEQUENCE(2,2,2,G14)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 4, "Result of SEQUENCE(2,2,2,G14)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 5, "Result of SEQUENCE(2,2,2,G14)[1,1]"); oParser = new parserFormula('SEQUENCE(2,2,2,G15)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,2,G15)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of SEQUENCE(2,2,2,G15)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, "Result of SEQUENCE(2,2,2,G15)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, "Result of SEQUENCE(2,2,2,G15)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 2, "Result of SEQUENCE(2,2,2,G15)[1,1]"); oParser = new parserFormula('SEQUENCE(2,2,2,G16)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,2,G16)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of SEQUENCE(2,2,2,G16)"); oParser = new parserFormula('SEQUENCE(2,2,2,G17)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,2,G17)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", "Result of SEQUENCE(2,2,2,G17)"); oParser = new parserFormula('SEQUENCE(2,2,2,G18)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2,2,2,G18)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of SEQUENCE(2,2,2,G18)"); // array/cellsRange tests oParser = new parserFormula('SEQUENCE({1,2;2,3})', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE({1,2;2,3})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE({1,2;2,3})[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, "Result of SEQUENCE({1,2;2,3})[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 1, "Result of SEQUENCE({1,2;2,3})[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 1, "Result of SEQUENCE({1,2;2,3})[1,1]"); oParser = new parserFormula('SEQUENCE(1,{2,2;2,2})', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(1,{2,2;2,2})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(1,{2,2;2,2})[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, "Result of SEQUENCE(1,{2,2;2,2})[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 1, "Result of SEQUENCE(1,{2,2;2,2})[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 1, "Result of SEQUENCE(1,{2,2;2,2})[1,1]"); oParser = new parserFormula('SEQUENCE(1,2,{2,2;2,2})', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(1,2,{2,2;2,2})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of SEQUENCE(1,2,{2,2;2,2})[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, "Result of SEQUENCE(1,2,{2,2;2,2})[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, "Result of SEQUENCE(1,2,{2,2;2,2})[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 2, "Result of SEQUENCE(1,2,{2,2;2,2})[1,1]"); oParser = new parserFormula('SEQUENCE(1,2,4,{2,2;2,2})', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(1,2,4,{2,2;2,2})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 4, "Result of SEQUENCE(1,2,2,{2,2;2,2})[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 4, "Result of SEQUENCE(1,2,2,{2,2;2,2})[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 4, "Result of SEQUENCE(1,2,2,{2,2;2,2})[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, "Result of SEQUENCE(1,2,2,{2,2;2,2})[1,1]"); oParser = new parserFormula('SEQUENCE({1,2,3},{1,2},1,1)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE({1,2,3},{1,2},1,1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE({1,2,3},{1,2},1,1)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, "Result of SEQUENCE({1,2,3},{1,2},1,1)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#N/A", "Result of SEQUENCE({1,2,3},{1,2},1,1)[0,2]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of SEQUENCE({1,2,3},{1,2},1,1)[1,0]"); oParser = new parserFormula('SEQUENCE({1,2,3;3,2,1},{1;2},1,1)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE({1,2,3;3,2,1},{1;2},1,1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE({1,2,3;3,2,1},{1;2},1,1)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, "Result of SEQUENCE({1,2,3;3,2,1},{1;2},1,1)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 1, "Result of SEQUENCE({1,2,3;3,2,1},{1;2},1,1)[0,2]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 1, "Result of SEQUENCE({1,2,3;3,2,1},{1;2},1,1)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 1, "Result of SEQUENCE({1,2,3;3,2,1},{1;2},1,1)[1,1]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 1, "Result of SEQUENCE({1,2,3;3,2,1},{1;2},1,1)[1,2]"); oParser = new parserFormula('SEQUENCE(1,{1,2,3;3,2,1},{1;2},1)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(1,{1,2,3;3,2,1},{1;2},1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(1,{1,2,3;3,2,1},{1;2},1)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, "Result of SEQUENCE(1,{1,2,3;3,2,1},{1;2},1)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 1, "Result of SEQUENCE(1,{1,2,3;3,2,1},{1;2},1)[0,2]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, "Result of SEQUENCE(1,{1,2,3;3,2,1},{1;2},1)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 2, "Result of SEQUENCE(1,{1,2,3;3,2,1},{1;2},1)[1,1]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 2, "Result of SEQUENCE(1,{1,2,3;3,2,1},{1;2},1)[1,2]"); oParser = new parserFormula('SEQUENCE(1,1,{1,2,3;3,2,1},{1;2})', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(1,1,{1,2,3;3,2,1},{1;2})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(1,1,{1,2,3;3,2,1},{1;2})[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, "Result of SEQUENCE(1,1,{1,2,3;3,2,1},{1;2})[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 3, "Result of SEQUENCE(1,1,{1,2,3;3,2,1},{1;2})[0,2]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, "Result of SEQUENCE(1,1,{1,2,3;3,2,1},{1;2})[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 2, "Result of SEQUENCE(1,1,{1,2,3;3,2,1},{1;2})[1,1]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 1, "Result of SEQUENCE(1,1,{1,2,3;3,2,1},{1;2})[1,2]"); oParser = new parserFormula('SEQUENCE({1;2},1,1,{1,2,3;3,2,1})', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE({1;2},1,1,{1,2,3;3,2,1})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE({1;2},1,1,{1,2,3;3,2,1})[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, "Result of SEQUENCE({1;2},1,1,{1,2,3;3,2,1})[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 1, "Result of SEQUENCE({1;2},1,1,{1,2,3;3,2,1})[0,2]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 1, "Result of SEQUENCE({1;2},1,1,{1,2,3;3,2,1})[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 1, "Result of SEQUENCE({1;2},1,1,{1,2,3;3,2,1})[1,1]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 1, "Result of SEQUENCE({1;2},1,1,{1,2,3;3,2,1})[1,2]"); oParser = new parserFormula('SEQUENCE({1;2},{1,2,3;FALSE,"2s",TRUE},1,1)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE({1;2},{1,2,3;FALSE,"2s",TRUE},1,1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE({1;2},{1,2,3;FALSE,'2s',TRUE},1,1)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, "Result of SEQUENCE({1;2},{1,2,3;FALSE,'2s',TRUE},1,1)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 1, "Result of SEQUENCE({1;2},{1,2,3;FALSE,'2s',TRUE},1,1)[0,2]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", "Result of SEQUENCE({1;2},{1,2,3;FALSE,'2s',TRUE},1,1)[1,0]"); // #CALC! assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#VALUE!", "Result of SEQUENCE({1;2},{1,2,3;FALSE,'2s',TRUE},1,1)[1,1]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 1, "Result of SEQUENCE({1;2},{1,2,3;FALSE,'2s',TRUE},1,1)[1,2]"); oParser = new parserFormula('SEQUENCE({1;"3s"},{1,2,3;3,2,1},1,1)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE({1;"3s"},{1,2,3;3,2,1},1,1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE({1;'3s'},{1,2,3;3,2,1},1,1)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, "Result of SEQUENCE({1;'3s'},{1,2,3;3,2,1},1,1)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 1, "Result of SEQUENCE({1;'3s'},{1,2,3;3,2,1},1,1)[0,2]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", "Result of SEQUENCE({1;'3s'},{1,2,3;3,2,1},1,1)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#VALUE!", "Result of SEQUENCE({1;'3s'},{1,2,3;3,2,1},1,1)[1,1]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "#VALUE!", "Result of SEQUENCE({1;'3s'},{1,2,3;3,2,1},1,1)[1,2]"); oParser = new parserFormula('SEQUENCE({1;3},{1,2,3;3,2,1},{1,"2s",TRUE},1)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE({1;3},{1,2,3;3,2,1},{1,"2s",TRUE},1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE({1;3},{1,2,3;3,2,1},{1,'2s',TRUE},1)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", "Result of SEQUENCE({1;3},{1,2,3;3,2,1},{1,'2s',TRUE},1)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 1, "Result of SEQUENCE({1;3},{1,2,3;3,2,1},{1,'2s',TRUE},1)[0,2]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 1, "Result of SEQUENCE({1;3},{1,2,3;3,2,1},{1,'2s',TRUE},1)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#VALUE!", "Result of SEQUENCE({1;3},{1,2,3;3,2,1},{1,'2s',TRUE},1)[1,1]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 1, "Result of SEQUENCE({1;3},{1,2,3;3,2,1},{1,'2s',TRUE},1)[1,2]"); oParser = new parserFormula('SEQUENCE(1,{1;3},{1,2,3;3,2,1},{1,"2s",TRUE})', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(1,{1;3},{1,2,3;3,2,1},{1,"2s",TRUE})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(1,{1;3},{1,2,3;3,2,1},{1,'2s',TRUE})[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", "Result of SEQUENCE(1,{1;3},{1,2,3;3,2,1},{1,'2s',TRUE})[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 3, "Result of SEQUENCE(1,{1;3},{1,2,3;3,2,1},{1,'2s',TRUE})[0,2]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, "Result of SEQUENCE(1,{1;3},{1,2,3;3,2,1},{1,'2s',TRUE})[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#VALUE!", "Result of SEQUENCE(1,{1;3},{1,2,3;3,2,1},{1,'2s',TRUE})[1,1]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 1, "Result of SEQUENCE(1,{1;3},{1,2,3;3,2,1},{1,'2s',TRUE})[1,2]"); oParser = new parserFormula('SEQUENCE({1,"2s",TRUE},{1;3},{1,2,3;3,2,1},1)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE({1,"2s",TRUE},{1;3},{1,2,3;3,2,1},1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE({1,'2s',TRUE},{1;3},{1,2,3;3,2,1},1)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", "Result of SEQUENCE({1,'2s',TRUE},{1;3},{1,2,3;3,2,1},1)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 3, "Result of SEQUENCE({1,'2s',TRUE},{1;3},{1,2,3;3,2,1},1)[0,2]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, "Result of SEQUENCE({1,'2s',TRUE},{1;3},{1,2,3;3,2,1},1)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#VALUE!", "Result of SEQUENCE({1,'2s',TRUE},{1;3},{1,2,3;3,2,1},1)[1,1]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 1, "Result of SEQUENCE({1,'2s',TRUE},{1;3},{1,2,3;3,2,1},1)[1,2]"); oParser = new parserFormula('SEQUENCE(1,{1,"2s",TRUE},{1;3},{1,2,3;3,2,1})', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(1,{1,"2s",TRUE},{1;3},{1,2,3;3,2,1})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(1,{1,'2s',TRUE},{1;3},{1,2,3;3,2,1})[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", "Result of SEQUENCE(1,{1,'2s',TRUE},{1;3},{1,2,3;3,2,1})[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 1, "Result of SEQUENCE(1,{1,'2s',TRUE},{1;3},{1,2,3;3,2,1})[0,2]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, "Result of SEQUENCE(1,{1,'2s',TRUE},{1;3},{1,2,3;3,2,1})[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#VALUE!", "Result of SEQUENCE(1,{1,'2s',TRUE},{1;3},{1,2,3;3,2,1})[1,1]"); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 3, "Result of SEQUENCE(1,{1,'2s',TRUE},{1;3},{1,2,3;3,2,1})[1,2]"); oParser = new parserFormula('SEQUENCE(1,1,,{1,2;3,4})', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(1,1,,{1,2;3,4})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(1,1,,{1,2;3,4})[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, "Result of SEQUENCE(1,1,,{1,2;3,4})[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 1, "Result of SEQUENCE(1,1,,{1,2;3,4})[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 1, "Result of SEQUENCE(1,1,,{1,2;3,4})[1,1]"); oParser = new parserFormula('SEQUENCE(1,1,G10,{1,2;3,4})', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(1,1,G10,{1,2;3,4})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 0, "Result of SEQUENCE(1,1,G10,{1,2;3,4})[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 0, "Result of SEQUENCE(1,1,G10,{1,2;3,4})[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 0, "Result of SEQUENCE(1,1,G10,{1,2;3,4})[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 0, "Result of SEQUENCE(1,1,G10,{1,2;3,4})[1,1]"); oParser = new parserFormula('SEQUENCE(1,1,G11,{1,2;3,4})', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(1,1,G11,{1,2;3,4})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 0, "Result of SEQUENCE(1,1,G11,{1,2;3,4})[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 0, "Result of SEQUENCE(1,1,G11,{1,2;3,4})[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 0, "Result of SEQUENCE(1,1,G11,{1,2;3,4})[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 0, "Result of SEQUENCE(1,1,G11,{1,2;3,4})[1,1]"); oParser = new parserFormula('SEQUENCE(2.9,2.1,0.9,1.1)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2.9,2.1,0.9,1.1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 0.9, "Result of SEQUENCE(2.9,2.1,0.9,1.1)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, "Result of SEQUENCE(2.9,2.1,0.9,1.1)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3.1, "Result of SEQUENCE(2.9,2.1,0.9,1.1)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4.2, "Result of SEQUENCE(2.9,2.1,0.9,1.1)[1,1]"); // =SEQUENCE(2.9,2.1,-0.9,-1.010101) oParser = new parserFormula('SEQUENCE(2.4,2.5,-0.9,-1.01010)', "A2", ws); assert.ok(oParser.parse(), 'SEQUENCE(2.4,2.5,-0.9,-1.01010)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), -0.9, "Result of SEQUENCE(2.4,2.5,-0.9,-1.01010)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), -1.9101, "Result of SEQUENCE(2.4,2.5,-0.9,-1.01010)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), -2.9202, "Result of SEQUENCE(2.4,2.5,-0.9,-1.01010)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), -3.9303, "Result of SEQUENCE(2.4,2.5,-0.9,-1.01010)[1,1]"); // Max array size (10223960?) // oParser = new parserFormula('SEQUENCE(10223960,2,1,1)', "A2", ws); // assert.ok(oParser.parse(), 'SEQUENCE(10223960,2,1,1)'); // array = oParser.calculate(); // assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SEQUENCE(10223960,1,1,1)[0,0]"); // assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, "Result of SEQUENCE(10223960,1,1,1)[0,1]"); // assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, "Result of SEQUENCE(10223960,1,1,1)[1,0]"); // assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, "Result of SEQUENCE(10223960,1,1,1)[1,1]"); }); QUnit.test("Test: \"FILTER\"", function (assert) { let array; ws.getRange2("B10").setValue(""); ws.getRange2("B11").setValue(); ws.getRange2("F10").setValue("1"); ws.getRange2("F11").setValue("3"); ws.getRange2("F12").setValue("5"); ws.getRange2("F13").setValue("7"); ws.getRange2("F14").setValue("9"); ws.getRange2("F15").setValue("11"); ws.getRange2("G10").setValue("25"); ws.getRange2("G11").setValue("24"); ws.getRange2("G12").setValue("23"); ws.getRange2("G13").setValue("22"); ws.getRange2("G14").setValue("21"); ws.getRange2("G15").setValue("20"); ws.getRange2("H10").setValue("1"); ws.getRange2("H11").setValue("-10"); ws.getRange2("H12").setValue("-5"); ws.getRange2("H13").setValue("0"); ws.getRange2("H14").setValue("5"); ws.getRange2("H15").setValue("10"); // range && range oParser = new parserFormula("FILTER(F10:H15,F10:H10=1)", "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), "FILTER(F10:H15,F10:H10=1)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of FILTER(F10:H15,F10:H10=1)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, 'Result of FILTER(F10:H15,F10:H10=1)[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "", 'Result of FILTER(F10:H15,F10:H10=1)[0,2]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, 'Result of FILTER(F10:H15,F10:H10=1)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), -10, 'Result of FILTER(F10:H15,F10:H10=1)[1,1]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "", 'Result of FILTER(F10:H15,F10:H10=1)[1,2]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 5, 'Result of FILTER(F10:H15,F10:H10=1)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), -5, 'Result of FILTER(F10:H15,F10:H10=1)[2,1]'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 7, 'Result of FILTER(F10:H15,F10:H10=1)[3,0]'); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), 0, 'Result of FILTER(F10:H15,F10:H10=1)[3,1]'); oParser = new parserFormula('FILTER({1;2;3},{FALSE;FALSE;FALSE},25)', "A2", ws); assert.ok(oParser.parse(), 'FILTER({1;2;3},{FALSE;FALSE;FALSE},25)'); array = oParser.calculate(); assert.strictEqual(oParser.calculate().getValue(), 25, 'Result of FILTER({1;2;3},{FALSE;FALSE;FALSE},25)'); oParser = new parserFormula('FILTER({1,2,3}, {TRUE,FALSE,TRUE})', "С2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), 'FILTER({1,2,3}, {TRUE,FALSE,TRUE})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of FILTER({1,2,3}, {TRUE,FALSE,TRUE})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, 'Result of FILTER({1,2,3}, {TRUE,FALSE,TRUE})[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "", 'Result of FILTER({1,2,3}, {TRUE,FALSE,TRUE})[0,2]'); oParser = new parserFormula("FILTER(F10:H15,F10:F15>8)", "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), "FILTER(F10:H15,F10:F15>8)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 9, 'Result of FILTER(F10:H15,F10:F15>8)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 21, 'Result of FILTER(F10:H15,F10:F15>8)[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 5, 'Result of FILTER(F10:H15,F10:F15>8)[0,2]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 11, 'Result of FILTER(F10:H15,F10:F15>8)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 20, 'Result of FILTER(F10:H15,F10:F15>8)[1,1]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 10, 'Result of FILTER(F10:H15,F10:F15>8)[1,2]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", 'Result of FILTER(F10:H15,F10:F15>8)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "", 'Result of FILTER(F10:H15,F10:F15>8)[2,1]'); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "", 'Result of FILTER(F10:H15,F10:F15>8)[2,2]'); oParser = new parserFormula("FILTER({1;2;3;4},{FALSE;0;1;1},25)", "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), "FILTER({1;2;3;4},{FALSE;0;1;1},25)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 3, 'Result of FILTER({1;2;3;4},{FALSE;0;1;1},25)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", 'Result of FILTER({1;2;3;4},{FALSE;0;1;1},25)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 4, 'Result of FILTER({1;2;3;4},{FALSE;0;1;1},25)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", 'Result of FILTER({1;2;3;4},{FALSE;0;1;1},25)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", 'Result of FILTER({1;2;3;4},{FALSE;0;1;1},25)[2,0]'); oParser = new parserFormula('FILTER({1;2;3;4},{"FALSE";0;1;1},25)', "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), 'FILTER({1;2;3;4},{"FALSE";0;1;1},25)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 3, 'Result of FILTER({1;2;3;4},{"FALSE";0;1;1},25)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", 'Result of FILTER({1;2;3;4},{"FALSE";0;1;1},25)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 4, 'Result of FILTER({1;2;3;4},{"FALSE";0;1;1},25)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", 'Result of FILTER({1;2;3;4},{"FALSE";0;1;1},25)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", 'Result of FILTER({1;2;3;4},{"FALSE";0;1;1},25)[2,0]'); oParser = new parserFormula('FILTER({1;2;3;4},{"FALSE";0;"TRUE";"trUe"},25)', "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), 'FILTER({1;2;3;4},{"FALSE";0;"TRUE";"trUe"},25)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 3, 'Result of FILTER({1;2;3;4},{"FALSE";0;"TRUE";"trUe"},25)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", 'Result of FILTER({1;2;3;4},{"FALSE";0;"TRUE";"trUe"},25)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 4, 'Result of FILTER({1;2;3;4},{"FALSE";0;"TRUE";"trUe"},25)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", 'Result of FILTER({1;2;3;4},{"FALSE";0;"TRUE";"trUe"},25)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", 'Result of FILTER({1;2;3;4},{"FALSE";0;"TRUE";"trUe"},25)[2,0]'); oParser = new parserFormula('FILTER({1;2;3;4},{FALSE;"0";1;1},25)', "C2", ws); assert.ok(oParser.parse(), 'FILTER({1;2;3;4},{FALSE;"0";1;1},25)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", 'Result of FILTER({1;2;3;4},{FALSE;"0";1;1},25)'); oParser = new parserFormula('FILTER({1;2;3;4},{FALSE;0;1;"str"},25)', "C2", ws); assert.ok(oParser.parse(), 'FILTER({1;2;3;4},{FALSE;0;1;"str"},25)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", 'Result of FILTER({1;2;3;4},{FALSE;0;1;"str"},25)'); oParser = new parserFormula('FILTER({1;2;3;4;5},{FALSE;0;1;"str"},25)', "C2", ws); assert.ok(oParser.parse(), 'FILTER({1;2;3;4;5},{FALSE;0;1;"str"},25)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", 'Result of FILTER({1;2;3;4;5},{FALSE;0;1;"str"},25)'); oParser = new parserFormula('FILTER({1;2;3},{FALSE;TRUE},25)', "C2", ws); assert.ok(oParser.parse(), 'FILTER({1;2;3},{FALSE;TRUE},25)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", 'Result of FILTER({1;2;3},{FALSE;TRUE},25)'); oParser = new parserFormula('FILTER({1;2;3},{FALSE;TRUE})', "C2", ws); assert.ok(oParser.parse(), 'FILTER({1;2;3},{FALSE;TRUE})'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", 'Result of FILTER({1;2;3},{FALSE;TRUE})'); oParser = new parserFormula("FILTER(F10:H15,(F10:F15>5)*(F10:F15<9))", "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), "FILTER(F10:H15,(F10:F15>5)*(F10:F15<9)))"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 7, 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<9)))[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 22, 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<9)))[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 0, 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<9)))[0,2]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<9)))[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<9)))[1,1]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<9)))[1,2]'); oParser = new parserFormula("FILTER(F10:H15,(F10:H10=1)*(F11:H11=-10))", "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), "FILTER(F10:H15,(F10:H10=1)*(F11:H11=-10))"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of FILTER(F10:H15,(F10:H10=1)*(F11:H11=-10))[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", 'Result of FILTER(F10:H15,(F10:H10=1)*(F11:H11=-10))[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#N/A", 'Result of FILTER(F10:H15,(F10:H10=1)*(F11:H11=-10))[0,2]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), -10, 'Result of FILTER(F10:H15,(F10:H10=1)*(F11:H11=-10))[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", 'Result of FILTER(F10:H15,(F10:H10=1)*(F11:H11=-10))[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), -5, 'Result of FILTER(F10:H15,(F10:H10=1)*(F11:H11=-10))[2,0]'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 0, 'Result of FILTER(F10:H15,(F10:H10=1)*(F11:H11=-10))[3,0]'); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 5, 'Result of FILTER(F10:H15,(F10:H10=1)*(F11:H11=-10))[4,0]'); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 10, 'Result of FILTER(F10:H15,(F10:H10=1)*(F11:H11=-10))[5,0]'); oParser = new parserFormula('FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),F10:G11)', "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), "FILTER(F10:H15,(F10:F15>5)*(F10:F15<6)),F10:G11)"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),F10:G11))[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 25, 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),F10:G11))[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),F10:G11))[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 24, 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),F10:G11))[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),F10:G11))[2,0]'); oParser = new parserFormula('FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),B10)', "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), "FILTER(F10:H15,(F10:F15>5)*(F10:F15<6)),B10)"); array = oParser.calculate(); assert.strictEqual(array.getValue().getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),B10))'); oParser = new parserFormula('FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),B11)', "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), "FILTER(F10:H15,(F10:F15>5)*(F10:F15<6)),B11)"); array = oParser.calculate(); assert.strictEqual(array.getValue().getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),B11))'); oParser = new parserFormula('FILTER(F10:H15,(F10:F15>5)*(F10:F15<6), "")', "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), "FILTER(F10:H15,(F10:F15>5)*(F10:F15<6)))"); array = oParser.calculate(); assert.strictEqual(array.getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),""))'); oParser = new parserFormula('FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),25)', "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), "FILTER(F10:H15,(F10:F15>5)*(F10:F15<6)),25)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), 25, 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),25))'); oParser = new parserFormula('FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),"str")', "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), "FILTER(F10:H15,(F10:F15>5)*(F10:F15<6)),'str')"); array = oParser.calculate(); assert.strictEqual(array.getValue(), "str", 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),"str"))'); oParser = new parserFormula('FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),TRUE)', "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), "FILTER(F10:H15,(F10:F15>5)*(F10:F15<6)),TRUE)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), "TRUE", 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),TRUE))'); oParser = new parserFormula('FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),FALSE)', "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), "FILTER(F10:H15,(F10:F15>5)*(F10:F15<6)),FALSE)"); array = oParser.calculate(); assert.strictEqual(array.getValue(), "FALSE", 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),FALSE))'); oParser = new parserFormula('FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),{1,2,3})', "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), "FILTER(F10:H15,(F10:F15>5)*(F10:F15<6)),{1,2,3})"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),{1,2,3}))[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),{1,2,3}))[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 3, 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),{1,2,3}))[0,2]'); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),{1,2,3}))[0,3]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),{1,2,3}))[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),{1,2,3}))[1,1]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),{1,2,3}))[1,2]'); assert.strictEqual(array.getElementRowCol(1, 3).getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),{1,2,3}))[1,3]'); oParser = new parserFormula('FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),{1;2;3})', "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), "FILTER(F10:H15,(F10:F15>5)*(F10:F15<6)),{1;2;3})"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),{1;2;3}))[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),{1;2;3}))[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),{1;2;3}))[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),{1;2;3}))[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 3, 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),{1;2;3}))[2,0]'); oParser = new parserFormula('FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),{1,2;3,4})', "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), "FILTER(F10:H15,(F10:F15>5)*(F10:F15<6)),{1,2;3,4})"); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),{1,2;3,4}))[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),{1,2;3,4}))[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),{1,2;3,4}))[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),{1,2;3,4}))[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(F10:F15<6),{1,2;3,4}))[2,0]'); oParser = new parserFormula('FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15))', "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), 'FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15))'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 9, 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15))[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 21, 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15))[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 5, 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15))[0,2]'); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15))[0,3]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 11, 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15))[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 20, 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15))[1,1]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 10, 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15))[1,2]'); assert.strictEqual(array.getElementRowCol(1, 3).getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15))[1,3]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15))[2,0]'); oParser = new parserFormula('FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(TRUE))', "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), 'FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(TRUE))'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 9, 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(TRUE))[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 21, 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(TRUE))[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 5, 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(TRUE))[0,2]'); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(TRUE))[0,3]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 11, 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(TRUE))[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 20, 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(TRUE))[1,1]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 10, 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(TRUE))[1,2]'); assert.strictEqual(array.getElementRowCol(1, 3).getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(TRUE))[1,3]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(TRUE))[2,0]'); oParser = new parserFormula('FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(1))', "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), 'FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(1))'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 9, 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(1))[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 21, 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(1))[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 5, 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(1))[0,2]'); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(1))[0,3]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 11, 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(1))[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 20, 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(1))[1,1]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 10, 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(1))[1,2]'); assert.strictEqual(array.getElementRowCol(1, 3).getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(1))[1,3]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(1))[2,0]'); oParser = new parserFormula('FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*({1}))', "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), 'FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*({1}))'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 9, 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*({1}))[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 21, 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*({1}))[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 5, 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*({1}))[0,2]'); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*({1}))[0,3]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 11, 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*({1}))[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 20, 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*({1}))[1,1]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 10, 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*({1}))[1,2]'); assert.strictEqual(array.getElementRowCol(1, 3).getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*({1}))[1,3]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*({1}))[2,0]'); oParser = new parserFormula('FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(FALSE))', "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), 'FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(FALSE))'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(FALSE))'); oParser = new parserFormula('FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(0))', "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), 'FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(0))'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*(0))'); oParser = new parserFormula('FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*({0}))', "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), 'FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*({0}))'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*({0}))'); oParser = new parserFormula('FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*({1,2}))', "C2", ws); oParser.setArrayFormulaRef(ws.getRange2("C2:E7").bbox); assert.ok(oParser.parse(), 'FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*({1,2}))'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", 'Result of FILTER(F10:H15,(F10:F15>5)*(G10:G15<23)*(H10:H15)*({1,2}))'); // value && value oParser = new parserFormula('FILTER(12,"0")', "A2", ws); assert.ok(oParser.parse(), 'FILTER(12,"0")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of FILTER(12,"0")'); oParser = new parserFormula('FILTER(12,"1")', "A2", ws); assert.ok(oParser.parse(), 'FILTER(12,"1")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of FILTER(12,"1")'); oParser = new parserFormula('FILTER(12,"TRUE")', "A2", ws); assert.ok(oParser.parse(), 'FILTER(12,"TRUE")'); assert.strictEqual(oParser.calculate().getValue(), 12, 'Result of FILTER(12,"TRUE")'); oParser = new parserFormula('FILTER(12,"FALSE")', "A2", ws); assert.ok(oParser.parse(), 'FILTER(12,"FALSE")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of FILTER(12,"FALSE")'); // #CALC! oParser = new parserFormula('FILTER(12,"0",25)', "A2", ws); assert.ok(oParser.parse(), 'FILTER(12,"0",25)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of FILTER(12,"0",25)'); oParser = new parserFormula('FILTER(12,"1",25)', "A2", ws); assert.ok(oParser.parse(), 'FILTER(12,"1",25)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of FILTER(12,"1",25)'); oParser = new parserFormula('FILTER(12,"TRUE",25)', "A2", ws); assert.ok(oParser.parse(), 'FILTER(12,"TRUE",25)'); assert.strictEqual(oParser.calculate().getValue(), 12, 'Result of FILTER(12,"TRUE",25)'); oParser = new parserFormula('FILTER(12,"FALSE",25)', "A2", ws); assert.ok(oParser.parse(), 'FILTER(12,"FALSE")'); assert.strictEqual(oParser.calculate().getValue(), 25, 'Result of FILTER(12,"FALSE")'); oParser = new parserFormula('FILTER(12,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'FILTER(12,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), 12, 'Result of FILTER(12,TRUE)'); oParser = new parserFormula('FILTER(12,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'FILTER(12,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of FILTER(12,FALSE)'); // #CALC! oParser = new parserFormula('FILTER(12,12)', "A2", ws); assert.ok(oParser.parse(), 'FILTER(12,12)'); assert.strictEqual(oParser.calculate().getValue(), 12, 'Result of FILTER(12,12)'); oParser = new parserFormula('FILTER(12,0)', "A2", ws); assert.ok(oParser.parse(), 'FILTER(12,0)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of FILTER(12,0)'); // #CALC! oParser = new parserFormula('FILTER(FALSE,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'FILTER(FALSE,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), "FALSE", 'Result of FILTER(FALSE,TRUE)'); oParser = new parserFormula('FILTER(#N/A,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'FILTER(#N/A,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of FILTER(#N/A,TRUE)'); oParser = new parserFormula('FILTER(FALSE,#NUM!)', "A2", ws); assert.ok(oParser.parse(), 'FILTER(FALSE,#NUM!)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of FILTER(FALSE,#NUM!)'); oParser = new parserFormula('FILTER(#N/A,#NUM!)', "A2", ws); assert.ok(oParser.parse(), 'FILTER(#N/A,#NUM!)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of FILTER(#N/A,#NUM!)'); oParser = new parserFormula('FILTER(,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'FILTER(,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of FILTER(,TRUE)'); oParser = new parserFormula('FILTER(B10,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'FILTER(B10,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), "", 'Result of FILTER(B10,TRUE)'); // 0 oParser = new parserFormula('FILTER(B11,TRUE)', "A2", ws); assert.ok(oParser.parse(), 'FILTER(B11,TRUE)'); assert.strictEqual(oParser.calculate().getValue(), "", 'Result of FILTER(B11,TRUE)'); // 0 oParser = new parserFormula('FILTER(TRUE,)', "A2", ws); assert.ok(oParser.parse(), 'FILTER(TRUE,)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of FILTER(TRUE,)'); oParser = new parserFormula('FILTER(TRUE,B10)', "A2", ws); assert.ok(oParser.parse(), 'FILTER(TRUE,B10)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of FILTER(TRUE,B10)'); // #CALC! oParser = new parserFormula('FILTER(TRUE,B11)', "A2", ws); assert.ok(oParser.parse(), 'FILTER(TRUE,B11)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of FILTER(TRUE,B11)'); // #CALC! // value && range oParser = new parserFormula('FILTER("z", {TRUE})', "A2", ws); assert.ok(oParser.parse(), 'FILTER("z", {TRUE})'); assert.strictEqual(oParser.calculate().getValue(), "z", 'Result of FILTER("z", {TRUE})'); oParser = new parserFormula('FILTER("z", {TRUE,FALSE})', "A2", ws); assert.ok(oParser.parse(), 'FILTER("z", {TRUE,FALSE})'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of FILTER("z", {TRUE,FALSE})'); oParser = new parserFormula('FILTER("x", {TRUE;FALSE})', "A2", ws); assert.ok(oParser.parse(), 'FILTER("x", {TRUE;FALSE})'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of FILTER("x", {TRUE;FALSE})'); oParser = new parserFormula('FILTER("12", {FALSE})', "A2", ws); assert.ok(oParser.parse(), 'FILTER("12", {FALSE})'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of FILTER("12", {FALSE})'); // #CALC! // range && value oParser = new parserFormula('FILTER({1;2;3},FALSE,25)', "C2", ws); assert.ok(oParser.parse(), 'FILTER({1;2;3},FALSE,25)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), 25, 'Result of FILTER({1;2;3},FALSE,25)'); oParser = new parserFormula('FILTER({1,2,3},TRUE)', "A2", ws); assert.ok(oParser.parse(), 'FILTER({1,2,3},TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of FILTER({1,2,3},TRUE)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, 'Result of FILTER({1,2,3},TRUE)[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 3, 'Result of FILTER({1,2,3},TRUE)[0,2]'); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "", 'Result of FILTER({1,2,3},TRUE)[0,3]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", 'Result of FILTER({1,2,3},TRUE)[1,0]'); oParser = new parserFormula('FILTER({1;2;3},TRUE)', "A2", ws); assert.ok(oParser.parse(), 'FILTER({1;2;3},TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of FILTER({1,2,3},TRUE)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", 'Result of FILTER({1,2,3},TRUE)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, 'Result of FILTER({1,2,3},TRUE)[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 3, 'Result of FILTER({1,2,3},TRUE)[2,0]'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "", 'Result of FILTER({1,2,3},TRUE)[3,0]'); oParser = new parserFormula('FILTER({1;2;3},FALSE, 25)', "A2", ws); assert.ok(oParser.parse(), 'FILTER({1;2;3},FALSE, 25)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), 25, 'Result of FILTER({1,2,3},FALSE)'); oParser = new parserFormula('FILTER({1;2;3},FALSE,)', "A2", ws); assert.ok(oParser.parse(), 'FILTER({1;2;3},FALSE,)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", 'Result of FILTER({1,2,3},FALSE,)'); oParser = new parserFormula('FILTER({1;2;3},FALSE,B10)', "A2", ws); assert.ok(oParser.parse(), 'FILTER({1;2;3},FALSE,B10)'); array = oParser.calculate(); assert.strictEqual(array.getValue().getValue(), "", 'Result of FILTER({1,2,3},FALSE,B10)'); // 0 oParser = new parserFormula('FILTER({1;2;3},FALSE,B11)', "A2", ws); assert.ok(oParser.parse(), 'FILTER({1;2;3},FALSE,B11)'); array = oParser.calculate(); assert.strictEqual(array.getValue().getValue(), "", 'Result of FILTER({1,2,3},FALSE,B11)'); // 0 oParser = new parserFormula('FILTER({1;2;3},FALSE,#N/A)', "A2", ws); assert.ok(oParser.parse(), 'FILTER({1;2;3},FALSE,#N/A)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#N/A", 'Result of FILTER({1,2,3},FALSE,#N/A)'); oParser = new parserFormula('FILTER({1;2;3},FALSE,0)', "A2", ws); assert.ok(oParser.parse(), 'FILTER({1;2;3},FALSE,0)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), 0, 'Result of FILTER({1,2,3},FALSE,0)'); oParser = new parserFormula('FILTER(12,TRUE,)', "A2", ws); assert.ok(oParser.parse(), 'FILTER(12,TRUE,)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), 12, 'Result of FILTER(12,TRUE,)'); oParser = new parserFormula('FILTER(12,TRUE,#N/A)', "A2", ws); assert.ok(oParser.parse(), 'FILTER(12,TRUE,#N/A)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), 12, 'Result of FILTER(12,TRUE,#N/A)'); ws.getRange2("A:B").cleanAll(); ws.getRange2("A100:A200").setValue("10"); ws.getRange2("A100").setValue("1"); ws.getRange2("A102").setValue("2"); ws.getRange2("A105").setValue("3"); ws.getRange2("A110").setValue("4"); ws.getRange2("B100:B150").setValue("Str"); ws.getRange2("B100").setValue("Test"); ws.getRange2("B102").setValue("Test"); ws.getRange2("B105").setValue("Test"); ws.getRange2("B110").setValue("Test"); // for bug 64954 oParser = new parserFormula('FILTER(A:A,B:B="Test")', "A2", ws); assert.ok(oParser.parse(), 'FILTER(A:A,B:B="Test")'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 1, 'Result of FILTER(A:A,B:B="Test")'); assert.strictEqual(array.getElementRowCol(1,0).getValue(), 2, 'Result of FILTER(A:A,B:B="Test")'); assert.strictEqual(array.getElementRowCol(2,0).getValue(), 3, 'Result of FILTER(A:A,B:B="Test")'); assert.strictEqual(array.getElementRowCol(3,0).getValue(), 4, 'Result of FILTER(A:A,B:B="Test")'); oParser = new parserFormula('FILTER(A:A<3,B:B="Test")', "A2", ws); assert.ok(oParser.parse(), 'FILTER(A:A<3,B:B="Test")'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), "TRUE", 'Result of FILTER(A:A<3,B:B="Test")'); assert.strictEqual(array.getElementRowCol(1,0).getValue(), "TRUE", 'Result of FILTER(A:A<3,B:B="Test")'); assert.strictEqual(array.getElementRowCol(2,0).getValue(), "FALSE", 'Result of FILTER(A:A<3,B:B="Test")'); assert.strictEqual(array.getElementRowCol(3,0).getValue(), "FALSE", 'Result of FILTER(A:A<3,B:B="Test")'); }); QUnit.test("Test: \"ARRAYTOTEXT\"", function (assert) { let array; ws.getRange2("B10").setValue(""); ws.getRange2("B11").setValue(); ws.getRange2("C10").setValue(""); ws.getRange2("C11").setValue("1"); ws.getRange2("C110").setValue("12"); ws.getRange2("C110").setNumFormat("@"); ws.getRange2("D10").setValue("19"); ws.getRange2("D11").setValue("#N/A"); ws.getRange2("D12").setValue("0"); ws.getRange2("E10").setValue("str"); ws.getRange2("E11").setValue("TRUE"); ws.getRange2("E12").setValue("1"); // array|range && array|range|value oParser = new parserFormula('ARRAYTOTEXT(B10:C11,0)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(B10:C11,0)'); assert.strictEqual(oParser.calculate().getValue(), ", , , 1", 'Result of ARRAYTOTEXT(B10:C11,0)'); oParser = new parserFormula('ARRAYTOTEXT(B10:C11,1)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(B10:C11,1)'); assert.strictEqual(oParser.calculate().getValue(), "{,;,1}", 'Result of ARRAYTOTEXT(B10:C11,1)'); oParser = new parserFormula('ARRAYTOTEXT(12,B10:C11)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(12,B10:C11)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "12", 'Result of ARRAYTOTEXT(12,B10:C11)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "12", 'Result of ARRAYTOTEXT(12,B10:C11)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "12", 'Result of ARRAYTOTEXT(12,B10:C11)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), '{12}', 'Result of ARRAYTOTEXT(12,B10:C11)[1,1]'); oParser = new parserFormula('ARRAYTOTEXT("12",B10:C11)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT("12",B10:C11)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "12", 'Result of ARRAYTOTEXT("12",B10:C11)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "12", 'Result of ARRAYTOTEXT("12",B10:C11)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "12", 'Result of ARRAYTOTEXT("12",B10:C11)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), '{"12"}', 'Result of ARRAYTOTEXT("12",B10:C11)[1,1]'); oParser = new parserFormula('ARRAYTOTEXT(C110,B10:C11)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(C110,B10:C11)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "12", 'Result of ARRAYTOTEXT(C110,B10:C11)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "12", 'Result of ARRAYTOTEXT(C110,B10:C11)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "12", 'Result of ARRAYTOTEXT(C110,B10:C11)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), '{12}', 'Result of ARRAYTOTEXT(C110,B10:C11)[1,1]'); oParser = new parserFormula('ARRAYTOTEXT(C110,{1,0;FALSE,TRUE})', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(C110,{1,0;FALSE,TRUE})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "{12}", 'Result of ARRAYTOTEXT(C110,{1,0;FALSE,TRUE})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "12", 'Result of ARRAYTOTEXT(C110,{1,0;FALSE,TRUE})[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "12", 'Result of ARRAYTOTEXT(C110,{1,0;FALSE,TRUE})[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), '{12}', 'Result of ARRAYTOTEXT(C110,{1,0;FALSE,TRUE})[1,1]'); oParser = new parserFormula('ARRAYTOTEXT(B10:C11,B10:C11)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(B10:C11,B10:C11)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), ", , , 1", 'Result of ARRAYTOTEXT(B10:C11,B10:C11)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), ", , , 1", 'Result of ARRAYTOTEXT(B10:C11,B10:C11)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), ", , , 1", 'Result of ARRAYTOTEXT(B10:C11,B10:C11)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), '{,;,1}', 'Result of ARRAYTOTEXT(B10:C11,B10:C11)[1,1]'); oParser = new parserFormula('ARRAYTOTEXT(D10:E11)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(D10:E11)'); assert.strictEqual(oParser.calculate().getValue(), "19, str, #N/A, TRUE", 'Result of ARRAYTOTEXT(D10:E11)'); oParser = new parserFormula('ARRAYTOTEXT(D10:E11,1)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(D10:E11,1)'); assert.strictEqual(oParser.calculate().getValue(), '{19,"str";#N/A,TRUE}', 'Result of ARRAYTOTEXT(D10:E11,1)'); oParser = new parserFormula('ARRAYTOTEXT(D10:E11,2)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(D10:E11,2)'); assert.strictEqual(oParser.calculate().getValue(), '#VALUE!', 'Result of ARRAYTOTEXT(D10:E11,2)'); oParser = new parserFormula('ARRAYTOTEXT(12,{3,#NUM!;0,1})', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(12,{3,#NUM!;0,1})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", 'Result of ARRAYTOTEXT(12,{3,#NUM!;0,1})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#NUM!", 'Result of ARRAYTOTEXT(12,{3,#NUM!;0,1})[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "12", 'Result of ARRAYTOTEXT(12,{3,#NUM!;0,1})[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), '{12}', 'Result of ARRAYTOTEXT(12,{3,#NUM!;0,1})[1,1]'); oParser = new parserFormula('ARRAYTOTEXT("12",{3,#NUM!;0,1})', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT("12",{3,#NUM!;0,1})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", 'Result of ARRAYTOTEXT(12,{3,#NUM!;0,1})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#NUM!", 'Result of ARRAYTOTEXT(12,{3,#NUM!;0,1})[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), '12', 'Result of ARRAYTOTEXT(12,{3,#NUM!;0,1})[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), '{"12"}', 'Result of ARRAYTOTEXT(12,{3,#NUM!;0,1})[1,1]'); oParser = new parserFormula('ARRAYTOTEXT("1s",{3,#NUM!;0,1})', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT("1s",{3,#NUM!;0,1})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", 'Result of ARRAYTOTEXT(12,{3,#NUM!;0,1})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#NUM!", 'Result of ARRAYTOTEXT(12,{3,#NUM!;0,1})[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), '1s', 'Result of ARRAYTOTEXT(12,{3,#NUM!;0,1})[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), '{"1s"}', 'Result of ARRAYTOTEXT(12,{3,#NUM!;0,1})[1,1]'); oParser = new parserFormula('ARRAYTOTEXT(FALSE,{3,#NUM!;0,1})', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(FALSE,{3,#NUM!;0,1})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", 'Result of ARRAYTOTEXT(12,{3,#NUM!;0,1})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#NUM!", 'Result of ARRAYTOTEXT(12,{3,#NUM!;0,1})[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 'FALSE', 'Result of ARRAYTOTEXT(12,{3,#NUM!;0,1})[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), '{FALSE}', 'Result of ARRAYTOTEXT(12,{3,#NUM!;0,1})[1,1]'); oParser = new parserFormula('ARRAYTOTEXT(TRUE,{3,#NUM!;0,1})', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(TRUE,{3,#NUM!;0,1})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", 'Result of ARRAYTOTEXT(12,{3,#NUM!;0,1})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#NUM!", 'Result of ARRAYTOTEXT(12,{3,#NUM!;0,1})[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 'TRUE', 'Result of ARRAYTOTEXT(12,{3,#NUM!;0,1})[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), '{TRUE}', 'Result of ARRAYTOTEXT(12,{3,#NUM!;0,1})[1,1]'); oParser = new parserFormula('ARRAYTOTEXT(D10:E11,{0,1,2})', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(D10:E11,{0,1,2})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "19, str, #N/A, TRUE", 'Result of ARRAYTOTEXT(D10:E11,{0,1,2})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), '{19,"str";#N/A,TRUE}', 'Result of ARRAYTOTEXT(D10:E11,{0,1,2})[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#VALUE!", 'Result of ARRAYTOTEXT(D10:E11,{0,1,2})[0,2]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), '', 'Result of ARRAYTOTEXT(D10:E11,{0,1,2})[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), '', 'Result of ARRAYTOTEXT(D10:E11,{0,1,2})[1,1]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), '', 'Result of ARRAYTOTEXT(D10:E11,{0,1,2})[1,2]'); oParser = new parserFormula('ARRAYTOTEXT(D10:E11,{0,1,2;FALSE,"1","TRUE"})', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(D10:E11,{0,1,2})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), '19, str, #N/A, TRUE', 'Result of ARRAYTOTEXT(D10:E11,{0,1,2})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), '{19,"str";#N/A,TRUE}', 'Result of ARRAYTOTEXT(D10:E11,{0,1,2})[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), '#VALUE!', 'Result of ARRAYTOTEXT(D10:E11,{0,1,2})[0,2]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), '19, str, #N/A, TRUE', 'Result of ARRAYTOTEXT(D10:E11,{0,1,2})[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), '{19,"str";#N/A,TRUE}', 'Result of ARRAYTOTEXT(D10:E11,{0,1,2})[1,1]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), '#VALUE!', 'Result of ARRAYTOTEXT(D10:E11,{0,1,2})[1,2]'); oParser = new parserFormula('ARRAYTOTEXT(D10:E11, D10:E12)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(D10:E11, D10:E12)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", 'Result of ARRAYTOTEXT(D10:E11,D10:E12)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", 'Result of ARRAYTOTEXT(D10:E11,D10:E12)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#N/A", 'Result of ARRAYTOTEXT(D10:E11,D10:E12)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), '{19,"str";#N/A,TRUE}', 'Result of ARRAYTOTEXT(D10:E11,D10:E12)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "19, str, #N/A, TRUE", 'Result of ARRAYTOTEXT(D10:E11,D10:E12)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), '{19,"str";#N/A,TRUE}', 'Result of ARRAYTOTEXT(D10:E11,D10:E12)[2,1]'); oParser = new parserFormula('ARRAYTOTEXT({"str",12,TRUE},{3,#NUM!;0,1})', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT({"str",12,TRUE},{3,#NUM!;0,1})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", 'Result of ARRAYTOTEXT({"str",12,TRUE},{3,#NUM!;0,1})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#NUM!", 'Result of ARRAYTOTEXT({"str",12,TRUE},{3,#NUM!;0,1})[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "str, 12, TRUE", 'Result of ARRAYTOTEXT({"str",12,TRUE},{3,#NUM!;0,1})[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), '{"str",12,TRUE}', 'Result of ARRAYTOTEXT({"str",12,TRUE},{3,#NUM!;0,1})[1,1]'); oParser = new parserFormula('ARRAYTOTEXT({"str",12,TRUE},{3,#NUM!;"0",TRUE})', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT({"str",12,TRUE},{3,#NUM!;"0",TRUE})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", 'Result of ARRAYTOTEXT({"str",12,TRUE},{3,#NUM!;"0",TRUE})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#NUM!", 'Result of ARRAYTOTEXT({"str",12,TRUE},{3,#NUM!;"0",TRUE})[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "str, 12, TRUE", 'Result of ARRAYTOTEXT({"str",12,TRUE},{3,#NUM!;"0",TRUE})[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), '{"str",12,TRUE}', 'Result of ARRAYTOTEXT({"str",12,TRUE},{3,#NUM!;"0",TRUE})[1,1]'); // value && array|range|value oParser = new parserFormula('ARRAYTOTEXT(,0)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(,0)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of ARRAYTOTEXT(,0)'); oParser = new parserFormula('ARRAYTOTEXT(,B10)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(,B10)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of ARRAYTOTEXT(,B10)'); oParser = new parserFormula('ARRAYTOTEXT(,B11)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(,B11)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of ARRAYTOTEXT(,B11)'); oParser = new parserFormula('ARRAYTOTEXT(12)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(12)'); assert.strictEqual(oParser.calculate().getValue(), "12", 'Result of ARRAYTOTEXT(12)'); oParser = new parserFormula('ARRAYTOTEXT(12,1)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(12,1)'); assert.strictEqual(oParser.calculate().getValue(), "{12}", 'Result of ARRAYTOTEXT(12,1)'); oParser = new parserFormula('ARRAYTOTEXT("12")', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT("12")'); assert.strictEqual(oParser.calculate().getValue(), "12", 'Result of ARRAYTOTEXT("12")'); oParser = new parserFormula('ARRAYTOTEXT(TRUE)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(TRUE)'); assert.strictEqual(oParser.calculate().getValue(), "TRUE", 'Result of ARRAYTOTEXT(TRUE)'); oParser = new parserFormula('ARRAYTOTEXT(FALSE)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(FALSE)'); assert.strictEqual(oParser.calculate().getValue(), "FALSE", 'Result of ARRAYTOTEXT(FALSE)'); oParser = new parserFormula('ARRAYTOTEXT(#N/A)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(#N/A)'); assert.strictEqual(oParser.calculate().getValue(), "#N/A", 'Result of ARRAYTOTEXT(#N/A)'); oParser = new parserFormula('ARRAYTOTEXT("str")', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT("str")'); assert.strictEqual(oParser.calculate().getValue(), "str", 'Result of ARRAYTOTEXT("str")'); oParser = new parserFormula('ARRAYTOTEXT("str", "0")', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT("str", "0")'); assert.strictEqual(oParser.calculate().getValue(), 'str', 'Result of ARRAYTOTEXT("str", "0")'); oParser = new parserFormula('ARRAYTOTEXT("str", "1")', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT("str", "1")'); assert.strictEqual(oParser.calculate().getValue(), '{"str"}', 'Result of ARRAYTOTEXT("str", "1")'); oParser = new parserFormula('ARRAYTOTEXT("str", "1s")', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT("str", "1s")'); assert.strictEqual(oParser.calculate().getValue(), '#VALUE!', 'Result of ARRAYTOTEXT("str", "1s")'); oParser = new parserFormula('ARRAYTOTEXT("str",FALSE)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT("str",FALSE)'); assert.strictEqual(oParser.calculate().getValue(), "str", 'Result of ARRAYTOTEXT("str",FALSE)'); oParser = new parserFormula('ARRAYTOTEXT("str", TRUE)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT("str", TRUE)'); assert.strictEqual(oParser.calculate().getValue(), '{"str"}', 'Result of ARRAYTOTEXT("str", TRUE)'); oParser = new parserFormula('ARRAYTOTEXT("str", 1)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT("str", 1)'); assert.strictEqual(oParser.calculate().getValue(), '{"str"}', 'Result of ARRAYTOTEXT("str", 1)'); oParser = new parserFormula('ARRAYTOTEXT(E10)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(E10)'); assert.strictEqual(oParser.calculate().getValue(), "str", 'Result of ARRAYTOTEXT(E10)'); oParser = new parserFormula('ARRAYTOTEXT(E10, "0")', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(E10, "0")'); assert.strictEqual(oParser.calculate().getValue(), 'str', 'Result of ARRAYTOTEXT(E10, "0")'); oParser = new parserFormula('ARRAYTOTEXT(E10, "1")', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(E10, "1")'); assert.strictEqual(oParser.calculate().getValue(), '{"str"}', 'Result of ARRAYTOTEXT(E10, "1")'); oParser = new parserFormula('ARRAYTOTEXT(E10, "1s")', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(E10, "1s")'); assert.strictEqual(oParser.calculate().getValue(), '#VALUE!', 'Result of ARRAYTOTEXT(E10, "1s")'); oParser = new parserFormula('ARRAYTOTEXT(E10,FALSE)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(E10,FALSE)'); assert.strictEqual(oParser.calculate().getValue(), "str", 'Result of ARRAYTOTEXT(E10,FALSE)'); oParser = new parserFormula('ARRAYTOTEXT(E10, TRUE)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(E10, TRUE)'); assert.strictEqual(oParser.calculate().getValue(), '{"str"}', 'Result of ARRAYTOTEXT(E10, TRUE)'); oParser = new parserFormula('ARRAYTOTEXT(E10, 1)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(E10, 1)'); assert.strictEqual(oParser.calculate().getValue(), '{"str"}', 'Result of ARRAYTOTEXT(E10, 1)'); oParser = new parserFormula('ARRAYTOTEXT("str", 12)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT("str", 12)'); assert.strictEqual(oParser.calculate().getValue(), '#VALUE!', 'Result of ARRAYTOTEXT("str", 12)'); oParser = new parserFormula('ARRAYTOTEXT(#NUM!, #N/A)', "A2", ws); assert.ok(oParser.parse(), 'ARRAYTOTEXT(#NUM!, #N/A)'); assert.strictEqual(oParser.calculate().getValue(), "#NUM!", 'Result of ARRAYTOTEXT(#NUM!, #N/A)'); }); QUnit.test("Test: \"SORT\"", function (assert) { let array; ws.getRange2("B20").setValue(""); ws.getRange2("B21").setValue(); ws.getRange2("C20").setValue(""); ws.getRange2("C21").setValue("1"); ws.getRange2("C22").cleanAll(); ws.getRange2("C30").setValue("12"); ws.getRange2("C30").setNumFormat("@"); ws.getRange2("D10").setValue("19"); ws.getRange2("D11").setValue("#N/A"); ws.getRange2("D12").setValue("0"); ws.getRange2("E10").setValue("str"); ws.getRange2("E11").setValue("TRUE"); ws.getRange2("E12").setValue("1"); ws.getRange2("F10").setValue("string1"); ws.getRange2("F11").setValue("string2"); ws.getRange2("F12").setValue("1string"); ws.getRange2("F13").setValue("2string"); ws.getRange2("G10").setValue("Strung1"); ws.getRange2("G11").setValue("sTrung2"); ws.getRange2("G12").setValue("strunG33"); ws.getRange2("G13").setValue("1String"); ws.getRange2("F100").setValue("1s"); ws.getRange2("F101").setValue("Родион"); ws.getRange2("F102").setValue("222Gleb222"); ws.getRange2("F103").setValue("20"); ws.getRange2("F104").setValue("1"); ws.getRange2("H10").setValue("25"); ws.getRange2("H11").setValue("3"); ws.getRange2("H12").setValue("27"); ws.getRange2("I10").setValue("-23"); ws.getRange2("I11").setValue("-1"); ws.getRange2("I12").setValue("-3"); ws.getRange2("J10").setValue("2"); ws.getRange2("J11").setValue("6"); ws.getRange2("J12").setValue("9"); ws.getRange2("K10").setValue("4"); ws.getRange2("K11").setValue("6"); ws.getRange2("K12").setValue("1"); oParser = new parserFormula('SORT(J10:K12,2,1,D10:E12)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(J10:K12,2,1,D10:E12)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, 'Result of SORT(J10:K12,2,1,D10:E12)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", 'Result of SORT(J10:K12,2,1,D10:E12)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#N/A", 'Result of SORT(J10:K12,2,1,D10:E12)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 0, 'Result of SORT(J10:K12,2,1,D10:E12)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#VALUE!", 'Result of SORT(J10:K12,2,1,D10:E12)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#VALUE!", 'Result of SORT(J10:K12,2,1,D10:E12)[2,1]'); oParser = new parserFormula('SORT(J10:K12,1,1,D10:E12)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(J10:K12,1,1,D10:E12)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, 'Result of SORT(J10:K12,1,1,D10:E12)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", 'Result of SORT(J10:K12,1,1,D10:E12)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#N/A", 'Result of SORT(J10:K12,1,1,D10:E12)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 0, 'Result of SORT(J10:K12,1,1,D10:E12)[1,1]'); // #VALUE! assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#VALUE!", 'Result of SORT(J10:K12,1,1,D10:E12)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#VALUE!", 'Result of SORT(J10:K12,1,1,D10:E12)[2,1]'); oParser = new parserFormula('SORT(H10:I12,C21:C22)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(H10:I12,C21:C22)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", 'Result of SORT(H10:I12,C21:C22)'); oParser = new parserFormula('SORT(H10:I12)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(H10:I12)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 3, 'Result of SORT(H10:I12)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), -1, 'Result of SORT(H10:I12)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 25, 'Result of SORT(H10:I12)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), -23, 'Result of SORT(H10:I12)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 27, 'Result of SORT(H10:I12)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), -3, 'Result of SORT(H10:I12)[2,1]'); oParser = new parserFormula('SORT(H10:I12,2)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(H10:I12,2)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 25, 'Result of SORT(H10:I12,2)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), -23, 'Result of SORT(H10:I12,2)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 27, 'Result of SORT(H10:I12,2)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), -3, 'Result of SORT(H10:I12,2)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 3, 'Result of SORT(H10:I12,2)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), -1, 'Result of SORT(H10:I12,2)[2,1]'); oParser = new parserFormula('SORT(H10:I12,,-1)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(H10:I12,,-1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 27, 'Result of SORT(H10:I12,,-1)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), -3, 'Result of SORT(H10:I12,,-1)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 25, 'Result of SORT(H10:I12,,-1)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), -23, 'Result of SORT(H10:I12,,-1)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 3, 'Result of SORT(H10:I12,,-1)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), -1, 'Result of SORT(H10:I12,,-1)[2,1]'); oParser = new parserFormula('SORT(H10:I12,2,-1)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(H10:I12,2,-1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 3, 'Result of SORT(H10:I12,2,-1)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), -1, 'Result of SORT(H10:I12,2,-1)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 27, 'Result of SORT(H10:I12,2,-1)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), -3, 'Result of SORT(H10:I12,2,-1)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 25, 'Result of SORT(H10:I12,2,-1)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), -23, 'Result of SORT(H10:I12,2,-1)[2,1]'); oParser = new parserFormula('SORT(H10:I12,,,TRUE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(H10:I12,,,TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), -23, 'Result of SORT(H10:I12,,,TRUE)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 25, 'Result of SORT(H10:I12,,,TRUE)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), -1, 'Result of SORT(H10:I12,,,TRUE)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 3, 'Result of SORT(H10:I12,,,TRUE)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), -3, 'Result of SORT(H10:I12,,,TRUE)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 27, 'Result of SORT(H10:I12,,,TRUE)[2,1]'); oParser = new parserFormula('SORT(H10:I12,2,-1,TRUE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(H10:I12,2,-1,TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 25, 'Result of SORT(H10:I12,2,-1,TRUE)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), -23, 'Result of SORT(H10:I12,2,-1,TRUE)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, 'Result of SORT(H10:I12,2,-1,TRUE)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), -1, 'Result of SORT(H10:I12,2,-1,TRUE)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 27, 'Result of SORT(H10:I12,2,-1,TRUE)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), -3, 'Result of SORT(H10:I12,2,-1,TRUE)[2,1]'); oParser = new parserFormula('SORT(H10:I12,3,-1,TRUE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(H10:I12,3,-1,TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 25, 'Result of SORT(H10:I12,3,-1,TRUE)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), -23, 'Result of SORT(H10:I12,3,-1,TRUE)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, 'Result of SORT(H10:I12,3,-1,TRUE)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), -1, 'Result of SORT(H10:I12,3,-1,TRUE)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 27, 'Result of SORT(H10:I12,3,-1,TRUE)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), -3, 'Result of SORT(H10:I12,3,-1,TRUE)[2,1]'); oParser = new parserFormula('SORT(H10:I12,3,-1,FALSE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(H10:I12,3,-1,FALSE)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", 'Result of SORT(H10:I12,3,-1,FALSE)'); oParser = new parserFormula('SORT(H10:I12,3)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(H10:I12,3)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", 'Result of SORT(H10:I12,3)'); oParser = new parserFormula('SORT(F10:G13,1,1,TRUE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(F10:G13,1,1,TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "string1", 'Result of SORT(F10:G13,1,1,TRUE)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "Strung1", 'Result of SORT(F10:G13,1,1,TRUE)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "string2", 'Result of SORT(F10:G13,1,1,TRUE)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "sTrung2", 'Result of SORT(F10:G13,1,1,TRUE)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "1string", 'Result of SORT(F10:G13,1,1,TRUE)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "strunG33", 'Result of SORT(F10:G13,1,1,TRUE)[2,1]'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "2string", 'Result of SORT(F10:G13,1,1,TRUE)[3,0]'); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), "1String", 'Result of SORT(F10:G13,1,1,TRUE)[3,1]'); oParser = new parserFormula('SORT(F10:G13,2,1,FALSE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(F10:G13,2,1,FALSE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "2string", 'Result of SORT(F10:G13,1,1,TRUE)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "1String", 'Result of SORT(F10:G13,1,1,TRUE)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "string1", 'Result of SORT(F10:G13,1,1,TRUE)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "Strung1", 'Result of SORT(F10:G13,1,1,TRUE)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "string2", 'Result of SORT(F10:G13,1,1,TRUE)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "sTrung2", 'Result of SORT(F10:G13,1,1,TRUE)[2,1]'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "1string", 'Result of SORT(F10:G13,1,1,TRUE)[3,0]'); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), "strunG33", 'Result of SORT(F10:G13,1,1,TRUE)[3,1]'); oParser = new parserFormula('SORT(B20:C21,1,1,TRUE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(B20:C21,1,1,TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "", 'Result of SORT(B20:C21,1,1,TRUE)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", 'Result of SORT(B20:C21,1,1,TRUE)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", 'Result of SORT(B20:C21,1,1,TRUE)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 1, 'Result of SORT(B20:C21,1,1,TRUE)[1,1]'); oParser = new parserFormula('SORT(D10:E12,1,1,TRUE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(D10:E12,1,1,TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 19, 'Result of SORT(D10:E12,1,1,TRUE)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "str", 'Result of SORT(D10:E12,1,1,TRUE)[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "", 'Result of SORT(D10:E12,1,1,TRUE)[0,2]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#N/A", 'Result of SORT(D10:E12,1,1,TRUE)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "TRUE", 'Result of SORT(D10:E12,1,1,TRUE)[1,1]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "", 'Result of SORT(D10:E12,1,1,TRUE)[1,2]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 0, 'Result of SORT(D10:E12,1,1,TRUE)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 1, 'Result of SORT(D10:E12,1,1,TRUE)[2,1]'); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "", 'Result of SORT(D10:E12,1,1,TRUE)[2,2]'); oParser = new parserFormula('SORT(25,-1,1,TRUE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(25,-1,1,TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", 'Result of SORT(25,-1,1,TRUE)'); oParser = new parserFormula('SORT(25,0,1,TRUE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(25,0,1,TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", 'Result of SORT(25,0,1,TRUE)'); oParser = new parserFormula('SORT(25,1,1,TRUE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(25,1,1,TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 25, 'Result of SORT(25,1,1,TRUE)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", 'Result of SORT(25,1,1,TRUE)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", 'Result of SORT(25,1,1,TRUE)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", 'Result of SORT(25,1,1,TRUE)[1,1]'); oParser = new parserFormula('SORT(25,2,1,TRUE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(25,2,1,TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", 'Result of SORT(25,2,1,TRUE)'); oParser = new parserFormula('SORT(25,1,-1,TRUE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(25,1,-1,TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 25, 'Result of SORT(25,1,-1,TRUE)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", 'Result of SORT(25,1,-1,TRUE)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", 'Result of SORT(25,1,-1,TRUE)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", 'Result of SORT(25,1,-1,TRUE)[1,1]'); oParser = new parserFormula('SORT(25,1,0,TRUE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(25,1,0,TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", 'Result of SORT(25,1,0,TRUE)'); oParser = new parserFormula('SORT(25,1,1,FALSE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(25,1,1,FALSE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 25, 'Result of SORT(25,1,1,TRUE)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", 'Result of SORT(25,1,1,TRUE)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", 'Result of SORT(25,1,1,TRUE)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", 'Result of SORT(25,1,1,TRUE)[1,1]'); // arrays oParser = new parserFormula('SORT({2,3,4;6,6,6;9,2,1},,-1,FALSE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT({2,3,4;6,6,6;9,2,1},,-1,FALSE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 9, 'Result of SORT({2,3,4;6,6,6;9,2,1},,-1,FALSE)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, 'Result of SORT({2,3,4;6,6,6;9,2,1},,-1,FALSE)[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 1, 'Result of SORT({2,3,4;6,6,6;9,2,1},,-1,FALSE)[0,2]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 6, 'Result of SORT({2,3,4;6,6,6;9,2,1},,-1,FALSE)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 6, 'Result of SORT({2,3,4;6,6,6;9,2,1},,-1,FALSE)[1,1]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 6, 'Result of SORT({2,3,4;6,6,6;9,2,1},,-1,FALSE)[1,2]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 2, 'Result of SORT({2,3,4;6,6,6;9,2,1},,-1,FALSE)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 3, 'Result of SORT({2,3,4;6,6,6;9,2,1},,-1,FALSE)[2,1]'); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), 4, 'Result of SORT({2,3,4;6,6,6;9,2,1},,-1,FALSE)[2,2]'); oParser = new parserFormula('SORT({2,3,4;6,6,6;9,2,1},,1,FALSE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT({2,3,4;6,6,6;9,2,1},,1,FALSE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, 'Result of SORT({2,3,4;6,6,6;9,2,1},,1,FALSE)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, 'Result of SORT({2,3,4;6,6,6;9,2,1},,1,FALSE)[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 4, 'Result of SORT({2,3,4;6,6,6;9,2,1},,1,FALSE)[0,2]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 6, 'Result of SORT({2,3,4;6,6,6;9,2,1},,1,FALSE)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 6, 'Result of SORT({2,3,4;6,6,6;9,2,1},,-,FALSE)[1,1]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 6, 'Result of SORT({2,3,4;6,6,6;9,2,1},,1,FALSE)[1,2]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 9, 'Result of SORT({2,3,4;6,6,6;9,2,1},,1,FALSE)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 2, 'Result of SORT({2,3,4;6,6,6;9,2,1},,1,FALSE)[2,1]'); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), 1, 'Result of SORT({2,3,4;6,6,6;9,2,1},,1,FALSE)[2,2]'); oParser = new parserFormula('SORT({2,3,4;6,6,6;9,2,1},,-1,TRUE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT({2,3,4;6,6,6;9,2,1},,-1,TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 4, 'Result of SORT({2,3,4;6,6,6;9,2,1},,-1,TRUE)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, 'Result of SORT({2,3,4;6,6,6;9,2,1},,-1,TRUE)[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 2, 'Result of SORT({2,3,4;6,6,6;9,2,1},,-1,TRUE)[0,2]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 6, 'Result of SORT({2,3,4;6,6,6;9,2,1},,-1,TRUE)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 6, 'Result of SORT({2,3,4;6,6,6;9,2,1},,-1,TRUE)[1,1]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 6, 'Result of SORT({2,3,4;6,6,6;9,2,1},,-1,TRUE)[1,2]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 1, 'Result of SORT({2,3,4;6,6,6;9,2,1},,-1,TRUE)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 2, 'Result of SORT({2,3,4;6,6,6;9,2,1},,-1,TRUE)[2,1]'); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), 9, 'Result of SORT({2,3,4;6,6,6;9,2,1},,-1,TRUE)[2,2]'); oParser = new parserFormula('SORT({2,3,4;6,6,6;9,2,1},,1,TRUE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT({2,3,4;6,6,6;9,2,1},,1,TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, 'Result of SORT({2,3,4;6,6,6;9,2,1},,1,TRUE)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, 'Result of SORT({2,3,4;6,6,6;9,2,1},,1,TRUE)[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 4, 'Result of SORT({2,3,4;6,6,6;9,2,1},,1,TRUE)[0,2]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 6, 'Result of SORT({2,3,4;6,6,6;9,2,1},,1,TRUE)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 6, 'Result of SORT({2,3,4;6,6,6;9,2,1},,1,TRUE)[1,1]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 6, 'Result of SORT({2,3,4;6,6,6;9,2,1},,1,TRUE)[1,2]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 9, 'Result of SORT({2,3,4;6,6,6;9,2,1},,1,TRUE)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 2, 'Result of SORT({2,3,4;6,6,6;9,2,1},,1,TRUE)[2,1]'); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), 1, 'Result of SORT({2,3,4;6,6,6;9,2,1},,1,TRUE)[2,2]'); oParser = new parserFormula('SORT({2,4;6,6;9,1},{2,3},1,TRUE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT({2,4;6,6;9,1},{2,3},1,TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, 'Result of SORT({2,4;6,6;9,1},{3,3},1,TRUE)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 4, 'Result of SORT({2,4;6,6;9,1},{3,3},1,TRUE)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 6, 'Result of SORT({2,4;6,6;9,1},{3,3},1,TRUE)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 6, 'Result of SORT({2,4;6,6;9,1},{3,3},1,TRUE)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 9, 'Result of SORT({2,4;6,6;9,1},{3,3},1,TRUE)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 1, 'Result of SORT({2,4;6,6;9,1},{3,3},1,TRUE)[2,1]'); oParser = new parserFormula('SORT({2,4;6,6;9,1},{2,3},1,FALSE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT({2,4;6,6;9,1},{2,3},1,FALSE)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", 'Result of SORT({2,4;6,6;9,1},{3,3},1,FALSE)'); oParser = new parserFormula('SORT({2,4;6,6;9,1},1,1,{TRUE,FALSE})', 'A2', ws); assert.ok(oParser.parse(), 'SORT({2,4;6,6;9,1},1,1,{TRUE,FALSE})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, 'Result of SORT({2,4;6,6;9,1},1,1,{TRUE,FALSE})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 0, 'Result of SORT({2,4;6,6;9,1},1,1,{TRUE,FALSE})[0,1]'); // #VALUE! oParser = new parserFormula('SORT({2,4;6,6;9,1},1,-1,{TRUE,FALSE})', 'A2', ws); assert.ok(oParser.parse(), 'SORT({2,4;6,6;9,1},1,-1,{TRUE,FALSE})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 4, 'Result of SORT({2,4;6,6;9,1},1,-1,{TRUE,FALSE})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 0, 'Result of SORT({2,4;6,6;9,1},1,-1,{TRUE,FALSE})[0,1]'); // #VALUE! oParser = new parserFormula('SORT({2,4;6,6;9,1},2,1,{TRUE,FALSE})', 'A2', ws); assert.ok(oParser.parse(), 'SORT({2,4;6,6;9,1},2,1,{TRUE,FALSE})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, 'Result of SORT({2,4;6,6;9,1},2,1,{TRUE,FALSE})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 0, 'Result of SORT({2,4;6,6;9,1},2,1,{TRUE,FALSE})[0,1]'); oParser = new parserFormula('SORT({2,4;6,6;9,1},2,-1,{TRUE,FALSE})', 'A2', ws); assert.ok(oParser.parse(), 'SORT({2,4;6,6;9,1},2,-1,{TRUE,FALSE})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, 'Result of SORT({2,4;6,6;9,1},2,-1,{TRUE,FALSE})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 0, 'Result of SORT({2,4;6,6;9,1},2,-1,{TRUE,FALSE})[0,1]'); oParser = new parserFormula('SORT({2,4;6,6;9,1},1,1,{FALSE,TRUE})', 'A2', ws); assert.ok(oParser.parse(), 'SORT({2,4;6,6;9,1},1,1,{FALSE,TRUE})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, 'Result of SORT({2,4;6,6;9,1},1,1,{FALSE,TRUE})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 0, 'Result of SORT({2,4;6,6;9,1},1,1,{FALSE,TRUE})[0,1]'); // #VALUE! oParser = new parserFormula('SORT({2,4;6,6;9,1},1,-1,{FALSE,TRUE})', 'A2', ws); assert.ok(oParser.parse(), 'SORT({2,4;6,6;9,1},1,-1,{FALSE,TRUE})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 9, 'Result of SORT({2,4;6,6;9,1},1,-1,{FALSE,TRUE})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 0, 'Result of SORT({2,4;6,6;9,1},1,-1,{FALSE,TRUE})[0,1]'); oParser = new parserFormula('SORT({2,4;6,6;9,1},2,1,{FALSE,TRUE})', 'A2', ws); assert.ok(oParser.parse(), 'SORT({2,4;6,6;9,1},2,1,{FALSE,TRUE})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 9, 'Result of SORT({2,4;6,6;9,1},2,1,{FALSE,TRUE})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 0, 'Result of SORT({2,4;6,6;9,1},2,1,{FALSE,TRUE})[0,1]'); oParser = new parserFormula('SORT({2,4;6,6;9,1},2,-1,{FALSE,TRUE})', 'A2', ws); assert.ok(oParser.parse(), 'SORT({2,4;6,6;9,1},2,-1,{FALSE,TRUE})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 6, 'Result of SORT({2,4;6,6;9,1},2,-1,{FALSE,TRUE})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 0, 'Result of SORT({2,4;6,6;9,1},2,-1,{FALSE,TRUE})[0,1]'); oParser = new parserFormula('SORT(25,1.9,1.9,FALSE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(25,1.9,1.9,FALSE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 25, "Result of SORT(25,1.9,1.9,FALSE)"); oParser = new parserFormula('SORT(25,0.9,1.9,FALSE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(25,0.9,1.9,FALSE)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", "Result of SORT(25,0.9,1.9,FALSE)"); oParser = new parserFormula('SORT(25,1.9,0.9,FALSE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(25,1.9,0.9,FALSE)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", "Result of SORT(25,1.9,0.9,FALSE)"); oParser = new parserFormula('SORT(25,1.9,-1.9,FALSE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(25,1.9,-1.9,FALSE)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", "Result of SORT(25,1.9,-1.9,FALSE)"); oParser = new parserFormula('SORT(25,1.9,-0.9,FALSE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(25,1.9,-0.9,FALSE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 25, "Result of SORT(25,1.9,-0.9,FALSE)"); ws.getRange2("AB101").setValue("a"); ws.getRange2("AB102").setValue("1"); oParser = new parserFormula('SORT(AB101:AB102,1,1)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(AB101:AB102,1,1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of SORT(AB101:AB102,1,1)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", 'Result of SORT(AB101:AB102,1,1)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "a", 'Result of SORT(AB101:AB102,1,1)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", 'Result of SORT(AB101:AB102,1,1)[1,1]'); oParser = new parserFormula('SORT(AB101:AB102,1,-1)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(AB101:AB102,1,-1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "a", 'Result of SORT(AB101:AB102,1,-1)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", 'Result of SORT(AB101:AB102,1,-1)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 1, 'Result of SORT(AB101:AB102,1,-1)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", 'Result of SORT(AB101:AB102,1,-1)[1,1]'); ws.getRange2("A101").setValue("a"); ws.getRange2("A102").setValue("1"); oParser = new parserFormula('SORT(A101:A102,1,1)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(A101:A102,1,1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of SORT(A101:A102,1,1)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", 'Result of SORT(A101:A102,1,1)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "a", 'Result of SORT(A101:A102,1,1)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", 'Result of SORT(A101:A102,1,1)[1,1]'); ws.getRange2("B101").setValue(""); ws.getRange2("B102").setValue(""); ws.getRange2("B103").setValue(""); ws.getRange2("B104").setValue(""); ws.getRange2("B105").setValue(""); ws.getRange2("C101").setValue("str"); ws.getRange2("C102").setValue("99999"); ws.getRange2("C103").setValue("#NUM!"); ws.getRange2("C104").setValue("FALSE"); ws.getRange2("C105").setValue(""); oParser = new parserFormula('SORT(B101:C105,1,1,TRUE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(B101:C105,1,1,TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "str", 'Result of SORT(B101:C105,1,1,TRUE)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", 'Result of SORT(B101:C105,1,1,TRUE)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 99999, 'Result of SORT(B101:C105,1,1,TRUE)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", 'Result of SORT(B101:C105,1,1,TRUE)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#NUM!", 'Result of SORT(B101:C105,1,1,TRUE)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "", 'Result of SORT(B101:C105,1,1,TRUE)[2,1]'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "FALSE", 'Result of SORT(B101:C105,1,1,TRUE)[3,0]'); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), "", 'Result of SORT(B101:C105,1,1,TRUE)[3,1]'); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "", 'Result of SORT(B101:C105,1,1,TRUE)[4,0]'); assert.strictEqual(array.getElementRowCol(4, 1).getValue(), "", 'Result of SORT(B101:C105,1,1,TRUE)[4,1]'); oParser = new parserFormula('SORT(B101:C104,2,1,FALSE)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(A101:A102,2,1,FALSE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "", 'Result of SORT(B101:C105,1,1,TRUE)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 99999, 'Result of SORT(B101:C105,1,1,TRUE)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", 'Result of SORT(B101:C105,1,1,TRUE)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "str", 'Result of SORT(B101:C105,1,1,TRUE)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", 'Result of SORT(B101:C105,1,1,TRUE)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "FALSE", 'Result of SORT(B101:C105,1,1,TRUE)[2,1]'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "", 'Result of SORT(B101:C105,1,1,TRUE)[3,0]'); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), "#NUM!", 'Result of SORT(B101:C105,1,1,TRUE)[3,1]'); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "", 'Result of SORT(B101:C105,1,1,TRUE)[4,0]'); assert.strictEqual(array.getElementRowCol(4, 1).getValue(), "", 'Result of SORT(B101:C105,1,1,TRUE)[4,1]'); ws.getRange2("B1:C2").cleanAll(); oParser = new parserFormula('SORT(B1:B2,C1:C2)', 'A2', ws); assert.ok(oParser.parse(), 'SORT(B1:B2,C1:C2)'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of SORT(B1:B2,C1:C2)'); }); QUnit.test("Test: \"SORTBY\"", function (assert) { let array; ws.getRange2("B20").setValue(""); ws.getRange2("B21").setValue(); ws.getRange2("C20").setValue(""); ws.getRange2("C21").setValue("1"); ws.getRange2("B20:C21").cleanAll(); ws.getRange2("C30").setValue("12"); ws.getRange2("C30").setNumFormat("@"); ws.getRange2("D10").setValue("19"); ws.getRange2("D11").setValue("#N/A"); ws.getRange2("D12").setValue("0"); ws.getRange2("E10").setValue("str"); ws.getRange2("E11").setValue("TRUE"); ws.getRange2("E12").setValue("1"); ws.getRange2("F10").setValue("1s"); ws.getRange2("F11").setValue("Родион"); ws.getRange2("F12").setValue("222Gleb222"); ws.getRange2("F13").setValue("20"); ws.getRange2("F14").setValue("1"); ws.getRange2("H10").setValue("25"); ws.getRange2("H11").setValue("3"); ws.getRange2("H12").setValue("27"); ws.getRange2("I10").setValue("-23"); ws.getRange2("I11").setValue("-1"); ws.getRange2("I12").setValue("-3"); ws.getRange2("J10").setValue("#N/A"); ws.getRange2("J11").setValue("#NUM!"); ws.getRange2("J12").setValue("#DIV/0!"); oParser = new parserFormula('SORTBY(H10,,E11)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(H10,,E11)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 25, 'Result of SORTBY(H10,,E11)'); oParser = new parserFormula('SORTBY(H10,H12,E11)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(H10,H12,E11)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 25, 'Result of SORTBY(H10,H12,E11)'); oParser = new parserFormula('SORTBY(J10,H12,E11)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(J10,H12,E11)'); array = oParser.calculate(); assert.strictEqual(array.getValue().getValue(), "#N/A", 'Result of SORTBY(J10,H12,E11)'); oParser = new parserFormula('SORTBY(J10,J11,E11)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(J10,J11,E11)'); array = oParser.calculate(); assert.strictEqual(array.getValue().getValue(), "#N/A", 'Result of SORTBY(J10,J11,E11)'); oParser = new parserFormula('SORTBY(J10,J11,J12)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(J10,J11,J12)'); array = oParser.calculate(); assert.strictEqual(array.getValue().getValue(), "#N/A", 'Result of SORTBY(J10,J11,J12)'); oParser = new parserFormula('SORTBY(25,,TRUE)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(25,,TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 25, 'Result of SORTBY(25,,TRUE)'); oParser = new parserFormula('SORTBY(25,27,TRUE)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(25,27,TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 25, 'Result of SORTBY(25,27,TRUE)'); oParser = new parserFormula('SORTBY(#N/A,27,TRUE)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(#N/A,27,TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#N/A", 'Result of SORTBY(#N/A,27,TRUE)'); oParser = new parserFormula('SORTBY(25,#NUM!,TRUE)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(25,#NUM!,TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#NUM!", 'Result of SORTBY(25,#NUM!,TRUE)'); oParser = new parserFormula('SORTBY(25,24,#DIV/0!)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(25,24,#DIV/0!)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#DIV/0!", 'Result of SORTBY(25,27,#DIV/0!)'); oParser = new parserFormula('SORTBY(#N/A,#NUM!,#DIV/0!)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(#N/A,#NUM!,#DIV/0!)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#N/A", 'Result of SORTBY(#N/A,#NUM!,#DIV/0!)'); oParser = new parserFormula('SORTBY(,B21:B21)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(,B21:B21)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "", 'Result of SORTBY(,B21:B21)[0,0]'); oParser = new parserFormula('SORTBY(D10:D10,B21:B21)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(D10:D10,B21:B21)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 19, 'Result of SORTBY(D10:D10,B21:B21)[0,0]'); oParser = new parserFormula('SORTBY(F10:F14,F10:F14)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(F10:F14,F10:F14)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of SORTBY(F10:F14,F10:F14)[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 20, 'Result of SORTBY(F10:F14,F10:F14)[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "1s", 'Result of SORTBY(F10:F14,F10:F14)[2,0]'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "222Gleb222", 'Result of SORTBY(F10:F14,F10:F14)[3,0]'); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "Родион", 'Result of SORTBY(F10:F14,F10:F14)[4,0]'); oParser = new parserFormula('SORTBY(F10:F14,F10:F14,-1)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(F10:F14,F10:F14,-1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "Родион", 'Result of SORTBY(F10:F14,F10:F14)[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "222Gleb222", 'Result of SORTBY(F10:F14,F10:F14)[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "1s", 'Result of SORTBY(F10:F14,F10:F14)[2,0]'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 20, 'Result of SORTBY(F10:F14,F10:F14)[3,0]'); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 1, 'Result of SORTBY(F10:F14,F10:F14)[4,0]'); oParser = new parserFormula('SORTBY(H10:I12,H10:H12)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(H10:I12,H10:H12)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 3, 'Result of SORTBY(H10:I12,H10:H12)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), -1, 'Result of SORTBY(H10:I12,H10:H12)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 25, 'Result of SORTBY(H10:I12,H10:H12)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), -23, 'Result of SORTBY(H10:I12,H10:H12)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 27, 'Result of SORTBY(H10:I12,H10:H12)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), -3, 'Result of SORTBY(H10:I12,H10:H12)[2,1]'); oParser = new parserFormula('SORTBY(H10:I12,H10:H12,-1)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(H10:I12,H10:H12,-1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 27, 'Result of SORTBY(H10:I12,H10:H12,-1)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), -3, 'Result of SORTBY(H10:I12,H10:H12,-1)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 25, 'Result of SORTBY(H10:I12,H10:H12,-1)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), -23, 'Result of SORTBY(H10:I12,H10:H12,-1)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 3, 'Result of SORTBY(H10:I12,H10:H12,-1)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), -1, 'Result of SORTBY(H10:I12,H10:H12,-1)[2,1]'); oParser = new parserFormula('SORTBY(H10:I12,H10:I10)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(H10:I12,H10:I10)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), -23, 'Result of SORTBY(H10:I12,H10:I10)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 25, 'Result of SORTBY(H10:I12,H10:I10)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), -1, 'Result of SORTBY(H10:I12,H10:I10)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 3, 'Result of SORTBY(H10:I12,H10:I10)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), -3, 'Result of SORTBY(H10:I12,H10:I10)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 27, 'Result of SORTBY(H10:I12,H10:I10)[2,1]'); oParser = new parserFormula('SORTBY(H10:I12,H10:I10,-1)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(H10:I12,H10:I10,-1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 25, 'Result of SORTBY(H10:I12,H10:I10,-1)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), -23, 'Result of SORTBY(H10:I12,H10:I10,-1)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, 'Result of SORTBY(H10:I12,H10:I10,-1)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), -1, 'Result of SORTBY(H10:I12,H10:I10,-1)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 27, 'Result of SORTBY(H10:I12,H10:I10,-1)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), -3, 'Result of SORTBY(H10:I12,H10:I10,-1)[2,1]'); oParser = new parserFormula('SORTBY(H10:I12,H10:I10,E12)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(H10:I12,H10:I10,E12)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), -23, 'Result of SORTBY(H10:I12,H10:I10,1)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 25, 'Result of SORTBY(H10:I12,H10:I10,1)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), -1, 'Result of SORTBY(H10:I12,H10:I10,1)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 3, 'Result of SORTBY(H10:I12,H10:I10,1)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), -3, 'Result of SORTBY(H10:I12,H10:I10,1)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 27, 'Result of SORTBY(H10:I12,H10:I10,1)[2,1]'); oParser = new parserFormula('SORTBY(H10:I12,H10:I10,E12:E12)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(H10:I12,H10:I10,E12:E12)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), -23, 'Result of SORTBY(H10:I12,H10:I10,1)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 25, 'Result of SORTBY(H10:I12,H10:I10,1)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), -1, 'Result of SORTBY(H10:I12,H10:I10,1)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 3, 'Result of SORTBY(H10:I12,H10:I10,1)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), -3, 'Result of SORTBY(H10:I12,H10:I10,1)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 27, 'Result of SORTBY(H10:I12,H10:I10,1)[2,1]'); oParser = new parserFormula('SORTBY(H10:I12,H10:I10,I11)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(H10:I12,H10:I10,I11)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 25, 'Result of SORTBY(H10:I12,H10:I10,-1)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), -23, 'Result of SORTBY(H10:I12,H10:I10,-1)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, 'Result of SORTBY(H10:I12,H10:I10,-1)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), -1, 'Result of SORTBY(H10:I12,H10:I10,-1)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 27, 'Result of SORTBY(H10:I12,H10:I10,-1)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), -3, 'Result of SORTBY(H10:I12,H10:I10,-1)[2,1]'); oParser = new parserFormula('SORTBY(H10:I12,H10:I10,I11:I11)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(H10:I12,H10:I10,I11:I11)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 25, 'Result of SORTBY(H10:I12,H10:I10,-1)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), -23, 'Result of SORTBY(H10:I12,H10:I10,-1)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, 'Result of SORTBY(H10:I12,H10:I10,-1)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), -1, 'Result of SORTBY(H10:I12,H10:I10,-1)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 27, 'Result of SORTBY(H10:I12,H10:I10,-1)[2,0]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), -3, 'Result of SORTBY(H10:I12,H10:I10,-1)[2,1]'); ws.getRange2("C101").setValue("1"); ws.getRange2("C102").setValue("2"); ws.getRange2("C103").setValue("2"); ws.getRange2("C104").setValue("2"); ws.getRange2("C105").setValue("4"); ws.getRange2("C106").setValue("5"); ws.getRange2("D101").setValue("8"); ws.getRange2("D102").setValue("3"); ws.getRange2("D103").setValue("4"); ws.getRange2("D104").setValue("4"); ws.getRange2("D105").setValue("7"); ws.getRange2("D106").setValue("4"); ws.getRange2("E101").setValue("0"); ws.getRange2("E102").setValue("3"); ws.getRange2("E103").setValue("2"); ws.getRange2("E104").setValue("1"); ws.getRange2("E105").setValue("2"); ws.getRange2("E106").setValue("3"); ws.getRange2("F101").setValue("0"); ws.getRange2("F102").setValue("5"); ws.getRange2("F103").setValue("0"); ws.getRange2("F104").setValue("0"); ws.getRange2("F105").setValue("0"); ws.getRange2("F106").setValue("6"); oParser = new parserFormula('SORTBY(C101:D101,{1,2,3,4,5},1)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(C101:D101,{1,2,3,4,5},1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 1, 'Result of SORTBY(C101:D101,{1,2,3,4,5},1)[0,0]'); assert.strictEqual(array.getElementRowCol(0,1).getValue(), 8, 'Result of SORTBY(C101:D101,{1,2,3,4,5},1)[0,1]'); assert.strictEqual(array.getElementRowCol(0,2).getValue(), "", 'Result of SORTBY(C101:D101,{1,2,3,4,5},1)[0,2]'); oParser = new parserFormula('SORTBY(C101:D101,{1,2,3,4,5},-1)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(C101:D101,{1,2,3,4,5},-1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), 1, 'Result of SORTBY(C101:D101,{1,2,3,4,5},-1)[0,0]'); assert.strictEqual(array.getElementRowCol(0,1).getValue(), 8, 'Result of SORTBY(C101:D101,{1,2,3,4,5},-1)[0,1]'); assert.strictEqual(array.getElementRowCol(0,2).getValue(), "", 'Result of SORTBY(C101:D101,{1,2,3,4,5},-1)[0,2]'); // two conditions(by_row) // let bbox = ws.getRange2("C2").bbox; // let cellWithFormula = new window['AscCommonExcel'].CCellWithFormula(ws, bbox.r1, bbox.c1); oParser = new parserFormula('SORTBY(C101:F106,C101:F101,1,C103:F103,-1)', "C2", ws); // oParser.setArrayFormulaRef(ws.getRange2("C2").bbox); assert.ok(oParser.parse(), 'SORTBY(C101:F106,C101:F101,1,C103:F103,-1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 0, 'Result of SORTBY(C101:F106,C101:F101,1,C103:F103,-1)[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, 'Result of SORTBY(C101:F106,D101:D106,1,F101:F106,-1)[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 2, 'Result of SORTBY(C101:F106,D101:D106,1,F101:F106,-1)[2,0]'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 1, 'Result of SORTBY(C101:F106,D101:D106,1,F101:F106,-1)[3,0]'); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 2, 'Result of SORTBY(C101:F106,D101:D106,1,F101:F106,-1)[4,0]'); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 3, 'Result of SORTBY(C101:F106,D101:D106,1,F101:F106,-1)[5,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 0, 'Result of SORTBY(C101:F106,D101:D106,1,F101:F106,-1)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 5, 'Result of SORTBY(C101:F106,D101:D106,1,F101:F106,-1)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 0, 'Result of SORTBY(C101:F106,D101:D106,1,F101:F106,-1)[2,1]'); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), 0, 'Result of SORTBY(C101:F106,D101:D106,1,F101:F106,-1)[3,1]'); assert.strictEqual(array.getElementRowCol(4, 1).getValue(), 0, 'Result of SORTBY(C101:F106,D101:D106,1,F101:F106,-1)[4,1]'); assert.strictEqual(array.getElementRowCol(5, 1).getValue(), 6, 'Result of SORTBY(C101:F106,D101:D106,1,F101:F106,-1)[5,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 1, 'Result of SORTBY(C101:F106,D101:D106,1,F101:F106,-1)[0,2]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 2, 'Result of SORTBY(C101:F106,D101:D106,1,F101:F106,-1)[1,2]'); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), 2, 'Result of SORTBY(C101:F106,D101:D106,1,F101:F106,-1)[2,2]'); assert.strictEqual(array.getElementRowCol(3, 2).getValue(), 2, 'Result of SORTBY(C101:F106,D101:D106,1,F101:F106,-1)[3,2]'); assert.strictEqual(array.getElementRowCol(4, 2).getValue(), 4, 'Result of SORTBY(C101:F106,D101:D106,1,F101:F106,-1)[4,2]'); assert.strictEqual(array.getElementRowCol(5, 2).getValue(), 5, 'Result of SORTBY(C101:F106,D101:D106,1,F101:F106,-1)[5,2]'); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 8, 'Result of SORTBY(C101:F106,D101:D106,1,F101:F106,-1)[0,3]'); assert.strictEqual(array.getElementRowCol(1, 3).getValue(), 3, 'Result of SORTBY(C101:F106,D101:D106,1,F101:F106,-1)[1,3]'); assert.strictEqual(array.getElementRowCol(2, 3).getValue(), 4, 'Result of SORTBY(C101:F106,D101:D106,1,F101:F106,-1)[2,3]'); assert.strictEqual(array.getElementRowCol(3, 3).getValue(), 4, 'Result of SORTBY(C101:F106,D101:D106,1,F101:F106,-1)[3,3]'); assert.strictEqual(array.getElementRowCol(4, 3).getValue(), 7, 'Result of SORTBY(C101:F106,D101:D106,1,F101:F106,-1)[4,3]'); assert.strictEqual(array.getElementRowCol(5, 3).getValue(), 4, 'Result of SORTBY(C101:F106,D101:D106,1,F101:F106,-1)[5,3]'); oParser = new parserFormula('SORTBY(C101:F106,C101:F101,,C103:F103,)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(C101:F106,C101:F101,1,C103:F103,1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 0, 'Result of SORTBY(C101:F106,C101:F101,,C103:F103,)[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 5, 'Result of SORTBY(C101:F106,D101:D106,,F101:F106,)[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 0, 'Result of SORTBY(C101:F106,D101:D106,,F101:F106,)[2,0]'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 0, 'Result of SORTBY(C101:F106,D101:D106,,F101:F106,)[3,0]'); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 0, 'Result of SORTBY(C101:F106,D101:D106,,F101:F106,)[4,0]'); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 6, 'Result of SORTBY(C101:F106,D101:D106,,F101:F106,)[5,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 0, 'Result of SORTBY(C101:F106,D101:D106,,F101:F106,)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 3, 'Result of SORTBY(C101:F106,D101:D106,,F101:F106,)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 2, 'Result of SORTBY(C101:F106,D101:D106,,F101:F106,)[2,1]'); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), 1, 'Result of SORTBY(C101:F106,D101:D106,,F101:F106,)[3,1]'); assert.strictEqual(array.getElementRowCol(4, 1).getValue(), 2, 'Result of SORTBY(C101:F106,D101:D106,,F101:F106,)[4,1]'); assert.strictEqual(array.getElementRowCol(5, 1).getValue(), 3, 'Result of SORTBY(C101:F106,D101:D106,,F101:F106,)[5,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 1, 'Result of SORTBY(C101:F106,D101:D106,,F101:F106,)[0,2]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 2, 'Result of SORTBY(C101:F106,D101:D106,,F101:F106,)[1,2]'); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), 2, 'Result of SORTBY(C101:F106,D101:D106,,F101:F106,)[2,2]'); assert.strictEqual(array.getElementRowCol(3, 2).getValue(), 2, 'Result of SORTBY(C101:F106,D101:D106,,F101:F106,)[3,2]'); assert.strictEqual(array.getElementRowCol(4, 2).getValue(), 4, 'Result of SORTBY(C101:F106,D101:D106,,F101:F106,)[4,2]'); assert.strictEqual(array.getElementRowCol(5, 2).getValue(), 5, 'Result of SORTBY(C101:F106,D101:D106,,F101:F106,)[5,2]'); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 8, 'Result of SORTBY(C101:F106,D101:D106,,F101:F106,)[0,3]'); assert.strictEqual(array.getElementRowCol(1, 3).getValue(), 3, 'Result of SORTBY(C101:F106,D101:D106,,F101:F106,)[1,3]'); assert.strictEqual(array.getElementRowCol(2, 3).getValue(), 4, 'Result of SORTBY(C101:F106,D101:D106,,F101:F106,)[2,3]'); assert.strictEqual(array.getElementRowCol(3, 3).getValue(), 4, 'Result of SORTBY(C101:F106,D101:D106,,F101:F106,)[3,3]'); assert.strictEqual(array.getElementRowCol(4, 3).getValue(), 7, 'Result of SORTBY(C101:F106,D101:D106,,F101:F106,)[4,3]'); assert.strictEqual(array.getElementRowCol(5, 3).getValue(), 4, 'Result of SORTBY(C101:F106,D101:D106,,F101:F106,)[5,3]'); // two conditions(by_col) oParser = new parserFormula('SORTBY(C101:F106,D101:D106,1,F101:F106,-1)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(C101:F106,D101:D106,1,F101:F106,-1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,-1)[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 5, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,-1)[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 2, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,-1)[2,0]'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 2, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,-1)[3,0]'); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 4, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,-1)[4,0]'); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 1, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,-1)[5,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,-1)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,-1)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 4, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,-1)[2,1]'); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), 4, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,-1)[3,1]'); assert.strictEqual(array.getElementRowCol(4, 1).getValue(), 7, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,-1)[4,1]'); assert.strictEqual(array.getElementRowCol(5, 1).getValue(), 8, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,-1)[5,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 3, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,-1)[0,2]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 3, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,-1)[1,2]'); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), 2, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,-1)[2,2]'); assert.strictEqual(array.getElementRowCol(3, 2).getValue(), 1, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,-1)[3,2]'); assert.strictEqual(array.getElementRowCol(4, 2).getValue(), 2, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,-1)[4,2]'); assert.strictEqual(array.getElementRowCol(5, 2).getValue(), 0, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,-1)[5,2]'); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 5, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,-1)[0,3]'); assert.strictEqual(array.getElementRowCol(1, 3).getValue(), 6, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,-1)[1,3]'); assert.strictEqual(array.getElementRowCol(2, 3).getValue(), 0, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,-1)[2,3]'); assert.strictEqual(array.getElementRowCol(3, 3).getValue(), 0, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,-1)[3,3]'); assert.strictEqual(array.getElementRowCol(4, 3).getValue(), 0, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,-1)[4,3]'); assert.strictEqual(array.getElementRowCol(5, 3).getValue(), 0, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,-1)[5,3]'); oParser = new parserFormula('SORTBY(C101:F106,D101:D106,1,F101:F106,1)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(C101:F106,D101:D106,1,F101:F106,1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,1)[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,1)[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 2, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,1)[2,0]'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 5, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,1)[3,0]'); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 4, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,1)[4,0]'); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 1, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,1)[5,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,1)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,1)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 4, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,1)[2,1]'); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), 4, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,1)[3,1]'); assert.strictEqual(array.getElementRowCol(4, 1).getValue(), 7, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,1)[4,1]'); assert.strictEqual(array.getElementRowCol(5, 1).getValue(), 8, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,1)[5,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 3, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,1)[0,2]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 2, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,1)[1,2]'); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), 1, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,1)[2,2]'); assert.strictEqual(array.getElementRowCol(3, 2).getValue(), 3, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,1)[3,2]'); assert.strictEqual(array.getElementRowCol(4, 2).getValue(), 2, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,1)[4,2]'); assert.strictEqual(array.getElementRowCol(5, 2).getValue(), 0, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,1)[5,2]'); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 5, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,1)[0,3]'); assert.strictEqual(array.getElementRowCol(1, 3).getValue(), 0, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,1)[1,3]'); assert.strictEqual(array.getElementRowCol(2, 3).getValue(), 0, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,1)[2,3]'); assert.strictEqual(array.getElementRowCol(3, 3).getValue(), 6, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,1)[3,3]'); assert.strictEqual(array.getElementRowCol(4, 3).getValue(), 0, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,1)[4,3]'); assert.strictEqual(array.getElementRowCol(5, 3).getValue(), 0, 'Result of SORTBY(C101:E106,D101:D106,1,F101:F106,1)[5,3]'); oParser = new parserFormula('SORTBY(C101:E106,C101:C106,1,D101:D106,-1)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(C101:E106,C101:C106,1,D101:D106,-1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1)[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1)[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 2, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1)[2,0]'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 2, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1)[3,0]'); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 4, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1)[4,0]'); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 5, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1)[5,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 8, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 4, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1)[2,1]'); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), 3, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1)[3,1]'); assert.strictEqual(array.getElementRowCol(4, 1).getValue(), 7, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1)[4,1]'); assert.strictEqual(array.getElementRowCol(5, 1).getValue(), 4, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1)[5,1]'); // three conditions(by_col) oParser = new parserFormula('SORTBY(C101:E106,C101:C106,1,D101:D106,-1,E101:E106,1)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(C101:E106,C101:C106,1,D101:D106,-1,E101:E106,1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1,E101:E106,1)[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1,E101:E106,1)[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 2, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1,E101:E106,1)[2,0]'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 2, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1,E101:E106,1)[3,0]'); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 4, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1,E101:E106,1)[4,0]'); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 5, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1,E101:E106,1)[5,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 8, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1,E101:E106,1)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1,E101:E106,1)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 4, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1,E101:E106,1)[2,1]'); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), 3, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1,E101:E106,1)[3,1]'); assert.strictEqual(array.getElementRowCol(4, 1).getValue(), 7, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1,E101:E106,1)[4,1]'); assert.strictEqual(array.getElementRowCol(5, 1).getValue(), 4, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1,E101:E106,1)[5,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 0, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1,E101:E106,1)[0,2]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 1, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1,E101:E106,1)[1,2]'); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), 2, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1,E101:E106,1)[2,2]'); assert.strictEqual(array.getElementRowCol(3, 2).getValue(), 3, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1,E101:E106,1)[3,2]'); assert.strictEqual(array.getElementRowCol(4, 2).getValue(), 2, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1,E101:E106,1)[4,2]'); assert.strictEqual(array.getElementRowCol(5, 2).getValue(), 3, 'Result of SORTBY(C101:E106,C101:C106,1,D101:D106,-1,E101:E106,1)[5,2]'); oParser = new parserFormula('SORTBY(C101:E106,D101:D106,1,C101:C106,-1,E101:E106,-1)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(C101:E106,D101:D106,1,C101:C106,-1,E101:E106,-1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, 'Result of SORTBY(C101:E106,D101:D106,1,C101:C106,-1,E101:E106,-1)[0,0]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 5, 'Result of SORTBY(C101:E106,D101:D106,1,C101:C106,-1,E101:E106,-1)[1,0]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 2, 'Result of SORTBY(C101:E106,D101:D106,1,C101:C106,-1,E101:E106,-1)[2,0]'); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), 2, 'Result of SORTBY(C101:E106,D101:D106,1,C101:C106,-1,E101:E106,-1)[3,0]'); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), 4, 'Result of SORTBY(C101:E106,D101:D106,1,C101:C106,-1,E101:E106,-1)[4,0]'); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), 1, 'Result of SORTBY(C101:E106,D101:D106,1,C101:C106,-1,E101:E106,-1)[5,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, 'Result of SORTBY(C101:E106,D101:D106,1,C101:C106,-1,E101:E106,-1)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, 'Result of SORTBY(C101:E106,D101:D106,1,C101:C106,-1,E101:E106,-1)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 1).getValue(), 4, 'Result of SORTBY(C101:E106,D101:D106,1,C101:C106,-1,E101:E106,-1)[2,1]'); assert.strictEqual(array.getElementRowCol(3, 1).getValue(), 4, 'Result of SORTBY(C101:E106,D101:D106,1,C101:C106,-1,E101:E106,-1)[3,1]'); assert.strictEqual(array.getElementRowCol(4, 1).getValue(), 7, 'Result of SORTBY(C101:E106,D101:D106,1,C101:C106,-1,E101:E106,-1)[4,1]'); assert.strictEqual(array.getElementRowCol(5, 1).getValue(), 8, 'Result of SORTBY(C101:E106,D101:D106,1,C101:C106,-1,E101:E106,-1)[5,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 3, 'Result of SORTBY(C101:E106,D101:D106,1,C101:C106,-1,E101:E106,-1)[0,2]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 3, 'Result of SORTBY(C101:E106,D101:D106,1,C101:C106,-1,E101:E106,-1)[1,2]'); assert.strictEqual(array.getElementRowCol(2, 2).getValue(), 2, 'Result of SORTBY(C101:E106,D101:D106,1,C101:C106,-1,E101:E106,-1)[2,2]'); assert.strictEqual(array.getElementRowCol(3, 2).getValue(), 1, 'Result of SORTBY(C101:E106,D101:D106,1,C101:C106,-1,E101:E106,-1)[3,2]'); assert.strictEqual(array.getElementRowCol(4, 2).getValue(), 2, 'Result of SORTBY(C101:E106,D101:D106,1,C101:C106,-1,E101:E106,-1)[4,2]'); assert.strictEqual(array.getElementRowCol(5, 2).getValue(), 0, 'Result of SORTBY(C101:E106,D101:D106,1,C101:C106,-1,E101:E106,-1)[5,2]'); oParser = new parserFormula('SORTBY(1,1,1)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(1,1,1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of SORTBY(1,1,1)'); oParser = new parserFormula('SORTBY(1,1,)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(1,1,)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of SORTBY(1,1,)'); oParser = new parserFormula('SORTBY(1,,)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(1,,)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of SORTBY(1,,)'); oParser = new parserFormula('SORTBY(,,)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(,,)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "", 'Result of SORTBY(,,)'); oParser = new parserFormula('SORTBY("str",1,1)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY("str",1,1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "str", 'Result of SORTBY("str",1,1)'); oParser = new parserFormula('SORTBY("str","1",1)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY("str","1",1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "str", 'Result of SORTBY("str","1",1)'); oParser = new parserFormula('SORTBY("str","1s",1)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY("str","1s",1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "str", 'Result of SORTBY("str","1s",1)'); oParser = new parserFormula('SORTBY("str","1s","1s")', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY("str","1s","1s")'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", 'Result of SORTBY("str","1s","1s")'); oParser = new parserFormula('SORTBY(TRUE,1,TRUE)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(TRUE,1,TRUE)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "TRUE", 'Result of SORTBY(TRUE,1,TRUE)'); oParser = new parserFormula('SORTBY(TRUE,1,FALSE)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(TRUE,1,FALSE)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", 'Result of SORTBY(TRUE,1,FALSE)'); // ??? oParser = new parserFormula('SORTBY(TRUE,{1,2},"1")', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(TRUE,{1,2},"1")'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0,0).getValue(), "TRUE", 'Result of SORTBY(TRUE,{1,2},"1")'); oParser = new parserFormula('SORTBY(H10:I12,I10:I12,{1,#N/A;2,-2})', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(H10:I12,I10:I12,{1,#N/A;2,-2})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 25, 'Result of SORTBY(H10:I12,I10:I12,{1,#N/A;2,-2})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#N/A", 'Result of SORTBY(H10:I12,I10:I12,{1,#N/A;2,-2})[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", 'Result of SORTBY(H10:I12,I10:I12,{1,#N/A;2,-2})[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#VALUE!", 'Result of SORTBY(H10:I12,I10:I12,{1,#N/A;2,-2})[1,1]'); oParser = new parserFormula('SORTBY(H10:I12,I10:I12,{1,#N/A;2,-2})', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(H10:I12,I10:I12,{1,#N/A;2,-2})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 25, 'Result of SORTBY(H10:I12,I10:I12,{1,#N/A;2,-2})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#N/A", 'Result of SORTBY(H10:I12,I10:I12,{1,#N/A;2,-2})[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", 'Result of SORTBY(H10:I12,I10:I12,{1,#N/A;2,-2})[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#VALUE!", 'Result of SORTBY(H10:I12,I10:I12,{1,#N/A;2,-2})[1,1]'); oParser = new parserFormula('SORTBY(H10:I12,I10:I12,{2,1;2,-2})', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(H10:I12,I10:I12,{2,1;2,-2})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", 'Result of SORTBY(H10:I12,I10:I12,{2,1;2,-2}[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 25, 'Result of SORTBY(H10:I12,I10:I12,{2,1;2,-2}[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", 'Result of SORTBY(H10:I12,I10:I12,{2,1;2,-2}[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#VALUE!", 'Result of SORTBY(H10:I12,I10:I12,{2,1;2,-2}[1,1]'); oParser = new parserFormula('SORTBY(H10:I12,I10:I12,{2,-1;2,-2})', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(H10:I12,I10:I12,{2,-1;2,-2})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", 'Result of SORTBY(H10:I12,I10:I12,{2,-1;2,-2}[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, 'Result of SORTBY(H10:I12,I10:I12,{2,-1;2,-2}[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", 'Result of SORTBY(H10:I12,I10:I12,{2,-1;2,-2}[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#VALUE!", 'Result of SORTBY(H10:I12,I10:I12,{2,-1;2,-2}[1,1]'); oParser = new parserFormula('SORTBY(H10:I12,I10:I12,{#NUM!,#N/A;"1","1s"})', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(H10:I12,I10:I12,{#NUM!,#N/A;"1","1s"})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#NUM!", 'Result of SORTBY(H10:I12,I10:I12,{#NUM!,#N/A;"1","1s"})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#N/A", 'Result of SORTBY(H10:I12,I10:I12,{#NUM!,#N/A;"1","1s"})[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 25, 'Result of SORTBY(H10:I12,I10:I12,{#NUM!,#N/A;"1","1s"})[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#VALUE!", 'Result of SORTBY(H10:I12,I10:I12,{#NUM!,#N/A;"1","1s"})[1,1]'); oParser = new parserFormula('SORTBY(H10:I12,I10:I12,{#NUM!,#N/A;"-1","1s"})', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(H10:I12,I10:I12,{#NUM!,#N/A;"-1","1s"})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#NUM!", 'Result of SORTBY(H10:I12,I10:I12,{#NUM!,#N/A;"-1","1s"})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#N/A", 'Result of SORTBY(H10:I12,I10:I12,{#NUM!,#N/A;"-1","1s"})[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, 'Result of SORTBY(H10:I12,I10:I12,{#NUM!,#N/A;"-1","1s"})[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#VALUE!", 'Result of SORTBY(H10:I12,I10:I12,{#NUM!,#N/A;"-1","1s"})[1,1]'); oParser = new parserFormula('SORTBY(H10:I12,I10:I12,{#NUM!,#N/A;"-2","1"})', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(H10:I12,I10:I12,{#NUM!,#N/A;"-2","1"})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#NUM!", 'Result of SORTBY(H10:I12,I10:I12,{#NUM!,#N/A;"-2","1"})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#N/A", 'Result of SORTBY(H10:I12,I10:I12,{#NUM!,#N/A;"-2","1"})[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", 'Result of SORTBY(H10:I12,I10:I12,{#NUM!,#N/A;"-2","1"})[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 25, 'Result of SORTBY(H10:I12,I10:I12,{#NUM!,#N/A;"-2","1"})[1,1]'); oParser = new parserFormula('SORTBY(B20:C21,C20:C21,{#NUM!,#N/A;"-1","1s"})', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(B20:C21,C20:C21,{#NUM!,#N/A;"-1","1s"})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#NUM!", 'Result of SORTBY(B20:C21,C20:C21,{#NUM!,#N/A;"-1","1s"})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#N/A", 'Result of SORTBY(B20:C21,C20:C21,{#NUM!,#N/A;"-1","1s"})[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", 'Result of SORTBY(B20:C21,C20:C21,{#NUM!,#N/A;"-1","1s"})[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "#VALUE!", 'Result of SORTBY(B20:C21,C20:C21,{#NUM!,#N/A;"-1","1s"})[1,1]'); oParser = new parserFormula('SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},1)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},1)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},1)[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 3, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},1)[0,2]'); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 4, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},1)[0,3]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},1)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},1)[1,1]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 6, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},1)[1,2]'); assert.strictEqual(array.getElementRowCol(1, 3).getValue(), 8, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},1)[1,3]'); oParser = new parserFormula('SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},-1)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},-1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 4, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},-1)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},-1)[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 2, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},-1)[0,2]'); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 1, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},-1)[0,3]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 8, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},-1)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 6, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},-1)[1,1]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 4, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},-1)[1,2]'); assert.strictEqual(array.getElementRowCol(1, 3).getValue(), 2, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},-1)[1,3]'); oParser = new parserFormula('SORTBY({1,2,3,4;2,4,6,8},{1,2;3,4},-1)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY({1,2,3,4;2,4,6,8},{1,2;3,4},-1)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2;3,4},-1)'); oParser = new parserFormula('SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},E12)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},E12)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},1)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},1)[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 3, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},1)[0,2]'); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 4, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},1)[0,3]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},1)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},1)[1,1]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 6, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},1)[1,2]'); assert.strictEqual(array.getElementRowCol(1, 3).getValue(), 8, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},1)[1,3]'); oParser = new parserFormula('SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},I11)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},I11)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 4, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},-1)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 3, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},-1)[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 2, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},-1)[0,2]'); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 1, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},-1)[0,3]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 8, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},-1)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 6, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},-1)[1,1]'); assert.strictEqual(array.getElementRowCol(1, 2).getValue(), 4, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},-1)[1,2]'); assert.strictEqual(array.getElementRowCol(1, 3).getValue(), 2, 'Result of SORTBY({1,2,3,4;2,4,6,8},{1,2,3,4},-1)[1,3]'); oParser = new parserFormula('SORTBY(TRUE,FALSE,{1,1,1,-1})', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(TRUE,FALSE,{1,1,1,-1})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "TRUE", 'Result of SORTBY(TRUE,FALSE,{1,1,1,-1})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 0, 'Result of SORTBY(TRUE,FALSE,{1,1,1,-1})[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 0, 'Result of SORTBY(TRUE,FALSE,{1,1,1,-1})[0,2]'); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 0, 'Result of SORTBY(TRUE,FALSE,{1,1,1,-1})[0,3]'); oParser = new parserFormula('SORTBY(TRUE,FALSE,{1,2,1,-1})', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(TRUE,FALSE,{1,2,1,-1})'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "TRUE", 'Result of SORTBY(TRUE,FALSE,{1,2,1,-1})[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", 'Result of SORTBY(TRUE,FALSE,{1,2,1,-1})[0,1]'); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 0, 'Result of SORTBY(TRUE,FALSE,{1,2,1,-1})[0,2]'); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 0, 'Result of SORTBY(TRUE,FALSE,{1,2,1,-1})[0,3]'); ws.getRange2("C4").setValue("Глеб"); ws.getRange2("C5").setValue("Максим"); ws.getRange2("C6").setValue("Елена"); ws.getRange2("D4").setValue("52"); ws.getRange2("D5").setValue("19"); ws.getRange2("D6").setValue("18"); oParser = new parserFormula('SORTBY(C4:D11,C4:D4)', 'A2', ws); assert.ok(oParser.parse(), 'SORTBY(C4:D11,C4:D4)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 52, 'Result of SORTBY(C4:D11,C4:D4)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "Глеб", 'Result of SORTBY(C4:D11,C4:D4)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 19, 'Result of SORTBY(C4:D11,C4:D4)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "Максим", 'Result of SORTBY(C4:D11,C4:D4)[1,1]'); // rows tests(single col) ws.getRange2("A101").setValue("1"); ws.getRange2("A102").setValue("2"); ws.getRange2("B101").setValue("a"); ws.getRange2("B102").setValue("b"); ws.getRange2("A104").setValue("2"); ws.getRange2("A105").setValue("1"); oParser = new parserFormula('SORTBY(A101:A102,B101:B102)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C101:D103").bbox); assert.ok(oParser.parse(), 'SORTBY(A101:A102,B101:B102)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SORTBY(A101:A102,B101:B102)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SORTBY(A101:A102,B101:B102)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, "Result of SORTBY(A101:A102,B101:B102)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SORTBY(A101:A102,B101:B102)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", "Result of SORTBY(A101:A102,B101:B102)[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#N/A", "Result of SORTBY(A101:A102,B101:B102)[3,0]"); } oParser = new parserFormula('SORTBY(A101:A102,B101:B102,-1)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C101:D103").bbox); assert.ok(oParser.parse(), 'SORTBY(A101:A102,B101:B102,-1)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of SORTBY(A101:A102,B101:B102,-1)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SORTBY(A101:A102,B101:B102,-1)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 1, "Result of SORTBY(A101:A102,B101:B102,-1)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SORTBY(A101:A102,B101:B102,-1)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", "Result of SORTBY(A101:A102,B101:B102,-1)[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#N/A", "Result of SORTBY(A101:A102,B101:B102,-1)[3,0]"); } oParser = new parserFormula('SORTBY(A101:A102,,-1)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C101:D103").bbox); assert.ok(oParser.parse(), 'SORTBY(A101:A102,,-1)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SORTBY(A101:A102,,-1)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SORTBY(A101:A102,,-1)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, "Result of SORTBY(A101:A102,,-1)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SORTBY(A101:A102,,-1)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", "Result of SORTBY(A101:A102,,-1)[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#N/A", "Result of SORTBY(A101:A102,,-1)[3,0]"); } oParser = new parserFormula('SORTBY(A101:A102,B101:B102,,B101:B102,A101:A102)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C101:D103").bbox); assert.ok(oParser.parse(), 'SORTBY(A101:A102,B101:B102,,B101:B102,A101:A102)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SORTBY(A101:A102,B101:B102,,B101:B102,A101:A102)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SORTBY(A101:A102,B101:B102,,B101:B102,A101:A102)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", "Result of SORTBY(A101:A102,B101:B102,,B101:B102,A101:A102)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SORTBY(A101:A102,B101:B102,,B101:B102,A101:A102)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", "Result of SORTBY(A101:A102,B101:B102,,B101:B102,A101:A102)[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#N/A", "Result of SORTBY(A101:A102,B101:B102,,B101:B102,A101:A102)[3,0]"); } oParser = new parserFormula('SORTBY(A101:A102,B101:B102,-1,B101:B102,A101:A102)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C101:D103").bbox); assert.ok(oParser.parse(), 'SORTBY(A101:A102,B101:B102,-1,B101:B102,A101:A102)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of SORTBY(A101:A102,B101:B102,-1,B101:B102,A101:A102)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SORTBY(A101:A102,B101:B102,-1,B101:B102,A101:A102)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", "Result of SORTBY(A101:A102,B101:B102,-1,B101:B102,A101:A102)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SORTBY(A101:A102,B101:B102,-1,B101:B102,A101:A102)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", "Result of SORTBY(A101:A102,B101:B102,-1,B101:B102,A101:A102)[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#N/A", "Result of SORTBY(A101:A102,B101:B102,-1,B101:B102,A101:A102)[3,0]"); } oParser = new parserFormula('SORTBY(A101:A102,B101:B102,,A101:A102,B101:B102)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C101:D103").bbox); assert.ok(oParser.parse(), 'SORTBY(A101:A102,B101:B102,,A101:A102,B101:B102)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", "Result of SORTBY(A101:A102,B101:B102,,A101:A102,B101:B102)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SORTBY(A101:A102,B101:B102,,A101:A102,B101:B102)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", "Result of SORTBY(A101:A102,B101:B102,,A101:A102,B101:B102)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SORTBY(A101:A102,B101:B102,,A101:A102,B101:B102)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", "Result of SORTBY(A101:A102,B101:B102,,A101:A102,B101:B102)[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#N/A", "Result of SORTBY(A101:A102,B101:B102,,A101:A102,B101:B102)[3,0]"); } oParser = new parserFormula('SORTBY(A101:A102,B101:B102,-1,A101:A102,B101:B102)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C101:D103").bbox); assert.ok(oParser.parse(), 'SORTBY(A101:A102,B101:B102,-1,A101:A102,B101:B102)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", "Result of SORTBY(A101:A102,B101:B102,-1,A101:A102,B101:B102)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SORTBY(A101:A102,B101:B102,-1,A101:A102,B101:B102)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", "Result of SORTBY(A101:A102,B101:B102,-1,A101:A102,B101:B102)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SORTBY(A101:A102,B101:B102,-1,A101:A102,B101:B102)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", "Result of SORTBY(A101:A102,B101:B102,-1,A101:A102,B101:B102)[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#N/A", "Result of SORTBY(A101:A102,B101:B102,-1,A101:A102,B101:B102)[3,0]"); } oParser = new parserFormula('SORTBY(A101:A102,B101:B102,-1,A101:A102,)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C101:D103").bbox); assert.ok(oParser.parse(), 'SORTBY(A101:A102,B101:B102,-1,A101:A102,)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of SORTBY(A101:A102,B101:B102,-1,A101:A102,)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SORTBY(A101:A102,B101:B102,-1,A101:A102,)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 1, "Result of SORTBY(A101:A102,B101:B102,-1,A101:A102,)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SORTBY(A101:A102,B101:B102,-1,A101:A102,)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", "Result of SORTBY(A101:A102,B101:B102,-1,A101:A102,)[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#N/A", "Result of SORTBY(A101:A102,B101:B102,-1,A101:A102,)[3,0]"); } oParser = new parserFormula('SORTBY(A101:A102,B101:B102,-1,,B101:B102)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C101:D103").bbox); assert.ok(oParser.parse(), 'SORTBY(A101:A102,B101:B102,-1,,B101:B102)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", "Result of SORTBY(A101:A102,B101:B102,-1,,B101:B102)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SORTBY(A101:A102,B101:B102,-1,,B101:B102)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", "Result of SORTBY(A101:A102,B101:B102,-1,,B101:B102)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SORTBY(A101:A102,B101:B102,-1,,B101:B102)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", "Result of SORTBY(A101:A102,B101:B102,-1,,B101:B102)[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#N/A", "Result of SORTBY(A101:A102,B101:B102,-1,,B101:B102)[3,0]"); } oParser = new parserFormula('SORTBY(A101:A102,B101:B102,-1,,)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C101:D103").bbox); assert.ok(oParser.parse(), 'SORTBY(A101:A102,B101:B102,-1,,)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", "Result of SORTBY(A101:A102,B101:B102,-1,,)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SORTBY(A101:A102,B101:B102,-1,,)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", "Result of SORTBY(A101:A102,B101:B102,-1,,)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SORTBY(A101:A102,B101:B102,-1,,)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", "Result of SORTBY(A101:A102,B101:B102,-1,,)[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#N/A", "Result of SORTBY(A101:A102,B101:B102,-1,,)[3,0]"); } oParser = new parserFormula('SORTBY(A101:A102,,-1,A101:A102,B101:B102)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C101:D103").bbox); assert.ok(oParser.parse(), 'SORTBY(A101:A102,,-1,A101:A102,B101:B102)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", "Result of SORTBY(A101:A102,,-1,A101:A102,B101:B102)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SORTBY(A101:A102,,-1,A101:A102,B101:B102)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", "Result of SORTBY(A101:A102,,-1,A101:A102,B101:B102)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SORTBY(A101:A102,,-1,A101:A102,B101:B102)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", "Result of SORTBY(A101:A102,,-1,A101:A102,B101:B102)[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#N/A", "Result of SORTBY(A101:A102,,-1,A101:A102,B101:B102)[3,0]"); } // rows tests(single col) ws.getRange2("P10").setValue("1"); ws.getRange2("P11").setValue("8"); ws.getRange2("P12").setValue("0"); ws.getRange2("P13").setValue("0"); ws.getRange2("P14").setValue("1"); ws.getRange2("P15").setValue("1"); ws.getRange2("Q10").setValue("3"); ws.getRange2("Q11").setValue("2"); ws.getRange2("Q12").setValue("1"); ws.getRange2("Q13").setValue("-1"); ws.getRange2("Q14").setValue("1"); ws.getRange2("Q15").setValue("1"); oParser = new parserFormula('SORTBY(P10:P13,Q10:Q13,1,P10:P13,Q10:Q13)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C101:D103").bbox); assert.ok(oParser.parse(), 'SORTBY(P10:P13,Q10:Q13,1,P10:P13,Q10:Q13)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", "Result of SORTBY(P10:P13,Q10:Q13,1,P10:P13,Q10:Q13)[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", "Result of SORTBY(P10:P13,Q10:Q13,1,P10:P13,Q10:Q13)[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 0, "Result of SORTBY(P10:P13,Q10:Q13,1,P10:P13,Q10:Q13)[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#VALUE!", "Result of SORTBY(P10:P13,Q10:Q13,1,P10:P13,Q10:Q13)[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "", "Result of SORTBY(P10:P13,Q10:Q13,1,P10:P13,Q10:Q13)[4,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SORTBY(P10:P13,Q10:Q13,1,P10:P13,Q10:Q13)[0,1]"); } oParser = new parserFormula('SORTBY(P10:P13,Q10:Q13,-1,P10:P13,Q10:Q13)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C101:D103").bbox); assert.ok(oParser.parse(), 'SORTBY(P10:P13,Q10:Q13,-1,P10:P13,Q10:Q13)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", "Result of SORTBY(P10:P13,Q10:Q13,-1,P10:P13,Q10:Q13)[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", "Result of SORTBY(P10:P13,Q10:Q13,-1,P10:P13,Q10:Q13)[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 1, "Result of SORTBY(P10:P13,Q10:Q13,-1,P10:P13,Q10:Q13)[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#VALUE!", "Result of SORTBY(P10:P13,Q10:Q13,-1,P10:P13,Q10:Q13)[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "", "Result of SORTBY(P10:P13,Q10:Q13,-1,P10:P13,Q10:Q13)[4,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SORTBY(P10:P13,Q10:Q13,-1,P10:P13,Q10:Q13)[0,1]"); } oParser = new parserFormula('SORTBY(P10:P15,Q10:Q15,1,P10:P15,Q10:Q15)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C101:D103").bbox); assert.ok(oParser.parse(), 'SORTBY(P10:P15,Q10:Q15,1,P10:P15,Q10:Q15)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", "Result of SORTBY(P10:P15,Q10:Q15,1,P10:P15,Q10:Q15)[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", "Result of SORTBY(P10:P15,Q10:Q15,1,P10:P15,Q10:Q15)[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 0, "Result of SORTBY(P10:P15,Q10:Q15,1,P10:P15,Q10:Q15)[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#VALUE!", "Result of SORTBY(P10:P15,Q10:Q15,1,P10:P15,Q10:Q15)[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "#VALUE!", "Result of SORTBY(P10:P15,Q10:Q15,1,P10:P15,Q10:Q15)[4,0]"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), "#VALUE!", "Result of SORTBY(P10:P15,Q10:Q15,1,P10:P15,Q10:Q15)[5,0]"); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), "", "Result of SORTBY(P10:P15,Q10:Q15,1,P10:P15,Q10:Q15)[6,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SORTBY(P10:P15,Q10:Q15,1,P10:P15,Q10:Q15)[0,1]"); } oParser = new parserFormula('SORTBY(P10:P15,Q10:Q15,-1,P10:P15,Q10:Q15)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C101:D103").bbox); assert.ok(oParser.parse(), 'SORTBY(P10:P15,Q10:Q15,-1,P10:P15,Q10:Q15)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", "Result of SORTBY(P10:P15,Q10:Q15,-1,P10:P15,Q10:Q15)[0,0]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "#VALUE!", "Result of SORTBY(P10:P15,Q10:Q15,-1,P10:P15,Q10:Q15)[1,0]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 1, "Result of SORTBY(P10:P15,Q10:Q15,-1,P10:P15,Q10:Q15)[2,0]"); assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#VALUE!", "Result of SORTBY(P10:P15,Q10:Q15,-1,P10:P15,Q10:Q15)[3,0]"); assert.strictEqual(array.getElementRowCol(4, 0).getValue(), "#VALUE!", "Result of SORTBY(P10:P15,Q10:Q15,-1,P10:P15,Q10:Q15)[4,0]"); assert.strictEqual(array.getElementRowCol(5, 0).getValue(), "#VALUE!", "Result of SORTBY(P10:P15,Q10:Q15,-1,P10:P15,Q10:Q15)[5,0]"); assert.strictEqual(array.getElementRowCol(6, 0).getValue(), "", "Result of SORTBY(P10:P15,Q10:Q15,-1,P10:P15,Q10:Q15)[6,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SORTBY(P10:P15,Q10:Q15,-1,P10:P15,Q10:Q15)[0,1]"); } // cols tests (single row) ws.getRange2("A114").setValue("1"); ws.getRange2("B114").setValue("2"); ws.getRange2("A115").setValue("a"); ws.getRange2("B115").setValue("b"); oParser = new parserFormula('SORTBY(A114:B114,A115:B115)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C101:D103").bbox); assert.ok(oParser.parse(), 'SORTBY(A114:B114,A115:B115)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SORTBY(A114:B114,A115:B115)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, "Result of SORTBY(A114:B114,A115:B115)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of SORTBY(A114:B114,A115:B115)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SORTBY(A114:B114,A115:B115)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", "Result of SORTBY(A114:B114,A115:B115)[2,0]"); } oParser = new parserFormula('SORTBY(A114:B114,A115:B115,-1)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C101:D103").bbox); assert.ok(oParser.parse(), 'SORTBY(A114:B114,A115:B115,-1)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of SORTBY(A114:B114,A115:B115,-1)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, "Result of SORTBY(A114:B114,A115:B115,-1)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of SORTBY(A114:B114,A115:B115,-1)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SORTBY(A114:B114,A115:B115,-1)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", "Result of SORTBY(A114:B114,A115:B115,-1)[2,0]"); } oParser = new parserFormula('SORTBY(A114:B114,A115:B115,,A115:B115,A114:B114)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C101:D103").bbox); assert.ok(oParser.parse(), 'SORTBY(A114:B114,A115:B115,,A115:B115,A114:B114)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SORTBY(A114:B114,A115:B115,,A115:B115,A114:B114)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", "Result of SORTBY(A114:B114,A115:B115,,A115:B115,A114:B114)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of SORTBY(A114:B114,A115:B115,,A115:B115,A114:B114)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SORTBY(A114:B114,A115:B115,,A115:B115,A114:B114)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", "Result of SORTBY(A114:B114,A115:B115,,A115:B115,A114:B114)[2,0]"); } oParser = new parserFormula('SORTBY(A114:B114,A115:B115,-1,A115:B115,A114:B114)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C101:D103").bbox); assert.ok(oParser.parse(), 'SORTBY(A114:B114,A115:B115,-1,A115:B115,A114:B114)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of SORTBY(A114:B114,A115:B115,-1,A115:B115,A114:B114)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", "Result of SORTBY(A114:B114,A115:B115,-1,A115:B115,A114:B114)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of SORTBY(A114:B114,A115:B115,-1,A115:B115,A114:B114)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SORTBY(A114:B114,A115:B115,-1,A115:B115,A114:B114)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", "Result of SORTBY(A114:B114,A115:B115,-1,A115:B115,A114:B114)[2,0]"); } // cols tests (single row) ws.getRange2("P1").setValue("1"); ws.getRange2("Q1").setValue("8"); ws.getRange2("R1").setValue("0"); ws.getRange2("S1").setValue("0"); ws.getRange2("T1").setValue("1"); ws.getRange2("U1").setValue("1"); ws.getRange2("P2").setValue("3"); ws.getRange2("Q2").setValue("2"); ws.getRange2("R2").setValue("1"); ws.getRange2("S2").setValue("-1"); ws.getRange2("T2").setValue("1"); ws.getRange2("U2").setValue("1"); oParser = new parserFormula('SORTBY(P1:S1;P2:S2;1;P1:S1;P2:S2)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C101:I110").bbox); assert.ok(oParser.parse(), 'SORTBY(P1:S1;P2:S2;1;P1:S1;P2:S2)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", "Result of SORTBY(P1:S1;P2:S2;1;P1:S1;P2:S2)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", "Result of SORTBY(P1:S1;P2:S2;1;P1:S1;P2:S2)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 0, "Result of SORTBY(P1:S1;P2:S2;1;P1:S1;P2:S2)[0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 0, "Result of SORTBY(P1:S1;P2:S2;1;P1:S1;P2:S2)[0,3]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of SORTBY(P1:S1;P2:S2;1;P1:S1;P2:S2)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SORTBY(P1:S1;P2:S2;1;P1:S1;P2:S2)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", "Result of SORTBY(P1:S1;P2:S2;1;P1:S1;P2:S2)[2,0]"); } oParser = new parserFormula('SORTBY(P1:S1;P2:S2;-1;P1:S1;P2:S2)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C101:I110").bbox); assert.ok(oParser.parse(), 'SORTBY(P1:S1;P2:S2;-1;P1:S1;P2:S2)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", "Result of SORTBY(P1:S1;P2:S2;-1;P1:S1;P2:S2)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", "Result of SORTBY(P1:S1;P2:S2;-1;P1:S1;P2:S2)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 1, "Result of SORTBY(P1:S1;P2:S2;-1;P1:S1;P2:S2)[0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 0, "Result of SORTBY(P1:S1;P2:S2;-1;P1:S1;P2:S2)[0,3]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of SORTBY(P1:S1;P2:S2;-1;P1:S1;P2:S2)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SORTBY(P1:S1;P2:S2;-1;P1:S1;P2:S2)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", "Result of SORTBY(P1:S1;P2:S2;-1;P1:S1;P2:S2)[2,0]"); } oParser = new parserFormula('SORTBY(P1:U1;P2:U2;1;P1:U1;P2:U2)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C101:I110").bbox); assert.ok(oParser.parse(), 'SORTBY(P1:U1;P2:U2;1;P1:U1;P2:U2)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", "Result of SORTBY(P1:U1;P2:U2;1;P1:U1;P2:U2)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", "Result of SORTBY(P1:U1;P2:U2;1;P1:U1;P2:U2)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 0, "Result of SORTBY(P1:U1;P2:U2;1;P1:U1;P2:U2)[0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 0, "Result of SORTBY(P1:U1;P2:U2;1;P1:U1;P2:U2)[0,3]"); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), 0, "Result of SORTBY(P1:U1;P2:U2;1;P1:U1;P2:U2)[0,4]"); assert.strictEqual(array.getElementRowCol(0, 5).getValue(), 0, "Result of SORTBY(P1:U1;P2:U2;1;P1:U1;P2:U2)[0,5]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of SORTBY(P1:U1;P2:U2;1;P1:U1;P2:U2)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SORTBY(P1:U1;P2:U2;1;P1:U1;P2:U2)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", "Result of SORTBY(P1:U1;P2:U2;1;P1:U1;P2:U2)[2,0]"); } oParser = new parserFormula('SORTBY(P1:U1;P2:U2;-1;P1:U1;P2:U2)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C101:I110").bbox); assert.ok(oParser.parse(), 'SORTBY(P1:U1;P2:U2;-1;P1:U1;P2:U2)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "#VALUE!", "Result of SORTBY(P1:U1;P2:U2;-1;P1:U1;P2:U2)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "#VALUE!", "Result of SORTBY(P1:U1;P2:U2;-1;P1:U1;P2:U2)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 1, "Result of SORTBY(P1:U1;P2:U2;-1;P1:U1;P2:U2)[0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 0, "Result of SORTBY(P1:U1;P2:U2;-1;P1:U1;P2:U2)[0,3]"); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), 0, "Result of SORTBY(P1:U1;P2:U2;-1;P1:U1;P2:U2)[0,4]"); assert.strictEqual(array.getElementRowCol(0, 5).getValue(), 0, "Result of SORTBY(P1:U1;P2:U2;-1;P1:U1;P2:U2)[0,5]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of SORTBY(P1:U1;P2:U2;-1;P1:U1;P2:U2)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SORTBY(P1:U1;P2:U2;-1;P1:U1;P2:U2)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", "Result of SORTBY(P1:U1;P2:U2;-1;P1:U1;P2:U2)[2,0]"); } // cols tests (single row) ws.getRange2("V1").setValue("2"); ws.getRange2("W1").setValue("3"); ws.getRange2("X1").setValue("1"); ws.getRange2("Y1").setValue("4"); ws.getRange2("V2").setValue("-1"); ws.getRange2("W2").setValue("1"); ws.getRange2("X2").setValue("-1"); ws.getRange2("Y2").setValue("1"); oParser = new parserFormula('SORTBY(V1:Y1,V2:Y2,1,V1:Y1,V2:Y2)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C101:I110").bbox); assert.ok(oParser.parse(), 'SORTBY(V1:Y1,V2:Y2,1,V1:Y1,V2:Y2)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of SORTBY(V1:Y1,V2:Y2,1,V1:Y1,V2:Y2)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 0, "Result of SORTBY(V1:Y1,V2:Y2,1,V1:Y1,V2:Y2)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 0, "Result of SORTBY(V1:Y1,V2:Y2,1,V1:Y1,V2:Y2)[0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 0, "Result of SORTBY(V1:Y1,V2:Y2,1,V1:Y1,V2:Y2)[0,3]"); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), "", "Result of SORTBY(V1:Y1,V2:Y2,1,V1:Y1,V2:Y2)[0,4]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of SORTBY(V1:Y1,V2:Y2,1,V1:Y1,V2:Y2)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SORTBY(V1:Y1,V2:Y2,1,V1:Y1,V2:Y2)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", "Result of SORTBY(V1:Y1,V2:Y2,1,V1:Y1,V2:Y2)[2,0]"); } oParser = new parserFormula('SORTBY(V1:Y1,V2:Y2,-1,V1:Y1,V2:Y2)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C101:I110").bbox); assert.ok(oParser.parse(), 'SORTBY(V1:Y1,V2:Y2,-1,V1:Y1,V2:Y2)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 3, "Result of SORTBY(V1:Y1,V2:Y2,-1,V1:Y1,V2:Y2)[0,0]"); // 4 assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 0, "Result of SORTBY(V1:Y1,V2:Y2,-1,V1:Y1,V2:Y2)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 0, "Result of SORTBY(V1:Y1,V2:Y2,-1,V1:Y1,V2:Y2)[0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 0, "Result of SORTBY(V1:Y1,V2:Y2,-1,V1:Y1,V2:Y2)[0,3]"); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), "", "Result of SORTBY(V1:Y1,V2:Y2,-1,V1:Y1,V2:Y2)[0,4]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of SORTBY(V1:Y1,V2:Y2,-1,V1:Y1,V2:Y2)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SORTBY(V1:Y1,V2:Y2,-1,V1:Y1,V2:Y2)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", "Result of SORTBY(V1:Y1,V2:Y2,-1,V1:Y1,V2:Y2)[2,0]"); } oParser = new parserFormula('SORTBY(V1:Y1,V2:Y2,1)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C201:I210").bbox); assert.ok(oParser.parse(), 'SORTBY(V1:Y1,V2:Y2,1)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 2, "Result of SORTBY(V1:Y1,V2:Y2,1)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, "Result of SORTBY(V1:Y1,V2:Y2,1)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 3, "Result of SORTBY(V1:Y1,V2:Y2,1)[0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 4, "Result of SORTBY(V1:Y1,V2:Y2,1)[0,3]"); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), "", "Result of SORTBY(V1:Y1,V2:Y2,1)[0,4]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of SORTBY(V1:Y1,V2:Y2,1)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SORTBY(V1:Y1,V2:Y2,1)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", "Result of SORTBY(V1:Y1,V2:Y2,1)[2,0]"); } oParser = new parserFormula('SORTBY(V1:Y1,V2:Y2,-1)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C201:I210").bbox); assert.ok(oParser.parse(), 'SORTBY(V1:Y1,V2:Y2,-1)'); array = oParser.calculate(); if (AscCommonExcel.cElementType.array === array.type) { assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 3, "Result of SORTBY(V1:Y1,V2:Y2,-1)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 4, "Result of SORTBY(V1:Y1,V2:Y2,-1)[0,1]"); assert.strictEqual(array.getElementRowCol(0, 2).getValue(), 2, "Result of SORTBY(V1:Y1,V2:Y2,-1)[0,2]"); assert.strictEqual(array.getElementRowCol(0, 3).getValue(), 1, "Result of SORTBY(V1:Y1,V2:Y2,-1)[0,3]"); assert.strictEqual(array.getElementRowCol(0, 4).getValue(), "", "Result of SORTBY(V1:Y1,V2:Y2,-1)[0,4]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", "Result of SORTBY(V1:Y1,V2:Y2,-1)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SORTBY(V1:Y1,V2:Y2,-1)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", "Result of SORTBY(V1:Y1,V2:Y2,-1)[2,0]"); } // For bug 64072 ws.getRange2("A1:Z100").cleanAll(); ws.getRange2("A1").setValue("1"); ws.getRange2("A2").setValue("2"); ws.getRange2("A3").setValue("3"); oParser = new parserFormula('SORTBY(A1:A3,)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C201:I210").bbox); assert.ok(oParser.parse(), 'SORTBY(A1:A3,)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SORTBY(A1:A3,)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SORTBY(A1:A3,)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, "Result of SORTBY(A1:A3,)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SORTBY(A1:A3,)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 3, "Result of SORTBY(A1:A3,)[2,0]"); oParser = new parserFormula('SORTBY(A1:A3,1)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C201:I210").bbox); assert.ok(oParser.parse(), 'SORTBY(A1:A3,1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Result of SORTBY(A1:A3,1)[0,0]"); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", "Result of SORTBY(A1:A3,1)[0,1]"); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, "Result of SORTBY(A1:A3,1)[1,0]"); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", "Result of SORTBY(A1:A3,1)[1,1]"); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 3, "Result of SORTBY(A1:A3,1)[2,0]"); oParser = new parserFormula('SORTBY(A1:A3,"str")', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C201:I210").bbox); assert.ok(oParser.parse(), 'SORTBY(A1:A3,"str")'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of SORTBY(A1:A3,"str")[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", 'Result of SORTBY(A1:A3,"str")[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, 'Result of SORTBY(A1:A3,"str")[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", 'Result of SORTBY(A1:A3,"str")[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 3, 'Result of SORTBY(A1:A3,"str")[2,0]'); oParser = new parserFormula('SORTBY(A1:A3,#DIV/0!)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C201:I210").bbox); assert.ok(oParser.parse(), 'SORTBY(A1:A3,#DIV/0!)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#DIV/0!", 'Result of SORTBY(A1:A3,#DIV/0!)'); oParser = new parserFormula('SORTBY(A1:A3,,)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C201:I210").bbox); assert.ok(oParser.parse(), 'SORTBY(A1:A3,,)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of SORTBY(A1:A3,,)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", 'Result of SORTBY(A1:A3,,)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, 'Result of SORTBY(A1:A3,,)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", 'Result of SORTBY(A1:A3,,)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 3, 'Result of SORTBY(A1:A3,,)[2,0]'); oParser = new parserFormula('SORTBY(A1:A3,A2:A3)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C201:I210").bbox); assert.ok(oParser.parse(), 'SORTBY(A1:A3,A2:A3)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", 'Result of SORTBY(A1:A3,A2:A3)'); oParser = new parserFormula('SORTBY(A1:A3,{1,2,3})', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C201:I210").bbox); assert.ok(oParser.parse(), 'SORTBY(A1:A3,{1,2,3})'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", 'Result of SORTBY(A1:A3,{1,2,3})'); oParser = new parserFormula('SORTBY(A1:A3,,1,2,1)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C201:I210").bbox); assert.ok(oParser.parse(), 'SORTBY(A1:A3,,1,2,1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of SORTBY(A1:A3,,1,2,1)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", 'Result of SORTBY(A1:A3,,1,2,1)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, 'Result of SORTBY(A1:A3,,1,2,1)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", 'Result of SORTBY(A1:A3,,1,2,1)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 3, 'Result of SORTBY(A1:A3,,1,2,1)[2,0]'); oParser = new parserFormula('SORTBY(A1:A3,,1,"str",1)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C201:I210").bbox); assert.ok(oParser.parse(), 'SORTBY(A1:A3,,1,"str",1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of SORTBY(A1:A3,,1,"str",1)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", 'Result of SORTBY(A1:A3,,1,"str",1)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, 'Result of SORTBY(A1:A3,,1,"str",1)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", 'Result of SORTBY(A1:A3,,1,"str",1)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 3, 'Result of SORTBY(A1:A3,,1,"str",1)[2,0]'); oParser = new parserFormula('SORTBY(A1:A3,,1,{2;3;1},1)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C201:I210").bbox); assert.ok(oParser.parse(), 'SORTBY(A1:A3,,1,{2;3;1},1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of SORTBY(A1:A3,,1,{2;3;1},1)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", 'Result of SORTBY(A1:A3,,1,{2;3;1},1)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, 'Result of SORTBY(A1:A3,,1,{2;3;1},1)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", 'Result of SORTBY(A1:A3,,1,{2;3;1},1)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 3, 'Result of SORTBY(A1:A3,,1,{2;3;1},1)[2,0]'); oParser = new parserFormula('SORTBY(A1:A3,1,1,{3;2;1},1)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C201:I210").bbox); assert.ok(oParser.parse(), 'SORTBY(A1:A3,1,1,{3;2;1},1)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of SORTBY(A1:A3,1,1,{3;2;1},1)[0,0]'); assert.strictEqual(array.getElementRowCol(0, 1).getValue(), "", 'Result of SORTBY(A1:A3,1,1,{3;2;1},1)[0,1]'); assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 2, 'Result of SORTBY(A1:A3,1,1,{3;2;1},1)[1,0]'); assert.strictEqual(array.getElementRowCol(1, 1).getValue(), "", 'Result of SORTBY(A1:A3,1,1,{3;2;1},1)[1,1]'); assert.strictEqual(array.getElementRowCol(2, 0).getValue(), 3, 'Result of SORTBY(A1:A3,1,1,{3;2;1},1)[2,0]'); oParser = new parserFormula('SORTBY(A1:A3,{3;2;1},1,1,1)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("C201:I210").bbox); assert.ok(oParser.parse(), 'SORTBY(A1:A3,{3;2;1},1,1,1)'); array = oParser.calculate(); assert.strictEqual(array.getValue(), "#VALUE!", 'Result of SORTBY(A1:A3,{3;2;1},1,1,1)'); ws.getRange2("A1:C3").cleanAll(); oParser = new parserFormula('SORTBY(C1:C3,C1:C3)', "A1", ws); oParser.setArrayFormulaRef(ws.getRange2("A1:A3").bbox); assert.ok(oParser.parse(), 'SORTBY(C1:C3,C1:C3)'); array = oParser.calculate(); assert.strictEqual(array.getElementRowCol(0, 0).getValue(), "", 'Result of SORTBY(C1:C3,C1:C3)[0,0]'); // cEmpty assert.strictEqual(array.getElementRowCol(1, 0).getValue(), "", 'Result of SORTBY(C1:C3,C1:C3)[1,0]'); // cEmpty assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "", 'Result of SORTBY(C1:C3,C1:C3)[2,0]'); // cEmpty // oParser = new parserFormula('SORTBY(C4:D6,C4:D4,{1,1;1,1},C5:D5,1,C6:D6,1)', 'A2', ws); // assert.ok(oParser.parse(), 'SORTBY(C4:D6,C4:D4,{1,1;1,1},C5:D5,1,C6:D6,1)'); // array = oParser.calculate(); // assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 52, 'Result of SORTBY(C4:D6,C4:D4,{1,1;1,1},C5:D5,1,C6:D6,1)[0,0]'); // assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 0, 'Result of SORTBY(C4:D6,C4:D4,{1,1;1,1},C5:D5,1,C6:D6,1)[0,1]'); // assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "", 'Result of SORTBY(C4:D6,C4:D4,{1,1;1,1},C5:D5,1,C6:D6,1)[0,2]'); // assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "", 'Result of SORTBY(C4:D6,C4:D4,{1,1;1,1},C5:D5,1,C6:D6,1)[0,3]'); // assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 0, 'Result of SORTBY(C4:D6,C4:D4,{1,1;1,1},C5:D5,1,C6:D6,1)[1,0]'); // assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 0, 'Result of SORTBY(C4:D6,C4:D4,{1,1;1,1},C5:D5,1,C6:D6,1)[1,1]'); // assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "", 'Result of SORTBY(C4:D6,C4:D4,{1,1;1,1},C5:D5,1,C6:D6,1)[1,2]'); // assert.strictEqual(array.getElementRowCol(1, 3).getValue(), "", 'Result of SORTBY(C4:D6,C4:D4,{1,1;1,1},C5:D5,1,C6:D6,1)[1,3]'); // oParser = new parserFormula('SORTBY(C4:D6,C4:D4,{1,1;1,1},C5:D5,1,C6:D6,{1,1,1,2})', 'A2', ws); // assert.ok(oParser.parse(), 'SORTBY(C4:D6,C4:D4,{1,1;1,1},C5:D5,1,C6:D6,{1,1,1,2})'); // array = oParser.calculate(); // assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 52, 'Result of SORTBY(C4:D6,C4:D4,{1,1;1,1},C5:D5,1,C6:D6,{1,1,1,2})[0,0]'); // assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 0, 'Result of SORTBY(C4:D6,C4:D4,{1,1;1,1},C5:D5,1,C6:D6,{1,1,1,2})[0,1]'); // assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#N/A", 'Result of SORTBY(C4:D6,C4:D4,{1,1;1,1},C5:D5,1,C6:D6,{1,1,1,2})[0,2]'); // assert.strictEqual(array.getElementRowCol(0, 3).getValue(), "#N/A", 'Result of SORTBY(C4:D6,C4:D4,{1,1;1,1},C5:D5,1,C6:D6,{1,1,1,2})[0,3]'); // assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 0, 'Result of SORTBY(C4:D6,C4:D4,{1,1;1,1},C5:D5,1,C6:D6,{1,1,1,2})[1,0]'); // assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 0, 'Result of SORTBY(C4:D6,C4:D4,{1,1;1,1},C5:D5,1,C6:D6,{1,1,1,2})[1,1]'); // assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "#N/A", 'Result of SORTBY(C4:D6,C4:D4,{1,1;1,1},C5:D5,1,C6:D6,{1,1,1,2})[1,2]'); // assert.strictEqual(array.getElementRowCol(1, 3).getValue(), "#N/A", 'Result of SORTBY(C4:D6,C4:D4,{1,1;1,1},C5:D5,1,C6:D6,{1,1,1,2})[1,3]'); // =SORTBY(C4:D6,C4:D4,{1,1,1,1},C5:D5,D24:E25,C6:D6,{-1,1,-2}) // 1row: #VALUE #VALUE #N/A #N/A 2row: #VALUE 52 #N/A #N/A }); QUnit.test("Test: \"AREAS\"", function (assert) { oParser = new parserFormula('AREAS(1)', "A1", ws); assert.ok(oParser.parse(), "AREAS(1)"); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", "Result of AREAS(1)"); oParser = new parserFormula('AREAS("str")', "A1", ws); assert.ok(oParser.parse(), 'AREAS("str")'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of AREAS("str")'); oParser = new parserFormula('AREAS({1,2,3})', "A1", ws); assert.ok(oParser.parse(), 'AREAS({1,2,3})'); assert.strictEqual(oParser.calculate().getValue(), "#VALUE!", 'Result of AREAS({1,2,3})'); oParser = new parserFormula('AREAS(A10)', "A1", ws); assert.ok(oParser.parse(), "AREAS(A10)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of AREAS(A10)"); oParser = new parserFormula('AREAS('+ ws.getName() + '!A10)', "A1", ws); assert.ok(oParser.parse(), "AREAS(Sheet1!A10)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of AREAS(Sheet1!A10)"); oParser = new parserFormula('AREAS(A10:A11)', "A1", ws); assert.ok(oParser.parse(), "AREAS(A10:A11)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of AREAS(A10:A11)"); oParser = new parserFormula('AREAS('+ ws.getName() + '!A10:A11)', "A1", ws); assert.ok(oParser.parse(), "AREAS(Sheet1!A10:A11)"); assert.strictEqual(oParser.calculate().getValue(), 1, "Result of AREAS(Sheet1!A10:A11)"); }); QUnit.test("Test: \"reference argument test\"", function (assert) { ws.getRange2("A1").setValue("1"); ws.getRange2("A2").setValue("2"); ws.getRange2("A3").setValue("3"); ws.getRange2("A4").setValue("4"); ws.getRange2("A5").setValue("5"); ws.getRange2("A6").setValue("6"); ws.getRange2("B1").setValue("2"); ws.getRange2("B2").setValue(""); ws.getRange2("B3").setValue("3"); ws.getRange2("B4").setValue("4"); ws.getRange2("B5").setValue("5"); ws.getRange2("B6").setValue("6"); oParser = new parserFormula('IRR(SIN(A1:B4))', 'A2', ws); assert.ok(oParser.parse(), 'IRR(SIN(A1:B4))'); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, -0.123554096, 'IRR(SIN(A1:B4))'); oParser = new parserFormula('MIRR(SIN(A2:B4),1,1)', 'A2', ws); assert.ok(oParser.parse(), 'MIRR(SIN(A2:B4),1,1)'); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 2.36894463, 'MIRR(SIN(A2:B4),1,1)'); oParser = new parserFormula('COLUMN(INDEX(A1:B3,1,1))', 'A2', ws); assert.ok(oParser.parse(), 'COLUMN(INDEX(A1:B3,1,1))'); assert.strictEqual(oParser.calculate().getValue(), 1, 'COLUMN(INDEX(A1:B3,1,1))'); oParser = new parserFormula('COLUMNS(SIN($A$1:$B$4))', 'A2', ws); assert.ok(oParser.parse(), 'COLUMNS(SIN($A$1:$B$4))'); assert.strictEqual(oParser.calculate().getValue(), 2, 'COLUMNS(SIN($A$1:$B$4))'); oParser = new parserFormula('INDEX(SIN(A1:B3),1,1)', 'A2', ws); assert.ok(oParser.parse(), 'INDEX(SIN(A1:B3),1,1)'); assert.strictEqual(oParser.calculate().getValue().toFixed(9) - 0, 0.841470985, 'INDEX(SIN(A1:B3),1,1)'); /*oParser = new parserFormula( 'OFFSET(INDEX(A1:B3,1,1),1,1)', 'A2', ws ); assert.ok( oParser.parse(),'OFFSET(INDEX(A1:B3,1,1),1,1)' ); assert.strictEqual( oParser.calculate().getValue(),0,'OFFSET(INDEX(A1:B3,1,1),1,1)');*/ oParser = new parserFormula('ROW(INDEX(A1:B3,1,1))', 'A2', ws); assert.ok(oParser.parse(), 'ROW(INDEX(A1:B3,1,1))'); assert.strictEqual(oParser.calculate().getValue(), 1, 'ROW(INDEX(A1:B3,1,1))'); oParser = new parserFormula('ROWS(SIN(A1:B3))', 'A2', ws); assert.ok(oParser.parse(), 'ROWS(SIN(A1:B3))'); assert.strictEqual(oParser.calculate().getValue(), 3, 'ROWS(SIN(A1:B3))'); oParser = new parserFormula('SUBTOTAL(1,INDEX(A1:B3,1,1))', 'A2', ws); assert.ok(oParser.parse(), 'SUBTOTAL(1,INDEX(A1:B3,1,1))'); assert.strictEqual(oParser.calculate().getValue(), 1, 'SUBTOTAL(1,INDEX(A1:B3,1,1))'); oParser = new parserFormula('SUMIF(INDEX(A1:B3,1,1),1,INDEX(A1:B3,1,1))', 'A2', ws); assert.ok(oParser.parse(), 'SUMIF(INDEX(A1:B3,1,1),1,INDEX(A1:B3,1,1))'); assert.strictEqual(oParser.calculate().getValue(), 1, 'SUMIF(INDEX(A1:B3,1,1),1,INDEX(A1:B3,1,1))'); oParser = new parserFormula('SUMIFS(INDEX(A1:B3,1,1),INDEX(A1:B3,1,1),INDEX(A1:B3,1,1))', 'A2', ws); assert.ok(oParser.parse(), 'SUMIFS(INDEX(A1:B3,1,1),INDEX(A1:B3,1,1),INDEX(A1:B3,1,1))'); assert.strictEqual(oParser.calculate().getValue(), 1, 'SUMIFS(INDEX(A1:B3,1,1),INDEX(A1:B3,1,1),INDEX(A1:B3,1,1))'); oParser = new parserFormula('AVERAGEIF(INDEX(A1:B3,1,1),INDEX(A1:B3,1,1),INDEX(A1:B3,1,1))', 'A2', ws); assert.ok(oParser.parse(), 'AVERAGEIF(INDEX(A1:B3,1,1),INDEX(A1:B3,1,1),INDEX(A1:B3,1,1))'); assert.strictEqual(oParser.calculate().getValue(), 1, 'AVERAGEIF(INDEX(A1:B3,1,1),INDEX(A1:B3,1,1),INDEX(A1:B3,1,1))'); oParser = new parserFormula('COUNTBLANK(INDEX(A1:B3,1,1))', 'A2', ws); assert.ok(oParser.parse(), 'COUNTBLANK(INDEX(A1:B3,1,1))'); assert.strictEqual(oParser.calculate().getValue(), 0, 'COUNTBLANK(INDEX(A1:B3,1,1))'); oParser = new parserFormula('COUNTIF(INDEX(A1:B3,1,1),INDEX(A1:B3,1,1))', 'A2', ws); assert.ok(oParser.parse(), 'COUNTIF(INDEX(A1:B3,1,1),INDEX(A1:B3,1,1))'); assert.strictEqual(oParser.calculate().getValue(), 1, 'COUNTIF(INDEX(A1:B3,1,1),INDEX(A1:B3,1,1))'); oParser = new parserFormula('COUNTIFS(INDEX(A1:B3,1,1),INDEX(A1:B3,1,1))', 'A2', ws); assert.ok(oParser.parse(), 'COUNTIFS(INDEX(A1:B3,1,1),INDEX(A1:B3,1,1))'); assert.strictEqual(oParser.calculate().getValue(), 1, 'COUNTIFS(INDEX(A1:B3,1,1),INDEX(A1:B3,1,1))'); ws.getRange2("A2").setValue("qq"); ws.getRange2("A3").setValue("ww"); ws.getRange2("A4").setValue("ee"); ws.getRange2("A5").setValue("qq"); ws.getRange2("A6").setValue("qq"); ws.getRange2("A7").setValue("ww"); ws.getRange2("A8").setValue("ww"); ws.getRange2("A9").setValue("ww"); ws.getRange2("A10").setValue("eee"); ws.getRange2("B1").setValue("qqqq"); ws.getRange2("B2").setValue("ee"); var _f = 'IFERROR(INDEX($A$2:$A$10,MATCH(0,INDEX(COUNTIF($B$1:B1,$A$2:$A$10)+(COUNTIF($A$2:$A$10,$A$2:$A$10)<>1),0,0),0)),"")'; oParser = new parserFormula(_f, 'A2', ws); assert.ok(oParser.parse(), _f); assert.strictEqual(oParser.calculate().getValue().getValue(), "ee", _f); _f = 'IFERROR(INDEX($A$2:$A$10,MATCH(0,INDEX(COUNTIF($B$1:B2,$A$2:$A$10)+(COUNTIF($A$2:$A$10,$A$2:$A$10)<>1),0,0),0)),"")'; oParser = new parserFormula(_f, 'A2', ws); assert.ok(oParser.parse(), _f); assert.strictEqual(oParser.calculate().getValue().getValue(), "eee", _f); _f = 'INDEX($A$2:$A$10,MATCH(0,INDEX(COUNTIF($B$1:B1,$A$2:$A$10)+(COUNTIF($A$2:$A$10,$A$2:$A$10)<>1),0,0),0))'; oParser = new parserFormula(_f, 'A2', ws); assert.ok(oParser.parse(), _f); assert.strictEqual(oParser.calculate().getValue().getValue(), "ee", _f); _f = 'MATCH(0,INDEX({1;1;0;1;1;1;1;1;0},0,0))'; oParser = new parserFormula(_f, 'A2', ws); assert.ok(oParser.parse(), _f); assert.strictEqual(oParser.calculate().getValue(), "#N/A", _f); _f = 'INDEX($A$2:$A$10,MATCH(0,INDEX({1;1;0;1;1;1;1;1;0},0,0),0))'; oParser = new parserFormula(_f, 'A2', ws); assert.ok(oParser.parse(), _f); assert.strictEqual(oParser.calculate().getValue().getValue(), "ee", _f); _f = 'INDEX($A$2:$A$10,3)'; oParser = new parserFormula(_f, 'A2', ws); assert.ok(oParser.parse(), _f); assert.strictEqual(oParser.calculate().getValue().getValue(), "ee", _f); _f = 'INDEX($A$2:$A$10,MATCH(0,{1;1;0;1;1;1;1;1;0},0))'; oParser = new parserFormula(_f, 'A2', ws); assert.ok(oParser.parse(), _f); assert.strictEqual(oParser.calculate().getValue().getValue(), "ee", _f); _f = 'MATCH(0,INDEX(COUNTIF($B$1:B1,$A$2:$A$10)+(COUNTIF($A$2:$A$10,$A$2:$A$10)<>1),0,0),0)'; oParser = new parserFormula(_f, 'A2', ws); assert.ok(oParser.parse(), _f); assert.strictEqual(oParser.calculate().getValue(), 3, _f); }); QUnit.test("Test: \"GetAllFormulas test\"", function (assert) { wb.dependencyFormulas.unlockRecal(); let formulaRange, formulas; ws.getRange2("A1:AAZ10000").cleanAll(); formulaRange = ws.getRange2("A10:A110"); ws.getRange2("A9").setValue("=SIN(10)"); // ws.selectionRange.ranges = [ws.getRange2("A10:A110").getBBox0()]; // ws.selectionRange.setActiveCell(ws.getRange2("A10").getBBox0().r1, ws.getRange2("A10").getBBox0().c1); ws.getRange2("A10:A110").setValue("=SUM(A2)", null, null, formulaRange.bbox); formulaRange = ws.getRange2("B1:B10000"); ws.getRange2("B1:B10000").setValue("=1/NOT(ISBLANK(A1:A10000))", null, null, formulaRange.bbox); ws.getRange2("C1").setValue("=RAND()"); ws.getRange2("C2").setValue("=SIN(B1)"); formulaRange = ws.getRange2("C1:C110"); ws.getRange2("C10:C110").setValue("=B:B", null, null, formulaRange.bbox); formulaRange = ws.getRange2("D1:D10"); ws.getRange2("D1:D10").setValue("=C1", null, null, formulaRange.bbox); formulas = wb.getAllFormulas(); assert.ok(1, "Created 6 formulas on a sheet: 3 regular, 3 array-formula"); assert.strictEqual(formulas.length, 6, "GetAllFormulas array length"); let randRegValBefore = ws.getRange2("C1").getValue(), randArrayFValBefore = ws.getRange2("D1").getValue(); // recalculate workbook wb.calculate(4); formulas = wb.getAllFormulas(); assert.ok(1, "Check formulas after workbook recalculate"); assert.strictEqual(formulas.length, 6, "GetAllFormulas array length"); let randRegValAfter = ws.getRange2("C1").getValue(), randArrayFValAfter = ws.getRange2("D1").getValue(); assert.ok(1, "Check values after workbook recalculate. Values shouldn't be the same"); assert.strictEqual(randRegValBefore !== randRegValAfter, true, "Check values after recalculate"); assert.strictEqual(randArrayFValBefore !== randArrayFValAfter, true, "Check values after recalculate"); ws.getRange2("A1:Z10000").cleanAll(); }); QUnit.test("Test: \"Dynamic array test\"", function (assert) { let bboxParent, cellWithFormula, formulaInfo, resultRow, resultCol, applyByArray, array; // wb.dependencyFormulas.unlockRecal(); ws.getRange2("A1:Z10").cleanAll(); ws.getRange2("A1").setValue("1"); ws.getRange2("A2").setValue("2"); ws.getRange2("A3").setValue("3"); ws.getRange2("B1").setValue("4"); ws.getRange2("B2").setValue("str"); ws.getRange2("B3").setValue("6"); ws.getRange2("C1").setValue("1"); ws.getRange2("C2").setValue(); ws.getRange2("C3").setValue("1"); // let parent = AscCommonExcel.g_oRangeCache.getAscRange("D1"); bboxParent = ws.getRange2("D1").bbox; cellWithFormula = new window['AscCommonExcel'].CCellWithFormula(ws, bboxParent.r1, bboxParent.c1); ws.getRange2("C3").setValue("=SIN(A1:A3)", null, null, bboxParent); // TODO: review tests with ranges after adding dynamic arrays and add findRefByOutStack formula to use in tests oParser = new parserFormula('A1:A3', cellWithFormula, ws); assert.ok(oParser.parse(), 'A1:A3'); formulaInfo = ws.getRefDynamicInfo(oParser); resultRow = formulaInfo && formulaInfo.dynamicRange.getHeight(); resultCol = formulaInfo && formulaInfo.dynamicRange.getWidth(); applyByArray = formulaInfo && formulaInfo.applyByArray; assert.strictEqual(applyByArray, false, 'Is =A1:A3 array formula'); assert.strictEqual(resultRow, false, 'Rows in =A1:A3'); assert.strictEqual(resultCol, false, 'Cols in =A1:A3'); oParser = new parserFormula('{1;2;3}', cellWithFormula, ws); assert.ok(oParser.parse(), '{1;2;3}'); formulaInfo = ws.getRefDynamicInfo(oParser); resultRow = formulaInfo && formulaInfo.dynamicRange.getHeight(); resultCol = formulaInfo && formulaInfo.dynamicRange.getWidth(); applyByArray = formulaInfo && formulaInfo.applyByArray; assert.strictEqual(applyByArray, true, 'Is ={1;2;3} array formula'); assert.strictEqual(resultRow, 3, 'Rows in ={1;2;3}'); assert.strictEqual(resultCol, 1, 'Cols in ={1;2;3}'); oParser = new parserFormula('A1:C1', cellWithFormula, ws); assert.ok(oParser.parse(), 'A1:C1'); formulaInfo = ws.getRefDynamicInfo(oParser); resultRow = formulaInfo && formulaInfo.dynamicRange.getHeight(); resultCol = formulaInfo && formulaInfo.dynamicRange.getWidth(); applyByArray = formulaInfo && formulaInfo.applyByArray; assert.strictEqual(applyByArray, false, 'Is =A1:C1 array formula'); assert.strictEqual(resultRow, false, 'Rows in =A1:C1'); assert.strictEqual(resultCol, false, 'Cols in =A1:C1'); oParser = new parserFormula('{1,2,3}', cellWithFormula, ws); assert.ok(oParser.parse(), '{1,2,3}'); formulaInfo = ws.getRefDynamicInfo(oParser); resultRow = formulaInfo && formulaInfo.dynamicRange.getHeight(); resultCol = formulaInfo && formulaInfo.dynamicRange.getWidth(); applyByArray = formulaInfo && formulaInfo.applyByArray; assert.strictEqual(applyByArray, true, 'Is ={1,2,3} array formula'); assert.strictEqual(resultRow, 1, 'Rows in ={1,2,3}'); assert.strictEqual(resultCol, 3, 'Cols in ={1,2,3}'); oParser = new parserFormula('A1:C3', cellWithFormula, ws); assert.ok(oParser.parse(), 'A1:C3'); formulaInfo = ws.getRefDynamicInfo(oParser); resultRow = formulaInfo && formulaInfo.dynamicRange.getHeight(); resultCol = formulaInfo && formulaInfo.dynamicRange.getWidth(); applyByArray = formulaInfo && formulaInfo.applyByArray; assert.strictEqual(applyByArray, false, 'Is =A1:C3 array formula'); assert.strictEqual(resultRow, false, 'Rows in =A1:C3'); assert.strictEqual(resultCol, false, 'Cols in =A1:C3'); oParser = new parserFormula('{1,2;3,4}', cellWithFormula, ws); assert.ok(oParser.parse(), '{1,2;3,4}'); formulaInfo = ws.getRefDynamicInfo(oParser); resultRow = formulaInfo && formulaInfo.dynamicRange.getHeight(); resultCol = formulaInfo && formulaInfo.dynamicRange.getWidth(); applyByArray = formulaInfo && formulaInfo.applyByArray; assert.strictEqual(applyByArray, true, 'Is ={1,2;3,4} array formula'); assert.strictEqual(resultRow, 2, 'Rows in ={1,2;3,4}'); assert.strictEqual(resultCol, 2, 'Cols in ={1,2;3,4}'); oParser = new parserFormula('SIN(A1:A3)', cellWithFormula, ws); assert.ok(oParser.parse(), 'SIN(A1:A3)'); formulaInfo = ws.getRefDynamicInfo(oParser); resultRow = formulaInfo && formulaInfo.dynamicRange.getHeight(); resultCol = formulaInfo && formulaInfo.dynamicRange.getWidth(); applyByArray = formulaInfo && formulaInfo.applyByArray; assert.strictEqual(applyByArray, true, 'Is =SIN(A1:A3) array formula'); assert.strictEqual(resultRow, 3, 'Rows in =SIN(A1:A3)'); assert.strictEqual(resultCol, 1, 'Cols in =SIN(A1:A3)'); oParser = new parserFormula('SIN({1;2;3})', cellWithFormula, ws); assert.ok(oParser.parse(), 'SIN({1;2;3})'); formulaInfo = ws.getRefDynamicInfo(oParser); resultRow = formulaInfo && formulaInfo.dynamicRange.getHeight(); resultCol = formulaInfo && formulaInfo.dynamicRange.getWidth(); applyByArray = formulaInfo && formulaInfo.applyByArray; assert.strictEqual(applyByArray, true, 'Is =SIN({1;2;3}) array formula'); assert.strictEqual(resultRow, 3, 'Rows in =SIN({1;2;3})'); assert.strictEqual(resultCol, 1, 'Cols in =SIN({1;2;3})'); oParser = new parserFormula('SIN(A1:C1)', cellWithFormula, ws); assert.ok(oParser.parse(), 'SIN(A1:C1)'); formulaInfo = ws.getRefDynamicInfo(oParser); resultRow = formulaInfo && formulaInfo.dynamicRange.getHeight(); resultCol = formulaInfo && formulaInfo.dynamicRange.getWidth(); applyByArray = formulaInfo && formulaInfo.applyByArray; assert.strictEqual(applyByArray, true, 'Is =SIN(A1:C1) array formula'); assert.strictEqual(resultRow, 1, 'Rows in =SIN(A1:C1)'); assert.strictEqual(resultCol, 3, 'Cols in =SIN(A1:C1)'); oParser = new parserFormula('SIN({1,2,3})', cellWithFormula, ws); assert.ok(oParser.parse(), 'SIN({1,2,3})'); formulaInfo = ws.getRefDynamicInfo(oParser); resultRow = formulaInfo && formulaInfo.dynamicRange.getHeight(); resultCol = formulaInfo && formulaInfo.dynamicRange.getWidth(); applyByArray = formulaInfo && formulaInfo.applyByArray; assert.strictEqual(applyByArray, true, 'Is =SIN({1,2,3}) array formula'); assert.strictEqual(resultRow, 1, 'Rows in =SIN({1,2,3})'); assert.strictEqual(resultCol, 3, 'Cols in =SIN({1,2,3})'); oParser = new parserFormula('SIN(A1:C3)', cellWithFormula, ws); assert.ok(oParser.parse(), 'SIN(A1:C3)'); formulaInfo = ws.getRefDynamicInfo(oParser); resultRow = formulaInfo && formulaInfo.dynamicRange.getHeight(); resultCol = formulaInfo && formulaInfo.dynamicRange.getWidth(); applyByArray = formulaInfo && formulaInfo.applyByArray; assert.strictEqual(applyByArray, true, 'Is =SIN(A1:C3) array formula'); assert.strictEqual(resultRow, 3, 'Rows in =SIN(A1:C3)'); assert.strictEqual(resultCol, 3, 'Cols in =SIN(A1:C3)'); oParser = new parserFormula('SIN({1,2;3,4})', cellWithFormula, ws); assert.ok(oParser.parse(), 'SIN({1,2;3,4})'); formulaInfo = ws.getRefDynamicInfo(oParser); resultRow = formulaInfo && formulaInfo.dynamicRange.getHeight(); resultCol = formulaInfo && formulaInfo.dynamicRange.getWidth(); applyByArray = formulaInfo && formulaInfo.applyByArray; assert.strictEqual(applyByArray, true, 'Is =SIN({1,2;3,4}) array formula'); assert.strictEqual(resultRow, 2, 'Rows in =SIN({1,2;3,4})'); assert.strictEqual(resultCol, 2, 'Cols in =SIN({1,2;3,4})'); oParser = new parserFormula('A:A', cellWithFormula, ws); assert.ok(oParser.parse(), 'A:A'); formulaInfo = ws.getRefDynamicInfo(oParser); resultRow = formulaInfo && formulaInfo.dynamicRange.getHeight(); resultCol = formulaInfo && formulaInfo.dynamicRange.getWidth(); applyByArray = formulaInfo && formulaInfo.applyByArray; assert.strictEqual(applyByArray, false, 'Is =A:A array formula'); assert.strictEqual(resultRow, false /*AscCommon.gc_nMaxRow*/, 'Rows in =A:A from D1'); assert.strictEqual(resultCol, false, 'Cols in =A:A from D1'); oParser = new parserFormula('A1:XFD1', cellWithFormula, ws); assert.ok(oParser.parse(), 'A1:XFD1'); formulaInfo = ws.getRefDynamicInfo(oParser); resultRow = formulaInfo && formulaInfo.dynamicRange.getHeight(); resultCol = formulaInfo && formulaInfo.dynamicRange.getWidth(); applyByArray = formulaInfo && formulaInfo.applyByArray; assert.strictEqual(applyByArray, false, 'Is =A1:XFD1 array formula'); assert.strictEqual(resultRow, false, 'Rows in =A1:XFD1 from D1'); assert.strictEqual(resultCol, false /*AscCommon.gc_nMaxCol - 3*/, 'Cols in =A1:XFD1 from D1'); oParser = new parserFormula('SIN(A1)', cellWithFormula, ws); assert.ok(oParser.parse(), 'SIN(A1)'); formulaInfo = ws.getRefDynamicInfo(oParser); resultRow = formulaInfo && formulaInfo.dynamicRange.getHeight(); resultCol = formulaInfo && formulaInfo.dynamicRange.getWidth(); applyByArray = formulaInfo && formulaInfo.applyByArray; assert.strictEqual(applyByArray, false, 'Is =SIN(A1) array formula'); assert.strictEqual(resultRow, false, 'Rows in =SIN(A1)'); assert.strictEqual(resultCol, false, 'Cols in =SIN(A1)'); oParser = new parserFormula('SUM(A1:A3)', cellWithFormula, ws); assert.ok(oParser.parse(), 'SUM(A1:A3)'); formulaInfo = ws.getRefDynamicInfo(oParser); resultRow = formulaInfo && formulaInfo.dynamicRange.getHeight(); resultCol = formulaInfo && formulaInfo.dynamicRange.getWidth(); applyByArray = formulaInfo && formulaInfo.applyByArray; assert.strictEqual(applyByArray, false, 'Is =SUM(A1:A3) array formula'); assert.strictEqual(resultRow, false, 'Rows in =SUM(A1:A3)'); assert.strictEqual(resultCol, false, 'Cols in =SUM(A1:A3)'); oParser = new parserFormula('SUM(A1:A3+A1:A3)', cellWithFormula, ws); assert.ok(oParser.parse(), 'SUM(A1:A3+A1:A3)'); formulaInfo = ws.getRefDynamicInfo(oParser); resultRow = formulaInfo && formulaInfo.dynamicRange.getHeight(); resultCol = formulaInfo && formulaInfo.dynamicRange.getWidth(); applyByArray = formulaInfo && formulaInfo.applyByArray; assert.strictEqual(applyByArray, false, 'Is =SUM(A1:A3+A1:A3) array formula'); assert.strictEqual(resultRow, false, 'Rows in =SUM(A1:A3+A1:A3)'); assert.strictEqual(resultCol, false, 'Cols in =SUM(A1:A3+A1:A3)'); oParser = new parserFormula('SUM(A1:A3+A1:A3)+A1:A3', cellWithFormula, ws); assert.ok(oParser.parse(), 'SUM(A1:A3+A1:A3)+A1:A3'); formulaInfo = ws.getRefDynamicInfo(oParser); resultRow = formulaInfo && formulaInfo.dynamicRange.getHeight(); resultCol = formulaInfo && formulaInfo.dynamicRange.getWidth(); applyByArray = formulaInfo && formulaInfo.applyByArray; assert.strictEqual(applyByArray, true, 'Is =SUM(A1:A3+A1:A3)+A1:A3 array formula'); assert.strictEqual(resultRow, 3, 'Rows in =SUM(A1:A3+A1:A3)+A1:A3'); assert.strictEqual(resultCol, 1, 'Cols in =SUM(A1:A3+A1:A3)+A1:A3'); oParser = new parserFormula('SUM(SIN(A1:A3)+A1:A3)', cellWithFormula, ws); assert.ok(oParser.parse(), 'SUM(SIN(A1:A3)+A1:A3)'); formulaInfo = ws.getRefDynamicInfo(oParser); resultRow = formulaInfo && formulaInfo.dynamicRange.getHeight(); resultCol = formulaInfo && formulaInfo.dynamicRange.getWidth(); applyByArray = formulaInfo && formulaInfo.applyByArray; assert.strictEqual(applyByArray, false, 'Is =SUM(SIN(A1:A3)+A1:A3) array formula'); assert.strictEqual(resultRow, false, 'Rows in =SUM(SIN(A1:A3)+A1:A3)'); assert.strictEqual(resultCol, false, 'Cols in =SUM(SIN(A1:A3)+A1:A3)'); oParser = new parserFormula('SUM(SIN(SUM(A1:A3)))', cellWithFormula, ws); assert.ok(oParser.parse(), 'SUM(SIN(SUM(A1:A3)))'); formulaInfo = ws.getRefDynamicInfo(oParser); resultRow = formulaInfo && formulaInfo.dynamicRange.getHeight(); resultCol = formulaInfo && formulaInfo.dynamicRange.getWidth(); applyByArray = formulaInfo && formulaInfo.applyByArray; assert.strictEqual(applyByArray, false, 'Is =SUM(SIN(SUM(A1:A3))) array formula'); assert.strictEqual(resultRow, false, 'Rows in =SUM(SIN(SUM(A1:A3)))'); assert.strictEqual(resultCol, false, 'Cols in =SUM(SIN(SUM(A1:A3)))'); oParser = new parserFormula('SIN(SUM(SIN(A1:A3)))', cellWithFormula, ws); assert.ok(oParser.parse(), 'SIN(SUM(SIN(A1:A3)))'); formulaInfo = ws.getRefDynamicInfo(oParser); resultRow = formulaInfo && formulaInfo.dynamicRange.getHeight(); resultCol = formulaInfo && formulaInfo.dynamicRange.getWidth(); applyByArray = formulaInfo && formulaInfo.applyByArray; assert.strictEqual(applyByArray, false, 'Is =SIN(SUM(SIN(A1:A3))) array formula'); assert.strictEqual(resultRow, false, 'Rows in =SIN(SUM(SIN(A1:A3)))'); assert.strictEqual(resultCol, false, 'Cols in =SIN(SUM(SIN(A1:A3)))'); oParser = new parserFormula('COS(SIN(A1)*SUM(A1:A3)+A1:A3)', cellWithFormula, ws); assert.ok(oParser.parse(), 'COS(SIN(A1)*SUM(A1:A3)+A1:A3)'); formulaInfo = ws.getRefDynamicInfo(oParser); resultRow = formulaInfo && formulaInfo.dynamicRange.getHeight(); resultCol = formulaInfo && formulaInfo.dynamicRange.getWidth(); applyByArray = formulaInfo && formulaInfo.applyByArray; assert.strictEqual(applyByArray, true, 'Is =COS(SIN(A1)*SUM(A1:A3)+A1:A3) array formula'); assert.strictEqual(resultRow, 3, 'Rows in =COS(SIN(A1)*SUM(A1:A3)+A1:A3)'); assert.strictEqual(resultCol, 1, 'Cols in =COS(SIN(A1)*SUM(A1:A3)+A1:A3)'); oParser = new parserFormula('SIN(A1+A1:A3)', cellWithFormula, ws); assert.ok(oParser.parse(), 'SIN(A1+A1:A3)'); formulaInfo = ws.getRefDynamicInfo(oParser); resultRow = formulaInfo && formulaInfo.dynamicRange.getHeight(); resultCol = formulaInfo && formulaInfo.dynamicRange.getWidth(); applyByArray = formulaInfo && formulaInfo.applyByArray; assert.strictEqual(applyByArray, true, 'Is =SIN(A1+A1:A3) array formula'); assert.strictEqual(resultRow, 3, 'Rows in =SIN(A1+A1:A3)'); assert.strictEqual(resultCol, 1, 'Cols in =SIN(A1+A1:A3)'); oParser = new parserFormula('{1,2}*{3;4}', cellWithFormula, ws); assert.ok(oParser.parse(), '{1,2}*{3;4}'); formulaInfo = ws.getRefDynamicInfo(oParser); resultRow = formulaInfo && formulaInfo.dynamicRange.getHeight(); resultCol = formulaInfo && formulaInfo.dynamicRange.getWidth(); applyByArray = formulaInfo && formulaInfo.applyByArray; assert.strictEqual(applyByArray, true, 'Is ={1,2}*{3;4} array formula'); assert.strictEqual(resultRow, 2, 'Rows in ={1,2}*{3;4}'); assert.strictEqual(resultCol, 2, 'Cols in ={1,2}*{3;4}'); oParser = new parserFormula('{2}*{2}', cellWithFormula, ws); assert.ok(oParser.parse(), '{2}*{2}'); formulaInfo = ws.getRefDynamicInfo(oParser); resultRow = formulaInfo && formulaInfo.dynamicRange.getHeight(); resultCol = formulaInfo && formulaInfo.dynamicRange.getWidth(); applyByArray = formulaInfo && formulaInfo.applyByArray; assert.strictEqual(applyByArray, true, 'Is ={2}*{2} array formula'); assert.strictEqual(resultRow, 1, 'Rows in ={1,2}*{3;4}'); assert.strictEqual(resultCol, 1, 'Cols in ={1,2}*{3;4}'); // #N/A check ws.getRange2("A100:Z110").cleanAll(); bboxParent = ws.getRange2("D100").bbox; cellWithFormula = new window['AscCommonExcel'].CCellWithFormula(ws, bboxParent.r1, bboxParent.c1); oParser = new parserFormula('A100:B101', cellWithFormula, ws); oParser.setArrayFormulaRef(ws.getRange2("D100:E104").bbox); assert.ok(oParser.parse(), 'A100:B101'); array = oParser.calculate(); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1, bboxParent.c1).getValue(), "", "Result of =A100:B101 [0,0]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1, bboxParent.c1 + 1).getValue(), "", "Result of =A100:B101 [0,1]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1, bboxParent.c1 + 2).getValue(), "#N/A", "Result of =A100:B101 [0,2]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1, bboxParent.c1 + 3).getValue(), "#N/A", "Result of =A100:B101 [0,3]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1 + 1, bboxParent.c1).getValue(), "", "Result of =A100:B101 [1,0]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1 + 1, bboxParent.c1 + 1).getValue(), "", "Result of =A100:B101 [1,1]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1 + 1, bboxParent.c1 + 2).getValue(), "#N/A", "Result of =A100:B101 [1,2]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1 + 1, bboxParent.c1 + 3).getValue(), "#N/A", "Result of =A100:B101 [1,3]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1 + 2, bboxParent.c1).getValue(), "#N/A", "Result of =A100:B101 [2,0]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1 + 2, bboxParent.c1 + 1).getValue(), "#N/A", "Result of =A100:B101 [2,1]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1 + 2, bboxParent.c1 + 2).getValue(), "#N/A", "Result of =A100:B101 [2,2]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1 + 2, bboxParent.c1 + 3).getValue(), "#N/A", "Result of =A100:B101 [2,3]"); ws.getRange2("A100").setValue("1"); bboxParent = ws.getRange2("I100").bbox; cellWithFormula = new window['AscCommonExcel'].CCellWithFormula(ws, bboxParent.r1, bboxParent.c1); oParser = new parserFormula('A100:B101', cellWithFormula, ws); oParser.setArrayFormulaRef(ws.getRange2("I100:J104").bbox); assert.ok(oParser.parse(), 'A100:B101'); array = oParser.calculate(); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1, bboxParent.c1).getValue(), 1, "Result of =A100:B101 [0,0]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1, bboxParent.c1 + 1).getValue(), "", "Result of =A100:B101 [0,1]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1, bboxParent.c1 + 2).getValue(), "#N/A", "Result of =A100:B101 [0,2]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1, bboxParent.c1 + 3).getValue(), "#N/A", "Result of =A100:B101 [0,3]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1 + 1, bboxParent.c1).getValue(), "", "Result of =A100:B101 [1,0]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1 + 1, bboxParent.c1 + 1).getValue(), "", "Result of =A100:B101 [1,1]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1 + 1, bboxParent.c1 + 2).getValue(), "#N/A", "Result of =A100:B101 [1,2]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1 + 1, bboxParent.c1 + 3).getValue(), "#N/A", "Result of =A100:B101 [1,3]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1 + 2, bboxParent.c1).getValue(), "#N/A", "Result of =A100:B101 [2,0]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1 + 2, bboxParent.c1 + 1).getValue(), "#N/A", "Result of =A100:B101 [2,1]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1 + 2, bboxParent.c1 + 2).getValue(), "#N/A", "Result of =A100:B101 [2,2]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1 + 2, bboxParent.c1 + 3).getValue(), "#N/A", "Result of =A100:B101 [2,3]"); ws.getRange2("B101").setValue("#N/A"); bboxParent = ws.getRange2("M100").bbox; cellWithFormula = new window['AscCommonExcel'].CCellWithFormula(ws, bboxParent.r1, bboxParent.c1); oParser = new parserFormula('A100:B101', cellWithFormula, ws); oParser.setArrayFormulaRef(ws.getRange2("M100:O104").bbox); assert.ok(oParser.parse(), 'A100:B101'); array = oParser.calculate(); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1, bboxParent.c1).getValue(), 1, "Result of =A100:B101 [0,0]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1, bboxParent.c1 + 1).getValue(), "", "Result of =A100:B101 [0,1]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1, bboxParent.c1 + 2).getValue(), "#N/A", "Result of =A100:B101 [0,2]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1, bboxParent.c1 + 3).getValue(), "#N/A", "Result of =A100:B101 [0,3]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1 + 1, bboxParent.c1).getValue(), "", "Result of =A100:B101 [1,0]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1 + 1, bboxParent.c1 + 1).getValue(), "#N/A", "Result of =A100:B101 [1,1]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1 + 1, bboxParent.c1 + 2).getValue(), "#N/A", "Result of =A100:B101 [1,2]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1 + 1, bboxParent.c1 + 3).getValue(), "#N/A", "Result of =A100:B101 [1,3]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1 + 2, bboxParent.c1).getValue(), "#N/A", "Result of =A100:B101 [2,0]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1 + 2, bboxParent.c1 + 1).getValue(), "#N/A", "Result of =A100:B101 [2,1]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1 + 2, bboxParent.c1 + 2).getValue(), "#N/A", "Result of =A100:B101 [2,2]"); assert.strictEqual(oParser.simplifyRefType(array, ws, bboxParent.r1 + 2, bboxParent.c1 + 3).getValue(), "#N/A", "Result of =A100:B101 [2,3]"); }); QUnit.test("Long string splitting", function (assert) { // Test case for long string (300 chars - should split into 2 parts) let originalString = "a".repeat(300); ws.getRange2("A1").setValue("=\"" + originalString + "\""); let formula = ws.getRange2("A1").getFormula(); let expectedSplits = Math.ceil(originalString.length / 255) - 1; let actualSplits = (formula.match(/&/g) || []).length; assert.equal(actualSplits, expectedSplits, "300-char string should have exactly 1 concatenation"); assert.equal(ws.getRange2("A1").getValue(), originalString, "Result should match original 300-char string"); // Test very long string (600 chars - should split into 3 parts) let longString = "b".repeat(600); ws.getRange2("A2").setValue("=\"" + longString + "\""); formula = ws.getRange2("A2").getFormula(); expectedSplits = Math.ceil(longString.length / 255) - 1; actualSplits = (formula.match(/&/g) || []).length; assert.equal(actualSplits, expectedSplits, "600-char string should have exactly 2 concatenations"); assert.equal(ws.getRange2("A2").getValue(), longString, "Result should match original 600-char string"); // Test mixed content string (480 chars - should split into 2 parts) let mixedString = "Hello world! ".repeat(40); // 480 characters ws.getRange2("A3").setValue("=\"" + mixedString + "\""); formula = ws.getRange2("A3").getFormula(); expectedSplits = Math.ceil(mixedString.length / 255) - 1; actualSplits = (formula.match(/&/g) || []).length; assert.equal(actualSplits, expectedSplits, "480-char string should have exactly 1 concatenation"); assert.equal(ws.getRange2("A3").getValue(), mixedString, "Result should match original mixed string"); // Test boundary case (255 chars - should not split) let boundaryString = "c".repeat(255); ws.getRange2("A4").setValue("=\"" + boundaryString + "\""); formula = ws.getRange2("A4").getFormula(); actualSplits = (formula.match(/&/g) || []).length; assert.equal(actualSplits, 0, "255-char string should have no concatenations"); assert.equal(ws.getRange2("A4").getValue(), boundaryString, "Result should match original boundary string"); // Test string with quotes (360 chars with quotes - should split into 2 parts) let quotedString = "Test\"\"Quote".repeat(30); // 12 chars * 30 = 360 chars ws.getRange2("A5").setValue("=\"" + quotedString + "\""); formula = ws.getRange2("A5").getFormula(); expectedSplits = Math.ceil(quotedString.length / 255) - 1; actualSplits = (formula.match(/&/g) || []).length; assert.equal(actualSplits, expectedSplits, "360-char quoted string should have exactly 1 concatenation"); assert.equal(ws.getRange2("A5").getValue(), quotedString.replace(/\"\"/g, "\""), "Result should match original quoted string"); }); QUnit.test("Long string splitting in functions", function (assert) { // Test CONCATENATE with long strings (300 + 200 chars) let string1 = "a".repeat(300); let string2 = "b".repeat(200); ws.getRange2("B1").setValue("=\"" + string2 + "\""); ws.getRange2("A1").setValue("=CONCATENATE(\"" + string1 + "\", B1)"); let formula = ws.getRange2("A1").getFormula(); let expectedSplits = Math.ceil(string1.length / 255) - 1; let actualSplits = (formula.match(/&/g) || []).length; assert.equal(actualSplits, expectedSplits, "CONCATENATE with 300-char string should have exactly 1 concatenation"); assert.equal(ws.getRange2("A1").getValue(), string1 + string2, "CONCATENATE result should match combined strings"); // Test FIND with long strings (300 chars search in 600 chars text) let searchString = "needle".repeat(50); // 300 chars let haystackString = "needle".repeat(100); // 600 chars ws.getRange2("A2").setValue("=FIND(\"" + searchString + "\", \"" + haystackString + "\")"); formula = ws.getRange2("A2").getFormula(); expectedSplits = Math.ceil(searchString.length / 255) - 1 + Math.ceil(haystackString.length / 255) - 1; actualSplits = (formula.match(/&/g) || []).length; assert.equal(actualSplits, expectedSplits, "FIND with long strings should have exactly 3 concatenations"); assert.equal(ws.getRange2("A2").getValue(), 1, "FIND should work with split strings"); // Test nested functions (400 chars) let nestedString = "nested_text".repeat(40); // 400 chars ws.getRange2("A4").setValue("=LEN(UPPER(\"" + nestedString + "\"))"); formula = ws.getRange2("A4").getFormula(); expectedSplits = Math.ceil(nestedString.length / 255) - 1; actualSplits = (formula.match(/&/g) || []).length; assert.equal(actualSplits, expectedSplits, "Nested function with 400-char string should have exactly 1 concatenation"); assert.equal(ws.getRange2("A4").getValue(), nestedString.length, "Nested functions should work with split strings"); }); function calcCustomFunction (innerFunc, jsDoc, oDoc, fCompare) { let api = window["Asc"]["editor"]; if (jsDoc) { let oJsDoc = AscCommon.parseJSDoc(jsDoc); api.addCustomFunction(innerFunc, oJsDoc[0]); fCompare("jsDoc"); } /*if (oDoc) { api.addCustomFunction(innerFunc, oDoc); fCompare("oDoc"); }*/ } function initCustomFunctionData() { ws.getRange2("A100").setValue("1"); ws.getRange2("A101").setValue("2"); ws.getRange2("B100").setValue("3"); ws.getRange2("B101").setValue("4"); ws.getRange2("C100").setValue("test1"); ws.getRange2("C101").setValue("test2"); ws.getRange2("D100").setValue("test3"); ws.getRange2("D101").setValue("test4"); ws.getRange2("E100").setValue("TRUE"); ws.getRange2("E101").setValue("FALSE"); ws.getRange2("F100").setValue("FALSE"); ws.getRange2("F101").setValue("TRUE"); ws.getRange2("G100").setValue("#VALUE!"); ws.getRange2("G101").setValue("#REF!"); ws.getRange2("H100").setValue("#VALUE!"); ws.getRange2("H101").setValue("#DIV/0!"); } let prefix = ""; let sJsDoc, oDoc, fCustomFunc; function initParamsCustomFunction(aInputTypes, sReturnType) { //generate jsdoc sJsDoc = "/**\n" + "\t\t * Calculates\n" + "\t\t * @customfunction\n"; for (let i in aInputTypes) { let argName = "arg" + ((i - 0) + 1); if (aInputTypes[i].isOptional) { argName = "[" + argName + (aInputTypes[i].defaultValue ? "=" + aInputTypes[i].defaultValue : "") + "]" } sJsDoc += "\t\t * @param {" + aInputTypes[i].type + "} " + argName + " " + "Description.\n"; } sJsDoc += "\t\t * @returns {" + sReturnType + "} The sum of the numbers.\n\t\t */"; oDoc = {}; for (let i in aInputTypes) { if (!oDoc["params"]) { oDoc["params"] = []; } oDoc["params"].push({"type": aInputTypes[i].type, "name": "name", "isOptional": !!aInputTypes[i].isOptional, "description": "description_params"}); } oDoc["properties"] = []; oDoc["description"] = "all_desc"; oDoc["returnInfo"] = {"type": sReturnType, "description": "description_return"}; } function doCustomFunctionTasks(assert, aTasks, typeToArgMap, funcName, _descArgs, _callback) { //generate -> // let desc = "Custom_function_ADD_@NUMBER_@NUMBER_INPUT_NUMBER_NUMBER"; // calcCustomFunction(func, sJsDoc, oDoc, function (_desc) { // oParser = new parserFormula(prefix + 'ADD(10, 10)', 'A2', ws); // assert.ok(oParser.parse(), desc + "_" + _desc); // assert.strictEqual(oParser.calculate().getValue(), 20, desc + "_" + _desc); // }); for (let i in aTasks) { let task = aTasks[i]; let desc = "Custom_function_" + funcName + "_" +_descArgs + "_INPUT_"; let sFunc = funcName + "("; for (let j = 0; j < aTasks[i].paramsType.length; j++) { sFunc += typeToArgMap[aTasks[i].paramsType[j]]; if (j !== aTasks[i].paramsType.length - 1) { sFunc += ","; } desc += "_" + aTasks[i].paramsType[j]; } sFunc += ")"; calcCustomFunction(fCustomFunc, sJsDoc, oDoc, function (_desc) { if (_callback) { wb.asyncFormulasManager.endCallback = function () { let calculateRes = ws.getRange2("A1"); assert.strictEqual(calculateRes.getValue(), task.result, desc + "_" + _desc); _callback && _callback(); wb.asyncFormulasManager.endCallback = null; }; ws.getRange2("A1").setValue("=" + prefix + sFunc); } else { oParser = new parserFormula(prefix + sFunc, new AscCommonExcel.CCellWithFormula(ws, 1, 0), ws); assert.ok(oParser.parse(), "parse_ " + desc + "_" + _desc); let calculateRes = oParser.calculate(); if (typeof task.result === "object") { for (let i = 0; i < task.result.length; i++) { for (let j = 0; j < task.result[i].length; j++) { assert.strictEqual(calculateRes.getElementRowCol(i, j).getValue(), task.result[i][j], desc + "_" + _desc); } } } else { assert.strictEqual(calculateRes.getValue(), task.result, desc + "_" + _desc); } } }); } } function executeCustomFunction (_func, callback) { wb.dependencyFormulas.unlockRecal(); initCustomFunctionData(); let api = window["Asc"]["editor"]; let trueWb = api.wb; api.wb = {addCustomFunction: AscCommonExcel.WorkbookView.prototype.addCustomFunction, initCustomEngine: AscCommonExcel.WorkbookView.prototype.initCustomEngine}; _func(callback); if (!callback) { api.wb = trueWb; ws.getRange2("A1:Z10000").cleanAll(); } } QUnit.test("Test: \"Custom function test: base operation: number\"", function (assert) { executeCustomFunction(function () { fCustomFunc = function simpleFunc1(arg1, arg2) { return arg2; }; let typeToArgMap = {"number": 10, "stringNumber": '"1"', "string": '"test"', "bool": "TRUE", "error": "#REF!", "array": "{1,2,3}", "ref": "A100", "range": "A100:B101" }; //********** 1. @number / @number <- @number ********** initParamsCustomFunction([{type: "number"}, {type: "number"}], "number"); let aTasks = [ {paramsType: ["number"], result: "#VALUE!"}, {paramsType: [], result: "#VALUE!"}, {paramsType: ["number", "number", "number"], result: "#VALUE!"}, {paramsType: ['number', 'number'], result: 10}, {paramsType: ['number', 'stringNumber'], result: 1}, {paramsType: ['number', 'string'], result: "#VALUE!"}, {paramsType: ['number', 'bool'], result: 1}, {paramsType: ['number', 'error'], result: "#REF!"}, {paramsType: ['number', 'array'], result: "#VALUE!"}, {paramsType: ['number', 'ref'], result: 1}, {paramsType: ['number', 'range'], result: "#VALUE!"} ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "_@NUMBER_@NUMBER->number"); //ms returns number! //********** 2. @number <- @string ********** initParamsCustomFunction([{type: "number"}, {type: "number"}], "string"); aTasks = [ {paramsType: ['number', 'number'], result: "10"}, {paramsType: ['number', 'stringNumber'], result: "1"}, {paramsType: ['number', 'string'], result: "#VALUE!"}, {paramsType: ['number', 'bool'], result: "1"}, {paramsType: ['number', 'error'], result: "#REF!"}, {paramsType: ['number', 'array'], result: "#VALUE!"}, {paramsType: ['number', 'ref'], result: "1"}, {paramsType: ['number', 'range'], result: "#VALUE!"}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_@NUMBER->string !"); //********** 3. @number <- @boolean ********** initParamsCustomFunction([{type: "number"}, {type: "number"}], "boolean"); aTasks = [ {paramsType: ['number', 'number'], result: 10}, {paramsType: ['number', 'stringNumber'], result: 1}, {paramsType: ['number', 'string'], result:"#VALUE!"}, {paramsType: ['number', 'bool'], result: 1}, {paramsType: ['number', 'error'], result:"#REF!"}, {paramsType: ['number', 'array'], result:"#VALUE!"}, {paramsType: ['number', 'ref'], result: 1}, {paramsType: ['number', 'range'], result:"#VALUE!"}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_@number->boolean !"); //********** 4. @number<- @any ********** initParamsCustomFunction([{type: "number"}, {type: "number"}], "any"); aTasks = [ {paramsType: ['number', 'number'], result: 10}, {paramsType: ['number', 'stringNumber'], result: 1}, {paramsType: ['number', 'string'], result:"#VALUE!"}, {paramsType: ['number', 'bool'], result: 1}, {paramsType: ['number', 'error'], result:"#REF!"}, {paramsType: ['number', 'array'], result:"#VALUE!"}, {paramsType: ['number', 'ref'], result: 1}, {paramsType: ['number', 'range'], result:"#VALUE!"}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_number-> any !"); //********** 5. @number / @number <- @number[][] ********** initParamsCustomFunction([{type: "number"}, {type: "number"}], "number[][]"); aTasks = [ {paramsType: ['number', 'number'], result: "#VALUE!"}, {paramsType: ['number', 'stringNumber'], result: "#VALUE!"}, {paramsType: ['number', 'string'], result: "#VALUE!"}, {paramsType: ['number', 'bool'], result: "#VALUE!"}, {paramsType: ['number', 'error'], result: "#REF!"}, {paramsType: ['number', 'array'], result: "#VALUE!"}, {paramsType: ['number', 'ref'], result: "#VALUE!"}, {paramsType: ['number', 'range'], result: "#VALUE!"}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_@NUMBER->number[][] !"); //********** 6. @number[][] / @number <- @number ********** initParamsCustomFunction([{type: "number[][]"}, {type: "number"}], "number"); aTasks = [ {paramsType: ['number', 'number'], result: 10}, {paramsType: ['number', 'stringNumber'], result: 1}, {paramsType: ['number', 'string'], result: "#VALUE!"}, {paramsType: ['number', 'bool'], result: 1}, {paramsType: ['number', 'error'], result: "#REF!"}, {paramsType: ['number', 'array'], result: "#VALUE!"}, {paramsType: ['number', 'ref'], result: 1}, {paramsType: ['number', 'range'], result: "#VALUE!"} ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER[][]_@NUMBER->number !"); //**********7. @number / @number <- @string[][] ********** initParamsCustomFunction([{type: "number"}, {type: "number"}], "string[][]"); aTasks = [ {paramsType: ['number', 'number'], result: "#VALUE!"}, {paramsType: ['number', 'stringNumber'], result: "#VALUE!"}, {paramsType: ['number', 'string'], result: "#VALUE!"}, {paramsType: ['number', 'bool'], result: "#VALUE!"}, {paramsType: ['number', 'error'], result: "#REF!"}, {paramsType: ['number', 'array'], result: "#VALUE!"}, {paramsType: ['number', 'ref'], result: "#VALUE!"}, {paramsType: ['number', 'range'], result: "#VALUE!"}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_@NUMBER->string[][] !"); //********** 8. @number / @number[][]<- @any[][] ********** initParamsCustomFunction([{type: "number"}, {type: "number[][]"}], "any[][]"); aTasks = [ {paramsType: ['number', 'number'], result: [[10]]}, {paramsType: ['number', 'stringNumber'], result: [[1]]}, {paramsType: ['number', 'string'], result: "#VALUE!"}, {paramsType: ['number', 'bool'], result: [[1]]}, {paramsType: ['number', 'error'], result:"#REF!"}, {paramsType: ['number', 'array'], result: [[1]]}, {paramsType: ['number', 'ref'], result: [[1]]}, {paramsType: ['number', 'range'], result: [[1]]}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_number[][]-> any[][] !"); }); }); QUnit.test("Test: \"Custom function test: base operation: number[][]\"", function (assert) { executeCustomFunction(function () { fCustomFunc = function simpleFunc2(arg1) { return arg1; }; let typeToArgMap = {"number": 10, "stringNumber": '"1"', "string": '"test"', "bool": "TRUE", "error": "#REF!", "array": "{1,2,3}", "ref": "A100", "range": "A100:B101" }; //********** 1. @number[][] <- @number[][] ********** initParamsCustomFunction([{type: "number[][]"}], "number[][]"); let aTasks = [ {paramsType: ['number'], result: [[10]]}, {paramsType: ['stringNumber'], result: [[1]]}, {paramsType: ['string'], result: "#VALUE!"}, {paramsType: ['bool'], result: [[1]]}, {paramsType: ['error'], result: "#REF!"}, {paramsType: ['array'], result: [[1,2,3]]}, {paramsType: ['ref'], result: [[1]]}, {paramsType: ['range'], result: [[1]]}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_@NUMBER[][]->number[][] !"); //ms returns number! //********** 2. @number[][] <- @string[][] ********** initParamsCustomFunction([{type: "number[][]"}], "string[][]"); aTasks = [ {paramsType: ['number'], result: [["10"]]}, {paramsType: ['stringNumber'], result: [["1"]]}, {paramsType: ['string'], result: "#VALUE!"}, {paramsType: ['bool'], result: [["1"]]}, {paramsType: ['error'], result: "#REF!"}, {paramsType: ['array'], result: [["1","2","3"]]}, {paramsType: ['ref'], result: [["1"]]}, {paramsType: ['range'], result: [["1"]]}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_@NUMBER[][]->string[][] !"); //********** 3. @number[][] <- @number ********** initParamsCustomFunction([{type: "number[][]"}], "number"); aTasks = [ {paramsType: ['number'], result: "#VALUE!"}, {paramsType: ['stringNumber'], result: "#VALUE!"}, {paramsType: ['string'], result: "#VALUE!"}, {paramsType: ['bool'], result: "#VALUE!"}, {paramsType: ['error'], result: "#REF!"}, {paramsType: ['array'], result: "#VALUE!"}, {paramsType: ['ref'], result: "#VALUE!"}, {paramsType: ['range'], result: "#VALUE!"}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_@NUMBER[][]->number !"); //********** 4. @number[][] <- @string ********** initParamsCustomFunction([{type: "number[][]"}], "string"); aTasks = [ {paramsType: ['number'], result: "#VALUE!"}, {paramsType: ['stringNumber'], result: "#VALUE!"}, {paramsType: ['string'], result: "#VALUE!"}, {paramsType: ['bool'], result: "#VALUE!"}, {paramsType: ['error'], result: "#REF!"}, {paramsType: ['array'], result: "#VALUE!"}, {paramsType: ['ref'], result: "#VALUE!"}, {paramsType: ['range'], result: "#VALUE!"}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_@NUMBER[][]->string !"); //********** 5. @number[][]<- @any[][] ********** initParamsCustomFunction([{type: "number[][]"}], "any[][]"); aTasks = [ {paramsType: ['number'], result: [[10]]}, {paramsType: ['stringNumber'], result: [[1]]}, {paramsType: ['string'], result: "#VALUE!"}, {paramsType: ['bool'], result: [[1]]}, {paramsType: ['error'], result:"#REF!"}, {paramsType: ['array'], result: [[1]]}, {paramsType: ['ref'], result: [[1]]}, {paramsType: ['range'], result: [[1]]}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_number[][]-> any[][] !"); }); }); QUnit.test("Test: \"Custom function test: base operation: string\"", function (assert) { executeCustomFunction(function () { fCustomFunc = function simpleFunc3(arg1) { return arg1; }; let typeToArgMap = {"number": 10, "stringNumber": '"1"', "string": '"test"', "bool": "TRUE", "error": "#REF!", "array": "{1,2,3}", "ref": "A100", "range": "A100:B101" }; //********** 1. @string -> @number ********** initParamsCustomFunction([{type: "string"}], "number"); let aTasks = [ {paramsType: ['number'], result: "10"}, {paramsType: ['stringNumber'], result: "1"}, {paramsType: ['string'], result: "test"}, {paramsType: ['bool'], result: "TRUE"}, {paramsType: ['error'], result: "#REF!"}, {paramsType: ['array'], result: "#VALUE!"}, {paramsType: ['ref'], result: "1"}, {paramsType: ['range'], result: "#VALUE!"} ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "_@NUMBER@STRING->number"); //********** 2. @string -> @string ********** initParamsCustomFunction([{type: "string"}], "string"); aTasks = [ {paramsType: ['number'], result: "10"}, {paramsType: ['stringNumber'], result: "1"}, {paramsType: ['string'], result: "test"}, {paramsType: ['bool'], result: "TRUE"}, {paramsType: ['error'], result: "#REF!"}, {paramsType: ['array'], result: "#VALUE!"}, {paramsType: ['ref'], result: "1"}, {paramsType: ['range'], result: "#VALUE!"} ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "_@NUMBER@STRING->STRING"); //********** 3. @string<- @boolean ********** initParamsCustomFunction([{type: "string"}], "boolean"); aTasks = [ {paramsType: ['number'], result: "10"}, {paramsType: ['stringNumber'], result: "1"}, {paramsType: ['string'], result: "test"}, {paramsType: ['bool'], result: "TRUE"}, {paramsType: ['error'], result:"#REF!"}, {paramsType: ['array'], result:"#VALUE!"}, {paramsType: ['ref'], result: "1"}, {paramsType: ['range'], result:"#VALUE!"}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_@string->boolean !"); //********** 7. @string<- @boolean[][] ********** initParamsCustomFunction([{type: "string"}], "boolean[][]"); aTasks = [ {paramsType: ['number'], result:"#VALUE!"}, {paramsType: ['stringNumber'], result:"#VALUE!"}, {paramsType: ['string'], result:"#VALUE!"}, {paramsType: ['bool'], result:"#VALUE!"}, {paramsType: ['error'], result:"#REF!"}, {paramsType: ['array'], result:"#VALUE!"}, {paramsType: ['ref'], result:"#VALUE!"}, {paramsType: ['range'], result:"#VALUE!"} ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_@string->boolean[][] !"); }); }); QUnit.test("Test: \"Custom function test: base operation: string[][]\"", function (assert) { executeCustomFunction(function () { fCustomFunc = function simpleFunc4(arg1) { return arg1; }; let typeToArgMap = {"number": 10, "stringNumber": '"1"', "string": '"test"', "bool": "TRUE", "error": "#REF!", "array": "{1,2,3}", "ref": "A100", "range": "A100:B101" }; //********** 1. @string[][] <- @string[][] ********** initParamsCustomFunction([{type: "string[][]"}], "string[][]"); let aTasks = [ {paramsType: ['number'], result: [["10"]]}, {paramsType: ['stringNumber'], result: [["1"]]}, {paramsType: ['string'], result: [["test"]]}, {paramsType: ['bool'], result: [["TRUE"]]}, {paramsType: ['error'], result: "#REF!"}, {paramsType: ['array'], result: [["1"]]}, {paramsType: ['ref'], result: [["1"]]}, {paramsType: ['range'], result: [["1"]]}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_@STRING[][]->string[][] !"); //********** 6. @string[][]<- @boolean ********** initParamsCustomFunction([{type: "string[][]"}], "boolean"); aTasks = [ {paramsType: ['number'], result:"#VALUE!"}, {paramsType: ['stringNumber'], result:"#VALUE!"}, {paramsType: ['string'], result:"#VALUE!"}, {paramsType: ['bool'], result:"#VALUE!"}, {paramsType: ['error'], result:"#REF!"}, {paramsType: ['array'], result:"#VALUE!"}, {paramsType: ['ref'], result:"#VALUE!"}, {paramsType: ['range'], result:"#VALUE!"}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_@string[][]->boolean !"); //********** 8. @string[][]<- @boolean[][] ********** initParamsCustomFunction([{type: "string[][]"}], "boolean[][]"); aTasks = [ {paramsType: ['number'], result: [["10"]]}, {paramsType: ['stringNumber'], result: [["1"]]}, {paramsType: ['string'], result: [["test"]]}, {paramsType: ['bool'], result: [["TRUE"]]}, {paramsType: ['error'], result:"#REF!"}, {paramsType: ['array'], result: [["1"]]}, {paramsType: ['ref'], result: [["1"]]}, {paramsType: ['range'], result: [["1"]]} ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_@string[][]->boolean[][] !"); //********** 9. @string[][]<- @any[][] ********** initParamsCustomFunction([{type: "string[][]"}], "any[][]"); aTasks = [ {paramsType: ['number'], result: [["10"]]}, {paramsType: ['stringNumber'], result: [["1"]]}, {paramsType: ['string'], result: [["test"]]}, {paramsType: ['bool'], result: [["TRUE"]]}, {paramsType: ['error'], result:"#REF!"}, {paramsType: ['array'], result: [["1"]]}, {paramsType: ['ref'], result: [["1"]]}, {paramsType: ['range'], result: [["1"]]}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_string[][]-> any[][] !"); }); }); QUnit.test("Test: \"Custom function test: base operation: boolean\"", function (assert) { executeCustomFunction(function () { fCustomFunc = function simpleFunc5(arg1) { return arg1; }; let typeToArgMap = {"number": 10, "stringNumber": '"1"', "string": '"test"', "bool": "TRUE", "error": "#REF!", "array": "{1,2,3}", "ref": "A100", "range": "A100:B101" }; //********** 1. @boolean <- @number ********** initParamsCustomFunction([{type: "boolean"}], "number"); let aTasks = [ {paramsType: ['number'], result: "TRUE"}, {paramsType: ['stringNumber'], result: "#VALUE!"}, {paramsType: ['string'], result: "#VALUE!"}, {paramsType: ['bool'], result: "TRUE"}, {paramsType: ['error'], result: "#REF!"}, {paramsType: ['array'], result: "#VALUE!"}, {paramsType: ['ref'], result: "TRUE"}, {paramsType: ['range'], result: "#VALUE!"}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_@BOOLEAN->NUMBER !"); //********** 2.@boolean <- @boolean ********** initParamsCustomFunction([{type: "boolean"}], "boolean"); aTasks = [ {paramsType: ['number'], result: "TRUE"}, {paramsType: ['stringNumber'], result: "#VALUE!"}, {paramsType: ['string'], result: "#VALUE!"}, {paramsType: ['bool'], result: "TRUE"}, {paramsType: ['error'], result: "#REF!"}, {paramsType: ['array'], result: "#VALUE!"}, {paramsType: ['ref'], result: "TRUE"}, {paramsType: ['range'], result: "#VALUE!"} ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_@BOOLEAN->boolean !"); //********** 3. @boolean<- @boolean[][] ********** initParamsCustomFunction([{type: "boolean"}], "boolean[][]"); aTasks = [ {paramsType: ['number'], result:"#VALUE!"}, {paramsType: ['stringNumber'], result:"#VALUE!"}, {paramsType: ['string'], result:"#VALUE!"}, {paramsType: ['bool'], result:"#VALUE!"}, {paramsType: ['error'], result:"#REF!"}, {paramsType: ['array'], result:"#VALUE!"}, {paramsType: ['ref'], result:"#VALUE!"}, {paramsType: ['range'], result:"#VALUE!"}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_@BOOLEAN->boolean[][] !"); //********** 4. @boolean<- @any ********** initParamsCustomFunction([{type: "boolean"}], "any"); aTasks = [ {paramsType: ['number'], result: "TRUE"}, {paramsType: ['stringNumber'], result:"#VALUE!"}, {paramsType: ['string'], result:"#VALUE!"}, {paramsType: ['bool'], result: "TRUE"}, {paramsType: ['error'], result:"#REF!"}, {paramsType: ['array'], result:"#VALUE!"}, {paramsType: ['ref'], result: "TRUE"}, {paramsType: ['range'], result:"#VALUE!"}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_boolean-> any !"); }); }); QUnit.test("Test: \"Custom function test: base operation: boolean[][]\"", function (assert) { executeCustomFunction(function () { fCustomFunc = function simpleFunc6(arg1) { return arg1; }; let typeToArgMap = {"number": 10, "stringNumber": '"1"', "string": '"test"', "bool": "TRUE", "error": "#REF!", "array": "{1,2,3}", "ref": "A100", "range": "A100:B101" }; //********** 1.@boolean[][] <- @boolean[][] ********** initParamsCustomFunction([{type: "boolean[][]"}], "boolean[][]"); let aTasks = [ {paramsType: ['number'], result: [["TRUE"]]}, {paramsType: ['stringNumber'], result:"#VALUE!"}, {paramsType: ['string'], result:"#VALUE!"}, {paramsType: ['bool'], result: [["TRUE"]]}, {paramsType: ['error'], result:"#REF!"}, {paramsType: ['array'], result: [["TRUE"]]}, {paramsType: ['ref'], result: [["TRUE"]]}, {paramsType: ['range'], result: [["TRUE"]]} ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_@BOOLEAN[][]->boolean[][] !"); //********** 2. @boolean[][]<- @boolean ********** initParamsCustomFunction([{type: "boolean[][]"}], "boolean"); aTasks = [ {paramsType: ['number'], result:"#VALUE!"}, {paramsType: ['stringNumber'], result:"#VALUE!"}, {paramsType: ['string'], result:"#VALUE!"}, {paramsType: ['bool'], result:"#VALUE!"}, {paramsType: ['error'], result:"#REF!"}, {paramsType: ['array'], result:"#VALUE!"}, {paramsType: ['ref'], result:"#VALUE!"}, {paramsType: ['range'], result:"#VALUE!"}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_@BOOLEAN[][]->boolean !"); //********** 6. @boolean[][]<- @number[][] ********** initParamsCustomFunction([{type: "boolean[][]"}], "number[][]"); aTasks = [ {paramsType: ['number'], result: [["TRUE"]]}, {paramsType: ['stringNumber'], result:"#VALUE!"}, {paramsType: ['string'], result:"#VALUE!"}, {paramsType: ['bool'], result: [["TRUE"]]}, {paramsType: ['error'], result:"#REF!"}, {paramsType: ['array'], result: [["TRUE"]]}, {paramsType: ['ref'], result: [["TRUE"]]}, {paramsType: ['range'], result: [["TRUE"]]} ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_@BOOLEAN[][]->number[][] !"); //********** 7. @number / @boolean[][]<- @string[][] ********** initParamsCustomFunction([{type: "boolean[][]"}], "string[][]"); aTasks = [ {paramsType: ['number'], result: [["TRUE"]]}, {paramsType: ['stringNumber'], result:"#VALUE!"}, {paramsType: ['string'], result:"#VALUE!"}, {paramsType: ['bool'], result: [["TRUE"]]}, {paramsType: ['error'], result:"#REF!"}, {paramsType: ['array'], result: [["TRUE"]]}, {paramsType: ['ref'], result: [["TRUE"]]}, {paramsType: ['range'], result: [["TRUE"]]} ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_@BOOLEAN[][]->string[][] !"); //********** 8. @boolean[][]<- @string[][] ********** initParamsCustomFunction([{type: "boolean[][]"}], "string[][]"); aTasks = [ {paramsType: ['number'], result: [["TRUE"]]}, {paramsType: ['stringNumber'], result:"#VALUE!"}, {paramsType: ['string'], result:"#VALUE!"}, {paramsType: ['bool'], result: [["TRUE"]]}, {paramsType: ['error'], result:"#REF!"}, {paramsType: ['array'], result: [["TRUE"]]}, {paramsType: ['ref'], result: [["TRUE"]]}, {paramsType: ['range'], result: [["TRUE"]]}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_@boolean[][]->string[][] !"); //********** 10. @boolean[][]<- @any[][] ********** initParamsCustomFunction([{type: "boolean[][]"}], "any[][]"); aTasks = [ {paramsType: ['number'], result: [["TRUE"]]}, {paramsType: ['stringNumber'], result:"#VALUE!"}, {paramsType: ['string'], result:"#VALUE!"}, {paramsType: ['bool'], result: [["TRUE"]]}, {paramsType: ['error'], result:"#REF!"}, {paramsType: ['array'], result: [["TRUE"]]}, {paramsType: ['ref'], result: [["TRUE"]]}, {paramsType: ['range'], result: [["TRUE"]]}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_boolean[][]-> any[][] !"); }); }); QUnit.test("Test: \"Custom function test: base operation: any\"", function (assert) { executeCustomFunction(function () { fCustomFunc = function simpleFunc7(arg1) { return arg1; }; let typeToArgMap = {"number": 10, "stringNumber": '"1"', "string": '"test"', "bool": "TRUE", "error": "#REF!", "array": "{1,2,3}", "ref": "A100", "range": "A100:B101" }; //********** 1. @any<- @number ********** initParamsCustomFunction([{type: "any"}], "number"); let aTasks = [ {paramsType: ['number'], result: 10}, {paramsType: ['stringNumber'], result: "1"}, {paramsType: ['string'], result: "test"}, {paramsType: ['bool'], result: "TRUE"}, {paramsType: ['error'], result:"#REF!"}, {paramsType: ['array'], result:"#VALUE!"}, {paramsType: ['ref'], result: 1}, {paramsType: ['range'], result:"#VALUE!"}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_any-> number !"); //********** 2. @any<- @any ********** initParamsCustomFunction([{type: "any"}], "any"); aTasks = [ {paramsType: ['number'], result: 10}, {paramsType: ['stringNumber'], result: "1"}, {paramsType: ['string'], result: "test"}, {paramsType: ['bool'], result: "TRUE"}, {paramsType: ['error'], result:"#REF!"}, {paramsType: ['array'], result:"#VALUE!"}, {paramsType: ['ref'], result: 1}, {paramsType: ['range'], result:"#VALUE!"}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_any-> any !"); //********** 3. @any<- @string ********** initParamsCustomFunction([{type: "any"}], "string"); aTasks = [ {paramsType: ['number'], result: "10"},//ms returns number {paramsType: ['stringNumber'], result: "1"}, {paramsType: ['string'], result: "test"}, {paramsType: ['bool'], result: "TRUE"}, {paramsType: ['error'], result:"#REF!"}, {paramsType: ['array'], result:"#VALUE!"}, {paramsType: ['ref'], result: "1"},//ms returns number {paramsType: ['range'], result:"#VALUE!"}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_any-> string !"); //********** 4. @any<- @boolean ********** initParamsCustomFunction([{type: "any"}], "boolean"); aTasks = [ {paramsType: ['number'], result: 10}, {paramsType: ['stringNumber'], result: "1"}, {paramsType: ['string'], result: "test"}, {paramsType: ['bool'], result: "TRUE"}, {paramsType: ['error'], result:"#REF!"}, {paramsType: ['array'], result:"#VALUE!"}, {paramsType: ['ref'], result: 1}, {paramsType: ['range'], result:"#VALUE!"}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_any-> boolean !"); //********** 5. @any<- @boolean ********** initParamsCustomFunction([{type: "any"}], "boolean[][]"); aTasks = [ {paramsType: ['number'], result:"#VALUE!"}, {paramsType: ['stringNumber'], result:"#VALUE!"}, {paramsType: ['string'], result:"#VALUE!"}, {paramsType: ['bool'], result:"#VALUE!"}, {paramsType: ['error'], result:"#REF!"}, {paramsType: ['array'], result:"#VALUE!"}, {paramsType: ['ref'], result:"#VALUE!"}, {paramsType: ['range'], result:"#VALUE!"}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_any-> boolean[][] !"); }); }); QUnit.test("Test: \"Custom function test: base operation: any[][]\"", function (assert) { executeCustomFunction(function () { fCustomFunc = function simpleFunc8(arg1) { return arg1; }; let typeToArgMap = {"number": 10, "stringNumber": '"1"', "string": '"test"', "bool": "TRUE", "error": "#REF!", "array": "{1,2,3}", "ref": "A100", "range": "A100:B101" }; //********** 1. @any[][]<- @number[][] ********** initParamsCustomFunction([{type: "any[][]"}], "number[][]"); let aTasks = [ {paramsType: ['number'], result: [[10]]}, {paramsType: ['stringNumber'], result: [["1"]]}, {paramsType: ['string'], result: [["test"]]}, {paramsType: ['bool'], result: [["TRUE"]]}, {paramsType: ['error'], result:"#REF!"}, {paramsType: ['array'], result: [[1]]}, {paramsType: ['ref'], result: [[1]]}, {paramsType: ['range'], result: [[1]]}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_any[][]-> number[][] !"); //********** 2. @any[][]<- @string[][] ********** initParamsCustomFunction([{type: "any[][]"}], "string[][]"); aTasks = [ {paramsType: ['number'], result: [["10"]]}, {paramsType: ['stringNumber'], result: [["1"]]}, {paramsType: ['string'], result: [["test"]]}, {paramsType: ['bool'], result: [["TRUE"]]}, {paramsType: ['error'], result:"#REF!"}, {paramsType: ['array'], result: [["1"]]}, {paramsType: ['ref'], result: [["1"]]}, {paramsType: ['range'], result: [["1"]]}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_any[][]-> string[][] !"); //********** 3. @any[][]<- @boolean[][] ********** initParamsCustomFunction([{type: "any[][]"}], "boolean[][]"); aTasks = [ {paramsType: ['number'], result: [[10]]}, {paramsType: ['stringNumber'], result: [["1"]]}, {paramsType: ['string'], result: [["test"]]}, {paramsType: ['bool'], result: [["TRUE"]]}, {paramsType: ['error'], result:"#REF!"}, {paramsType: ['array'], result: [[1]]}, {paramsType: ['ref'], result: [[1]]}, {paramsType: ['range'], result: [[1]]}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_any[][]-> boolean[][] !"); //********** 4. @any[][]<- @any[][] ********** initParamsCustomFunction([{type: "any[][]"}], "any[][]"); aTasks = [ {paramsType: ['number'], result: [[10]]}, {paramsType: ['stringNumber'], result: [["1"]]}, {paramsType: ['string'], result: [["test"]]}, {paramsType: ['bool'], result: [["TRUE"]]}, {paramsType: ['error'], result:"#REF!"}, {paramsType: ['array'], result: [[1]]}, {paramsType: ['ref'], result: [[1]]}, {paramsType: ['range'], result: [[1]]}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! _@NUMBER_any[][]-> any[][] !"); }); }); QUnit.test("Test: \"Custom function test: other\"", function (assert) { executeCustomFunction(function () { let typeToArgMap = {"number": 10, "stringNumber": '"1"', "string": '"test"', "bool": "TRUE", "error": "#REF!", "array": "{1,2,3}", "ref": "A100", "range": "A100:B101" }; //empty function fCustomFunc = function simpleFunc9() { }; initParamsCustomFunction([], "number"); let aTasks = [ {paramsType: ['number'], result:"#VALUE!"}, {paramsType: ['stringNumber'], result:"#VALUE!"}, {paramsType: ['string'], result:"#VALUE!"}, {paramsType: ['bool'], result:"#VALUE!"}, {paramsType: ['error'], result:"#VALUE!"}, {paramsType: ['array'], result:"#VALUE!"}, {paramsType: ['ref'], result:"#VALUE!"}, {paramsType: ['range'], result:"#VALUE!"} ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! empty function !"); //return null fCustomFunc = function simpleFunc10() { return null; }; initParamsCustomFunction([], "number"); aTasks = [ {paramsType: ['number'], result:"#VALUE!"}, {paramsType: ['stringNumber'], result:"#VALUE!"}, {paramsType: ['string'], result:"#VALUE!"}, {paramsType: ['bool'], result:"#VALUE!"}, {paramsType: ['error'], result:"#VALUE!"}, {paramsType: ['array'], result:"#VALUE!"}, {paramsType: ['ref'], result:"#VALUE!"}, {paramsType: ['range'], result:"#VALUE!"} ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! return null !"); //return undefined fCustomFunc = function simpleFunc11() { return undefined; }; initParamsCustomFunction([], "number"); aTasks = [ {paramsType: ['number'], result:"#VALUE!"}, {paramsType: ['stringNumber'], result:"#VALUE!"}, {paramsType: ['string'], result:"#VALUE!"}, {paramsType: ['bool'], result:"#VALUE!"}, {paramsType: ['error'], result:"#VALUE!"}, {paramsType: ['array'], result:"#VALUE!"}, {paramsType: ['ref'], result:"#VALUE!"}, {paramsType: ['range'], result:"#VALUE!"} ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! return undefined !"); //return NaN fCustomFunc = function simpleFunc12() { return NaN; }; initParamsCustomFunction([], "number"); aTasks = [ {paramsType: ['number'], result:"#VALUE!"}, {paramsType: ['stringNumber'], result:"#VALUE!"}, {paramsType: ['string'], result:"#VALUE!"}, {paramsType: ['bool'], result:"#VALUE!"}, {paramsType: ['error'], result:"#VALUE!"}, {paramsType: ['array'], result:"#VALUE!"}, {paramsType: ['ref'], result:"#VALUE!"}, {paramsType: ['range'], result:"#VALUE!"} ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! return NaN !"); fCustomFunc = function simpleFunc13(arg1, arg2) { return arg2; }; initParamsCustomFunction([], "number"); aTasks = [ {paramsType: ['number', 'number'], result: 10}, {paramsType: ['number', 'stringNumber'], result: "1"}, {paramsType: ['number', 'string'], result: "test"}, {paramsType: ['number', 'bool'], result: "TRUE"}, {paramsType: ['number', 'error'], result: "#REF!"}, {paramsType: ['number', 'array'], result: "#VALUE!"}, {paramsType: ['number', 'ref'], result: 1}, {paramsType: ['number', 'range'], result: "#VALUE!"}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! call function without args !"); initParamsCustomFunction([{type: "any"},{type: "any"},{type: "any"}], "number"); aTasks = [ {paramsType: ['number', 'number'], result: 10}, {paramsType: ['number', 'stringNumber'], result: "1"}, {paramsType: ['number', 'string'], result: "test"}, {paramsType: ['number', 'bool'], result: "TRUE"}, {paramsType: ['number', 'error'], result: "#REF!"}, {paramsType: ['number', 'array'], result: "#VALUE!"}, {paramsType: ['number', 'ref'], result: 1}, {paramsType: ['number', 'range'], result: "#VALUE!"}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! init args params count more then function contain!"); fCustomFunc = function simpleFunc14(arg1, arg2, arg3) { return arg2; }; initParamsCustomFunction([{type: "any"},{type: "any"},{type: "any"}], "number"); aTasks = [ {paramsType: ['number'], result:"#VALUE!"}, {paramsType: ['stringNumber'], result:"#VALUE!"}, {paramsType: ['string'], result:"#VALUE!"}, {paramsType: ['bool'], result:"#VALUE!"}, {paramsType: ['error'], result:"#VALUE!"}, {paramsType: ['array'], result:"#VALUE!"}, {paramsType: ['ref'], result:"#VALUE!"}, {paramsType: ['range'], result:"#VALUE!"} ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! call function less then function arg count !"); //isOptional initParamsCustomFunction([{type: "any"},{type: "any"},{type: "any", isOptional: true}], "number"); aTasks = [ {paramsType: ['number', 'number'], result: 10}, {paramsType: ['number', 'stringNumber'], result: "1"}, {paramsType: ['number', 'string'], result: "test"}, {paramsType: ['number', 'bool'], result: "TRUE"}, {paramsType: ['number', 'error'], result: "#REF!"}, {paramsType: ['number', 'array'], result: "#VALUE!"}, {paramsType: ['number', 'ref'], result: 1}, {paramsType: ['number', 'range'], result: "#VALUE!"}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! optional third param !"); //defaultvalue //ms ignore defaultValue option, while skip fCustomFunc = function simpleFunc15(arg1, arg2, arg3) { return arg3; }; initParamsCustomFunction([{type: "any"},{type: "any"},{type: "any", defaultValue: 123, isOptional: true}], "number"); aTasks = [ {paramsType: ['number', 'number'], result: "123"} ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "! defaultvalue !"); }); }); QUnit.test("Test: \"Custom function test: number+number->number\"", function (assert) { executeCustomFunction(function () { fCustomFunc = function add1(arg1, arg2) { return arg1 + arg2; }; //********** 1. @number / @number <- @number ********** initParamsCustomFunction([{type: "number"}, {type: "number"}], "number"); let typeToArgMap = {"number": 10, "stringNumber": '"1"', "string": '"test"', "bool": "TRUE", "error": "#REF!", "array": "{1,2,3}", "ref": "A100", "range": "A100:B101" }; let aTasks = [ {paramsType: ["number", "number"], result: 20}, {paramsType: ["number", "stringNumber"], result: 11}, {paramsType: ["number", "string"], result: "#VALUE!"}, {paramsType: ["number", "bool"], result: 11}, {paramsType: ["number", "error"], result: "#REF!"}, {paramsType: ["number", "array"], result: "#VALUE!"}, {paramsType: ["number", "ref"], result: 11}, {paramsType: ["number", "range"], result: "#VALUE!"}, {paramsType: ["string", "string"], result: "#VALUE!"}, {paramsType: ["string", "stringNumber"], result: "#VALUE!"}, {paramsType: ["string", "bool"], result: "#VALUE!"}, {paramsType: ["string", "error"], result: "#REF!"}, {paramsType: ["string", "array"], result: "#VALUE!"}, {paramsType: ["string", "ref"], result: "#VALUE!"}, {paramsType: ["string", "range"], result: "#VALUE!"}, {paramsType: ["bool", "bool"], result: 2}, {paramsType: ["bool", "stringNumber"], result: 2}, {paramsType: ["bool", "error"], result: "#REF!"}, {paramsType: ["bool", "array"], result: "#VALUE!"}, {paramsType: ["bool", "ref"], result: 2}, {paramsType: ["bool", "range"], result: "#VALUE!"}, {paramsType: ["error", "stringNumber"], result: "#REF!"}, {paramsType: ["error", "error"], result: "#REF!"}, {paramsType: ["error", "array"], result: "#REF!"}, {paramsType: ["error", "ref"], result: "#REF!"}, {paramsType: ["error", "range"], result: "#REF!"}, {paramsType: ["array", "stringNumber"], result: "#VALUE!"}, {paramsType: ["array", "array"], result: "#VALUE!"}, {paramsType: ["array", "ref"], result: "#VALUE!"}, {paramsType: ["array", "range"], result: "#VALUE!"}, {paramsType: ["ref", "stringNumber"], result: 2}, {paramsType: ["ref", "ref"], result: 2}, {paramsType: ["ref", "range"], result: "#VALUE!"}, {paramsType: ["range", "stringNumber"], result: "#VALUE!"}, {paramsType: ["range", "range"], result: "#VALUE!"} ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "_@NUMBER_@NUMBER"); }); }); QUnit.test("Test: \"Custom function test: string+number->number\"", function (assert) { executeCustomFunction(function () { fCustomFunc = function add2(arg1, arg2) { return arg1 + arg2; }; let typeToArgMap = {"number": 10, "stringNumber": '"1"', "string": '"test"', "bool": "TRUE", "error": "#REF!", "array": "{1,2,3}", "ref": "A100", "range": "A100:B101" }; //********** 2. @string / @number <- @number ********** initParamsCustomFunction([{type: "string"}, {type: "number"}], "number"); let aTasks = [ {paramsType: ['number', 'number'], result: "1010"}, {paramsType: ['number', 'stringNumber'], result: "101"}, {paramsType: ['number', 'string'], result: "#VALUE!"}, {paramsType: ['number', 'bool'], result: "101"}, {paramsType: ['number', 'error'], result: "#REF!"}, {paramsType: ['number', 'array'], result: "#VALUE!"}, {paramsType: ['number', 'ref'], result: "101"}, {paramsType: ['number', 'range'], result: "#VALUE!"}, {paramsType: ['string', 'number'], result: "test10"}, {paramsType: ['string', 'string'], result: "#VALUE!"}, {paramsType: ['string', 'stringNumber'], result: "test1"}, {paramsType: ['string', 'bool'], result: "test1"}, {paramsType: ['string', 'error'], result: "#REF!"}, {paramsType: ['string', 'array'], result: "#VALUE!"}, {paramsType: ['string', 'ref'], result: "test1"}, {paramsType: ['string', 'range'], result: "#VALUE!"}, {paramsType: ['bool', 'number'], result: "TRUE10"}, {paramsType: ['bool', 'string'], result: "#VALUE!"}, {paramsType: ['bool', 'bool'], result: "TRUE1"}, {paramsType: ['bool', 'stringNumber'], result: "TRUE1"}, {paramsType: ['bool', 'error'], result: "#REF!"}, {paramsType: ['bool', 'array'], result: "#VALUE!"}, {paramsType: ['bool', 'ref'], result: "TRUE1"}, {paramsType: ['bool', 'range'], result: "#VALUE!"}, {paramsType: ['error', 'number'], result: "#REF!"}, {paramsType: ['error', 'string'], result: "#REF!"}, {paramsType: ['error', 'bool'], result: "#REF!"}, {paramsType: ['error', 'stringNumber'], result: "#REF!"}, {paramsType: ['error', 'error'], result: "#REF!"}, {paramsType: ['error', 'array'], result: "#REF!"}, {paramsType: ['error', 'ref'], result: "#REF!"}, {paramsType: ['error', 'range'], result: "#REF!"}, {paramsType: ['array', 'number'], result: "#VALUE!"}, {paramsType: ['array', 'string'], result: "#VALUE!"}, {paramsType: ['array', 'bool'], result: "#VALUE!"}, {paramsType: ['array', 'stringNumber'], result: "#VALUE!"}, {paramsType: ['array', 'error'], result: "#REF!"}, {paramsType: ['array', 'array'], result: "#VALUE!"}, {paramsType: ['array', 'ref'], result: "#VALUE!"}, {paramsType: ['array', 'range'], result: "#VALUE!"}, {paramsType: ['ref', 'number'], result: "110"}, {paramsType: ['ref', 'string'], result: "#VALUE!"}, {paramsType: ['ref', 'bool'], result: "11"}, {paramsType: ['ref', 'stringNumber'], result: "11"}, {paramsType: ['ref', 'error'], result: "#REF!"}, {paramsType: ['ref', 'array'], result: "#VALUE!"}, {paramsType: ['ref', 'ref'], result: "11"}, {paramsType: ['ref', 'range'], result: "#VALUE!"}, {paramsType: ['range', 'number'], result: "#VALUE!"}, {paramsType: ['range', 'string'], result: "#VALUE!"}, {paramsType: ['range', 'bool'], result: "#VALUE!"}, {paramsType: ['range', 'stringNumber'], result: "#VALUE!"}, {paramsType: ['range', 'error'], result: "#REF!"}, {paramsType: ['range', 'array'], result: "#VALUE!"}, {paramsType: ['range', 'ref'], result: "#VALUE!"}, {paramsType: ['range', 'range'], result: "#VALUE!"}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "_@STRING_@NUMBER"); }); }); QUnit.test("Test: \"Custom function test: string+string->number\"", function (assert) { executeCustomFunction(function () { fCustomFunc = function add3(arg1, arg2) { return arg1 + arg2; }; let typeToArgMap = {"number": 10, "stringNumber": '"1"', "string": '"test"', "bool": "TRUE", "error": "#REF!", "array": "{1,2,3}", "ref": "A100", "range": "A100:B101" }; //********** 3. @string / @string <- @number ********** initParamsCustomFunction([{type: "string"}, {type: "string"}], "number"); let aTasks = [ {paramsType: ['number', 'number'], result: "1010"}, {paramsType: ['number', 'stringNumber'], result: "101"}, {paramsType: ['number', 'string'], result: "10test"}, {paramsType: ['number', 'bool'], result: "10TRUE"}, {paramsType: ['number', 'error'], result: "#REF!"}, {paramsType: ['number', 'array'], result: "#VALUE!"}, {paramsType: ['number', 'ref'], result: "101"}, {paramsType: ['number', 'range'], result: "#VALUE!"}, {paramsType: ['string', 'number'], result: "test10"}, {paramsType: ['string', 'string'], result: "testtest"}, {paramsType: ['string', 'stringNumber'], result: "test1"}, {paramsType: ['string', 'bool'], result: "testTRUE"}, {paramsType: ['string', 'error'], result: "#REF!"}, {paramsType: ['string', 'array'], result: "#VALUE!"}, {paramsType: ['string', 'ref'], result: "test1"}, {paramsType: ['string', 'range'], result: "#VALUE!"}, {paramsType: ['bool', 'number'], result: "TRUE10"}, {paramsType: ['bool', 'string'], result: "TRUEtest"}, {paramsType: ['bool', 'bool'], result: "TRUETRUE"}, {paramsType: ['bool', 'stringNumber'], result: "TRUE1"}, {paramsType: ['bool', 'error'], result: "#REF!"}, {paramsType: ['bool', 'array'], result: "#VALUE!"}, {paramsType: ['bool', 'ref'], result: "TRUE1"}, {paramsType: ['bool', 'range'], result: "#VALUE!"}, {paramsType: ['error', 'number'], result: "#REF!"}, {paramsType: ['error', 'string'], result: "#REF!"}, {paramsType: ['error', 'bool'], result: "#REF!"}, {paramsType: ['error', 'stringNumber'], result: "#REF!"}, {paramsType: ['error', 'error'], result: "#REF!"}, {paramsType: ['error', 'array'], result: "#REF!"}, {paramsType: ['error', 'ref'], result: "#REF!"}, {paramsType: ['error', 'range'], result: "#REF!"}, {paramsType: ['array', 'number'], result: "#VALUE!"}, {paramsType: ['array', 'string'], result: "#VALUE!"}, {paramsType: ['array', 'bool'], result: "#VALUE!"}, {paramsType: ['array', 'stringNumber'], result: "#VALUE!"}, {paramsType: ['array', 'error'], result: "#REF!"}, {paramsType: ['array', 'array'], result: "#VALUE!"}, {paramsType: ['array', 'ref'], result: "#VALUE!"}, {paramsType: ['array', 'range'], result: "#VALUE!"}, {paramsType: ['ref', 'number'], result: "110"}, {paramsType: ['ref', 'string'], result: "1test"}, {paramsType: ['ref', 'bool'], result: "1TRUE"}, {paramsType: ['ref', 'stringNumber'], result: "11"}, {paramsType: ['ref', 'error'], result: "#REF!"}, {paramsType: ['ref', 'array'], result: "#VALUE!"}, {paramsType: ['ref', 'ref'], result: "11"}, {paramsType: ['ref', 'range'], result: "#VALUE!"}, {paramsType: ['range', 'number'], result: "#VALUE!"}, {paramsType: ['range', 'string'], result: "#VALUE!"}, {paramsType: ['range', 'bool'], result: "#VALUE!"}, {paramsType: ['range', 'stringNumber'], result: "#VALUE!"}, {paramsType: ['range', 'error'], result: "#REF!"}, {paramsType: ['range', 'array'], result: "#VALUE!"}, {paramsType: ['range', 'ref'], result: "#VALUE!"}, {paramsType: ['range', 'range'], result: "#VALUE!"}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "_@STRING_@STRING"); }); }); QUnit.test("Test: \"Custom function test: string+string->string\"", function (assert) { executeCustomFunction(function () { fCustomFunc = function add(arg1, arg2) { return arg1 + arg2; }; let typeToArgMap = {"number": 10, "stringNumber": '"1"', "string": '"test"', "bool": "TRUE", "error": "#REF!", "array": "{1,2,3}", "ref": "A100", "range": "A100:B101" }; //********** 4. @string / @string <- @string ********** initParamsCustomFunction([{type: "string"}, {type: "string"}], "string"); let aTasks = [ {paramsType: ['number', 'number'], result: "1010"}, {paramsType: ['number', 'stringNumber'], result: "101"}, {paramsType: ['number', 'string'], result: "10test"}, {paramsType: ['number', 'bool'], result: "10TRUE"}, {paramsType: ['number', 'error'], result: "#REF!"}, {paramsType: ['number', 'array'], result: "#VALUE!"}, {paramsType: ['number', 'ref'], result: "101"}, {paramsType: ['number', 'range'], result: "#VALUE!"}, {paramsType: ['string', 'number'], result: "test10"}, {paramsType: ['string', 'string'], result: "testtest"}, {paramsType: ['string', 'stringNumber'], result: "test1"}, {paramsType: ['string', 'bool'], result: "testTRUE"}, {paramsType: ['string', 'error'], result: "#REF!"}, {paramsType: ['string', 'array'], result: "#VALUE!"}, {paramsType: ['string', 'ref'], result: "test1"}, {paramsType: ['string', 'range'], result: "#VALUE!"}, {paramsType: ['bool', 'number'], result: "TRUE10"}, {paramsType: ['bool', 'string'], result: "TRUEtest"}, {paramsType: ['bool', 'bool'], result: "TRUETRUE"}, {paramsType: ['bool', 'stringNumber'], result: "TRUE1"}, {paramsType: ['bool', 'error'], result: "#REF!"}, {paramsType: ['bool', 'array'], result: "#VALUE!"}, {paramsType: ['bool', 'ref'], result: "TRUE1"}, {paramsType: ['bool', 'range'], result: "#VALUE!"}, {paramsType: ['error', 'number'], result: "#REF!"}, {paramsType: ['error', 'string'], result: "#REF!"}, {paramsType: ['error', 'bool'], result: "#REF!"}, {paramsType: ['error', 'stringNumber'], result: "#REF!"}, {paramsType: ['error', 'error'], result: "#REF!"}, {paramsType: ['error', 'array'], result: "#REF!"}, {paramsType: ['error', 'ref'], result: "#REF!"}, {paramsType: ['error', 'range'], result: "#REF!"}, {paramsType: ['array', 'number'], result: "#VALUE!"}, {paramsType: ['array', 'string'], result: "#VALUE!"}, {paramsType: ['array', 'bool'], result: "#VALUE!"}, {paramsType: ['array', 'stringNumber'], result: "#VALUE!"}, {paramsType: ['array', 'error'], result: "#REF!"}, {paramsType: ['array', 'array'], result: "#VALUE!"}, {paramsType: ['array', 'ref'], result: "#VALUE!"}, {paramsType: ['array', 'range'], result: "#VALUE!"}, {paramsType: ['ref', 'number'], result: "110"}, {paramsType: ['ref', 'string'], result: "1test"}, {paramsType: ['ref', 'bool'], result: "1TRUE"}, {paramsType: ['ref', 'stringNumber'], result: "11"}, {paramsType: ['ref', 'error'], result: "#REF!"}, {paramsType: ['ref', 'array'], result: "#VALUE!"}, {paramsType: ['ref', 'ref'], result: "11"}, {paramsType: ['ref', 'range'], result: "#VALUE!"}, {paramsType: ['range', 'number'], result: "#VALUE!"}, {paramsType: ['range', 'string'], result: "#VALUE!"}, {paramsType: ['range', 'bool'], result: "#VALUE!"}, {paramsType: ['range', 'stringNumber'], result: "#VALUE!"}, {paramsType: ['range', 'error'], result: "#REF!"}, {paramsType: ['range', 'array'], result: "#VALUE!"}, {paramsType: ['range', 'ref'], result: "#VALUE!"}, {paramsType: ['range', 'range'], result: "#VALUE!"}, ]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "_@STRING_@STRING"); }); }); QUnit.test("Test: \"Custom function test: number[][]+number->number\"", function (assert) { executeCustomFunction(function () { fCustomFunc = function add(arg1, arg2) { return arg1 + arg2; }; let typeToArgMap = {"number": 10, "stringNumber": '"1"', "string": '"test"', "bool": "TRUE", "error": "#REF!", "array": "{1,2,3}", "ref": "A100", "range": "A100:B101" }; //********** 2. @number[][] / @number <- @number ********** initParamsCustomFunction([{type: "number[][]"}, {type: "number"}], "number"); let aTasks = [ {paramsType: ['number', 'number'], result: "1010"}, {paramsType: ['number', 'stringNumber'], result: "101"}, {paramsType: ['number', 'string'], result: "10test"}, {paramsType: ['number', 'bool'], result: "10TRUE"}, {paramsType: ['number', 'error'], result: "#REF!"}, {paramsType: ['number', 'array'], result: "#VALUE!"}, {paramsType: ['number', 'ref'], result: "101"}, {paramsType: ['number', 'range'], result: "#VALUE!"}, {paramsType: ['string', 'number'], result: "test10"}, {paramsType: ['string', 'string'], result: "testtest"}, {paramsType: ['string', 'stringNumber'], result: "test1"}, {paramsType: ['string', 'bool'], result: "testTRUE"}, {paramsType: ['string', 'error'], result: "#REF!"}, {paramsType: ['string', 'array'], result: "#VALUE!"}, {paramsType: ['string', 'ref'], result: "test1"}, {paramsType: ['string', 'range'], result: "#VALUE!"}, {paramsType: ['bool', 'number'], result: "TRUE10"}, {paramsType: ['bool', 'string'], result: "TRUEtest"}, {paramsType: ['bool', 'bool'], result: "TRUETRUE"}, {paramsType: ['bool', 'stringNumber'], result: "TRUE1"}, {paramsType: ['bool', 'error'], result: "#REF!"}, {paramsType: ['bool', 'array'], result: "#VALUE!"}, {paramsType: ['bool', 'ref'], result: "TRUE1"}, {paramsType: ['bool', 'range'], result: "#VALUE!"}, {paramsType: ['error', 'number'], result: "#REF!"}, {paramsType: ['error', 'string'], result: "#REF!"}, {paramsType: ['error', 'bool'], result: "#REF!"}, {paramsType: ['error', 'stringNumber'], result: "#REF!"}, {paramsType: ['error', 'error'], result: "#REF!"}, {paramsType: ['error', 'array'], result: "#REF!"}, {paramsType: ['error', 'ref'], result: "#REF!"}, {paramsType: ['error', 'range'], result: "#REF!"}, {paramsType: ['array', 'number'], result: "#VALUE!"}, {paramsType: ['array', 'string'], result: "#VALUE!"}, {paramsType: ['array', 'bool'], result: "#VALUE!"}, {paramsType: ['array', 'stringNumber'], result: "#VALUE!"}, {paramsType: ['array', 'error'], result: "#REF!"}, {paramsType: ['array', 'array'], result: "#VALUE!"}, {paramsType: ['array', 'ref'], result: "#VALUE!"}, {paramsType: ['array', 'range'], result: "#VALUE!"}, {paramsType: ['ref', 'number'], result: "110"}, {paramsType: ['ref', 'string'], result: "1test"}, {paramsType: ['ref', 'bool'], result: "1TRUE"}, {paramsType: ['ref', 'stringNumber'], result: "11"}, {paramsType: ['ref', 'error'], result: "#REF!"}, {paramsType: ['ref', 'array'], result: "#VALUE!"}, {paramsType: ['ref', 'ref'], result: "11"}, {paramsType: ['ref', 'range'], result: "#VALUE!"}, {paramsType: ['range', 'number'], result: "#VALUE!"}, {paramsType: ['range', 'string'], result: "#VALUE!"}, {paramsType: ['range', 'bool'], result: "#VALUE!"}, {paramsType: ['range', 'stringNumber'], result: "#VALUE!"}, {paramsType: ['range', 'error'], result: "#REF!"}, {paramsType: ['range', 'array'], result: "#VALUE!"}, {paramsType: ['range', 'ref'], result: "#VALUE!"}, {paramsType: ['range', 'range'], result: "#VALUE!"}, ]; assert.ok(1,1); //doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "_@number[][]_@number"); }); }); QUnit.test("Test: \"Custom function test: async function\"", function (assert) { let done; executeCustomFunction(function (_callback, trueWb) { // Create async custom function fCustomFunc = async function simpleAsyncFunc(arg1, arg2) { // Simulate async operation await new Promise(resolve => setTimeout(resolve, 10)); return arg2; }; let typeToArgMap = { "number": 10, "stringNumber": '"1"', "string": '"test"', "bool": "TRUE", "error": "#REF!", "array": "{1,2,3}", "ref": "A100", "range": "A100:B101" }; // Initialize custom function with number parameters initParamsCustomFunction( [{type: "number"}, {type: "number"}], "number" ); // Test async function done = assert.async(); let aTasks = [{ paramsType: ["number", "number"], result: "10" }]; // Execute and verify async result doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "_ASYNC_TEST", _callback); }, function (trueWb) { let api = window["Asc"]["editor"]; api.wb = trueWb; done(); ws.getRange2("A1:Z10000").cleanAll(); }); }); QUnit.test("Test: \"Custom function test: async operations\"", function (assert) { let done; executeCustomFunction(function (_callback, trueWb) { // Async function that returns promise fCustomFunc = async function asyncPromiseFunc(arg1, arg2) { return new Promise((resolve) => { setTimeout(() => { resolve(arg1 + arg2); }, 10); }); }; let typeToArgMap = { "number": 10, "stringNumber": '"1"', "string": '"test"', "bool": "TRUE", "error": "#REF!", "array": "{1,2,3}", "ref": "A100", "range": "A100:B101" }; // Initialize with number parameters initParamsCustomFunction( [{type: "number"}, {type: "number"}], "number" ); // Setup async test done = assert.async(); let aTasks = [ { paramsType: ["number", "number"], result: "20" // 10 + 10 }, { paramsType: ["string", "number"], result: "test10" }, { paramsType: ["number", "error"], result: "#REF!" } ]; // Execute tests with callback doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "_ASYNC_PROMISE_TEST", _callback); }, function (trueWb) { let api = window["Asc"]["editor"]; api.wb = trueWb; done(); ws.getRange2("A1:Z10000").cleanAll(); }); }); QUnit.test("Test: \"Custom function test: async multiple operations\"", function (assert) { let done; executeCustomFunction(function (_callback, trueWb) { // Async function with multiple awaits fCustomFunc = async function asyncMultipleFunc(arg1, arg2) { await new Promise(resolve => setTimeout(resolve, 5)); let temp = arg1 * 2; await new Promise(resolve => setTimeout(resolve, 5)); return temp + arg2; }; let typeToArgMap = { "number": 5, "stringNumber": '"1"', "string": '"test"', "bool": "TRUE", "error": "#REF!", "array": "{1,2,3}", "ref": "A100", "range": "A100:B101" }; initParamsCustomFunction( [{type: "number"}, {type: "number"}], "number" ); done = assert.async(); let aTasks = [{ paramsType: ["number", "number"], result: "15" // (5 * 2) + 5 }]; doCustomFunctionTasks(assert, aTasks, typeToArgMap, fCustomFunc.name.toUpperCase(), "_ASYNC_MULTIPLE_TEST", _callback); }, function (trueWb) { let api = window["Asc"]["editor"]; api.wb = trueWb; done(); ws.getRange2("A1:Z10000").cleanAll(); }); }); /** * Tests async function calculation with cell dependencies * A1 = number + asyncFunc * B1 = A1 + B2 + asyncFunc2 * B2 = C2 + asyncFunc3 * C2 = A1 + asyncFunc4 */ QUnit.test('Async formula calculation', function(assert) { const done = assert.async(); // For async test completion // Setup initial values and async functions const asyncFunc = function() { return new Promise((resolve) => { setTimeout(() => { resolve(10); }, 1); }); }; const asyncFunc2 = function() { return new Promise((resolve) => { setTimeout(() => { resolve(20); }, 1); }); }; const asyncFunc3 = function() { return new Promise((resolve) => { setTimeout(() => { resolve(30); }, 1); }); }; const asyncFunc4 = function() { return new Promise((resolve) => { setTimeout(() => { resolve(40); }, 1); }); }; // Register async functions initParamsCustomFunction( [{type: "number"}, {type: "number"}], "number" ); executeCustomFunction(function (callback) { let api = window["Asc"]["editor"]; let oJsDoc = AscCommon.parseJSDoc(sJsDoc); api.addCustomFunction(asyncFunc, oJsDoc[0]); api.addCustomFunction(asyncFunc2, oJsDoc[0]); api.addCustomFunction(asyncFunc3, oJsDoc[0]); api.addCustomFunction(asyncFunc4, oJsDoc[0]); wb.asyncFormulasManager.endCallback = function () { // Check final calculated values assert.strictEqual(ws.getRange2("A1").getValue(), "15", "A1 calculated correctly"); assert.strictEqual(ws.getRange2("C2").getValue(), "55", "C2 calculated correctly"); assert.strictEqual(ws.getRange2("B2").getValue(), "85", "B2 calculated correctly"); assert.strictEqual(ws.getRange2("B1").getValue(), "120", "B1 calculated correctly"); callback(); wb.asyncFormulasManager.endCallback = null; }; // Set cell formulas wb.dependencyFormulas.lockRecal(); ws.getRange2("A1").setValue("=5+ASYNCFUNC()"); ws.getRange2("B1").setValue("=A1+B2+ASYNCFUNC2()"); ws.getRange2("B2").setValue("=C2+ASYNCFUNC3()"); ws.getRange2("C2").setValue("=A1+ASYNCFUNC4()"); wb.dependencyFormulas.unlockRecal(); // Expected calculation sequence: // 1. A1 = 5 + 10 = 15 // 2. C2 = 15 + 40 = 55 // 3. B2 = 55 + 30 = 85 // 4. B1 = 15 + 85 + 20 = 120 // Check initial state - cells should show loading state assert.strictEqual(ws.getRange2("A1").getValue(), "#BUSY!", "A1 shows loading state"); assert.strictEqual(ws.getRange2("B1").getValue(), "#BUSY!", "B1 shows loading state"); assert.strictEqual(ws.getRange2("B2").getValue(), "#BUSY!", "B2 shows loading state"); assert.strictEqual(ws.getRange2("C2").getValue(), "#BUSY!", "C2 shows loading state"); }, function () { done(); // Complete async test ws.getRange2("A1:Z10000").cleanAll(); }); }); /** * Tests complex async function calculation with multiple cell dependencies * A1 = number + GetCurrentPrice() * B1 = A1 + C1 + CalculateTax() * C1 = D1 + GetShippingCost() * D1 = A2 + B2 + GetDiscountValue() * A2 = FetchStockQuantity() + GetWarehouseStock() * B2 = C2 + CalculateHandlingFee() * C2 = GetSupplierPrice() * GetMarkupRate() * D2 = (A1 + B1) * GetCurrencyRate() * E1 = SUM(A1:D1) + CalculateInsurance() * E2 = AVERAGE(A2:D2) + GetServiceFee() */ QUnit.test('Complex async formula calculation with business logic', function(assert) { const done = assert.async(); const GetCurrentPrice = function() { return new Promise((resolve) => { setTimeout(() => { resolve(10); }, 1); }); }; const CalculateTax = function() { return new Promise((resolve) => { setTimeout(() => { resolve(20); }, 1); }); }; // Функция расчета стоимости доставки const GetShippingCost = function() { return new Promise((resolve) => { setTimeout(() => { resolve(30); }, 1); }); }; const GetDiscountValue = function() { return new Promise((resolve) => { setTimeout(() => { resolve(40); // Значение скидки }, 1); }); }; const FetchStockQuantity = function() { return new Promise((resolve) => { setTimeout(() => { resolve(50); }, 1); }); }; const GetWarehouseStock = function() { return new Promise((resolve) => { setTimeout(() => { resolve(60); }, 1); }); }; const CalculateHandlingFee = function() { return new Promise((resolve) => { setTimeout(() => { resolve(70); }, 1); }); }; const GetSupplierPrice = function() { return new Promise((resolve) => { setTimeout(() => { resolve(80); }, 1); }); }; const GetMarkupRate = function() { return new Promise((resolve) => { setTimeout(() => { resolve(90); }, 1); }); }; const GetCurrencyRate = function() { return new Promise((resolve) => { setTimeout(() => { resolve(100); }, 1); }); }; const CalculateInsurance = function() { return new Promise((resolve) => { setTimeout(() => { resolve(110); }, 1); }); }; const GetServiceFee = function() { return new Promise((resolve) => { setTimeout(() => { resolve(120); }, 1); }); }; // Register async functions initParamsCustomFunction( [{type: "number"}, {type: "number"}], "number" ); executeCustomFunction(function (callback) { let api = window["Asc"]["editor"]; let oJsDoc = AscCommon.parseJSDoc(sJsDoc); // Register all async functions const asyncFunctions = { GetCurrentPrice, CalculateTax, GetShippingCost, GetDiscountValue, FetchStockQuantity, GetWarehouseStock, CalculateHandlingFee, GetSupplierPrice, GetMarkupRate, GetCurrencyRate, CalculateInsurance, GetServiceFee }; Object.entries(asyncFunctions).forEach(([_, func]) => { api.addCustomFunction(func, oJsDoc[0]); }); wb.asyncFormulasManager.endCallback = function () { // Check final calculated values // A1 = 5 + 10 = 15 assert.strictEqual(ws.getRange2("A1").getValue(), "15", "A1 calculated correctly"); // A2 = 50 + 60 = 110 assert.strictEqual(ws.getRange2("A2").getValue(), "110", "A2 calculated correctly"); // C2 = 80 * 90 = 7200 assert.strictEqual(ws.getRange2("C2").getValue(), "7200", "C2 calculated correctly"); // B2 = 7200 + 70 = 7270 assert.strictEqual(ws.getRange2("B2").getValue(), "7270", "B2 calculated correctly"); // D1 = 110 + 7270 + 40 = 7420 assert.strictEqual(ws.getRange2("D1").getValue(), "7420", "D1 calculated correctly"); // C1 = 7420 + 30 = 7450 assert.strictEqual(ws.getRange2("C1").getValue(), "7450", "C1 calculated correctly"); // B1 = 15 + 7450 + 20 = 7485 assert.strictEqual(ws.getRange2("B1").getValue(), "7485", "B1 calculated correctly"); // D2 = (15 + 7485) * 100 = 750000 assert.strictEqual(ws.getRange2("D2").getValue(), "750000", "D2 calculated correctly"); // E1 = (15 + 7485 + 7450 + 7420) + 110 = 22480 assert.strictEqual(ws.getRange2("E1").getValue(), "22480", "E1 calculated correctly"); // E2 = AVERAGE(110, 7270, 7200, 750000) + 120 = 191265 assert.strictEqual(ws.getRange2("E2").getValue(), "191265", "E2 calculated correctly"); callback(); wb.asyncFormulasManager.endCallback = null; }; // Set cell formulas with complex dependencies wb.dependencyFormulas.lockRecal(); ws.getRange2("A1").setValue("=5+GetCurrentPrice()"); ws.getRange2("A2").setValue("=FetchStockQuantity()+GetWarehouseStock()"); ws.getRange2("C2").setValue("=GetSupplierPrice()*GetMarkupRate()"); ws.getRange2("B2").setValue("=C2+CalculateHandlingFee()"); ws.getRange2("D1").setValue("=A2+B2+GetDiscountValue()"); ws.getRange2("C1").setValue("=D1+GetShippingCost()"); ws.getRange2("B1").setValue("=A1+C1+CalculateTax()"); ws.getRange2("D2").setValue("=(A1+B1)*GetCurrencyRate()"); ws.getRange2("E1").setValue("=SUM(A1:D1)+CalculateInsurance()"); ws.getRange2("E2").setValue("=AVERAGE(A2:D2)+GetServiceFee()"); wb.dependencyFormulas.unlockRecal(); // Check initial loading states const rangesToCheck = ["A1", "B1", "C1", "D1", "A2", "B2", "C2", "D2", "E1", "E2"]; rangesToCheck.forEach(range => { assert.strictEqual( ws.getRange2(range).getValue(), "#BUSY!", `${range} shows loading state` ); }); }, function () { done(); ws.getRange2("A1:Z10000").cleanAll(); }); }); QUnit.test('Chain of dependent async functions with arguments', function(assert) { const done = assert.async(); // Setup async functions const asyncFunc1 = function(value) { return new Promise((resolve) => { setTimeout(() => { resolve(value + 10); }, 1); }); }; const asyncFunc2 = function(value) { return new Promise((resolve) => { setTimeout(() => { resolve(value + 20); }, 1); }); }; const asyncFunc3 = function(value) { return new Promise((resolve) => { setTimeout(() => { resolve(value + 30); }, 1); }); }; const asyncFunc4 = function(value) { return new Promise((resolve) => { setTimeout(() => { resolve(value + 40); }, 1); }); }; const asyncFunc5 = function(value) { return new Promise((resolve) => { setTimeout(() => { resolve(value + 50); }, 1); }); }; // Register async functions initParamsCustomFunction( [{type: "number"}, {type: "number"}], "number" ); executeCustomFunction(function (callback) { let api = window["Asc"]["editor"]; let oJsDoc = AscCommon.parseJSDoc(sJsDoc); api.addCustomFunction(asyncFunc1, oJsDoc[0]); api.addCustomFunction(asyncFunc2, oJsDoc[0]); api.addCustomFunction(asyncFunc3, oJsDoc[0]); api.addCustomFunction(asyncFunc4, oJsDoc[0]); api.addCustomFunction(asyncFunc5, oJsDoc[0]); wb.asyncFormulasManager.endCallback = function () { // Check final calculated values // A5 = ASYNCFUNC5(5) = 5 + 50 = 55 // A4 = ASYNCFUNC4(55) = 55 + 40 = 95 // A3 = ASYNCFUNC3(95) = 95 + 30 = 125 // A2 = ASYNCFUNC2(125) = 125 + 20 = 145 // A1 = ASYNCFUNC1(145) = 145 + 10 = 155 assert.strictEqual(ws.getRange2("A5").getValue(), "55", "A5 calculated correctly"); assert.strictEqual(ws.getRange2("A4").getValue(), "95", "A4 calculated correctly"); assert.strictEqual(ws.getRange2("A3").getValue(), "125", "A3 calculated correctly"); assert.strictEqual(ws.getRange2("A2").getValue(), "145", "A2 calculated correctly"); assert.strictEqual(ws.getRange2("A1").getValue(), "155", "A1 calculated correctly"); callback(); wb.asyncFormulasManager.endCallback = null; }; // Set cell formulas with chain dependency through function arguments ws.getRange2("A5").setValue("=ASYNCFUNC5(5)"); ws.getRange2("A4").setValue("=ASYNCFUNC4(A5)"); ws.getRange2("A3").setValue("=ASYNCFUNC3(A4)"); ws.getRange2("A2").setValue("=ASYNCFUNC2(A3)"); ws.getRange2("A1").setValue("=ASYNCFUNC1(A2)"); // Expected calculation sequence: // 1. A5 = ASYNCFUNC5(5) = 55 // 2. A4 = ASYNCFUNC4(55) = 95 // 3. A3 = ASYNCFUNC3(95) = 125 // 4. A2 = ASYNCFUNC2(125) = 145 // 5. A1 = ASYNCFUNC1(145) = 155 // Check initial state - cells should show loading state /*assert.strictEqual(ws.getRange2("A1").getValue(), "#BUSY!", "A1 shows loading state"); assert.strictEqual(ws.getRange2("A2").getValue(), "#BUSY!", "A2 shows loading state"); assert.strictEqual(ws.getRange2("A3").getValue(), "#BUSY!", "A3 shows loading state"); assert.strictEqual(ws.getRange2("A4").getValue(), "#BUSY!", "A4 shows loading state"); assert.strictEqual(ws.getRange2("A5").getValue(), "#BUSY!", "A5 shows loading state");*/ }, function () { done(); ws.getRange2("A1:Z10000").cleanAll(); }); }); QUnit.test("Test: \"3d_ref_tests\"", function (assert) { let cellWithFormula = new AscCommonExcel.CCellWithFormula(ws, 1, 0); let wsName = "हरियाणवी"; let newWs = wb.createWorksheet(1, wsName); oParser = new parserFormula(wsName + '!A1', "A2", ws); assert.ok(oParser.parse(), wsName + '!A1'); assert.strictEqual(oParser.calculate().getValue().getValue(), "", wsName + '!A1'); // without quotes oParser = new parserFormula("SUM(" + wsName + "!A1,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM(" + wsName + "!A1,0). isLocal = true. Link to 3d range A1 inside function without quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM(" + wsName + "!A1,0)"); oParser = new parserFormula("SUM(" + wsName + "!A1:A2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM(" + wsName + "!A1:A2,0). isLocal = true. Link to 3d range A1:A2 inside function without quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM(" + wsName + "!A1:A2,0)"); oParser = new parserFormula("SUM(" + wsName + "!$A$1:$A$2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM(" + wsName + "!$A$1:$A$2,0). isLocal = true. Link to 3d range $A$1:$A$2 inside function without quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM(" + wsName + "!$A$1:$A$2,0)"); oParser = new parserFormula("SUM(" + wsName + "!A:A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM(" + wsName + "!A:A,0). isLocal = true. Link to 3d range A:A inside function without quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM(" + wsName + "!A:A,0)"); oParser = new parserFormula("SUM(" + wsName + "!$A:$A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM(" + wsName + "!$A:$A,0). isLocal = true. Link to 3d range $A:$A inside function without quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM(" + wsName + "!$A:$A,0)"); // with quotes oParser = new parserFormula("SUM('" + wsName + "'!A1,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!A1,0). isLocal = true. Link to 3d range A1 inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!A1,0)"); oParser = new parserFormula("SUM('" + wsName + "'!A1:A2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!A1:A2,0). isLocal = true. Link to 3d range A1:A2 inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!A1:A2,0)"); oParser = new parserFormula("SUM('" + wsName + "'!$A$1:$A$2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!$A$1:$A$2,0). isLocal = true. Link to 3d range $A$1:$A$2 inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!$A$1:$A$2,0)"); oParser = new parserFormula("SUM('" + wsName + "'!A:A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!A:A,0). isLocal = true. Link to 3d range A:A inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!A:A,0)"); oParser = new parserFormula("SUM('" + wsName + "'!$A:$A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!$A:$A,0). isLocal = true. Link to 3d range $A:$A inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!$A:$A,0)"); wsName = "हरियाण.वी"; newWs.setName(wsName); oParser = new parserFormula(wsName + '!A1', "A2", ws); assert.ok(oParser.parse(), wsName + '!A1'); assert.strictEqual(oParser.calculate().getValue().getValue(), "", wsName + '!A1'); // without quotes oParser = new parserFormula("SUM(" + wsName + "!A1,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM(" + wsName + "!A1,0). isLocal = true. Link to 3d range A1 inside function without quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM(" + wsName + "!A1,0)"); oParser = new parserFormula("SUM(" + wsName + "!A1:A2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM(" + wsName + "!A1:A2,0). isLocal = true. Link to 3d range A1:A2 inside function without quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM(" + wsName + "!A1:A2,0)"); oParser = new parserFormula("SUM(" + wsName + "!$A$1:$A$2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM(" + wsName + "!$A$1:$A$2,0). isLocal = true. Link to 3d range $A$1:$A$2 inside function without quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM(" + wsName + "!$A$1:$A$2,0)"); oParser = new parserFormula("SUM(" + wsName + "!A:A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM(" + wsName + "!A:A,0). isLocal = true. Link to 3d range A:A inside function without quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM(" + wsName + "!A:A,0)"); oParser = new parserFormula("SUM(" + wsName + "!$A:$A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM(" + wsName + "!$A:$A,0). isLocal = true. Link to 3d range $A:$A inside function without quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM(" + wsName + "!$A:$A,0)"); // with quotes oParser = new parserFormula("SUM('" + wsName + "'!A1,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!A1,0). isLocal = true. Link to 3d range A1 inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!A1,0)"); oParser = new parserFormula("SUM('" + wsName + "'!A1:A2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!A1:A2,0). isLocal = true. Link to 3d range A1:A2 inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!A1:A2,0)"); oParser = new parserFormula("SUM('" + wsName + "'!$A$1:$A$2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!$A$1:$A$2,0). isLocal = true. Link to 3d range $A$1:$A$2 inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!$A$1:$A$2,0)"); oParser = new parserFormula("SUM('" + wsName + "'!A:A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!A:A,0). isLocal = true. Link to 3d range A:A inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!A:A,0)"); oParser = new parserFormula("SUM('" + wsName + "'!$A:$A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!$A:$A,0). isLocal = true. Link to 3d range $A:$A inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!$A:$A,0)"); wsName = "हरियाण वी"; newWs.setName(wsName); oParser = new parserFormula(wsName + '!A1', "A2", ws); assert.notOk(oParser.parse(), wsName + '!A1'); oParser = new parserFormula("'" + wsName + "'" + '!A1', "A2", ws); assert.ok(oParser.parse(), "'" + wsName + "'" + '!A1'); assert.strictEqual(oParser.calculate().getValue().getValue(), "", wsName + '!A1'); // without quotes oParser = new parserFormula("SUM(" + wsName + "!A1,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!A1,0). isLocal = true. Link to 3d range A1 inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!A1,0)"); oParser = new parserFormula("SUM(" + wsName + "!A1:A2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!A1:A2,0). isLocal = true. Link to 3d range A1:A2 inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!A1:A2,0)"); oParser = new parserFormula("SUM(" + wsName + "!$A$1:$A$2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!$A$1:$A$2,0). isLocal = true. Link to 3d range $A$1:$A$2 inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!$A$1:$A$2,0)"); oParser = new parserFormula("SUM(" + wsName + "!A:A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!A:A,0). isLocal = true. Link to 3d range A:A inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!A:A,0)"); oParser = new parserFormula("SUM(" + wsName + "!$A:$A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!$A:$A,0). isLocal = true. Link to 3d range $A:$A inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!$A:$A,0)"); // with quotes oParser = new parserFormula("SUM('" + wsName + "'!A1,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!A1,0). isLocal = true. Link to 3d range A1 inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!A1,0)"); oParser = new parserFormula("SUM('" + wsName + "'!A1:A2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!A1:A2,0). isLocal = true. Link to 3d range A1:A2 inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!A1:A2,0)"); oParser = new parserFormula("SUM('" + wsName + "'!$A$1:$A$2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!$A$1:$A$2,0). isLocal = true. Link to 3d range $A$1:$A$2 inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!$A$1:$A$2,0)"); oParser = new parserFormula("SUM('" + wsName + "'!A:A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!A:A,0). isLocal = true. Link to 3d range A:A inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!A:A,0)"); oParser = new parserFormula("SUM('" + wsName + "'!$A:$A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!$A:$A,0). isLocal = true. Link to 3d range $A:$A inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!$A:$A,0)"); wsName = "हरियाणवी_test_тест_اختبار_123"; newWs.setName(wsName); oParser = new parserFormula(wsName + '!A1', "A2", ws); assert.ok(oParser.parse(), wsName + '!A1'); assert.strictEqual(oParser.calculate().getValue().getValue(), "", wsName + '!A1'); // without quotes oParser = new parserFormula("SUM(" + wsName + "!A1,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM(" + wsName + "!A1,0). isLocal = true. Link to 3d range A1 inside function without quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM(" + wsName + "!A1,0)"); oParser = new parserFormula("SUM(" + wsName + "!A1:A2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM(" + wsName + "!A1:A2,0). isLocal = true. Link to 3d range A1:A2 inside function without quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM(" + wsName + "!A1:A2,0)"); oParser = new parserFormula("SUM(" + wsName + "!$A$1:$A$2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM(" + wsName + "!$A$1:$A$2,0). isLocal = true. Link to 3d range $A$1:$A$2 inside function without quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM(" + wsName + "!$A$1:$A$2,0)"); oParser = new parserFormula("SUM(" + wsName + "!A:A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM(" + wsName + "!A:A,0). isLocal = true. Link to 3d range A:A inside function without quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM(" + wsName + "!A:A,0)"); oParser = new parserFormula("SUM(" + wsName + "!$A:$A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM(" + wsName + "!$A:$A,0). isLocal = true. Link to 3d range $A:$A inside function without quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM(" + wsName + "!$A:$A,0)"); // with quotes oParser = new parserFormula("SUM('" + wsName + "'!A1,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!A1,0). isLocal = true. Link to 3d range A1 inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!A1,0)"); oParser = new parserFormula("SUM('" + wsName + "'!A1:A2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!A1:A2,0). isLocal = true. Link to 3d range A1:A2 inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!A1:A2,0)"); oParser = new parserFormula("SUM('" + wsName + "'!$A$1:$A$2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!$A$1:$A$2,0). isLocal = true. Link to 3d range $A$1:$A$2 inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!$A$1:$A$2,0)"); oParser = new parserFormula("SUM('" + wsName + "'!A:A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!A:A,0). isLocal = true. Link to 3d range A:A inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!A:A,0)"); oParser = new parserFormula("SUM('" + wsName + "'!$A:$A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!$A:$A,0). isLocal = true. Link to 3d range $A:$A inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!$A:$A,0)"); wsName = "हरियाणवी_test_тест_اختبار_1 23"; newWs.setName(wsName); oParser = new parserFormula("'" + wsName + "'" + '!A1', "A2", ws); assert.ok(oParser.parse(), "'" + wsName + "'" + '!A1'); assert.strictEqual(oParser.calculate().getValue().getValue(), "", wsName + '!A1'); // without quotes oParser = new parserFormula("SUM(" + wsName + "!A1:A2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!A1:A2,0). isLocal = true. Link to 3d range A1:A2 inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!A1:A2,0)"); oParser = new parserFormula("SUM(" + wsName + "!$A$1:$A$2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!$A$1:$A$2,0). isLocal = true. Link to 3d range $A$1:$A$2 inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!$A$1:$A$2,0)"); oParser = new parserFormula("SUM(" + wsName + "!A:A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!A:A,0). isLocal = true. Link to 3d range A:A inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!A:A,0)"); oParser = new parserFormula("SUM(" + wsName + "!$A:$A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!$A:$A,0). isLocal = true. Link to 3d range $A:$A inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!$A:$A,0)"); // with quotes oParser = new parserFormula("SUM('" + wsName + "'!A1:A2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!A1:A2,0). isLocal = true. Link to 3d range A1:A2 inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!A1:A2,0)"); oParser = new parserFormula("SUM('" + wsName + "'!$A$1:$A$2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!$A$1:$A$2,0). isLocal = true. Link to 3d range $A$1:$A$2 inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!$A$1:$A$2,0)"); oParser = new parserFormula("SUM('" + wsName + "'!A:A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!A:A,0). isLocal = true. Link to 3d range A:A inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!A:A,0)"); oParser = new parserFormula("SUM('" + wsName + "'!$A:$A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!$A:$A,0). isLocal = true. Link to 3d range $A:$A inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!$A:$A,0)"); wsName = "Ả, ẻ, Ỏ"; newWs.setName(wsName); oParser = new parserFormula("'" + wsName + "'" + '!A1', "A2", ws); assert.ok(oParser.parse(), "'" + wsName + "'" + '!A1'); assert.strictEqual(oParser.calculate().getValue().getValue(), "", wsName + '!A1'); // without quotes oParser = new parserFormula("SUM(" + wsName + "!A1:A2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!A1:A2,0). isLocal = true. Link to 3d range A1:A2 inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!A1:A2,0)"); oParser = new parserFormula("SUM(" + wsName + "!$A$1:$A$2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!$A$1:$A$2,0). isLocal = true. Link to 3d range $A$1:$A$2 inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!$A$1:$A$2,0)"); oParser = new parserFormula("SUM(" + wsName + "!A:A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!A:A,0). isLocal = true. Link to 3d range A:A inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!A:A,0)"); oParser = new parserFormula("SUM(" + wsName + "!$A:$A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!$A:$A,0). isLocal = true. Link to 3d range $A:$A inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!$A:$A,0)"); // with quotes oParser = new parserFormula("SUM('" + wsName + "'!A1:A2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!A1:A2,0). isLocal = true. Link to 3d range A1:A2 inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!A1:A2,0)"); oParser = new parserFormula("SUM('" + wsName + "'!$A$1:$A$2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!$A$1:$A$2,0). isLocal = true. Link to 3d range $A$1:$A$2 inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!$A$1:$A$2,0)"); oParser = new parserFormula("SUM('" + wsName + "'!A:A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!A:A,0). isLocal = true. Link to 3d range A:A inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!A:A,0)"); oParser = new parserFormula("SUM('" + wsName + "'!$A:$A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!$A:$A,0). isLocal = true. Link to 3d range $A:$A inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!$A:$A,0)"); wsName = "@©™®†‡§"; newWs.setName(wsName); oParser = new parserFormula("'" + wsName + "'" + '!A1', "A2", ws); assert.ok(oParser.parse(), "'" + wsName + "'" + '!A1'); assert.strictEqual(oParser.calculate().getValue().getValue(), "", wsName + '!A1'); // without quotes oParser = new parserFormula("SUM(" + wsName + "!A1:A2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!A1:A2,0). isLocal = true. Link to 3d range A1:A2 inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!A1:A2,0)"); oParser = new parserFormula("SUM(" + wsName + "!$A$1:$A$2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!$A$1:$A$2,0). isLocal = true. Link to 3d range $A$1:$A$2 inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!$A$1:$A$2,0)"); oParser = new parserFormula("SUM(" + wsName + "!A:A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!A:A,0). isLocal = true. Link to 3d range A:A inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!A:A,0)"); oParser = new parserFormula("SUM(" + wsName + "!$A:$A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!$A:$A,0). isLocal = true. Link to 3d range $A:$A inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!$A:$A,0)"); // with quotes oParser = new parserFormula("SUM('" + wsName + "'!A1:A2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!A1:A2,0). isLocal = true. Link to 3d range A1:A2 inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!A1:A2,0)"); oParser = new parserFormula("SUM('" + wsName + "'!$A$1:$A$2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!$A$1:$A$2,0). isLocal = true. Link to 3d range $A$1:$A$2 inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!$A$1:$A$2,0)"); oParser = new parserFormula("SUM('" + wsName + "'!A:A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!A:A,0). isLocal = true. Link to 3d range A:A inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!A:A,0)"); oParser = new parserFormula("SUM('" + wsName + "'!$A:$A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!$A:$A,0). isLocal = true. Link to 3d range $A:$A inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!$A:$A,0)"); wsName = "Sheet!25"; newWs.setName(wsName); // without quotes oParser = new parserFormula("SUM(" + wsName + "!A1:A2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!A1:A2,0). isLocal = true. Link to 3d range A1:A2 inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!A1:A2,0)"); oParser = new parserFormula("SUM(" + wsName + "!$A$1:$A$2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!$A$1:$A$2,0). isLocal = true. Link to 3d range $A$1:$A$2 inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!$A$1:$A$2,0)"); oParser = new parserFormula("SUM(" + wsName + "!A:A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!A:A,0). isLocal = true. Link to 3d range A:A inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!A:A,0)"); oParser = new parserFormula("SUM(" + wsName + "!$A:$A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!$A:$A,0). isLocal = true. Link to 3d range $A:$A inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!$A:$A,0)"); // with quotes oParser = new parserFormula("SUM('" + wsName + "'!A1:A2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!A1:A2,0). isLocal = true. Link to 3d range A1:A2 inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!A1:A2,0)"); oParser = new parserFormula("SUM('" + wsName + "'!$A$1:$A$2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!$A$1:$A$2,0). isLocal = true. Link to 3d range $A$1:$A$2 inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!$A$1:$A$2,0)"); oParser = new parserFormula("SUM('" + wsName + "'!A:A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!A:A,0). isLocal = true. Link to 3d range A:A inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!A:A,0)"); oParser = new parserFormula("SUM('" + wsName + "'!$A:$A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!$A:$A,0). isLocal = true. Link to 3d range $A:$A inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!$A:$A,0)"); wsName = ",;"; newWs.setName(wsName); // without quotes oParser = new parserFormula("SUM(" + wsName + "!A1:A2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!A1:A2,0). isLocal = true. Link to 3d range A1:A2 inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!A1:A2,0)"); oParser = new parserFormula("SUM(" + wsName + "!$A$1:$A$2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!$A$1:$A$2,0). isLocal = true. Link to 3d range $A$1:$A$2 inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!$A$1:$A$2,0)"); oParser = new parserFormula("SUM(" + wsName + "!A:A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!A:A,0). isLocal = true. Link to 3d range A:A inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!A:A,0)"); oParser = new parserFormula("SUM(" + wsName + "!$A:$A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!$A:$A,0). isLocal = true. Link to 3d range $A:$A inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!$A:$A,0)"); // with quotes oParser = new parserFormula("SUM('" + wsName + "'!A1:A2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!A1:A2,0). isLocal = true. Link to 3d range A1:A2 inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!A1:A2,0)"); oParser = new parserFormula("SUM('" + wsName + "'!$A$1:$A$2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!$A$1:$A$2,0). isLocal = true. Link to 3d range $A$1:$A$2 inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!$A$1:$A$2,0)"); oParser = new parserFormula("SUM('" + wsName + "'!A:A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!A:A,0). isLocal = true. Link to 3d range A:A inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!A:A,0)"); oParser = new parserFormula("SUM('" + wsName + "'!$A:$A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!$A:$A,0). isLocal = true. Link to 3d range $A:$A inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!$A:$A,0)"); wsName = "ds ds ds ! ds ; !"; newWs.setName(wsName); // without quotes oParser = new parserFormula("SUM(" + wsName + "!A1:A2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!A1:A2,0). isLocal = true. Link to 3d range A1:A2 inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!A1:A2,0)"); oParser = new parserFormula("SUM(" + wsName + "!$A$1:$A$2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!$A$1:$A$2,0). isLocal = true. Link to 3d range $A$1:$A$2 inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!$A$1:$A$2,0)"); oParser = new parserFormula("SUM(" + wsName + "!A:A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!A:A,0). isLocal = true. Link to 3d range A:A inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!A:A,0)"); oParser = new parserFormula("SUM(" + wsName + "!$A:$A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true) === false, "SUM(" + wsName + "!$A:$A,0). isLocal = true. Link to 3d range $A:$A inside function without quotes"); assert.strictEqual(oParser.calculate().getValue(), "#NAME?", "SUM(" + wsName + "!$A:$A,0)"); // with quotes oParser = new parserFormula("SUM('" + wsName + "'!A1:A2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!A1:A2,0). isLocal = true. Link to 3d range A1:A2 inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!A1:A2,0)"); oParser = new parserFormula("SUM('" + wsName + "'!$A$1:$A$2,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!$A$1:$A$2,0). isLocal = true. Link to 3d range $A$1:$A$2 inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!$A$1:$A$2,0)"); oParser = new parserFormula("SUM('" + wsName + "'!A:A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!A:A,0). isLocal = true. Link to 3d range A:A inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!A:A,0)"); oParser = new parserFormula("SUM('" + wsName + "'!$A:$A,0)", cellWithFormula, ws); assert.ok(oParser.parse(true), "SUM('" + wsName + "'!$A:$A,0). isLocal = true. Link to 3d range $A:$A inside function with quotes"); assert.ok(oParser.outStack.length > 2, "OutStack length after parse"); assert.strictEqual(oParser.calculate().getValue(), 0, "SUM('" + wsName + "'!$A:$A,0)"); }); // Mocks for API Testing Asc.spreadsheet_api.prototype._init = function () { this._loadModules(); }; Asc.spreadsheet_api.prototype._loadFonts = function (fonts, callback) { callback(); }; AscCommonExcel.WorkbookView.prototype._calcMaxDigitWidth = function () { }; AscCommonExcel.WorkbookView.prototype._init = function () { }; AscCommonExcel.WorkbookView.prototype._isLockedUserProtectedRange = function (callback) { callback(true); }; AscCommonExcel.WorkbookView.prototype._onWSSelectionChanged = function () { }; AscCommonExcel.WorkbookView.prototype.showWorksheet = function () { }; AscCommonExcel.WorkbookView.prototype.recalculateDrawingObjects = function () { }; AscCommonExcel.WorkbookView.prototype.restoreFocus = function () { }; AscCommonExcel.WorksheetView.prototype._init = function () { }; AscCommonExcel.WorksheetView.prototype.updateRanges = function () { }; AscCommonExcel.WorksheetView.prototype._autoFitColumnsWidth = function () { }; AscCommonExcel.WorksheetView.prototype.cleanSelection = function () { }; AscCommonExcel.WorksheetView.prototype._drawSelection = function () { }; AscCommonExcel.WorksheetView.prototype._scrollToRange = function () { }; AscCommonExcel.WorksheetView.prototype.draw = function () { }; AscCommonExcel.WorksheetView.prototype._prepareDrawingObjects = function () { }; AscCommonExcel.WorksheetView.prototype._initCellsArea = function () { }; AscCommonExcel.WorksheetView.prototype.getZoom = function () { }; AscCommonExcel.WorksheetView.prototype._prepareCellTextMetricsCache = function () { }; AscCommon.baseEditorsApi.prototype._onEndLoadSdk = function () { }; AscCommonExcel.WorksheetView.prototype._isLockedCells = function (oFromRange, subType, callback) { callback(true); return true; }; AscCommonExcel.WorksheetView.prototype._isLockedAll = function (callback) { callback(true); }; AscCommonExcel.WorksheetView.prototype._isLockedFrozenPane = function (callback) { callback(true); }; AscCommonExcel.WorksheetView.prototype._updateVisibleColsCount = function () { }; AscCommonExcel.WorksheetView.prototype._calcActiveCellOffset = function () { }; AscCommon.baseEditorsApi.prototype._onEndLoadSdk = function () { }; Asc.ReadDefTableStyles = function () { }; QUnit.test("Test: API Calculation option", function (assert) { // Init api let api = new Asc.spreadsheet_api({ 'id-view': 'editor_sdk' }); window["Asc"]["editor"] = api; api.FontLoader = { LoadDocumentFonts: function() { } }; api._onEndLoadSdk(); api.isOpenOOXInBrowser = false; api.OpenDocumentFromBin(null, AscCommon.getEmpty()); api.initCollaborativeEditing({}); api._coAuthoringInitCollaborativeEditing({}); api.wb = new AscCommonExcel.WorkbookView(api.wbModel, api.controller, api.handlers, api.HtmlElement, api.topLineEditorElement, api, api.collaborativeEditing, api.fontRenderingMode); // Test api: GetCalcSettings let oCalcSettings = api.asc_GetCalcSettings(); assert.ok(oCalcSettings, "API: GetCalcSettings: Calculation setting object is created"); assert.strictEqual(oCalcSettings.bIterativeCalc, false, '"Enable iterative calculation" is "false" as default value'); assert.strictEqual(oCalcSettings.nMaxIterations, 100, '"Maximum Iterations" is "100" as default value'); assert.strictEqual(oCalcSettings.nMaxChange, 0.001, '"Maximum Change" is "0.001" as default value'); // Test api: UpdateCalcSettings // Update CalcSettings for api test, need to check changes for: CalcSetting, CalcPr, and CalcRecursion oCalcSettings.asc_setIterativeCalc(true); oCalcSettings.asc_setMaxIterations(15); api.asc_UpdateCalcSettings(oCalcSettings); // Check CalcPr let oCalcPr = api.wbModel.calcPr; assert.strictEqual(oCalcPr.iterate, true, 'API: UpdateCalcSettings. oCalcPr check: "iterate" is "true"'); assert.strictEqual(oCalcPr.iterateCount, 15, 'API: UpdateCalcSettings. oCalcPr check: "iterateCount" is "10"'); assert.strictEqual(oCalcPr.iterateDelta, null, 'API: UpdateCalcSettings. oCalcPr check: "iterateDelta" is "null"'); // Check CalcRecursion let g_cCalcRecursion = AscCommonExcel.g_cCalcRecursion; assert.strictEqual(g_cCalcRecursion.bIsEnabledRecursion, true, 'API: UpdateCalcSettings. CalcRecursion check: "bIsEnabledRecursion" is "true"'); assert.strictEqual(g_cCalcRecursion.nMaxIterations, 15, 'API: UpdateCalcSettings. CalcRecursion check: "nMaxIterations" is "15"'); assert.strictEqual(g_cCalcRecursion.nRelativeError, 0.001, 'API: UpdateCalcSettings. CalcRecursion check: "nRelativeError" is "0.001"'); // Case: UpdateCalcSettings update Maximum Change oCalcSettings.asc_setMaxChange(0.00001); api.asc_UpdateCalcSettings(oCalcSettings); // Check CalcPr assert.strictEqual(oCalcPr.iterateDelta, 0.00001, 'API: UpdateCalcSettings. oCalcPr check: "iterateDelta" is "0.00001"'); // Check CalcRecursion assert.strictEqual(g_cCalcRecursion.nRelativeError, 0.00001, 'API: UpdateCalcSettings. CalcRecursion check: "nRelativeError" is "0.00001"'); }); wb.dependencyFormulas.unlockRecal(); });