Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
110f9e35
Kaydet (Commit)
110f9e35
authored
Eyl 04, 2015
tarafından
Victor Stinner
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
test_time: add tests on HALF_UP rounding mode for _PyTime_ObjectToTime_t() and
_PyTime_ObjectToTimespec()
üst
1320f08b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
90 additions
and
40 deletions
+90
-40
test_time.py
Lib/test/test_time.py
+90
-40
No files found.
Lib/test/test_time.py
Dosyayı görüntüle @
110f9e35
...
...
@@ -606,24 +606,49 @@ class TestPytime(unittest.TestCase):
@support.cpython_only
def
test_time_t
(
self
):
from
_testcapi
import
pytime_object_to_time_t
# Conversion giving the same result for all rounding methods
for
rnd
in
ALL_ROUNDING_METHODS
:
for
obj
,
seconds
in
(
# int
(
-
1
,
-
1
),
(
0
,
0
),
(
1
,
1
),
# float
(
-
1.0
,
-
1
),
(
1.0
,
1
),
):
with
self
.
subTest
(
obj
=
obj
,
round
=
rnd
,
seconds
=
seconds
):
self
.
assertEqual
(
pytime_object_to_time_t
(
obj
,
rnd
),
seconds
)
# Conversion giving different results depending on the rounding method
FLOOR
=
_PyTime
.
ROUND_FLOOR
CEILING
=
_PyTime
.
ROUND_CEILING
HALF_UP
=
_PyTime
.
ROUND_HALF_UP
for
obj
,
time_t
,
rnd
in
(
# Round towards minus infinity (-inf)
(
0
,
0
,
_PyTime
.
ROUND_FLOOR
),
(
-
1
,
-
1
,
_PyTime
.
ROUND_FLOOR
),
(
-
1.0
,
-
1
,
_PyTime
.
ROUND_FLOOR
),
(
-
1.9
,
-
2
,
_PyTime
.
ROUND_FLOOR
),
(
1.0
,
1
,
_PyTime
.
ROUND_FLOOR
),
(
1.9
,
1
,
_PyTime
.
ROUND_FLOOR
),
# Round towards infinity (+inf)
(
0
,
0
,
_PyTime
.
ROUND_CEILING
),
(
-
1
,
-
1
,
_PyTime
.
ROUND_CEILING
),
(
-
1.0
,
-
1
,
_PyTime
.
ROUND_CEILING
),
(
-
1.9
,
-
1
,
_PyTime
.
ROUND_CEILING
),
(
1.0
,
1
,
_PyTime
.
ROUND_CEILING
),
(
1.9
,
2
,
_PyTime
.
ROUND_CEILING
),
(
-
1.9
,
-
2
,
FLOOR
),
(
-
1.9
,
-
1
,
CEILING
),
(
-
1.9
,
-
2
,
HALF_UP
),
(
1.9
,
1
,
FLOOR
),
(
1.9
,
2
,
CEILING
),
(
1.9
,
2
,
HALF_UP
),
# half up
(
-
0.999
,
-
1
,
HALF_UP
),
(
-
0.510
,
-
1
,
HALF_UP
),
(
-
0.500
,
-
1
,
HALF_UP
),
(
-
0.490
,
0
,
HALF_UP
),
(
0.490
,
0
,
HALF_UP
),
(
0.500
,
1
,
HALF_UP
),
(
0.510
,
1
,
HALF_UP
),
(
0.999
,
1
,
HALF_UP
),
):
self
.
assertEqual
(
pytime_object_to_time_t
(
obj
,
rnd
),
time_t
)
# Test OverflowError
rnd
=
_PyTime
.
ROUND_FLOOR
for
invalid
in
self
.
invalid_values
:
self
.
assertRaises
(
OverflowError
,
...
...
@@ -632,39 +657,64 @@ class TestPytime(unittest.TestCase):
@support.cpython_only
def
test_timespec
(
self
):
from
_testcapi
import
pytime_object_to_timespec
# Conversion giving the same result for all rounding methods
for
rnd
in
ALL_ROUNDING_METHODS
:
for
obj
,
timespec
in
(
# int
(
0
,
(
0
,
0
)),
(
-
1
,
(
-
1
,
0
)),
# float
(
-
1.2
,
(
-
2
,
800000000
)),
(
-
1.0
,
(
-
1
,
0
)),
(
-
1e-9
,
(
-
1
,
999999999
)),
(
1e-9
,
(
0
,
1
)),
(
1.0
,
(
1
,
0
)),
):
with
self
.
subTest
(
obj
=
obj
,
round
=
rnd
,
timespec
=
timespec
):
self
.
assertEqual
(
pytime_object_to_timespec
(
obj
,
rnd
),
timespec
)
# Conversion giving different results depending on the rounding method
FLOOR
=
_PyTime
.
ROUND_FLOOR
CEILING
=
_PyTime
.
ROUND_CEILING
HALF_UP
=
_PyTime
.
ROUND_HALF_UP
for
obj
,
timespec
,
rnd
in
(
# Round towards minus infinity (-inf)
(
0
,
(
0
,
0
),
_PyTime
.
ROUND_FLOOR
),
(
-
1
,
(
-
1
,
0
),
_PyTime
.
ROUND_FLOOR
),
(
-
1.0
,
(
-
1
,
0
),
_PyTime
.
ROUND_FLOOR
),
(
1e-9
,
(
0
,
1
),
_PyTime
.
ROUND_FLOOR
),
(
1e-10
,
(
0
,
0
),
_PyTime
.
ROUND_FLOOR
),
(
-
1e-9
,
(
-
1
,
999999999
),
_PyTime
.
ROUND_FLOOR
),
(
-
1e-10
,
(
-
1
,
999999999
),
_PyTime
.
ROUND_FLOOR
),
(
-
1.2
,
(
-
2
,
800000000
),
_PyTime
.
ROUND_FLOOR
),
(
0.9999999999
,
(
0
,
999999999
),
_PyTime
.
ROUND_FLOOR
),
(
1.1234567890
,
(
1
,
123456789
),
_PyTime
.
ROUND_FLOOR
),
(
1.1234567899
,
(
1
,
123456789
),
_PyTime
.
ROUND_FLOOR
),
(
-
1.1234567890
,
(
-
2
,
876543211
),
_PyTime
.
ROUND_FLOOR
),
(
-
1.1234567891
,
(
-
2
,
876543210
),
_PyTime
.
ROUND_FLOOR
),
(
-
1e-10
,
(
0
,
0
),
CEILING
),
(
-
1e-10
,
(
-
1
,
999999999
),
FLOOR
),
(
-
1e-10
,
(
0
,
0
),
HALF_UP
),
(
1e-10
,
(
0
,
0
),
FLOOR
),
(
1e-10
,
(
0
,
1
),
CEILING
),
(
1e-10
,
(
0
,
0
),
HALF_UP
),
(
0.9999999999
,
(
0
,
999999999
),
FLOOR
),
(
0.9999999999
,
(
1
,
0
),
CEILING
),
(
1.1234567890
,
(
1
,
123456789
),
FLOOR
),
(
1.1234567899
,
(
1
,
123456789
),
FLOOR
),
(
-
1.1234567890
,
(
-
2
,
876543211
),
FLOOR
),
(
-
1.1234567891
,
(
-
2
,
876543210
),
FLOOR
),
# Round towards infinity (+inf)
(
0
,
(
0
,
0
),
_PyTime
.
ROUND_CEILING
),
(
-
1
,
(
-
1
,
0
),
_PyTime
.
ROUND_CEILING
),
(
-
1.0
,
(
-
1
,
0
),
_PyTime
.
ROUND_CEILING
),
(
1e-9
,
(
0
,
1
),
_PyTime
.
ROUND_CEILING
),
(
1e-10
,
(
0
,
1
),
_PyTime
.
ROUND_CEILING
),
(
-
1e-9
,
(
-
1
,
999999999
),
_PyTime
.
ROUND_CEILING
),
(
-
1e-10
,
(
0
,
0
),
_PyTime
.
ROUND_CEILING
),
(
-
1.2
,
(
-
2
,
800000000
),
_PyTime
.
ROUND_CEILING
),
(
0.9999999999
,
(
1
,
0
),
_PyTime
.
ROUND_CEILING
),
(
1.1234567890
,
(
1
,
123456790
),
_PyTime
.
ROUND_CEILING
),
(
1.1234567899
,
(
1
,
123456790
),
_PyTime
.
ROUND_CEILING
),
(
-
1.1234567890
,
(
-
2
,
876543211
),
_PyTime
.
ROUND_CEILING
),
(
-
1.1234567891
,
(
-
2
,
876543211
),
_PyTime
.
ROUND_CEILING
),
(
1.1234567890
,
(
1
,
123456790
),
CEILING
),
(
1.1234567899
,
(
1
,
123456790
),
CEILING
),
(
-
1.1234567890
,
(
-
2
,
876543211
),
CEILING
),
(
-
1.1234567891
,
(
-
2
,
876543211
),
CEILING
),
# half up
(
-
0.6e-9
,
(
-
1
,
999999999
),
HALF_UP
),
# skipped, 0.5e-6 is inexact in base 2
#(-0.5e-9, (-1, 999999999), HALF_UP),
(
-
0.4e-9
,
(
0
,
0
),
HALF_UP
),
(
0.4e-9
,
(
0
,
0
),
HALF_UP
),
(
0.5e-9
,
(
0
,
1
),
HALF_UP
),
(
0.6e-9
,
(
0
,
1
),
HALF_UP
),
):
with
self
.
subTest
(
obj
=
obj
,
round
=
rnd
,
timespec
=
timespec
):
self
.
assertEqual
(
pytime_object_to_timespec
(
obj
,
rnd
),
timespec
)
# Test OverflowError
rnd
=
_PyTime
.
ROUND_FLOOR
for
invalid
in
self
.
invalid_values
:
self
.
assertRaises
(
OverflowError
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment