1/* 2 * Copyright (C) 2016 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 android.support.percent; 18 19import android.app.Activity; 20import android.app.Instrumentation; 21import android.support.test.InstrumentationRegistry; 22import android.support.test.rule.ActivityTestRule; 23import android.support.test.runner.AndroidJUnit4; 24import android.test.ActivityInstrumentationTestCase2; 25import junit.framework.Assert; 26import org.junit.Before; 27import org.junit.Rule; 28import org.junit.runner.RunWith; 29 30import static junit.framework.Assert.assertEquals; 31 32@RunWith(AndroidJUnit4.class) 33public abstract class BaseInstrumentationTestCase<A extends Activity> { 34 @Rule 35 public final ActivityTestRule<A> mActivityTestRule; 36 37 protected BaseInstrumentationTestCase(Class<A> activityClass) { 38 mActivityTestRule = new ActivityTestRule<A>(activityClass); 39 } 40 41 protected static void assertFuzzyEquals(String description, float expected, float actual) { 42 // On devices with certain screen densities we may run into situations where multiplying 43 // container width / height by a certain fraction ends up in a number that is almost but 44 // not exactly a round float number. For example, we can do float math to compute 15% 45 // of 1440 pixels and get 216.00002 due to inexactness of float math. This is why our 46 // tolerance is slightly bigger than 1 pixel in the comparison below. 47 assertEquals(description, expected, actual, 1.1f); 48 } 49} 50