Skip to content

Commit 1c735bd

Browse files
committed
paying some more technical debt
1 parent 2d4aa5c commit 1c735bd

16 files changed

Lines changed: 83 additions & 349 deletions

core/src/main/kotlin/org/evomaster/core/search/gene/regex/DisjunctionListRxGene.kt

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -148,50 +148,26 @@ class DisjunctionListRxGene(
148148
.containsSameValueAs(other.disjunctions[activeDisjunction])
149149
}
150150

151-
152-
153151
override fun mutationWeight(): Double = disjunctions.map { it.mutationWeight() }.sum() + 1
154152

155153
override fun unsafeCopyValueFrom(other: Gene): Boolean {
156-
if (other !is DisjunctionListRxGene) {
157-
throw IllegalArgumentException("Invalid gene type ${other.javaClass}")
154+
if (other !is DisjunctionListRxGene
155+
|| other.disjunctions.size != disjunctions.size) {
156+
return false
158157
}
159158

160-
//TODO: Man, shall we check the size of [disjunctions]
161-
162-
return updateValueOnlyIfValid({
163-
var ok = true
164-
for (i in 0 until disjunctions.size) {
165-
ok = ok && this.disjunctions[i].unsafeCopyValueFrom(other.disjunctions[i])
166-
}
167-
if (ok){
168-
this.activeDisjunction = other.activeDisjunction
169-
}
170-
ok
171-
}, true)
172-
173-
}
174-
175-
override fun unsafeSetFromStringValue(gene: Gene): Boolean {
176-
if (gene is DisjunctionListRxGene && gene.disjunctions.size == disjunctions.size){
177-
var result = true
178-
disjunctions.indices.forEach { i->
179-
val r = disjunctions[i].unsafeSetFromStringValue(gene.disjunctions[i])
180-
if (!r)
181-
LoggingUtil.uniqueWarn(log, "cannot bind disjunctions (name: ${disjunctions[i].name}) at index $i")
182-
result = result && r
183-
}
184-
185-
activeDisjunction = gene.activeDisjunction
186-
return result
159+
var ok = true
160+
for (i in 0 until disjunctions.size) {
161+
ok = ok && this.disjunctions[i].unsafeCopyValueFrom(other.disjunctions[i])
187162
}
188-
189-
LoggingUtil.uniqueWarn(log, "cannot bind DisjunctionListRxGene with ${gene::class.java.simpleName}")
190-
return false
163+
if (ok){
164+
this.activeDisjunction = other.activeDisjunction
165+
}
166+
return ok
191167
}
192168

193169
override fun isChildUsed(child: Gene) : Boolean {
194170
verifyChild(child)
195171
return child == disjunctions[activeDisjunction]
196172
}
197-
}
173+
}

core/src/main/kotlin/org/evomaster/core/search/gene/regex/DisjunctionRxGene.kt

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -166,46 +166,20 @@ class DisjunctionRxGene(
166166
}
167167

168168
override fun unsafeCopyValueFrom(other: Gene): Boolean {
169-
if (other !is DisjunctionRxGene) {
170-
throw IllegalArgumentException("Invalid gene type ${other.javaClass}")
169+
if (other !is DisjunctionRxGene
170+
|| other.terms.size != this.terms.size) {
171+
return false
171172
}
172-
val current = this.copy()
173-
return updateValueOnlyIfValid(
174-
{
175-
var ok = true
176-
for (i in 0 until terms.size) {
177-
ok = ok && this.terms[i].unsafeCopyValueFrom(other.terms[i])
178-
}
179-
if (ok){
180-
this.extraPrefix = other.extraPrefix
181-
this.extraPostfix = other.extraPostfix
182-
}
183-
ok
184173

185-
}, true
186-
)
187-
}
188-
189-
override fun unsafeSetFromStringValue(gene: Gene): Boolean {
190-
if (gene is DisjunctionRxGene && terms.size == gene.terms.size){
191-
var result = true
192-
terms.indices.forEach { i->
193-
val r = terms[i].unsafeSetFromStringValue(gene.terms[i])
194-
if (!r)
195-
LoggingUtil.uniqueWarn(log, "cannot bind the term (name: ${terms[i].name}) at index $i")
196-
result = result && r
197-
}
198-
199-
extraPostfix = gene.extraPrefix
200-
extraPrefix = gene.extraPrefix
201-
202-
if (!result){
203-
LoggingUtil.uniqueWarn(log, "not fully completely bind DisjunctionRxGene")
204-
}
205-
return result
174+
var ok = true
175+
for (i in 0 until terms.size) {
176+
ok = ok && this.terms[i].unsafeCopyValueFrom(other.terms[i])
206177
}
207-
208-
LoggingUtil.uniqueWarn(log, "cannot bind DisjunctionRxGene with ${gene::class.java.simpleName}")
209-
return false
178+
if (ok){
179+
this.extraPrefix = other.extraPrefix
180+
this.extraPostfix = other.extraPostfix
181+
}
182+
return ok
210183
}
211-
}
184+
185+
}

core/src/main/kotlin/org/evomaster/core/search/gene/regex/PatternCharacterBlockGene.kt

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,8 @@ class PatternCharacterBlockGene(
5656
}
5757

5858
override fun unsafeCopyValueFrom(other: Gene): Boolean {
59-
if (other !is PatternCharacterBlockGene) {
60-
throw IllegalArgumentException("Invalid gene type ${other.javaClass}")
61-
}
62-
63-
if(other.stringBlock != this.stringBlock) {
64-
//this should not happen
65-
throw IllegalStateException("Not supposed to copy value for " + this.javaClass.simpleName)
66-
}
67-
68-
return true
59+
//do nothing
60+
return containsSameValueAs(other)
6961
}
7062

71-
override fun unsafeSetFromStringValue(gene: Gene): Boolean {
72-
// do nothing
73-
return true
74-
}
75-
}
63+
}

core/src/main/kotlin/org/evomaster/core/search/gene/regex/QuantifierRxGene.kt

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -217,56 +217,25 @@ class QuantifierRxGene(
217217

218218
override fun unsafeCopyValueFrom(other: Gene): Boolean {
219219
if (other !is QuantifierRxGene) {
220-
throw IllegalArgumentException("Invalid gene type ${other.javaClass}")
220+
return false
221221
}
222222

223-
return updateValueOnlyIfValid(
224-
{
225-
if (this.atoms.size == other.atoms.size) {
226-
//same size, so just copy over the values
227-
var ok = true
228-
for (i in 0 until other.atoms.size) {
229-
ok = ok && this.atoms[i].unsafeCopyValueFrom(other.atoms[i])
230-
}
231-
ok
232-
} else {
233-
//different size, so clear and create new copies
234-
this.killAllChildren()
235-
other.atoms.forEach{
236-
val a = it.copy()
237-
a.resetLocalIdRecursively()
238-
this.addChild(a)
239-
}
240-
true
241-
}
242-
}, true
243-
)
244-
}
245-
246-
/*
247-
Note that value binding cannot be performed on the [atoms]
248-
*/
249-
override fun unsafeSetFromStringValue(gene: Gene): Boolean {
250-
if (gene is QuantifierRxGene){
251-
var result = true
252-
if(atoms.size == gene.atoms.size){
253-
atoms.indices.forEach {
254-
val r = atoms[it].unsafeSetFromStringValue(gene.atoms[it])
255-
if (!r)
256-
LoggingUtil.uniqueWarn(log, "value binding for QuantifierRxGene does not perform successfully at index $it")
257-
result = r && result
258-
}
259-
}else{
260-
this.killAllChildren()
261-
gene.atoms.forEach{
262-
val a = it.copy()
263-
a.resetLocalIdRecursively()
264-
this.addChild(a)
265-
}
223+
return if (this.atoms.size == other.atoms.size) {
224+
//same size, so just copy over the values
225+
var ok = true
226+
for (i in 0 until other.atoms.size) {
227+
ok = ok && this.atoms[i].unsafeCopyValueFrom(other.atoms[i])
266228
}
267-
return result
229+
ok
230+
} else {
231+
//different size, so clear and create new copies
232+
this.killAllChildren()
233+
other.atoms.forEach{
234+
val a = it.copy()
235+
a.resetLocalIdRecursively()
236+
this.addChild(a)
237+
}
238+
true
268239
}
269-
LoggingUtil.uniqueWarn(log, "cannot bind the QuantifierRxGene with ${gene::class.java.simpleName}")
270-
return false
271240
}
272-
}
241+
}

core/src/main/kotlin/org/evomaster/core/search/gene/regex/RegexGene.kt

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,8 @@ class RegexGene(
103103

104104
override fun unsafeCopyValueFrom(other: Gene): Boolean {
105105
if(other !is RegexGene){
106-
throw IllegalArgumentException("Invalid gene type ${other.javaClass}")
106+
return false
107107
}
108-
return updateValueOnlyIfValid(
109-
{this.disjunctions.unsafeCopyValueFrom(other.disjunctions)}, false
110-
)
111-
}
112-
113-
override fun unsafeSetFromStringValue(gene: Gene): Boolean {
114-
if (gene is RegexGene){
115-
return disjunctions.unsafeSetFromStringValue(gene.disjunctions)
116-
}
117-
return false
108+
return this.disjunctions.unsafeCopyValueFrom(other.disjunctions)
118109
}
119-
}
110+
}

core/src/main/kotlin/org/evomaster/core/search/gene/sql/geometric/SqlBoxGene.kt

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@ class SqlBoxGene(
3131

3232
override fun unsafeCopyValueFrom(other: Gene): Boolean {
3333
if (other !is SqlBoxGene) {
34-
throw IllegalArgumentException("Invalid gene type ${other.javaClass}")
34+
return false
3535
}
3636

37-
return updateValueOnlyIfValid(
38-
{this.p.unsafeCopyValueFrom(other.p) && this.q.unsafeCopyValueFrom(other.q)}, true
39-
)
37+
return this.p.unsafeCopyValueFrom(other.p) && this.q.unsafeCopyValueFrom(other.q)
4038
}
4139

4240
override fun containsSameValueAs(other: Gene): Boolean {
@@ -47,18 +45,6 @@ class SqlBoxGene(
4745
&& this.q.containsSameValueAs(other.q)
4846
}
4947

50-
override fun unsafeSetFromStringValue(gene: Gene): Boolean {
51-
return when {
52-
gene is SqlBoxGene -> {
53-
p.unsafeSetFromStringValue(gene.p) &&
54-
q.unsafeSetFromStringValue(gene.q)
55-
}
56-
else -> {
57-
LoggingUtil.uniqueWarn(log, "cannot bind PointGene with ${gene::class.java.simpleName}")
58-
false
59-
}
60-
}
61-
}
6248

6349
override fun customShouldApplyShallowMutation(
6450
randomness: Randomness,
@@ -69,4 +55,4 @@ class SqlBoxGene(
6955
return false
7056
}
7157

72-
}
58+
}

core/src/main/kotlin/org/evomaster/core/search/gene/sql/geometric/SqlCircleGene.kt

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,10 @@ class SqlCircleGene(
5555

5656
override fun unsafeCopyValueFrom(other: Gene): Boolean {
5757
if (other !is SqlCircleGene) {
58-
throw IllegalArgumentException("Invalid gene type ${other.javaClass}")
58+
return false
5959
}
6060

61-
return updateValueOnlyIfValid(
62-
{this.c.unsafeCopyValueFrom(other.c) && this.r.unsafeCopyValueFrom(other.r)}, true
63-
)
61+
return this.c.unsafeCopyValueFrom(other.c) && this.r.unsafeCopyValueFrom(other.r)
6462
}
6563

6664
override fun containsSameValueAs(other: Gene): Boolean {
@@ -72,19 +70,6 @@ class SqlCircleGene(
7270
}
7371

7472

75-
override fun unsafeSetFromStringValue(gene: Gene): Boolean {
76-
return when {
77-
gene is SqlCircleGene -> {
78-
c.unsafeSetFromStringValue(gene.c) &&
79-
r.unsafeSetFromStringValue(gene.r)
80-
}
81-
else -> {
82-
LoggingUtil.uniqueWarn(log, "cannot bind CircleGene with ${gene::class.java.simpleName}")
83-
false
84-
}
85-
}
86-
}
87-
8873
override fun customShouldApplyShallowMutation(
8974
randomness: Randomness,
9075
selectionStrategy: SubsetGeneMutationSelectionStrategy,
@@ -94,4 +79,4 @@ class SqlCircleGene(
9479
return false
9580
}
9681

97-
}
82+
}

core/src/main/kotlin/org/evomaster/core/search/gene/sql/geometric/SqlGeometryCollectionGene.kt

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,9 @@ class SqlGeometryCollectionGene(
8383

8484
override fun unsafeCopyValueFrom(other: Gene): Boolean {
8585
if (other !is SqlGeometryCollectionGene) {
86-
throw IllegalArgumentException("Invalid gene type ${other.javaClass}")
86+
return false
8787
}
88-
return updateValueOnlyIfValid(
89-
{this.elements.unsafeCopyValueFrom(other.elements)}, false
90-
)
88+
return this.elements.unsafeCopyValueFrom(other.elements)
9189
}
9290

9391
override fun containsSameValueAs(other: Gene): Boolean {
@@ -97,19 +95,6 @@ class SqlGeometryCollectionGene(
9795
return this.elements.containsSameValueAs(other.elements)
9896
}
9997

100-
101-
override fun unsafeSetFromStringValue(gene: Gene): Boolean {
102-
return when (gene) {
103-
is SqlGeometryCollectionGene -> {
104-
elements.unsafeSetFromStringValue(gene.elements)
105-
}
106-
else -> {
107-
LoggingUtil.uniqueWarn(log, "cannot bind PathGene with ${gene::class.java.simpleName}")
108-
false
109-
}
110-
}
111-
}
112-
11398
override fun customShouldApplyShallowMutation(
11499
randomness: Randomness,
115100
selectionStrategy: SubsetGeneMutationSelectionStrategy,
@@ -119,4 +104,4 @@ class SqlGeometryCollectionGene(
119104
return false
120105
}
121106

122-
}
107+
}

0 commit comments

Comments
 (0)