changeset 255:13ec22bec5d4

corrected typos and bugs and added a test
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 23 Jul 2012 23:07:19 -0400
parents 4b71e81e3383
children dc1faa7287bd
files python/extrapolation.py python/moving.py python/run-tests.sh python/tests/extrapolation.txt python/tests/moving.txt
diffstat 5 files changed, 31 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/python/extrapolation.py	Mon Jul 23 12:35:45 2012 -0400
+++ b/python/extrapolation.py	Mon Jul 23 23:07:19 2012 -0400
@@ -26,7 +26,8 @@
 
     def predictPosition(self, nTimeSteps):
         if nTimeSteps > 0 and not nTimeSteps in self.predictedPositions.keys():
-            self.predictedPositions[nTimeSteps], self.predictedspeedOrientations[nTimeSteps] = predictPosition(self.predictedPositions[nTimeSteps-1], self.predictedspeedOrientations[nTimeSteps-1], self.control, maxSpeed)
+            self.predictPosition(nTimeSteps-1)
+            self.predictedPositions[nTimeSteps], self.predictedSpeedOrientations[nTimeSteps] = moving.predictPosition(self.predictedPositions[nTimeSteps-1], self.predictedSpeedOrientations[nTimeSteps-1], self.control, self.maxSpeed)
         return self.predictedPositions[nTimeSteps]
 
 class ExtrapolatedTrajectoryAdaptation(ExtrapolatedTrajectoryConstant):
@@ -204,3 +205,12 @@
     return POC
 
 
+if __name__ == "__main__":
+    import doctest
+    import unittest
+    suite = doctest.DocFileSuite('tests/extrapolation.txt')
+    #suite = doctest.DocTestSuite()
+    unittest.TextTestRunner().run(suite)
+    #doctest.testmod()
+    #doctest.testfile("example.txt")
+
--- a/python/moving.py	Mon Jul 23 12:35:45 2012 -0400
+++ b/python/moving.py	Mon Jul 23 23:07:19 2012 -0400
@@ -245,11 +245,11 @@
 
     def __add__(self, other):
         'a norm cannot become negative'
-        return NormAngle(max(self.norm+other.norm, 0), self.orientation+other.orientation)
+        return NormAngle(max(self.norm+other.norm, 0), self.angle+other.angle)
 
     def getPoint(self):
         from math import cos, sin
-        return Point(self.norm*cos(self.orientation), self.norm*sin(self.orientation))
+        return Point(self.norm*cos(self.angle), self.norm*sin(self.angle))
 
 
 def predictPositionNoLimit(nTimeSteps, initialPosition, initialVelocity, initialAcceleration = Point(0,0)):
@@ -571,7 +571,7 @@
     def predictPosition(self, instant, nTimeSteps, externalAcceleration = Point(0,0)):
         '''Predicts the position of object at instant+deltaT, 
         at constant speed'''
-        return predictPosition(nTimeSteps, self.getPositionAtInstant(instant), self.getVelocityAtInstant(instant), externalAcceleration)
+        return predictPositionNoLimit(nTimeSteps, self.getPositionAtInstant(instant), self.getVelocityAtInstant(instant), externalAcceleration)
 
     @staticmethod
     def collisionCourseDotProduct(movingObject1, movingObject2, instant):
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/run-tests.sh	Mon Jul 23 23:07:19 2012 -0400
@@ -0,0 +1,7 @@
+#!/bin/sh
+# for file in tests/*... basename
+python moving.py
+python storage.py
+python indicators.py
+python utils.py
+python extrapolation.py
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/tests/extrapolation.txt	Mon Jul 23 23:07:19 2012 -0400
@@ -0,0 +1,8 @@
+>>> import extrapolation
+>>> import moving
+
+>>> et = extrapolation.ExtrapolatedTrajectoryConstant(moving.Point(0,0), moving.Point(1,0))
+>>> et.predictPosition(4) # doctest:+ELLIPSIS
+(0.0...,4.0...)
+>>> et.predictPosition(1) # doctest:+ELLIPSIS
+(0.0...,1.0...)
--- a/python/tests/moving.txt	Mon Jul 23 12:35:45 2012 -0400
+++ b/python/tests/moving.txt	Mon Jul 23 23:07:19 2012 -0400
@@ -54,8 +54,8 @@
 >>> Point(3,2).inPolygon([Point(0,0),Point(4,0),Point(4,3),Point(0,3)])
 True
 
->>> predictPosition(10, Point(0,0), Point(1,1)) # doctest:+ELLIPSIS
-(10...,10...)
+>>> predictPositionNoLimit(10, Point(0,0), Point(1,1)) # doctest:+ELLIPSIS
+((1.0...,1.0...), (10.0...,10.0...))
 
 >>> segmentIntersection(Point(0,0),Point(1,1), Point(0,1), Point(1,2))
 >>> segmentIntersection(Point(0,1),Point(1,0), Point(0,2), Point(2,1))