/*
 * ARX: Powerful Data Anonymization
 * Copyright 2012 - 2016 Fabian Prasser, Florian Kohlmayer and contributors
 * 
 * Licensed 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.deidentifier.arx.test;

import java.util.ArrayList;
import java.util.Iterator;

import org.deidentifier.arx.ARXResult;
import org.deidentifier.arx.metric.Metric;
import org.junit.Before;

/**
 * 
 */
public abstract class AbstractTest {
    
    /**
     * 
     */
    public static enum TestMetric {
        
        /** TODO */
        DMSTAR,
                                   
                                   /** TODO */
        DM,
                                   
                                   /** TODO */
        HEIGHT,
                                   
                                   /** TODO */
        PREC,
                                   
                                   /** TODO */
        ENTROPY,
                                   
                                   /** TODO */
        NMENTROPY
    }
    
    /** TODO */
    protected DataProvider provider = null;
    
    @Before
    public void setUp() {
        provider = new DataProvider();
    }
    
    /**
     * 
     *
     * @param metricType
     * @return
     */
    protected Metric<?> createMetric(final TestMetric metricType) {
        // create metric
        Metric<?> metric = null;
        switch (metricType) {
        case PREC:
            metric = Metric.createPrecisionMetric();
            break;
        case HEIGHT:
            metric = Metric.createHeightMetric();
            break;
        case DMSTAR:
            metric = Metric.createDiscernabilityMetric(true);
            break;
        case DM:
            metric = Metric.createDiscernabilityMetric(false);
            break;
        case ENTROPY:
            metric = Metric.createEntropyMetric();
            break;
        default:
            break;
        }
        return metric;
    }
    
    /**
     * 
     *
     * @param iterator
     * @return
     */
    protected String[][] iteratorToArray(final Iterator<String[]> iterator) {
        final ArrayList<String[]> list = new ArrayList<String[]>();
        while (iterator.hasNext()) {
            list.add(iterator.next());
        }
        return list.toArray(new String[list.size()][]);
    }
    
    /**
     * 
     *
     * @param array
     */
    protected void printArray(final String[][] array) {
        System.out.print("{");
        
        for (int j = 0; j < array.length; j++) {
            final String[] strings = array[j];
            System.out.print("{");
            for (int i = 0; i < strings.length; i++) {
                final String string = strings[i];
                System.out.print("\"");
                System.out.print(string);
                System.out.print("\"");
                if (i < (strings.length - 1)) {
                    System.out.print(",");
                }
            }
            System.out.print("}");
            if (j < (array.length - 1)) {
                System.out.print(",");
            }
            System.out.println();
        }
        System.out.print("}");
    }
    
    /**
     * 
     *
     * @param result
     * @return
     */
    protected String[][] resultToArray(final ARXResult result) {
        final ArrayList<String[]> list = new ArrayList<String[]>();
        final Iterator<String[]> transformed = result.getOutput(false).iterator();
        while (transformed.hasNext()) {
            list.add(transformed.next());
        }
        return list.toArray(new String[list.size()][]);
    }
}

@@ -877,16 +877,94 @@
 %0A/**%0A * 
+Abstract test class%0A * %0A * @author Fabian Prasser%0A * @author Florian Kohlmayer
 %0A */%0Apub
@@ -1013,24 +1013,40 @@
  /**%0A     * 
+Enum for metrics
 %0A     */%0A   
@@ -1091,37 +1091,38 @@
    %0A        /** 
-TODO 
+Metric
 */%0A        DMSTA
@@ -1136,471 +1136,161 @@
     
-                           %0A                                   /** TODO */%0A        DM,%0A                                   %0A                                   /** TODO */%0A        HEIGHT,%0A                                   %0A                                   /** TODO */%0A        PREC,%0A                                   %0A                                   /** TODO */%0A        ENTROPY,%0A                                   %0A                                   /** TODO 
+/** Metric*/%0A        DM,%0A        /** Metric*/%0A        HEIGHT,%0A        /** Metric*/%0A        PREC,%0A        /** Metric*/%0A        ENTROPY,%0A        /** Metric
 */%0A 
@@ -1329,12 +1329,21 @@
 /** 
-TODO
+Data provider
  */%0A
@@ -1486,39 +1486,48 @@
 %0A    /**%0A     * 
-%0A     *
+Creates a metric
 %0A     * @param m
@@ -2276,39 +2276,48 @@
 %0A    /**%0A     * 
-%0A     *
+Convert to array
 %0A     * @param i
@@ -2653,39 +2653,43 @@
 %0A    /**%0A     * 
-%0A     *
+Print array
 %0A     * @param a
@@ -3509,23 +3509,32 @@
 %0A     * 
-%0A     *
+Convert to array
 %0A     * 

Add documentation