Commit 997d6034 authored by ISWB Prasetya's avatar ISWB Prasetya
Browse files

investigating G2 prefix generator

parent 78d2fc1d
......@@ -132,7 +132,7 @@ public class G2 {
SingleTarget t ;
if (config.refinementHeuristic.equals("evo")) t = new EvoSingleTarget(config,g2sg,co) ;
else t = new SingleTarget(config,g2sg,co) ;
worklist.addTarget(t);
//worklist.addTarget(t);
}
for (Method m : g2sg.scope.methods) {
if (Modifier.isStatic(m.getModifiers())) continue ;
......
......@@ -63,8 +63,8 @@ public class G2ValueMG {
public int maxLevelOfObjectsNesting = 3 ;
public int collectionSize = 3 ;
public float epsilon = 0.05f ; // max. distance to neighbor in float and double
public float chanceToPickPreviousPrimitive = 0.2f ;
public float chanceToPickSeededPrimitive = 0.55f ;
public float chanceToPickPreviousPrimitive = 0.5f ;
public float chanceToPickSeededPrimitive = 0.35f ;
public float chanceToPickNeighbor = 0.1f ; // chance to choose a neighbor of a seeded value
private EnumMG enumgens = new EnumMG();
......@@ -114,7 +114,7 @@ public class G2ValueMG {
Class C = ((JTfun) ty).fun ;
List<Serializable> s = usedSPrimitives.get(normalizeSPrimitiveTy(C)) ;
if (!s.contains(u)) {
//System.out.println(">> registering a primitive in the pool: " + u);
// System.out.println(">> registering a primitive in the pool: " + u);
s.add(u) ;
}
// well... we don't really index the primitives, so just return -1 ...
......@@ -377,7 +377,11 @@ public class G2ValueMG {
if (!Reflection.isPrimitiveLike(ty) && ty != String.class) return null ;
Serializable o = null ;
float toss = rnd.nextFloat() ;
if (toss < chanceToPickPreviousPrimitive) o = getRandomPreviouslyGeneratedSPrimitive(ty) ;
if (toss < chanceToPickPreviousPrimitive) {
//System.out.println("===> chanceToPickPreviousPrimitive " ) ;
o = getRandomPreviouslyGeneratedSPrimitive(ty) ;
//System.out.println("===> REUSING " + o) ;
}
else {
toss = toss - chanceToPickPreviousPrimitive ;
if (toss < chanceToPickSeededPrimitive) o = getRandomSeededSPrimitive(ty) ;
......@@ -463,12 +467,12 @@ public class G2ValueMG {
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),
refgens.objectUnderTest().WithChance(0.35),
refgens.objectUnderTestIfSubclass().WithChance(0.35),
refgens.random().WithChance(0.35),
nullgens.constant().WithChance(0.05),
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),
......
......@@ -12,7 +12,10 @@ public class Test_G2_forTriangle {
config.dirToSaveSuites = "/Users/iswbprasetya/tmp/t3" ;
config.dirOfStaticInfo = "/Users/iswbprasetya/tmp/t3" ;
config.generateJunitForEachSuite = false ;
config.refinementHeuristic="evo" ;
config.maxPrefixLength = 10 ;
config.maxSuffixLength = 1 ;
config.numberOfPrefixes = 60 ;
// config.refinementHeuristic="evo" ;
return config ;
}
......@@ -35,17 +38,17 @@ public class Test_G2_forTriangle {
}
static void genWithG2() throws Exception {
G2.generateSuites("Sequenic.T3.Examples.Triangle1",config(),60000) ;
G2.generateSuites("Sequenic.T3.Examples.Triangle1",config(),300000) ;
}
public static void replayG2() throws Throwable {
ReplayCmd.main("--bulk=trace(.*)Triangle(.*)tr --runall /Users/iswbprasetya/tmp/t3") ;
}
static public void main(String[] args) throws Throwable {
test_one_bareG2() ;
//test_one_bareG2() ;
//test_two_bareG2() ;
//genWithG2() ;
genWithG2() ;
//replayG2() ;
}
}
......@@ -9,40 +9,48 @@ public class Triangle1 implements Serializable {
private float z = 0 ;
public Triangle1(){
//System.out.println("Creating a triangle");
System.out.println("*** Triangle()") ;
}
public void setX(float x) {
System.out.println("* setX " + x) ;
if (x<=0) throw new IllegalArgumentException() ;
this.x = x ;
}
public void setY(float y) {
System.out.println("* setY " + y) ;
if (y<=0) throw new IllegalArgumentException() ;
this.y = y ;
}
public void setZ(float z) {
System.out.println("* setZ " + z) ;
if (z<=0) throw new IllegalArgumentException() ;
this.z = z ;
}
public boolean isTriangle() {
System.out.println("* isTriangle") ;
if (x >= y+z) return false ;
if (y >= x+z) return false ;
return z < x+y ;
}
public boolean isIsoleces() {
System.out.println("* isIsoleces") ;
if (x==y) return true ;
if (y==z) return true ;
if (x==z) return true ;
return false ;
}
public boolean isEquilateral() {
System.out.println("* isEquilateral") ;
return (x==y) && (y==z) ;
}
public boolean isScalene() {
System.out.println("* isEquilateral") ;
return ! isIsoleces() ;
}
@Override
public boolean equals(Object o) {
System.out.println("* equals") ;
if (o instanceof Triangle1) {
//if (o != this) System.out.println(">>> o is NOT this!") ;
//else System.out.println(">>> o is this!") ;
......@@ -53,4 +61,11 @@ public class Triangle1 implements Serializable {
}
return false ;
}
public String toString() {
System.out.println("* toString") ;
return "Triangle: " + x + "/" + y + "/" + z ;
}
}
......@@ -92,7 +92,11 @@ public class SegmentG extends AbstractSeqGenerator {
int N = methods_.size() ;
if (N==0) return null ;
Method M = methods_.get(methodMGbase.rnd.nextInt(N)) ;
if (M.getName().startsWith("set")) methods_.remove(M) ;
String mname = M.getName().toLowerCase() ;
if (mname.startsWith("set") || mname.startsWith("clear")
|| mname.startsWith("reset")
)
methods_.remove(M) ;
else {
Integer M_cnt = counts.get(M) ;
if (M_cnt == null) M_cnt = 1 ; else M_cnt ++ ;
......
......@@ -41,7 +41,7 @@ public class REFMG {
return P -> {
Integer k = pool.rndGetIndex(P.ty) ;
if (k!=null) {
System.out.println("=== REUSING obj: " + pool.get(k)) ;
//System.out.println("===> REUSING obj: " + pool.get(k)) ;
return new Maybe(new REF(k)) ;
}
else {
......@@ -56,6 +56,7 @@ public class REFMG {
Integer k = pool.getIndexOfObjectUnderTest() ;
if (k==null) return null ;
if (P.ty.equals(pool.getTypeOfObjectUnderTest())) {
//System.out.println("#### YES") ;
return new Maybe(new REF(k)) ;
}
else return null ;
......@@ -66,7 +67,10 @@ public class REFMG {
return P -> {
Integer k = pool.getIndexOfObjectUnderTest() ;
if (k==null) return null ;
if (JTypeUtils.getTopClass(P.ty).isAssignableFrom(pool.getObjectUnderTest().getClass())) {
Class Ctobj = pool.getObjectUnderTest().getClass() ;
//System.out.println("#### P.ty = " + JTypeUtils.getTopClass(P.ty) + " vs " + Ctobj.getName()) ;
if (JTypeUtils.getTopClass(P.ty).isAssignableFrom(Ctobj)) {
//System.out.println("#### ok") ;
return new Maybe(new REF(k)) ;
}
else return null ;
......
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