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
1dabdb25
Kaydet (Commit)
1dabdb25
authored
Şub 02, 2008
tarafından
Mark Dickinson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Make the Rational constructor accept '3.' and '.2' as well as '3.2'.
üst
5a6cfee6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
3 deletions
+18
-3
rational.py
Lib/rational.py
+12
-3
test_rational.py
Lib/test/test_rational.py
+6
-0
No files found.
Lib/rational.py
Dosyayı görüntüle @
1dabdb25
...
@@ -25,9 +25,18 @@ def gcd(a, b):
...
@@ -25,9 +25,18 @@ def gcd(a, b):
return
a
return
a
_RATIONAL_FORMAT
=
re
.
compile
(
_RATIONAL_FORMAT
=
re
.
compile
(
r"""
r'^\s*(?P<sign>[-+]?)(?P<num>\d+)'
\A\s* # optional whitespace at the start, then
r'(?:/(?P<denom>\d+)|\.(?P<decimal>\d+))?\s*$'
)
(?P<sign>[-+]?) # an optional sign, then
(?=\d|\.\d) # lookahead for digit or .digit
(?P<num>\d*) # numerator (possibly empty)
(?: # followed by an optional
/(?P<denom>\d+) # / and denominator
| # or
\.(?P<decimal>\d*) # decimal point and fractional part
)?
\s*\Z # and optional whitespace to finish
"""
,
re
.
VERBOSE
)
class
Rational
(
RationalAbc
):
class
Rational
(
RationalAbc
):
...
...
Lib/test/test_rational.py
Dosyayı görüntüle @
1dabdb25
...
@@ -78,6 +78,8 @@ class RationalTest(unittest.TestCase):
...
@@ -78,6 +78,8 @@ class RationalTest(unittest.TestCase):
self
.
assertEquals
((
16
,
5
),
_components
(
R
(
" 3.2 "
)))
self
.
assertEquals
((
16
,
5
),
_components
(
R
(
" 3.2 "
)))
self
.
assertEquals
((
-
16
,
5
),
_components
(
R
(
u" -3.2 "
)))
self
.
assertEquals
((
-
16
,
5
),
_components
(
R
(
u" -3.2 "
)))
self
.
assertEquals
((
-
3
,
1
),
_components
(
R
(
u" -3. "
)))
self
.
assertEquals
((
3
,
5
),
_components
(
R
(
u" .6 "
)))
self
.
assertRaisesMessage
(
self
.
assertRaisesMessage
(
...
@@ -113,6 +115,10 @@ class RationalTest(unittest.TestCase):
...
@@ -113,6 +115,10 @@ class RationalTest(unittest.TestCase):
# Don't accept combinations of decimals and rationals.
# Don't accept combinations of decimals and rationals.
ValueError
,
"Invalid literal for Rational: 3.2/7"
,
ValueError
,
"Invalid literal for Rational: 3.2/7"
,
R
,
"3.2/7"
)
R
,
"3.2/7"
)
self
.
assertRaisesMessage
(
# Allow 3. and .3, but not .
ValueError
,
"Invalid literal for Rational: ."
,
R
,
"."
)
def
testImmutable
(
self
):
def
testImmutable
(
self
):
r
=
R
(
7
,
3
)
r
=
R
(
7
,
3
)
...
...
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