SreeramaYeshwanthGowd commented on code in PR #39443:
URL: https://github.com/apache/beam/pull/39443#discussion_r3638432021


##########
sdks/python/apache_beam/testing/util_test.py:
##########
@@ -93,6 +94,50 @@ def test_assert_with_custom_comparator(self):
           p | Create([1, 2, 3]),
           equal_to(['1', '2', '3'], equals_fn=lambda e, a: int(e) == int(a)))
 
+  def test_equal_to_approx(self):
+    with TestPipeline() as p:
+      assert_that(
+          p | Create([1.0, 2.0, 3.0]),

Review Comment:
   Done, added an int to the input.



##########
sdks/python/apache_beam/testing/util_test.py:
##########
@@ -93,6 +94,50 @@ def test_assert_with_custom_comparator(self):
           p | Create([1, 2, 3]),
           equal_to(['1', '2', '3'], equals_fn=lambda e, a: int(e) == int(a)))
 
+  def test_equal_to_approx(self):
+    with TestPipeline() as p:
+      assert_that(
+          p | Create([1.0, 2.0, 3.0]),
+          equal_to_approx([3.0000000001, 2.0, 1.0]))
+
+  def test_equal_to_approx_nested(self):
+    with TestPipeline() as p:
+      assert_that(
+          p | Create([('a', 1.0), ('b', 2.0)]),
+          equal_to_approx([('b', 2.0000000001), ('a', 1.0)]))

Review Comment:
   Done.



##########
sdks/python/apache_beam/testing/util.py:
##########
@@ -231,6 +234,33 @@ def row_namedtuple_equals_fn(expected, actual, 
fallback_equals_fn=None):
   return True
 
 
+def equal_to_approx(expected, rel_tol=1e-09, abs_tol=0.0):
+  """Matcher used by assert_that that compares numeric elements approximately.

Review Comment:
   Done, added the Args and Example sections. Thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to