From be331fffd1b3d0304ebe30f48c478d63e6bb296b Mon Sep 17 00:00:00 2001 From: jbrover Date: Mon, 27 Sep 2021 12:38:12 -0500 Subject: [PATCH 1/5] preliminary turn speed outline --- movement_unit_tests.py | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/movement_unit_tests.py b/movement_unit_tests.py index b6df652..52f3297 100644 --- a/movement_unit_tests.py +++ b/movement_unit_tests.py @@ -2,6 +2,7 @@ import time from test_support.movement import MovementManager import sys +import logging def user_accepts(question): @@ -21,13 +22,14 @@ def print_test_case_name(function_name): class TestBase(unittest.TestCase): def setUp(self): self.movement_manager = MovementManager() + logging.basicConfig(filename="unittest.log", level=logging.DEBUG) 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 +45,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 +61,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 +77,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 +89,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 +101,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 +113,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 +125,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 +142,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 +156,19 @@ 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?'): + return + + raise ValueError('Robot has unacceptable minimum turn speed') + def get_test_suite(): test_suite = unittest.TestSuite() test_suite.addTest(unittest.makeSuite(StraightFast)) @@ -165,6 +180,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 From 108a2445dd12401326e6f31b79c45ca9e0e17416 Mon Sep 17 00:00:00 2001 From: jbrover Date: Mon, 27 Sep 2021 13:45:20 -0500 Subject: [PATCH 2/5] preliminary unit test updates --- movement_unit_tests.py | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/movement_unit_tests.py b/movement_unit_tests.py index 52f3297..277d6d1 100644 --- a/movement_unit_tests.py +++ b/movement_unit_tests.py @@ -1,8 +1,10 @@ +import logging import unittest import time from test_support.movement import MovementManager import sys -import logging + + def user_accepts(question): @@ -22,7 +24,12 @@ def print_test_case_name(function_name): class TestBase(unittest.TestCase): def setUp(self): self.movement_manager = MovementManager() - logging.basicConfig(filename="unittest.log", level=logging.DEBUG) + self.logger = logging.getLogger("testlog") + self.logger.setLevel(logging.DEBUG) + fh = logging.FileHandler("unittest.log") + fh.setLevel(logging.DEBUG) + self.logger.addHandler(fh) + def runTest(self): raise ValueError('test not implemented') @@ -165,21 +172,23 @@ def runTest(self): 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 - raise ValueError('Robot has unacceptable minimum turn speed') + 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)) - test_suite.addTest(unittest.makeSuite(StraightModerate)) - test_suite.addTest(unittest.makeSuite(StraightSlow)) - test_suite.addTest(unittest.makeSuite(RotateClockwiseFast)) - test_suite.addTest(unittest.makeSuite(RotateClockwiseSlow)) - test_suite.addTest(unittest.makeSuite(RotateAnticlockwiseFast)) - test_suite.addTest(unittest.makeSuite(RotateAnticlockwiseSlow)) - test_suite.addTest(unittest.makeSuite(SquareClockwise)) - test_suite.addTest(unittest.makeSuite(SquareAnticlockwise)) + #test_suite.addTest(unittest.makeSuite(StraightFast)) + #test_suite.addTest(unittest.makeSuite(StraightModerate)) + #test_suite.addTest(unittest.makeSuite(StraightSlow)) + #test_suite.addTest(unittest.makeSuite(RotateClockwiseFast)) + #test_suite.addTest(unittest.makeSuite(RotateClockwiseSlow)) + #test_suite.addTest(unittest.makeSuite(RotateAnticlockwiseFast)) + #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 From c957a89ec59afa28ee6f8d68cccc1e74ddbd769c Mon Sep 17 00:00:00 2001 From: jbrover Date: Mon, 27 Sep 2021 13:54:06 -0500 Subject: [PATCH 3/5] add logging and full test suite --- movement_unit_tests.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/movement_unit_tests.py b/movement_unit_tests.py index 277d6d1..595abbc 100644 --- a/movement_unit_tests.py +++ b/movement_unit_tests.py @@ -180,15 +180,15 @@ def runTest(self): def get_test_suite(): test_suite = unittest.TestSuite() - #test_suite.addTest(unittest.makeSuite(StraightFast)) - #test_suite.addTest(unittest.makeSuite(StraightModerate)) - #test_suite.addTest(unittest.makeSuite(StraightSlow)) - #test_suite.addTest(unittest.makeSuite(RotateClockwiseFast)) - #test_suite.addTest(unittest.makeSuite(RotateClockwiseSlow)) - #test_suite.addTest(unittest.makeSuite(RotateAnticlockwiseFast)) - #test_suite.addTest(unittest.makeSuite(RotateAnticlockwiseSlow)) - #test_suite.addTest(unittest.makeSuite(SquareClockwise)) - #test_suite.addTest(unittest.makeSuite(SquareAnticlockwise)) + test_suite.addTest(unittest.makeSuite(StraightFast)) + test_suite.addTest(unittest.makeSuite(StraightModerate)) + test_suite.addTest(unittest.makeSuite(StraightSlow)) + test_suite.addTest(unittest.makeSuite(RotateClockwiseFast)) + test_suite.addTest(unittest.makeSuite(RotateClockwiseSlow)) + test_suite.addTest(unittest.makeSuite(RotateAnticlockwiseFast)) + 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 From 868861eb7612ede5d1599873a3f69ea2e7bf83f2 Mon Sep 17 00:00:00 2001 From: jbrover Date: Mon, 27 Sep 2021 14:15:43 -0500 Subject: [PATCH 4/5] fix file open bug --- movement_unit_tests.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/movement_unit_tests.py b/movement_unit_tests.py index 595abbc..b35c87f 100644 --- a/movement_unit_tests.py +++ b/movement_unit_tests.py @@ -3,6 +3,7 @@ import time from test_support.movement import MovementManager import sys +import os @@ -29,6 +30,8 @@ def setUp(self): fh = logging.FileHandler("unittest.log") fh.setLevel(logging.DEBUG) self.logger.addHandler(fh) + with open(os.path.dirname(os.path.realpath(__file__)) + "/unittest.log", mode="a+") as f: + pass def runTest(self): raise ValueError('test not implemented') From 8a826382eaf66872375fd23b09105997d1b18124 Mon Sep 17 00:00:00 2001 From: jbrover Date: Mon, 27 Sep 2021 14:25:12 -0500 Subject: [PATCH 5/5] fix bug with filepath --- movement_unit_tests.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/movement_unit_tests.py b/movement_unit_tests.py index b35c87f..7b00010 100644 --- a/movement_unit_tests.py +++ b/movement_unit_tests.py @@ -27,11 +27,12 @@ def setUp(self): self.movement_manager = MovementManager() self.logger = logging.getLogger("testlog") self.logger.setLevel(logging.DEBUG) - fh = logging.FileHandler("unittest.log") - fh.setLevel(logging.DEBUG) - self.logger.addHandler(fh) 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')