From 72af4312866a2c534a9fdc9036cf9e0ec27cc6e7 Mon Sep 17 00:00:00 2001 From: aschenzle Date: Tue, 1 Dec 2026 11:21:08 -0700 Subject: [PATCH] Make DynamoDB null scalar seeds mutable --- .../core/database/dynamodb/DynamoDbAction.kt | 8 ++-- .../dynamodb/DynamoDbInsertBuilder.kt | 23 +++++----- .../evomaster/core/output/DynamoDbWriter.kt | 44 +++---------------- .../sql/NullableImpact.kt | 4 +- .../dynamodb/DynamoDbActionTransformerTest.kt | 39 ++++++++++++++++ .../dynamodb/DynamoDbInsertBuilderTest.kt | 35 ++++++++------- .../core/output/DynamoDbWriterTest.kt | 11 ++++- .../sql/SqlNullImpactTest.kt | 11 ++++- 8 files changed, 103 insertions(+), 72 deletions(-) diff --git a/core/src/main/kotlin/org/evomaster/core/database/dynamodb/DynamoDbAction.kt b/core/src/main/kotlin/org/evomaster/core/database/dynamodb/DynamoDbAction.kt index f1379a8d49..83ea04dde8 100644 --- a/core/src/main/kotlin/org/evomaster/core/database/dynamodb/DynamoDbAction.kt +++ b/core/src/main/kotlin/org/evomaster/core/database/dynamodb/DynamoDbAction.kt @@ -17,6 +17,7 @@ import org.evomaster.core.search.gene.numeric.BigDecimalGene import org.evomaster.core.search.gene.placeholder.ImmutableDataHolderGene import org.evomaster.core.search.gene.string.StringGene import org.evomaster.core.search.gene.wrapper.ChoiceGene +import org.evomaster.core.search.gene.wrapper.NullableGene import java.math.BigDecimal import java.util.TreeSet @@ -24,7 +25,7 @@ import java.util.TreeSet * A typed attribute gene belonging to a DynamoDB item. * * @property attributeName name of the DynamoDB item attribute - * @property type native DynamoDB attribute type + * @property type native DynamoDB type of the seed attribute. A null seed can evolve into a scalar. * @property gene evolvable value for the attribute */ data class DynamoDbAttributeGene( @@ -39,7 +40,7 @@ data class DynamoDbAttributeGene( DynamoDbValueType.STRING -> geneToPlainString(gene) DynamoDbValueType.NUMBER -> geneToPlainNumber(gene) DynamoDbValueType.BOOLEAN -> geneToPlainBoolean(gene) - DynamoDbValueType.NULL -> null + DynamoDbValueType.NULL -> (gene as? NullableGene)?.let(::geneToPlainValue) DynamoDbValueType.MAP, DynamoDbValueType.LIST -> geneToPlainValue(gene) DynamoDbValueType.STRING_SET -> geneToPlainSet(gene, ::geneToPlainString) DynamoDbValueType.NUMBER_SET -> geneToPlainSet(gene, ::geneToPlainNumber) @@ -68,7 +69,7 @@ data class DynamoDbAttributeGene( (gene as? BooleanGene)?.value?.toString() ?: gene.getValueAsRawString() ) - DynamoDbValueType.NULL -> DynamoDbDtoUtils.fromPlainValue(attributeName, null) + DynamoDbValueType.NULL, DynamoDbValueType.MAP, DynamoDbValueType.LIST, DynamoDbValueType.STRING_SET, @@ -120,6 +121,7 @@ data class DynamoDbAttributeGene( gene.getViewOfElements().map { geneToPlainValue(it) } } is HeterogeneousListGene -> gene.elements.map { geneToPlainValue(it) } + is NullableGene -> if (gene.isActive) geneToPlainValue(gene.gene) else null is ChoiceGene<*> -> geneToPlainValue(gene.activeGene()) is ImmutableDataHolderGene -> when (gene.value) { "null" -> null diff --git a/core/src/main/kotlin/org/evomaster/core/database/dynamodb/DynamoDbInsertBuilder.kt b/core/src/main/kotlin/org/evomaster/core/database/dynamodb/DynamoDbInsertBuilder.kt index ebc0c50af0..5ad21df75e 100644 --- a/core/src/main/kotlin/org/evomaster/core/database/dynamodb/DynamoDbInsertBuilder.kt +++ b/core/src/main/kotlin/org/evomaster/core/database/dynamodb/DynamoDbInsertBuilder.kt @@ -22,9 +22,9 @@ import org.evomaster.core.search.gene.datetime.TimeOffsetGene import org.evomaster.core.search.gene.numeric.BigDecimalGene import org.evomaster.core.search.gene.numeric.IntegerGene import org.evomaster.core.search.gene.numeric.LongGene -import org.evomaster.core.search.gene.placeholder.ImmutableDataHolderGene import org.evomaster.core.search.gene.string.StringGene import org.evomaster.core.search.gene.wrapper.ChoiceGene +import org.evomaster.core.search.gene.wrapper.NullableGene import org.evomaster.core.search.gene.wrapper.OptionalGene import org.evomaster.core.search.service.Randomness import java.math.BigDecimal @@ -191,7 +191,8 @@ object DynamoDbInsertBuilder { * Builds an EvoMaster gene tree from a composite, set, or null DynamoDB attribute DTO. * Maps use fixed-key [ObjectGene]s, lists (including empty `[]`) use mutable-size [HeterogeneousListGene]s * protecting inferred seed elements via `minSize`, string/number sets use [ProtectedUniqueArrayGene]s - * preventing empty sets and duplicates, and nulls use [ImmutableDataHolderGene]. + * preventing empty sets and duplicates. Null seeds start with an inactive [NullableGene] + * that can evolve into a string, number, or boolean. */ fun buildDocumentGene(name: String, dto: DynamoDbAttributeValueDto): Gene { fun build(currentName: String, currentDto: DynamoDbAttributeValueDto): Gene { @@ -207,19 +208,11 @@ object DynamoDbInsertBuilder { val elements = currentDto.listValue?.mapIndexed { index, childDto -> build("${currentName}_$index", childDto) } ?: emptyList() - val listTemplate = ChoiceGene( - "${currentName}_template", - listOf( - StringGene("${currentName}_s"), - BigDecimalGene("${currentName}_n"), - BooleanGene("${currentName}_b") - ) - ) HeterogeneousListGene( name = currentName, elements = elements, isFixed = false, - template = listTemplate, + template = buildScalarChoice(currentName, "${currentName}_template"), minSize = elements.size, maxSize = elements.size + ArrayGene.MAX_SIZE ) @@ -265,7 +258,7 @@ object DynamoDbInsertBuilder { ) } DynamoDbValueTypeDto.NULL, null -> { - ImmutableDataHolderGene(currentName, "null", inQuotes = false) + NullableGene(currentName, buildScalarChoice(currentName), isActive = false) } DynamoDbValueTypeDto.STRING -> { StringGene(currentName, currentDto.value ?: "") @@ -283,6 +276,12 @@ object DynamoDbInsertBuilder { return build(name, dto) } + /** Builds the scalar alternatives used for list growth and null mutations. */ + private fun buildScalarChoice(name: String, choiceName: String = name): ChoiceGene = ChoiceGene( + choiceName, + listOf(StringGene("${name}_s"), BigDecimalGene("${name}_n"), BooleanGene("${name}_b")) + ) + /** * Builds a formatted gene or fallback [StringGene] for a DynamoDB string attribute. */ diff --git a/core/src/main/kotlin/org/evomaster/core/output/DynamoDbWriter.kt b/core/src/main/kotlin/org/evomaster/core/output/DynamoDbWriter.kt index 3779f0cae0..b0400490e7 100644 --- a/core/src/main/kotlin/org/evomaster/core/output/DynamoDbWriter.kt +++ b/core/src/main/kotlin/org/evomaster/core/output/DynamoDbWriter.kt @@ -4,10 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper import org.apache.commons.text.StringEscapeUtils import org.evomaster.client.java.controller.api.dto.database.operations.DynamoDbAttributeValueDto import org.evomaster.client.java.controller.api.dto.database.operations.DynamoDbValueTypeDto -import org.evomaster.core.database.dynamodb.DynamoDbValueType import org.evomaster.core.search.action.EvaluatedDynamoDbAction -import org.evomaster.core.search.gene.BooleanGene -import org.evomaster.core.search.gene.numeric.BigDecimalGene /** * Generates DynamoDB initialization code for emitted tests. @@ -46,42 +43,13 @@ object DynamoDbWriter { lines.add(".insertInto(\"${escape(action.tableName, format)}\")") action.attributes.forEach { attribute -> val name = "\"${escape(attribute.attributeName, format)}\"" - val value = when (attribute.type) { - DynamoDbValueType.MAP, - DynamoDbValueType.LIST, - DynamoDbValueType.STRING_SET, - DynamoDbValueType.NUMBER_SET, - DynamoDbValueType.NULL -> { - val ddbJson = ddbJsonMapper.writeValueAsString(toDynamoDbJsonNode(attribute.toDto())) - "\"${escape(ddbJson, format)}\"" - } - DynamoDbValueType.STRING -> { - val raw = attribute.gene.getValueAsRawString() - val literal = "'${raw.replace("'", "''")}'" - "\"${escape(literal, format)}\"" - } - DynamoDbValueType.NUMBER -> { - val raw = (attribute.gene as? BigDecimalGene)?.value?.toPlainString() - ?: attribute.gene.getValueAsRawString() - "\"${escape(raw, format)}\"" - } - DynamoDbValueType.BOOLEAN -> { - val raw = (attribute.gene as? BooleanGene)?.value?.toString() - ?: attribute.gene.getValueAsRawString() - "\"$raw\"" - } + val dto = attribute.toDto() + val (method, value) = when (dto.type) { + DynamoDbValueTypeDto.STRING -> "d" to "'${dto.value.replace("'", "''")}'" + DynamoDbValueTypeDto.NUMBER, DynamoDbValueTypeDto.BOOLEAN -> "d" to dto.value + else -> "ddbJson" to ddbJsonMapper.writeValueAsString(toDynamoDbJsonNode(dto)) } - val method = when (attribute.type) { - DynamoDbValueType.MAP, - DynamoDbValueType.LIST, - DynamoDbValueType.STRING_SET, - DynamoDbValueType.NUMBER_SET, - DynamoDbValueType.NULL -> "ddbJson" - DynamoDbValueType.STRING, - DynamoDbValueType.NUMBER, - DynamoDbValueType.BOOLEAN -> "d" - } - lines.add(".$method($name, $value)") + lines.add(".$method($name, \"${escape(value, format)}\")") } } lines.add(".dtos()") diff --git a/core/src/main/kotlin/org/evomaster/core/search/impact/impactinfocollection/sql/NullableImpact.kt b/core/src/main/kotlin/org/evomaster/core/search/impact/impactinfocollection/sql/NullableImpact.kt index 8f9b26dcb9..426c21afd8 100644 --- a/core/src/main/kotlin/org/evomaster/core/search/impact/impactinfocollection/sql/NullableImpact.kt +++ b/core/src/main/kotlin/org/evomaster/core/search/impact/impactinfocollection/sql/NullableImpact.kt @@ -78,6 +78,6 @@ class NullableImpact(sharedImpactInfo: SharedImpactInfo, specificImpactInfo: Spe override fun syncImpact(previous: Gene?, current: Gene) { check(previous,current) - geneImpact.syncImpact((previous as NullableGene).gene, (current as NullableGene).gene) + geneImpact.syncImpact((previous as? NullableGene)?.gene, (current as NullableGene).gene) } -} \ No newline at end of file +} diff --git a/core/src/test/kotlin/org/evomaster/core/database/dynamodb/DynamoDbActionTransformerTest.kt b/core/src/test/kotlin/org/evomaster/core/database/dynamodb/DynamoDbActionTransformerTest.kt index dfc3eb757b..b3cd237d83 100644 --- a/core/src/test/kotlin/org/evomaster/core/database/dynamodb/DynamoDbActionTransformerTest.kt +++ b/core/src/test/kotlin/org/evomaster/core/database/dynamodb/DynamoDbActionTransformerTest.kt @@ -3,9 +3,13 @@ package org.evomaster.core.database.dynamodb import org.evomaster.client.java.controller.api.dto.database.operations.DynamoDbDtoUtils import org.evomaster.client.java.controller.api.dto.database.operations.DynamoDbValueTypeDto import org.evomaster.core.search.gene.BooleanGene +import org.evomaster.core.search.gene.collection.HeterogeneousListGene import org.evomaster.core.search.gene.numeric.BigDecimalGene import org.evomaster.core.search.gene.string.StringGene +import org.evomaster.core.search.gene.wrapper.ChoiceGene +import org.evomaster.core.search.gene.wrapper.NullableGene import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotEquals import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test import java.math.BigDecimal @@ -66,6 +70,26 @@ class DynamoDbActionTransformerTest { assertEquals(listOf("mvp", "world-cup"), attributes[2].mapValue.getValue("tags").setValue) assertEquals(DynamoDbValueTypeDto.NULL, attributes[2].mapValue.getValue("coach").type) assertEquals(DynamoDbValueTypeDto.NULL, attributes[3].type) + + val seedKey = action.seedKey + val nullGene = action.attributes[3].gene as NullableGene + val choice = nullGene.gene as ChoiceGene<*> + nullGene.isActive = true + for ((index, value) in listOf("null", BigDecimal("10.50"), true).withIndex()) { + choice.selectActiveGene(index) + when (val selected = choice.activeGene()) { + is StringGene -> selected.value = value as String + is BigDecimalGene -> selected.value = value as BigDecimal + is BooleanGene -> selected.value = value as Boolean + } + val actual = DynamoDbActionTransformer.transform(listOf(action)).insertions.single().attributes[3] + assertEquals(DynamoDbDtoUtils.fromPlainValue("retiredAt", value), actual) + assertEquals(value, action.attributes[3].toPlainValue()) + assertNotEquals(seedKey, action.insertionKey()) + assertEquals(seedKey, (action.copy() as DynamoDbAction).seedKey) + } + nullGene.isActive = false + assertEquals(seedKey, action.insertionKey()) } @Test @@ -112,4 +136,19 @@ class DynamoDbActionTransformerTest { val transported = DynamoDbActionTransformer.transform(listOf(action)).insertions.single().attributes.single() assertEquals(profileDto, transported) } + + @Test + fun transformsAnActivatedNullListElement() { + val dto = DynamoDbDtoUtils.fromPlainValue("matchTimeline", listOf("Final", null)) + val list = DynamoDbInsertBuilder.buildDocumentGene("matchTimeline", dto) as HeterogeneousListGene + val gene = list.elements[1] as NullableGene + val choice = gene.gene as ChoiceGene<*> + choice.selectActiveGene(2) + (choice.activeGene() as BooleanGene).value = true + gene.isActive = true + + val attribute = DynamoDbAttributeGene("matchTimeline", DynamoDbValueType.LIST, list) + assertEquals(listOf("Final", true), attribute.toPlainValue()) + assertEquals(DynamoDbDtoUtils.fromPlainValue("matchTimeline", listOf("Final", true)), attribute.toDto()) + } } diff --git a/core/src/test/kotlin/org/evomaster/core/database/dynamodb/DynamoDbInsertBuilderTest.kt b/core/src/test/kotlin/org/evomaster/core/database/dynamodb/DynamoDbInsertBuilderTest.kt index 963aaa47e5..c71b0c8076 100644 --- a/core/src/test/kotlin/org/evomaster/core/database/dynamodb/DynamoDbInsertBuilderTest.kt +++ b/core/src/test/kotlin/org/evomaster/core/database/dynamodb/DynamoDbInsertBuilderTest.kt @@ -16,11 +16,12 @@ import org.evomaster.core.search.gene.datetime.DateTimeGene import org.evomaster.core.search.gene.datetime.FormatForDatesAndTimes import org.evomaster.core.search.gene.datetime.TimeGene import org.evomaster.core.search.gene.numeric.BigDecimalGene -import org.evomaster.core.search.gene.placeholder.ImmutableDataHolderGene import org.evomaster.core.search.gene.string.StringGene +import org.evomaster.core.search.gene.wrapper.ChoiceGene +import org.evomaster.core.search.gene.wrapper.NullableGene import org.evomaster.core.search.impact.impactinfocollection.MutatedGeneWithContext -import org.evomaster.core.search.impact.impactinfocollection.GeneImpact import org.evomaster.core.search.impact.impactinfocollection.ImpactUtils +import org.evomaster.core.search.impact.impactinfocollection.sql.NullableImpact import org.evomaster.core.search.impact.impactinfocollection.value.ObjectGeneImpact import org.evomaster.core.search.impact.impactinfocollection.value.StringGeneImpact import org.evomaster.core.search.impact.impactinfocollection.value.collection.ArrayGeneImpact @@ -186,7 +187,7 @@ class DynamoDbInsertBuilderTest { } @Test - fun testNestedLeavesExtractedIntoImmutableGeneTree() { + fun testNestedLeavesExtractedIntoDocumentGeneTree() { val payload = mapOf( "profile" to mapOf( "role" to "admin", @@ -213,12 +214,12 @@ class DynamoDbInsertBuilderTest { assertEquals("admin", stringMap["role"]!!.value) val numberGenes = leaves.filterIsInstance() - assertEquals(3, numberGenes.size) + assertEquals(4, numberGenes.size) assertTrue(numberGenes.any { it.value == BigDecimal("99.5") }) val boolGenes = leaves.filterIsInstance() - assertEquals(1, boolGenes.size) - assertTrue(boolGenes.first().value) + assertEquals(2, boolGenes.size) + assertTrue(boolGenes.single { it.name == "active" }.value) val tagsGene = rootGene.fixedFields.first { it.name == "tags" } as HeterogeneousListGene assertFalse(tagsGene.isFixed) @@ -240,9 +241,14 @@ class DynamoDbInsertBuilderTest { assertTrue(emptyListGene.elements.isEmpty()) assertTrue(emptyListGene.isMutable()) - val nullGene = rootGene.fixedFields.first { it.name == "nothing" } as ImmutableDataHolderGene - assertEquals("null", nullGene.value) - assertFalse(nullGene.inQuotes) + val nullGene = rootGene.fixedFields.first { it.name == "nothing" } as NullableGene + assertFalse(nullGene.isActive) + assertTrue(nullGene.isMutable()) + val choice = nullGene.gene as ChoiceGene<*> + assertEquals( + listOf(StringGene::class, BigDecimalGene::class, BooleanGene::class), + choice.getViewOfChildren().map { it::class } + ) assertEquals(dto, action.attributes.single().toDto()) } @@ -276,7 +282,7 @@ class DynamoDbInsertBuilderTest { assertTrue(ImpactUtils.createGeneImpact(tagsGene.elements[2], "tags_2") is HeterogeneousListGeneImpact) assertTrue(ImpactUtils.createGeneImpact(tagsGene.elements[3], "tags_3") is ArrayGeneImpact) assertTrue(ImpactUtils.createGeneImpact(tagsGene.elements[4], "tags_4") is ArrayGeneImpact) - assertTrue(ImpactUtils.createGeneImpact(tagsGene.elements[5], "tags_5") is GeneImpact) + assertTrue(ImpactUtils.createGeneImpact(tagsGene.elements[5], "tags_5") is NullableImpact) } @Test @@ -357,14 +363,14 @@ class DynamoDbInsertBuilderTest { val action = DynamoDbInsertBuilder.buildInsertActions(listOf(DynamoDbFailedQuery("Items", listOf(dto))), Randomness()).single() val objGene = action.attributes.single().gene as ObjectGene - assertEquals(53, objGene.flatView().filterIsInstance().size) + assertEquals(54, objGene.flatView().filterIsInstance().size) val z50 = objGene.fixedFields.first { it.name == "z50_str_null" } as StringGene val z51 = objGene.fixedFields.first { it.name == "z51_num" } as BigDecimalGene val z52 = objGene.fixedFields.first { it.name == "z52_bool" } as BooleanGene val z53 = objGene.fixedFields.first { it.name == "z53_ss" } as ProtectedUniqueArrayGene<*> val z54 = objGene.fixedFields.first { it.name == "z54_ns" } as ProtectedUniqueArrayGene<*> val z55 = objGene.fixedFields.first { it.name == "z55_empty_list" } as HeterogeneousListGene - val z56 = objGene.fixedFields.first { it.name == "z56_null" } as ImmutableDataHolderGene + val z56 = objGene.fixedFields.first { it.name == "z56_null" } as NullableGene assertTrue(z50.isMutable()) assertEquals("null", z50.value) @@ -383,9 +389,8 @@ class DynamoDbInsertBuilderTest { assertTrue(z55.isMutable()) assertTrue(z55.elements.isEmpty()) - assertFalse(z56.isMutable()) - assertEquals("null", z56.value) - assertFalse(z56.inQuotes) + assertTrue(z56.isMutable()) + assertFalse(z56.isActive) val roundTripped = action.attributes.single().toDto() assertEquals(dto, roundTripped) diff --git a/core/src/test/kotlin/org/evomaster/core/output/DynamoDbWriterTest.kt b/core/src/test/kotlin/org/evomaster/core/output/DynamoDbWriterTest.kt index c27dc58590..89101489f7 100644 --- a/core/src/test/kotlin/org/evomaster/core/output/DynamoDbWriterTest.kt +++ b/core/src/test/kotlin/org/evomaster/core/output/DynamoDbWriterTest.kt @@ -12,6 +12,8 @@ import org.evomaster.core.search.action.EvaluatedDynamoDbAction import org.evomaster.core.search.gene.BooleanGene import org.evomaster.core.search.gene.numeric.BigDecimalGene import org.evomaster.core.search.gene.string.StringGene +import org.evomaster.core.search.gene.wrapper.ChoiceGene +import org.evomaster.core.search.gene.wrapper.NullableGene import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test @@ -165,6 +167,11 @@ class DynamoDbWriterTest { val positions = DynamoDbDtoUtils.fromPlainValue("positions", setOf("forward", "captain")) val jerseyNumbers = DynamoDbDtoUtils.fromPlainValue("jerseyNumbers", setOf(BigDecimal("10"), BigDecimal("30.5"))) val coach = DynamoDbDtoUtils.fromPlainValue("coach", null) + val captainFromNull = DynamoDbInsertBuilder.buildDocumentGene("captainFromNull", coach) as NullableGene + val captainChoice = captainFromNull.gene as ChoiceGene<*> + captainChoice.selectActiveGene(2) + (captainChoice.activeGene() as BooleanGene).value = true + captainFromNull.isActive = true val action = DynamoDbAction( "WorldCupPlayers", listOf( @@ -176,7 +183,8 @@ class DynamoDbWriterTest { DynamoDbAttributeGene("squad", DynamoDbValueType.fromDto(document.type), DynamoDbInsertBuilder.buildDocumentGene("squad", document)), DynamoDbAttributeGene("positions", DynamoDbValueType.fromDto(positions.type), DynamoDbInsertBuilder.buildDocumentGene("positions", positions)), DynamoDbAttributeGene("jerseyNumbers", DynamoDbValueType.fromDto(jerseyNumbers.type), DynamoDbInsertBuilder.buildDocumentGene("jerseyNumbers", jerseyNumbers)), - DynamoDbAttributeGene("coach", DynamoDbValueType.fromDto(coach.type), DynamoDbInsertBuilder.buildDocumentGene("coach", coach)) + DynamoDbAttributeGene("coach", DynamoDbValueType.fromDto(coach.type), DynamoDbInsertBuilder.buildDocumentGene("coach", coach)), + DynamoDbAttributeGene("captainFromNull", DynamoDbValueType.NULL, captainFromNull) ) ) action.setLocalId("world-cup-round-trip") @@ -219,5 +227,6 @@ class DynamoDbWriterTest { assertEquals(positions, attributes.getValue("positions")) assertEquals(jerseyNumbers, attributes.getValue("jerseyNumbers")) assertEquals(coach, attributes.getValue("coach")) + assertEquals(DynamoDbDtoUtils.fromPlainValue("captainFromNull", true), attributes.getValue("captainFromNull")) } } diff --git a/core/src/test/kotlin/org/evomaster/core/search/impact/impactinfocollection/sql/SqlNullImpactTest.kt b/core/src/test/kotlin/org/evomaster/core/search/impact/impactinfocollection/sql/SqlNullImpactTest.kt index 70f94a7aec..be2b5c73e7 100644 --- a/core/src/test/kotlin/org/evomaster/core/search/impact/impactinfocollection/sql/SqlNullImpactTest.kt +++ b/core/src/test/kotlin/org/evomaster/core/search/impact/impactinfocollection/sql/SqlNullImpactTest.kt @@ -8,6 +8,7 @@ import org.evomaster.core.search.impact.impactinfocollection.GeneImpactTest import org.evomaster.core.search.impact.impactinfocollection.ImpactOptions import org.evomaster.core.search.impact.impactinfocollection.MutatedGeneWithContext import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertDoesNotThrow /** * created by manzh on 2019-10-09 @@ -35,6 +36,14 @@ class SqlNullImpactTest : GeneImpactTest() { return MutatedGeneWithContext(current = geneToMutate, previous = original,) } + @Test + fun syncsWithoutPreviousGene() { + val gene = NullableGene("nullable", IntegerGene("value")) + val impact = NullableImpact("nullable", gene) + + assertDoesNotThrow { impact.syncImpact(previous = null, current = gene) } + } + @Test fun testActiveAndGene(){ @@ -60,4 +69,4 @@ class SqlNullImpactTest : GeneImpactTest() { assertImpact((pair.second as NullableImpact).geneImpact, (pairG.second as NullableImpact).geneImpact, ImpactOptions.IMPACT_IMPROVEMENT) } -} \ No newline at end of file +}