001package com.studentgui.apppages;
002
003import java.lang.reflect.Method;
004
005import static org.junit.jupiter.api.Assertions.assertArrayEquals;
006import org.junit.jupiter.api.Test;
007
008/**
009 * Small unit test to validate deterministic jitter reproducibility.
010 * The test uses reflection to invoke the private addJitter(double) helper
011 * on two separate JLineGraph instances configured with the same seed and
012 * deterministic mode. The produced sequences must match exactly.
013 */
014public class JLineGraphDeterministicJitterTest {
015
016    @Test
017    /**
018     * Verify that deterministic jitter with the same seed produces identical
019     * numeric sequences across separate JLineGraph instances.
020     */
021
022    public void deterministicJitterProducesSameSequence() throws Exception {
023        JLineGraph g1 = new JLineGraph();
024        JLineGraph g2 = new JLineGraph();
025
026        g1.setJitterDeterministic(true);
027        g2.setJitterDeterministic(true);
028        g1.setJitterSeed(123456789L);
029        g2.setJitterSeed(123456789L);
030
031        Method addJitter = JLineGraph.class.getDeclaredMethod("addJitter", double.class);
032        addJitter.setAccessible(true);
033
034        final int N = 10;
035        double[] seq1 = new double[N];
036        double[] seq2 = new double[N];
037
038        double base = 2.0;
039        for (int i = 0; i < N; i++) {
040            seq1[i] = (double) addJitter.invoke(g1, base);
041            seq2[i] = (double) addJitter.invoke(g2, base);
042        }
043
044        // sequences must match exactly when using same seed
045        assertArrayEquals(seq1, seq2, 0.0);
046    }
047}