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