package cs437.som.neighborhood;

import org.testng.annotations.Test;

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

public class GaussianNeighborhoodWidthFunctionTest {
    private static final int ITERATIONS = 1000;
    private static final double STANDARD_DEVIATION = 100.0;
    private static final int[] SAMPLES = {0, 1, 10, 100, 200, 500, 1000};
    private static final double[] SAMPLE_RESULTS =
            {0.00398942, 0.00398922, 0.00396953, 0.00241971, 0.00053991,
                    1.48672e-8, 7.6946e-25};
    private static final double[] SAMPLE_ACCURACY =
            {1.0e-8, 1.0e-8, 1.0e-8, 1.0e-8, 1.0e-8, 1.0e-13, 1.0e-29};

    @Test
    public void testNeighborhoodWidth() throws Exception {
        GaussianNeighborhoodWidthFunction gnwf =
                new GaussianNeighborhoodWidthFunction(STANDARD_DEVIATION);
        gnwf.setExpectedIterations(ITERATIONS);

        // always decreasing
        double last = gnwf.neighborhoodWidth(0);
        for (int i = 1; i < ITERATIONS; i++) {
            double current = gnwf.neighborhoodWidth(i);
            assertTrue(current <= last, "Must consistently decrease.");
            last = current;
        }

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

@@ -26,16 +26,58 @@
 rhood;%0A%0A
+import org.testng.annotations.BeforeTest;%0A
 import o
@@ -733,136 +733,107 @@
     
-@Test%0A    public void testNeighborhoodWidth() throws Exception %7B%0A        GaussianNeighborhoodWidthFunction gnwf =%0A      
+private GaussianNeighborhoodWidthFunction gnwf;%0A%0A    @BeforeTest%0A    public void setUp() %7B%0A
         
   ne
@@ -828,17 +828,22 @@
         
- 
+gnwf =
  new Gau
@@ -946,37 +946,88 @@
 S);%0A
-%0A        // always decreasing
+    %7D%0A%0A    @Test%0A    public void testConsistentlyDecreasing() throws Exception %7B
 %0A   
@@ -1289,58 +1289,59 @@
   %7D%0A
-%0A
     
+%7D%0A%0A
     
-// Verify the function fits known samples
+@Test%0A    public void testBySampling() %7B
 %0A   

Split tests into seperate methods in GaussianNeighborhoodWidthFunctionTest.