Skip to content
Permalink
Browse files

Adjusted basic assertions.

Code somewhat cleaned up.
Added escapes for special characters (\ and $) and a couple of tests for them.
Updated to account for differences between Kotlin and Java.
Added targetFormat to the Gene (to allow the gene to know the format needed).
  • Loading branch information...
bogdanmarculescu committed Apr 29, 2019
1 parent 030b6b8 commit 85884e68b85786b7b4e008252d44017777e1a5d2
Showing with 94 additions and 76 deletions.
  1. +3 −3 core/src/main/kotlin/org/evomaster/core/database/DbActionTransformer.kt
  2. +1 −1 core/src/main/kotlin/org/evomaster/core/database/DbActionUtils.kt
  3. +5 −6 core/src/main/kotlin/org/evomaster/core/output/TestCaseWriter.kt
  4. +1 −1 core/src/main/kotlin/org/evomaster/core/problem/rest/service/RestFitness.kt
  5. +3 −2 core/src/main/kotlin/org/evomaster/core/search/gene/ArrayGene.kt
  6. +2 −1 core/src/main/kotlin/org/evomaster/core/search/gene/Base64StringGene.kt
  7. +2 −1 core/src/main/kotlin/org/evomaster/core/search/gene/BooleanGene.kt
  8. +2 −1 core/src/main/kotlin/org/evomaster/core/search/gene/CycleObjectGene.kt
  9. +2 −1 core/src/main/kotlin/org/evomaster/core/search/gene/DateGene.kt
  10. +2 −1 core/src/main/kotlin/org/evomaster/core/search/gene/DateTimeGene.kt
  11. +3 −2 core/src/main/kotlin/org/evomaster/core/search/gene/DisruptiveGene.kt
  12. +2 −1 core/src/main/kotlin/org/evomaster/core/search/gene/DoubleGene.kt
  13. +2 −1 core/src/main/kotlin/org/evomaster/core/search/gene/EnumGene.kt
  14. +2 −1 core/src/main/kotlin/org/evomaster/core/search/gene/FloatGene.kt
  15. +4 −2 core/src/main/kotlin/org/evomaster/core/search/gene/Gene.kt
  16. +2 −1 core/src/main/kotlin/org/evomaster/core/search/gene/ImmutableDataHolderGene.kt
  17. +2 −1 core/src/main/kotlin/org/evomaster/core/search/gene/IntegerGene.kt
  18. +2 −1 core/src/main/kotlin/org/evomaster/core/search/gene/LongGene.kt
  19. +3 −2 core/src/main/kotlin/org/evomaster/core/search/gene/MapGene.kt
  20. +4 −3 core/src/main/kotlin/org/evomaster/core/search/gene/ObjectGene.kt
  21. +3 −2 core/src/main/kotlin/org/evomaster/core/search/gene/OptionalGene.kt
  22. +2 −1 core/src/main/kotlin/org/evomaster/core/search/gene/SqlAutoIncrementGene.kt
  23. +3 −2 core/src/main/kotlin/org/evomaster/core/search/gene/SqlForeignKeyGene.kt
  24. +3 −2 core/src/main/kotlin/org/evomaster/core/search/gene/SqlPrimaryKeyGene.kt
  25. +3 −1 core/src/main/kotlin/org/evomaster/core/search/gene/SqlTimestampGene.kt
  26. +9 −8 core/src/main/kotlin/org/evomaster/core/search/gene/StringGene.kt
  27. +2 −1 core/src/main/kotlin/org/evomaster/core/search/gene/TimeGene.kt
  28. +1 −1 core/src/test/kotlin/org/evomaster/core/search/gene/Base64StringGeneTest.kt
  29. +3 −3 core/src/test/kotlin/org/evomaster/core/search/gene/MapGeneTest.kt
  30. +10 −9 core/src/test/kotlin/org/evomaster/core/search/gene/StringGeneTest.kt
  31. +1 −2 experiments/src/main/kotlin/org/evomaster/experiments/objects/service/ObjFitness.kt
  32. +1 −2 experiments/src/main/kotlin/org/evomaster/experiments/objects/service/ObjRestSampler.kt
  33. +4 −9 experiments/src/main/kotlin/org/evomaster/experiments/objects/writer/ObjTestCaseWriter.kt
@@ -56,10 +56,10 @@ object DbActionTransformer {
if (k is SqlForeignKeyGene) {
isFkReferenceToNonPrintable = handleSqlForeignKey(k, previous, entry)
} else {
entry.printableValue = g.getValueAsPrintableString()
entry.printableValue = g.getValueAsPrintableString(targetFormat = null)
}
} else {
entry.printableValue = g.getValueAsPrintableString()
entry.printableValue = g.getValueAsPrintableString(targetFormat = null)
}

entry.variableName = g.getVariableName()
@@ -99,7 +99,7 @@ object DbActionTransformer {
if (isFkReferenceToNonPrintable) {
entry.foreignKeyToPreviouslyGeneratedRow = g.uniqueIdOfPrimaryKey
} else {
entry.printableValue = g.getValueAsPrintableString(previous)
entry.printableValue = g.getValueAsPrintableString(previous, targetFormat = null)
}

return isFkReferenceToNonPrintable
@@ -283,7 +283,7 @@ object DbActionUtils {
} else if ((g is SqlPrimaryKeyGene && g.isReferenceToNonPrintable(all))) {
"FK_REFERENCE_ " + (g.gene as SqlForeignKeyGene).uniqueIdOfPrimaryKey
} else {
g.getValueAsPrintableString(all)
g.getValueAsPrintableString(all, targetFormat = null)
}
}

@@ -17,7 +17,6 @@ import org.evomaster.core.search.EvaluatedAction
import org.evomaster.core.search.gene.Gene
import org.evomaster.core.search.gene.SqlForeignKeyGene
import org.evomaster.core.search.gene.SqlPrimaryKeyGene
import java.awt.PageAttributes
import javax.ws.rs.core.MediaType


@@ -176,7 +175,7 @@ class TestCaseWriter {
return getPrintableValue(g.gene)

} else {
return StringEscapeUtils.escapeJava(g.getValueAsPrintableString())
return StringEscapeUtils.escapeJava(g.getValueAsPrintableString(targetFormat = null))
}
}

@@ -446,9 +445,9 @@ class TestCaseWriter {
if(bodyParam.isJson()) {

val body = if (readable) {
OutputFormatter.JSON_FORMATTER.getFormatted(bodyParam.gene.getValueAsPrintableString(mode = "json"))
OutputFormatter.JSON_FORMATTER.getFormatted(bodyParam.gene.getValueAsPrintableString(mode = "json", targetFormat = null))
} else {
bodyParam.gene.getValueAsPrintableString(mode = "json")
bodyParam.gene.getValueAsPrintableString(mode = "json", targetFormat = null)
}

//needed as JSON uses ""
@@ -472,7 +471,7 @@ class TestCaseWriter {
val body = bodyParam.gene.getValueAsPrintableString("xml")
lines.add(".body(\"$body\")")
} */ else if(bodyParam.isTextPlain()) {
val body = bodyParam.gene.getValueAsPrintableString(mode = "text")
val body = bodyParam.gene.getValueAsPrintableString(mode = "text", targetFormat = null)
lines.add(".body($body)")
} else {
throw IllegalStateException("Unrecognized type: " + bodyParam.contentType())
@@ -496,7 +495,7 @@ class TestCaseWriter {
call.parameters.filterIsInstance<HeaderParam>()
.filter { !prechosenAuthHeaders.contains(it.name) }
.forEach {
lines.add(".header(\"${it.name}\", ${it.gene.getValueAsPrintableString()})")
lines.add(".header(\"${it.name}\", ${it.gene.getValueAsPrintableString(targetFormat = null)})")
}
}

@@ -358,7 +358,7 @@ class RestFitness : FitnessFunction<RestIndividual>() {
body.isTextPlain() -> "text"
else -> throw IllegalStateException("Cannot handle body type: " + body.contentType())
}
Entity.entity(body.gene.getValueAsPrintableString(mode = mode), body.contentType())
Entity.entity(body.gene.getValueAsPrintableString(mode = mode, targetFormat = null), body.contentType())
} else if (forms != null) {
Entity.entity(forms, MediaType.APPLICATION_FORM_URLENCODED_TYPE)
} else if(a.verb == HttpVerb.PUT || a.verb == HttpVerb.PATCH){
@@ -1,5 +1,6 @@
package org.evomaster.core.search.gene

import org.evomaster.core.output.OutputFormat
import org.evomaster.core.search.service.Randomness


@@ -56,9 +57,9 @@ class ArrayGene<T>(
}
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
return "[" +
elements.map { g -> g.getValueAsPrintableString(previousGenes, mode) }.joinToString(", ") +
elements.map { g -> g.getValueAsPrintableString(previousGenes, mode, null) }.joinToString(", ") +
"]";
}

@@ -1,5 +1,6 @@
package org.evomaster.core.search.gene

import org.evomaster.core.output.OutputFormat
import org.evomaster.core.search.service.Randomness
import java.util.*

@@ -14,7 +15,7 @@ class Base64StringGene(
data.randomize(randomness, forceNewValue)
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
return Base64.getEncoder().encodeToString(data.value.toByteArray())
}

@@ -1,5 +1,6 @@
package org.evomaster.core.search.gene

import org.evomaster.core.output.OutputFormat
import org.evomaster.core.search.service.Randomness


@@ -21,7 +22,7 @@ class BooleanGene(name: String, var value: Boolean = true) : Gene(name) {
value = k
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
return value.toString()
}

@@ -1,5 +1,6 @@
package org.evomaster.core.search.gene

import org.evomaster.core.output.OutputFormat
import org.evomaster.core.search.service.Randomness

/**
@@ -23,7 +24,7 @@ class CycleObjectGene(name: String) : ObjectGene(name, listOf()) {
//nothing to do
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
throw IllegalStateException("CycleObjectGene has no value")
}

@@ -1,5 +1,6 @@
package org.evomaster.core.search.gene

import org.evomaster.core.output.OutputFormat
import org.evomaster.core.search.service.Randomness

/**
@@ -28,7 +29,7 @@ class DateGene(
day.randomize(randomness, forceNewValue, allGenes)
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
return "\"${getValueAsRawString()}\""
}

@@ -1,5 +1,6 @@
package org.evomaster.core.search.gene

import org.evomaster.core.output.OutputFormat
import org.evomaster.core.search.service.Randomness

/**
@@ -32,7 +33,7 @@ open class DateTimeGene(
time.randomize(randomness, forceNewValue, allGenes)
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
return "\"${getValueAsRawString()}\""
}

@@ -1,5 +1,6 @@
package org.evomaster.core.search.gene

import org.evomaster.core.output.OutputFormat
import org.evomaster.core.search.service.Randomness

/**
@@ -26,8 +27,8 @@ class DisruptiveGene<out T>(name: String, val gene: T, var probability: Double)
gene.randomize(randomness, forceNewValue, allGenes)
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?): String {
return gene.getValueAsPrintableString(previousGenes, mode)
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
return gene.getValueAsPrintableString(previousGenes, mode, null)
}

override fun getValueAsRawString(): String {
@@ -1,5 +1,6 @@
package org.evomaster.core.search.gene

import org.evomaster.core.output.OutputFormat
import org.evomaster.core.search.service.Randomness


@@ -15,7 +16,7 @@ class DoubleGene(name: String,
value = randomness.nextDouble()
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
return value.toString()
}

@@ -1,5 +1,6 @@
package org.evomaster.core.search.gene

import org.evomaster.core.output.OutputFormat
import org.evomaster.core.search.service.Randomness


@@ -39,7 +40,7 @@ class EnumGene<T>(
index = k
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {

val res = values[index]
if(res is String){
@@ -1,5 +1,6 @@
package org.evomaster.core.search.gene

import org.evomaster.core.output.OutputFormat
import org.evomaster.core.search.service.Randomness


@@ -15,7 +16,7 @@ class FloatGene(name: String,
value = randomness.nextFloat()
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
return value.toString()
}

@@ -1,5 +1,6 @@
package org.evomaster.core.search.gene

import org.evomaster.core.output.OutputFormat
import org.evomaster.core.search.service.Randomness


@@ -61,11 +62,12 @@ abstract class Gene(var name: String) {
*/
abstract fun getValueAsPrintableString(
previousGenes: List<Gene> = listOf(),
mode: String? = null
mode: String? = null,
targetFormat: OutputFormat? = null
) : String


open fun getValueAsRawString() = getValueAsPrintableString()
open fun getValueAsRawString() = getValueAsPrintableString(targetFormat = null)

abstract fun copyValueFrom(other: Gene)

@@ -1,5 +1,6 @@
package org.evomaster.core.search.gene

import org.evomaster.core.output.OutputFormat
import org.evomaster.core.search.service.Randomness


@@ -26,7 +27,7 @@ class ImmutableDataHolderGene(name: String, val value: String, val inQuotes: Boo
throw IllegalStateException("Not supposed to modify an immutable gene")
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {

if(inQuotes){
return "\"$value\""
@@ -1,5 +1,6 @@
package org.evomaster.core.search.gene

import org.evomaster.core.output.OutputFormat
import org.evomaster.core.search.service.Randomness


@@ -65,7 +66,7 @@ class IntegerGene(

}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
return value.toString()
}
}
@@ -1,5 +1,6 @@
package org.evomaster.core.search.gene

import org.evomaster.core.output.OutputFormat
import org.evomaster.core.search.service.Randomness


@@ -30,7 +31,7 @@ class LongGene (
value = k
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?) : String{
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?) : String{
return value.toString()
}

@@ -1,5 +1,6 @@
package org.evomaster.core.search.gene

import org.evomaster.core.output.OutputFormat
import org.evomaster.core.search.service.Randomness


@@ -58,14 +59,14 @@ class MapGene<T>(
}
}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?): String {
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
return "{" +
elements.filter { f ->
f !is CycleObjectGene &&
(f !is OptionalGene || f.isActive)
}.map { f ->
"""
"${f.name}":${f.getValueAsPrintableString()}
"${f.name}":${f.getValueAsPrintableString(targetFormat = null)}
"""
}.joinToString(",") +
"}";
@@ -1,5 +1,6 @@
package org.evomaster.core.search.gene

import org.evomaster.core.output.OutputFormat
import org.evomaster.core.search.service.Randomness

/**
@@ -36,7 +37,7 @@ open class ObjectGene(name: String, val fields: List<out Gene>, val refType : St
}


override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?) : String{
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?) : String{

val buffer = StringBuffer()

@@ -48,7 +49,7 @@ open class ObjectGene(name: String, val fields: List<out Gene>, val refType : St
it !is CycleObjectGene &&
(it !is OptionalGene || it.isActive)
}.map {
"\"${it.name}\":${it.getValueAsPrintableString(previousGenes,mode)}"
"\"${it.name}\":${it.getValueAsPrintableString(previousGenes, mode, null)}"
}.joinTo(buffer, ", ")

buffer.append("}")
@@ -67,7 +68,7 @@ open class ObjectGene(name: String, val fields: List<out Gene>, val refType : St
(it !is OptionalGene || it.isActive)
}.forEach {
buffer.append(openXml(it.name))
buffer.append(it.getValueAsPrintableString(previousGenes,mode))
buffer.append(it.getValueAsPrintableString(previousGenes, mode, null))
buffer.append(closeXml(it.name))
}

@@ -1,5 +1,6 @@
package org.evomaster.core.search.gene

import org.evomaster.core.output.OutputFormat
import org.evomaster.core.search.service.Randomness

/**
@@ -50,8 +51,8 @@ class OptionalGene(name: String,

}

override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?): String {
return gene.getValueAsPrintableString()
override fun getValueAsPrintableString(previousGenes: List<Gene>, mode: String?, targetFormat: OutputFormat?): String {
return gene.getValueAsPrintableString(targetFormat = null)
}

override fun getValueAsRawString(): String {
Oops, something went wrong.

0 comments on commit 85884e6

Please sign in to comment.
You can’t perform that action at this time.