Commit 78d2fc1d authored by ISWB Prasetya's avatar ISWB Prasetya
Browse files

making G2 generator to reuse more from pool as params for target-method

parent f5cbef34
......@@ -72,6 +72,7 @@ public class G2SuiteGen {
public Pool pool ;
private G2ValueMG gen2vmg ;
private Generator<PARAM,STEP> valueMG ;
private Generator<PARAM,STEP> valueMG_with_tendency_to_reuse_objs ;
public StaticInfo staticInfo = null ;
public CodeCoverage codeCoverage = null ;
......@@ -193,6 +194,7 @@ public class G2SuiteGen {
resetSeededConstants() ;
pool = gen2vmg.pool ;
valueMG = gen2vmg.valueMG() ;
valueMG_with_tendency_to_reuse_objs = gen2vmg.valueMG_leaningTowardsReuseOldObjects() ;
}
private String[] seededSPrimitives;
......@@ -202,9 +204,9 @@ public class G2SuiteGen {
* below, and the list of instanceOf constants is cleared.
*/
public void resetSeededConstants() {
String[] seeded = { "0", "1", "-1", "2", "9",
"10", "0.0001", "0.05", "-0.05" ,
"<abc@com>","<www.x.com>","<2000-12-12>","<24:00:00>"
String[] seeded = { "0", "1", "-1", "2", "7",
"10", "0.0001", "0.05", "-0.05" , "2018" , "<X>", "<joe>", "<127.0.0.1>",
"<abc@com>","www.w3.org>","<2000-12-12>","<24:00:00>"
} ;
seededSPrimitives = seeded ;
gen2vmg.configureSeededSPrimitives(seededSPrimitives);
......@@ -582,7 +584,8 @@ public class G2SuiteGen {
addInstanceOfConstants(staticInfo.getInstanceOfClasses(m)) ;
}
T3SeqG seqG = new T3SeqG(pool,scope,maxNumberOfStepRetry,valueMG) ;
//T3SeqG seqG = new T3SeqG(pool,scope,maxNumberOfStepRetry,valueMG) ;
T3SeqG seqG = new T3SeqG(pool,scope,maxNumberOfStepRetry,valueMG_with_tendency_to_reuse_objs) ;
Generator<SEQ_RT_info,SEQ_RT_info> suffixgen ;
if (regressionMode) {
if (scope.mutators.contains(m)) {
......
......@@ -455,6 +455,33 @@ public class G2ValueMG {
return g ;
}
/**
* This will construct the meta-generator to generate values; the generator will have
* higher probability to reuse objects from the pool.
*/
public Generator<PARAM,STEP> valueMG_leaningTowardsReuseOldObjects() {
FUN<Generator<PARAM,STEP>> recGenerator = new FUN<Generator<PARAM,STEP>>() ;
Generator<PARAM,STEP> g =
FirstOf(
refgens.random().WithChance(0.4),
nullgens.constant().WithChance(0.04),
sprimitiveMG(),
enumgens.random(),
refgens.objectUnderTest().WithChance(0.4),
refgens.objectUnderTestIfSubclass().WithChance(0.1),
collectiongens.collectionlike(recGenerator),
lambdagens.constlambdaMG(recGenerator),
constructorgens.useConstructor(recGenerator).transformReq(P -> remapPARAM_with_InstanceOfConstants(P)).WithChance(0.4),
constructorgens.useConstructor(recGenerator),
constructorgens.useCreationyMethod(recGenerator).transformReq(P -> remapPARAM_with_InstanceOfConstants(P)).WithChance(0.4),
constructorgens.useCreationyMethod(recGenerator),
// if all the above fails.. then generate null
nullgens.defaulting()
) ;
recGenerator.fun = g ;
return g ;
}
public static void main(String[] args) {
System.out.println(String.class.isPrimitive()) ;
......
......@@ -22,10 +22,23 @@ public class Item implements Serializable {
System.out.println(">>> incPrice " + x) ;
price += x ;
}
public String setCode(String code) {
System.out.println(">>> setCode " + code) ;
this.code = code; return this.code ;
public static class Code {
String code ;
public Code(String c) { code = c ; }
public String toString() { return "Code " + code ; }
}
public String setCode(Code c) {
System.out.println(">>> setCode " + c.code) ;
this.code = c.code; return this.code ;
}
public boolean checkzSameCode(Code c) {
System.out.println(">>> checkzSameCode " + c.code) ;
return code.equals(c.code) ;
}
public String getCode() {
System.out.println(">>> getCode ") ;
return code ;
......
......@@ -91,19 +91,14 @@ public class SegmentG extends AbstractSeqGenerator {
Generator<SEQ_RT_info,STEP> methodMGxx = info -> {
int N = methods_.size() ;
if (N==0) return null ;
if (N==1) {
Method M = methods_.get(0) ;
Method M = methods_.get(methodMGbase.rnd.nextInt(N)) ;
if (M.getName().startsWith("set")) methods_.remove(M) ;
else {
Integer M_cnt = counts.get(M) ;
if (M_cnt == null) M_cnt = 1 ; else M_cnt ++ ;
if (M_cnt >= 2) methods_.remove(M) ;
return methodMGbase.select(M).generate(info) ;
if (M_cnt >= 2) methods_.remove(M) ;
counts.put(M, M_cnt) ;
}
// randomly select a method :
Method M = methods_.get(methodMGbase.rnd.nextInt(N)) ;
Integer M_cnt = counts.get(M) ;
if (M_cnt == null) M_cnt = 1 ; else M_cnt ++ ;
if (M_cnt >= 2) methods_.remove(M) ;
counts.put(M, M_cnt) ;
return methodMGbase.select(M).generate(info) ;
} ;
......
......@@ -41,6 +41,7 @@ public class REFMG {
return P -> {
Integer k = pool.rndGetIndex(P.ty) ;
if (k!=null) {
System.out.println("=== REUSING obj: " + pool.get(k)) ;
return new Maybe(new REF(k)) ;
}
else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment