All Downloads are FREE. Search and download functionalities are using the official Maven repository.

lu.uni.serval.ikora.smells.checks.ComplicatedSetupCheck Maven / Gradle / Ivy

There is a newer version: 0.1.19
Show newest version
package lu.uni.serval.ikora.smells.checks;

import lu.uni.serval.ikora.smells.SmellCheck;
import lu.uni.serval.ikora.smells.SmellConfiguration;
import lu.uni.serval.ikora.smells.SmellMetric;
import lu.uni.serval.ikora.smells.SmellResult;

import lu.uni.serval.ikora.core.analytics.difference.Edit;
import lu.uni.serval.ikora.core.analytics.KeywordStatistics;
import lu.uni.serval.ikora.core.model.KeywordCall;
import lu.uni.serval.ikora.core.model.SourceNode;
import lu.uni.serval.ikora.core.model.TestCase;

import java.util.HashSet;
import java.util.Optional;
import java.util.Set;

public class ComplicatedSetupCheck implements SmellCheck {
    @Override
    public SmellResult computeMetric(TestCase testCase, SmellConfiguration configuration) {
        double rawValue = Double.NaN;
        double normalizedValue = Double.NaN;

        final Set nodes = new HashSet<>();
        final Optional setup = testCase.getSetup();

        if(setup.isPresent()){
            int setupSize = KeywordStatistics.getSequenceSize(setup.get());
            int testCaseSize = KeywordStatistics.getSequenceSize(testCase);

            nodes.add(setup.get());

            rawValue = setupSize;
            normalizedValue = rawValue / (setupSize + testCaseSize);
        }

        return new SmellResult(SmellMetric.Type.COMPLICATED_SETUP_SCENARIOS, rawValue, normalizedValue, nodes);
    }

    @Override
    public boolean isFix(Edit edit, Set nodes, SmellConfiguration configuration) {
            if(nodes.contains(edit.getLeft())){
                int oldSize = KeywordStatistics.getSequenceSize(edit.getLeft());
                int newSize = KeywordStatistics.getSequenceSize(edit.getRight());

                return oldSize > newSize;
            }

        return false;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy