Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GradientColorKeyframeAnimation does not handle progress outside [0,1] #2427

Merged
merged 5 commits into from
Dec 15, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add GradientColorTest
  • Loading branch information
Sven Obser committed Dec 13, 2023
commit 68da2bab2a2fe2dfdba549dae7a7d26c2ea304eb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.airbnb.lottie.model.content;

import junit.framework.TestCase;
import org.junit.Test;

import java.util.Arrays;

public class GradientColorTest extends TestCase {

private final GradientColor start = new GradientColor(new float[]{0f, 1f}, new int[]{0xFF000000, 0xFF020202});

private final GradientColor end = new GradientColor(new float[]{0f, 1f}, new int[]{0xFF020202, 0xFF040404});

private final GradientColor gradient = new GradientColor(new float[2], new int[2]);

@Test
public void testLerpWithOutOfBoundsNegativeProgress() {
gradient.lerp(start, end, -42f);
assertEquals(start, gradient);
}

@Test
public void testLerpWithZeroProgress() {
gradient.lerp(start, end, 0f);
assertEquals(start, gradient);
}

@Test
public void testLerpWithHalfProgress() {
gradient.lerp(start, end, 0.5f);
GradientColor half = new GradientColor(new float[]{0f, 1f}, new int[]{0xFF010101, 0xFF030303});
assertEquals(half, gradient);
}

@Test
public void testLerpWithOneProgress() {
gradient.lerp(start, end, 1f);
assertEquals(end, gradient);
}

@Test
public void testLerpWithOutOfBoundsPositiveProgress() {
gradient.lerp(start, end, 42f);
assertEquals(end, gradient);
}
}