diff options
| author | Kostya <mail@sartin.in> | 2026-10-11 19:28:04 +0300 |
|---|---|---|
| committer | Kostya <mail@sartin.in> | 2026-10-11 19:28:30 +0300 |
| commit | 3a734b84705ccb8174e9cf24b74d7a3c3b2c1beb (patch) | |
| tree | 80408f2f1e6af973b1f61288c87a89b4ee8e96d3 /ui-fx/src/test | |
| parent | dc616e0f340f28b320253bf9a70778a07b885ffd (diff) | |
| download | guess-market-3a734b84705ccb8174e9cf24b74d7a3c3b2c1beb.tar.gz guess-market-3a734b84705ccb8174e9cf24b74d7a3c3b2c1beb.tar.xz guess-market-3a734b84705ccb8174e9cf24b74d7a3c3b2c1beb.zip | |
ui-fx: move the JavaFX UI into a module that sees only the api
Exercise 3 asks for a new desktop client that reuses the Exercise 2
screens, and the course asks that clients depend on the DTO contract,
never on the engine. ui-desktop mixed both: its views and controllers
only talk to the api interfaces, but AppView and AppState each had a
convenience constructor that built a ServiceEngine, which tied every UI
class to the service module.
Move the screens, controllers, components, FXML, skins and fonts into
a new ui-fx module that depends on api alone. Packages are unchanged,
so FXML controller names and resource paths keep working as they are.
ui-desktop keeps only the Exercise 2 app: Launcher, App, which now
builds the ServiceEngine and passes its contexts in, and ServiceEngine
itself. The Exercise 3 client can then reuse ui-fx with remote
contexts and never put the engine on its classpath. The build proves
the split: ui-fx compiles with nothing but api visible.
Tests move with the code they cover. AppStateTest drives the real
engine, so it stays in ui-desktop.
Diffstat (limited to 'ui-fx/src/test')
3 files changed, 131 insertions, 0 deletions
diff --git a/ui-fx/src/test/java/market/guess/ui/desktop/AnimTest.java b/ui-fx/src/test/java/market/guess/ui/desktop/AnimTest.java new file mode 100644 index 0000000..1a39ba1 --- /dev/null +++ b/ui-fx/src/test/java/market/guess/ui/desktop/AnimTest.java | |||
| @@ -0,0 +1,70 @@ | |||
| 1 | package market.guess.ui.desktop; | ||
| 2 | |||
| 3 | import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| 4 | |||
| 5 | import market.guess.ui.desktop.components.graphic.GraphicHelper; | ||
| 6 | import market.guess.ui.desktop.components.graphic.MarketChartGraphic; | ||
| 7 | import market.guess.ui.desktop.components.graphic.Motion; | ||
| 8 | import market.guess.ui.desktop.components.graphic.SparklineGraphic; | ||
| 9 | import org.junit.jupiter.api.Test; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * The handoff requires "animations off" to show the frozen final frame, fully legible and never | ||
| 13 | * blank. Since every graphic renders as a function of progress, that contract is exactly: at | ||
| 14 | * progress 1, every driver lands on its designed end value. | ||
| 15 | */ | ||
| 16 | class AnimTest { | ||
| 17 | private static final double[] BAR1 = {0, .35, .30, 1, .60, .6, 1, .35}; | ||
| 18 | |||
| 19 | @Test | ||
| 20 | void keyframesHoldTheirEndValue() { | ||
| 21 | assertEquals(.35, GraphicHelper.at(0, BAR1), 1e-9); | ||
| 22 | assertEquals(1.0, GraphicHelper.at(.30, BAR1), 1e-9); | ||
| 23 | assertEquals(.35, GraphicHelper.at(1, BAR1), 1e-9); | ||
| 24 | assertEquals(.675, GraphicHelper.at(.15, BAR1), 1e-9); // interpolates linearly between stops | ||
| 25 | assertEquals(.35, Motion.at(0, BAR1), 1e-9); | ||
| 26 | } | ||
| 27 | |||
| 28 | @Test | ||
| 29 | void ridersEndOnTheLastPointOfTheirPath() { | ||
| 30 | assertEquals( | ||
| 31 | MarketChartGraphic.YES_CURVE[6], | ||
| 32 | MarketChartGraphic.rideCurve(MarketChartGraphic.YES_CURVE, 1)[0], | ||
| 33 | 1e-6); | ||
| 34 | assertEquals( | ||
| 35 | MarketChartGraphic.YES_CURVE[7], | ||
| 36 | MarketChartGraphic.rideCurve(MarketChartGraphic.YES_CURVE, 1)[1], | ||
| 37 | 1e-6); | ||
| 38 | |||
| 39 | int last = SparklineGraphic.SPARK.length; | ||
| 40 | assertEquals( | ||
| 41 | SparklineGraphic.SPARK[last - 2], | ||
| 42 | SparklineGraphic.ridePolyline(SparklineGraphic.SPARK, 1)[0], | ||
| 43 | 1e-6); | ||
| 44 | assertEquals( | ||
| 45 | SparklineGraphic.SPARK[last - 1], | ||
| 46 | SparklineGraphic.ridePolyline(SparklineGraphic.SPARK, 1)[1], | ||
| 47 | 1e-6); | ||
| 48 | } | ||
| 49 | |||
| 50 | @Test | ||
| 51 | void ridersStartOnTheFirstPointOfTheirPath() { | ||
| 52 | assertEquals( | ||
| 53 | MarketChartGraphic.YES_CURVE[0], | ||
| 54 | MarketChartGraphic.rideCurve(MarketChartGraphic.YES_CURVE, 0)[0], | ||
| 55 | 1e-6); | ||
| 56 | assertEquals( | ||
| 57 | MarketChartGraphic.YES_CURVE[1], | ||
| 58 | MarketChartGraphic.rideCurve(MarketChartGraphic.YES_CURVE, 0)[1], | ||
| 59 | 1e-6); | ||
| 60 | |||
| 61 | assertEquals( | ||
| 62 | SparklineGraphic.SPARK[0], | ||
| 63 | SparklineGraphic.ridePolyline(SparklineGraphic.SPARK, 0)[0], | ||
| 64 | 1e-6); | ||
| 65 | assertEquals( | ||
| 66 | SparklineGraphic.SPARK[1], | ||
| 67 | SparklineGraphic.ridePolyline(SparklineGraphic.SPARK, 0)[1], | ||
| 68 | 1e-6); | ||
| 69 | } | ||
| 70 | } | ||
diff --git a/ui-fx/src/test/java/market/guess/ui/desktop/ChartsTest.java b/ui-fx/src/test/java/market/guess/ui/desktop/ChartsTest.java new file mode 100644 index 0000000..c5cb280 --- /dev/null +++ b/ui-fx/src/test/java/market/guess/ui/desktop/ChartsTest.java | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | package market.guess.ui.desktop; | ||
| 2 | |||
| 3 | import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| 4 | import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| 5 | |||
| 6 | import market.guess.ui.desktop.util.Charts; | ||
| 7 | import org.junit.jupiter.api.Test; | ||
| 8 | |||
| 9 | class ChartsTest { | ||
| 10 | |||
| 11 | @Test | ||
| 12 | void testToEpochSecondFromIndex() { | ||
| 13 | double t0 = Charts.toEpochSecond(0); | ||
| 14 | double t1 = Charts.toEpochSecond(1); | ||
| 15 | double t2 = Charts.toEpochSecond(2); | ||
| 16 | |||
| 17 | assertEquals(Charts.BASE_TIME, t0, 1e-6); | ||
| 18 | assertEquals(Charts.BASE_TIME + 1800, t1, 1e-6); | ||
| 19 | assertEquals(Charts.BASE_TIME + 3600, t2, 1e-6); | ||
| 20 | } | ||
| 21 | |||
| 22 | @Test | ||
| 23 | void testToEpochSecondIdempotentForTimestamps() { | ||
| 24 | long epoch = 1_700_000_000L; | ||
| 25 | assertEquals(epoch, Charts.toEpochSecond(epoch), 1e-6); | ||
| 26 | } | ||
| 27 | |||
| 28 | @Test | ||
| 29 | void testBaseTimeIsReasonable() { | ||
| 30 | assertTrue(Charts.BASE_TIME > 1_700_000_000L); | ||
| 31 | } | ||
| 32 | } | ||
diff --git a/ui-fx/src/test/java/market/guess/ui/desktop/FormatTest.java b/ui-fx/src/test/java/market/guess/ui/desktop/FormatTest.java new file mode 100644 index 0000000..956a322 --- /dev/null +++ b/ui-fx/src/test/java/market/guess/ui/desktop/FormatTest.java | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | package market.guess.ui.desktop; | ||
| 2 | |||
| 3 | import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| 4 | |||
| 5 | import java.math.BigDecimal; | ||
| 6 | import market.guess.ui.desktop.util.Format; | ||
| 7 | import org.junit.jupiter.api.Test; | ||
| 8 | |||
| 9 | class FormatTest { | ||
| 10 | |||
| 11 | @Test | ||
| 12 | void testMoneyFormatting() { | ||
| 13 | assertEquals("$0.00", Format.money((BigDecimal) null)); | ||
| 14 | assertEquals("$0.00", Format.money(BigDecimal.ZERO)); | ||
| 15 | assertEquals("$0.50", Format.money(new BigDecimal("0.50"))); | ||
| 16 | assertEquals("$123.45", Format.money(new BigDecimal("123.45"))); | ||
| 17 | assertEquals("-$5.00", Format.money(new BigDecimal("-5.00"))); | ||
| 18 | assertEquals("$100.00", Format.money(100.0)); | ||
| 19 | assertEquals("-$2.50", Format.money(-2.50)); | ||
| 20 | } | ||
| 21 | |||
| 22 | @Test | ||
| 23 | void testProbFormatting() { | ||
| 24 | assertEquals("0.50", Format.prob(0.50)); | ||
| 25 | assertEquals("0.75", Format.prob(0.751)); | ||
| 26 | assertEquals("0.00", Format.prob(0.00)); | ||
| 27 | assertEquals("1.00", Format.prob(1.00)); | ||
| 28 | } | ||
| 29 | } | ||