summaryrefslogtreecommitdiff
path: root/tests/sources/0600_bubble_sort.c
diff options
context:
space:
mode:
authorAlex AUVOLAT <alex.auvolat@ens.fr>2014-04-30 17:19:08 +0200
committerAlex AUVOLAT <alex.auvolat@ens.fr>2014-04-30 17:19:08 +0200
commitbcde99fbe99174a094f38fdda70ad69d65a423f4 (patch)
tree21e16494aba19c4a63d55eba877abfe7fe5d8e80 /tests/sources/0600_bubble_sort.c
downloadSemVerif-Projet-bcde99fbe99174a094f38fdda70ad69d65a423f4.tar.gz
SemVerif-Projet-bcde99fbe99174a094f38fdda70ad69d65a423f4.zip
Fist commit (WIP)
Diffstat (limited to 'tests/sources/0600_bubble_sort.c')
-rw-r--r--tests/sources/0600_bubble_sort.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/sources/0600_bubble_sort.c b/tests/sources/0600_bubble_sort.c
new file mode 100644
index 0000000..5cad03d
--- /dev/null
+++ b/tests/sources/0600_bubble_sort.c
@@ -0,0 +1,32 @@
+// Example from Cousot Habwachs POPL 1978
+
+// Bubble sort, where array operations are abstracted away
+// to get a non-deterministic scalar program
+
+// expected results:
+// - with polyhedra, no assertion failure (proof of absence of array overflow)
+// - with intervals, assertion failure
+
+int B,J,T;
+int N = rand(0,100000); // array size
+
+B = N;
+while (B >= 1) {
+ J = 1;
+ T = 0;
+ while (J <= B-1) {
+
+ // array bound-check
+ assert(1 <= J && J <= N);
+ assert(1 <= (J+1) && (J+1) <= N);
+
+ // the non-deterministic test models comparing TAB[J] and TAB[J+1]
+ if (rand(0,1)==0) {
+ // where, we would exchange TAB[J] and TAB[J+1];
+ T = J;
+ }
+
+ J = J + 1;
+ }
+ B = T;
+}