de.metanome.smart_data_cat.fd.FDAlgorithmTest.java Source code

Java tutorial

Introduction

Here is the source code for de.metanome.smart_data_cat.fd.FDAlgorithmTest.java

Source

/*
 * Copyright 2014 by the Metanome project
 *
 * 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 de.metanome.smart_data_cat.fd;

import java.io.File;
import java.util.ArrayList;

import de.metanome.algorithm_integration.AlgorithmConfigurationException;
import de.metanome.algorithm_integration.configuration.ConfigurationSettingFileInput;
import de.metanome.algorithm_integration.result_receiver.CouldNotReceiveResultException;
import de.metanome.algorithm_integration.result_receiver.FunctionalDependencyResultReceiver;
import de.metanome.algorithm_integration.result_receiver.UniqueColumnCombinationResultReceiver;
import de.metanome.backend.input.csv.DefaultFileInputGenerator;
import de.metanome.smart_data_cat.ucc.UCCAprioriAlgorithm;

import org.apache.commons.lang3.time.StopWatch;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.mockito.Mockito.mock;

public class FDAlgorithmTest {

    protected TaneAlgorithm taneAlgorithm;
    protected String pathIdentifier;
    private DefaultFileInputGenerator fileInputGenerator;
    protected ArrayList<DefaultFileInputGenerator> inputs;

    /**
     * @throws java.lang.Exception
     */
    @Before
    public void setUp() throws Exception {
        taneAlgorithm = new TaneAlgorithm();

        ConfigurationSettingFileInput fileInputSettings = new ConfigurationSettingFileInput(
                "src/test/resources/WDC_planets.csv", true, ',', '\"', '\\', false, true, 0, true, true);

        String path = "D:/Dokumente/DPDC/Data_FunctionalDependencies";
        inputs = new ArrayList<DefaultFileInputGenerator>();
        File folder = new File(path);
        for (String file : folder.list()) {
            ConfigurationSettingFileInput fileInput = new ConfigurationSettingFileInput(path + "/" + file, true,
                    ',', '\"', '\\', false, true, 0, false, true);

            inputs.add(new DefaultFileInputGenerator(fileInput));
        }

        fileInputGenerator = new DefaultFileInputGenerator(fileInputSettings);
    }

    /**
     * @throws java.lang.Exception
     */
    @After
    public void tearDown() throws Exception {

    }

    /**
     * Test method for {@link UCCAprioriAlgorithm#execute()}
     * <p/>
     * When the algorithm is started after configuration a result should be
     * received.
     */
    @Test
    public void testExecute() throws AlgorithmConfigurationException, CouldNotReceiveResultException {
        long start, end;

        // Setup
        this.taneAlgorithm.setRelationalInputConfigurationValue("input file", fileInputGenerator);

        // Execute functionality
        FunctionalDependencyResultReceiver resultReceiver = mock(FunctionalDependencyResultReceiver.class);
        this.taneAlgorithm.setResultReceiver(resultReceiver);

        // Tane
        start = System.currentTimeMillis();
        this.taneAlgorithm.execute();
        end = System.currentTimeMillis();
        System.out.println("Tane: " + (end - start) + "ms (" + taneAlgorithm.numResults + " results)");

    }

    /**
     * Test method for {@link TaneAlgorithm#execute()}
     * <p/>
     * When the algorithm is started after configuration a result should be
     * received.
     */
    @Test
    public void testExecuteAll() throws AlgorithmConfigurationException, CouldNotReceiveResultException {
        long start, end;

        // Execute functionality

        for (DefaultFileInputGenerator input : inputs) {

            taneAlgorithm = new TaneAlgorithm();
            // Setup
            this.taneAlgorithm.setRelationalInputConfigurationValue("input file", input);

            FunctionalDependencyResultReceiver resultReceiver = mock(FunctionalDependencyResultReceiver.class);
            this.taneAlgorithm.setResultReceiver(resultReceiver);

            // Tane
            start = System.currentTimeMillis();
            this.taneAlgorithm.execute();
            end = System.currentTimeMillis();
            System.out.println(input.getInputFile().getName() + " : " + (end - start) + "ms ("
                    + taneAlgorithm.numResults + " results)");

        }

    }

}