Make demo tests less sensitive to tiny floating point errors.

More work getting MacOS build process to work.
Avoid excessive number of floating point digits of
output in the demo tests, so that insignificant
floating point variations don't cause unit test failures.
This commit is contained in:
Don Cross
2022-01-07 20:19:23 -05:00
parent cb4c9a6549
commit 753554db67
11 changed files with 52 additions and 23 deletions

View File

@@ -829,6 +829,11 @@ The vector also includes a time stamp.
Returns the length of the vector in AU.
<a name="Vector.format"></a>
### Vector.format(self, coord_format)
Returns a custom format string representation of the vector.
---
<a name="enumerations"></a>

View File

@@ -170,6 +170,11 @@ class Vector:
def __sub__(self, other):
return Vector(self.x - other.x, self.y - other.y, self.z - other.z, self.t)
def format(self, coord_format):
"""Returns a custom format string representation of the vector."""
layout = '({:' + coord_format + '}, {:' + coord_format + '}, {:' + coord_format + '}, {})'
return layout.format(self.x, self.y, self.z, str(self.t))
class StateVector:
"""A combination of a position vector, a velocity vector, and a time.
@@ -758,10 +763,10 @@ class Observer:
def __str__(self):
text = '('
text += 'S' if (self.latitude < 0) else 'N'
text += '{}, '.format(abs(self.latitude))
text += '{:0.8f}, '.format(abs(self.latitude))
text += 'W' if (self.longitude < 0) else 'E'
text += '{}, '.format(abs(self.longitude))
text += '{}m'.format(self.height)
text += '{:0.8f}, '.format(abs(self.longitude))
text += '{:0.3f}m'.format(self.height)
text += ')'
return text