Skip to content

Commit

Permalink
Cleaned comments from the code
Browse files Browse the repository at this point in the history
  • Loading branch information
onurd86 committed Sep 26, 2023
1 parent 15d8d8b commit c0415a3
Showing 1 changed file with 13 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.evomaster.core.problem.rest.*;
import org.evomaster.core.search.*;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -178,7 +179,6 @@ private boolean pathsMatchFocusOrPrefix(RestPath pathToAnalyze, RestPath pathFoc

// if mode is focus, path and pathFocusOrPrefix match only if they are the same
if (focusMode) {

return pathToAnalyze.isEquivalent(pathFocusOrPrefix);
}
// focusMode is false, which means prefix match
Expand Down Expand Up @@ -206,82 +206,29 @@ else if (paths.isEmpty()) {

// in focusMode, none of the paths match with the empty path
// in prefix mode, every path matches with the empty path
return focusMode != true;
return !focusMode;
}
else {

// actions and results
// actions and noMAtchFlag
List<RestCallAction> actions = ind.getIndividual().seeMainExecutableActions();
List<ActionResult> results = ind.seeResults(actions);

boolean noMatchFlag = false;

for (int i = 0; i < actions.size() && !noMatchFlag; i++) {

RestCallAction action = actions.get(i);

// if none of them match in one solution, noMatchFlag is true
if (paths.stream().noneMatch(currentPath -> pathsMatchFocusOrPrefix(action.getPath(),
currentPath, focusMode))) {
noMatchFlag = true;
}

}

// if a patch which does not match has been encountered, return false
return noMatchFlag != true;
return !noMatchFlag;
}


}

/*
Path only version of hasAtLeastOne
protected boolean hasFocusInPath(EvaluatedIndividual<RestIndividual> ind,
String path)
{
List<RestCallAction> actions = ind.getIndividual().seeMainExecutableActions();
List<ActionResult> results = ind.seeResults(actions);
//boolean stopped = false;
//for (int i = 0; i < actions.size() && !stopped; i++) {
for (int i = 0; i < actions.size(); i++) {
RestCallResult res = (RestCallResult) results.get(i);
//stopped = res.getStopping();
RestCallAction action = actions.get(i);
//System.out.println(action.getPath());
// check if it is the path with -1
if (path != null) {
RestPath target = new RestPath(path);
if (!action.getPath().isEquivalent(target)) {
// to exclude /:-1/v2/swagger.json from search
if (!action.getPath().toString().contains(".json"))
{
continue;
}
}
}
return true;
}
return false;
}
*/


/*
All solutions should have one of the provided paths as the focus or the prefix
*/
Expand All @@ -291,6 +238,7 @@ protected void assertAllSolutionsHavePathFocusOrPrefixList(Solution<RestIndividu
// convert String list of paths to list of RestPaths
List<RestPath> listOfRestPaths = new ArrayList<>();

// convert list of Strings to a list of RestPaths
for (String path : paths) {
listOfRestPaths.add(new RestPath(path));
}
Expand All @@ -299,94 +247,24 @@ protected void assertAllSolutionsHavePathFocusOrPrefixList(Solution<RestIndividu
boolean ok = solution.getIndividuals().stream().allMatch(
ind -> hasFocusOrPrefixInPath(ind, listOfRestPaths, focusMode) );

// error message
String errorMsg = "Not all the provided paths are contained in the solution as" +
" the focus or prefix\n";
errorMsg = errorMsg + "List of paths given to check:\n";

// display paths in the error message
for (String path : paths) {
errorMsg = errorMsg + path + "\n";
errorMsg = MessageFormat.format("{0}{1}\n", errorMsg, path);
}

// display list of paths included in the solution in the error message
errorMsg = errorMsg + "List of paths included in the solution\n";
errorMsg = errorMsg + restActions(solution);

// assertion
assertTrue(ok, errorMsg + restActions(solution));

}

/*
protected void assertAllSolutionsHavePathFocus(Solution<RestIndividual> solution,
String path) {
boolean ok = solution.getIndividuals().stream().allMatch(
ind -> hasFocusInPath(ind, path));
String errorMsg = "Seed " + (defaultSeed-1)+". ";
errorMsg += "Missing " + path + "\n";
assertTrue(ok, errorMsg + restActions(solution));
}
*/

/*
protected boolean hasPrefixInPath(EvaluatedIndividual<RestIndividual> ind,
String path)
{
List<RestCallAction> actions = ind.getIndividual().seeMainExecutableActions();
List<ActionResult> results = ind.seeResults(actions);
//boolean stopped = false;
//for (int i = 0; i < actions.size() && !stopped; i++) {
for (int i = 0; i < actions.size(); i++) {
RestCallResult res = (RestCallResult) results.get(i);
//stopped = res.getStopping();
RestCallAction action = actions.get(i);
//System.out.println(action.getPath());
// check if it is the path with -1
if (path != null) {
RestPath target = new RestPath(path);
if (!action.getPath().toString().startsWith(path)) {
// to exclude /:-1/v2/swagger.json from search
if (!action.getPath().toString().contains(".json"))
{
continue;
}
}
}
return true;
}
return false;
}
*/

/*
protected void assertAllSolutionsHavePathPrefix(Solution<RestIndividual> solution,
String path) {
boolean ok = solution.getIndividuals().stream().allMatch(
ind -> hasPrefixInPath(ind, path));
String errorMsg = "Seed " + (defaultSeed-1)+". ";
errorMsg += "Missing " + path + "\n";
assertTrue(ok, errorMsg + restActions(solution));
}
*/



protected int countExpected(Solution<RestIndividual> solution,
HttpVerb verb,
int expectedStatusCode,
Expand Down

0 comments on commit c0415a3

Please sign in to comment.