Skip to content

Commit 701d105

Browse files
committed
fixed series of bugs
1 parent 851df23 commit 701d105

6 files changed

Lines changed: 25 additions & 14 deletions

File tree

core/src/main/kotlin/org/evomaster/core/search/gene/ObjectGene.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,10 @@ class ObjectGene(
112112
.forEach { it.randomize(randomness, tryToForceNewValue) }
113113

114114
if (!isFixed){
115-
Lazy.assert {
116-
template != null && additionalFields != null
117-
}
118-
if (additionalFields!!.isNotEmpty())
115+
Lazy.assert { template != null && additionalFields != null }
116+
if (additionalFields!!.isNotEmpty()) {
119117
killChildren(additionalFields!!)
118+
}
120119
val num = randomness.nextInt(MAX_SIZE_ADDITIONAL_FIELDS)
121120
repeat(num){
122121
val added = sampleElementToAdd(randomness)
@@ -265,9 +264,12 @@ class ObjectGene(
265264
}
266265

267266
if(!isFixed){
268-
//TODO what if there is a mismatch here? semantic of this function is unclear
269-
for (i in additionalFields!!.indices){
270-
ok = ok && this.additionalFields!![i].unsafeCopyValueFrom(other.additionalFields!![i])
267+
if (additionalFields!!.isNotEmpty()) {
268+
killChildren(additionalFields!!)
269+
}
270+
val otherAdditionalFields = other.additionalFields
271+
otherAdditionalFields?.forEach {
272+
addChild(it.copy())
271273
}
272274
}
273275

core/src/main/kotlin/org/evomaster/core/search/gene/UUIDGene.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class UUIDGene(
9292
val gene = other.getPhenotype()
9393

9494
if (gene !is UUIDGene) {
95-
throw IllegalArgumentException("Invalid gene type ${gene.javaClass}")
95+
return false
9696
}
9797
return this.mostSigBits.unsafeCopyValueFrom(gene.mostSigBits)
9898
&& this.leastSigBits.unsafeCopyValueFrom(gene.leastSigBits)

core/src/main/kotlin/org/evomaster/core/search/gene/collection/FlexibleMapGene.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,18 @@ where T : Gene {
5858
}
5959

6060
override fun unsafeCopyValueFrom(other: Gene): Boolean {
61-
//TODO
62-
LoggingUtil.uniqueWarn(log,"unsafeCopyValueFrom() not implemented for FlexibleMapGene")
6361

64-
return false
62+
if(other !is FlexibleMapGene<*>) {
63+
return false
64+
}
65+
66+
killAllChildren()
67+
val elements = other.elements
68+
.mapNotNull { it.copy() as? PairGene<T, FlexibleGene> }
69+
.toMutableList()
70+
elements.forEach { it.resetLocalIdRecursively() }
71+
addChildren(elements)
72+
return true
6573
}
6674

6775
override fun isPrintable(): Boolean {

core/src/main/kotlin/org/evomaster/core/search/gene/sql/geometric/SqlPolygonGene.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,15 @@ class SqlPolygonGene(
4646
val pointList = mutableListOf<SqlPointGene>()
4747
repeat(minLengthOfPolygonRing) {
4848
val newGene = points.template.copy() as SqlPointGene
49+
newGene.doInitialize(randomness)
4950
pointList.add(newGene)
5051
do {
5152
newGene.randomize(randomness, tryToForceNewValue)
5253
} while (onlyNonIntersectingPolygons && !noCrossOvers(pointList))
5354
}
5455
points.randomize(randomness, tryToForceNewValue)
5556
points.killAllChildren()
56-
pointList.map { points.addChild(it) }
57+
pointList.forEach { points.addChild(it) }
5758
assert(isLocallyValid())
5859
}
5960

core/src/main/kotlin/org/evomaster/core/search/gene/sql/textsearch/SqlTextSearchQueryGene.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class SqlTextSearchQueryGene(
7878
*/
7979
if (queryLexemes.getViewOfElements().isEmpty()) {
8080
val stringGene = StringGene("lexeme")
81+
stringGene.doInitialize(randomness)
8182
stringGene.randomize(randomness, tryToForceNewValue)
8283
queryLexemes.addElement(stringGene)
8384
}

core/src/test/kotlin/org/evomaster/core/search/gene/GeneRandomizedTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import org.junit.jupiter.api.assertThrows
1313
class GeneRandomizedTest : AbstractGeneTest(){
1414

1515

16-
// @Disabled("seed 1796 is still failing")
1716
@TestFactory
1817
fun testRandomized(): Collection<DynamicTest> {
1918
return (1000..2000L).map {
@@ -50,7 +49,7 @@ class GeneRandomizedTest : AbstractGeneTest(){
5049
}
5150

5251
//FIXME put back once fix all issues it finds
53-
//verifyCopyValueFrom(mutable, rand)
52+
verifyCopyValueFrom(mutable, rand)
5453
}
5554

5655
private fun verifyCopyValueFrom(

0 commit comments

Comments
 (0)