diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2016-04-02 14:12:34 -0700 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2016-05-27 09:12:26 -0700 |
commit | ff4ba2d99593ed84963b3f71c555b529dd905835 (patch) | |
tree | df473dbc5a6ec373367de624187323a5132dc9b6 /tests/src/com/android/launcher3 | |
parent | 3c4b03dd01b89a4d4beba6a866ae3bb9093e101e (diff) | |
download | android_packages_apps_Trebuchet-ff4ba2d99593ed84963b3f71c555b529dd905835.tar.gz android_packages_apps_Trebuchet-ff4ba2d99593ed84963b3f71c555b529dd905835.tar.bz2 android_packages_apps_Trebuchet-ff4ba2d99593ed84963b3f71c555b529dd905835.zip |
Refactoring out grid occupancy management in a separate class
Change-Id: I37a830c0f2eb0a0dd4f5fc78fa29127cb18cb3c2
Diffstat (limited to 'tests/src/com/android/launcher3')
-rw-r--r-- | tests/src/com/android/launcher3/util/FocusLogicTest.java | 2 | ||||
-rw-r--r-- | tests/src/com/android/launcher3/util/GridOccupancyTest.java | 61 |
2 files changed, 62 insertions, 1 deletions
diff --git a/tests/src/com/android/launcher3/util/FocusLogicTest.java b/tests/src/com/android/launcher3/util/FocusLogicTest.java index 386f7dd34..eee567fb8 100644 --- a/tests/src/com/android/launcher3/util/FocusLogicTest.java +++ b/tests/src/com/android/launcher3/util/FocusLogicTest.java @@ -14,7 +14,7 @@ * the License. */ -package com.android.launcher3; +package com.android.launcher3.util; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; diff --git a/tests/src/com/android/launcher3/util/GridOccupancyTest.java b/tests/src/com/android/launcher3/util/GridOccupancyTest.java new file mode 100644 index 000000000..7d0fe716e --- /dev/null +++ b/tests/src/com/android/launcher3/util/GridOccupancyTest.java @@ -0,0 +1,61 @@ +package com.android.launcher3.util; + +import android.test.suitebuilder.annotation.SmallTest; + +import junit.framework.TestCase; + +/** + * Unit tests for {@link GridOccupancy} + */ +@SmallTest +public class GridOccupancyTest extends TestCase { + + public void testFindVacantCell() { + GridOccupancy grid = initGrid(4, + 1, 1, 1, 0, 0, + 0, 0, 1, 1, 0, + 0, 0, 0, 0, 0, + 1, 1, 0, 0, 0 + ); + + int[] vacant = new int[2]; + assertTrue(grid.findVacantCell(vacant, 2, 2)); + assertEquals(vacant[0], 0); + assertEquals(vacant[1], 1); + + assertTrue(grid.findVacantCell(vacant, 3, 2)); + assertEquals(vacant[0], 2); + assertEquals(vacant[1], 2); + + assertFalse(grid.findVacantCell(vacant, 3, 3)); + } + + public void testIsRegionVacant() { + GridOccupancy grid = initGrid(4, + 1, 1, 1, 0, 0, + 0, 0, 1, 1, 0, + 0, 0, 0, 0, 0, + 1, 1, 0, 0, 0 + ); + + assertTrue(grid.isRegionVacant(4, 0, 1, 4)); + assertTrue(grid.isRegionVacant(0, 1, 2, 2)); + assertTrue(grid.isRegionVacant(2, 2, 3, 2)); + + assertFalse(grid.isRegionVacant(3, 0, 2, 4)); + assertFalse(grid.isRegionVacant(0, 0, 2, 1)); + } + + private GridOccupancy initGrid(int rows, int... cells) { + int cols = cells.length / rows; + int i = 0; + GridOccupancy grid = new GridOccupancy(cols, rows); + for (int y = 0; y < rows; y++) { + for (int x = 0; x < cols; x++) { + grid.cells[x][y] = cells[i] != 0; + i++; + } + } + return grid; + } +} |