test_case.py
Go to the documentation of this file.
1 """
2 GTSAM Copyright 2010-2019, Georgia Tech Research Corporation,
3 Atlanta, Georgia 30332-0415
4 All Rights Reserved
5 
6 See LICENSE for the license information
7 
8 TestCase class with GTSAM assert utils.
9 Author: Frank Dellaert
10 """
11 import pickle
12 import unittest
13 
14 
15 class GtsamTestCase(unittest.TestCase):
16  """TestCase class with GTSAM assert utils."""
17 
18  def gtsamAssertEquals(self, actual, expected, tol=1e-9):
19  """ AssertEqual function that prints out actual and expected if not equal.
20  Usage:
21  self.gtsamAssertEqual(actual,expected)
22  Keyword Arguments:
23  tol {float} -- tolerance passed to 'equals', default 1e-9
24  """
25  import numpy
26  if isinstance(expected, numpy.ndarray):
27  equal = numpy.allclose(actual, expected, atol=tol)
28  else:
29  equal = actual.equals(expected, tol)
30  if not equal:
31  raise self.failureException(
32  "Values are not equal:\n{}!={}".format(actual, expected))
33 
34  def assertEqualityOnPickleRoundtrip(self, obj: object, tol=1e-9) -> None:
35  """ Performs a round-trip using pickle and asserts equality.
36 
37  Usage:
38  self.assertEqualityOnPickleRoundtrip(obj)
39  Keyword Arguments:
40  tol {float} -- tolerance passed to 'equals', default 1e-9
41  """
42  roundTripObj = pickle.loads(pickle.dumps(obj))
43  self.gtsamAssertEquals(roundTripObj, obj)
def gtsamAssertEquals(self, actual, expected, tol=1e-9)
Definition: test_case.py:18
bool isinstance(handle obj)
Definition: pytypes.h:384


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:46:03