Home | History | Annotate | Download | only in tests
      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 
     17 package androidx.vectordrawable.graphics.drawable.tests;
     18 
     19 import static org.junit.Assert.assertTrue;
     20 
     21 import android.app.Activity;
     22 import android.support.test.filters.MediumTest;
     23 import android.support.test.rule.ActivityTestRule;
     24 import android.view.animation.Interpolator;
     25 
     26 import androidx.vectordrawable.graphics.drawable.AnimationUtilsCompat;
     27 import androidx.vectordrawable.test.R;
     28 
     29 import org.junit.Before;
     30 import org.junit.Rule;
     31 import org.junit.Test;
     32 import org.junit.runner.RunWith;
     33 import org.junit.runners.Parameterized;
     34 
     35 import java.util.Arrays;
     36 import java.util.Collection;
     37 
     38 @MediumTest
     39 @RunWith(Parameterized.class)
     40 public class PathInterpolatorValueParameterizedTest {
     41     private static final float EPSILON = 1e-3f;
     42     @Rule
     43     public ActivityTestRule<DrawableStubActivity> mActivityRule =
     44             new ActivityTestRule<>(DrawableStubActivity.class);
     45 
     46     private Activity mActivity = null;
     47     private int mResId;
     48     private float mExpected;
     49 
     50     @Parameterized.Parameters
     51     public static Collection<Object[]> data() {
     52         return Arrays.asList(new Object[][]{
     53                 {R.interpolator.control_points_interpolator, 0.89f},
     54                 {R.interpolator.single_control_point_interpolator, 0.086f},
     55                 {R.interpolator.path_interpolator, 0.85f}
     56         });
     57     }
     58 
     59     public PathInterpolatorValueParameterizedTest(final int resId, float expected)
     60             throws Throwable {
     61         mResId = resId;
     62         mExpected = expected;
     63     }
     64 
     65     @Before
     66     public void setup() {
     67         mActivity = mActivityRule.getActivity();
     68     }
     69 
     70     @Test
     71     public void testPathInterpolator() throws Exception {
     72         Interpolator interpolator = AnimationUtilsCompat.loadInterpolator(mActivity, mResId);
     73         float value = interpolator.getInterpolation(0.5f);
     74         float delta = Math.abs(value - mExpected);
     75         assertTrue("value " + value + " is different than expected " + mExpected, delta < EPSILON);
     76     }
     77 }
     78