File tree Expand file tree Collapse file tree
main/kotlin/org/evomaster/core/search/gene
test/kotlin/org/evomaster/core/search/gene Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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)
Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change @@ -13,7 +13,6 @@ import org.junit.jupiter.api.assertThrows
1313class 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 (
You can’t perform that action at this time.
0 commit comments