forked from Rust-related/RustPython
Add tests for round functions
This commit is contained in:
@@ -1,4 +1,21 @@
|
||||
assert round(0.0, 0) == 0.0
|
||||
from testutils import assertRaises
|
||||
|
||||
assert round(0) == 0
|
||||
assert isinstance(round(0), int)
|
||||
assert round(0.0) == 0
|
||||
assert isinstance(round(0.0), int)
|
||||
|
||||
assert round(0, None) == 0
|
||||
assert isinstance(round(0, None), int)
|
||||
assert round(0.0, None) == 0
|
||||
assert isinstance(round(0, None), int)
|
||||
|
||||
assert round(0, 0) == 0
|
||||
assert isinstance(round(0, 0), int)
|
||||
assert round(0.0, 0) == 0.0 # Cannot check the type
|
||||
assert isinstance(round(0.0, 0), float)
|
||||
|
||||
with assertRaises(TypeError):
|
||||
round(0, 0.0)
|
||||
round(0, 0.0)
|
||||
with assertRaises(TypeError):
|
||||
round(0.0, 0.0)
|
||||
|
||||
@@ -163,6 +163,8 @@ assert isinstance(0.5.__round__(None), int)
|
||||
assert isinstance(1.5.__round__(None), int)
|
||||
assert 0.5.__round__(None) == 0
|
||||
assert 1.5.__round__(None) == 2
|
||||
assert_raises(TypeError, lambda: 0.5.__round__(0.0))
|
||||
assert_raises(TypeError, lambda: 1.5.__round__(0.0))
|
||||
assert_raises(OverflowError, float('inf').__round__)
|
||||
assert_raises(ValueError, float('nan').__round__)
|
||||
|
||||
|
||||
@@ -139,3 +139,16 @@ class F(float):
|
||||
return 3
|
||||
|
||||
assert int(F(1.2)) == 3
|
||||
|
||||
assert isinstance((0).__round__(), int)
|
||||
assert isinstance((1).__round__(), int)
|
||||
assert (0).__round__() == 0
|
||||
assert (1).__round__() == 1
|
||||
assert isinstance((0).__round__(0), int)
|
||||
assert isinstance((1).__round__(0), int)
|
||||
assert (0).__round__(0) == 0
|
||||
assert (1).__round__(0) == 1
|
||||
assert_raises(TypeError, lambda: (0).__round__(None))
|
||||
assert_raises(TypeError, lambda: (1).__round__(None))
|
||||
assert_raises(TypeError, lambda: (0).__round__(0.0))
|
||||
assert_raises(TypeError, lambda: (1).__round__(0.0))
|
||||
Reference in New Issue
Block a user