package cs437.som.neighborhood;

import org.testng.annotations.Test;

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

public class HyperbolicNeighborhoodWidthFunctionTest {
    private static final double MAXIMUM_DIFFERENCE = 0.0000000000000001;
    private static final int ITERATIONS = 1000;
    private static final double START_WIDTH = 10.0;
    private static final double END_WIDTH = 1.0;

    @Test
    public void testNeighborhoodWidth() throws Exception {
        HyperbolicNeighborhoodWidthFunction hnwf =
                new HyperbolicNeighborhoodWidthFunction(START_WIDTH, END_WIDTH);
        hnwf.setExpectedIterations(ITERATIONS);

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

        assertEquals(hnwf.neighborhoodWidth(0), START_WIDTH, MAXIMUM_DIFFERENCE);
        for (int i = 1; i < ITERATIONS; i++) {
            assertTrue(hnwf.neighborhoodWidth(i) < START_WIDTH - (i / ITERATIONS),
                    "Hyperbolic function should be less than linear.");
        }

        // todo check against perfect hyperbola
    }
}

@@ -432,16 +432,287 @@
 = 1.0;%0A%0A
+    private static final int%5B%5D SAMPLES = %7B0,100,200,500,1000%7D;%0A    private static final double%5B%5D SAMPLE_RESULTS =%0A            %7B10, 7.94328, 6.30957, 3.16228, 1%7D;%0A    private static final double%5B%5D SAMPLE_ACCURACY =%0A            %7B1.0e-10, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-10%7D;%0A%0A
     @Tes
@@ -1528,44 +1528,228 @@
  // 
-todo check against perfect hyperbola
+Verify the function fits known samples%0A        for (int j = 0; j %3C SAMPLES.length; j++) %7B%0A            assertEquals(hnwf.neighborhoodWidth(SAMPLES%5Bj%5D), SAMPLE_RESULTS%5Bj%5D,%0A                    SAMPLE_ACCURACY%5Bj%5D);%0A        %7D
 %0A   

Add sample-based testing to HyperbolicNeighborhoodWidthFunctionTest.