@odoo/o-spreadsheet 14.0.0 → 14.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/.eslintrc.json +20 -0
  2. package/.husky/post-checkout +9 -0
  3. package/.husky/pre-commit +39 -0
  4. package/.prettierignore +1 -0
  5. package/astToFormula.patch +0 -0
  6. package/demo/data.js +255 -0
  7. package/demo/index.html +9 -0
  8. package/demo/libs/Chart.bundle.js +20755 -0
  9. package/demo/main.js +101 -0
  10. package/doc/readme.md +46 -0
  11. package/package.json +3 -17
  12. package/rollup.config.js +23 -0
  13. package/src/base_plugin.ts +102 -0
  14. package/src/components/autofill.ts +146 -0
  15. package/src/components/bottom_bar.ts +199 -0
  16. package/src/components/color_picker.ts +150 -0
  17. package/src/components/composer/autocomplete_dropdown.ts +135 -0
  18. package/src/components/composer/composer.ts +487 -0
  19. package/src/components/composer/content_editable_helper.ts +146 -0
  20. package/src/components/figures/chart.ts +70 -0
  21. package/src/components/figures/container.ts +268 -0
  22. package/src/components/figures/text_figure.ts +36 -0
  23. package/src/components/grid.ts +635 -0
  24. package/src/components/helpers/dom_helpers.ts +7 -0
  25. package/src/components/helpers/drag_and_drop.ts +17 -0
  26. package/src/components/icons.ts +36 -0
  27. package/src/components/index.ts +1 -0
  28. package/src/components/menu.ts +288 -0
  29. package/src/components/overlay.ts +457 -0
  30. package/src/components/scrollbar.ts +22 -0
  31. package/src/components/selection_input.ts +168 -0
  32. package/src/components/side_panel/cell_is_rule_editor.ts +169 -0
  33. package/src/components/side_panel/chart_panel.ts +104 -0
  34. package/src/components/side_panel/color_scale_rule_editor.ts +145 -0
  35. package/src/components/side_panel/conditional_formatting.ts +396 -0
  36. package/src/components/side_panel/side_panel.ts +127 -0
  37. package/src/components/side_panel/translations_terms.ts +45 -0
  38. package/src/components/spreadsheet.ts +198 -0
  39. package/src/components/top_bar.ts +535 -0
  40. package/src/constants.ts +26 -0
  41. package/src/data.ts +149 -0
  42. package/src/fonts.ts +41 -0
  43. package/src/formulas/compiler.ts +258 -0
  44. package/src/formulas/composer_tokenizer.ts +70 -0
  45. package/src/formulas/index.ts +15 -0
  46. package/src/formulas/normalize.ts +52 -0
  47. package/src/formulas/parser.ts +280 -0
  48. package/src/formulas/range_tokenizer.ts +97 -0
  49. package/src/formulas/tokenizer.ts +242 -0
  50. package/src/functions/arguments.ts +114 -0
  51. package/src/functions/dates.ts +302 -0
  52. package/src/functions/helpers.ts +592 -0
  53. package/src/functions/index.ts +52 -0
  54. package/src/functions/module_database.ts +282 -0
  55. package/src/functions/module_date.ts +743 -0
  56. package/src/functions/module_info.ts +69 -0
  57. package/src/functions/module_logical.ts +208 -0
  58. package/src/functions/module_lookup.ts +185 -0
  59. package/src/functions/module_math.ts +1252 -0
  60. package/src/functions/module_operators.ts +291 -0
  61. package/src/functions/module_statistical.ts +882 -0
  62. package/src/functions/module_text.ts +370 -0
  63. package/src/helpers/color.ts +30 -0
  64. package/src/helpers/coordinates.ts +71 -0
  65. package/src/helpers/grid_manipulation.ts +68 -0
  66. package/src/helpers/index.ts +7 -0
  67. package/src/helpers/misc.ts +76 -0
  68. package/src/helpers/numbers.ts +117 -0
  69. package/src/helpers/uuid.ts +19 -0
  70. package/src/helpers/zones.ts +263 -0
  71. package/src/history.ts +186 -0
  72. package/src/index.ts +84 -0
  73. package/src/model.ts +261 -0
  74. package/src/plugins/autofill.ts +412 -0
  75. package/src/plugins/chart.ts +404 -0
  76. package/src/plugins/clipboard.ts +461 -0
  77. package/src/plugins/conditional_format.ts +445 -0
  78. package/src/plugins/core.ts +1502 -0
  79. package/src/plugins/edition.ts +157 -0
  80. package/src/plugins/evaluation.ts +428 -0
  81. package/src/plugins/figures.ts +123 -0
  82. package/src/plugins/formatting.ts +630 -0
  83. package/src/plugins/highlight.ts +187 -0
  84. package/src/plugins/index.ts +32 -0
  85. package/src/plugins/merge.ts +524 -0
  86. package/src/plugins/renderer.ts +571 -0
  87. package/src/plugins/selection.ts +562 -0
  88. package/src/plugins/selection_inputs.ts +326 -0
  89. package/src/registries/autofill_modifiers.ts +76 -0
  90. package/src/registries/autofill_rules.ts +98 -0
  91. package/src/registries/figure_registry.ts +30 -0
  92. package/src/registries/index.ts +7 -0
  93. package/src/registries/menu_items_registry.ts +110 -0
  94. package/src/registries/menus/cell_menu_registry.ts +79 -0
  95. package/src/registries/menus/col_menu_registry.ts +63 -0
  96. package/src/registries/menus/index.ts +6 -0
  97. package/src/registries/menus/menu_items_actions.ts +425 -0
  98. package/src/registries/menus/row_menu_registry.ts +63 -0
  99. package/src/registries/menus/sheet_menu_registry.ts +75 -0
  100. package/src/registries/menus/topbar_menu_registry.ts +204 -0
  101. package/src/registries/side_panel_registry.ts +26 -0
  102. package/src/registries/topbar_component_registry.ts +12 -0
  103. package/src/registry.ts +51 -0
  104. package/src/translation.ts +44 -0
  105. package/src/types/autofill.ts +48 -0
  106. package/src/types/chart.ts +26 -0
  107. package/src/types/commands.ts +716 -0
  108. package/src/types/conditional_formatting.ts +124 -0
  109. package/src/types/env.ts +13 -0
  110. package/src/types/functions.ts +35 -0
  111. package/src/types/getters.ts +103 -0
  112. package/src/types/index.ts +20 -0
  113. package/src/types/misc.ts +143 -0
  114. package/src/types/rendering.ts +41 -0
  115. package/src/types/workbook_data.ts +62 -0
  116. package/tests/__mocks__/uuid.ts +7 -0
  117. package/tests/canvas.mock.ts +34 -0
  118. package/tests/components/__mocks__/content_editable_helper.ts +79 -0
  119. package/tests/components/__mocks__/scrollbar.ts +18 -0
  120. package/tests/components/__snapshots__/autocomplete_dropdown_test.ts.snap +29 -0
  121. package/tests/components/__snapshots__/bottom_bar_test.ts.snap +75 -0
  122. package/tests/components/__snapshots__/context_menu_test.ts.snap +88 -0
  123. package/tests/components/__snapshots__/grid_test.ts.snap +60 -0
  124. package/tests/components/__snapshots__/spreadsheet_test.ts.snap +455 -0
  125. package/tests/components/__snapshots__/top_bar_test.ts.snap +705 -0
  126. package/tests/components/autocomplete_dropdown_test.ts +315 -0
  127. package/tests/components/autofill_test.ts +167 -0
  128. package/tests/components/bottom_bar_test.ts +262 -0
  129. package/tests/components/chart_side_panel_test.ts +123 -0
  130. package/tests/components/composer_test.ts +400 -0
  131. package/tests/components/context_menu_test.ts +825 -0
  132. package/tests/components/grid_manipulation_test.ts +163 -0
  133. package/tests/components/grid_test.ts +581 -0
  134. package/tests/components/overlay_test.ts +541 -0
  135. package/tests/components/selection_input_test.ts +259 -0
  136. package/tests/components/side_panel_test.ts +148 -0
  137. package/tests/components/spreadsheet_test.ts +194 -0
  138. package/tests/components/top_bar_test.ts +427 -0
  139. package/tests/data_test.ts +175 -0
  140. package/tests/dom_helper.ts +42 -0
  141. package/tests/formulas/__snapshots__/compiler_test.ts.snap +302 -0
  142. package/tests/formulas/compiler_test.ts +266 -0
  143. package/tests/formulas/composer_tokenizer_test.ts +137 -0
  144. package/tests/formulas/expressions_test.ts +57 -0
  145. package/tests/formulas/formulas_test.ts +80 -0
  146. package/tests/formulas/normalize_test.ts +82 -0
  147. package/tests/formulas/parser_test.ts +224 -0
  148. package/tests/formulas/range_tokenizer_test.ts +187 -0
  149. package/tests/formulas/tokenizer_test.ts +164 -0
  150. package/tests/functions/arguments_test.ts +141 -0
  151. package/tests/functions/dates_test.ts +1081 -0
  152. package/tests/functions/functions_test.ts +53 -0
  153. package/tests/functions/helper_test.ts +98 -0
  154. package/tests/functions/module_database_test.ts +311 -0
  155. package/tests/functions/module_date_test.ts +941 -0
  156. package/tests/functions/module_info_test.ts +139 -0
  157. package/tests/functions/module_logical_test.ts +369 -0
  158. package/tests/functions/module_lookup_test.ts +541 -0
  159. package/tests/functions/module_math_test.ts +2482 -0
  160. package/tests/functions/module_operators_test.ts +955 -0
  161. package/tests/functions/module_statistical_test.ts +2014 -0
  162. package/tests/functions/module_text_test.ts +667 -0
  163. package/tests/helpers/coordinates_test.ts +25 -0
  164. package/tests/helpers/misc_test.ts +95 -0
  165. package/tests/helpers/numbers_test.ts +196 -0
  166. package/tests/helpers/zones_test.ts +97 -0
  167. package/tests/helpers.ts +384 -0
  168. package/tests/menu_items_registry_test.ts +540 -0
  169. package/tests/model/plugins/__snapshots__/chart_test.ts.snap +90 -0
  170. package/tests/model/plugins/chart_test.ts +562 -0
  171. package/tests/model_test.ts +82 -0
  172. package/tests/plugins/__snapshots__/conditional_formatting_test.ts.snap +131 -0
  173. package/tests/plugins/__snapshots__/renderer_test.ts.snap +371 -0
  174. package/tests/plugins/autofill_test.ts +457 -0
  175. package/tests/plugins/borders_test.ts +295 -0
  176. package/tests/plugins/clipboard_test.ts +1180 -0
  177. package/tests/plugins/conditional_formatting_test.ts +1253 -0
  178. package/tests/plugins/core_test.ts +614 -0
  179. package/tests/plugins/edition_test.ts +100 -0
  180. package/tests/plugins/evaluation_async_test.ts +332 -0
  181. package/tests/plugins/evaluation_dates_test.ts +79 -0
  182. package/tests/plugins/evaluation_test.ts +901 -0
  183. package/tests/plugins/figures_test.ts +327 -0
  184. package/tests/plugins/formatting_test.ts +391 -0
  185. package/tests/plugins/grid_manipulation_test.ts +1366 -0
  186. package/tests/plugins/highlight_test.ts +413 -0
  187. package/tests/plugins/history_test.ts +142 -0
  188. package/tests/plugins/import_export_test.ts +276 -0
  189. package/tests/plugins/merges_test.ts +490 -0
  190. package/tests/plugins/navigation_test.ts +181 -0
  191. package/tests/plugins/plugins/evaluation_test.ts +111 -0
  192. package/tests/plugins/renderer_test.ts +598 -0
  193. package/tests/plugins/resizing_test.ts +152 -0
  194. package/tests/plugins/selection_input_test.ts +409 -0
  195. package/tests/plugins/selection_test.ts +442 -0
  196. package/tests/plugins/sheets_test.ts +643 -0
  197. package/tests/plugins/style_test.ts +90 -0
  198. package/tsconfig.json +22 -0
@@ -0,0 +1,2014 @@
1
+ import { evaluateCell, evaluateGrid } from "../helpers";
2
+
3
+ describe("statistical", () => {
4
+ //----------------------------------------------------------------------------
5
+ // AVEDEV
6
+ //----------------------------------------------------------------------------
7
+
8
+ test("AVEDEV: functional tests on simple arguments", () => {
9
+ expect(evaluateCell("A1", { A1: "=AVEDEV()" })).toBe("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
10
+ expect(evaluateCell("A1", { A1: "=AVEDEV(,)" })).toBe(0);
11
+ expect(evaluateCell("A1", { A1: "=AVEDEV(0)" })).toBe(0);
12
+ expect(evaluateCell("A1", { A1: "=AVEDEV(1, 2)" })).toBe(0.5);
13
+ expect(evaluateCell("A1", { A1: "=AVEDEV( , 2)" })).toBe(1);
14
+ expect(evaluateCell("A1", { A1: "=AVEDEV(1, 2, 3, )" })).toBe(1);
15
+ expect(evaluateCell("A1", { A1: "=AVEDEV(1.5, 2.5)" })).toBe(0.5);
16
+ expect(evaluateCell("A1", { A1: "=AVEDEV(-10, 20)" })).toBe(15);
17
+ });
18
+
19
+ test("AVEDEV: casting tests on simple arguments", () => {
20
+ expect(evaluateCell("A1", { A1: '=AVEDEV("2", "-6")' })).toBe(4);
21
+ expect(evaluateCell("A1", { A1: '=AVEDEV("2", "")' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
22
+ expect(evaluateCell("A1", { A1: '=AVEDEV("2", " -6 ")' })).toBe(4);
23
+ expect(evaluateCell("A1", { A1: "=AVEDEV(TRUE, FALSE)" })).toBe(0.5);
24
+ expect(evaluateCell("A1", { A1: '=AVEDEV("8/8/2008", "10/10/2010")' })).toBe(396.5);
25
+ });
26
+
27
+ test("AVEDEV: functional tests on cell arguments", () => {
28
+ expect(evaluateCell("A1", { A1: "=AVEDEV(A2)", A2: "" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
29
+ expect(evaluateCell("A1", { A1: "=AVEDEV(A2)", A2: "0" })).toBe(0);
30
+ expect(evaluateCell("A1", { A1: "=AVEDEV(A2, A3)", A2: "1", A3: "2" })).toBe(0.5);
31
+ expect(evaluateCell("A1", { A1: "=AVEDEV(A2, A3, A4)", A2: "1", A3: "", A4: "2" })).toBe(0.5);
32
+ expect(evaluateCell("A1", { A1: "=AVEDEV(A2, A3, A4)", A2: "", A3: "1", A4: "2" })).toBe(0.5);
33
+ expect(evaluateCell("A1", { A1: "=AVEDEV(A2, A3)", A2: "1.5", A3: "2.5" })).toBe(0.5);
34
+ expect(evaluateCell("A1", { A1: "=AVEDEV(A2, A3)", A2: "-10", A3: "20" })).toBe(15);
35
+ });
36
+
37
+ test("AVEDEV: casting tests on cell arguments", () => {
38
+ expect(evaluateCell("A1", { A1: "=AVEDEV(A2, A3)", A2: '"2"', A3: '"6"' })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
39
+ expect(evaluateCell("A1", { A1: "=AVEDEV(A2, A3)", A2: '"2"', A3: "42" })).toBe(0);
40
+ expect(evaluateCell("A1", { A1: "=AVEDEV(A2, A3)", A2: "TRUE", A3: "FALSE" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
41
+ expect(evaluateCell("A1", { A1: "=AVEDEV(A2, A3)", A2: "TRUE", A3: "42" })).toBe(0);
42
+ expect(evaluateCell("A1", { A1: "=AVEDEV(A2, A3)", A2: "8/8/2008", A3: "10/10/2010" })).toBe(
43
+ 396.5
44
+ );
45
+ });
46
+
47
+ test("AVEDEV: functional tests on range arguments", () => {
48
+ const grid = {
49
+ A1: "=AVEDEV(B2:D4)",
50
+ A2: "=AVEDEV(B2:C3, B4:C4, D2:D3, D4)",
51
+ B2: "42.2",
52
+ C2: "TRUE",
53
+ D2: "FALSE",
54
+ B3: "",
55
+ C3: "-10.2",
56
+ D3: "kikou",
57
+ B4: '"111111"',
58
+ C4: "0",
59
+ D4: "0",
60
+ };
61
+ expect(evaluateCell("A1", grid)).toEqual(17.1);
62
+ expect(evaluateCell("A2", grid)).toEqual(17.1);
63
+ });
64
+
65
+ //----------------------------------------------------------------------------
66
+ // AVERAGE
67
+ //----------------------------------------------------------------------------
68
+
69
+ test("AVERAGE: functional tests on simple arguments", () => {
70
+ expect(evaluateCell("A1", { A1: "=average()" })).toEqual("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
71
+ expect(evaluateCell("A1", { A1: "=average(0)" })).toBe(0);
72
+ expect(evaluateCell("A1", { A1: "=average(1, 2)" })).toBe(1.5);
73
+ expect(evaluateCell("A1", { A1: "=average(1, , 2)" })).toBe(1);
74
+ expect(evaluateCell("A1", { A1: "=average( , 1, 2)" })).toBe(1);
75
+ expect(evaluateCell("A1", { A1: "=average(1.5, 2.5)" })).toBe(2);
76
+ expect(evaluateCell("A1", { A1: "=average(-10, 20)" })).toBe(5);
77
+ });
78
+
79
+ test("AVERAGE: casting tests on simple arguments", () => {
80
+ expect(evaluateCell("A1", { A1: '=average("2", "-6")' })).toBe(-2);
81
+ expect(evaluateCell("A1", { A1: "=average(TRUE, FALSE)" })).toBe(0.5);
82
+ expect(evaluateCell("A1", { A1: '=average("08/08/2008", "10/10/2010")' })).toBe(40064.5);
83
+ });
84
+
85
+ test("AVERAGE: functional tests on cell arguments", () => {
86
+ expect(evaluateCell("A1", { A1: "=average(A2)", A2: "" })).toEqual("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
87
+ expect(evaluateCell("A1", { A1: "=average(A2)", A2: "0" })).toBe(0);
88
+ expect(evaluateCell("A1", { A1: "=average(A2, A3)", A2: "1", A3: "2" })).toBe(1.5);
89
+ expect(evaluateCell("A1", { A1: "=average(A2, A3, A4)", A2: "1", A3: "", A4: "2" })).toBe(1.5);
90
+ expect(evaluateCell("A1", { A1: "=average(A2, A3, A4)", A2: "", A3: "1", A4: "2" })).toBe(1.5);
91
+ expect(evaluateCell("A1", { A1: "=average(A2, A3)", A2: "1.5", A3: "2.5" })).toBe(2);
92
+ expect(evaluateCell("A1", { A1: "=average(A2, A3)", A2: "-10", A3: "20" })).toBe(5);
93
+ });
94
+
95
+ test("AVERAGE: casting tests on cell arguments", () => {
96
+ expect(evaluateCell("A1", { A1: "=average(A2, A3)", A2: '"2"', A3: '"6"' })).toEqual("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
97
+ expect(evaluateCell("A1", { A1: "=average(A2, A3)", A2: '"2"', A3: "42" })).toBe(42);
98
+ expect(evaluateCell("A1", { A1: "=average(A2, A3)", A2: "TRUE", A3: "FALSE" })).toEqual(
99
+ "#ERROR"
100
+ ); // @compatibility: on google sheets, return #DIV/0!
101
+ expect(evaluateCell("A1", { A1: "=average(A2, A3)", A2: "TRUE", A3: "42" })).toBe(42);
102
+ expect(evaluateCell("A1", { A1: "=average(A2, A3)", A2: "08/08/2008", A3: "10/10/2010" })).toBe(
103
+ 40064.5
104
+ );
105
+ });
106
+
107
+ test("AVERAGE: functional tests on range arguments", () => {
108
+ const grid = {
109
+ A1: "=average(B2:D4)",
110
+ A2: "=average(B2:C3, B4:C4, D2:D3, D4)",
111
+ B2: "42.2",
112
+ C2: "TRUE",
113
+ D2: "FALSE",
114
+ B3: "",
115
+ C3: "-10.2",
116
+ D3: "kikou",
117
+ B4: '"111111"',
118
+ C4: "0",
119
+ D4: "0",
120
+ };
121
+ expect(evaluateCell("A1", grid)).toEqual(8);
122
+ expect(evaluateCell("A2", grid)).toEqual(8);
123
+ });
124
+
125
+ //----------------------------------------------------------------------------
126
+ // AVERAGE.WEIGHTED
127
+ //----------------------------------------------------------------------------
128
+
129
+ test("AVERAGE.WEIGHTED: functional tests on simple arguments", () => {
130
+ expect(evaluateCell("A1", { A1: "=average.weighted( , )" })).toEqual("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
131
+ expect(evaluateCell("A1", { A1: "=average.weighted(0, 0)" })).toEqual("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
132
+ expect(evaluateCell("A1", { A1: "=average.weighted(0, 1)" })).toBe(0);
133
+ expect(evaluateCell("A1", { A1: "=average.weighted(1, 1, 3)" })).toEqual("#ERROR"); // @compatibility: on google sheets, return #N/A
134
+ expect(evaluateCell("A1", { A1: "=average.weighted(1, 1, 3, 3)" })).toBe(2.5);
135
+ expect(evaluateCell("A1", { A1: "=average.weighted( , 1, 3, 3)" })).toBe(2.25);
136
+ expect(evaluateCell("A1", { A1: "=average.weighted(1, 1, 3, )" })).toBe(1);
137
+ expect(evaluateCell("A1", { A1: "=average.weighted(1, , 3, )" })).toEqual("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
138
+ expect(evaluateCell("A1", { A1: "=average.weighted(1.5, 1, 2.5, 4)" })).toBe(2.3);
139
+ expect(evaluateCell("A1", { A1: "=average.weighted(4, 1.5, 2, 2.5)" })).toBe(2.75);
140
+ expect(evaluateCell("A1", { A1: "=average.weighted(-10, 1, 20, 2)" })).toBe(10);
141
+ expect(evaluateCell("A1", { A1: "=average.weighted(1, -1, 3, 3)" })).toEqual("#ERROR"); // @compatibility: on google sheets, return #VALUE!
142
+ });
143
+
144
+ test("AVERAGE.WEIGHTED: casting tests on simple arguments", () => {
145
+ expect(evaluateCell("A1", { A1: '=average.weighted("-10", "1", "20", "2")' })).toBe(10);
146
+ expect(evaluateCell("A1", { A1: "=average.weighted(TRUE, FALSE)" })).toEqual("#ERROR"); // @compatibility: on google sheets, return #VALUE!
147
+ expect(evaluateCell("A1", { A1: "=average.weighted(FALSE, TRUE)" })).toBe(0);
148
+ expect(evaluateCell("A1", { A1: '=average.weighted("@#%!*", "@#%!*", "20", "2")' })).toEqual(
149
+ "#ERROR"
150
+ ); // @compatibility: on google sheets, return #VALUE!
151
+ });
152
+
153
+ test("AVERAGE.WEIGHTED: functional tests on cell arguments", () => {
154
+ expect(evaluateCell("A1", { A1: "=average.weighted(A2, A3)", A2: "", A3: "" })).toEqual(
155
+ "#ERROR"
156
+ ); // @compatibility: on google sheets, return #DIV/0!
157
+ expect(evaluateCell("A1", { A1: "=average.weighted(A2, A3)", A2: "0", A3: "0" })).toEqual(
158
+ "#ERROR"
159
+ ); // @compatibility: on google sheets, return #DIV/0!
160
+ expect(evaluateCell("A1", { A1: "=average.weighted(A2, A3)", A2: "0", A3: "1" })).toBe(0);
161
+ expect(
162
+ evaluateCell("A1", { A1: "=average.weighted(A2, A3, A4)", A2: "1", A3: "1", A4: "3" })
163
+ ).toEqual("#ERROR"); // @compatibility: on google sheets, return #N/A
164
+ expect(
165
+ evaluateCell("A1", {
166
+ A1: "=average.weighted(A2, A3, A4, A5)",
167
+ A2: "1",
168
+ A3: "1",
169
+ A4: "3",
170
+ A5: "3",
171
+ })
172
+ ).toBe(2.5);
173
+ expect(
174
+ evaluateCell("A1", {
175
+ A1: "=average.weighted(A2, A3, A4, A5)",
176
+ A2: "",
177
+ A3: "1",
178
+ A4: "3",
179
+ A5: "3",
180
+ })
181
+ ).toEqual("#ERROR"); // @compatibility: on google sheets, return #VALUE!
182
+ expect(
183
+ evaluateCell("A1", {
184
+ A1: "=average.weighted(A2, A3, A4, A5)",
185
+ A2: "1",
186
+ A3: "1",
187
+ A4: "3",
188
+ A5: "",
189
+ })
190
+ ).toEqual("#ERROR"); // @compatibility: on google sheets, return #VALUE!
191
+ expect(
192
+ evaluateCell("A1", {
193
+ A1: "=average.weighted(A2, A3, A4, A5)",
194
+ A2: "1.5",
195
+ A3: "1",
196
+ A4: "2.5",
197
+ A5: "4",
198
+ })
199
+ ).toBe(2.3);
200
+ expect(
201
+ evaluateCell("A1", {
202
+ A1: "=average.weighted(A2, A3, A4, A5)",
203
+ A2: "4",
204
+ A3: "1.5",
205
+ A4: "2",
206
+ A5: "2.5",
207
+ })
208
+ ).toBe(2.75);
209
+ expect(
210
+ evaluateCell("A1", {
211
+ A1: "=average.weighted(A2, A3, A4, A5)",
212
+ A2: "-10",
213
+ A3: "1",
214
+ A4: "20",
215
+ A5: "2",
216
+ })
217
+ ).toBe(10);
218
+ expect(
219
+ evaluateCell("A1", {
220
+ A1: "=average.weighted(A2, A3, A4, A5)",
221
+ A2: "1",
222
+ A3: "-1",
223
+ A4: "3",
224
+ A5: "3",
225
+ })
226
+ ).toEqual("#ERROR"); // @compatibility: on google sheets, return #VALUE!
227
+ });
228
+
229
+ test("AVERAGE.WEIGHTED: casting tests on cell arguments", () => {
230
+ expect(
231
+ evaluateCell("A1", {
232
+ A1: "=average.weighted(A2, A3, A4, A5)",
233
+ A2: '"2"',
234
+ A3: '"1"',
235
+ A4: '"6"',
236
+ A5: '"1"',
237
+ })
238
+ ).toEqual("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
239
+ expect(
240
+ evaluateCell("A1", {
241
+ A1: "=average.weighted(A2, A3, A4, A5)",
242
+ A2: '"2"',
243
+ A3: '"1"',
244
+ A4: "6",
245
+ A5: "1",
246
+ })
247
+ ).toBe(6);
248
+ expect(
249
+ evaluateCell("A1", {
250
+ A1: "=average.weighted(A2, A3, A4, A5)",
251
+ A2: '"2"',
252
+ A3: "1",
253
+ A4: "6",
254
+ A5: "1",
255
+ })
256
+ ).toEqual("#ERROR"); // @compatibility: on google sheets, return #VALUE!
257
+ expect(
258
+ evaluateCell("A1", {
259
+ A1: "=average.weighted(A2, A3, A4, A5)",
260
+ A2: "2",
261
+ A3: '"1"',
262
+ A4: "6",
263
+ A5: '"1"',
264
+ })
265
+ ).toEqual("#ERROR"); // @compatibility: on google sheets, return #VALUE!
266
+ expect(
267
+ evaluateCell("A1", {
268
+ A1: "=average.weighted(A2, A3, A4, A5)",
269
+ A2: "FALSE",
270
+ A3: "TRUE",
271
+ A4: "FALSE",
272
+ A5: "TRUE",
273
+ })
274
+ ).toEqual("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
275
+ expect(
276
+ evaluateCell("A1", {
277
+ A1: "=average.weighted(A2, A3, A4, A5)",
278
+ A2: "FALSE",
279
+ A3: "TRUE",
280
+ A4: "6",
281
+ A5: "TRUE",
282
+ })
283
+ ).toEqual("#ERROR"); // @compatibility: on google sheets, return #VALUE!
284
+ expect(
285
+ evaluateCell("A1", {
286
+ A1: "=average.weighted(A2, A3, A4, A5)",
287
+ A2: "FALSE",
288
+ A3: "TRUE",
289
+ A4: "6",
290
+ A5: "1",
291
+ })
292
+ ).toBe(6);
293
+ });
294
+
295
+ test("AVERAGE.WEIGHTED: functional tests on range arguments", () => {
296
+ const grid = {
297
+ A1: "=average.weighted(C1, C3, D1, D3, E1, E3, F1, F3)",
298
+ A2: "=average.weighted(C1:F1, C3:F3)",
299
+ A3: "=average.weighted(C1:D1, C3:D3, E1:F1, E3:F3)",
300
+ A4: "=average.weighted(C1:F1, B5:B8)",
301
+ A5: "=average.weighted(C1, B5, D1, B6, E1, B7, F1, B8)",
302
+ A6: "=average.weighted(C2, C3, D2, D3, E2, E3, F2, F3)",
303
+ A7: "=average.weighted(C2:F2, C3:F3)",
304
+ A8: "=average.weighted(C2, C4, D2, D4, E2, E4, F2, F4)",
305
+ A9: "=average.weighted(C2:D2, C4:D4, E2:F2, E4:F4)",
306
+ A10: "=average.weighted(C2:F2, C4:F4)",
307
+ B5: "2",
308
+ B6: "4",
309
+ B7: "2",
310
+ B8: "2",
311
+ C1: "0",
312
+ D1: "10",
313
+ E1: "20",
314
+ F1: "40",
315
+ C2: "42.2",
316
+ D2: "TRUE",
317
+ E2: "Jean Bambois",
318
+ F2: "-10.2",
319
+ C3: "2",
320
+ D3: "4",
321
+ E3: "2",
322
+ F3: "2",
323
+ C4: "2",
324
+ D4: "Jean Bonbeurre",
325
+ E4: "",
326
+ F4: "2",
327
+ };
328
+ expect(evaluateCell("A1", grid)).toBe(16);
329
+ expect(evaluateCell("A2", grid)).toBe(16);
330
+ expect(evaluateCell("A3", grid)).toBe(16);
331
+ expect(evaluateCell("A4", grid)).toEqual("#ERROR"); // @compatibility: on google sheets, return #VALUE!
332
+ expect(evaluateCell("A5", grid)).toBe(16);
333
+ expect(evaluateCell("A6", grid)).toEqual("#ERROR"); // @compatibility: on google sheets, return #VALUE!
334
+ expect(evaluateCell("A7", grid)).toEqual("#ERROR"); // @compatibility: on google sheets, return #VALUE!
335
+ expect(evaluateCell("A8", grid)).toBe(16);
336
+ expect(evaluateCell("A9", grid)).toBe(16);
337
+ expect(evaluateCell("A10", grid)).toBe(16);
338
+ });
339
+
340
+ //----------------------------------------------------------------------------
341
+ // AVERAGEA
342
+ //----------------------------------------------------------------------------
343
+
344
+ test("AVERAGEA: functional tests on simple arguments", () => {
345
+ expect(evaluateCell("A1", { A1: "=AVERAGEA()" })).toBe("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
346
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(,)" })).toBe(0);
347
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(0)" })).toBe(0);
348
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(1, 2)" })).toBe(1.5);
349
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(1, , 2)" })).toBe(1);
350
+ expect(evaluateCell("A1", { A1: "=AVERAGEA( , 1, 2)" })).toBe(1);
351
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(1.5, 2.5)" })).toBe(2);
352
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(-10, 20)" })).toBe(5);
353
+ });
354
+
355
+ test("AVERAGEA: casting tests on simple arguments", () => {
356
+ expect(evaluateCell("A1", { A1: '=AVERAGEA("")' })).toBe(0);
357
+ expect(evaluateCell("A1", { A1: '=AVERAGEA(" ")' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
358
+ expect(evaluateCell("A1", { A1: '=AVERAGEA("hello there")' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
359
+ expect(evaluateCell("A1", { A1: '=AVERAGEA("2", "-6")' })).toBe(-2);
360
+ expect(evaluateCell("A1", { A1: '=AVERAGEA("2", "")' })).toBe(1);
361
+ expect(evaluateCell("A1", { A1: '=AVERAGEA("2", " -6 ")' })).toBe(-2);
362
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(TRUE, FALSE)" })).toBe(0.5);
363
+ expect(evaluateCell("A1", { A1: '=AVERAGEA("0", "01/01/1900")' })).toBe(1);
364
+ });
365
+
366
+ test("AVERAGEA: functional tests on cell arguments", () => {
367
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(A2)", A2: "" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
368
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(A2)", A2: " " })).toBe(0);
369
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(A2)", A2: "0" })).toBe(0);
370
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(A2, A3)", A2: "1", A3: "2" })).toBe(1.5);
371
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(A2, A3, A4)", A2: "1", A3: "", A4: "2" })).toBe(1.5);
372
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(A2, A3, A4)", A2: "", A3: "1", A4: "3" })).toBe(2);
373
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(A2, A3)", A2: "1.5", A3: "2.5" })).toBe(2);
374
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(A2, A3)", A2: "-10", A3: "20" })).toBe(5);
375
+ });
376
+
377
+ test("AVERAGEA: casting tests on cell arguments", () => {
378
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(A2)", A2: '""' })).toBe(0);
379
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(A2)", A2: '" "' })).toBe(0);
380
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(A2)", A2: '"42"' })).toBe(0);
381
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(A2, A3)", A2: '"2"', A3: '"6"' })).toBe(0);
382
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(A2, A3)", A2: '"2"', A3: "42" })).toBe(21);
383
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(A2, A3)", A2: "TRUE", A3: "FALSE" })).toBe(0.5); // @compatibility: on google sheets, return #DIV/0!
384
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(A2, A3)", A2: "TRUE", A3: "42" })).toBe(21.5);
385
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(A2)", A2: '=""' })).toBe(0);
386
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(A2)", A2: '=" "' })).toBe(0);
387
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(A2)", A2: '="42"' })).toBe(0);
388
+ expect(evaluateCell("A1", { A1: "=AVERAGEA(A2)", A2: "01/20/1900" })).toBe(21);
389
+ });
390
+
391
+ test("AVERAGEA: functional tests on range arguments", () => {
392
+ const grid = {
393
+ A1: "=AVERAGEA(B2:D4)",
394
+ A2: "=AVERAGEA(B2:C3, B4:C4, D2:D3, D4)",
395
+ B2: "10",
396
+ C2: "TRUE",
397
+ D2: "FALSE",
398
+ C3: "5",
399
+ D3: "kikou",
400
+ B4: '"111111"',
401
+ C4: "0",
402
+ D4: "0",
403
+ };
404
+ expect(evaluateCell("A1", grid)).toBe(2);
405
+ expect(evaluateCell("A2", grid)).toBe(2);
406
+ });
407
+
408
+ //----------------------------------------------------------------------------
409
+ // AVERAGEIF
410
+ //----------------------------------------------------------------------------
411
+
412
+ test("AVERAGEIF: functional tests on range", () => {
413
+ // prettier-ignore
414
+ const grid = {
415
+ A1: "Coffee" , B1: "4" ,
416
+ A2: "Newspaper" , B2: "1" ,
417
+ A3: "Taxi" , B3: "10" ,
418
+ A4: "Golf" , B4: "26" ,
419
+ A5: "Taxi" , B5: "8" ,
420
+ A6: "Coffee" , B6: "3.5",
421
+ A7: "Gas" , B7: "46" ,
422
+ A8: "Restaurant", B8: "31" ,
423
+
424
+
425
+ A12: '=AVERAGEIF(A1:A8, "Taxi", B1:B8)',
426
+ A13: '=AVERAGEIF(B1:B8, ">=10", B1:B8)',
427
+ A14: '=AVERAGEIF(B1:B8, ">=10")',
428
+ A15: '=AVERAGEIF(A1:A8, "G*", B1:B8)',
429
+ };
430
+
431
+ const gridResult = evaluateGrid(grid);
432
+ expect(gridResult.A12).toBe(9);
433
+ expect(gridResult.A13).toBe(28.25);
434
+ expect(gridResult.A14).toBe(28.25);
435
+ expect(gridResult.A15).toBe(36);
436
+ });
437
+
438
+ //----------------------------------------------------------------------------
439
+ // AVERAGEIFS
440
+ //----------------------------------------------------------------------------
441
+
442
+ test("AVERAGEIFS: functional tests on range", () => {
443
+ // prettier-ignore
444
+ const grid = {
445
+ B1: "4" , C1: "14", D1: "Yes",
446
+ B2: "28", C2: "30", D2: "Yes",
447
+ B3: "31", C3: "47", D3: "Yes",
448
+ B4: "12", C4: "0" , D4: "Yes",
449
+ B5: "31", C5: "47", D5: "Yes",
450
+ B6: "13", C6: "5" , D6: "No" ,
451
+ B7: "18", C7: "43", D7: "No" ,
452
+ B8: "24", C8: "7" , D8: "Yes",
453
+ B9: "44", C9: "28", D9: "No" ,
454
+ B10: "22", C10: "23", D10: "No" ,
455
+ B11: "9" , C11: "13", D11: "No" ,
456
+
457
+ A12: '=AVERAGEIFS(B1:B11, B1:B11, ">20")',
458
+ A13: '=AVERAGEIFS(B1:B11, B1:B11, ">20", C1:C11, "<30")',
459
+ A14: '=AVERAGEIFS(B1:B11, D1:D11, "No")',
460
+ };
461
+
462
+ const gridResult = evaluateGrid(grid);
463
+ expect(gridResult.A12).toBe(30);
464
+ expect(gridResult.A13).toBe(30);
465
+ expect(gridResult.A14).toBe(21.2);
466
+ });
467
+
468
+ //----------------------------------------------------------------------------
469
+ // COUNT
470
+ //----------------------------------------------------------------------------
471
+
472
+ test("COUNT: functional tests on simple arguments", () => {
473
+ expect(evaluateCell("A1", { A1: "=count()" })).toEqual("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
474
+ expect(evaluateCell("A1", { A1: "=count( , )" })).toBe(2);
475
+ expect(evaluateCell("A1", { A1: "=count(1, 2, 3, 4)" })).toBe(4);
476
+ expect(evaluateCell("A1", { A1: "=count(1, 2, -3, 4.4)" })).toBe(4);
477
+ expect(evaluateCell("A1", { A1: "=count(1, 2, 3, , 4)" })).toBe(5);
478
+ expect(evaluateCell("A1", { A1: "=count(1 ,2, 3%)" })).toBe(3);
479
+ });
480
+
481
+ test("count: casting tests on simple arguments", () => {
482
+ expect(evaluateCell("A1", { A1: '=count(1, 2, "")' })).toBe(2);
483
+ expect(evaluateCell("A1", { A1: '=count(1, 2, " ")' })).toBe(2);
484
+ expect(evaluateCell("A1", { A1: '=count(1, 2, "3")' })).toBe(3);
485
+ expect(evaluateCell("A1", { A1: '=count(1, 2, "-3")' })).toBe(3);
486
+ expect(evaluateCell("A1", { A1: "=count(1, 2, TRUE)" })).toBe(3);
487
+ expect(evaluateCell("A1", { A1: '=count(1, 2, "TRUE")' })).toBe(2);
488
+ expect(evaluateCell("A1", { A1: '=count(1, 2, "3%")' })).toBe(3);
489
+ expect(evaluateCell("A1", { A1: '=count(1, 2, "3@")' })).toBe(2);
490
+ expect(evaluateCell("A1", { A1: '=count(1, 2, "2020-03-26")' })).toBe(3);
491
+ });
492
+
493
+ test("COUNT: functional tests on cell arguments", () => {
494
+ expect(evaluateCell("A1", { A1: "=count(A2)", A2: "" })).toBe(0);
495
+ expect(evaluateCell("A1", { A1: "=count(A2)", A2: "0" })).toBe(1);
496
+ expect(evaluateCell("A1", { A1: "=count(A2, A3)", A2: "1", A3: "42" })).toBe(2);
497
+ expect(evaluateCell("A1", { A1: "=count(A2, A3)", A2: "-1", A3: "4.2" })).toBe(2);
498
+ expect(evaluateCell("A1", { A1: "=count(A2, A3)", A2: "1", A3: "" })).toBe(1);
499
+ expect(evaluateCell("A1", { A1: "=count(A2, A3)", A2: "1", A3: "3%" })).toBe(2);
500
+ });
501
+
502
+ test("COUNT: casting tests on cell arguments", () => {
503
+ expect(evaluateCell("A1", { A1: "=count(A2, A3)", A2: "42", A3: '""' })).toBe(1);
504
+ expect(evaluateCell("A1", { A1: "=count(A2, A3)", A2: "42", A3: '" "' })).toBe(1);
505
+ expect(evaluateCell("A1", { A1: "=count(A2, A3)", A2: "42", A3: '"3"' })).toBe(1);
506
+ expect(evaluateCell("A1", { A1: "=count(A2, A3)", A2: "42", A3: '"-3"' })).toBe(1);
507
+ expect(evaluateCell("A1", { A1: "=count(A2, A3)", A2: "42", A3: "TRUE" })).toBe(1);
508
+ expect(evaluateCell("A1", { A1: "=count(A2, A3)", A2: "42", A3: '"TRUE"' })).toBe(1);
509
+ expect(evaluateCell("A1", { A1: "=count(A2, A3)", A2: "42", A3: '"3%"' })).toBe(1);
510
+ expect(evaluateCell("A1", { A1: "=count(A2, A3)", A2: "42", A3: '"3@"' })).toBe(1);
511
+ expect(evaluateCell("A1", { A1: "=count(A2, A3)", A2: "1", A3: "05/22/2020" })).toBe(2);
512
+ });
513
+
514
+ test("COUNT: functional tests on range arguments", () => {
515
+ const grid = {
516
+ A1: "=count(B2:D5)",
517
+ A2: "=count(B2:C3, B4:C4, D2:D3, D4, B5:C5)",
518
+ B2: "42.2",
519
+ C2: "TRUE",
520
+ D2: "FALSE",
521
+ B3: "",
522
+ C3: "-10.2",
523
+ D3: "Jean Neypleinlenez",
524
+ B4: '"111111"',
525
+ C4: "0",
526
+ D4: "0",
527
+ B5: "05/17/2002",
528
+ C5: '"05/17/2002"',
529
+ };
530
+ expect(evaluateCell("A1", grid)).toEqual(5);
531
+ expect(evaluateCell("A2", grid)).toEqual(5);
532
+ });
533
+
534
+ //----------------------------------------------------------------------------
535
+ // COUNTA
536
+ //----------------------------------------------------------------------------
537
+
538
+ test("COUNTA: functional tests on simple arguments", () => {
539
+ expect(evaluateCell("A1", { A1: "=COUNTA()" })).toEqual("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
540
+ expect(evaluateCell("A1", { A1: "=COUNTA( , )" })).toBe(0);
541
+ expect(evaluateCell("A1", { A1: "=COUNTA(1, 2, 3, 4)" })).toBe(4);
542
+ expect(evaluateCell("A1", { A1: "=COUNTA(1, 2, -3, 4.4)" })).toBe(4);
543
+ expect(evaluateCell("A1", { A1: "=COUNTA(1, 2, 3, , 4)" })).toBe(4);
544
+ expect(evaluateCell("A1", { A1: "=COUNTA(1 ,2, 3%)" })).toBe(3);
545
+ });
546
+
547
+ test("COUNTA: casting tests on simple arguments", () => {
548
+ expect(evaluateCell("A1", { A1: '=COUNTA(1, 2, "")' })).toBe(3);
549
+ expect(evaluateCell("A1", { A1: '=COUNTA(1, 2, " ")' })).toBe(3);
550
+ expect(evaluateCell("A1", { A1: '=COUNTA(1, 2, "3")' })).toBe(3);
551
+ expect(evaluateCell("A1", { A1: '=COUNTA(1, 2, "-3")' })).toBe(3);
552
+ expect(evaluateCell("A1", { A1: "=COUNTA(1, 2, TRUE)" })).toBe(3);
553
+ expect(evaluateCell("A1", { A1: '=COUNTA(1, 2, "TRUE")' })).toBe(3);
554
+ expect(evaluateCell("A1", { A1: '=COUNTA(1, 2, "3%")' })).toBe(3);
555
+ expect(evaluateCell("A1", { A1: '=COUNTA(1, 2, "3@")' })).toBe(3);
556
+ });
557
+
558
+ test("COUNTA: functional tests on cell arguments", () => {
559
+ expect(evaluateCell("A1", { A1: "=COUNTA(A2)", A2: "" })).toBe(0);
560
+ expect(evaluateCell("A1", { A1: "=COUNTA(A2)", A2: "0" })).toBe(1);
561
+ expect(evaluateCell("A1", { A1: "=COUNTA(A2, A3)", A2: "1", A3: "42" })).toBe(2);
562
+ expect(evaluateCell("A1", { A1: "=COUNTA(A2, A3)", A2: "-1", A3: "4.2" })).toBe(2);
563
+ expect(evaluateCell("A1", { A1: "=COUNTA(A2, A3)", A2: "1", A3: "" })).toBe(1);
564
+ expect(evaluateCell("A1", { A1: "=COUNTA(A2, A3)", A2: "1", A3: "3%" })).toBe(2);
565
+ });
566
+
567
+ test("COUNTA: casting tests on cell arguments", () => {
568
+ expect(evaluateCell("A1", { A1: "=COUNTA(A2, A3)", A2: "42", A3: '""' })).toBe(2);
569
+ expect(evaluateCell("A1", { A1: "=COUNTA(A2, A3)", A2: "42", A3: '" "' })).toBe(2);
570
+ expect(evaluateCell("A1", { A1: "=COUNTA(A2, A3)", A2: "42", A3: '"3"' })).toBe(2);
571
+ expect(evaluateCell("A1", { A1: "=COUNTA(A2, A3)", A2: "42", A3: '"-3"' })).toBe(2);
572
+ expect(evaluateCell("A1", { A1: "=COUNTA(A2, A3)", A2: "42", A3: "TRUE" })).toBe(2);
573
+ expect(evaluateCell("A1", { A1: "=COUNTA(A2, A3)", A2: "42", A3: '"TRUE"' })).toBe(2);
574
+ expect(evaluateCell("A1", { A1: "=COUNTA(A2, A3)", A2: "42", A3: '"3%"' })).toBe(2);
575
+ expect(evaluateCell("A1", { A1: "=COUNTA(A2, A3)", A2: "42", A3: '"3@"' })).toBe(2);
576
+ expect(evaluateCell("A1", { A1: "=COUNTA(A2, A3)", A2: "42", A3: '=""' })).toBe(2);
577
+ expect(evaluateCell("A1", { A1: "=COUNTA(A2, A3)", A2: "42", A3: '=" "' })).toBe(2);
578
+ expect(evaluateCell("A1", { A1: "=COUNTA(A2, A3)", A2: "42", A3: '="42"' })).toBe(2);
579
+ });
580
+
581
+ test("COUNTA: functional tests on range arguments", () => {
582
+ const grid = {
583
+ A1: "=COUNTA(B2:D4)",
584
+ A2: "=COUNTA(B2:C3, B4:C4, D2:D3, D4)",
585
+ B2: "42.2",
586
+ C2: "TRUE",
587
+ D2: "FALSE",
588
+ C3: "-10.2",
589
+ D3: "Jean Ticonstitutionnalise",
590
+ B4: '"111111"',
591
+ C4: "0",
592
+ D4: "0",
593
+ };
594
+ expect(evaluateCell("A1", grid)).toBe(8);
595
+ expect(evaluateCell("A2", grid)).toBe(8);
596
+ });
597
+
598
+ //----------------------------------------------------------------------------
599
+ // COVAR
600
+ //----------------------------------------------------------------------------
601
+
602
+ test("COVAR: functional tests on range arguments", () => {
603
+ // prettier-ignore
604
+ const grid = {
605
+ A1: "1", B1: "4",
606
+ A2: "4", B2: "5",
607
+ A3: "7", B3: "6",
608
+
609
+ A4: "4", B4: "5", C4:"6",
610
+
611
+ A5: "1", B5: "4", C5:"4",
612
+ A6: "2", B6: "5", C6:"5",
613
+ B7: "6", C7:"6",
614
+ A8: "3", C8:"test",
615
+ A9: "4", C9:"TRUE",
616
+
617
+ A10: "=COVAR(A1:A3, B1:B3)",
618
+ A11: "=COVAR(A1:A3, A4:C4)",
619
+ A12: "=COVAR(A1:A3, B1:B2)",
620
+ A13: "=COVAR(A5:A9, B5:B9)",
621
+ A14: "=COVAR(A5:A9, C5:C9)",
622
+ A15: "=COVAR(A1, B1)",
623
+ };
624
+
625
+ const gridResult = evaluateGrid(grid);
626
+ expect(gridResult.A10).toEqual(2);
627
+ expect(gridResult.A11).toEqual(2);
628
+ expect(gridResult.A12).toEqual("#ERROR"); //@compatibility: on google sheet, return #N/A
629
+ expect(gridResult.A13).toEqual(0.25);
630
+ expect(gridResult.A14).toEqual(0.25);
631
+ expect(gridResult.A15).toEqual(0);
632
+ });
633
+
634
+ //----------------------------------------------------------------------------
635
+ // COVARIANCE.P
636
+ //----------------------------------------------------------------------------
637
+
638
+ test("COVARIANCE.P: functional tests on range arguments", () => {
639
+ // prettier-ignore
640
+ const grid = {
641
+ A1: "1", B1: "4",
642
+ A2: "4", B2: "5",
643
+ A3: "7", B3: "6",
644
+
645
+ A4: "4", B4: "5", C4:"6",
646
+
647
+ A5: "1", B5: "4", C5:"4",
648
+ A6: "2", B6: "5", C6:"5",
649
+ B7: "6", C7:"6",
650
+ A8: "3", C8:"test",
651
+ A9: "4", C9:"TRUE",
652
+
653
+ A10: "=COVARIANCE.P(A1:A3, B1:B3)",
654
+ A11: "=COVARIANCE.P(A1:A3, A4:C4)",
655
+ A12: "=COVARIANCE.P(A1:A3, B1:B2)",
656
+ A13: "=COVARIANCE.P(A5:A9, B5:B9)",
657
+ A14: "=COVARIANCE.P(A5:A9, C5:C9)",
658
+ A15: "=COVARIANCE.P(A1, B1)",
659
+ };
660
+
661
+ const gridResult = evaluateGrid(grid);
662
+ expect(gridResult.A10).toEqual(2);
663
+ expect(gridResult.A11).toEqual(2);
664
+ expect(gridResult.A12).toEqual("#ERROR"); //@compatibility: on google sheet, return #N/A
665
+ expect(gridResult.A13).toEqual(0.25);
666
+ expect(gridResult.A14).toEqual(0.25);
667
+ expect(gridResult.A15).toEqual(0);
668
+ });
669
+
670
+ //----------------------------------------------------------------------------
671
+ // COVARIANCE.S
672
+ //----------------------------------------------------------------------------
673
+
674
+ test("COVARIANCE.S: functional tests on range arguments", () => {
675
+ // prettier-ignore
676
+ const grid = {
677
+ A1: "1", B1: "4",
678
+ A2: "4", B2: "5",
679
+ A3: "7", B3: "6",
680
+
681
+ A4: "4", B4: "5", C4:"6",
682
+
683
+ A5: "1", B5: "4", C5:"4",
684
+ A6: "2", B6: "5", C6:"5",
685
+ B7: "6", C7:"6",
686
+ A8: "3", C8:"test",
687
+ A9: "4", C9:"TRUE",
688
+
689
+ A10: "=COVARIANCE.S(A1:A3, B1:B3)",
690
+ A11: "=COVARIANCE.S(A1:A3, A4:C4)",
691
+ A12: "=COVARIANCE.S(A1:A3, B1:B2)",
692
+ A13: "=COVARIANCE.S(A5:A9, B5:B9)",
693
+ A14: "=COVARIANCE.S(A5:A9, C5:C9)",
694
+ A15: "=COVARIANCE.S(A1, B1)",
695
+ };
696
+
697
+ const gridResult = evaluateGrid(grid);
698
+ expect(gridResult.A10).toEqual(3);
699
+ expect(gridResult.A11).toEqual(3);
700
+ expect(gridResult.A12).toEqual("#ERROR"); //@compatibility: on google sheet, return #N/A
701
+ expect(gridResult.A13).toEqual(0.5);
702
+ expect(gridResult.A14).toEqual(0.5);
703
+ expect(gridResult.A15).toEqual("#ERROR"); //@compatibility: on google sheet, return #NUM
704
+ });
705
+
706
+ //----------------------------------------------------------------------------
707
+ // LARGE
708
+ //----------------------------------------------------------------------------
709
+
710
+ test("LARGE: functional tests on simple arguments", () => {
711
+ expect(evaluateCell("A1", { A1: "=LARGE()" })).toBe("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
712
+ expect(evaluateCell("A1", { A1: "=LARGE( , )" })).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
713
+ expect(evaluateCell("A1", { A1: "=LARGE( , 0)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
714
+ expect(evaluateCell("A1", { A1: "=LARGE(2, 0)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
715
+ expect(evaluateCell("A1", { A1: "=LARGE(2, 1)" })).toBe(2);
716
+ expect(evaluateCell("A1", { A1: "=LARGE(2, 2)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
717
+ expect(evaluateCell("A1", { A1: "=LARGE(2, -1)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
718
+ expect(evaluateCell("A1", { A1: "=LARGE(2, 1.9)" })).toBe(2);
719
+ });
720
+
721
+ test("LARGE: casting tests on simple arguments", () => {
722
+ expect(evaluateCell("A1", { A1: '=LARGE(2, "1")' })).toBe(2);
723
+ expect(evaluateCell("A1", { A1: "=LARGE(2, TRUE)" })).toBe(2);
724
+ expect(evaluateCell("A1", { A1: "=LARGE(2, FALSE)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
725
+ expect(evaluateCell("A1", { A1: "=LARGE(TRUE, 1)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
726
+ expect(evaluateCell("A1", { A1: "=LARGE(False, 1)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
727
+ expect(evaluateCell("A1", { A1: '=LARGE("test", 1)' })).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
728
+ expect(evaluateCell("A1", { A1: '=LARGE("2", 1)' })).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
729
+ });
730
+
731
+ test("LARGE: functional tests on cell arguments", () => {
732
+ expect(evaluateCell("A1", { A1: "=LARGE(A2:A4, A5)", A2: "", A3: "", A4: "", A5: "0" })).toBe(
733
+ "#ERROR"
734
+ ); // @compatibility: on google sheets, return #NUM!
735
+ expect(evaluateCell("A1", { A1: "=LARGE(A2:A4, A5)", A2: "", A3: "", A4: "", A5: "1" })).toBe(
736
+ "#ERROR"
737
+ ); // @compatibility: on google sheets, return #NUM!
738
+ expect(
739
+ evaluateCell("A1", { A1: "=LARGE(A2:A4, A5)", A2: "3", A3: "1", A4: "2", A5: "1" })
740
+ ).toBe(3);
741
+ expect(
742
+ evaluateCell("A1", { A1: "=LARGE(A2:A4, A5)", A2: "3", A3: "1", A4: "2", A5: "2" })
743
+ ).toBe(2);
744
+ expect(
745
+ evaluateCell("A1", { A1: "=LARGE(A2:A4, A5)", A2: "3", A3: "-11", A4: "2", A5: "3" })
746
+ ).toBe(-11);
747
+ expect(
748
+ evaluateCell("A1", { A1: "=LARGE(A2:A4, A5)", A2: "3", A3: "1", A4: "2", A5: "4" })
749
+ ).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
750
+ expect(evaluateCell("A1", { A1: "=LARGE(A2:A4, A5)", A2: "3", A3: "", A4: "2", A5: "3" })).toBe(
751
+ "#ERROR"
752
+ ); // @compatibility: on google sheets, return #NUM!
753
+ expect(
754
+ evaluateCell("A1", { A1: "=LARGE(A2:A4, A5)", A2: "03/01/2020", A3: "-11", A4: "2", A5: "1" })
755
+ ).toBe(43891);
756
+ });
757
+
758
+ test("LARGE: casting tests on cell arguments", () => {
759
+ expect(
760
+ evaluateCell("A1", { A1: "=LARGE(A2:A4, A5)", A2: '"3"', A3: "", A4: "2", A5: "1" })
761
+ ).toBe(2);
762
+ expect(
763
+ evaluateCell("A1", { A1: "=LARGE(A2:A4, A5)", A2: '"3"', A3: "", A4: "", A5: "1" })
764
+ ).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
765
+ expect(
766
+ evaluateCell("A1", { A1: "=LARGE(A2:A4, A5)", A2: '="3"', A3: "", A4: "2", A5: "1" })
767
+ ).toBe(2);
768
+ expect(
769
+ evaluateCell("A1", {
770
+ A1: "=LARGE(A2:A4, A5)",
771
+ A2: "lol",
772
+ A3: "looool",
773
+ A4: "xdtrololol",
774
+ A5: "1",
775
+ })
776
+ ).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
777
+ expect(
778
+ evaluateCell("A1", { A1: "=LARGE(A2:A4, A5)", A2: '"3"', A3: '"1"', A4: '"2"', A5: "1" })
779
+ ).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
780
+ expect(
781
+ evaluateCell("A1", { A1: "=LARGE(A2:A4, A5)", A2: "TRUE", A3: "0", A4: "0", A5: "1" })
782
+ ).toBe(0);
783
+ });
784
+
785
+ //----------------------------------------------------------------------------
786
+ // MAX
787
+ //----------------------------------------------------------------------------
788
+
789
+ test("MAX: functional tests on simple arguments", () => {
790
+ expect(evaluateCell("A1", { A1: "=MAX()" })).toEqual("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
791
+ expect(evaluateCell("A1", { A1: "=MAX(,)" })).toBe(0);
792
+ expect(evaluateCell("A1", { A1: "=MAX(0)" })).toBe(0);
793
+ expect(evaluateCell("A1", { A1: "=MAX(1, 2, 3, 1, 2)" })).toBe(3);
794
+ expect(evaluateCell("A1", { A1: "=MAX(1, , 2, , 3)" })).toBe(3);
795
+ expect(evaluateCell("A1", { A1: "=MAX(1.5, 1.4)" })).toBe(1.5);
796
+ expect(evaluateCell("A1", { A1: "=MAX(-42.42)" })).toBe(-42.42);
797
+ expect(evaluateCell("A1", { A1: '=MAX("Jean Fume", "Jean Dreu")' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
798
+ expect(evaluateCell("A1", { A1: '=MAX("")' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
799
+ expect(evaluateCell("A1", { A1: '=MAX(" ")' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
800
+ expect(evaluateCell("A1", { A1: '=MAX("2", "-2")' })).toBe(2);
801
+ expect(evaluateCell("A1", { A1: '=MAX("2", "")' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
802
+ expect(evaluateCell("A1", { A1: '=MAX("2", " ")' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
803
+ expect(evaluateCell("A1", { A1: "=MAX(TRUE, FALSE)" })).toBe(1);
804
+ expect(evaluateCell("A1", { A1: '=MAX(0, "0", TRUE)' })).toBe(1);
805
+ expect(evaluateCell("A1", { A1: '=MAX("08/08/08", "10/10/10")' })).toBe(40461);
806
+ });
807
+
808
+ test("MAX: functional tests on cell arguments", () => {
809
+ expect(evaluateCell("A1", { A1: "=MAX(A2)", A2: "" })).toBe(0);
810
+ expect(evaluateCell("A1", { A1: "=MAX(A2)", A2: " " })).toBe(0);
811
+ expect(evaluateCell("A1", { A1: "=MAX(A2)", A2: "," })).toBe(0);
812
+ expect(evaluateCell("A1", { A1: "=MAX(A2)", A2: "0" })).toBe(0);
813
+ expect(evaluateCell("A1", { A1: "=MAX(A2, A3)", A2: "1", A3: "2" })).toBe(2);
814
+ expect(evaluateCell("A1", { A1: "=MAX(A2, A3, A4)", A2: "1", A3: "", A4: "2" })).toBe(2);
815
+ expect(
816
+ evaluateCell("A1", { A1: "=MAX(A2, A3, A4)", A2: "1.5", A3: "-10", A4: "Jean Terre" })
817
+ ).toBe(1.5);
818
+ expect(evaluateCell("A1", { A1: "=MAX(A2, A3)", A2: "", A3: "" })).toBe(0);
819
+ expect(evaluateCell("A1", { A1: "=MAX(A2, A3)", A2: " ", A3: "" })).toBe(0);
820
+ expect(evaluateCell("A1", { A1: "=MAX(A2, A3)", A2: "", A3: '=" "' })).toBe(0);
821
+ expect(evaluateCell("A1", { A1: "=MAX(A2, A3)", A2: " ", A3: '=" "' })).toBe(0);
822
+ expect(evaluateCell("A1", { A1: "=MAX(A2, A3)", A2: " ", A3: '=" "' })).toBe(0);
823
+ expect(evaluateCell("A1", { A1: "=MAX(A2, A3)", A2: " ", A3: '=" "' })).toBe(0);
824
+ expect(evaluateCell("A1", { A1: "=MAX(A2, A3)", A2: "24", A3: "42" })).toBe(42);
825
+ expect(evaluateCell("A1", { A1: "=MAX(A2, A3)", A2: "24", A3: '"42"' })).toBe(24);
826
+ expect(evaluateCell("A1", { A1: "=MAX(A2, A3)", A2: "24", A3: "=42" })).toBe(42);
827
+ expect(evaluateCell("A1", { A1: "=MAX(A2, A3)", A2: "24", A3: '="42"' })).toBe(24);
828
+ expect(evaluateCell("A1", { A1: "=MAX(A2, A3)", A2: '"24"', A3: '"42"' })).toBe(0);
829
+ expect(evaluateCell("A1", { A1: "=MAX(A2, A3)", A2: '"24"', A3: "=42" })).toBe(42);
830
+ expect(evaluateCell("A1", { A1: "=MAX(A2, A3)", A2: '"24"', A3: '="42"' })).toBe(0);
831
+ expect(evaluateCell("A1", { A1: "=MAX(A2, A3)", A2: "=24", A3: "=42" })).toBe(42);
832
+ expect(evaluateCell("A1", { A1: "=MAX(A2, A3)", A2: "=24", A3: '="42"' })).toBe(24);
833
+ expect(evaluateCell("A1", { A1: "=MAX(A2, A3)", A2: '="24"', A3: '="42"' })).toBe(0);
834
+ expect(evaluateCell("A1", { A1: "=MAX(A2, A3)", A2: "08/08/08", A3: "10/10/10" })).toBe(40461);
835
+ });
836
+
837
+ test("MAX: functional tests on simple and cell arguments", () => {
838
+ expect(evaluateCell("A1", { A1: "=MAX(A2,)", A2: "" })).toBe(0);
839
+ expect(evaluateCell("A1", { A1: "=MAX(A2,)", A2: " " })).toBe(0);
840
+ expect(evaluateCell("A1", { A1: "=MAX(A2,)", A2: '=""' })).toBe(0);
841
+ expect(evaluateCell("A1", { A1: "=MAX(A2,)", A2: '=" "' })).toBe(0);
842
+ expect(evaluateCell("A1", { A1: '=MAX(A2, "")', A2: "" })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
843
+ expect(evaluateCell("A1", { A1: '=MAX(A2, "")', A2: " " })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
844
+ expect(evaluateCell("A1", { A1: '=MAX(A2, "")', A2: '=""' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
845
+ expect(evaluateCell("A1", { A1: '=MAX(A2, "")', A2: '=" "' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
846
+ expect(evaluateCell("A1", { A1: '=MAX(A2, " ")', A2: "" })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
847
+ expect(evaluateCell("A1", { A1: '=MAX(A2, " ")', A2: " " })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
848
+ expect(evaluateCell("A1", { A1: '=MAX(A2, " ")', A2: '=""' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
849
+ expect(evaluateCell("A1", { A1: '=MAX(A2, " ")', A2: '=" "' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
850
+ expect(evaluateCell("A1", { A1: '=MAX(24, "42")' })).toBe(42);
851
+ expect(evaluateCell("A1", { A1: "=MAX(A2, 24)", A2: "42" })).toBe(42);
852
+ expect(evaluateCell("A1", { A1: "=MAX(A2, 24)", A2: '"42"' })).toBe(24);
853
+ expect(evaluateCell("A1", { A1: "=MAX(A2, 24)", A2: "=42" })).toBe(42);
854
+ expect(evaluateCell("A1", { A1: "=MAX(A2, 24)", A2: '="42"' })).toBe(24);
855
+ expect(evaluateCell("A1", { A1: '=MAX(A2, "24")', A2: "42" })).toBe(42);
856
+ expect(evaluateCell("A1", { A1: '=MAX(A2, "24")', A2: '"42"' })).toBe(24);
857
+ expect(evaluateCell("A1", { A1: '=MAX(A2, "24")', A2: "=42" })).toBe(42);
858
+ expect(evaluateCell("A1", { A1: '=MAX(A2, "24")', A2: '="42"' })).toBe(24);
859
+ expect(evaluateCell("A1", { A1: "=MAX(A2, TRUE)", A2: "0" })).toBe(1);
860
+ expect(evaluateCell("A1", { A1: "=MAX(A2, TRUE)", A2: '"0"' })).toBe(1);
861
+ expect(evaluateCell("A1", { A1: "=MAX(A2, TRUE)", A2: "=0" })).toBe(1);
862
+ expect(evaluateCell("A1", { A1: "=MAX(A2, TRUE)", A2: '="0"' })).toBe(1);
863
+ });
864
+
865
+ test("MAX: functional tests on range arguments", () => {
866
+ const grid = {
867
+ A1: "=MAX(B2:D3,B4:D4,E2:E3,E4)",
868
+
869
+ A2: "=MAX(B2:E2)",
870
+ A3: "=MAX(B3:E3)",
871
+ A4: "=MAX(B4:E4)",
872
+
873
+ B1: "=MAX(B2:B4)",
874
+ C1: "=MAX(C2:C4)",
875
+ D1: "=MAX(D2:D4)",
876
+ E1: "=MAX(E2:E4)",
877
+
878
+ B2: "=3",
879
+ C2: "3",
880
+ D2: '"9"',
881
+ E2: '="9"',
882
+
883
+ B3: '=" "',
884
+ C3: "0",
885
+ D3: "Jean PERRIN (10 de retrouvés)",
886
+ E3: '"Jean Boirébienunautre"',
887
+
888
+ B4: " ",
889
+ C4: '""',
890
+ D4: '=""',
891
+ E4: '" "',
892
+ };
893
+
894
+ const gridResult = evaluateGrid(grid);
895
+ expect(gridResult.A1).toEqual(3);
896
+ expect(gridResult.A2).toEqual(3);
897
+ expect(gridResult.A3).toEqual(0);
898
+ expect(gridResult.A4).toEqual(0);
899
+ expect(gridResult.B1).toEqual(3);
900
+ expect(gridResult.C1).toEqual(3);
901
+ expect(gridResult.D1).toEqual(0);
902
+ expect(gridResult.E1).toEqual(0);
903
+ });
904
+
905
+ //----------------------------------------------------------------------------
906
+ // MAXA
907
+ //----------------------------------------------------------------------------
908
+
909
+ test("MAXA: functional tests on simple arguments", () => {
910
+ expect(evaluateCell("A1", { A1: "=MAXA()" })).toEqual("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
911
+ expect(evaluateCell("A1", { A1: "=MAXA(,)" })).toBe(0);
912
+ expect(evaluateCell("A1", { A1: "=MAXA(0)" })).toBe(0);
913
+ expect(evaluateCell("A1", { A1: "=MAXA(1, 2, 3, 1, 2)" })).toBe(3);
914
+ expect(evaluateCell("A1", { A1: "=MAXA(-1, , -2, , -3)" })).toBe(0);
915
+ expect(evaluateCell("A1", { A1: "=MAXA(1.5, 1.4)" })).toBe(1.5);
916
+ expect(evaluateCell("A1", { A1: "=MAXA(-42.42)" })).toBe(-42.42);
917
+ expect(evaluateCell("A1", { A1: '=MAXA("Jean Fume", "Jean Dreu")' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
918
+ expect(evaluateCell("A1", { A1: '=MAXA("")' })).toBe(0);
919
+ expect(evaluateCell("A1", { A1: '=MAXA(" ")' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
920
+ expect(evaluateCell("A1", { A1: '=MAXA("2", "-2")' })).toBe(2);
921
+ expect(evaluateCell("A1", { A1: '=MAXA("2", " -2 ")' })).toBe(2);
922
+ expect(evaluateCell("A1", { A1: '=MAXA("2", "")' })).toBe(2);
923
+ expect(evaluateCell("A1", { A1: '=MAXA("2", " ")' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
924
+ expect(evaluateCell("A1", { A1: "=MAXA(TRUE, FALSE)" })).toBe(1);
925
+ expect(evaluateCell("A1", { A1: '=MAXA(0, "0", TRUE)' })).toBe(1);
926
+ expect(evaluateCell("A1", { A1: '=MAXA("10/10/2010", "8/8/2008")' })).toBe(40461);
927
+ });
928
+
929
+ test("MAXA: functional tests on cell arguments", () => {
930
+ expect(evaluateCell("A1", { A1: "=MAXA(A2)", A2: "" })).toBe(0);
931
+ expect(evaluateCell("A1", { A1: "=MAXA(A2)", A2: " " })).toBe(0);
932
+ expect(evaluateCell("A1", { A1: "=MAXA(A2)", A2: "," })).toBe(0);
933
+ expect(evaluateCell("A1", { A1: "=MAXA(A2)", A2: "0" })).toBe(0);
934
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, A3)", A2: "1", A3: "2" })).toBe(2);
935
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, A3, A4)", A2: "-1", A3: "", A4: "-2" })).toBe(-1);
936
+ expect(
937
+ evaluateCell("A1", { A1: "=MAXA(A2, A3, A4)", A2: "-1.5", A3: "-10", A4: "Jean Terre" })
938
+ ).toBe(0);
939
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, A3)", A2: "", A3: "" })).toBe(0);
940
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, A3)", A2: " ", A3: "" })).toBe(0);
941
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, A3)", A2: "", A3: '=" "' })).toBe(0);
942
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, A3)", A2: " ", A3: '=" "' })).toBe(0);
943
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, A3)", A2: " ", A3: '=" "' })).toBe(0);
944
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, A3)", A2: " ", A3: '=" "' })).toBe(0);
945
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, A3)", A2: "10/10/2010", A3: "8/8/2008" })).toBe(
946
+ 40461
947
+ );
948
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, A3)", A2: "24", A3: "42" })).toBe(42);
949
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, A3)", A2: "24", A3: '"42"' })).toBe(24);
950
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, A3)", A2: "24", A3: "=42" })).toBe(42);
951
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, A3)", A2: "24", A3: '="42"' })).toBe(24);
952
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, A3)", A2: '"24"', A3: '"42"' })).toBe(0);
953
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, A3)", A2: '"24"', A3: "=42" })).toBe(42);
954
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, A3)", A2: '"24"', A3: '="42"' })).toBe(0);
955
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, A3)", A2: "=24", A3: "=42" })).toBe(42);
956
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, A3)", A2: "=24", A3: '="42"' })).toBe(24);
957
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, A3)", A2: '="24"', A3: '="42"' })).toBe(0);
958
+ });
959
+
960
+ test("MAXA: functional tests on simple and cell arguments", () => {
961
+ expect(evaluateCell("A1", { A1: "=MAXA(A2,)", A2: "" })).toBe(0);
962
+ expect(evaluateCell("A1", { A1: "=MAXA(A2,)", A2: " " })).toBe(0);
963
+ expect(evaluateCell("A1", { A1: "=MAXA(A2,)", A2: '=""' })).toBe(0);
964
+ expect(evaluateCell("A1", { A1: "=MAXA(A2,)", A2: '=" "' })).toBe(0);
965
+ expect(evaluateCell("A1", { A1: '=MAXA(A2, "")', A2: "" })).toBe(0);
966
+ expect(evaluateCell("A1", { A1: '=MAXA(A2, "")', A2: " " })).toBe(0);
967
+ expect(evaluateCell("A1", { A1: '=MAXA(A2, "")', A2: '=""' })).toBe(0);
968
+ expect(evaluateCell("A1", { A1: '=MAXA(A2, "")', A2: '=" "' })).toBe(0);
969
+ expect(evaluateCell("A1", { A1: '=MAXA(A2, " ")', A2: "" })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
970
+ expect(evaluateCell("A1", { A1: '=MAXA(A2, " ")', A2: " " })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
971
+ expect(evaluateCell("A1", { A1: '=MAXA(A2, " ")', A2: '=""' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
972
+ expect(evaluateCell("A1", { A1: '=MAXA(A2, " ")', A2: '=" "' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
973
+ expect(evaluateCell("A1", { A1: '=MAXA(24, "42")' })).toBe(42);
974
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, 24)", A2: "42" })).toBe(42);
975
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, 24)", A2: '"42"' })).toBe(24);
976
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, 24)", A2: "=42" })).toBe(42);
977
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, 24)", A2: '="42"' })).toBe(24);
978
+ expect(evaluateCell("A1", { A1: '=MAXA(A2, "24")', A2: "42" })).toBe(42);
979
+ expect(evaluateCell("A1", { A1: '=MAXA(A2, "24")', A2: '"42"' })).toBe(24);
980
+ expect(evaluateCell("A1", { A1: '=MAXA(A2, "24")', A2: "=42" })).toBe(42);
981
+ expect(evaluateCell("A1", { A1: '=MAXA(A2, "24")', A2: '="42"' })).toBe(24);
982
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, TRUE)", A2: "0" })).toBe(1);
983
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, TRUE)", A2: '"0"' })).toBe(1);
984
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, TRUE)", A2: "=0" })).toBe(1);
985
+ expect(evaluateCell("A1", { A1: "=MAXA(A2, TRUE)", A2: '="0"' })).toBe(1);
986
+ });
987
+
988
+ test("MAXA: functional tests on range arguments", () => {
989
+ const grid = {
990
+ A1: "=MAXA(B2:D3,B4:D4,E2:E3,E4)",
991
+
992
+ A2: "=MAXA(B2:F2)",
993
+ A3: "=MAXA(B3:F3)",
994
+ A4: "=MAXA(B4:F4)",
995
+
996
+ B1: "=MAXA(B2:B4)",
997
+ C1: "=MAXA(C2:C4)",
998
+ D1: "=MAXA(D2:D4)",
999
+ E1: "=MAXA(E2:E4)",
1000
+ F1: "=MAXA(F2:F4)",
1001
+
1002
+ B2: "=-3",
1003
+ C2: "-3",
1004
+ D2: '"9"',
1005
+ E2: '="9"',
1006
+ F2: "-42",
1007
+
1008
+ B3: '=" "',
1009
+ C3: "3",
1010
+ D3: "Jean Balletoultan",
1011
+ E3: '"Jean Découvrepleindautres"',
1012
+ F3: "TRUE",
1013
+
1014
+ B4: "3",
1015
+ C4: '""',
1016
+ D4: '=""',
1017
+ E4: '" "',
1018
+ F4: "-100",
1019
+ };
1020
+
1021
+ const gridResult = evaluateGrid(grid);
1022
+ expect(gridResult.A1).toEqual(3);
1023
+ expect(gridResult.A2).toEqual(0);
1024
+ expect(gridResult.A3).toEqual(3);
1025
+ expect(gridResult.A4).toEqual(3);
1026
+ expect(gridResult.B1).toEqual(3);
1027
+ expect(gridResult.C1).toEqual(3);
1028
+ expect(gridResult.D1).toEqual(0);
1029
+ expect(gridResult.E1).toEqual(0);
1030
+ expect(gridResult.F1).toEqual(1);
1031
+ });
1032
+
1033
+ //----------------------------------------------------------------------------
1034
+ // MAXIFS
1035
+ //----------------------------------------------------------------------------
1036
+
1037
+ test("MAXIFS: functional tests on range", () => {
1038
+ // prettier-ignore
1039
+ const grid = {
1040
+ B1: "4" , C1: "14", D1: "Yes",
1041
+ B2: "28", C2: "30", D2: "Yes",
1042
+ B3: "31", C3: "47", D3: "Yes",
1043
+ B4: "12", C4: "0" , D4: "Yes",
1044
+ B5: "31", C5: "47", D5: "Yes",
1045
+ B6: "13", C6: "5" , D6: "No" ,
1046
+ B7: "18", C7: "43", D7: "No" ,
1047
+ B8: "24", C8: "7" , D8: "Yes",
1048
+ B9: "44", C9: "28", D9: "No" ,
1049
+ B10: "22", C10: "23", D10: "No" ,
1050
+ B11: "9" , C11: "13", D11: "No" ,
1051
+
1052
+ A12: '=MAXIFS(B1:B11, B1:B11, "<20")',
1053
+ A13: '=MAXIFS(B1:B11, B1:B11, ">20", C1:C11, "<28")',
1054
+ A14: '=MAXIFS(B1:B11, D1:D11, "yes")',
1055
+ };
1056
+
1057
+ const gridResult = evaluateGrid(grid);
1058
+ expect(gridResult.A12).toBe(18);
1059
+ expect(gridResult.A13).toBe(24);
1060
+ expect(gridResult.A14).toBe(31);
1061
+ });
1062
+
1063
+ //----------------------------------------------------------------------------
1064
+ // MIN
1065
+ //----------------------------------------------------------------------------
1066
+
1067
+ test("MIN: functional tests on simple arguments", () => {
1068
+ expect(evaluateCell("A1", { A1: "=MIN()" })).toEqual("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
1069
+ expect(evaluateCell("A1", { A1: "=MIN(,)" })).toBe(0);
1070
+ expect(evaluateCell("A1", { A1: "=MIN(0)" })).toBe(0);
1071
+ expect(evaluateCell("A1", { A1: "=MIN(1, 2, 3, 1, 2)" })).toBe(1);
1072
+ expect(evaluateCell("A1", { A1: "=MIN(1, , 2, , 3)" })).toBe(0);
1073
+ expect(evaluateCell("A1", { A1: "=MIN(1.5, 1.4)" })).toBe(1.4);
1074
+ expect(evaluateCell("A1", { A1: "=MIN(42.42)" })).toBe(42.42);
1075
+ expect(evaluateCell("A1", { A1: '=MIN("Jean Fume", "Jean Dreu")' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1076
+ expect(evaluateCell("A1", { A1: '=MIN("")' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1077
+ expect(evaluateCell("A1", { A1: '=MIN(" ")' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1078
+ expect(evaluateCell("A1", { A1: '=MIN("2", "-2")' })).toBe(-2);
1079
+ expect(evaluateCell("A1", { A1: '=MIN("2", "")' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1080
+ expect(evaluateCell("A1", { A1: '=MIN("2", " ")' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1081
+ expect(evaluateCell("A1", { A1: "=MIN(TRUE, FALSE)" })).toBe(0);
1082
+ expect(evaluateCell("A1", { A1: '=MIN(0, "0", TRUE)' })).toBe(0);
1083
+ expect(evaluateCell("A1", { A1: '=MIN("08/08/08", "10/10/10")' })).toBe(39668);
1084
+ });
1085
+
1086
+ test("MIN: functional tests on cell arguments", () => {
1087
+ expect(evaluateCell("A1", { A1: "=MIN(A2)", A2: "" })).toBe(0);
1088
+ expect(evaluateCell("A1", { A1: "=MIN(A2)", A2: " " })).toBe(0);
1089
+ expect(evaluateCell("A1", { A1: "=MIN(A2)", A2: "," })).toBe(0);
1090
+ expect(evaluateCell("A1", { A1: "=MIN(A2)", A2: "0" })).toBe(0);
1091
+ expect(evaluateCell("A1", { A1: "=MIN(A2, A3)", A2: "1", A3: "2" })).toBe(1);
1092
+ expect(evaluateCell("A1", { A1: "=MIN(A2, A3, A4)", A2: "1", A3: "", A4: "2" })).toBe(1);
1093
+ expect(
1094
+ evaluateCell("A1", { A1: "=MIN(A2, A3, A4)", A2: "1.5", A3: "-10", A4: "Jean Terre" })
1095
+ ).toBe(-10);
1096
+ expect(evaluateCell("A1", { A1: "=MIN(A2, A3)", A2: "", A3: "" })).toBe(0);
1097
+ expect(evaluateCell("A1", { A1: "=MIN(A2, A3)", A2: " ", A3: "" })).toBe(0);
1098
+ expect(evaluateCell("A1", { A1: "=MIN(A2, A3)", A2: "", A3: '=" "' })).toBe(0);
1099
+ expect(evaluateCell("A1", { A1: "=MIN(A2, A3)", A2: " ", A3: '=" "' })).toBe(0);
1100
+ expect(evaluateCell("A1", { A1: "=MIN(A2, A3)", A2: " ", A3: '=" "' })).toBe(0);
1101
+ expect(evaluateCell("A1", { A1: "=MIN(A2, A3)", A2: " ", A3: '=" "' })).toBe(0);
1102
+ expect(evaluateCell("A1", { A1: "=MIN(A2, A3)", A2: "08/08/08", A3: "10/10/10" })).toBe(39668);
1103
+ expect(evaluateCell("A1", { A1: "=MIN(A2, A3)", A2: "42", A3: "24" })).toBe(24);
1104
+ expect(evaluateCell("A1", { A1: "=MIN(A2, A3)", A2: "42", A3: '"24"' })).toBe(42);
1105
+ expect(evaluateCell("A1", { A1: "=MIN(A2, A3)", A2: "42", A3: "=24" })).toBe(24);
1106
+ expect(evaluateCell("A1", { A1: "=MIN(A2, A3)", A2: "42", A3: '="24"' })).toBe(42);
1107
+ expect(evaluateCell("A1", { A1: "=MIN(A2, A3)", A2: '"42"', A3: '"24"' })).toBe(0);
1108
+ expect(evaluateCell("A1", { A1: "=MIN(A2, A3)", A2: '"42"', A3: "=24" })).toBe(24);
1109
+ expect(evaluateCell("A1", { A1: "=MIN(A2, A3)", A2: '"42"', A3: '="24"' })).toBe(0);
1110
+ expect(evaluateCell("A1", { A1: "=MIN(A2, A3)", A2: "=42", A3: "=24" })).toBe(24);
1111
+ expect(evaluateCell("A1", { A1: "=MIN(A2, A3)", A2: "=42", A3: '="24"' })).toBe(42);
1112
+ expect(evaluateCell("A1", { A1: "=MIN(A2, A3)", A2: '="42"', A3: '="24"' })).toBe(0);
1113
+ });
1114
+
1115
+ test("MIN: functional tests on simple and cell arguments", () => {
1116
+ expect(evaluateCell("A1", { A1: "=MIN(A2,)", A2: "" })).toBe(0);
1117
+ expect(evaluateCell("A1", { A1: "=MIN(A2,)", A2: " " })).toBe(0);
1118
+ expect(evaluateCell("A1", { A1: "=MIN(A2,)", A2: '=""' })).toBe(0);
1119
+ expect(evaluateCell("A1", { A1: "=MIN(A2,)", A2: '=" "' })).toBe(0);
1120
+ expect(evaluateCell("A1", { A1: '=MIN(A2, "")', A2: "" })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1121
+ expect(evaluateCell("A1", { A1: '=MIN(A2, "")', A2: " " })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1122
+ expect(evaluateCell("A1", { A1: '=MIN(A2, "")', A2: '=""' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1123
+ expect(evaluateCell("A1", { A1: '=MIN(A2, "")', A2: '=" "' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1124
+ expect(evaluateCell("A1", { A1: '=MIN(A2, " ")', A2: "" })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1125
+ expect(evaluateCell("A1", { A1: '=MIN(A2, " ")', A2: " " })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1126
+ expect(evaluateCell("A1", { A1: '=MIN(A2, " ")', A2: '=""' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1127
+ expect(evaluateCell("A1", { A1: '=MIN(A2, " ")', A2: '=" "' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1128
+ expect(evaluateCell("A1", { A1: '=MIN(42, "24")' })).toBe(24);
1129
+ expect(evaluateCell("A1", { A1: "=MIN(A2, 42)", A2: "24" })).toBe(24);
1130
+ expect(evaluateCell("A1", { A1: "=MIN(A2, 42)", A2: '"24"' })).toBe(42);
1131
+ expect(evaluateCell("A1", { A1: "=MIN(A2, 42)", A2: "=24" })).toBe(24);
1132
+ expect(evaluateCell("A1", { A1: "=MIN(A2, 42)", A2: '="24"' })).toBe(42);
1133
+ expect(evaluateCell("A1", { A1: '=MIN(A2, "42")', A2: "24" })).toBe(24);
1134
+ expect(evaluateCell("A1", { A1: '=MIN(A2, "42")', A2: '"24"' })).toBe(42);
1135
+ expect(evaluateCell("A1", { A1: '=MIN(A2, "42")', A2: "=24" })).toBe(24);
1136
+ expect(evaluateCell("A1", { A1: '=MIN(A2, "42")', A2: '="24"' })).toBe(42);
1137
+ expect(evaluateCell("A1", { A1: "=MIN(A2, TRUE)", A2: "0" })).toBe(0);
1138
+ expect(evaluateCell("A1", { A1: "=MIN(A2, TRUE)", A2: '"0"' })).toBe(1);
1139
+ expect(evaluateCell("A1", { A1: "=MIN(A2, TRUE)", A2: "=0" })).toBe(0);
1140
+ expect(evaluateCell("A1", { A1: "=MIN(A2, TRUE)", A2: '="0"' })).toBe(1);
1141
+ });
1142
+
1143
+ test("MIN: functional tests on range arguments", () => {
1144
+ const grid = {
1145
+ A1: "=MIN(B2:D3,B4:D4,E2:E3,E4)",
1146
+
1147
+ A2: "=MIN(B2:E2)",
1148
+ A3: "=MIN(B3:E3)",
1149
+ A4: "=MIN(B4:E4)",
1150
+
1151
+ B1: "=MIN(B2:B4)",
1152
+ C1: "=MIN(C2:C4)",
1153
+ D1: "=MIN(D2:D4)",
1154
+ E1: "=MIN(E2:E4)",
1155
+
1156
+ B2: "=9",
1157
+ C2: "9",
1158
+ D2: '"0"',
1159
+ E2: '="0"',
1160
+
1161
+ B3: '=" "',
1162
+ C3: "3",
1163
+ D3: "Jean PERRIN (10 de retrouvés)",
1164
+ E3: '"Jean Boirébienunautre"',
1165
+
1166
+ B4: " ",
1167
+ C4: '""',
1168
+ D4: '=""',
1169
+ E4: '" "',
1170
+ };
1171
+
1172
+ const gridResult = evaluateGrid(grid);
1173
+ expect(gridResult.A1).toEqual(3);
1174
+ expect(gridResult.A2).toEqual(9);
1175
+ expect(gridResult.A3).toEqual(3);
1176
+ expect(gridResult.A4).toEqual(0);
1177
+ expect(gridResult.B1).toEqual(9);
1178
+ expect(gridResult.C1).toEqual(3);
1179
+ expect(gridResult.D1).toEqual(0);
1180
+ expect(gridResult.E1).toEqual(0);
1181
+ });
1182
+
1183
+ //----------------------------------------------------------------------------
1184
+ // MINA
1185
+ //----------------------------------------------------------------------------
1186
+
1187
+ test("MINA: functional tests on simple arguments", () => {
1188
+ expect(evaluateCell("A1", { A1: "=MINA()" })).toEqual("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
1189
+ expect(evaluateCell("A1", { A1: "=MINA(,)" })).toBe(0);
1190
+ expect(evaluateCell("A1", { A1: "=MINA(0)" })).toBe(0);
1191
+ expect(evaluateCell("A1", { A1: "=MINA(1, 2, 3, 1, 2)" })).toBe(1);
1192
+ expect(evaluateCell("A1", { A1: "=MINA(1, , 2, , 3)" })).toBe(0);
1193
+ expect(evaluateCell("A1", { A1: "=MINA(1.5, 1.4)" })).toBe(1.4);
1194
+ expect(evaluateCell("A1", { A1: "=MINA(42.42)" })).toBe(42.42);
1195
+ expect(evaluateCell("A1", { A1: '=MINA("Jean Fume", "Jean Dreu")' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1196
+ expect(evaluateCell("A1", { A1: '=MINA("")' })).toBe(0);
1197
+ expect(evaluateCell("A1", { A1: '=MINA(" ")' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1198
+ expect(evaluateCell("A1", { A1: '=MINA("2", "-2")' })).toBe(-2);
1199
+ expect(evaluateCell("A1", { A1: '=MINA("2", " -2 ")' })).toBe(-2);
1200
+ expect(evaluateCell("A1", { A1: '=MINA("2", "")' })).toBe(0);
1201
+ expect(evaluateCell("A1", { A1: '=MINA("2", " ")' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1202
+ expect(evaluateCell("A1", { A1: "=MINA(TRUE, FALSE)" })).toBe(0);
1203
+ expect(evaluateCell("A1", { A1: '=MINA(0, "0", TRUE)' })).toBe(0);
1204
+ expect(evaluateCell("A1", { A1: '=MINA(5, "4", TRUE)' })).toBe(1);
1205
+ expect(evaluateCell("A1", { A1: '=MINA("10/10/2010", "8/8/2008")' })).toBe(39668);
1206
+ });
1207
+
1208
+ test("MINA: functional tests on cell arguments", () => {
1209
+ expect(evaluateCell("A1", { A1: "=MINA(A2)", A2: "" })).toBe(0);
1210
+ expect(evaluateCell("A1", { A1: "=MINA(A2)", A2: " " })).toBe(0);
1211
+ expect(evaluateCell("A1", { A1: "=MINA(A2)", A2: "," })).toBe(0);
1212
+ expect(evaluateCell("A1", { A1: "=MINA(A2)", A2: "0" })).toBe(0);
1213
+ expect(evaluateCell("A1", { A1: "=MINA(A2, A3)", A2: "1", A3: "2" })).toBe(1);
1214
+ expect(evaluateCell("A1", { A1: "=MINA(A2, A3, A4)", A2: "1", A3: "", A4: "2" })).toBe(1);
1215
+ expect(
1216
+ evaluateCell("A1", { A1: "=MINA(A2, A3, A4)", A2: "1.5", A3: "10", A4: "Jean Terre" })
1217
+ ).toBe(0);
1218
+ expect(evaluateCell("A1", { A1: "=MINA(A2, A3)", A2: "", A3: "" })).toBe(0);
1219
+ expect(evaluateCell("A1", { A1: "=MINA(A2, A3)", A2: " ", A3: "" })).toBe(0);
1220
+ expect(evaluateCell("A1", { A1: "=MINA(A2, A3)", A2: "", A3: '=" "' })).toBe(0);
1221
+ expect(evaluateCell("A1", { A1: "=MINA(A2, A3)", A2: " ", A3: '=" "' })).toBe(0);
1222
+ expect(evaluateCell("A1", { A1: "=MINA(A2, A3)", A2: " ", A3: '=" "' })).toBe(0);
1223
+ expect(evaluateCell("A1", { A1: "=MINA(A2, A3)", A2: " ", A3: '=" "' })).toBe(0);
1224
+ expect(evaluateCell("A1", { A1: "=MINA(A2, A3)", A2: "42", A3: "24" })).toBe(24);
1225
+ expect(evaluateCell("A1", { A1: "=MINA(A2, A3)", A2: "42", A3: '"24"' })).toBe(0);
1226
+ expect(evaluateCell("A1", { A1: "=MINA(A2, A3)", A2: "42", A3: "=24" })).toBe(24);
1227
+ expect(evaluateCell("A1", { A1: "=MINA(A2, A3)", A2: "42", A3: '="24"' })).toBe(0);
1228
+ expect(evaluateCell("A1", { A1: "=MINA(A2, A3)", A2: '"42"', A3: '"24"' })).toBe(0);
1229
+ expect(evaluateCell("A1", { A1: "=MINA(A2, A3)", A2: '"42"', A3: "=24" })).toBe(0);
1230
+ expect(evaluateCell("A1", { A1: "=MINA(A2, A3)", A2: '"42"', A3: '="24"' })).toBe(0);
1231
+ expect(evaluateCell("A1", { A1: "=MINA(A2, A3)", A2: "=42", A3: "=24" })).toBe(24);
1232
+ expect(evaluateCell("A1", { A1: "=MINA(A2, A3)", A2: "=42", A3: '="24"' })).toBe(0);
1233
+ expect(evaluateCell("A1", { A1: "=MINA(A2, A3)", A2: '="42"', A3: '="24"' })).toBe(0);
1234
+ expect(evaluateCell("A1", { A1: "=MINA(A2, A3)", A2: "10/10/2010", A3: "8/8/2008" })).toBe(
1235
+ 39668
1236
+ );
1237
+ });
1238
+
1239
+ test("MINA: functional tests on simple and cell arguments", () => {
1240
+ expect(evaluateCell("A1", { A1: "=MINA(A2,)", A2: "" })).toBe(0);
1241
+ expect(evaluateCell("A1", { A1: "=MINA(A2,)", A2: " " })).toBe(0);
1242
+ expect(evaluateCell("A1", { A1: "=MINA(A2,)", A2: '=""' })).toBe(0);
1243
+ expect(evaluateCell("A1", { A1: "=MINA(A2,)", A2: '=" "' })).toBe(0);
1244
+ expect(evaluateCell("A1", { A1: '=MINA(A2, "")', A2: "" })).toBe(0);
1245
+ expect(evaluateCell("A1", { A1: '=MINA(A2, "")', A2: " " })).toBe(0);
1246
+ expect(evaluateCell("A1", { A1: '=MINA(A2, "")', A2: '=""' })).toBe(0);
1247
+ expect(evaluateCell("A1", { A1: '=MINA(A2, "")', A2: '=" "' })).toBe(0);
1248
+ expect(evaluateCell("A1", { A1: '=MINA(A2, " ")', A2: "" })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1249
+ expect(evaluateCell("A1", { A1: '=MINA(A2, " ")', A2: " " })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1250
+ expect(evaluateCell("A1", { A1: '=MINA(A2, " ")', A2: '=""' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1251
+ expect(evaluateCell("A1", { A1: '=MINA(A2, " ")', A2: '=" "' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1252
+ expect(evaluateCell("A1", { A1: '=MINA(42, "24")' })).toBe(24);
1253
+ expect(evaluateCell("A1", { A1: "=MINA(A2, 42)", A2: "24" })).toBe(24);
1254
+ expect(evaluateCell("A1", { A1: "=MINA(A2, 42)", A2: '"24"' })).toBe(0);
1255
+ expect(evaluateCell("A1", { A1: "=MINA(A2, 42)", A2: "=24" })).toBe(24);
1256
+ expect(evaluateCell("A1", { A1: "=MINA(A2, 42)", A2: '="24"' })).toBe(0);
1257
+ expect(evaluateCell("A1", { A1: '=MINA(A2, "42")', A2: "24" })).toBe(24);
1258
+ expect(evaluateCell("A1", { A1: '=MINA(A2, "42")', A2: '"24"' })).toBe(0);
1259
+ expect(evaluateCell("A1", { A1: '=MINA(A2, "42")', A2: "=24" })).toBe(24);
1260
+ expect(evaluateCell("A1", { A1: '=MINA(A2, "42")', A2: '="24"' })).toBe(0);
1261
+ expect(evaluateCell("A1", { A1: "=MINA(A2, TRUE)", A2: "2" })).toBe(1);
1262
+ expect(evaluateCell("A1", { A1: "=MINA(A2, TRUE)", A2: '"2"' })).toBe(0);
1263
+ expect(evaluateCell("A1", { A1: "=MINA(A2, TRUE)", A2: "=2" })).toBe(1);
1264
+ expect(evaluateCell("A1", { A1: "=MINA(A2, TRUE)", A2: '="2"' })).toBe(0);
1265
+ });
1266
+
1267
+ test("MINA: functional tests on range arguments", () => {
1268
+ const grid = {
1269
+ A1: "=MINA(B2:D3,B4:D4,E2:E3,E4)",
1270
+
1271
+ A2: "=MINA(B2:F2)",
1272
+ A3: "=MINA(B3:F3)",
1273
+ A4: "=MINA(B4:F4)",
1274
+
1275
+ B1: "=MINA(B2:B4)",
1276
+ C1: "=MINA(C2:C4)",
1277
+ D1: "=MINA(D2:D4)",
1278
+ E1: "=MINA(E2:E4)",
1279
+ F1: "=MINA(F2:F4)",
1280
+
1281
+ B2: "=9",
1282
+ C2: "9",
1283
+ D2: '"-9"',
1284
+ E2: '="-9"',
1285
+ F2: "5",
1286
+
1287
+ B3: '=" "',
1288
+ C3: "3",
1289
+ D3: "Jean Évumille",
1290
+ E3: '"Jean Duvoyage"',
1291
+ F3: "TRUE",
1292
+
1293
+ B4: "-42",
1294
+ C4: '""',
1295
+ D4: '=""',
1296
+ E4: '" "',
1297
+ F4: "42",
1298
+ };
1299
+
1300
+ const gridResult = evaluateGrid(grid);
1301
+ expect(gridResult.A1).toEqual(-42);
1302
+ expect(gridResult.A2).toEqual(0);
1303
+ expect(gridResult.A3).toEqual(0);
1304
+ expect(gridResult.A4).toEqual(-42);
1305
+ expect(gridResult.B1).toEqual(-42);
1306
+ expect(gridResult.C1).toEqual(0);
1307
+ expect(gridResult.D1).toEqual(0);
1308
+ expect(gridResult.E1).toEqual(0);
1309
+ expect(gridResult.F1).toEqual(1);
1310
+ });
1311
+
1312
+ //----------------------------------------------------------------------------
1313
+ // MINIFS
1314
+ //----------------------------------------------------------------------------
1315
+
1316
+ test("MINIFS: functional tests on range", () => {
1317
+ // prettier-ignore
1318
+ const grid = {
1319
+ B1: "4" , C1: "14", D1: "Yes",
1320
+ B2: "28", C2: "30", D2: "Yes",
1321
+ B3: "31", C3: "47", D3: "Yes",
1322
+ B4: "12", C4: "0" , D4: "Yes",
1323
+ B5: "31", C5: "47", D5: "Yes",
1324
+ B6: "13", C6: "5" , D6: "No" ,
1325
+ B7: "18", C7: "43", D7: "No" ,
1326
+ B8: "24", C8: "7" , D8: "Yes",
1327
+ B9: "44", C9: "28", D9: "No" ,
1328
+ B10: "22", C10: "23", D10: "No" ,
1329
+ B11: "9" , C11: "13", D11: "No" ,
1330
+
1331
+ A12: '=MINIFS(B1:B11, B1:B11, ">20")',
1332
+ A13: '=MINIFS(B1:B11, B1:B11, ">20", C1:C11, "<23")',
1333
+ A14: '=MINIFS(B1:B11, D1:D11, "no")',
1334
+ };
1335
+
1336
+ const gridResult = evaluateGrid(grid);
1337
+ expect(gridResult.A12).toBe(22);
1338
+ expect(gridResult.A13).toBe(24);
1339
+ expect(gridResult.A14).toBe(9);
1340
+ });
1341
+
1342
+ //----------------------------------------------------------------------------
1343
+ // SMALL
1344
+ //----------------------------------------------------------------------------
1345
+
1346
+ test("SMALL: functional tests on simple arguments", () => {
1347
+ expect(evaluateCell("A1", { A1: "=SMALL()" })).toBe("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
1348
+ expect(evaluateCell("A1", { A1: "=SMALL( , )" })).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
1349
+ expect(evaluateCell("A1", { A1: "=SMALL( , 0)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
1350
+ expect(evaluateCell("A1", { A1: "=SMALL(2, 0)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
1351
+ expect(evaluateCell("A1", { A1: "=SMALL(2, 1)" })).toBe(2);
1352
+ expect(evaluateCell("A1", { A1: "=SMALL(2, 2)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
1353
+ expect(evaluateCell("A1", { A1: "=SMALL(2, -1)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
1354
+ expect(evaluateCell("A1", { A1: "=SMALL(2, 1.9)" })).toBe(2);
1355
+ });
1356
+
1357
+ test("SMALL: casting tests on simple arguments", () => {
1358
+ expect(evaluateCell("A1", { A1: '=SMALL(2, "1")' })).toBe(2);
1359
+ expect(evaluateCell("A1", { A1: "=SMALL(2, TRUE)" })).toBe(2);
1360
+ expect(evaluateCell("A1", { A1: "=SMALL(2, FALSE)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
1361
+ expect(evaluateCell("A1", { A1: "=SMALL(TRUE, 1)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
1362
+ expect(evaluateCell("A1", { A1: "=SMALL(False, 1)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
1363
+ expect(evaluateCell("A1", { A1: '=SMALL("test", 1)' })).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
1364
+ expect(evaluateCell("A1", { A1: '=SMALL("2", 1)' })).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
1365
+ });
1366
+
1367
+ test("SMALL: functional tests on cell arguments", () => {
1368
+ expect(evaluateCell("A1", { A1: "=SMALL(A2:A4, A5)", A2: "", A3: "", A4: "", A5: "0" })).toBe(
1369
+ "#ERROR"
1370
+ ); // @compatibility: on google sheets, return #NUM!
1371
+ expect(evaluateCell("A1", { A1: "=SMALL(A2:A4, A5)", A2: "", A3: "", A4: "", A5: "1" })).toBe(
1372
+ "#ERROR"
1373
+ ); // @compatibility: on google sheets, return #NUM!
1374
+ expect(
1375
+ evaluateCell("A1", { A1: "=SMALL(A2:A4, A5)", A2: "3", A3: "1", A4: "2", A5: "1" })
1376
+ ).toBe(1);
1377
+ expect(
1378
+ evaluateCell("A1", { A1: "=SMALL(A2:A4, A5)", A2: "3", A3: "1", A4: "-42", A5: "1" })
1379
+ ).toBe(-42);
1380
+ expect(
1381
+ evaluateCell("A1", { A1: "=SMALL(A2:A4, A5)", A2: "3", A3: "1", A4: "2", A5: "2" })
1382
+ ).toBe(2);
1383
+ expect(
1384
+ evaluateCell("A1", { A1: "=SMALL(A2:A4, A5)", A2: "3", A3: "1", A4: "2", A5: "4" })
1385
+ ).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
1386
+ expect(evaluateCell("A1", { A1: "=SMALL(A2:A4, A5)", A2: "3", A3: "", A4: "2", A5: "3" })).toBe(
1387
+ "#ERROR"
1388
+ ); // @compatibility: on google sheets, return #NUM!
1389
+ expect(
1390
+ evaluateCell("A1", { A1: "=SMALL(A2:A4, A5)", A2: "03/01/2020", A3: "-11", A4: "2", A5: "1" })
1391
+ ).toBe(-11);
1392
+ expect(
1393
+ evaluateCell("A1", { A1: "=SMALL(A2:A3, A5)", A2: "03/01/2020", A3: "1e15", A5: "1" })
1394
+ ).toBe(43891);
1395
+ });
1396
+
1397
+ test("SMALL: casting tests on cell arguments", () => {
1398
+ expect(
1399
+ evaluateCell("A1", { A1: "=SMALL(A2:A4, A5)", A2: '"3"', A3: "", A4: "2", A5: "1" })
1400
+ ).toBe(2);
1401
+ expect(
1402
+ evaluateCell("A1", { A1: "=SMALL(A2:A4, A5)", A2: '"3"', A3: "", A4: "", A5: "1" })
1403
+ ).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
1404
+ expect(
1405
+ evaluateCell("A1", { A1: "=SMALL(A2:A4, A5)", A2: '="3"', A3: "", A4: "2", A5: "1" })
1406
+ ).toBe(2);
1407
+ expect(
1408
+ evaluateCell("A1", {
1409
+ A1: "=SMALL(A2:A4, A5)",
1410
+ A2: "lol",
1411
+ A3: "looool",
1412
+ A4: "xdtrololol",
1413
+ A5: "1",
1414
+ })
1415
+ ).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
1416
+ expect(
1417
+ evaluateCell("A1", { A1: "=SMALL(A2:A4, A5)", A2: '"3"', A3: '"1"', A4: '"2"', A5: "1" })
1418
+ ).toBe("#ERROR"); // @compatibility: on google sheets, return #NUM!
1419
+ expect(
1420
+ evaluateCell("A1", { A1: "=SMALL(A2:A4, A5)", A2: "TRUE", A3: "0", A4: "0", A5: "1" })
1421
+ ).toBe(0);
1422
+ });
1423
+
1424
+ //----------------------------------------------------------------------------
1425
+ // STDEV
1426
+ //----------------------------------------------------------------------------
1427
+
1428
+ test("STDEV: functional tests on simple arguments", () => {
1429
+ expect(evaluateCell("A1", { A1: "=STDEV()" })).toBe("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
1430
+ expect(evaluateCell("A1", { A1: "=STDEV(0)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1431
+ expect(evaluateCell("A1", { A1: "=STDEV(1)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1432
+ expect(evaluateCell("A1", { A1: "=STDEV(,)" })).toBe(0);
1433
+ expect(evaluateCell("A1", { A1: "=STDEV(0, 0)" })).toBe(0);
1434
+ expect(evaluateCell("A1", { A1: "=STDEV(2, 4)" })).toBeCloseTo(1.41);
1435
+ expect(evaluateCell("A1", { A1: "=STDEV(2, 4, 6)" })).toBe(2);
1436
+ expect(evaluateCell("A1", { A1: "=STDEV(2, 4, )" })).toBe(2);
1437
+ expect(evaluateCell("A1", { A1: "=STDEV(-2, 0, 2)" })).toBe(2);
1438
+ });
1439
+
1440
+ test("STDEV: casting tests on simple arguments", () => {
1441
+ expect(evaluateCell("A1", { A1: '=STDEV(2, 4, "6")' })).toBe(2);
1442
+ expect(evaluateCell("A1", { A1: "=STDEV(TRUE, 3, 5)" })).toBe(2);
1443
+ expect(evaluateCell("A1", { A1: '=STDEV("test", 3, 5)' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1444
+ expect(evaluateCell("A1", { A1: '=STDEV("8/8/2008", "10/10/2010")' })).toBeCloseTo(
1445
+ 560.73568,
1446
+ 5
1447
+ );
1448
+ });
1449
+
1450
+ test("STDEV: functional tests on cell arguments", () => {
1451
+ expect(evaluateCell("A1", { A1: "=STDEV(A2)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1452
+ expect(evaluateCell("A1", { A1: "=STDEV(A2)", A2: "0" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1453
+ expect(evaluateCell("A1", { A1: "=STDEV(A2)", A2: "1" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1454
+ expect(evaluateCell("A1", { A1: "=STDEV(A2, A3)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1455
+ expect(evaluateCell("A1", { A1: "=STDEV(A2, A3)", A2: "0", A3: "0" })).toBe(0);
1456
+ expect(evaluateCell("A1", { A1: "=STDEV(A2, A3)", A2: "2", A3: "4" })).toBeCloseTo(1.41);
1457
+ expect(evaluateCell("A1", { A1: "=STDEV(A2, A3, A4)", A2: "2", A3: "4", A4: "6" })).toBe(2);
1458
+ expect(evaluateCell("A1", { A1: "=STDEV(A2, A3, A4)", A2: "2", A3: "4" })).toBeCloseTo(1.41);
1459
+ expect(evaluateCell("A1", { A1: "=STDEV(A2, A3, A4)", A2: "-2", A3: "0", A4: "2" })).toBe(2);
1460
+ });
1461
+
1462
+ test("STDEV: casting tests on cell arguments", () => {
1463
+ expect(
1464
+ evaluateCell("A1", { A1: "=STDEV(A2, A3, A4)", A2: "2", A3: "4", A4: '="6"' })
1465
+ ).toBeCloseTo(1.41);
1466
+ expect(
1467
+ evaluateCell("A1", { A1: "=STDEV(A2, A3, A4)", A2: "TRUE", A3: "3", A4: "5" })
1468
+ ).toBeCloseTo(1.41);
1469
+ expect(
1470
+ evaluateCell("A1", { A1: "=STDEV(A2, A3, A4)", A2: "test", A3: "3", A4: "5" })
1471
+ ).toBeCloseTo(1.41);
1472
+ expect(
1473
+ evaluateCell("A1", { A1: "=STDEV(A2, A3, A4)", A2: "2", A3: "4", A4: '=""' })
1474
+ ).toBeCloseTo(1.41);
1475
+ expect(
1476
+ evaluateCell("A1", { A1: "=STDEV(A2, A3)", A2: "8/8/2008", A3: "10/10/2010" })
1477
+ ).toBeCloseTo(560.73568, 5);
1478
+ });
1479
+
1480
+ //----------------------------------------------------------------------------
1481
+ // STDEV.P
1482
+ //----------------------------------------------------------------------------
1483
+
1484
+ test("STDEV.P: functional tests on simple arguments", () => {
1485
+ expect(evaluateCell("A1", { A1: "=STDEV.P()" })).toBe("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
1486
+ expect(evaluateCell("A1", { A1: "=STDEV.P(0)" })).toBe(0);
1487
+ expect(evaluateCell("A1", { A1: "=STDEV.P(1)" })).toBe(0);
1488
+ expect(evaluateCell("A1", { A1: "=STDEV.P(,)" })).toBe(0);
1489
+ expect(evaluateCell("A1", { A1: "=STDEV.P(0, 0)" })).toBe(0);
1490
+ expect(evaluateCell("A1", { A1: "=STDEV.P(2, 4)" })).toBe(1);
1491
+ expect(evaluateCell("A1", { A1: "=STDEV.P(2, 5, 8)" })).toBeCloseTo(2.45);
1492
+ expect(evaluateCell("A1", { A1: "=STDEV.P(3, 6, )" })).toBeCloseTo(2.45);
1493
+ expect(evaluateCell("A1", { A1: "=STDEV.P(-3, 0, 3)" })).toBeCloseTo(2.45);
1494
+ });
1495
+
1496
+ test("STDEV.P: casting tests on simple arguments", () => {
1497
+ expect(evaluateCell("A1", { A1: '=STDEV.P(2, 5, "8")' })).toBeCloseTo(2.45);
1498
+ expect(evaluateCell("A1", { A1: "=STDEV.P(TRUE, 4, 7)" })).toBeCloseTo(2.45);
1499
+ expect(evaluateCell("A1", { A1: '=STDEV.P("test", 3, 5)' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1500
+ expect(evaluateCell("A1", { A1: '=STDEV.P("8/8/2008", "10/10/2010")' })).toBe(396.5);
1501
+ });
1502
+
1503
+ test("STDEV.P: functional tests on cell arguments", () => {
1504
+ expect(evaluateCell("A1", { A1: "=STDEV.P(A2)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1505
+ expect(evaluateCell("A1", { A1: "=STDEV.P(A2)", A2: "0" })).toBe(0);
1506
+ expect(evaluateCell("A1", { A1: "=STDEV.P(A2)", A2: "1" })).toBe(0);
1507
+ expect(evaluateCell("A1", { A1: "=STDEV.P(A2, A3)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1508
+ expect(evaluateCell("A1", { A1: "=STDEV.P(A2, A3)", A2: "0", A3: "0" })).toBe(0);
1509
+ expect(evaluateCell("A1", { A1: "=STDEV.P(A2, A3)", A2: "2", A3: "4" })).toBe(1);
1510
+ expect(
1511
+ evaluateCell("A1", { A1: "=STDEV.P(A2, A3, A4)", A2: "2", A3: "5", A4: "8" })
1512
+ ).toBeCloseTo(2.45);
1513
+ expect(evaluateCell("A1", { A1: "=STDEV.P(A2, A3, A4)", A2: "2", A3: "4" })).toBe(1);
1514
+ expect(
1515
+ evaluateCell("A1", { A1: "=STDEV.P(A2, A3, A4)", A2: "-3", A3: "0", A4: "3" })
1516
+ ).toBeCloseTo(2.45);
1517
+ });
1518
+
1519
+ test("STDEV.P: casting tests on cell arguments", () => {
1520
+ expect(evaluateCell("A1", { A1: "=STDEV.P(A2, A3, A4)", A2: "2", A3: "4", A4: '="6"' })).toBe(
1521
+ 1
1522
+ );
1523
+ expect(evaluateCell("A1", { A1: "=STDEV.P(A2, A3, A4)", A2: "TRUE", A3: "3", A4: "5" })).toBe(
1524
+ 1
1525
+ );
1526
+ expect(evaluateCell("A1", { A1: "=STDEV.P(A2, A3, A4)", A2: "test", A3: "3", A4: "5" })).toBe(
1527
+ 1
1528
+ );
1529
+ expect(evaluateCell("A1", { A1: "=STDEV.P(A2, A3, A4)", A2: "2", A3: "4", A4: '=""' })).toBe(1);
1530
+ expect(evaluateCell("A1", { A1: "=STDEV.P(A2, A3)", A2: "8/8/2008", A3: "10/10/2010" })).toBe(
1531
+ 396.5
1532
+ );
1533
+ });
1534
+
1535
+ //----------------------------------------------------------------------------
1536
+ // STDEV.S
1537
+ //----------------------------------------------------------------------------
1538
+
1539
+ test("STDEV.S: functional tests on simple arguments", () => {
1540
+ expect(evaluateCell("A1", { A1: "=STDEV.S()" })).toBe("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
1541
+ expect(evaluateCell("A1", { A1: "=STDEV.S(0)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1542
+ expect(evaluateCell("A1", { A1: "=STDEV.S(1)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1543
+ expect(evaluateCell("A1", { A1: "=STDEV.S(,)" })).toBe(0);
1544
+ expect(evaluateCell("A1", { A1: "=STDEV.S(0, 0)" })).toBe(0);
1545
+ expect(evaluateCell("A1", { A1: "=STDEV.S(2, 4)" })).toBeCloseTo(1.41);
1546
+ expect(evaluateCell("A1", { A1: "=STDEV.S(2, 4, 6)" })).toBe(2);
1547
+ expect(evaluateCell("A1", { A1: "=STDEV.S(2, 4, )" })).toBe(2);
1548
+ expect(evaluateCell("A1", { A1: "=STDEV.S(-2, 0, 2)" })).toBe(2);
1549
+ });
1550
+
1551
+ test("STDEV.S: casting tests on simple arguments", () => {
1552
+ expect(evaluateCell("A1", { A1: '=STDEV.S(2, 4, "6")' })).toBe(2);
1553
+ expect(evaluateCell("A1", { A1: "=STDEV.S(TRUE, 3, 5)" })).toBe(2);
1554
+ expect(evaluateCell("A1", { A1: '=STDEV.S("test", 3, 5)' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1555
+ expect(evaluateCell("A1", { A1: '=STDEV.S("8/8/2008", "10/10/2010")' })).toBeCloseTo(
1556
+ 560.73568,
1557
+ 5
1558
+ );
1559
+ });
1560
+
1561
+ test("STDEV.S: functional tests on cell arguments", () => {
1562
+ expect(evaluateCell("A1", { A1: "=STDEV.S(A2)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1563
+ expect(evaluateCell("A1", { A1: "=STDEV.S(A2)", A2: "0" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1564
+ expect(evaluateCell("A1", { A1: "=STDEV.S(A2)", A2: "1" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1565
+ expect(evaluateCell("A1", { A1: "=STDEV.S(A2, A3)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1566
+ expect(evaluateCell("A1", { A1: "=STDEV.S(A2, A3)", A2: "0", A3: "0" })).toBe(0);
1567
+ expect(evaluateCell("A1", { A1: "=STDEV.S(A2, A3)", A2: "2", A3: "4" })).toBeCloseTo(1.41);
1568
+ expect(evaluateCell("A1", { A1: "=STDEV.S(A2, A3, A4)", A2: "2", A3: "4", A4: "6" })).toBe(2);
1569
+ expect(evaluateCell("A1", { A1: "=STDEV.S(A2, A3, A4)", A2: "2", A3: "4" })).toBeCloseTo(1.41);
1570
+ expect(evaluateCell("A1", { A1: "=STDEV.S(A2, A3, A4)", A2: "-2", A3: "0", A4: "2" })).toBe(2);
1571
+ });
1572
+
1573
+ test("STDEV.S: casting tests on cell arguments", () => {
1574
+ expect(
1575
+ evaluateCell("A1", { A1: "=STDEV.S(A2, A3, A4)", A2: "2", A3: "4", A4: '="6"' })
1576
+ ).toBeCloseTo(1.41);
1577
+ expect(
1578
+ evaluateCell("A1", { A1: "=STDEV.S(A2, A3, A4)", A2: "TRUE", A3: "3", A4: "5" })
1579
+ ).toBeCloseTo(1.41);
1580
+ expect(
1581
+ evaluateCell("A1", { A1: "=STDEV.S(A2, A3, A4)", A2: "test", A3: "3", A4: "5" })
1582
+ ).toBeCloseTo(1.41);
1583
+ expect(
1584
+ evaluateCell("A1", { A1: "=STDEV.S(A2, A3, A4)", A2: "2", A3: "4", A4: '=""' })
1585
+ ).toBeCloseTo(1.41);
1586
+ expect(
1587
+ evaluateCell("A1", { A1: "=STDEV.S(A2, A3)", A2: "8/8/2008", A3: "10/10/2010" })
1588
+ ).toBeCloseTo(560.73568, 5);
1589
+ });
1590
+
1591
+ //----------------------------------------------------------------------------
1592
+ // STDEVA
1593
+ //----------------------------------------------------------------------------
1594
+
1595
+ test("STDEVA: functional tests on simple arguments", () => {
1596
+ expect(evaluateCell("A1", { A1: "=STDEVA()" })).toBe("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
1597
+ expect(evaluateCell("A1", { A1: "=STDEVA(0)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1598
+ expect(evaluateCell("A1", { A1: "=STDEVA(1)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1599
+ expect(evaluateCell("A1", { A1: "=STDEVA(,)" })).toBe(0);
1600
+ expect(evaluateCell("A1", { A1: "=STDEVA(0, 0)" })).toBe(0);
1601
+ expect(evaluateCell("A1", { A1: "=STDEVA(2, 4)" })).toBeCloseTo(1.41);
1602
+ expect(evaluateCell("A1", { A1: "=STDEVA(2, 4, 6)" })).toBe(2);
1603
+ expect(evaluateCell("A1", { A1: "=STDEVA(2, 4, )" })).toBe(2);
1604
+ expect(evaluateCell("A1", { A1: "=STDEVA(-2, 0, 2)" })).toBe(2);
1605
+ });
1606
+
1607
+ test("STDEVA: casting tests on simple arguments", () => {
1608
+ expect(evaluateCell("A1", { A1: '=STDEVA(2, 4, "6")' })).toBe(2);
1609
+ expect(evaluateCell("A1", { A1: "=STDEVA(TRUE, 3, 5)" })).toBe(2);
1610
+ expect(evaluateCell("A1", { A1: '=STDEVA("test", 3, 5)' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1611
+ expect(evaluateCell("A1", { A1: '=STDEVA("8/8/2008", "10/10/2010")' })).toBeCloseTo(
1612
+ 560.73568,
1613
+ 5
1614
+ );
1615
+ });
1616
+
1617
+ test("STDEVA: functional tests on cell arguments", () => {
1618
+ expect(evaluateCell("A1", { A1: "=STDEVA(A2)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1619
+ expect(evaluateCell("A1", { A1: "=STDEVA(A2)", A2: "0" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1620
+ expect(evaluateCell("A1", { A1: "=STDEVA(A2)", A2: "1" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1621
+ expect(evaluateCell("A1", { A1: "=STDEVA(A2, A3)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1622
+ expect(evaluateCell("A1", { A1: "=STDEVA(A2, A3)", A2: "0", A3: "0" })).toBe(0);
1623
+ expect(evaluateCell("A1", { A1: "=STDEVA(A2, A3)", A2: "2", A3: "4" })).toBeCloseTo(1.41);
1624
+ expect(evaluateCell("A1", { A1: "=STDEVA(A2, A3, A4)", A2: "2", A3: "4", A4: "6" })).toBe(2);
1625
+ expect(evaluateCell("A1", { A1: "=STDEVA(A2, A3, A4)", A2: "2", A3: "4" })).toBeCloseTo(1.41);
1626
+ expect(evaluateCell("A1", { A1: "=STDEVA(A2, A3, A4)", A2: "-2", A3: "0", A4: "2" })).toBe(2);
1627
+ });
1628
+
1629
+ test("STDEVA: casting tests on cell arguments", () => {
1630
+ expect(evaluateCell("A1", { A1: "=STDEVA(A2, A3, A4)", A2: "2", A3: "4", A4: '="6"' })).toBe(2);
1631
+ expect(evaluateCell("A1", { A1: "=STDEVA(A2, A3, A4)", A2: "TRUE", A3: "3", A4: "5" })).toBe(2);
1632
+ expect(
1633
+ evaluateCell("A1", { A1: "=STDEVA(A2, A3, A4)", A2: "test", A3: "3", A4: "5" })
1634
+ ).toBeCloseTo(2.52);
1635
+ expect(evaluateCell("A1", { A1: "=STDEVA(A2, A3, A4)", A2: "2", A3: "4", A4: '=""' })).toBe(2);
1636
+ expect(
1637
+ evaluateCell("A1", { A1: "=STDEVA(A2, A3)", A2: "8/8/2008", A3: "10/10/2010" })
1638
+ ).toBeCloseTo(560.73568, 5);
1639
+ });
1640
+
1641
+ //----------------------------------------------------------------------------
1642
+ // STDEVP
1643
+ //----------------------------------------------------------------------------
1644
+
1645
+ test("STDEVP: functional tests on simple arguments", () => {
1646
+ expect(evaluateCell("A1", { A1: "=STDEVP()" })).toBe("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
1647
+ expect(evaluateCell("A1", { A1: "=STDEVP(0)" })).toBe(0);
1648
+ expect(evaluateCell("A1", { A1: "=STDEVP(1)" })).toBe(0);
1649
+ expect(evaluateCell("A1", { A1: "=STDEVP(,)" })).toBe(0);
1650
+ expect(evaluateCell("A1", { A1: "=STDEVP(0, 0)" })).toBe(0);
1651
+ expect(evaluateCell("A1", { A1: "=STDEVP(2, 4)" })).toBe(1);
1652
+ expect(evaluateCell("A1", { A1: "=STDEVP(2, 5, 8)" })).toBeCloseTo(2.45);
1653
+ expect(evaluateCell("A1", { A1: "=STDEVP(3, 6, )" })).toBeCloseTo(2.45);
1654
+ expect(evaluateCell("A1", { A1: "=STDEVP(-3, 0, 3)" })).toBeCloseTo(2.45);
1655
+ });
1656
+
1657
+ test("STDEVP: casting tests on simple arguments", () => {
1658
+ expect(evaluateCell("A1", { A1: '=STDEVP(2, 5, "8")' })).toBeCloseTo(2.45);
1659
+ expect(evaluateCell("A1", { A1: "=STDEVP(TRUE, 4, 7)" })).toBeCloseTo(2.45);
1660
+ expect(evaluateCell("A1", { A1: '=STDEVP("test", 3, 5)' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1661
+ expect(evaluateCell("A1", { A1: '=STDEVP("8/8/2008", "10/10/2010")' })).toBe(396.5);
1662
+ });
1663
+
1664
+ test("STDEVP: functional tests on cell arguments", () => {
1665
+ expect(evaluateCell("A1", { A1: "=STDEVP(A2)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1666
+ expect(evaluateCell("A1", { A1: "=STDEVP(A2)", A2: "0" })).toBe(0);
1667
+ expect(evaluateCell("A1", { A1: "=STDEVP(A2)", A2: "1" })).toBe(0);
1668
+ expect(evaluateCell("A1", { A1: "=STDEVP(A2, A3)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1669
+ expect(evaluateCell("A1", { A1: "=STDEVP(A2, A3)", A2: "0", A3: "0" })).toBe(0);
1670
+ expect(evaluateCell("A1", { A1: "=STDEVP(A2, A3)", A2: "2", A3: "4" })).toBe(1);
1671
+ expect(
1672
+ evaluateCell("A1", { A1: "=STDEVP(A2, A3, A4)", A2: "2", A3: "5", A4: "8" })
1673
+ ).toBeCloseTo(2.45);
1674
+ expect(evaluateCell("A1", { A1: "=STDEVP(A2, A3, A4)", A2: "2", A3: "4" })).toBe(1);
1675
+ expect(
1676
+ evaluateCell("A1", { A1: "=STDEVP(A2, A3, A4)", A2: "-3", A3: "0", A4: "3" })
1677
+ ).toBeCloseTo(2.45);
1678
+ });
1679
+
1680
+ test("STDEVP: casting tests on cell arguments", () => {
1681
+ expect(evaluateCell("A1", { A1: "=STDEVP(A2, A3, A4)", A2: "2", A3: "4", A4: '="6"' })).toBe(1);
1682
+ expect(evaluateCell("A1", { A1: "=STDEVP(A2, A3, A4)", A2: "TRUE", A3: "3", A4: "5" })).toBe(1);
1683
+ expect(evaluateCell("A1", { A1: "=STDEVP(A2, A3, A4)", A2: "test", A3: "3", A4: "5" })).toBe(1);
1684
+ expect(evaluateCell("A1", { A1: "=STDEVP(A2, A3, A4)", A2: "2", A3: "4", A4: '=""' })).toBe(1);
1685
+ expect(evaluateCell("A1", { A1: "=STDEVP(A2, A3)", A2: "8/8/2008", A3: "10/10/2010" })).toBe(
1686
+ 396.5
1687
+ );
1688
+ });
1689
+
1690
+ //----------------------------------------------------------------------------
1691
+ // STDEVPA
1692
+ //----------------------------------------------------------------------------
1693
+
1694
+ test("STDEVPA: functional tests on simple arguments", () => {
1695
+ expect(evaluateCell("A1", { A1: "=STDEVPA()" })).toBe("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
1696
+ expect(evaluateCell("A1", { A1: "=STDEVPA(0)" })).toBe(0);
1697
+ expect(evaluateCell("A1", { A1: "=STDEVPA(1)" })).toBe(0);
1698
+ expect(evaluateCell("A1", { A1: "=STDEVPA(,)" })).toBe(0);
1699
+ expect(evaluateCell("A1", { A1: "=STDEVPA(0, 0)" })).toBe(0);
1700
+ expect(evaluateCell("A1", { A1: "=STDEVPA(2, 4)" })).toBe(1);
1701
+ expect(evaluateCell("A1", { A1: "=STDEVPA(2, 5, 8)" })).toBeCloseTo(2.45);
1702
+ expect(evaluateCell("A1", { A1: "=STDEVPA(3, 6, )" })).toBeCloseTo(2.45);
1703
+ expect(evaluateCell("A1", { A1: "=STDEVPA(-3, 0, 3)" })).toBeCloseTo(2.45);
1704
+ });
1705
+
1706
+ test("STDEVPA: casting tests on simple arguments", () => {
1707
+ expect(evaluateCell("A1", { A1: '=STDEVPA(2, 5, "8")' })).toBeCloseTo(2.45);
1708
+ expect(evaluateCell("A1", { A1: "=STDEVPA(TRUE, 4, 7)" })).toBeCloseTo(2.45);
1709
+ expect(evaluateCell("A1", { A1: '=STDEVPA("test", 3, 5)' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1710
+ expect(evaluateCell("A1", { A1: '=STDEVPA("8/8/2008", "10/10/2010")' })).toBe(396.5);
1711
+ });
1712
+
1713
+ test("STDEVPA: functional tests on cell arguments", () => {
1714
+ expect(evaluateCell("A1", { A1: "=STDEVPA(A2)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1715
+ expect(evaluateCell("A1", { A1: "=STDEVPA(A2)", A2: "0" })).toBe(0);
1716
+ expect(evaluateCell("A1", { A1: "=STDEVPA(A2)", A2: "1" })).toBe(0);
1717
+ expect(evaluateCell("A1", { A1: "=STDEVPA(A2, A3)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1718
+ expect(evaluateCell("A1", { A1: "=STDEVPA(A2, A3)", A2: "0", A3: "0" })).toBe(0);
1719
+ expect(evaluateCell("A1", { A1: "=STDEVPA(A2, A3)", A2: "2", A3: "4" })).toBe(1);
1720
+ expect(
1721
+ evaluateCell("A1", { A1: "=STDEVPA(A2, A3, A4)", A2: "2", A3: "5", A4: "8" })
1722
+ ).toBeCloseTo(2.45);
1723
+ expect(evaluateCell("A1", { A1: "=STDEVPA(A2, A3, A4)", A2: "2", A3: "4" })).toBe(1);
1724
+ expect(
1725
+ evaluateCell("A1", { A1: "=STDEVPA(A2, A3, A4)", A2: "-3", A3: "0", A4: "3" })
1726
+ ).toBeCloseTo(2.45);
1727
+ });
1728
+
1729
+ test("STDEVPA: casting tests on cell arguments", () => {
1730
+ expect(
1731
+ evaluateCell("A1", { A1: "=STDEVPA(A2, A3, A4)", A2: "3", A3: "6", A4: '="9"' })
1732
+ ).toBeCloseTo(2.45);
1733
+ expect(
1734
+ evaluateCell("A1", { A1: "=STDEVPA(A2, A3, A4)", A2: "TRUE", A3: "4", A4: "7" })
1735
+ ).toBeCloseTo(2.45);
1736
+ expect(
1737
+ evaluateCell("A1", { A1: "=STDEVPA(A2, A3, A4)", A2: "test", A3: "3", A4: "6" })
1738
+ ).toBeCloseTo(2.45);
1739
+ expect(
1740
+ evaluateCell("A1", { A1: "=STDEVPA(A2, A3, A4)", A2: "3", A3: "6", A4: '=""' })
1741
+ ).toBeCloseTo(2.45);
1742
+ expect(evaluateCell("A1", { A1: "=STDEVPA(A2, A3)", A2: "8/8/2008", A3: "10/10/2010" })).toBe(
1743
+ 396.5
1744
+ );
1745
+ });
1746
+
1747
+ //----------------------------------------------------------------------------
1748
+ // VAR
1749
+ //----------------------------------------------------------------------------
1750
+
1751
+ test("VAR: functional tests on simple arguments", () => {
1752
+ expect(evaluateCell("A1", { A1: "=VAR()" })).toBe("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
1753
+ expect(evaluateCell("A1", { A1: "=VAR(0)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1754
+ expect(evaluateCell("A1", { A1: "=VAR(1)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1755
+ expect(evaluateCell("A1", { A1: "=VAR(,)" })).toBe(0);
1756
+ expect(evaluateCell("A1", { A1: "=VAR(0, 0)" })).toBe(0);
1757
+ expect(evaluateCell("A1", { A1: "=VAR(2, 4)" })).toBe(2);
1758
+ expect(evaluateCell("A1", { A1: "=VAR(2, 4, 6)" })).toBe(4);
1759
+ expect(evaluateCell("A1", { A1: "=VAR(2, 4, )" })).toBe(4);
1760
+ expect(evaluateCell("A1", { A1: "=VAR(-2, 0, 2)" })).toBe(4);
1761
+ });
1762
+
1763
+ test("VAR: casting tests on simple arguments", () => {
1764
+ expect(evaluateCell("A1", { A1: '=VAR(2, 4, "6")' })).toBe(4);
1765
+ expect(evaluateCell("A1", { A1: "=VAR(TRUE, 3, 5)" })).toBe(4);
1766
+ expect(evaluateCell("A1", { A1: '=VAR("test", 3, 5)' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1767
+ expect(evaluateCell("A1", { A1: '=VAR("8/8/2008", "10/10/2010")' })).toBe(314424.5);
1768
+ });
1769
+
1770
+ test("VAR: functional tests on cell arguments", () => {
1771
+ expect(evaluateCell("A1", { A1: "=VAR(A2)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1772
+ expect(evaluateCell("A1", { A1: "=VAR(A2)", A2: "0" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1773
+ expect(evaluateCell("A1", { A1: "=VAR(A2)", A2: "1" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1774
+ expect(evaluateCell("A1", { A1: "=VAR(A2, A3)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1775
+ expect(evaluateCell("A1", { A1: "=VAR(A2, A3)", A2: "0", A3: "0" })).toBe(0);
1776
+ expect(evaluateCell("A1", { A1: "=VAR(A2, A3)", A2: "2", A3: "4" })).toBe(2);
1777
+ expect(evaluateCell("A1", { A1: "=VAR(A2, A3, A4)", A2: "2", A3: "4", A4: "6" })).toBe(4);
1778
+ expect(evaluateCell("A1", { A1: "=VAR(A2, A3, A4)", A2: "2", A3: "4" })).toBe(2);
1779
+ expect(evaluateCell("A1", { A1: "=VAR(A2, A3, A4)", A2: "-2", A3: "0", A4: "2" })).toBe(4);
1780
+ });
1781
+
1782
+ test("VAR: casting tests on cell arguments", () => {
1783
+ expect(evaluateCell("A1", { A1: "=VAR(A2, A3, A4)", A2: "2", A3: "4", A4: '="6"' })).toBe(2);
1784
+ expect(evaluateCell("A1", { A1: "=VAR(A2, A3, A4)", A2: "TRUE", A3: "3", A4: "5" })).toBe(2);
1785
+ expect(evaluateCell("A1", { A1: "=VAR(A2, A3, A4)", A2: "test", A3: "3", A4: "5" })).toBe(2);
1786
+ expect(evaluateCell("A1", { A1: "=VAR(A2, A3, A4)", A2: "2", A3: "4", A4: '=""' })).toBe(2);
1787
+ expect(evaluateCell("A1", { A1: "=VAR(A2, A3)", A2: "8/8/2008", A3: "10/10/2010" })).toBe(
1788
+ 314424.5
1789
+ );
1790
+ });
1791
+
1792
+ //----------------------------------------------------------------------------
1793
+ // VAR.P
1794
+ //----------------------------------------------------------------------------
1795
+
1796
+ test("VAR.P: functional tests on simple arguments", () => {
1797
+ expect(evaluateCell("A1", { A1: "=VAR.P()" })).toBe("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
1798
+ expect(evaluateCell("A1", { A1: "=VAR.P(0)" })).toBe(0);
1799
+ expect(evaluateCell("A1", { A1: "=VAR.P(1)" })).toBe(0);
1800
+ expect(evaluateCell("A1", { A1: "=VAR.P(,)" })).toBe(0);
1801
+ expect(evaluateCell("A1", { A1: "=VAR.P(0, 0)" })).toBe(0);
1802
+ expect(evaluateCell("A1", { A1: "=VAR.P(2, 4)" })).toBe(1);
1803
+ expect(evaluateCell("A1", { A1: "=VAR.P(2, 5, 8)" })).toBe(6);
1804
+ expect(evaluateCell("A1", { A1: "=VAR.P(3, 6, )" })).toBe(6);
1805
+ expect(evaluateCell("A1", { A1: "=VAR.P(-3, 0, 3)" })).toBe(6);
1806
+ });
1807
+
1808
+ test("VAR.P: casting tests on simple arguments", () => {
1809
+ expect(evaluateCell("A1", { A1: '=VAR.P(2, 5, "8")' })).toBe(6);
1810
+ expect(evaluateCell("A1", { A1: "=VAR.P(TRUE, 4, 7)" })).toBe(6);
1811
+ expect(evaluateCell("A1", { A1: '=VAR.P("test", 3, 5)' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1812
+ expect(evaluateCell("A1", { A1: '=VAR.P("1/11/1900", "1/8/1900", FALSE)' })).toBe(26);
1813
+ });
1814
+
1815
+ test("VAR.P: functional tests on cell arguments", () => {
1816
+ expect(evaluateCell("A1", { A1: "=VAR.P(A2)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1817
+ expect(evaluateCell("A1", { A1: "=VAR.P(A2)", A2: "0" })).toBe(0);
1818
+ expect(evaluateCell("A1", { A1: "=VAR.P(A2)", A2: "1" })).toBe(0);
1819
+ expect(evaluateCell("A1", { A1: "=VAR.P(A2, A3)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1820
+ expect(evaluateCell("A1", { A1: "=VAR.P(A2, A3)", A2: "0", A3: "0" })).toBe(0);
1821
+ expect(evaluateCell("A1", { A1: "=VAR.P(A2, A3)", A2: "2", A3: "4" })).toBe(1);
1822
+ expect(evaluateCell("A1", { A1: "=VAR.P(A2, A3, A4)", A2: "2", A3: "5", A4: "8" })).toBe(6);
1823
+ expect(evaluateCell("A1", { A1: "=VAR.P(A2, A3, A4)", A2: "2", A3: "4" })).toBe(1);
1824
+ expect(evaluateCell("A1", { A1: "=VAR.P(A2, A3, A4)", A2: "-3", A3: "0", A4: "3" })).toBe(6);
1825
+ });
1826
+
1827
+ test("VAR.P: casting tests on cell arguments", () => {
1828
+ expect(evaluateCell("A1", { A1: "=VAR.P(A2, A3, A4)", A2: "2", A3: "4", A4: '="6"' })).toBe(1);
1829
+ expect(evaluateCell("A1", { A1: "=VAR.P(A2, A3, A4)", A2: "TRUE", A3: "3", A4: "5" })).toBe(1);
1830
+ expect(evaluateCell("A1", { A1: "=VAR.P(A2, A3, A4)", A2: "test", A3: "3", A4: "5" })).toBe(1);
1831
+ expect(evaluateCell("A1", { A1: "=VAR.P(A2, A3, A4)", A2: "2", A3: "4", A4: '=""' })).toBe(1);
1832
+ expect(
1833
+ evaluateCell("A1", { A1: "=VAR.P(A2, A3, A4)", A2: "1/11/1900", A3: "1/8/1900", A4: "FALSE" })
1834
+ ).toBe(2.25);
1835
+ });
1836
+
1837
+ //----------------------------------------------------------------------------
1838
+ // VAR.S
1839
+ //----------------------------------------------------------------------------
1840
+
1841
+ test("VAR.S: functional tests on simple arguments", () => {
1842
+ expect(evaluateCell("A1", { A1: "=VAR.S()" })).toBe("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
1843
+ expect(evaluateCell("A1", { A1: "=VAR.S(0)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1844
+ expect(evaluateCell("A1", { A1: "=VAR.S(1)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1845
+ expect(evaluateCell("A1", { A1: "=VAR.S(,)" })).toBe(0);
1846
+ expect(evaluateCell("A1", { A1: "=VAR.S(0, 0)" })).toBe(0);
1847
+ expect(evaluateCell("A1", { A1: "=VAR.S(2, 4)" })).toBe(2);
1848
+ expect(evaluateCell("A1", { A1: "=VAR.S(2, 4, 6)" })).toBe(4);
1849
+ expect(evaluateCell("A1", { A1: "=VAR.S(2, 4, )" })).toBe(4);
1850
+ expect(evaluateCell("A1", { A1: "=VAR.S(-2, 0, 2)" })).toBe(4);
1851
+ });
1852
+
1853
+ test("VAR.S: casting tests on simple arguments", () => {
1854
+ expect(evaluateCell("A1", { A1: '=VAR.S(2, 4, "6")' })).toBe(4);
1855
+ expect(evaluateCell("A1", { A1: "=VAR.S(TRUE, 3, 5)" })).toBe(4);
1856
+ expect(evaluateCell("A1", { A1: '=VAR.S("test", 3, 5)' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1857
+ expect(evaluateCell("A1", { A1: '=VAR.S("1/11/1900", "1/8/1900", FALSE)' })).toBe(39);
1858
+ });
1859
+
1860
+ test("VAR.S: functional tests on cell arguments", () => {
1861
+ expect(evaluateCell("A1", { A1: "=VAR.S(A2)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1862
+ expect(evaluateCell("A1", { A1: "=VAR.S(A2)", A2: "0" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1863
+ expect(evaluateCell("A1", { A1: "=VAR.S(A2)", A2: "1" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1864
+ expect(evaluateCell("A1", { A1: "=VAR.S(A2, A3)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1865
+ expect(evaluateCell("A1", { A1: "=VAR.S(A2, A3)", A2: "0", A3: "0" })).toBe(0);
1866
+ expect(evaluateCell("A1", { A1: "=VAR.S(A2, A3)", A2: "2", A3: "4" })).toBe(2);
1867
+ expect(evaluateCell("A1", { A1: "=VAR.S(A2, A3, A4)", A2: "2", A3: "4", A4: "6" })).toBe(4);
1868
+ expect(evaluateCell("A1", { A1: "=VAR.S(A2, A3, A4)", A2: "2", A3: "4" })).toBe(2);
1869
+ expect(evaluateCell("A1", { A1: "=VAR.S(A2, A3, A4)", A2: "-2", A3: "0", A4: "2" })).toBe(4);
1870
+ });
1871
+
1872
+ test("VAR.S: casting tests on cell arguments", () => {
1873
+ expect(evaluateCell("A1", { A1: "=VAR.S(A2, A3, A4)", A2: "2", A3: "4", A4: '="6"' })).toBe(2);
1874
+ expect(evaluateCell("A1", { A1: "=VAR.S(A2, A3, A4)", A2: "TRUE", A3: "3", A4: "5" })).toBe(2);
1875
+ expect(evaluateCell("A1", { A1: "=VAR.S(A2, A3, A4)", A2: "test", A3: "3", A4: "5" })).toBe(2);
1876
+ expect(evaluateCell("A1", { A1: "=VAR.S(A2, A3, A4)", A2: "2", A3: "4", A4: '=""' })).toBe(2);
1877
+ expect(
1878
+ evaluateCell("A1", { A1: "=VAR.S(A2, A3, A4)", A2: "1/11/1900", A3: "1/8/1900", A4: "FALSE" })
1879
+ ).toBe(4.5);
1880
+ });
1881
+
1882
+ //----------------------------------------------------------------------------
1883
+ // VARA
1884
+ //----------------------------------------------------------------------------
1885
+
1886
+ test("VARA: functional tests on simple arguments", () => {
1887
+ expect(evaluateCell("A1", { A1: "=VARA()" })).toBe("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
1888
+ expect(evaluateCell("A1", { A1: "=VARA(0)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1889
+ expect(evaluateCell("A1", { A1: "=VARA(1)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1890
+ expect(evaluateCell("A1", { A1: "=VARA(,)" })).toBe(0);
1891
+ expect(evaluateCell("A1", { A1: "=VARA(0, 0)" })).toBe(0);
1892
+ expect(evaluateCell("A1", { A1: "=VARA(2, 4)" })).toBe(2);
1893
+ expect(evaluateCell("A1", { A1: "=VARA(2, 4, 6)" })).toBe(4);
1894
+ expect(evaluateCell("A1", { A1: "=VARA(2, 4, )" })).toBe(4);
1895
+ expect(evaluateCell("A1", { A1: "=VARA(-2, 0, 2)" })).toBe(4);
1896
+ });
1897
+
1898
+ test("VARA: casting tests on simple arguments", () => {
1899
+ expect(evaluateCell("A1", { A1: '=VARA(2, 4, "6")' })).toBe(4);
1900
+ expect(evaluateCell("A1", { A1: "=VARA(TRUE, 3, 5)" })).toBe(4);
1901
+ expect(evaluateCell("A1", { A1: '=VARA("test", 3, 5)' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1902
+ expect(evaluateCell("A1", { A1: '=VARA("1/11/1900", "1/8/1900", FALSE)' })).toBe(39);
1903
+ });
1904
+
1905
+ test("VARA: functional tests on cell arguments", () => {
1906
+ expect(evaluateCell("A1", { A1: "=VARA(A2)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1907
+ expect(evaluateCell("A1", { A1: "=VARA(A2)", A2: "0" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1908
+ expect(evaluateCell("A1", { A1: "=VARA(A2)", A2: "1" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1909
+ expect(evaluateCell("A1", { A1: "=VARA(A2, A3)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1910
+ expect(evaluateCell("A1", { A1: "=VARA(A2, A3)", A2: "0", A3: "0" })).toBe(0);
1911
+ expect(evaluateCell("A1", { A1: "=VARA(A2, A3)", A2: "2", A3: "4" })).toBe(2);
1912
+ expect(evaluateCell("A1", { A1: "=VARA(A2, A3, A4)", A2: "2", A3: "4", A4: "6" })).toBe(4);
1913
+ expect(evaluateCell("A1", { A1: "=VARA(A2, A3, A4)", A2: "2", A3: "4" })).toBe(2);
1914
+ expect(evaluateCell("A1", { A1: "=VARA(A2, A3, A4)", A2: "-2", A3: "0", A4: "2" })).toBe(4);
1915
+ });
1916
+
1917
+ test("VARA: casting tests on cell arguments", () => {
1918
+ expect(evaluateCell("A1", { A1: "=VARA(A2, A3, A4)", A2: "2", A3: "4", A4: '="6"' })).toBe(4);
1919
+ expect(evaluateCell("A1", { A1: "=VARA(A2, A3, A4)", A2: "TRUE", A3: "3", A4: "5" })).toBe(4);
1920
+ expect(evaluateCell("A1", { A1: "=VARA(A2, A3, A4)", A2: "test", A3: "3", A4: "6" })).toBe(9);
1921
+ expect(evaluateCell("A1", { A1: "=VARA(A2, A3, A4)", A2: "2", A3: "4", A4: '=""' })).toBe(4);
1922
+ expect(
1923
+ evaluateCell("A1", { A1: "=VARA(A2, A3, A4)", A2: "1/11/1900", A3: "1/8/1900", A4: "test" })
1924
+ ).toBe(39);
1925
+ });
1926
+
1927
+ //----------------------------------------------------------------------------
1928
+ // VARP
1929
+ //----------------------------------------------------------------------------
1930
+
1931
+ test("VARP: functional tests on simple arguments", () => {
1932
+ expect(evaluateCell("A1", { A1: "=VARP()" })).toBe("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
1933
+ expect(evaluateCell("A1", { A1: "=VARP(0)" })).toBe(0);
1934
+ expect(evaluateCell("A1", { A1: "=VARP(1)" })).toBe(0);
1935
+ expect(evaluateCell("A1", { A1: "=VARP(,)" })).toBe(0);
1936
+ expect(evaluateCell("A1", { A1: "=VARP(0, 0)" })).toBe(0);
1937
+ expect(evaluateCell("A1", { A1: "=VARP(2, 4)" })).toBe(1);
1938
+ expect(evaluateCell("A1", { A1: "=VARP(2, 5, 8)" })).toBe(6);
1939
+ expect(evaluateCell("A1", { A1: "=VARP(3, 6, )" })).toBe(6);
1940
+ expect(evaluateCell("A1", { A1: "=VARP(-3, 0, 3)" })).toBe(6);
1941
+ });
1942
+
1943
+ test("VARP: casting tests on simple arguments", () => {
1944
+ expect(evaluateCell("A1", { A1: '=VARP(2, 5, "8")' })).toBe(6);
1945
+ expect(evaluateCell("A1", { A1: "=VARP(TRUE, 4, 7)" })).toBe(6);
1946
+ expect(evaluateCell("A1", { A1: '=VARP("test", 3, 5)' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1947
+ expect(evaluateCell("A1", { A1: '=VARP("1/11/1900", "1/8/1900")' })).toBe(2.25);
1948
+ });
1949
+
1950
+ test("VARP: functional tests on cell arguments", () => {
1951
+ expect(evaluateCell("A1", { A1: "=VARP(A2)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1952
+ expect(evaluateCell("A1", { A1: "=VARP(A2)", A2: "0" })).toBe(0);
1953
+ expect(evaluateCell("A1", { A1: "=VARP(A2)", A2: "1" })).toBe(0);
1954
+ expect(evaluateCell("A1", { A1: "=VARP(A2, A3)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1955
+ expect(evaluateCell("A1", { A1: "=VARP(A2, A3)", A2: "0", A3: "0" })).toBe(0);
1956
+ expect(evaluateCell("A1", { A1: "=VARP(A2, A3)", A2: "2", A3: "4" })).toBe(1);
1957
+ expect(evaluateCell("A1", { A1: "=VARP(A2, A3, A4)", A2: "2", A3: "5", A4: "8" })).toBe(6);
1958
+ expect(evaluateCell("A1", { A1: "=VARP(A2, A3, A4)", A2: "2", A3: "4" })).toBe(1);
1959
+ expect(evaluateCell("A1", { A1: "=VARP(A2, A3, A4)", A2: "-3", A3: "0", A4: "3" })).toBe(6);
1960
+ });
1961
+
1962
+ test("VARP: casting tests on cell arguments", () => {
1963
+ expect(evaluateCell("A1", { A1: "=VARP(A2, A3, A4)", A2: "2", A3: "4", A4: '="6"' })).toBe(1);
1964
+ expect(evaluateCell("A1", { A1: "=VARP(A2, A3, A4)", A2: "TRUE", A3: "3", A4: "5" })).toBe(1);
1965
+ expect(evaluateCell("A1", { A1: "=VARP(A2, A3, A4)", A2: "test", A3: "3", A4: "5" })).toBe(1);
1966
+ expect(evaluateCell("A1", { A1: "=VARP(A2, A3, A4)", A2: "2", A3: "4", A4: '=""' })).toBe(1);
1967
+ expect(evaluateCell("A1", { A1: "=VARP(A2, A3)", A2: "1/11/1900", A3: "1/8/1900" })).toBe(2.25);
1968
+ });
1969
+
1970
+ //----------------------------------------------------------------------------
1971
+ // VARPA
1972
+ //----------------------------------------------------------------------------
1973
+
1974
+ test("VARPA: functional tests on simple arguments", () => {
1975
+ expect(evaluateCell("A1", { A1: "=VARPA()" })).toBe("#BAD_EXPR"); // @compatibility: on google sheets, return #N/A
1976
+ expect(evaluateCell("A1", { A1: "=VARPA(0)" })).toBe(0);
1977
+ expect(evaluateCell("A1", { A1: "=VARPA(1)" })).toBe(0);
1978
+ expect(evaluateCell("A1", { A1: "=VARPA(,)" })).toBe(0);
1979
+ expect(evaluateCell("A1", { A1: "=VARPA(0, 0)" })).toBe(0);
1980
+ expect(evaluateCell("A1", { A1: "=VARPA(2, 4)" })).toBe(1);
1981
+ expect(evaluateCell("A1", { A1: "=VARPA(2, 5, 8)" })).toBe(6);
1982
+ expect(evaluateCell("A1", { A1: "=VARPA(3, 6, )" })).toBe(6);
1983
+ expect(evaluateCell("A1", { A1: "=VARPA(-3, 0, 3)" })).toBe(6);
1984
+ });
1985
+
1986
+ test("VARPA: casting tests on simple arguments", () => {
1987
+ expect(evaluateCell("A1", { A1: '=VARPA(2, 5, "8")' })).toBe(6);
1988
+ expect(evaluateCell("A1", { A1: "=VARPA(TRUE, 4, 7)" })).toBe(6);
1989
+ expect(evaluateCell("A1", { A1: '=VARPA("test", 3, 5)' })).toBe("#ERROR"); // @compatibility: on google sheets, return #VALUE!
1990
+ expect(evaluateCell("A1", { A1: '=VARPA("1/11/1900", "1/8/1900", FALSE)' })).toBe(26);
1991
+ });
1992
+
1993
+ test("VARPA: functional tests on cell arguments", () => {
1994
+ expect(evaluateCell("A1", { A1: "=VARPA(A2)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1995
+ expect(evaluateCell("A1", { A1: "=VARPA(A2)", A2: "0" })).toBe(0);
1996
+ expect(evaluateCell("A1", { A1: "=VARPA(A2)", A2: "1" })).toBe(0);
1997
+ expect(evaluateCell("A1", { A1: "=VARPA(A2, A3)" })).toBe("#ERROR"); // @compatibility: on google sheets, return #DIV/0!
1998
+ expect(evaluateCell("A1", { A1: "=VARPA(A2, A3)", A2: "0", A3: "0" })).toBe(0);
1999
+ expect(evaluateCell("A1", { A1: "=VARPA(A2, A3)", A2: "2", A3: "4" })).toBe(1);
2000
+ expect(evaluateCell("A1", { A1: "=VARPA(A2, A3, A4)", A2: "2", A3: "5", A4: "8" })).toBe(6);
2001
+ expect(evaluateCell("A1", { A1: "=VARPA(A2, A3, A4)", A2: "2", A3: "4" })).toBe(1);
2002
+ expect(evaluateCell("A1", { A1: "=VARPA(A2, A3, A4)", A2: "-3", A3: "0", A4: "3" })).toBe(6);
2003
+ });
2004
+
2005
+ test("VARPA: casting tests on cell arguments", () => {
2006
+ expect(evaluateCell("A1", { A1: "=VARPA(A2, A3, A4)", A2: "3", A3: "6", A4: '="9"' })).toBe(6);
2007
+ expect(evaluateCell("A1", { A1: "=VARPA(A2, A3, A4)", A2: "TRUE", A3: "4", A4: "7" })).toBe(6);
2008
+ expect(evaluateCell("A1", { A1: "=VARPA(A2, A3, A4)", A2: "test", A3: "3", A4: "6" })).toBe(6);
2009
+ expect(evaluateCell("A1", { A1: "=VARPA(A2, A3, A4)", A2: "3", A3: "6", A4: '=""' })).toBe(6);
2010
+ expect(
2011
+ evaluateCell("A1", { A1: "=VARPA(A2, A3, A4)", A2: "1/11/1900", A3: "1/8/1900", A4: "test" })
2012
+ ).toBe(26);
2013
+ });
2014
+ });