Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
BTrees
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
BTrees
Commits
1dafb37d
Commit
1dafb37d
authored
Dec 04, 2012
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Coverage for BTrees._base.{set_operation,weightedIntersection}.
parent
77ecf4a5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
0 deletions
+64
-0
BTrees/tests/test__base.py
BTrees/tests/test__base.py
+64
-0
No files found.
BTrees/tests/test__base.py
View file @
1dafb37d
...
...
@@ -2410,6 +2410,28 @@ class TreeSetTests(unittest.TestCase):
self
.
assertTrue
(
letter
in
_set
)
class
Test_set_operation
(
unittest
.
TestCase
):
assertRaises
=
_assertRaises
def
_getTargetClass
(
self
):
from
.._base
import
set_operation
return
set_operation
def
_makeOne
(
self
,
func
,
set_type
):
return
self
.
_getTargetClass
()(
func
,
set_type
)
def
test_it
(
self
):
class
_SetType
(
object
):
pass
_called_with
=
[]
def
_func
(
*
args
,
**
kw
):
_called_with
.
append
((
args
,
kw
))
set_op
=
self
.
_makeOne
(
_func
,
_SetType
)
set_op
(
'a'
,
b
=
1
)
self
.
assertEqual
(
_called_with
,
[((
_SetType
,
'a'
,),
{
'b'
:
1
})])
class
_SetObBase
(
object
):
def
_makeSet
(
self
,
*
args
):
...
...
@@ -2629,12 +2651,52 @@ class Test_weightedUnion(unittest.TestCase, _SetObBase):
self
.
assertEqual
(
result
[
'e'
],
11
)
class
Test_weightedIntersection
(
unittest
.
TestCase
,
_SetObBase
):
def
_callFUT
(
self
,
*
args
,
**
kw
):
from
.._base
import
weightedIntersection
return
weightedIntersection
(
*
args
,
**
kw
)
def
test_both_none
(
self
):
self
.
assertEqual
(
self
.
_callFUT
(
_Mapping
,
None
,
None
),
(
0
,
None
))
def
test_lhs_none
(
self
):
rhs
=
self
.
_makeMapping
({
'a'
:
13
,
'c'
:
12
,
'e'
:
11
})
self
.
assertEqual
(
self
.
_callFUT
(
rhs
.
__class__
,
None
,
rhs
),
(
1
,
rhs
))
def
test_rhs_none
(
self
):
lhs
=
self
.
_makeMapping
({
'a'
:
13
,
'c'
:
12
,
'e'
:
11
})
self
.
assertEqual
(
self
.
_callFUT
(
lhs
.
__class__
,
lhs
,
None
),
(
1
,
lhs
))
def
test_lhs_mapping_rhs_set
(
self
):
lhs
=
self
.
_makeMapping
({
'a'
:
13
,
'b'
:
12
,
'c'
:
11
})
rhs
=
self
.
_makeSet
(
'a'
,
'd'
)
weight
,
result
=
self
.
_callFUT
(
lhs
.
__class__
,
lhs
,
rhs
)
self
.
assertTrue
(
isinstance
(
result
,
_Mapping
))
self
.
assertEqual
(
list
(
result
),
[
'a'
])
self
.
assertEqual
(
result
[
'a'
],
55
)
def
test_both_mappings_rhs_empty
(
self
):
lhs
=
self
.
_makeMapping
({
'a'
:
13
,
'b'
:
12
,
'c'
:
11
})
rhs
=
self
.
_makeMapping
({})
weight
,
result
=
self
.
_callFUT
(
lhs
.
__class__
,
lhs
,
rhs
)
self
.
assertEqual
(
list
(
result
),
[])
def
test_both_mappings_rhs_non_empty
(
self
):
lhs
=
self
.
_makeMapping
({
'a'
:
13
,
'c'
:
12
,
'e'
:
11
})
rhs
=
self
.
_makeMapping
({
'a'
:
10
,
'b'
:
22
,
'd'
:
33
})
weight
,
result
=
self
.
_callFUT
(
lhs
.
__class__
,
lhs
,
rhs
)
self
.
assertEqual
(
list
(
result
),
[
'a'
])
self
.
assertEqual
(
result
[
'a'
],
23
)
class
_Cache
(
object
):
def
__init__
(
self
):
self
.
_mru
=
[]
def
mru
(
self
,
oid
):
self
.
_mru
.
append
(
oid
)
class
_Jar
(
object
):
def
__init__
(
self
):
self
.
_current
=
set
()
...
...
@@ -2696,8 +2758,10 @@ def test_suite():
unittest
.
makeSuite
(
Test_TreeItems
),
unittest
.
makeSuite
(
TreeTests
),
unittest
.
makeSuite
(
TreeSetTests
),
unittest
.
makeSuite
(
Test_set_operation
),
unittest
.
makeSuite
(
Test_difference
),
unittest
.
makeSuite
(
Test_union
),
unittest
.
makeSuite
(
Test_intersection
),
unittest
.
makeSuite
(
Test_weightedUnion
),
unittest
.
makeSuite
(
Test_weightedIntersection
),
))
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