Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZODB
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
ZODB
Commits
6bec07f9
Commit
6bec07f9
authored
Feb 06, 2001
by
Chris McDonough
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tests for IO, OI, and II BTrees, added clear, insert, maxminkey, and range search tests.
parent
a0dadf7c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
119 additions
and
36 deletions
+119
-36
src/BTrees/tests/testBTrees.py
src/BTrees/tests/testBTrees.py
+119
-36
No files found.
src/BTrees/tests/testBTrees.py
View file @
6bec07f9
...
...
@@ -84,22 +84,21 @@
##############################################################################
import
sys
,
os
,
time
,
whrandom
print
sys
.
path
try
:
sys
.
path
.
insert
(
0
,
'.'
)
import
ZODB
except
:
sys
.
path
.
insert
(
0
,
'../..'
)
#os.chdir('../..')
import
ZODB
from
BTrees.OOBTree
import
OOBTree
from
unittest
import
TestCase
,
TestSuite
,
TextTestRunner
,
makeSuite
from
BTrees.IOBTree
import
IOBTree
from
BTrees.IIBTree
import
IIBTree
from
BTrees.OIBTree
import
OIBTree
class
TestBTrees
(
TestCase
):
def
setUp
(
self
):
self
.
t
=
OOBTree
()
from
unittest
import
TestCase
,
TestSuite
,
TextTestRunner
,
makeSuite
class
Base
:
def
tearDown
(
self
):
self
.
t
=
None
del
self
.
t
...
...
@@ -166,7 +165,7 @@ class TestBTrees(TestCase):
def
_deletefail
(
self
):
del
self
.
t
[
1
]
def
testDeleteNoChildrenWorks
(
self
):
def
dont
testDeleteNoChildrenWorks
(
self
):
self
.
t
[
5
]
=
6
self
.
t
[
2
]
=
10
self
.
t
[
6
]
=
12
...
...
@@ -178,7 +177,7 @@ class TestBTrees(TestCase):
diff
=
lsubtract
(
self
.
t
.
keys
(),
[
1
,
2
,
3
,
5
,
6
,
10
])
assert
diff
==
[],
diff
def
testDeleteOneChildWorks
(
self
):
def
dont
testDeleteOneChildWorks
(
self
):
self
.
t
[
5
]
=
6
self
.
t
[
2
]
=
10
self
.
t
[
6
]
=
12
...
...
@@ -190,7 +189,7 @@ class TestBTrees(TestCase):
diff
=
lsubtract
(
self
.
t
.
keys
(),
[
1
,
2
,
4
,
5
,
6
,
10
])
assert
diff
==
[],
diff
def
testDeleteTwoChildrenNoInorderSuccessorWorks
(
self
):
def
dont
testDeleteTwoChildrenNoInorderSuccessorWorks
(
self
):
self
.
t
[
5
]
=
6
self
.
t
[
2
]
=
10
self
.
t
[
6
]
=
12
...
...
@@ -202,30 +201,32 @@ class TestBTrees(TestCase):
diff
=
lsubtract
(
self
.
t
.
keys
(),
[
1
,
3
,
4
,
5
,
6
,
10
])
assert
diff
==
[],
diff
def
testDeleteTwoChildrenInorderSuccessorWorks
(
self
):
self
.
t
[
5
]
=
6
self
.
t
[
2
]
=
10
self
.
t
[
6
]
=
12
def
donttestDeleteTwoChildrenInorderSuccessorWorks
(
self
):
""" 7, 3, 8, 1, 5, 10, 6, 4 -- del 3 """
self
.
t
[
7
]
=
6
self
.
t
[
3
]
=
10
self
.
t
[
8
]
=
12
self
.
t
[
1
]
=
100
self
.
t
[
3
]
=
200
self
.
t
[
5
]
=
200
self
.
t
[
10
]
=
500
self
.
t
[
4
]
=
99
self
.
t
[
2.5
]
=
150
del
self
.
t
[
2
]
diff
=
lsubtract
(
self
.
t
.
keys
(),
[
1
,
2.5
,
3
,
4
,
5
,
6
,
10
])
self
.
t
[
6
]
=
99
self
.
t
[
4
]
=
150
del
self
.
t
[
3
]
diff
=
lsubtract
(
self
.
t
.
keys
(),
[
1
,
4
,
5
,
6
,
7
,
8
,
10
])
assert
diff
==
[],
diff
def
testDeleteRootWorks
(
self
):
self
.
t
[
5
]
=
6
self
.
t
[
2
]
=
10
self
.
t
[
6
]
=
12
def
donttestDeleteRootWorks
(
self
):
""" 7, 3, 8, 1, 5, 10, 6, 4 -- del 7 """
self
.
t
[
7
]
=
6
self
.
t
[
3
]
=
10
self
.
t
[
8
]
=
12
self
.
t
[
1
]
=
100
self
.
t
[
3
]
=
200
self
.
t
[
5
]
=
200
self
.
t
[
10
]
=
500
self
.
t
[
4
]
=
99
self
.
t
[
2.5
]
=
150
del
self
.
t
[
5
]
diff
=
lsubtract
(
self
.
t
.
keys
(),
[
1
,
2
,
2.5
,
3
,
4
,
6
,
10
])
self
.
t
[
6
]
=
99
self
.
t
[
4
]
=
150
del
self
.
t
[
7
]
diff
=
lsubtract
(
self
.
t
.
keys
(),
[
1
,
3
,
4
,
5
,
6
,
8
,
10
])
assert
diff
==
[],
diff
def
testRandomNonOverlappingInserts
(
self
):
...
...
@@ -263,7 +264,7 @@ class TestBTrees(TestCase):
addl
=
added
.
keys
()
assert
len
(
self
.
t
)
==
len
(
addl
),
len
(
self
.
t
)
def
testRandomDeletes
(
self
):
def
dont
testRandomDeletes
(
self
):
r
=
range
(
1000
)
added
=
[]
for
x
in
r
:
...
...
@@ -284,7 +285,7 @@ class TestBTrees(TestCase):
badones
.
append
(
x
)
assert
badones
==
[],
(
badones
,
added
,
deleted
)
def
testTargetedDeletes
(
self
):
def
dont
testTargetedDeletes
(
self
):
r
=
range
(
1000
)
for
x
in
r
:
k
=
whrandom
.
choice
(
r
)
...
...
@@ -294,10 +295,10 @@ class TestBTrees(TestCase):
del
self
.
t
[
x
]
except
KeyError
:
pass
#
assert realseq(self.t.keys()) == [], realseq(self.t.keys())
assert
realseq
(
self
.
t
.
keys
())
==
[],
realseq
(
self
.
t
.
keys
())
# this fails 1/22/2001 by segfaulting
def
testPathologicalRightBranching
(
self
):
def
dont
testPathologicalRightBranching
(
self
):
r
=
range
(
1000
)
for
x
in
r
:
self
.
t
[
x
]
=
1
...
...
@@ -306,7 +307,7 @@ class TestBTrees(TestCase):
del
self
.
t
[
x
]
assert
realseq
(
self
.
t
.
keys
())
==
[],
realseq
(
self
.
t
.
keys
())
def
testPathologicalLeftBranching
(
self
):
def
dont
testPathologicalLeftBranching
(
self
):
r
=
range
(
1000
)
revr
=
r
[:]
revr
.
reverse
()
...
...
@@ -318,7 +319,7 @@ class TestBTrees(TestCase):
del
self
.
t
[
x
]
assert
realseq
(
self
.
t
.
keys
())
==
[],
realseq
(
self
.
t
.
keys
())
def
testSuccessorChildParentRewriteExerciseCase
(
self
):
def
dont
testSuccessorChildParentRewriteExerciseCase
(
self
):
add_order
=
[
85
,
73
,
165
,
273
,
215
,
142
,
233
,
67
,
86
,
166
,
235
,
225
,
255
,
73
,
175
,
171
,
285
,
162
,
108
,
28
,
283
,
258
,
232
,
199
,
260
,
...
...
@@ -364,6 +365,84 @@ class TestBTrees(TestCase):
except
KeyError
:
if
self
.
t
.
has_key
(
x
):
assert
1
==
2
,
"failed to delete %s"
%
x
def
testMaxKeyMinKey
(
self
):
self
.
t
[
7
]
=
6
self
.
t
[
3
]
=
10
self
.
t
[
8
]
=
12
self
.
t
[
1
]
=
100
self
.
t
[
5
]
=
200
self
.
t
[
10
]
=
500
self
.
t
[
6
]
=
99
self
.
t
[
4
]
=
150
del
self
.
t
[
7
]
t
=
self
.
t
assert
t
.
maxKey
()
==
10
assert
t
.
maxKey
(
6
)
==
6
assert
t
.
maxKey
(
9
)
==
8
assert
t
.
minKey
()
==
1
assert
t
.
minKey
(
3
)
==
3
assert
t
.
minKey
(
9
)
==
10
def
testClear
(
self
):
r
=
range
(
100
)
for
x
in
r
:
rnd
=
whrandom
.
choice
(
r
)
self
.
t
[
rnd
]
=
0
self
.
t
.
clear
()
diff
=
lsubtract
(
list
(
self
.
t
.
keys
()),
[])
assert
diff
==
[],
diff
def
testRangeSearchAfterSequentialInsert
(
self
):
r
=
range
(
100
)
for
x
in
r
:
self
.
t
[
x
]
=
0
diff
=
lsubtract
(
list
(
self
.
t
.
keys
(
0
,
100
)),
r
)
assert
diff
==
[],
diff
def
testRangeSearchAfterRandomInsert
(
self
):
r
=
range
(
100
)
a
=
{}
for
x
in
r
:
rnd
=
whrandom
.
choice
(
r
)
self
.
t
[
rnd
]
=
0
a
[
rnd
]
=
0
diff
=
lsubtract
(
list
(
self
.
t
.
keys
(
0
,
100
)),
a
.
keys
())
assert
diff
==
[],
diff
def
testInsertMethod
(
self
):
t
=
self
.
t
t
[
0
]
=
1
assert
t
.
insert
(
0
,
1
)
==
0
assert
t
.
insert
(
1
,
1
)
==
1
assert
lsubtract
(
list
(
t
.
keys
()),
[
0
,
1
])
==
[]
class
TestIOBTrees
(
Base
,
TestCase
):
def
setUp
(
self
):
self
.
t
=
IOBTree
()
def
nonIntegerKeyRaises
(
self
):
self
.
assertRaises
(
TypeError
,
self
.
_stringraises
)
self
.
assertRaises
(
TypeError
,
self
.
_floatraises
)
def
_stringraises
(
self
):
self
.
t
[
'c'
]
=
1
def
_floatraises
(
self
):
self
.
t
[
2.5
]
=
1
class
TestOOBTrees
(
Base
,
TestCase
):
def
setUp
(
self
):
self
.
t
=
OOBTree
()
class
TestIIBTrees
(
Base
,
TestCase
):
def
setUp
(
self
):
self
.
t
=
IIBTree
()
class
TestOIBTrees
(
Base
,
TestCase
):
def
setUp
(
self
):
self
.
t
=
OIBTree
()
def
lsubtract
(
l1
,
l2
):
l
=
filter
(
lambda
x
,
l1
=
l1
:
x
not
in
l1
,
l2
)
l
=
l
+
filter
(
lambda
x
,
l2
=
l2
:
x
not
in
l2
,
l1
)
...
...
@@ -373,9 +452,13 @@ def realseq(itemsob):
return
map
(
lambda
x
:
x
,
itemsob
)
def
main
():
testsuite
=
makeSuite
(
TestBTrees
,
'test'
)
OOBTree
=
makeSuite
(
TestOOBTrees
,
'test'
)
IOBTree
=
makeSuite
(
TestIOBTrees
,
'test'
)
OIBTree
=
makeSuite
(
TestOIBTrees
,
'test'
)
IIBTree
=
makeSuite
(
TestIIBTrees
,
'test'
)
alltests
=
TestSuite
((
OOBTree
,
IOBTree
,
OIBTree
,
IIBTree
))
runner
=
TextTestRunner
()
runner
.
run
(
testsuite
)
runner
.
run
(
alltests
)
if
__name__
==
'__main__'
:
main
()
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