File tree Expand file tree Collapse file tree
main/kotlin/org/evomaster/core/search/gene
test/kotlin/org/evomaster/core/search/structuralelement/gene Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1180,18 +1180,21 @@ abstract class Gene(
11801180 * @param updateValue lambda performs update of value of the gene
11811181 * @param undoIfUpdateFails represents whether it needs to undo the value update if [updateValue] returns false
11821182 *
1183- * @return if the value is updated with [updateValue]
1183+ * @return if the value is updated with [updateValue]. note if for any reason the current gene was not valid,
1184+ * the validity of the update will not be checked.
11841185 */
11851186 fun updateValueOnlyIfValid (updateValue : () -> Boolean , undoIfUpdateFails : Boolean ): Boolean {
11861187
11871188 if (! undoIfUpdateFails) {
11881189 return updateValue()
11891190 }
11901191
1192+ val currentlyValid = isGloballyValid()
1193+
11911194 val current = copy()
11921195 val ok = updateValue()
11931196
1194- if (! ok || ! isGloballyValid()) {
1197+ if (! ok || (currentlyValid && ! isGloballyValid() )) {
11951198 val success = unsafeCopyValueFrom(current)
11961199 assert (success)
11971200 return false
Original file line number Diff line number Diff line change @@ -36,8 +36,17 @@ class SqlAutoIncrementGene(name: String) : SimpleGene(name) {
3636 * Man: need to check with Andrea, copyValueFrom of [ImmutableDataHolderGene] throw an exception
3737 */
3838 override fun unsafeCopyValueFrom (other : Gene ): Boolean {
39- // do nothing
40- return containsSameValueAs(other)
39+ if (other !is SqlAutoIncrementGene ) {
40+ return false
41+ }
42+ /*
43+ auto-increment are always unique... so a copy over should never work.
44+ however, here we return true instead of false to fulfill invariant that
45+ copyFrom a copy should always work...
46+
47+ TODO might check for side-effects, and see if need more complex handling
48+ */
49+ return true
4150 }
4251
4352 /* *
Original file line number Diff line number Diff line change @@ -38,10 +38,10 @@ abstract class GeneStructuralElementBaseTest : StructuralElementBaseTest() {
3838
3939 if (throwExceptionInCopyFromTest()){
4040 assertThrows<Exception > {
41- base.unsafeCopyValueFrom (template)
41+ base.copyValueFrom (template)
4242 }
4343 }else {
44- base.unsafeCopyValueFrom (template)
44+ base.copyValueFrom (template)
4545 assertCopyFrom(base)
4646 // keep structure after copyfrom
4747 assertChildren(base, - 1 )
Original file line number Diff line number Diff line change @@ -37,11 +37,11 @@ class CharacterClassEscapeRxGeneStructureTest : GeneStructuralElementBaseTest()
3737 }
3838
3939 @Test
40- fun testUnsafeCopyValueFromFailure (){
40+ fun testCopyValueFromFailure (){
4141 val base = getStructuralElement().copy()
4242 val copy = getCopyFromTemplate().copy()
4343
44- assertFalse(base.unsafeCopyValueFrom (copy))
44+ assertFalse(base.copyValueFrom (copy))
4545 }
4646
4747
You can’t perform that action at this time.
0 commit comments