MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_microsecond_rounding

Method test_microsecond_rounding

Lib/test/datetimetester.py:862–893  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

860 self.assertRaises(OverflowError, day.__mul__, -INF)
861
862 def test_microsecond_rounding(self):
863 td = timedelta
864 eq = self.assertEqual
865
866 # Single-field rounding.
867 eq(td(milliseconds=0.4/1000), td(0)) # rounds to 0
868 eq(td(milliseconds=-0.4/1000), td(0)) # rounds to 0
869 eq(td(milliseconds=0.5/1000), td(microseconds=0))
870 eq(td(milliseconds=-0.5/1000), td(microseconds=-0))
871 eq(td(milliseconds=0.6/1000), td(microseconds=1))
872 eq(td(milliseconds=-0.6/1000), td(microseconds=-1))
873 eq(td(milliseconds=1.5/1000), td(microseconds=2))
874 eq(td(milliseconds=-1.5/1000), td(microseconds=-2))
875 eq(td(seconds=0.5/10**6), td(microseconds=0))
876 eq(td(seconds=-0.5/10**6), td(microseconds=-0))
877 eq(td(seconds=1/2**7), td(microseconds=7812))
878 eq(td(seconds=-1/2**7), td(microseconds=-7812))
879
880 # Rounding due to contributions from more than one field.
881 us_per_hour = 3600e6
882 us_per_day = us_per_hour * 24
883 eq(td(days=.4/us_per_day), td(0))
884 eq(td(hours=.2/us_per_hour), td(0))
885 eq(td(days=.4/us_per_day, hours=.2/us_per_hour), td(microseconds=1))
886
887 eq(td(days=-.4/us_per_day), td(0))
888 eq(td(hours=-.2/us_per_hour), td(0))
889 eq(td(days=-.4/us_per_day, hours=-.2/us_per_hour), td(microseconds=-1))
890
891 # Test for a patch in Issue 8860
892 eq(td(microseconds=0.5), 0.5*td(microseconds=1.0))
893 eq(td(microseconds=0.5)//td.resolution, 0.5*td.resolution//td.resolution)
894
895 def test_massive_normalization(self):
896 td = timedelta(microseconds=-1)

Callers

nothing calls this directly

Calls 1

eqFunction · 0.90

Tested by

no test coverage detected