Skip to content

Commit

Permalink
v1.7.4 Array Flip
Browse files Browse the repository at this point in the history
  • Loading branch information
smabuk committed Nov 24, 2024
1 parent 31a47ea commit d301372
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/Smab.Helpers/GridHelpers/Flip.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace Smab.Helpers;
public static partial class ArrayHelpers {
public static T[,] FlipHorizontally<T>(this T[,] array) {
int colsCount = array.ColsCount();
int rowsCount = array.RowsCount();

T[,] result = new T[colsCount, rowsCount];

for (int row = 0; row < rowsCount; row++) {
for (int col = 0; col < colsCount; col++) {
result[col, row] = array[colsCount - col - 1, row];
}
}

return result;
}

public static T[,] FlipVertically<T>(this T[,] array) {
int colsCount = array.ColsCount();
int rowsCount = array.RowsCount();

T[,] result = new T[colsCount, rowsCount];

for (int row = 0; row < rowsCount; row++) {
for (int col = 0; col < colsCount; col++) {
result[col, row] = array[col, rowsCount - row - 1];
}
}

return result;
}
}
2 changes: 1 addition & 1 deletion src/Smab.Helpers/Smab.Helpers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>
<PropertyGroup>
<PackageReleaseNotes>.NET 9.0</PackageReleaseNotes>
<VersionPrefix>1.7.3</VersionPrefix>
<VersionPrefix>1.7.4</VersionPrefix>
<Preview></Preview>
<VersionSuffix Condition="'$(Preview)' != '' And '$(BUILD_BUILDNUMBER)' == ''">$(Preview).$([System.DateTime]::get_Now().get_Year())$([System.DateTime]::get_Now().get_Month().ToString("D2"))$([System.DateTime]::get_Now().get_Day().ToString("D2"))-$([System.DateTime]::get_Now().get_Hour().ToString("D2"))$([System.DateTime]::get_Now().get_Minute().ToString("D2"))</VersionSuffix>
<VersionSuffix Condition="'$(Preview)' != '' And '$(BUILD_BUILDNUMBER)' != ''">$(Preview).$(BUILD_BUILDNUMBER)</VersionSuffix>
Expand Down
34 changes: 34 additions & 0 deletions tests/Smab.Helpers.Tests/GridHelperTests/Flip.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace Smab.Helpers.Tests.GridHelperTests;
public class Flip(ITestOutputHelper testOutputHelper) {

Check warning on line 2 in tests/Smab.Helpers.Tests/GridHelperTests/Flip.cs

View workflow job for this annotation

GitHub Actions / publish_job

Parameter 'testOutputHelper' is unread.

Check warning on line 2 in tests/Smab.Helpers.Tests/GridHelperTests/Flip.cs

View workflow job for this annotation

GitHub Actions / publish_job

Parameter 'testOutputHelper' is unread.

private static readonly char[,] INPUT_ARRAY = """
A.B.1
CD..2
E.FG.
HIJ.3
""".Split(Environment.NewLine).To2dArray();

[Fact]
public void Flip_Horizontally() {
char[,] array = INPUT_ARRAY.FlipHorizontally();
string actual = string.Join(Environment.NewLine, array.AsStrings());
actual.ShouldBe("""
1.B.A
2..DC
.GF.E
3.JIH
""");
}

[Fact]
public void Flip_Vertically() {
char[,] array = INPUT_ARRAY.FlipVertically();
string actual = string.Join(Environment.NewLine, array.AsStrings());
actual.ShouldBe("""
HIJ.3
E.FG.
CD..2
A.B.1
""");
}
}

0 comments on commit d301372

Please sign in to comment.