Created
December 19, 2021 19:42
-
-
Save Vatyx/128f066bf80c3586f031b4ece4326b7f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
struct FTMatrix | |
{ | |
private TArray<bool> Storage; | |
private int N; | |
private int M; | |
FTMatrix(int N, int M) | |
{ | |
this.N = N; | |
this.M = M; | |
Storage.SetNum(N * M); | |
} | |
bool& opIndex(int i, int j) | |
{ | |
const int Index = (i * N) + j; | |
ensure(Storage.IsValidIndex(Index)); | |
return Storage[Index]; | |
} | |
const bool& opIndex(int i, int j) const | |
{ | |
const int Index = (i * N) + j; | |
ensure(Storage.IsValidIndex(Index)); | |
return Storage[Index]; | |
} | |
int Size() const | |
{ | |
return N * M; | |
} | |
}; | |
void Test_InitializeMatrix(FUnitTest& T) | |
{ | |
FTMatrix Matrix(10, 10); | |
T.AssertEquals(Matrix.Size(), 100); | |
} | |
void Test_IndexMatrix(FUnitTest& T) | |
{ | |
FTMatrix Matrix(10, 10); | |
T.AssertEquals(Matrix[1, 2], false); | |
Matrix[1, 2] = true; | |
T.AssertEquals(Matrix[1, 2], true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment