1/* 2 * Copyright 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 */ 16package com.android.managedprovisioning.preprovisioning.anim; 17 18import static android.graphics.Color.parseColor; 19import static android.graphics.Color.rgb; 20 21import static org.hamcrest.MatcherAssert.assertThat; 22import static org.hamcrest.Matchers.equalTo; 23 24import android.support.test.filters.SmallTest; 25 26import org.junit.Test; 27 28@SmallTest 29public class ColorMatcherTest { 30 private final ColorMatcher mColorMatcher = new ColorMatcher(); 31 32 @Test 33 public void findsCloseColor() { 34 assertCorrect(rgb(0, 0, 0), rgb(0, 0, 0)); 35 assertCorrect(rgb(1, 1, 1), rgb(0, 0, 0)); 36 assertCorrect(rgb(15, 15, 15), rgb(0, 0, 0)); 37 assertCorrect(rgb(16, 16, 16), rgb(32, 32, 32)); 38 assertCorrect(rgb(0xff, 0xff, 0xff), rgb(0xff, 0xff, 0xff)); 39 assertCorrect(rgb(0xfe, 0xfe, 0xfe), rgb(0xff, 0xff, 0xff)); 40 assertCorrect(rgb(100, 200, 50), rgb(96, 192, 64)); 41 assertCorrect(rgb(0xd4, 0, 0), rgb(0xe0, 0, 0)); 42 assertCorrect(parseColor("#d40000"), parseColor("#e00000")); 43 } 44 45 private void assertCorrect(int source, int expected) { 46 int actual = mColorMatcher.findClosestColor(source); 47 assertThat(actual, equalTo(expected)); 48 } 49}