File tree Expand file tree Collapse file tree
main/kotlin/org/evomaster/core/search/gene
test/kotlin/org/evomaster/core/search/gene/collection Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1210,8 +1210,7 @@ abstract class Gene(
12101210 // revert back
12111211 val success = unsafeCopyValueFrom(current)
12121212 // reversion should always work... if fails, it is a bug
1213- // FIXME put back once all are implemented, eg, TaintedMapGene currently missing
1214- // assert(success)
1213+ assert (success)
12151214 return false
12161215 }
12171216 return true
Original file line number Diff line number Diff line change @@ -220,16 +220,44 @@ class TaintedMapGene(
220220
221221
222222 override fun containsSameValueAs (other : Gene ): Boolean {
223- // TODO
224223
225- return false
224+ if (other !is TaintedMapGene ){
225+ return false
226+ }
227+
228+ if (this .elements.size != other.elements.size){
229+ return false
230+ }
231+
232+ for (e in this .elements){
233+ val x = other.elements.find { it.first.name == e.first.name }
234+ ? : return false
235+ if (! e.second.containsSameValueAs(x.second)){
236+ return false
237+ }
238+ }
239+
240+ return true
226241 }
227242
228243 override fun unsafeCopyValueFrom (other : Gene ): Boolean {
229- // TODO
230- LoggingUtil .uniqueWarn(log," unsafeCopyValueFrom() not implemented for TaintedMapGene" )
231244
232- return false
245+ if (other !is TaintedMapGene ){
246+ return false
247+ }
248+
249+ killAllChildren()
250+ learnedKeys.clear()
251+ learnedKeys.addAll(other.learnedKeys)
252+ learnedTypes.clear()
253+ learnedTypes.putAll(other.learnedTypes)
254+
255+ other.elements.forEach {
256+ addElement(it.copy() as PairGene <StringGene , Gene >)
257+ }
258+ taintId = other.taintId
259+
260+ return true
233261 }
234262
235263
Original file line number Diff line number Diff line change @@ -62,6 +62,36 @@ class TaintedMapGeneTest{
6262 }
6363
6464
65+ @Test
66+ fun testCopyFrom () {
67+
68+ val foo = TaintedMapGene (" foo" , TaintInputName .getTaintName(42 ))
69+ foo.doInitialize()
70+ assertEquals(1 , foo.getSizeOfElements())
71+
72+ // x
73+ foo.registerKey(" x" )
74+ foo.evolve()
75+ foo.registerNewType(" x" , " java/lang/Integer" )
76+ foo.evolve()
77+
78+ val bar = TaintedMapGene (" bar" , TaintInputName .getTaintName(66 ))
79+ bar.doInitialize()
80+
81+ // y
82+ bar.registerKey(" y" )
83+ bar.evolve()
84+ bar.registerNewType(" y" , " java/lang/Boolean" )
85+ bar.evolve()
86+
87+ assertFalse(foo.containsSameValueAs(bar))
88+
89+ val copied = foo.copyValueFrom(bar)
90+ assertTrue(copied)
91+
92+ assertTrue(foo.containsSameValueAs(bar))
93+ }
94+
6595 private fun verifyCollection (key : String , type : String , lambda : (ArrayDto ) -> Any? ){
6696
6797 val gene = TaintedMapGene (" foo" , TaintInputName .getTaintName(42 ))
You can’t perform that action at this time.
0 commit comments