package cs437.som.learningrate;

import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

public class HyperbolicLearningRateFunctionTest {
    private static final double MAXIMUM_DIFFERENCE = 0.0000000000000001;
    private static final int ITERATIONS = 1000;
    private static final double START_RATE = 0.8;
    private static final double END_RATE = 0.01;

    private static final int[] SAMPLES = {0,100,200,500,1000};
    private static final double[] SAMPLE_RESULTS =
            {0.8, 0.516156, 0.333021, 0.0894427, 0.01};
    private static final double[] SAMPLE_ACCURACY =
            {1.0e-1, 1.0e-6, 1.0e-6, 1.0e-7, 1.0e-2};

    @Test
    public void testLearningRate() throws Exception {
        HyperbolicLearningRateFunction hlrf =
                new HyperbolicLearningRateFunction(START_RATE, END_RATE);
        hlrf.setExpectedIterations(ITERATIONS);
        assertEquals(hlrf.learningRate(0), START_RATE, MAXIMUM_DIFFERENCE);
        assertEquals(hlrf.learningRate(ITERATIONS), END_RATE, MAXIMUM_DIFFERENCE);

        double last = hlrf.learningRate(1);
        for (int i = 2; i < ITERATIONS; i += 10) {
            double current = hlrf.learningRate(i);
            assertTrue(current < last, "Should consistently decay.");
            last = current;
        }

        // Verify the function fits known samples
        for (int j = 0; j < SAMPLES.length; j++) {
            assertEquals(hlrf.learningRate(SAMPLES[j]), SAMPLE_RESULTS[j],
                    SAMPLE_ACCURACY[j]);
        }
    }
}

@@ -26,16 +26,58 @@
 grate;%0A%0A
+import org.testng.annotations.BeforeTest;%0A
 import o
@@ -747,134 +747,113 @@
 2%7D;%0A
-%0A
     
-@Test
 %0A    p
-ublic void testLearningRate() throws Exception %7B%0A        HyperbolicLearningRateFunction hlrf =%0A       
+rivate HyperbolicLearningRateFunction hlrf;%0A%0A    @BeforeTest%0A    public void setUp() %7B%0A
         
  new
@@ -848,16 +848,22 @@
         
+hlrf =
  new Hyp
@@ -961,16 +961,67 @@
 TIONS);%0A
+    %7D%0A%0A    @Test%0A    public void testEndpoints() %7B%0A
         
@@ -1171,16 +1171,79 @@
 RENCE);%0A
+    %7D%0A%0A    @Test%0A    public void testShape() throws Exception %7B
 %0A       
@@ -1485,24 +1485,75 @@
 ;%0A        %7D%0A
+    %7D%0A%0A    @Test%0A    public void testBySampling() %7B
 %0A        // 

Split tests into seperate methods in HyperbolicLearningRateFunctionTest.