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 
17 package com.android.compose.animation.scene
18 
19 import androidx.compose.foundation.gestures.Orientation
20 import androidx.compose.ui.unit.Density
21 import androidx.compose.ui.unit.IntOffset
22 import androidx.compose.ui.unit.IntSize
23 import androidx.compose.ui.unit.dp
24 import androidx.test.ext.junit.runners.AndroidJUnit4
25 import com.google.common.truth.Truth.assertThat
26 import org.junit.Test
27 import org.junit.runner.RunWith
28 
29 @RunWith(AndroidJUnit4::class)
30 class FixedSizeEdgeDetectorTest {
31     private val detector = FixedSizeEdgeDetector(30.dp)
32     private val layoutSize = IntSize(100, 100)
33     private val density = Density(1f)
34 
35     @Test
horizontalEdgesnull36     fun horizontalEdges() {
37         fun horizontalEdge(position: Int): Edge? =
38             detector.source(
39                 layoutSize,
40                 position = IntOffset(position, 0),
41                 density,
42                 Orientation.Horizontal,
43             )
44 
45         assertThat(horizontalEdge(0)).isEqualTo(Edge.Left)
46         assertThat(horizontalEdge(30)).isEqualTo(Edge.Left)
47         assertThat(horizontalEdge(31)).isEqualTo(null)
48         assertThat(horizontalEdge(69)).isEqualTo(null)
49         assertThat(horizontalEdge(70)).isEqualTo(Edge.Right)
50         assertThat(horizontalEdge(100)).isEqualTo(Edge.Right)
51     }
52 
53     @Test
verticalEdgesnull54     fun verticalEdges() {
55         fun verticalEdge(position: Int): Edge? =
56             detector.source(
57                 layoutSize,
58                 position = IntOffset(0, position),
59                 density,
60                 Orientation.Vertical,
61             )
62 
63         assertThat(verticalEdge(0)).isEqualTo(Edge.Top)
64         assertThat(verticalEdge(30)).isEqualTo(Edge.Top)
65         assertThat(verticalEdge(31)).isEqualTo(null)
66         assertThat(verticalEdge(69)).isEqualTo(null)
67         assertThat(verticalEdge(70)).isEqualTo(Edge.Bottom)
68         assertThat(verticalEdge(100)).isEqualTo(Edge.Bottom)
69     }
70 }
71