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)
format
std::string format(const std::string &str, const std::vector< std::string > &find, const std::vector< std::string > &replace)
Definition: openglsupport.cpp:226
gtsam::utils.test_case.GtsamTestCase.gtsamAssertEquals
def gtsamAssertEquals(self, actual, expected, tol=1e-9)
Definition: test_case.py:18
isinstance
bool isinstance(handle obj)
Definition: pytypes.h:842
gtsam::utils.test_case.GtsamTestCase.assertEqualityOnPickleRoundtrip
None assertEqualityOnPickleRoundtrip(self, object obj, tol=1e-9)
Definition: test_case.py:34
gtsam::utils.test_case.GtsamTestCase
Definition: test_case.py:15


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:07:05