-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
|
||
|
||
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 | ||
"""); | ||
} | ||
} |