11import math
2+ from typing import Any , SupportsFloat
23
34import pytest
45
78from .typing import Array
89
910
11+ def assert_scalar_float (name : str , c : Any ):
12+ assert isinstance (c , SupportsFloat ), f"{ name } ={ c !r} does not look like a float"
13+
14+
1015def assert_0d_float (name : str , x : Array ):
1116 assert dh .is_float_dtype (
1217 x .dtype
@@ -17,16 +22,18 @@ def assert_0d_float(name: str, x: Array):
1722def test_irrational (name , n ):
1823 assert hasattr (xp , name )
1924 c = getattr (xp , name )
25+ assert_scalar_float (name , c )
2026 floor = math .floor (n )
21- assert c > floor , f"xp.{ name } ={ c } <= { floor } "
27+ assert c > floor , f"xp.{ name } ={ c !r } <= { floor } "
2228 ceil = math .ceil (n )
23- assert c < ceil , f"xp.{ name } ={ c } >= { ceil } "
29+ assert c < ceil , f"xp.{ name } ={ c !r } >= { ceil } "
2430 x = xp .asarray (c )
2531 assert_0d_float ("name" , x )
2632
2733
2834def test_inf ():
2935 assert hasattr (xp , "inf" )
36+ assert_scalar_float ("inf" , xp .inf )
3037 assert math .isinf (xp .inf )
3138 assert xp .inf > 0 , "xp.inf not greater than 0"
3239 x = xp .asarray (xp .inf )
@@ -36,6 +43,7 @@ def test_inf():
3643
3744def test_nan ():
3845 assert hasattr (xp , "nan" )
46+ assert_scalar_float ("nan" , xp .nan )
3947 assert math .isnan (xp .nan )
4048 assert xp .nan != xp .nan , "xp.nan should not have equality with itself"
4149 x = xp .asarray (xp .nan )
0 commit comments