package market.guess.ui.desktop; import static org.junit.jupiter.api.Assertions.assertEquals; import market.guess.ui.desktop.components.graphic.GraphicHelper; import market.guess.ui.desktop.components.graphic.MarketChartGraphic; import market.guess.ui.desktop.components.graphic.Motion; import market.guess.ui.desktop.components.graphic.SparklineGraphic; import org.junit.jupiter.api.Test; /** * The handoff requires "animations off" to show the frozen final frame, fully legible and never * blank. Since every graphic renders as a function of progress, that contract is exactly: at * progress 1, every driver lands on its designed end value. */ class AnimTest { private static final double[] BAR1 = {0, .35, .30, 1, .60, .6, 1, .35}; @Test void keyframesHoldTheirEndValue() { assertEquals(.35, GraphicHelper.at(0, BAR1), 1e-9); assertEquals(1.0, GraphicHelper.at(.30, BAR1), 1e-9); assertEquals(.35, GraphicHelper.at(1, BAR1), 1e-9); assertEquals(.675, GraphicHelper.at(.15, BAR1), 1e-9); // interpolates linearly between stops assertEquals(.35, Motion.at(0, BAR1), 1e-9); } @Test void ridersEndOnTheLastPointOfTheirPath() { assertEquals( MarketChartGraphic.YES_CURVE[6], MarketChartGraphic.rideCurve(MarketChartGraphic.YES_CURVE, 1)[0], 1e-6); assertEquals( MarketChartGraphic.YES_CURVE[7], MarketChartGraphic.rideCurve(MarketChartGraphic.YES_CURVE, 1)[1], 1e-6); int last = SparklineGraphic.SPARK.length; assertEquals( SparklineGraphic.SPARK[last - 2], SparklineGraphic.ridePolyline(SparklineGraphic.SPARK, 1)[0], 1e-6); assertEquals( SparklineGraphic.SPARK[last - 1], SparklineGraphic.ridePolyline(SparklineGraphic.SPARK, 1)[1], 1e-6); } @Test void ridersStartOnTheFirstPointOfTheirPath() { assertEquals( MarketChartGraphic.YES_CURVE[0], MarketChartGraphic.rideCurve(MarketChartGraphic.YES_CURVE, 0)[0], 1e-6); assertEquals( MarketChartGraphic.YES_CURVE[1], MarketChartGraphic.rideCurve(MarketChartGraphic.YES_CURVE, 0)[1], 1e-6); assertEquals( SparklineGraphic.SPARK[0], SparklineGraphic.ridePolyline(SparklineGraphic.SPARK, 0)[0], 1e-6); assertEquals( SparklineGraphic.SPARK[1], SparklineGraphic.ridePolyline(SparklineGraphic.SPARK, 0)[1], 1e-6); } }