1 / 5

Specifications in JML

Specifications in JML. Example: Linear Search: Environment: var N : int; b : array [0.. N ) of int; i, x : int; Frame: i : [ N >0  x  b [0.. N ), 0  i < N  (  j | 0  j < i : x  b [ j ])  x = b [ i ]]. In JML public static int[] b= {2,3,1,2,4, 3,4};

Download Presentation

Specifications in JML

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Specifications in JML • Example: Linear Search: • Environment: varN: int; b:array [0..N) of int; i, x: int; • Frame:i: [N>0 xb[0..N), 0 i <N (j| 0 j < i: xb[j]) x=b[i]] • In JML • public static int[] b= {2,3,1,2,4, 3,4}; • /*@ requires (\exists int j; 0<=j && j<b.length;x==b[j]); • @ ensures b[\result]==x; • @ ensures (\forall int j;0<=j && j<\result; b[j]!=x); • @*/ • public static int search1(int x){---} UCN T&B: JML-1

  2. Specifications in JML public static int search1(int x){ int i= 0; boolean found= false; while(i<b.length && !found){ if(x==b[i]) found= true; else i++; } return i; } public static void main(String[] args){ System.out.println(search1(3)); } public static int[] b= {2,3,1,2,4, 3,4}; UCN T&B: JML-1

  3. Specifications in JML public static int search1(int x){ int i= 0; boolean found= false; while(i<b.length && !found){ if(x==b[i]) found= true; else i++; } return i; } public static void main(String[] args){ System.out.println(search1(13)); } Precondition! UCN T&B: JML-1

  4. Specifications in JML public static int search1(int x){ int i= 0; boolean found= false; while(i<b.length && !found){ if(x==b[i]) found= true; else i++; } return i+1; } public static void main(String[] args){ System.out.println(search1(3)); } Postcondition! UCN T&B: JML-1

  5. Exercise • Implement and test a few of the examples or exercises in Java and JML. UCN T&B: JML-1

More Related