



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Instructions for a mini-project in the cmps 290g - topics in software engineering course during winter 2004. The project involves implementing a modelchecker class to ensure that the bubblesort algorithm never yields an assertion failure. Students are required to write code for the leq() method in the modelchecker class and run the model checker multiple times to test all possible paths. The supplied code includes the bubblesort class and the myint class, which represents symbolic integers.
Typology: Assignments
1 / 7
This page cannot be seen from the preview
Don't miss anything!




This homework is in the form of a mini-project. This project pulls together ideas from testing, model checking, and theorem proving. Your contribution can be implemented with under 100 lines of code. The code on the following pages provides basic infrastructure for this project. (This code is also at http://www.soe.ucsc.edu/classes/cmps290g/Winter04/code.)
Good luck!
/** The model checker skeleton. What you need to do is fill out this skeleton. */
public class ModelChecker {
/** Called by Bubblesort application to compare symbolic integers. */
public static boolean leq(MyInt x,MyInt y) { ... // Your job: write something clever here }
/** Main routine: Calls Bubblesort.main() multiple times to test all possible paths. */
public static void main(String[] args) { int numruns=0; while(...) { MyInt.reset(); numruns++; Bubblesort.main(); } System.out.println("Test runs: "+numruns); }
import java.util.*;
/** Represents a symbolic integer.
static ArrayList myInts=new ArrayList(); static int curNdx=0;
static void reset() { curNdx=0; }
private MyInt() { id=numMyInt++; }
public String toString() { return "v"+id; }
static MyInt get() { if (curNdx==myInts.size()) { myInts.add(new MyInt()); } return (MyInt)myInts.get(curNdx++); } }
public class Assert { public static void fail(String s) { throw new RuntimeException("Assertion failure: "+s); } public static void isTrue(boolean b) { if(!b) fail(""); }
public abstract class Constraint { public abstract Constraint negate(); }
/* Expresses constraints over MyInts of the form "x <= y + c", where x and y are MyInts.
public class ConstraintDiff extends Constraint { int c; MyInt x,y; // x <= y+c
ConstraintDiff(MyInt x, MyInt y,int c) { this.x=x; this.y=y; this.c=c; }
public Constraint negate() { return new ConstraintDiff(y,x,-c-1); }
public String toString() { return ""+x+"<="+y+(c==0? "": (c<0? ""+c : "+"+c)); }
public boolean equals(Object o) { if (!(o instanceof ConstraintDiff)) return false; ConstraintDiff d = (ConstraintDiff)o; return d.x==x && d.y==y && d.c==c; }
public int hashCode() { return x.hashCode()+y.hashCode()+c; }
return false; }
private static Iterator from(MyInt x,ArrayList constraints) { List r = new LinkedList(); for(Iterator i=constraints.iterator(); i.hasNext();) { ConstraintDiff cd=(ConstraintDiff)i.next(); if (cd.x==x) r.add(cd); } return r.iterator(); } private static Set symInts(ArrayList constraints) { Set r = new LinkedHashSet(); for(Iterator i=constraints.iterator(); i.hasNext();) { ConstraintDiff cd=(ConstraintDiff)i.next(); r.add(cd.x); r.add(cd.y); } return r; }