Run yapf on Spline UI
Change-Id: Id09023a4e651fd041ea5acc9814e441780307336
diff --git a/frc971/control_loops/python/polytope_test.py b/frc971/control_loops/python/polytope_test.py
index 68401c2..e5b8d5f 100755
--- a/frc971/control_loops/python/polytope_test.py
+++ b/frc971/control_loops/python/polytope_test.py
@@ -8,21 +8,17 @@
__author__ = 'Austin Schuh (austin.linux@gmail.com)'
+
def MakePoint(*args):
"""Makes a point from a set of arguments."""
return numpy.matrix([[arg] for arg in args])
+
class TestHPolytope(unittest.TestCase):
def setUp(self):
"""Builds a simple box polytope."""
- self.H = numpy.matrix([[1, 0],
- [-1, 0],
- [0, 1],
- [0, -1]])
- self.k = numpy.matrix([[12],
- [12],
- [12],
- [12]])
+ self.H = numpy.matrix([[1, 0], [-1, 0], [0, 1], [0, -1]])
+ self.k = numpy.matrix([[12], [12], [12], [12]])
self.p = polytope.HPolytope(self.H, self.k)
def test_Hk(self):
@@ -33,31 +29,35 @@
def test_IsInside(self):
"""Tests IsInside for various points."""
inside_points = [
- MakePoint(0, 0),
- MakePoint(6, 6),
- MakePoint(12, 6),
- MakePoint(-6, 10)]
+ MakePoint(0, 0),
+ MakePoint(6, 6),
+ MakePoint(12, 6),
+ MakePoint(-6, 10)
+ ]
outside_points = [
- MakePoint(14, 0),
- MakePoint(-14, 0),
- MakePoint(0, 14),
- MakePoint(0, -14),
- MakePoint(14, -14)]
+ MakePoint(14, 0),
+ MakePoint(-14, 0),
+ MakePoint(0, 14),
+ MakePoint(0, -14),
+ MakePoint(14, -14)
+ ]
for inside_point in inside_points:
- self.assertTrue(self.p.IsInside(inside_point),
- msg='Point is' + str(inside_point))
+ self.assertTrue(
+ self.p.IsInside(inside_point),
+ msg='Point is' + str(inside_point))
for outside_point in outside_points:
- self.assertFalse(self.p.IsInside(outside_point),
- msg='Point is' + str(outside_point))
+ self.assertFalse(
+ self.p.IsInside(outside_point),
+ msg='Point is' + str(outside_point))
def AreVertices(self, p, vertices):
"""Checks that all the vertices are on corners of the set."""
for i in range(vertices.shape[0]):
# Check that all the vertices have the correct number of active
# constraints.
- lmda = p.H * vertices[i,:].T - p.k
+ lmda = p.H * vertices[i, :].T - p.k
num_active_constraints = 0
for j in range(lmda.shape[0]):
# Verify that the constraints are either active, or not violated.
@@ -80,54 +80,39 @@
found_points.add(actual_index)
break
- self.assertEqual(len(found_points), actual.shape[0],
+ self.assertEqual(
+ len(found_points),
+ actual.shape[0],
msg="Expected:\n" + str(expected) + "\nActual:\n" + str(actual))
def test_Skewed_Nonsym_Vertices(self):
"""Tests the vertices of a severely skewed space."""
- self.H = numpy.matrix([[10, -1],
- [-1, -1],
- [-1, 10],
- [10, 10]])
- self.k = numpy.matrix([[2],
- [2],
- [2],
- [2]])
+ self.H = numpy.matrix([[10, -1], [-1, -1], [-1, 10], [10, 10]])
+ self.k = numpy.matrix([[2], [2], [2], [2]])
self.p = polytope.HPolytope(self.H, self.k)
vertices = self.p.Vertices()
self.AreVertices(self.p, vertices)
self.HasSamePoints(
- numpy.matrix([[0., 0.2],
- [0.2, 0.],
- [-2., 0.],
- [0., -2.]]),
+ numpy.matrix([[0., 0.2], [0.2, 0.], [-2., 0.], [0., -2.]]),
vertices)
def test_Vertices_Nonsym(self):
"""Tests the vertices of a nonsymetric space."""
- self.k = numpy.matrix([[6],
- [12],
- [2],
- [10]])
+ self.k = numpy.matrix([[6], [12], [2], [10]])
self.p = polytope.HPolytope(self.H, self.k)
vertices = self.p.Vertices()
self.AreVertices(self.p, vertices)
self.HasSamePoints(
- numpy.matrix([[6., 2.],
- [6., -10.],
- [-12., -10.],
- [-12., 2.]]),
+ numpy.matrix([[6., 2.], [6., -10.], [-12., -10.], [-12., 2.]]),
vertices)
def test_Vertices(self):
"""Tests the vertices of a nonsymetric space."""
- self.HasSamePoints(self.p.Vertices(),
- numpy.matrix([[12., 12.],
- [12., -12.],
- [-12., -12.],
- [-12., 12.]]))
+ self.HasSamePoints(
+ self.p.Vertices(),
+ numpy.matrix([[12., 12.], [12., -12.], [-12., -12.], [-12., 12.]]))
def test_concat(self):
"""Tests that the concat function works for simple inputs."""
@@ -138,11 +123,11 @@
def test_str(self):
"""Verifies that the str method works for the provided p."""
- self.assertEqual('[[ 1 0] [[12] \n'
- ' [-1 0] [[x0] <= [12] \n'
- ' [ 0 1] [x1]] [12] \n'
- ' [ 0 -1]] [12]] ',
- str(self.p))
+ self.assertEqual(
+ '[[ 1 0] [[12] \n'
+ ' [-1 0] [[x0] <= [12] \n'
+ ' [ 0 1] [x1]] [12] \n'
+ ' [ 0 -1]] [12]] ', str(self.p))
def MakePWithDims(self, num_constraints, num_dims):
"""Makes a zeroed out polytope with the correct size."""
@@ -153,40 +138,40 @@
def test_few_constraints_odd_constraint_even_dims_str(self):
"""Tests printing out the set with odd constraints and even dimensions."""
self.MakePWithDims(num_constraints=5, num_dims=2)
- self.assertEqual('[[0. 0.] [[0.] \n'
- ' [0. 0.] [[x0] [0.] \n'
- ' [0. 0.] [x1]] <= [0.] \n'
- ' [0. 0.] [0.] \n'
- ' [0. 0.]] [0.]] ',
- str(self.p))
+ self.assertEqual(
+ '[[0. 0.] [[0.] \n'
+ ' [0. 0.] [[x0] [0.] \n'
+ ' [0. 0.] [x1]] <= [0.] \n'
+ ' [0. 0.] [0.] \n'
+ ' [0. 0.]] [0.]] ', str(self.p))
def test_few_constraints_odd_constraint_small_dims_str(self):
"""Tests printing out the set with odd constraints and odd dimensions."""
self.MakePWithDims(num_constraints=5, num_dims=1)
- self.assertEqual('[[0.] [[0.] \n'
- ' [0.] [0.] \n'
- ' [0.] [[x0]] <= [0.] \n'
- ' [0.] [0.] \n'
- ' [0.]] [0.]] ',
- str(self.p))
+ self.assertEqual(
+ '[[0.] [[0.] \n'
+ ' [0.] [0.] \n'
+ ' [0.] [[x0]] <= [0.] \n'
+ ' [0.] [0.] \n'
+ ' [0.]] [0.]] ', str(self.p))
def test_few_constraints_odd_constraint_odd_dims_str(self):
"""Tests printing out the set with odd constraints and odd dimensions."""
self.MakePWithDims(num_constraints=5, num_dims=3)
- self.assertEqual('[[0. 0. 0.] [[0.] \n'
- ' [0. 0. 0.] [[x0] [0.] \n'
- ' [0. 0. 0.] [x1] <= [0.] \n'
- ' [0. 0. 0.] [x2]] [0.] \n'
- ' [0. 0. 0.]] [0.]] ',
- str(self.p))
+ self.assertEqual(
+ '[[0. 0. 0.] [[0.] \n'
+ ' [0. 0. 0.] [[x0] [0.] \n'
+ ' [0. 0. 0.] [x1] <= [0.] \n'
+ ' [0. 0. 0.] [x2]] [0.] \n'
+ ' [0. 0. 0.]] [0.]] ', str(self.p))
def test_many_constraints_even_constraint_odd_dims_str(self):
"""Tests printing out the set with even constraints and odd dimensions."""
self.MakePWithDims(num_constraints=2, num_dims=3)
- self.assertEqual('[[0. 0. 0.] [[x0] [[0.] \n'
- ' [0. 0. 0.]] [x1] <= [0.]] \n'
- ' [x2]] ',
- str(self.p))
+ self.assertEqual(
+ '[[0. 0. 0.] [[x0] [[0.] \n'
+ ' [0. 0. 0.]] [x1] <= [0.]] \n'
+ ' [x2]] ', str(self.p))
if __name__ == '__main__':