Skip to content

Commit

Permalink
Negative numbers and empty strings added to query param naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Pgarrett committed Nov 29, 2024
1 parent 35faac8 commit e07430f
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import org.evomaster.core.search.Solution
import org.evomaster.core.search.action.Action
import org.evomaster.core.search.action.EvaluatedAction
import org.evomaster.core.search.gene.BooleanGene
import org.evomaster.core.search.gene.numeric.NumberGene
import org.evomaster.core.search.gene.string.StringGene
import javax.ws.rs.core.MediaType

open class RestActionTestCaseNamingStrategy(
Expand Down Expand Up @@ -161,12 +163,38 @@ open class RestActionTestCaseNamingStrategy(
result.add(and)
}
}

val numberQueryParams = getNumberQueryParams(queryParams)
numberQueryParams.forEachIndexed { index, queryParam ->
result.add("negative")
result.add(queryParam.name)
if (index != numberQueryParams.lastIndex) {
result.add(and)
}
}

val emptyStringQueryParams = getEmptyStringQueryParams(queryParams)
emptyStringQueryParams.forEachIndexed { index, queryParam ->
result.add("empty")
result.add(queryParam.name)
if (index != emptyStringQueryParams.lastIndex) {
result.add(and)
}
}
}

private fun getBooleanQueryParams(queryParams: List<QueryParam>): List<QueryParam> {
return queryParams.filter { it.getGeneForQuery() is BooleanGene && (it.getGeneForQuery() as BooleanGene).value }
}

private fun getNumberQueryParams(queryParams: List<QueryParam>): List<QueryParam> {
return queryParams.filter { it.getGeneForQuery() is NumberGene<*> && (it.getGeneForQuery() as NumberGene<*>).value.toLong() < 0 }
}

private fun getEmptyStringQueryParams(queryParams: List<QueryParam>): List<QueryParam> {
return queryParams.filter { it.getGeneForQuery() is StringGene && (it.getGeneForQuery() as StringGene).getValueAsRawString().trim().isEmpty() }
}

private fun removeSolvedDuplicates(duplicatedIndividuals: MutableSet<EvaluatedIndividual<*>>, disambiguatedIndividuals: Set<EvaluatedIndividual<*>>) {
duplicatedIndividuals.removeAll(disambiguatedIndividuals)
}
Expand Down

0 comments on commit e07430f

Please sign in to comment.