/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.commons.math3.ml.clustering;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.math3.exception.MathIllegalArgumentException;
import org.apache.commons.math3.exception.NullArgumentException;
import org.apache.commons.math3.ml.distance.CanberraDistance;
import org.apache.commons.math3.ml.distance.DistanceMeasure;
import org.apache.commons.math3.random.JDKRandomGenerator;
import org.apache.commons.math3.random.RandomGenerator;
import org.junit.Test;

public class FuzzyKMeansClustererTest {

    @Test
    public void testCluster() {
        List<DoublePoint> points = new ArrayList<DoublePoint>();
        
        // create 10 data points: [1], ... [10]
        for (int i = 1; i <= 10; i++) {
            DoublePoint p = new DoublePoint(new double[] { i } );
            points.add(p);
        }

        final FuzzyKMeansClusterer<DoublePoint> transformer =
                new FuzzyKMeansClusterer<DoublePoint>(3, 2.0);
        final List<CentroidCluster<DoublePoint>> clusters = transformer.cluster(points);

        // we expect 3 clusters:
        //   [1], [2], [3]
        //   [4], [5], [6], [7]
        //   [8], [9], [10]
        final List<DoublePoint> clusterOne = Arrays.asList(points.get(0), points.get(1), points.get(2));
        final List<DoublePoint> clusterTwo = Arrays.asList(points.get(3), points.get(4), points.get(5), points.get(6));
        final List<DoublePoint> clusterThree = Arrays.asList(points.get(7), points.get(8), points.get(9));

        boolean cluster1Found = false;
        boolean cluster2Found = false;
        boolean cluster3Found = false;
        assertEquals(3, clusters.size());
        for (final Cluster<DoublePoint> cluster : clusters) {
            if (cluster.getPoints().containsAll(clusterOne)) {
                cluster1Found = true;
            }
            if (cluster.getPoints().containsAll(clusterTwo)) {
                cluster2Found = true;
            }
            if (cluster.getPoints().containsAll(clusterThree)) {
                cluster3Found = true;
            }
        }
        assertTrue(cluster1Found);
        assertTrue(cluster2Found);
        assertTrue(cluster3Found);
    }

    @Test(expected = MathIllegalArgumentException.class)
    public void testTooSmallFuzzynessFactor() {
        new FuzzyKMeansClusterer<DoublePoint>(3, 1.0);
    }

    @Test(expected = NullArgumentException.class)
    public void testNullDataset() {
        FuzzyKMeansClusterer<DoublePoint> clusterer = new FuzzyKMeansClusterer<DoublePoint>(3, 2.0);
        clusterer.cluster(null);
    }
    
    @Test
    public void testGetters() {
        DistanceMeasure measure = new CanberraDistance();
        RandomGenerator random = new JDKRandomGenerator();
        FuzzyKMeansClusterer<DoublePoint> clusterer =
                new FuzzyKMeansClusterer<DoublePoint>(3, 2.0, 100, measure, 1e-6, random);
        
        assertEquals(3, clusterer.getK());
        assertEquals(2.0, clusterer.getFuzziness(), 1e-6);
        assertEquals(100, clusterer.getMaxIterations());
        assertEquals(1e-6, clusterer.getEpsilon(), 1e-12);
        assertThat(clusterer.getDistanceMeasure(), is(measure));
        assertThat(clusterer.getRandomGenerator(), is(random));
    }

}

@@ -889,43 +889,141 @@
 ers.
-*;%0Aimport static org.junit.Assert.*
+is;%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertThat;%0Aimport static org.junit.Assert.assertTrue
 ;%0A%0Ai
@@ -1588,16 +1588,22 @@
         
+final 
 List%3CDou
@@ -1651,24 +1651,16 @@
 int%3E();%0A
-        
 %0A       
@@ -1752,16 +1752,22 @@
         
+final 
 DoublePo
@@ -3461,32 +3461,38 @@
 set() %7B%0A        
+final 
 FuzzyKMeansClust
@@ -3560,32 +3560,32 @@
 Point%3E(3, 2.0);%0A
-
         clustere
@@ -3607,21 +3607,17 @@
 ;%0A    %7D%0A
-    
 %0A
+
     @Tes
@@ -3658,16 +3658,22 @@
         
+final 
 Distance
@@ -3722,16 +3722,22 @@
         
+final 
 RandomGe
@@ -3787,16 +3787,22 @@
         
+final 
 FuzzyKMe
@@ -3930,24 +3930,16 @@
 andom);%0A
-        
 %0A       

Replace wildcard imports, add final declarations.