Skip to content

Commit

Permalink
Refactor test_assert_almost_equal to use unified float_type alias
Browse files Browse the repository at this point in the history
Signed-off-by: Leandro Augusto Lacerda Campos <15185896+leandrolcampos@users.noreply.github.com>
  • Loading branch information
leandrolcampos committed Apr 24, 2024
1 parent 43be78f commit 031ccbd
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions stdlib/test/testing/test_assertion.mojo
Expand Up @@ -57,8 +57,9 @@ def test_assert_equal_with_simd():


def test_assert_almost_equal():
alias _inf = inf[DType.float32]()
alias _nan = nan[DType.float32]()
alias float_type = DType.float32
alias _inf = inf[float_type]()
alias _nan = nan[float_type]()

@parameter
def _should_succeed[
Expand All @@ -79,21 +80,21 @@ def test_assert_almost_equal():
_should_succeed[DType.bool, 1](True, True)
_should_succeed(SIMD[DType.int32, 2](0, 1), SIMD[DType.int32, 2](0, 1))
_should_succeed(
SIMD[DType.float32, 2](-_inf, _inf), SIMD[DType.float32, 2](-_inf, _inf)
SIMD[float_type, 2](-_inf, _inf), SIMD[float_type, 2](-_inf, _inf)
)
_should_succeed(
SIMD[DType.float32, 2](-_nan, _nan),
SIMD[DType.float32, 2](-_nan, _nan),
SIMD[float_type, 2](-_nan, _nan),
SIMD[float_type, 2](-_nan, _nan),
equal_nan=True,
)
_should_succeed(
SIMD[DType.float32, 2](1.0, -1.1),
SIMD[DType.float32, 2](1.1, -1.0),
SIMD[float_type, 2](1.0, -1.1),
SIMD[float_type, 2](1.1, -1.0),
atol=0.11,
)
_should_succeed(
SIMD[DType.float32, 2](1.0, -1.1),
SIMD[DType.float32, 2](1.1, -1.0),
SIMD[float_type, 2](1.0, -1.1),
SIMD[float_type, 2](1.1, -1.0),
rtol=0.10,
)

Expand All @@ -119,38 +120,38 @@ def test_assert_almost_equal():
SIMD[DType.int32, 2](0, 1), SIMD[DType.int32, 2](0, -1), atol=5.0
)
_should_fail(
SIMD[DType.float32, 2](-_inf, 0.0),
SIMD[DType.float32, 2](_inf, 0.0),
SIMD[float_type, 2](-_inf, 0.0),
SIMD[float_type, 2](_inf, 0.0),
rtol=0.1,
)
_should_fail(
SIMD[DType.float32, 2](_inf, 0.0),
SIMD[DType.float32, 2](0.0, 0.0),
SIMD[float_type, 2](_inf, 0.0),
SIMD[float_type, 2](0.0, 0.0),
rtol=0.1,
)
_should_fail(
SIMD[DType.float32, 2](_nan, 0.0),
SIMD[DType.float32, 2](_nan, 0.0),
SIMD[float_type, 2](_nan, 0.0),
SIMD[float_type, 2](_nan, 0.0),
equal_nan=False,
)
_should_fail(
SIMD[DType.float32, 2](_nan, 0.0),
SIMD[DType.float32, 2](0.0, 0.0),
SIMD[float_type, 2](_nan, 0.0),
SIMD[float_type, 2](0.0, 0.0),
equal_nan=False,
)
_should_fail(
SIMD[DType.float32, 2](_nan, 0.0),
SIMD[DType.float32, 2](0.0, 0.0),
SIMD[float_type, 2](_nan, 0.0),
SIMD[float_type, 2](0.0, 0.0),
equal_nan=True,
)
_should_fail(
SIMD[DType.float32, 2](1.0, 0.0),
SIMD[DType.float32, 2](1.1, 0.0),
SIMD[float_type, 2](1.0, 0.0),
SIMD[float_type, 2](1.1, 0.0),
atol=0.05,
)
_should_fail(
SIMD[DType.float32, 2](-1.0, 0.0),
SIMD[DType.float32, 2](-1.1, 0.0),
SIMD[float_type, 2](-1.0, 0.0),
SIMD[float_type, 2](-1.1, 0.0),
rtol=0.05,
)

Expand Down

0 comments on commit 031ccbd

Please sign in to comment.