Adding unit test to ReorderAlgorithm
Adding 100 different test cases for the ReorderAlgorithm. The test cases are randomly generated using generateRandomTestCase() the boards are generated once and then written in the file reorder_algorithm_test_cases. I will leave the code to generate the boards in the Test even though is not used anymore in case we need to generate more boards later on. Also, I found that the ReorderAlgorithm was not deterministic, meaning that it could generate two different results with the same inputs (views positions and view being drag positions), because it was traversing a map whose has was the object id which is random. So I sort the views before traversing them. Bug: 229292911 Test: atest ReorderAlgorithmUnitTestCase Change-Id: I196eb8f1dafcb57d5259969268c458129ae4f46b
This commit is contained in:
1 parent
52cc03e42c
commit
45b39b50e5
6 files changed
+2306
-5
No files matched your search
@@ -171,6 +171,8 @@ public class CellLayoutBoard implements Comparable<CellLayoutBoard> {
|
||||
}
|
||||
}
|
||||
|
||||
private HashSet<Character> mUsedWidgetTypes = new HashSet<>();
|
||||
|
||||
static final int INFINITE = 99999;
|
||||
|
||||
char[][] mWidget = new char[30][30];
|
||||
@@ -182,6 +184,8 @@ public class CellLayoutBoard implements Comparable<CellLayoutBoard> {
|
||||
|
||||
WidgetRect mMain = null;
|
||||
|
||||
int mWidth, mHeight;
|
||||
|
||||
CellLayoutBoard() {
|
||||
for (int x = 0; x < mWidget.length; x++) {
|
||||
for (int y = 0; y < mWidget[0].length; y++) {
|
||||
@@ -190,6 +194,17 @@ public class CellLayoutBoard implements Comparable<CellLayoutBoard> {
|
||||
}
|
||||
}
|
||||
|
||||
CellLayoutBoard(int width, int height) {
|
||||
mWidget = new char[width][height];
|
||||
this.mWidth = width;
|
||||
this.mHeight = height;
|
||||
for (int x = 0; x < mWidget.length; x++) {
|
||||
for (int y = 0; y < mWidget[0].length; y++) {
|
||||
mWidget[x][y] = CellType.EMPTY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<WidgetRect> getWidgets() {
|
||||
return mWidgetsRects;
|
||||
}
|
||||
@@ -256,6 +271,16 @@ public class CellLayoutBoard implements Comparable<CellLayoutBoard> {
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private char getNextWidgetType() {
|
||||
for (char type = 'a'; type <= 'z'; type++) {
|
||||
if (type == 'i') continue;
|
||||
if (mUsedWidgetTypes.contains(type)) continue;
|
||||
mUsedWidgetTypes.add(type);
|
||||
return type;
|
||||
}
|
||||
return 'z';
|
||||
}
|
||||
|
||||
public void addWidget(int x, int y, int spanX, int spanY, char type) {
|
||||
Rect rect = new Rect(x, y + spanY - 1, x + spanX - 1, y);
|
||||
removeOverlappingItems(rect);
|
||||
@@ -268,6 +293,10 @@ public class CellLayoutBoard implements Comparable<CellLayoutBoard> {
|
||||
}
|
||||
}
|
||||
|
||||
public void addWidget(int x, int y, int spanX, int spanY) {
|
||||
addWidget(x, y, spanX, spanY, getNextWidgetType());
|
||||
}
|
||||
|
||||
public void addIcon(int x, int y) {
|
||||
Point iconCoord = new Point(x, y);
|
||||
removeOverlappingItems(iconCoord);
|
||||
@@ -367,6 +396,8 @@ public class CellLayoutBoard implements Comparable<CellLayoutBoard> {
|
||||
}
|
||||
}
|
||||
}
|
||||
board.mHeight = lines.length;
|
||||
board.mWidth = lines[0].length();
|
||||
board.mWidgetsRects = getRects(board.mWidget);
|
||||
board.mWidgetsRects.forEach(widgetRect -> {
|
||||
if (widgetRect.mType == CellType.MAIN_WIDGET) {
|
||||
@@ -380,6 +411,11 @@ public class CellLayoutBoard implements Comparable<CellLayoutBoard> {
|
||||
|
||||
public String toString(int maxX, int maxY) {
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.append("board: ");
|
||||
s.append(maxX);
|
||||
s.append("x");
|
||||
s.append(maxY);
|
||||
s.append("\n");
|
||||
maxX = Math.min(maxX, mWidget.length);
|
||||
maxY = Math.min(maxY, mWidget[0].length);
|
||||
for (int y = 0; y < maxY; y++) {
|
||||
@@ -391,6 +427,11 @@ public class CellLayoutBoard implements Comparable<CellLayoutBoard> {
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toString(mWidth, mHeight);
|
||||
}
|
||||
|
||||
public static List<CellLayoutBoard> boardListFromString(String boardsStr) {
|
||||
String[] lines = boardsStr.split("\n");
|
||||
ArrayList<String> individualBoards = new ArrayList<>();
|
||||
@@ -410,4 +451,12 @@ public class CellLayoutBoard implements Comparable<CellLayoutBoard> {
|
||||
}
|
||||
return boards;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return mHeight;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user