1/* 2 * Copyright (C) 2017 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 17package androidx.wear.widget.util; 18 19import static org.junit.Assert.assertEquals; 20 21import android.graphics.RectF; 22import android.support.test.filters.SmallTest; 23import android.support.test.runner.AndroidJUnit4; 24 25import org.junit.Before; 26import org.junit.Test; 27import org.junit.runner.RunWith; 28 29/** Unit tests for {@link ArcSwipe}. */ 30@SmallTest 31@RunWith(AndroidJUnit4.class) 32public class ArcSwipeTest { 33 private ArcSwipe mArcSwipeUnderTest; 34 private final RectF mFakeBounds = new RectF(0, 0, 400, 400); 35 36 @Before 37 public void setup() { 38 mArcSwipeUnderTest = new ArcSwipe(ArcSwipe.Gesture.FAST_CLOCKWISE, mFakeBounds); 39 } 40 41 @Test 42 public void testSweepAngleClockwise() { 43 assertEquals(0, mArcSwipeUnderTest.getSweepAngle(0, 0, true), 0.0f); 44 assertEquals(360, mArcSwipeUnderTest.getSweepAngle(0, 360, true), 0.0f); 45 assertEquals(90, mArcSwipeUnderTest.getSweepAngle(0, 90, true), 0.0f); 46 assertEquals(90, mArcSwipeUnderTest.getSweepAngle(90, 180, true), 0.0f); 47 assertEquals(225, mArcSwipeUnderTest.getSweepAngle(45, 270, true), 0.0f); 48 assertEquals(270, mArcSwipeUnderTest.getSweepAngle(90, 0, true), 0.0f); 49 assertEquals(170, mArcSwipeUnderTest.getSweepAngle(280, 90, true), 0.0f); 50 } 51 52 @Test 53 public void testSweepAngleAntiClockwise() { 54 assertEquals(360, mArcSwipeUnderTest.getSweepAngle(0, 0, false), 0.0f); 55 assertEquals(0, mArcSwipeUnderTest.getSweepAngle(0, 360, false), 0.0f); 56 assertEquals(270, mArcSwipeUnderTest.getSweepAngle(0, 90, false), 0.0f); 57 assertEquals(270, mArcSwipeUnderTest.getSweepAngle(90, 180, false), 0.0f); 58 assertEquals(135, mArcSwipeUnderTest.getSweepAngle(45, 270, false), 0.0f); 59 assertEquals(90, mArcSwipeUnderTest.getSweepAngle(90, 0, false), 0.0f); 60 assertEquals(190, mArcSwipeUnderTest.getSweepAngle(280, 90, false), 0.0f); 61 } 62 63 @Test 64 public void testGetAngle() { 65 assertEquals(0, mArcSwipeUnderTest.getAngle(200, 0), 0.0f); 66 assertEquals(90, mArcSwipeUnderTest.getAngle(400, 200), 0.0f); 67 assertEquals(180, mArcSwipeUnderTest.getAngle(200, 400), 0.0f); 68 assertEquals(270, mArcSwipeUnderTest.getAngle(0, 200), 0.0f); 69 } 70} 71