13. Especificaciones “in-code” public class SortedList { private LinkedList<Comparable> s private Comparable max public SortedList() public … insert(Comparable x) public … get() } public Comparable get_spec () { assert s.isEmpty() : "PRE" Comparable ret = get() assert … ret.compareTo(s.getLast()) 0 : "POST" return ret } Cuando T2 selecciona los métodos para la secuencia comprueba si existe un metodo_spec. Si existe lo utiliza en lugar del método original
14. Especificar un invariante parcial public class SortedList { private LinkedList<Comparable> s private Comparable max public SortedList() public … insert(Comparable x) public … get() } public boolean classinv () { return s.isEmpty() s.contains(max); } T2 verifica después de cada llamada si se cumple el invariante
15.
16. ** Error trace [1] : ** CREATING target object: (U2.T2.examples.SortedList) @ 0 s (LinkedList) @ 1 max NULL ** STEP 1. ** Calling method insert with: ** Receiver: target-obj ** Arg [0:] (Integer) : 29 ** Target object after the step: (U2.T2.examples.SortedList) @ 0 s (LinkedList) @ 3 [0] (Integer) : 29 max (Integer) : 29 ** STEP 2. ** Calling method insert with: ** Receiver: target-obj ** Arg [0:] (Integer) : 0 ** Target object after the step: (U2.T2.examples.SortedList) @ 0 s (LinkedList) @ 5 [0] (Integer) : 0 [1] (Integer) : 29 max (Integer) : 0 ** STEP 3. ** Calling method get_spec with: ** Receiver: target-obj ** Throwing java.lang.AssertionError: POST ** Target object after the step: (U2.T2.examples.SortedList) @ 0 s (LinkedList) @ 3 [0] (Integer) : 29 max (Integer) : 29 ** Assertion VIOLATED! ** Strack trace: java.lang.AssertionError: POST at U2.T2.examples.SortedList.get_spec(SortedList.java:44) ... Un error en insert detectado por la post-condición de get…. La ventaja del testeo basado en secuencias…..
17.
18.
19.
20.
21. Ejemplo Obtenido por T2: nombre del ultimo método/atributo llamado/asignado Indica en que estado del modelo nos encontramos Alterna en cada llamada entre el estado 1 y 2 del modelo de aplicacion Cuando no se cumple T2 descarta el paso de la secuencia automáticamente El modelo solo permite llamar a inc y a dec alternativamente
23. Algunos resultados Class #Meth Max. Cyclo # Inst Block Cov. (%) Branch Cov. (%) Time (ms) Fault #step BinarySearch Tree 18 7 359 94 72 907 No 20 K SortedList 7 6 212 98 85 16 yes 0.5 K Show 13 33 844 84 75 2500 no 5 K Pool 10 7 340 91 69 531 no 5 K