summaryrefslogtreecommitdiff
path: root/Test/dafny1/MatrixFun.dfy
diff options
context:
space:
mode:
authorGravatar rustanleino <unknown>2010-09-21 00:17:44 +0000
committerGravatar rustanleino <unknown>2010-09-21 00:17:44 +0000
commit40021fe7042eb08ed5b4d16034e23c9ed022c4aa (patch)
tree66212af4ff0f7ab4f2f6769143adad1fe01131c8 /Test/dafny1/MatrixFun.dfy
parentac901e76d0e5ba746377dda60d948b120cb3b4bc (diff)
Dafny: Compilation of multi-dimensional arrays
Diffstat (limited to 'Test/dafny1/MatrixFun.dfy')
-rw-r--r--Test/dafny1/MatrixFun.dfy41
1 files changed, 41 insertions, 0 deletions
diff --git a/Test/dafny1/MatrixFun.dfy b/Test/dafny1/MatrixFun.dfy
index 96d89ad6..86ad451d 100644
--- a/Test/dafny1/MatrixFun.dfy
+++ b/Test/dafny1/MatrixFun.dfy
@@ -57,3 +57,44 @@ method Flip<T>(m: array2<T>)
}
}
}
+
+method Main()
+{
+ var B := new bool[2,5];
+ B[0,0] := true; B[0,1] := false; B[0,2] := false; B[0,3] := true; B[0,4] := false;
+ B[1,0] := true; B[1,1] := true; B[1,2] := true; B[1,3] := true; B[1,4] := false;
+ print "Before:\n";
+ call PrintMatrix(B);
+ call MirrorImage(B);
+ print "Mirror image:\n";
+ call PrintMatrix(B);
+
+ var A := new int[3,3];
+ A[0,0] := 5; A[0,1] := 7; A[0,2] := 9;
+ A[1,0] := 6; A[1,1] := 2; A[1,2] := 3;
+ A[2,0] := 7; A[2,1] := 1; A[2,2] := 0;
+ print "Before:\n";
+ call PrintMatrix(A);
+ call Flip(A);
+ print "Flip:\n";
+ call PrintMatrix(A);
+}
+
+method PrintMatrix<T>(m: array2<T>)
+ requires m != null;
+{
+ var i := 0;
+ while (i < m.Length0) {
+ var j := 0;
+ while (j < m.Length1) {
+ print m[i,j];
+ j := j + 1;
+ if (j == m.Length1) {
+ print "\n";
+ } else {
+ print ", ";
+ }
+ }
+ i := i + 1;
+ }
+}