Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
031ddf9a
Commit
031ddf9a
authored
Sep 07, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit test for custom hash and equality methods in cypclass dicts
parent
cf8980bf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
0 deletions
+43
-0
tests/run/cypclass_builtin_dict.pyx
tests/run/cypclass_builtin_dict.pyx
+43
-0
No files found.
tests/run/cypclass_builtin_dict.pyx
View file @
031ddf9a
...
...
@@ -198,6 +198,49 @@ def test_contains():
return
-
2
return
0
cdef
cypclass
EqualIndex
(
Index
):
bint
__eq__
(
self
,
EqualIndex
other
):
return
self
.
index
==
other
.
index
int
__hash__
(
self
):
return
self
.
index
cdef
cypclass
AlwaysEqualIndex
(
Index
):
bint
__eq__
(
self
,
AlwaysEqualIndex
other
):
return
True
int
__hash__
(
self
):
return
0
def
test_custom_eq_and_hash
():
"""
>>> test_custom_eq_and_hash()
0
"""
d1
=
cypdict
[
EqualIndex
,
double
]()
d1
[
EqualIndex
(
0
)]
=
0.0
if
EqualIndex
(
0
)
not
in
d1
:
return
-
1
if
EqualIndex
(
1
)
in
d1
:
return
-
2
if
d1
.
__len__
()
!=
1
:
return
-
3
d1
[
EqualIndex
(
0
)]
=
2.0
if
d1
.
__len__
()
!=
1
:
return
-
4
d1
[
EqualIndex
(
1
)]
=
1.0
if
d1
.
__len__
()
!=
2
:
return
-
5
d2
=
cypdict
[
AlwaysEqualIndex
,
double
]()
d2
[
AlwaysEqualIndex
(
11
)]
=
11.0
for
i
in
range
(
10
):
index
=
AlwaysEqualIndex
(
i
)
if
index
not
in
d2
:
return
-
(
i
+
6
)
d2
[
index
]
=
<
double
>
i
if
d2
.
__len__
()
!=
1
:
return
-
(
i
+
16
)
return
0
def
test_nonexistent_getitem_exception
():
"""
>>> test_nonexistent_getitem_exception()
...
...
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