• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.launcher3.celllayout;
17 
18 import java.util.Iterator;
19 
20 /**
21  * Represents a test case for {@code ReorderAlgorithmUnitTest}. The test cases are generated from
22  * text, an example of a test is the following:
23  *
24  * board: 10x8
25  * aaaaaaaaai
26  * bbbbbcciii
27  * ---------f
28  * ---------f
29  * ---------f
30  * ---------i
31  * iiddddddii
32  * iieeiiiiii
33  * arguments: 2 5 7 1 3 1 widget valid
34  * board: 10x8
35  * bbbbbbbbbi
36  * eeeeecciii
37  * ---------a
38  * ---------a
39  * ---------a
40  * --zzzzzzzi
41  * iiddddddii
42  * iiffiiiiii
43  *
44  *
45  * This represents a Workspace boards and a dragged widget that wants to be dropped on the
46  * workspace. The endBoard represents the result from such drag
47  * The first board is the startBoard, the arguments are as follow: cellX, cellY, widget spanX,
48  * widget spanY, minimum spanX, minimum spanX, type of object being drag (icon, widget, folder ),
49  * if the resulting board is a valid solution or not reorder was found.
50  *
51  * For more information on how to read the board please go to the text file
52  * reorder_algorithm_test_cases
53  */
54 public class ReorderAlgorithmUnitTestCase {
55 
56     CellLayoutBoard startBoard;
57 
58     int x, y, spanX, spanY, minSpanX, minSpanY;
59     String type;
60     boolean isValidSolution;
61     CellLayoutBoard endBoard;
62 
readNextCase( Iterator<CellLayoutTestCaseReader.TestSection> sections)63     public static ReorderAlgorithmUnitTestCase readNextCase(
64             Iterator<CellLayoutTestCaseReader.TestSection> sections) {
65         ReorderAlgorithmUnitTestCase testCase = new ReorderAlgorithmUnitTestCase();
66         CellLayoutTestCaseReader.Board startBoard =
67                 (CellLayoutTestCaseReader.Board) sections.next();
68         testCase.startBoard = CellLayoutBoard.boardFromString(startBoard.board);
69         CellLayoutTestCaseReader.Arguments arguments =
70                 (CellLayoutTestCaseReader.Arguments) sections.next();
71         testCase.x = Integer.parseInt(arguments.arguments[0]);
72         testCase.y = Integer.parseInt(arguments.arguments[1]);
73         testCase.spanX = Integer.parseInt(arguments.arguments[2]);
74         testCase.spanY = Integer.parseInt(arguments.arguments[3]);
75         testCase.minSpanX = Integer.parseInt(arguments.arguments[4]);
76         testCase.minSpanY = Integer.parseInt(arguments.arguments[5]);
77         testCase.type = arguments.arguments[6];
78         testCase.isValidSolution = arguments.arguments[7].compareTo("valid") == 0;
79 
80         CellLayoutTestCaseReader.Board endBoard = (CellLayoutTestCaseReader.Board) sections.next();
81         testCase.endBoard = CellLayoutBoard.boardFromString(endBoard.board);
82         return testCase;
83     }
84 
getStartBoard()85     public CellLayoutBoard getStartBoard() {
86         return startBoard;
87     }
88 
getX()89     public int getX() {
90         return x;
91     }
92 
setX(int x)93     public void setX(int x) {
94         this.x = x;
95     }
96 
getY()97     public int getY() {
98         return y;
99     }
100 
setY(int y)101     public void setY(int y) {
102         this.y = y;
103     }
104 
getSpanX()105     public int getSpanX() {
106         return spanX;
107     }
108 
setSpanX(int spanX)109     public void setSpanX(int spanX) {
110         this.spanX = spanX;
111     }
112 
getSpanY()113     public int getSpanY() {
114         return spanY;
115     }
116 
setSpanY(int spanY)117     public void setSpanY(int spanY) {
118         this.spanY = spanY;
119     }
120 
getType()121     public String getType() {
122         return type;
123     }
124 
setType(String type)125     public void setType(String type) {
126         this.type = type;
127     }
128 
isValidSolution()129     public boolean isValidSolution() {
130         return isValidSolution;
131     }
132 
setValidSolution(boolean validSolution)133     public void setValidSolution(boolean validSolution) {
134         isValidSolution = validSolution;
135     }
136 
getEndBoard()137     public CellLayoutBoard getEndBoard() {
138         return endBoard;
139     }
140 
setEndBoard(CellLayoutBoard endBoard)141     public void setEndBoard(CellLayoutBoard endBoard) {
142         this.endBoard = endBoard;
143     }
144 
145     @Override
toString()146     public String toString() {
147         String valid = isValidSolution ? "valid" : "invalid";
148         return startBoard + "arguments: " + x + " " + y + " " + spanX + " " + spanY + " " + minSpanX
149                 + " " + minSpanY + " " + type + " " + valid + "\n" + endBoard;
150     }
151 }
152