Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Pei-Hsun Lee
AP_Exercise6_binary sorted tree
Commits
9338b477
Commit
9338b477
authored
Apr 27, 2021
by
Pei-Hsun Lee
Browse files
Update Programming_Paradigms/bintree_test.py, Programming_Paradigms/bintree.py files
parents
Changes
2
Hide whitespace changes
Inline
Side-by-side
Programming_Paradigms/bintree.py
0 → 100644
View file @
9338b477
#!/usr/bin/env python3
# *-* coding:utf-8 *-*
if
__name__
==
"__main__"
:
pass
Programming_Paradigms/bintree_test.py
0 → 100644
View file @
9338b477
#!/usr/bin/env python3
# *-* coding:utf-8 *-*
import
unittest
from
bintree
import
BinTree
,
BinTreeNode
class
TestBinTree
(
unittest
.
TestCase
):
def
test_create_has_root_none
(
self
):
tree
=
BinTree
()
self
.
assertIsNone
(
tree
.
root
)
def
test_has_insert_and_search
(
self
):
tree
=
BinTree
()
tree
.
insert
(
1
)
self
.
assertIsInstance
(
tree
.
search
(
1
),
BinTreeNode
)
self
.
assertIsNone
(
tree
.
search
(
0
))
def
test_insert_into_empty_tree
(
self
):
tree
=
BinTree
()
tree
.
insert
(
1
)
self
.
assertIsNotNone
(
tree
.
root
)
self
.
assertIsInstance
(
tree
.
root
,
BinTreeNode
)
self
.
assertEqual
(
tree
.
root
.
value
,
1
)
def
test_example
(
self
):
values
=
[
7
,
3
,
9
,
2
,
4
,
8
,
11
]
tree
=
BinTree
()
for
value
in
values
:
tree
.
insert
(
value
)
for
value
in
values
:
node
=
tree
.
search
(
value
)
self
.
assertIsInstance
(
node
,
BinTreeNode
)
self
.
assertEqual
(
value
,
node
.
value
)
node
=
tree
.
search
(
3
)
self
.
assertEqual
(
node
.
value
,
3
)
self
.
assertEqual
(
node
.
left
.
value
,
2
)
self
.
assertEqual
(
node
.
right
.
value
,
4
)
class
TestBinTreeNode
(
unittest
.
TestCase
):
def
test_creation
(
self
):
node
=
BinTreeNode
(
5
)
self
.
assertEqual
(
node
.
value
,
5
)
def
test_has_left_and_right
(
self
):
node
=
BinTreeNode
(
0
)
self
.
assertIn
(
"left"
,
node
.
__dict__
)
self
.
assertIn
(
"right"
,
node
.
__dict__
)
def
test_has_insert_and_search
(
self
):
node
=
BinTreeNode
(
0
)
node
.
insert
(
1
)
node
.
search
(
1
)
if
__name__
==
"__main__"
:
unittest
.
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