Contract simple examples

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5078 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Tiger Feng 2003-09-05 19:07:01 +00:00
commit f7babc08a2
10 changed files with 291 additions and 0 deletions

View file

@ -0,0 +1,11 @@
#include <stdio.h>
int Circle (int x, int y, int radius) {
/* Draw Circle */
printf("Drawing the circle...\n");
/* Return -1 to test contract post assertion */
if (radius == 2)
return -1;
else
return 1;
}

View file

@ -0,0 +1,17 @@
/* File : example.i */
/* Basic C example for swig contract */
/* Tiger, University of Chicago, 2003 */
%module example
%contract Circle (int x, int y, int radius) {
require:
x >= 0;
y >= 0;
radius > x;
ensure:
Circle >= 0;
}
extern int Circle (int x, int y, int radius);

View file

@ -0,0 +1,17 @@
import example
# Call the Circle() function correctly
x = 1;
y = 1;
r = 3;
c = example.Circle(x, y, r)
# test post-assertion
x = 1;
y = 1;
r = 2;
c = example.Circle(x, y, r)
print "The return value of Circle(%d, %d, %d) is %d" % (x,y,r,c)

View file

@ -0,0 +1,20 @@
import example
# Call the Circle() function correctly
x = 1;
y = 1;
r = 3;
c = example.Circle(x, y, r)
print "The return value of Circle(%d, %d, %d) is %d" % (x,y,r,c)
# test pre-assertion
x = 1;
y = -1;
r = 3;
c = example.Circle(x, y, r)
print "The return value of Circle(%d, %d, %d) is %d" % (x,y,r,c)