Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,10 @@ class ArrayGene<T>(
*/
fun doesExist(gene: T): Boolean{
if (!isElementApplicableToUniqueCheck(ParamUtil.getValueGene(gene))) return false
return elements.any { ParamUtil.getValueGene(it).containsSameValueAs(ParamUtil.getValueGene(gene)) }
return elements.any {
it.getLeafGene().javaClass == gene.getLeafGene().javaClass &&
it.getLeafGene().containsSameValueAs(gene.getLeafGene())
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package org.evomaster.core.search.gene

import org.evomaster.core.search.gene.collection.ArrayGene
import org.evomaster.core.search.gene.collection.EnumGene
import org.evomaster.core.search.gene.numeric.BigIntegerGene
import org.evomaster.core.search.gene.numeric.IntegerGene
import org.evomaster.core.search.gene.numeric.LongGene
import org.evomaster.core.search.gene.string.StringGene
import org.evomaster.core.search.gene.utils.GeneUtils
import org.evomaster.core.search.gene.wrapper.ChoiceGene
import org.evomaster.core.search.service.Randomness
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
Expand Down Expand Up @@ -207,4 +210,31 @@ class ArrayGeneTest {
assertTrue(!xmlOutput.contains("]"), "XML should not contain square brackets")
assertTrue(!xmlOutput.contains(", "), "XML must not contain commas with spaces")
}

@Test
fun testDoesExistWithDifferentNumericGeneTypes() {
val bigIntegerGeneValue = java.math.BigInteger.valueOf(42L)
val bigIntegerGene = BigIntegerGene("bigInt", bigIntegerGeneValue)

val integerGeneValue = 42
val integerGene = IntegerGene("int", integerGeneValue)

val choiceGene = ChoiceGene("choice", listOf(bigIntegerGene, integerGene))

val arrayWithChoiceGenes = ArrayGene(
"arrayOfChoiceGenes",
template = ChoiceGene("template", listOf(bigIntegerGene, integerGene)),
elements = mutableListOf(choiceGene)
)

val anotherChoiceGene = ChoiceGene("choice", listOf(bigIntegerGene, integerGene))

choiceGene.selectActiveGene(0)
anotherChoiceGene.selectActiveGene(1)

assertFalse(arrayWithChoiceGenes.doesExist(anotherChoiceGene))

}


}
Loading