Files
radzen-blazor/Radzen.Blazor.Tests/Spreadsheet/XMatchFunctionTests.cs
Atanas Korchev 7179194877 Add Tier 1 and Tier 2 Excel-compatible formula functions
Add COUNTIF/COUNTIFS, SUMIFS, AVERAGEIF/AVERAGEIFS, MAXIFS/MINIFS, MATCH/XMATCH,
CONCATENATE, ABS, MOD, MEDIAN, IFS, SWITCH, POWER, SQRT, PRODUCT, SUMPRODUCT,
CEILING, FLOOR, STDEV/STDEVP/VAR/VARP (and .S/.P aliases), MODE (and MODE.SNGL),
RANK (and RANK.EQ), COUNTBLANK, IFNA, ISBLANK/ISNUMBER/ISTEXT/ISERROR/ISNA,
DAYS, NETWORKDAYS, WORKDAY, DATEVALUE, EXACT, CHAR, CODE.

Engine support: ParameterType.Group preserves argument boundaries for variadic
range/criteria pairs and arrays; FunctionStore.Add registers dotted-name aliases;
the parser accepts dotted function names; CellData comparisons are case-insensitive
and MatchesCriteria handles =/<> operators and wildcards. Fixes a latent CHOOSE bug
where range arguments were flattened. All function results verified against Excel.
2026-06-15 18:45:18 +03:00

51 lines
1.3 KiB
C#

using Xunit;
using Radzen.Documents.Spreadsheet;
namespace Radzen.Blazor.Spreadsheet.Tests;
public class XMatchFunctionTests
{
readonly Worksheet sheet = new(10, 10);
[Fact]
public void ShouldMatchExactByDefault()
{
sheet.Cells["A1"].Value = "Hat";
sheet.Cells["A2"].Value = "Gloves";
sheet.Cells["A3"].Value = "Scarf";
sheet.Cells["B1"].Formula = "=XMATCH(\"Gloves\",A1:A3)";
Assert.Equal(2d, sheet.Cells["B1"].Value);
}
[Fact]
public void ShouldReturnNAWhenNotFound()
{
sheet.Cells["A1"].Value = "Hat";
sheet.Cells["B1"].Formula = "=XMATCH(\"Gloves\",A1:A1)";
Assert.Equal(CellError.NA, sheet.Cells["B1"].Value);
}
[Fact]
public void ShouldMatchNextSmaller()
{
sheet.Cells["A1"].Value = 1;
sheet.Cells["A2"].Value = 5;
sheet.Cells["A3"].Value = 10;
// match_mode -1: exact or next smaller; 7 -> 5 at position 2
sheet.Cells["B1"].Formula = "=XMATCH(7,A1:A3,-1)";
Assert.Equal(2d, sheet.Cells["B1"].Value);
}
[Fact]
public void ShouldMatchWildcard()
{
sheet.Cells["A1"].Value = "apple";
sheet.Cells["A2"].Value = "banana";
sheet.Cells["B1"].Formula = "=XMATCH(\"ban*\",A1:A2,2)";
Assert.Equal(2d, sheet.Cells["B1"].Value);
}
}