diff --git a/movement_unit_tests.py b/movement_unit_tests.py index b6df652..7b00010 100644 --- a/movement_unit_tests.py +++ b/movement_unit_tests.py @@ -1,7 +1,11 @@ +import logging import unittest import time from test_support.movement import MovementManager import sys +import os + + def user_accepts(question): @@ -21,13 +25,22 @@ def print_test_case_name(function_name): class TestBase(unittest.TestCase): def setUp(self): self.movement_manager = MovementManager() + self.logger = logging.getLogger("testlog") + self.logger.setLevel(logging.DEBUG) + with open(os.path.dirname(os.path.realpath(__file__)) + "/unittest.log", mode="a+") as f: + pass + fh = logging.FileHandler(os.path.dirname(os.path.realpath(__file__)) + "/unittest.log") + fh.setLevel(logging.DEBUG) + self.logger.addHandler(fh) + + def runTest(self): raise ValueError('test not implemented') class StraightFast(TestBase): def runTest(self): if not user_accepts('Next test: Fast drive straight and back. Are you ready?'): - print 'continuing anyway' + exit() self.movement_manager.set_max_linear_velocity(0.75) @@ -43,7 +56,7 @@ def runTest(self): class StraightModerate(TestBase): def runTest(self): if not user_accepts('Next test: Medium drive straight and back. Are you ready?'): - print 'continuing anyway' + exit() self.movement_manager.set_max_linear_velocity(0.5) @@ -59,7 +72,7 @@ def runTest(self): class StraightSlow(TestBase): def runTest(self): if not user_accepts('Next test: Slow drive straight and back. Are you ready?'): - print 'continuing anyway' + exit() self.movement_manager.set_max_linear_velocity(0.25) @@ -75,7 +88,7 @@ def runTest(self): class RotateClockwiseFast(TestBase): def runTest(self): if not user_accepts('Next test: Fast Right turn. Are you ready?'): - print 'continuing anyway' + exit() self.movement_manager.set_max_angular_velocity(.75) self.movement_manager.turn(-6.28) @@ -87,7 +100,7 @@ def runTest(self): class RotateClockwiseSlow(TestBase): def runTest(self): if not user_accepts('Next test: Slow Right turn. Are you ready?'): - print 'continuing anyway' + exit() self.movement_manager.set_max_angular_velocity(.628) self.movement_manager.turn(-6.28) @@ -99,7 +112,7 @@ def runTest(self): class RotateAnticlockwiseFast(TestBase): def runTest(self): if not user_accepts('Next test: Fast Left turn. Are you ready?'): - print 'continuing anyway' + exit() self.movement_manager.set_max_angular_velocity(0.75) self.movement_manager.turn(6.28) @@ -111,7 +124,7 @@ def runTest(self): class RotateAnticlockwiseSlow(TestBase): def runTest(self): if not user_accepts('Next test: Slow Left turn. Are you ready?'): - print 'continuing anyway' + exit() self.movement_manager.set_max_angular_velocity(.628) self.movement_manager.turn(6.28) @@ -123,7 +136,7 @@ def runTest(self): class SquareClockwise(TestBase): def runTest(self): if not user_accepts('Next test: Clockwise Box. Are you ready?'): - print 'continuing anyway' + exit() self.movement_manager.set_max_angular_velocity(1.24) self.movement_manager.set_max_linear_velocity(0.25) @@ -140,7 +153,7 @@ def runTest(self): class SquareAnticlockwise(TestBase): def runTest(self): if not user_accepts('Next test: Counter clockwise Box. Are you ready?'): - print 'continuing anyway' + exit() self.movement_manager.set_max_angular_velocity(1.24) self.movement_manager.set_max_linear_velocity(0.25) @@ -154,6 +167,21 @@ def runTest(self): if not user_accepts('did the robot drive in a shape resembling a square?'): raise ValueError('AntiClockwiseSquareError') +class MinTurnSpeed(TestBase): + def runTest(self): + if not user_accepts('Next test: Min turn speed: Are you ready?'): + exit() + + for speed in [0.3, 0.4, 0.5]: + self.movement_manager.set_max_angular_velocity(speed) + self.movement_manager.turn(0.5 * 6.28) + if user_accepts('Was the robot able to turn without stalling?'): + self.logger.debug('Min turn speed: %f' % speed) + return + + self.logger.error('Robot has unacceptable minimum turn speed') + raise ValueError('Robot has unacceptable minimum turn speed') + def get_test_suite(): test_suite = unittest.TestSuite() test_suite.addTest(unittest.makeSuite(StraightFast)) @@ -165,6 +193,7 @@ def get_test_suite(): test_suite.addTest(unittest.makeSuite(RotateAnticlockwiseSlow)) test_suite.addTest(unittest.makeSuite(SquareClockwise)) test_suite.addTest(unittest.makeSuite(SquareAnticlockwise)) + test_suite.addTest(unittest.makeSuite(MinTurnSpeed)) return test_suite