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;

    private static final int[] SAMPLES = {0,100,200,500,1000};
    private static final double[] SAMPLE_RESULTS =
            {10, 7.94328, 6.30957, 3.16228, 1};
    private static final double[] SAMPLE_ACCURACY =
            {1.0e-10, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-10};

    @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.");
        }

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

@@ -26,16 +26,58 @@
 rhood;%0A%0A
+import org.testng.annotations.BeforeTest;%0A
 import o
@@ -753,138 +753,109 @@
     
-@Test%0A    public void testNeighborhoodWidth() throws Exception %7B%0A        HyperbolicNeighborhoodWidthFunction hnwf =%0A      
+private HyperbolicNeighborhoodWidthFunction hnwf;%0A%0A    @BeforeTest%0A    public void setUp() %7B%0A
         
   ne
@@ -850,17 +850,22 @@
         
- 
+hnwf =
  new Hyp
@@ -970,16 +970,89 @@
 TIONS);%0A
+    %7D%0A%0A    @Test%0A    public void testConsistentDecay() throws Exception %7B
 %0A       
@@ -1321,81 +1321,77 @@
     
-assertEquals(hnwf.neighborhoodWidth(0), START_WIDTH, MAXIMUM_DIFFERENCE);
+testBySampling();%0A    %7D%0A%0A    @Test%0A    public void testBySampling() %7B
 %0A   
@@ -1408,32 +1408,36 @@
 int 
-i = 1; i %3C ITERATIONS; i
+j = 0; j %3C SAMPLES.length; j
 ++) 
@@ -1456,20 +1456,22 @@
   assert
-True
+Equals
 (hnwf.ne
@@ -1490,44 +1490,80 @@
 dth(
-i) %3C START_WIDTH - (i / ITERATIONS),
+SAMPLES%5Bj%5D), SAMPLE_RESULTS%5Bj%5D,%0A                    SAMPLE_ACCURACY%5Bj%5D);
 %0A   
@@ -1571,132 +1571,147 @@
     
+%7D%0A
     
+%7D%0A%0A
     
-    %22Hyperbolic function should be less than l
+@Test%0A    public void testLessThanL
 inear
-.%22);%0A        %7D%0A%0A        // Verify the function fits known samples
+() %7B%0A        assertEquals(hnwf.neighborhoodWidth(0), START_WIDTH, MAXIMUM_DIFFERENCE);
 %0A   
@@ -1728,36 +1728,32 @@
 int 
-j = 0; j %3C SAMPLES.length; j
+i = 1; i %3C ITERATIONS; i
 ++) 
@@ -1764,38 +1764,36 @@
           assert
-Equals
+True
 (hnwf.neighborho
@@ -1804,78 +1804,114 @@
 dth(
-SAMPLES%5Bj%5D), SAMPLE_RESULTS%5Bj%5D,%0A                    SAMPLE_ACCURACY%5Bj%5D
+i) %3C START_WIDTH - (i / ITERATIONS),%0A                    %22Hyperbolic function should be less than linear.%22
 );%0A 

Split tests into seperate methods in HyperbolicNeighborhoodWidthFunctionTest.