1/* 2 * Copyright (C) 2015 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.v7.graphics; 18 19import org.junit.Test; 20import org.junit.runner.RunWith; 21 22import android.graphics.Bitmap; 23import android.graphics.BitmapFactory; 24import android.support.test.runner.AndroidJUnit4; 25import android.test.InstrumentationTestCase; 26import android.test.suitebuilder.annotation.MediumTest; 27 28import static android.support.v7.graphics.TestUtils.loadSampleBitmap; 29import static org.junit.Assert.assertEquals; 30 31@RunWith(AndroidJUnit4.class) 32public class ConsistencyTest { 33 34 private static final int NUMBER_TRIALS = 10; 35 36 @Test 37 @MediumTest 38 public void testConsistency() { 39 Palette lastPalette = null; 40 final Bitmap bitmap = loadSampleBitmap(); 41 42 for (int i = 0; i < NUMBER_TRIALS; i++) { 43 Palette newPalette = Palette.from(bitmap).generate(); 44 if (lastPalette != null) { 45 assetPalettesEqual(lastPalette, newPalette); 46 } 47 lastPalette = newPalette; 48 } 49 } 50 51 private static void assetPalettesEqual(Palette p1, Palette p2) { 52 assertEquals(p1.getVibrantSwatch(), p2.getVibrantSwatch()); 53 assertEquals(p1.getLightVibrantSwatch(), p2.getLightVibrantSwatch()); 54 assertEquals(p1.getDarkVibrantSwatch(), p2.getDarkVibrantSwatch()); 55 assertEquals(p1.getMutedSwatch(), p2.getMutedSwatch()); 56 assertEquals(p1.getLightMutedSwatch(), p2.getLightMutedSwatch()); 57 assertEquals(p1.getDarkMutedSwatch(), p2.getDarkMutedSwatch()); 58 } 59} 60