Testing Gradient Color Array Merging Implementation in Lottie Android
This test suite validates the GradientColorParser functionality in Lottie Android, focusing on array merging operations for gradient color processing. The tests ensure proper handling of float arrays with various scenarios including distinct and non-distinct elements.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
airbnb/lottie-android
lottie/src/test/java/com/airbnb/lottie/parser/GradientColorParserTest.java
package com.airbnb.lottie.parser;
import static org.junit.Assert.assertArrayEquals;
import org.junit.Test;
public class GradientColorParserTest {
@Test public void testNoDistinctShort() {
assertMerged(new float[]{1}, new float[]{2}, new float[]{1, 2});
}
@Test public void testNoDistinct() {
assertMerged(new float[]{1, 2, 3}, new float[]{4, 5, 6}, new float[]{1, 2, 3, 4, 5, 6});
}
@Test public void testWithDistinct() {
assertMerged(new float[]{1, 2, 3, 5}, new float[]{4, 5, 6}, new float[]{1, 2, 3, 4, 5, 6});
}
@Test public void testWithDistinctInterleavingValues() {
assertMerged(new float[]{2, 4, 5, 6, 8, 10}, new float[]{1, 3, 4, 5, 7, 9}, new float[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
}
@Test public void testIdentical() {
assertMerged(new float[]{2, 3}, new float[]{2, 3}, new float[]{2, 3});
}
private void assertMerged(float[] arrayA, float[] arrayB, float[] merged) {
assertArrayEquals(merged, GradientColorParser.mergeUniqueElements(arrayA, arrayB), 0f);
}
}