package cs437.som.neighborhood;

import org.testng.annotations.Test;

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

public class LinearDecayNeighborhoodWidthFunctionTest {
    private static final double MAXIMUM_DIFFERENCE = 0.0000000000000001;
    private static final double MAXIMUM_SLOPE_DIFFERENCE = 0.001;
    private static final int ITERATIONS = 1000;
    private static final double WIDTH = 1.0;

    @Test
    public void testNeighborhoodWidth() throws Exception {
        LinearDecayNeighborhoodWidthFunction ldnwf =
                new LinearDecayNeighborhoodWidthFunction(WIDTH);
        ldnwf.setExpectedIterations(ITERATIONS);

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

        double slope = ldnwf.neighborhoodWidth(1) - ldnwf.neighborhoodWidth(0);
        for (int i = 1; i < ITERATIONS; i++) {
            double currentSlope = ldnwf.neighborhoodWidth(i+1)
                    - ldnwf.neighborhoodWidth(i);
            assertEquals(currentSlope, slope, MAXIMUM_SLOPE_DIFFERENCE,
                    String.format("Should have constant slope. @%d", i));
        }

        assertEquals(ldnwf.neighborhoodWidth(0), WIDTH, MAXIMUM_DIFFERENCE);
        for (int i = 1; i < ITERATIONS; i++) {
            assertEquals(ldnwf.neighborhoodWidth(i), WIDTH - ((double) i / ITERATIONS),
                    MAXIMUM_DIFFERENCE, "Should be exactly linear.");
        }
    }
}

@@ -26,16 +26,58 @@
 rhood;%0A%0A
+import org.testng.annotations.BeforeTest;%0A
 import o
@@ -493,140 +493,111 @@
     
-@Test%0A    public void testNeighborhoodWidth() throws Exception %7B%0A        LinearDecayNeighborhoodWidthFunction ldnwf =%0A      
+private LinearDecayNeighborhoodWidthFunction ldnwf;%0A%0A    @BeforeTest%0A    public void setUp() %7B%0A
         
   ne
@@ -592,17 +592,23 @@
         
- 
+ldnwf =
  new Lin
@@ -698,16 +698,86 @@
 TIONS);%0A
+    %7D%0A%0A    @Test%0A    public void testAlwaysDecays() throws Exception %7B
 %0A       
@@ -1035,86 +1035,136 @@
   %7D%0A
-%0A
     
+%7D%0A%0A    @Test%0A
     
-double slope = ldnwf.neighborhoodWidth(1) - ldnwf.neighborhoodWidth(0
+public void testMustBeLinear() %7B%0A        assertEquals(ldnwf.neighborhoodWidth(0), WIDTH, MAXIMUM_DIFFERENCE
 );%0A 
@@ -1225,30 +1225,21 @@
     
-double currentSlope = 
+assertEquals(
 ldnw
@@ -1263,107 +1263,65 @@
 th(i
-+1)%0A                    - ldnwf.neighborhoodWidth(i);%0A            assertEquals(currentSlope, slope,
+), WIDTH - ((double) i / ITERATIONS),%0A                   
  MAX
@@ -1317,38 +1317,32 @@
         MAXIMUM_
-SLOPE_
 DIFFERENCE,%0A    
@@ -1336,29 +1336,55 @@
 FERENCE,
-%0A    
+ %22Should be exactly linear.%22);%0A
         
         
@@ -1379,155 +1379,142 @@
     
+%7D%0A
     
+%7D%0A%0A
     
-String.format(%22Should have c
+@Test%0A    public void testC
 onstant
- s
+S
 lope
-. @%25d%22, i));%0A        %7D%0A%0A        assertEquals(ldnwf.neighborhoodWidth(0), WIDTH, MAXIMUM_DIFFERENCE
+() %7B%0A        double slope = ldnwf.neighborhoodWidth(1) - ldnwf.neighborhoodWidth(0
 );%0A 
@@ -1567,37 +1567,46 @@
             
-assertEquals(
+double currentSlope = 
 ldnwf.neighb
@@ -1622,65 +1622,109 @@
 th(i
-), WIDTH - ((double) i / ITERATIONS),%0A                   
+ + 1)%0A                    - ldnwf.neighborhoodWidth(i);%0A            assertEquals(currentSlope, slope,
  MAX
@@ -1720,32 +1720,38 @@
  slope, MAXIMUM_
+SLOPE_
 DIFFERENCE, %22Sho
@@ -1749,36 +1749,80 @@
 NCE,
- %22Should be exactly linear.%22
+%0A                    String.format(%22Should have constant slope. @%25d%22, i)
 );%0A 

Split tests into seperate methods in LinearDecayNeighborhoodWidthFunctionTest.