Anonymous avatar Anonymous committed 62aa64a

unit test and rect fixes

Comments (0)

Files changed (5)

 	Angus, Guillaume Proux, Frank Raiser,
 	Austin Henry, Kaweh Kazemi, Arturo Aldama,
         Mike Mulcheck
+- Nat Pryce for starting our unit tests
 
 Cheers to TheCorruptor for his incredible work on the pygame logo.
 
 # BREAK = change breaks existing code
 # BUG	= fixed a bug that was (or could have been) crashing
 
+January 16, 2001
+	implemented basic unit tests
+	several bug cleanups with Rects (thx unit tests)
+
 January 14, 2001
 	display.update() boundaries fixed
 

docs/ref/Rect.html

 Rect.clamp(rectstyle) -> Rect
 </tt></font><ul>
 Returns a new rectangle that is moved to be
-completely inside the base rectangle. If the given
-rectangle is too large for the base rectangle in
+completely inside the argument rectangle. If the base
+rectangle is too large for the argument rectangle in
 an axis, it will be centered on that axis.
 </ul><br>&nbsp;<br>
 
 Rect.clamp_ip(rectstyle) -> None
 </tt></font><ul>
 Moves the Rect to be
-completely inside the base rectangle. If the given
-rectangle is too large for the base rectangle in
+completely inside the argument rectangle. If the given
+rectangle is too large for the argument rectangle in
 an axis, it will be centered on that axis.
 </ul><br>&nbsp;<br>
 
+import sys
+import os
+import re
+import unittest
+
+main_dir = os.path.split(os.path.abspath(sys.argv[0]))[0]
+test_subdir = 'test'
+
+# Make sure we're in the correct directory
+os.chdir( main_dir )
+
+# Add the modules directory to the python path    
+sys.path.insert( 0, test_subdir )
+
+# Load all the tests
+suite = unittest.TestSuite()
+test_module_re = re.compile('^(.+_test)\.py$')
+for file in os.listdir(test_subdir):
+    for module in test_module_re.findall(file):
+        print 'loading ' + module
+        __import__( module )
+        test = unittest.defaultTestLoader.loadTestsFromName( module )
+        suite.addTest( test )
+
+# Run the tests
+runner = unittest.TextTestRunner()
+runner.run( suite )
 	if(!TwoShortsFromObj(args, &x, &y))
 		return RAISE(PyExc_TypeError, "argument must contain two numbers");
 
-	inside = x>=self->r.x && x<=self->r.x+self->r.w && 
-				y>=self->r.y && y<=self->r.y+self->r.h;
+	inside = x>=self->r.x && x<self->r.x+self->r.w && 
+				y>=self->r.y && y<self->r.y+self->r.h;
 
 	return PyInt_FromLong(inside);
 }
 		return RAISE(PyExc_TypeError, "Argument must be rect style object");
 
 	contained = (self->r.x <= argrect->x) && (self->r.y <= argrect->y) &&
-					(self->r.x + self->r.w >= argrect->x + argrect->w) &&
-					(self->r.y + self->r.h >= argrect->y + argrect->h);
+	            (self->r.x + self->r.w >= argrect->x + argrect->w) &&
+	            (self->r.y + self->r.h >= argrect->y + argrect->h) &&
+	            (self->r.x + self->r.w > argrect->x) &&
+	            (self->r.y + self->r.h > argrect->y);
 
 	return PyInt_FromLong(contained);
 }
     /*DOC*/    "move rectangle inside another\n"
     /*DOC*/    "\n"
     /*DOC*/    "Returns a new rectangle that is moved to be\n"
-    /*DOC*/    "completely inside the base rectangle. If the given\n"
-    /*DOC*/    "rectangle is too large for the base rectangle in\n"
+    /*DOC*/    "completely inside the argument rectangle. If the base\n"
+    /*DOC*/    "rectangle is too large for the argument rectangle in\n"
     /*DOC*/    "an axis, it will be centered on that axis.\n"
     /*DOC*/ ;
 
 		return RAISE(PyExc_TypeError, "Argument must be rect style object");
 
 	if(self->r.w >= argrect->w)
-		x = (argrect->x+argrect->w) / 2 - self->r.w / 2;
+		x = argrect->x + argrect->w / 2 - self->r.w / 2;
 	else if(self->r.x < argrect->x)
 		x = argrect->x;
 	else if(self->r.x + self->r.w > argrect->x + argrect->w)
 		x = self->r.x;
 
 	if(self->r.h >= argrect->h)
-		y = (argrect->y+argrect->h) / 2 - self->r.h / 2;
+		y = argrect->y + argrect->h / 2 - self->r.h / 2;
 	else if(self->r.y < argrect->y)
 		y = argrect->y;
 	else if(self->r.y + self->r.h > argrect->y + argrect->h)
     /*DOC*/    "moves the rectangle inside another\n"
     /*DOC*/    "\n"
     /*DOC*/    "Moves the Rect to be\n"
-    /*DOC*/    "completely inside the base rectangle. If the given\n"
-    /*DOC*/    "rectangle is too large for the base rectangle in\n"
+    /*DOC*/    "completely inside the argument rectangle. If the given\n"
+    /*DOC*/    "rectangle is too large for the argument rectangle in\n"
     /*DOC*/    "an axis, it will be centered on that axis.\n"
     /*DOC*/ ;
 
 		return RAISE(PyExc_TypeError, "Argument must be rect style object");
 
 	if(self->r.w >= argrect->w)
-		x = (argrect->x+argrect->w) / 2 - self->r.w / 2;
+		x = argrect->x + argrect->w / 2 - self->r.w / 2;
 	else if(self->r.x < argrect->x)
 		x = argrect->x;
 	else if(self->r.x + self->r.w > argrect->x + argrect->w)
 		x = self->r.x;
 
 	if(self->r.h >= argrect->h)
-		y = (argrect->y+argrect->h) / 2 - self->r.h / 2;
+		y = argrect->y + argrect->h / 2 - self->r.h / 2;
 	else if(self->r.y < argrect->y)
 		y = argrect->y;
 	else if(self->r.y + self->r.h > argrect->y + argrect->h)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.