Skip to content

Commit cee11e0

Browse files
committed
[CN-Test-Gen] Add more failing CI tests
1 parent 75dce8c commit cee11e0

File tree

4 files changed

+216
-0
lines changed

4 files changed

+216
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Sorted list
2+
3+
struct List
4+
{
5+
int value;
6+
struct List* next;
7+
};
8+
9+
/*@
10+
datatype IntList {
11+
Nil {},
12+
Cons { i32 head, IntList tail }
13+
}
14+
15+
function (boolean) validCons(i32 head, IntList tail) {
16+
match tail {
17+
Nil {} => { true }
18+
Cons { head: next, tail: _ } => { head <= next }
19+
}
20+
}
21+
22+
predicate IntList ListSegment(pointer from, pointer to) {
23+
if (ptr_eq(from,to)) {
24+
return Nil {};
25+
} else {
26+
take head = Owned<struct List>(from);
27+
take tail = ListSegment(head.next, to);
28+
assert(validCons(head.value,tail));
29+
return Cons { head: head.value, tail: tail };
30+
}
31+
}
32+
@*/
33+
34+
void *cn_malloc(unsigned long size);
35+
36+
37+
// This is invalid because we don't preserve the sorted invariant.
38+
void cons(int x, struct List** xs)
39+
/*@
40+
requires
41+
take list_ptr = Owned<struct List*>(xs);
42+
take list = ListSegment(list_ptr,NULL);
43+
ensures
44+
take new_list_ptr = Owned<struct List*>(xs);
45+
take new_list = ListSegment(new_list_ptr,NULL);
46+
@*/
47+
{
48+
struct List *node = (struct List*) cn_malloc(sizeof(struct List));
49+
node->value = x;
50+
node->next = *xs;
51+
*xs = node;
52+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Sorted list
2+
3+
struct List
4+
{
5+
int value;
6+
struct List* next;
7+
};
8+
9+
/*@
10+
datatype IntList {
11+
Nil {},
12+
Cons { i32 head, IntList tail }
13+
}
14+
15+
function (boolean) validCons(i32 head, IntList tail) {
16+
match tail {
17+
Nil {} => { true }
18+
Cons { head: next, tail: _ } => { head <= next }
19+
}
20+
}
21+
22+
function [rec] (IntList) insertList(boolean dups, i32 x, IntList xs) {
23+
match xs {
24+
Nil {} => { Cons { head: x, tail: Nil {} } }
25+
Cons { head: head, tail: tail } => {
26+
if (head < x) {
27+
Cons { head: head, tail: insertList(dups, x,tail) }
28+
} else {
29+
if (!dups && head == x) {
30+
xs
31+
} else {
32+
Cons { head: x, tail: xs }
33+
}
34+
}
35+
}
36+
}
37+
}
38+
39+
predicate IntList ListSegment(pointer from, pointer to) {
40+
if (ptr_eq(from,to)) {
41+
return Nil {};
42+
} else {
43+
take head = Owned<struct List>(from);
44+
take tail = ListSegment(head.next, to);
45+
assert(validCons(head.value,tail));
46+
return Cons { head: head.value, tail: tail };
47+
}
48+
}
49+
@*/
50+
51+
void *cn_malloc(unsigned long size);
52+
53+
void insert(int x, struct List **xs)
54+
/*@
55+
requires
56+
take list_ptr = Owned<struct List*>(xs);
57+
take list = ListSegment(list_ptr,NULL);
58+
ensures
59+
take new_list_ptr = Owned<struct List*>(xs);
60+
take new_list = ListSegment(new_list_ptr,NULL);
61+
new_list == insertList(false,x,list);
62+
@*/
63+
{
64+
struct List *node = (struct List*) cn_malloc(sizeof(struct List));
65+
node->value = x;
66+
67+
struct List* prev = 0;
68+
struct List* cur = *xs;
69+
while (cur && cur->value < x) {
70+
prev = cur;
71+
cur = cur->next;
72+
}
73+
74+
if (prev) {
75+
prev->next = node;
76+
node->next = cur;
77+
} else {
78+
node->next = *xs;
79+
*xs = node;
80+
}
81+
82+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Sorted list
2+
3+
struct List
4+
{
5+
int value;
6+
struct List* next;
7+
};
8+
9+
/*@
10+
datatype IntList {
11+
Nil {},
12+
Cons { i32 head, IntList tail }
13+
}
14+
15+
function (boolean) validCons(i32 head, IntList tail) {
16+
match tail {
17+
Nil {} => { true }
18+
Cons { head: next, tail: _ } => { head <= next }
19+
}
20+
}
21+
22+
function [rec] (IntList) insertList(boolean dups, i32 x, IntList xs) {
23+
match xs {
24+
Nil {} => { Cons { head: x, tail: Nil {} } }
25+
Cons { head: head, tail: tail } => {
26+
if (head < x) {
27+
Cons { head: head, tail: insertList(dups, x,tail) }
28+
} else {
29+
if (!dups && head == x) {
30+
xs
31+
} else {
32+
Cons { head: x, tail: xs }
33+
}
34+
}
35+
}
36+
}
37+
}
38+
39+
predicate IntList ListSegment(pointer from, pointer to) {
40+
if (ptr_eq(from,to)) {
41+
return Nil {};
42+
} else {
43+
take head = Owned<struct List>(from);
44+
take tail = ListSegment(head.next, to);
45+
assert(validCons(head.value,tail));
46+
return Cons { head: head.value, tail: tail };
47+
}
48+
}
49+
@*/
50+
51+
void *cn_malloc(unsigned long size);
52+
53+
void insert(int x, struct List **xs)
54+
/*@
55+
requires
56+
take list_ptr = Owned<struct List*>(xs);
57+
take list = ListSegment(list_ptr,NULL);
58+
ensures
59+
take new_list_ptr = Owned<struct List*>(xs);
60+
take new_list = ListSegment(new_list_ptr,NULL);
61+
new_list == insertList(true,x,list);
62+
@*/
63+
{
64+
struct List *node = (struct List*) cn_malloc(sizeof(struct List));
65+
node->value = x;
66+
67+
struct List* prev = 0;
68+
struct List* cur = *xs;
69+
while (cur && cur->value < x) {
70+
prev = cur;
71+
cur = cur->next;
72+
}
73+
74+
if (prev) {
75+
prev->next = node;
76+
node->next = cur;
77+
} else {
78+
node->next = *xs;
79+
*xs = node;
80+
}
81+
82+
}
File renamed without changes.

0 commit comments

Comments
 (0)