1 /* 2 * Copyright (C) 2024 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 17 package com.android.launcher3.celllayout 18 19 import org.junit.Rule 20 import org.junit.Test 21 22 // @RunWith(AndroidJUnit4::class) b/353965234 23 class CellLayoutMethodsTest { 24 25 @JvmField @Rule var cellLayoutBuilder = UnitTestCellLayoutBuilderRule() 26 27 //@Test pointToCellExactnull28 fun pointToCellExact() { 29 val width = 1000 30 val height = 1000 31 val columns = 30 32 val rows = 30 33 val cl = cellLayoutBuilder.createCellLayout(columns, rows, false, width, height) 34 35 val res = intArrayOf(0, 0) 36 for (col in 0..<columns) { 37 for (row in 0..<rows) { 38 val x = (width / columns) * col 39 val y = (height / rows) * row 40 cl.pointToCellExact(x, y, res) 41 cl.pointToCellExact(x, y, res) 42 assertValues(col, res, row, columns, rows, width, height, x, y) 43 } 44 } 45 46 cl.pointToCellExact(-10, -10, res) 47 assertValues(0, res, 0, columns, rows, width, height, -10, -10) 48 cl.pointToCellExact(width + 10, height + 10, res) 49 assertValues(columns - 1, res, rows - 1, columns, rows, width, height, -10, -10) 50 } 51 assertValuesnull52 private fun assertValues( 53 col: Int, 54 res: IntArray, 55 row: Int, 56 columns: Int, 57 rows: Int, 58 width: Int, 59 height: Int, 60 x: Int, 61 y: Int 62 ) { 63 assert(col == res[0] && row == res[1]) { 64 "Cell Layout with values (c= $columns, r= $rows, w= $width, h= $height) didn't mapped correctly the pixels ($x, $y) to the cells ($col, $row) with result (${res[0]}, ${res[1]})" 65 } 66 } 67 } 68