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 from copy import deepcopy
14 
15 
16 class GtsamTestCase(unittest.TestCase):
17  """TestCase class with GTSAM assert utils."""
18 
19  def gtsamAssertEquals(self, actual, expected, tol=1e-9):
20  """ AssertEqual function that prints out actual and expected if not equal.
21  Usage:
22  self.gtsamAssertEqual(actual,expected)
23  Keyword Arguments:
24  tol {float} -- tolerance passed to 'equals', default 1e-9
25  """
26  import numpy
27  if isinstance(expected, numpy.ndarray):
28  equal = numpy.allclose(actual, expected, atol=tol)
29  else:
30  equal = actual.equals(expected, tol)
31  if not equal:
32  raise self.failureException("Values are not equal:\n{}!={}".format(
33  actual, expected))
34 
35  def assertEqualityOnPickleRoundtrip(self, obj: object, tol=1e-9) -> None:
36  """ Performs a round-trip using pickle and asserts equality.
37 
38  Usage:
39  self.assertEqualityOnPickleRoundtrip(obj)
40  Keyword Arguments:
41  tol {float} -- tolerance passed to 'equals', default 1e-9
42  """
43  roundTripObj = pickle.loads(pickle.dumps(obj))
44  self.gtsamAssertEquals(roundTripObj, obj)
45 
46  def assertDeepCopyEquality(self, obj):
47  """Perform assertion by checking if a
48  deep copied version of `obj` is equal to itself.
49 
50  Args:
51  obj: The object to check is deep-copyable.
52  """
53  # If deep copy failed, then this will throw an error
54  obj2 = deepcopy(obj)
55  self.gtsamAssertEquals(obj, obj2)
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:19
isinstance
bool isinstance(handle obj)
Definition: pytypes.h:842
gtsam::utils.test_case.GtsamTestCase.assertDeepCopyEquality
def assertDeepCopyEquality(self, obj)
Definition: test_case.py:46
gtsam::utils.test_case.GtsamTestCase.assertEqualityOnPickleRoundtrip
None assertEqualityOnPickleRoundtrip(self, object obj, tol=1e-9)
Definition: test_case.py:35
gtsam::utils.test_case.GtsamTestCase
Definition: test_case.py:16


gtsam
Author(s):
autogenerated on Sat Jan 4 2025 04:05:39