Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
0639f598
Commit
0639f598
authored
Sep 18, 2001
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a similar test for rich comparisons.
parent
59b68656
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
1 deletion
+67
-1
Lib/test/test_descr.py
Lib/test/test_descr.py
+67
-1
No files found.
Lib/test/test_descr.py
View file @
0639f598
...
...
@@ -1833,7 +1833,9 @@ def str_subclass_as_dict_key():
def
classic_comparisons
():
if
verbose
:
print
"Testing classic comparisons..."
for
base
in
(
int
,
object
):
class
classic
:
pass
for
base
in
(
classic
,
int
,
object
):
if
verbose
:
print
" (base = %s)"
%
base
class
C
(
base
):
def
__init__
(
self
,
value
):
...
...
@@ -1858,6 +1860,69 @@ def classic_comparisons():
verify
(
cmp
(
c
[
x
],
y
)
==
cmp
(
x
,
y
),
"x=%d, y=%d"
%
(
x
,
y
))
verify
(
cmp
(
x
,
c
[
y
])
==
cmp
(
x
,
y
),
"x=%d, y=%d"
%
(
x
,
y
))
def
rich_comparisons
():
if
verbose
:
print
"Testing rich comparisons..."
class
classic
:
pass
for
base
in
(
classic
,
int
,
object
,
list
):
if
verbose
:
print
" (base = %s)"
%
base
class
C
(
base
):
def
__init__
(
self
,
value
):
self
.
value
=
int
(
value
)
def
__cmp__
(
self
,
other
):
raise
TestFailed
,
"shouldn't call __cmp__"
def
__eq__
(
self
,
other
):
if
isinstance
(
other
,
C
):
return
self
.
value
==
other
.
value
if
isinstance
(
other
,
int
)
or
isinstance
(
other
,
long
):
return
self
.
value
==
other
return
NotImplemented
def
__ne__
(
self
,
other
):
if
isinstance
(
other
,
C
):
return
self
.
value
!=
other
.
value
if
isinstance
(
other
,
int
)
or
isinstance
(
other
,
long
):
return
self
.
value
!=
other
return
NotImplemented
def
__lt__
(
self
,
other
):
if
isinstance
(
other
,
C
):
return
self
.
value
<
other
.
value
if
isinstance
(
other
,
int
)
or
isinstance
(
other
,
long
):
return
self
.
value
<
other
return
NotImplemented
def
__le__
(
self
,
other
):
if
isinstance
(
other
,
C
):
return
self
.
value
<=
other
.
value
if
isinstance
(
other
,
int
)
or
isinstance
(
other
,
long
):
return
self
.
value
<=
other
return
NotImplemented
def
__gt__
(
self
,
other
):
if
isinstance
(
other
,
C
):
return
self
.
value
>
other
.
value
if
isinstance
(
other
,
int
)
or
isinstance
(
other
,
long
):
return
self
.
value
>
other
return
NotImplemented
def
__ge__
(
self
,
other
):
if
isinstance
(
other
,
C
):
return
self
.
value
>=
other
.
value
if
isinstance
(
other
,
int
)
or
isinstance
(
other
,
long
):
return
self
.
value
>=
other
return
NotImplemented
c1
=
C
(
1
)
c2
=
C
(
2
)
c3
=
C
(
3
)
verify
(
c1
==
1
)
c
=
{
1
:
c1
,
2
:
c2
,
3
:
c3
}
for
x
in
1
,
2
,
3
:
for
y
in
1
,
2
,
3
:
for
op
in
"<"
,
"<="
,
"=="
,
"!="
,
">"
,
">="
:
verify
(
eval
(
"c[x] %s c[y]"
%
op
)
==
eval
(
"x %s y"
%
op
),
"x=%d, y=%d"
%
(
x
,
y
))
verify
(
eval
(
"c[x] %s y"
%
op
)
==
eval
(
"x %s y"
%
op
),
"x=%d, y=%d"
%
(
x
,
y
))
verify
(
eval
(
"x %s c[y]"
%
op
)
==
eval
(
"x %s y"
%
op
),
"x=%d, y=%d"
%
(
x
,
y
))
def
all
():
lists
()
...
...
@@ -1897,6 +1962,7 @@ def all():
restricted
()
str_subclass_as_dict_key
()
classic_comparisons
()
rich_comparisons
()
all
()
...
...
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