Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Fix Unit Tests #1036

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Xamarin.CommunityToolkit.Behaviors
/// </summary>
public class ImpliedOrderGridBehavior : BaseBehavior<Grid>
{
bool[][]? usedMatrix;
int rowCount;
int columnCount;

Expand Down Expand Up @@ -51,21 +52,24 @@ bool[][] InitMatrix()
rowCount = View.RowDefinitions.Count;
if (rowCount == 0)
rowCount = 1;

columnCount = View.ColumnDefinitions.Count;
if (columnCount == 0)
columnCount = 1;

var newMatrix = new bool[rowCount][];
for (var r = 0; r < rowCount; r++)
newMatrix[r] = new bool[columnCount];

return newMatrix;
}

void FindNextCell(out int rowIndex, out int columnIndex, out bool[][] matrix)
void FindNextCell(out int rowIndex, out int columnIndex)
{
matrix = InitMatrix();
usedMatrix ??= InitMatrix();

// Find the first available row
var row = matrix.FirstOrDefault(r => r.Any(c => !c));
var row = usedMatrix.FirstOrDefault(r => r.Any(c => !c));

// If no row is found, set cell to origin and log
if (row == null)
Expand All @@ -75,13 +79,13 @@ void FindNextCell(out int rowIndex, out int columnIndex, out bool[][] matrix)
columnIndex = Math.Max(columnCount - 1, 0);
return;
}
rowIndex = matrix.IndexOf(row);
rowIndex = usedMatrix.IndexOf(row);

// Find the first available column
columnIndex = row.IndexOf(row.FirstOrDefault(c => !c));
}

void UpdateUsedCells(int row, int column, int rowSpan, int columnSpan, bool[][] usedMatrix)
void UpdateUsedCells(int row, int column, int rowSpan, int columnSpan)
{
var rowEnd = row + rowSpan;
var columnEnd = column + columnSpan;
Expand All @@ -102,8 +106,9 @@ void UpdateUsedCells(int row, int column, int rowSpan, int columnSpan, bool[][]
{
for (var c = column; c < columnEnd; c++)
{
if (usedMatrix[r][c])
if (usedMatrix?[r][c] ?? throw new NullReferenceException())
LogWarning($"Cell at row {r} column {c} has already been used.");

usedMatrix[r][c] = true;
}
}
Expand All @@ -114,15 +119,15 @@ void ProcessElement(BindableObject view)
var columnSpan = Grid.GetColumnSpan(view);
var rowSpan = Grid.GetRowSpan(view);

FindNextCell(out var row, out var column, out var usedMatrix);
FindNextCell(out var row, out var column);

// Check to see if the user manually assigned a row or column
if (view.IsSet(Grid.ColumnProperty))
column = Grid.GetColumn(view);
if (view.IsSet(Grid.RowProperty))
row = Grid.GetRow(view);

UpdateUsedCells(row, column, rowSpan, columnSpan, usedMatrix);
UpdateUsedCells(row, column, rowSpan, columnSpan);

// Set attributes
view.SetValue(Grid.ColumnProperty, column);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ public int MaximumDecimalPlaces
protected override ValueTask<bool> ValidateAsync(object? value, CancellationToken token)
{
if (value is not string valueString)
throw new ArgumentException($"Expected type string for parameter {nameof(value)}");
return new ValueTask<bool>(false);

if (!(double.TryParse(valueString, out var numeric)
&& numeric >= MinimumValue
&& numeric <= MaximumValue))
&& numeric >= MinimumValue
&& numeric <= MaximumValue))
{
return new ValueTask<bool>(false);
}

var decimalDelimeterIndex = valueString.IndexOf(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);
var hasDecimalDelimeter = decimalDelimeterIndex >= 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public object Convert(object[]? values, Type targetType, object? parameter, Cult
if (boolValues.Length != values.Length)
return false;

var count = boolValues.Count();
var count = boolValues.Count(v => v);

return ConditionType switch
{
Expand Down