2018-02-07 14:21:44 +01:00
|
|
|
/**
|
|
|
|
*
|
2019-06-30 16:01:08 +02:00
|
|
|
* Copyright © 2018-2019 Paul Schaub
|
2018-02-07 14:21:44 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
package org.jivesoftware.smackx.colors;
|
|
|
|
|
2019-05-07 18:51:22 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
2018-02-07 14:21:44 +01:00
|
|
|
|
|
|
|
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
2019-10-29 21:12:22 +01:00
|
|
|
|
2018-02-10 21:03:17 +01:00
|
|
|
import org.jivesoftware.smackx.colors.ConsistentColor.Deficiency;
|
|
|
|
|
2019-05-06 22:06:13 +02:00
|
|
|
import org.junit.jupiter.api.Test;
|
2018-02-07 14:21:44 +01:00
|
|
|
|
|
|
|
public class ConsistentColorsTest extends SmackTestSuite {
|
|
|
|
|
|
|
|
// Margin of error we allow due to floating point arithmetic
|
|
|
|
private static final float EPS = 0.001f;
|
|
|
|
|
2018-02-10 21:03:17 +01:00
|
|
|
private static final ConsistentColor.ConsistentColorSettings noDeficiency = new ConsistentColor.ConsistentColorSettings(Deficiency.none);
|
|
|
|
private static final ConsistentColor.ConsistentColorSettings redGreenDeficiency = new ConsistentColor.ConsistentColorSettings(Deficiency.redGreenBlindness);
|
|
|
|
private static final ConsistentColor.ConsistentColorSettings blueBlindnessDeficiency = new ConsistentColor.ConsistentColorSettings(Deficiency.blueBlindness);
|
2018-02-07 14:21:44 +01:00
|
|
|
|
2019-06-30 16:01:08 +02:00
|
|
|
private static final String romeo = "Romeo";
|
|
|
|
private static final String juliet = "juliet@capulet.lit";
|
|
|
|
private static final String emoji = "\uD83D\uDE3A";
|
|
|
|
private static final String council = "council";
|
|
|
|
|
2018-02-07 14:21:44 +01:00
|
|
|
/*
|
2019-06-30 16:01:08 +02:00
|
|
|
Below tests check the test vectors from XEP-0392 §13.
|
2018-02-07 14:21:44 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void romeoNoDeficiencyTest() {
|
2019-06-30 16:01:08 +02:00
|
|
|
float[] rgb = new float[] {0.865f, 0.000f, 0.686f};
|
|
|
|
assertRGBEquals(rgb, ConsistentColor.RGBFrom(romeo), EPS);
|
2018-02-07 14:21:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void romeoRedGreenBlindnessTest() {
|
2019-06-30 16:01:08 +02:00
|
|
|
float[] expected = new float[] {0.865f, 0.000f, 0.686f};
|
|
|
|
float[] actual = ConsistentColor.RGBFrom(romeo, redGreenDeficiency);
|
2018-02-07 14:21:44 +01:00
|
|
|
assertRGBEquals(expected, actual, EPS);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void romeoBlueBlindnessTest() {
|
2019-06-30 16:01:08 +02:00
|
|
|
float[] expected = new float[] {0.000f, 0.535f, 0.350f};
|
|
|
|
float[] actual = ConsistentColor.RGBFrom(romeo, blueBlindnessDeficiency);
|
2018-02-07 14:21:44 +01:00
|
|
|
assertRGBEquals(expected, actual, EPS);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void julietNoDeficiencyTest() {
|
2019-06-30 16:01:08 +02:00
|
|
|
float[] expected = new float[] {0.000f, 0.515f, 0.573f};
|
|
|
|
float[] actual = ConsistentColor.RGBFrom(juliet, noDeficiency);
|
2018-02-07 14:21:44 +01:00
|
|
|
assertRGBEquals(expected, actual, EPS);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void julietRedGreenBlindnessTest() {
|
2019-06-30 16:01:08 +02:00
|
|
|
float[] expected = new float[] {0.742f, 0.359f, 0.000f};
|
|
|
|
float[] actual = ConsistentColor.RGBFrom(juliet, redGreenDeficiency);
|
2018-02-07 14:21:44 +01:00
|
|
|
assertRGBEquals(expected, actual, EPS);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void julietBlueBlindnessTest() {
|
2019-06-30 16:01:08 +02:00
|
|
|
float[] expected = new float[] {0.742f, 0.359f, 0.000f};
|
|
|
|
float[] actual = ConsistentColor.RGBFrom(juliet, blueBlindnessDeficiency);
|
2018-02-07 14:21:44 +01:00
|
|
|
assertRGBEquals(expected, actual, EPS);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void emojiNoDeficiencyTest() {
|
2019-06-30 16:01:08 +02:00
|
|
|
float[] expected = new float[] {0.872f, 0.000f, 0.659f};
|
|
|
|
float[] actual = ConsistentColor.RGBFrom(emoji, noDeficiency);
|
2018-02-07 14:21:44 +01:00
|
|
|
assertRGBEquals(expected, actual, EPS);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void emojiRedGreenBlindnessTest() {
|
2019-06-30 16:01:08 +02:00
|
|
|
float[] expected = new float[] {0.872f, 0.000f, 0.659f};
|
|
|
|
float[] actual = ConsistentColor.RGBFrom(emoji, redGreenDeficiency);
|
2018-02-07 14:21:44 +01:00
|
|
|
assertRGBEquals(expected, actual, EPS);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void emojiBlueBlindnessTest() {
|
2019-06-30 16:01:08 +02:00
|
|
|
float[] expected = new float[] {0.000f, 0.533f, 0.373f};
|
|
|
|
float[] actual = ConsistentColor.RGBFrom(emoji, blueBlindnessDeficiency);
|
2018-02-07 14:21:44 +01:00
|
|
|
assertRGBEquals(expected, actual, EPS);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void councilNoDeficiencyTest() {
|
2019-06-30 16:01:08 +02:00
|
|
|
float[] expected = new float[] {0.918f, 0.000f, 0.394f};
|
|
|
|
float[] actual = ConsistentColor.RGBFrom(council, noDeficiency);
|
2018-02-07 14:21:44 +01:00
|
|
|
assertRGBEquals(expected, actual, EPS);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void councilRedGreenBlindnessTest() {
|
2019-06-30 16:01:08 +02:00
|
|
|
float[] expected = new float[] {0.918f, 0.000f, 0.394f};
|
|
|
|
float[] actual = ConsistentColor.RGBFrom(council, redGreenDeficiency);
|
2018-02-07 14:21:44 +01:00
|
|
|
assertRGBEquals(expected, actual, EPS);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void councilBlueBlindnessTest() {
|
2019-06-30 16:01:08 +02:00
|
|
|
float[] expected = new float[] {0.000f, 0.524f, 0.485f};
|
|
|
|
float[] actual = ConsistentColor.RGBFrom(council, blueBlindnessDeficiency);
|
2018-02-07 14:21:44 +01:00
|
|
|
assertRGBEquals(expected, actual, EPS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check, whether the values of two float arrays of size 3 are pairwise equal with an allowed error of eps.
|
|
|
|
*
|
|
|
|
* @param expected expected values
|
|
|
|
* @param actual actual values
|
|
|
|
* @param eps allowed error
|
|
|
|
*/
|
|
|
|
private static void assertRGBEquals(float[] expected, float[] actual, float eps) {
|
|
|
|
assertEquals(3, expected.length);
|
|
|
|
assertEquals(3, actual.length);
|
|
|
|
|
|
|
|
for (int i = 0; i < actual.length; i++) {
|
2019-06-30 16:01:08 +02:00
|
|
|
assertEquals(expected[i], actual[i], eps);
|
2018-02-07 14:21:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|