Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test dassert_lt() #1098

Merged
merged 8 commits into from
Jul 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions helpers/test/test_dbg.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,83 @@ def test4(self) -> None:
# #############################################################################
jayati1397 marked this conversation as resolved.
Show resolved Hide resolved


class Test_dassert_lt(hunitest.TestCase):
def test1(self) -> None:
"""
Test that the function doesn't raise an exception if first value is
less than second value.
"""
val1 = 1
val2 = 2
hdbg.dassert_lt(val1, val2)

def test2(self) -> None:
"""
Test that the function raises an exception if first value is equal to
second value.
"""
# Set inputs.
val1 = 2
val2 = 2
# Run.
with self.assertRaises(AssertionError) as cm:
hdbg.dassert_lt(val1, val2)
act = str(cm.exception)
exp = """
* Failed assertion *
2 < 2
"""
# Check.
self.assert_equal(act, exp, fuzzy_match=True)
jayati1397 marked this conversation as resolved.
Show resolved Hide resolved

def test3(self) -> None:
"""
Test that the function raises an exception if first value is greater
than second value.
"""
# Set inputs.
val1 = 3
val2 = 2
# Run.
with self.assertRaises(AssertionError) as cm:
hdbg.dassert_lt(val1, val2)
act = str(cm.exception)
exp = """
* Failed assertion *
3 < 2
"""
# Check.
self.assert_equal(act, exp, fuzzy_match=True)

def test4(self) -> None:
"""
Test that the function doesn't raise an exception when we pass string
inputs.
"""
val1 = "a"
val2 = "b"
hdbg.dassert_lt(val1, val2)

def test5(self) -> None:
"""
Test that the function raises an exception where first value is greater
than second value with floats.
"""
# Set inputs.
val1 = 2.0
val2 = 1.0
# Run.
with self.assertRaises(AssertionError) as cm:
hdbg.dassert_lt(val1, val2)
act = str(cm.exception)
exp = """
* Failed assertion *
2.0 < 1.0
"""
# Check.
self.assert_equal(act, exp, fuzzy_match=True)


class Test_dassert_is_integer(hunitest.TestCase):
def test1(self) -> None:
"""
Expand All @@ -740,7 +817,9 @@ def test3(self) -> None:
Test that the function raises an exception for float values that do not
represent an integer.
"""
# Set inputs.
val = 5.5
# Run.
with self.assertRaises(AssertionError) as cm:
hdbg.dassert_is_integer(val)
act = str(cm.exception)
Expand All @@ -756,7 +835,9 @@ def test4(self) -> None:
Test that the function raises an exception for non-integer and non-
float types.
"""
# Set inputs.
val = "5"
# Run.
with self.assertRaises(AssertionError) as cm:
hdbg.dassert_is_integer(val)
act = str(cm.exception)
Expand Down
Loading