diff --git a/core/src/main/kotlin/org/evomaster/core/search/gene/collection/ArrayGene.kt b/core/src/main/kotlin/org/evomaster/core/search/gene/collection/ArrayGene.kt index ccb72649d6..75928d81d7 100644 --- a/core/src/main/kotlin/org/evomaster/core/search/gene/collection/ArrayGene.kt +++ b/core/src/main/kotlin/org/evomaster/core/search/gene/collection/ArrayGene.kt @@ -376,7 +376,10 @@ class ArrayGene( */ 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()) + } } /** diff --git a/core/src/test/kotlin/org/evomaster/core/search/gene/ArrayGeneTest.kt b/core/src/test/kotlin/org/evomaster/core/search/gene/ArrayGeneTest.kt index 68bc3b7636..20f1586fff 100644 --- a/core/src/test/kotlin/org/evomaster/core/search/gene/ArrayGeneTest.kt +++ b/core/src/test/kotlin/org/evomaster/core/search/gene/ArrayGeneTest.kt @@ -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 @@ -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)) + + } + + }