Skip to content

Commit 9238828

Browse files
add test for field assign method
1 parent 0f067eb commit 9238828

3 files changed

Lines changed: 67 additions & 1 deletion

File tree

latte-umbrella/src/main/java/examples/MyStack.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void push( @Free Object value) {
2828
}
2929

3030

31-
public @Free Node test( @Free Object value) {
31+
public @Shared Node test( @Free Object value) {
3232
return new Node(value,null);
3333
}
3434

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
import specification.Borrowed;
3+
import specification.Free;
4+
import specification.Unique;
5+
import specification.Shared;
6+
7+
public class MyStackFieldAssignMethod {
8+
9+
@Unique Node root;
10+
11+
public MyStack(@Free Node root) {
12+
this.root = root;
13+
}
14+
15+
void push( @Free Object value) {
16+
Node r;
17+
Node n;
18+
19+
r = this.root; // save root in r
20+
this.root = null; //nullify root
21+
22+
23+
this.root = test(null);
24+
// n = new Node(value, r); //create new root
25+
// this.root = n; //replace root
26+
}
27+
28+
29+
public @Shared Node test( @Free Object value) {
30+
return new Node(value,null);
31+
}
32+
33+
}
34+
35+
/**
36+
* Node class for the stack example
37+
* Uses @Unique annotations to specify that the value and next fields are unique
38+
* in the scope of the Node class
39+
* @author catarina gamboa
40+
*
41+
*/
42+
class Node {
43+
44+
@Unique Object value;
45+
@Unique Node next;
46+
47+
/**
48+
* Constructor for the Node class using @Free value and next nodes
49+
* @param value
50+
* @param next
51+
*/
52+
public Node (@Free Object value, @Free Node next) {
53+
this.value = value;
54+
this.next = next;
55+
}
56+
}

latte-umbrella/src/test/java/latte/latte_umbrella/AppTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ public void testSmallestIncorrectExample(){
127127

128128
}
129129

130+
@Test
131+
public void testMyStackFieldAssignMethod(){
132+
try {
133+
App.launcher("src/test/examples/MyStackFieldAssignMethod.java");
134+
} catch (Exception e) {
135+
assertTrue(e instanceof LatteException);
136+
assertTrue(e.getMessage().contains("UNIQUE but got SHARED"));
137+
}
138+
}
139+
130140

131141
@Test
132142
public void testReachabilityUnitTest(){

0 commit comments

Comments
 (0)