Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
graph_drawing
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
graph_drawing
Commits
ab2d0af7
Commit
ab2d0af7
authored
May 02, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added 'negated' keyword argument to node constructor.
parent
aade5fc5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
7 deletions
+11
-7
node.py
node.py
+4
-4
tests/test_node.py
tests/test_node.py
+7
-3
No files found.
node.py
View file @
ab2d0af7
...
@@ -3,11 +3,11 @@ from copy import deepcopy
...
@@ -3,11 +3,11 @@ from copy import deepcopy
class
Node
(
object
):
class
Node
(
object
):
def
__init__
(
self
,
value
,
*
nodes
):
def
__init__
(
self
,
value
,
*
nodes
,
**
kwargs
):
super
(
Node
,
self
).
__init__
()
super
(
Node
,
self
).
__init__
()
self
.
value
,
self
.
nodes
=
value
,
list
(
nodes
)
self
.
value
,
self
.
nodes
=
value
,
list
(
nodes
)
self
.
is_leaf
=
False
self
.
is_leaf
=
False
self
.
negated
=
0
self
.
negated
=
kwargs
.
get
(
'negated'
,
0
)
def
__getitem__
(
self
,
n
):
def
__getitem__
(
self
,
n
):
return
self
.
nodes
[
n
]
return
self
.
nodes
[
n
]
...
@@ -43,8 +43,8 @@ class Node(object):
...
@@ -43,8 +43,8 @@ class Node(object):
class
Leaf
(
Node
):
class
Leaf
(
Node
):
def
__init__
(
self
,
value
):
def
__init__
(
self
,
value
,
**
kwargs
):
super
(
Leaf
,
self
).
__init__
(
value
)
super
(
Leaf
,
self
).
__init__
(
value
,
**
kwargs
)
self
.
value
=
value
self
.
value
=
value
self
.
nodes
=
None
self
.
nodes
=
None
self
.
is_leaf
=
True
self
.
is_leaf
=
True
...
...
tests/test_node.py
View file @
ab2d0af7
...
@@ -3,6 +3,7 @@ import doctest
...
@@ -3,6 +3,7 @@ import doctest
import
node
import
node
from
node
import
Node
,
Leaf
from
node
import
Node
,
Leaf
from
line
import
generate_line
class
TestNode
(
unittest
.
TestCase
):
class
TestNode
(
unittest
.
TestCase
):
...
@@ -15,9 +16,6 @@ class TestNode(unittest.TestCase):
...
@@ -15,9 +16,6 @@ class TestNode(unittest.TestCase):
self
.
l1
=
Leaf
(
'leaf 2'
)
self
.
l1
=
Leaf
(
'leaf 2'
)
self
.
node
=
Node
(
'node'
,
self
.
l0
,
self
.
l1
)
self
.
node
=
Node
(
'node'
,
self
.
l0
,
self
.
l1
)
def
tearDown
(
self
):
pass
def
test_getitem
(
self
):
def
test_getitem
(
self
):
assert
self
.
node
[
0
]
==
self
.
l0
assert
self
.
node
[
0
]
==
self
.
l0
...
@@ -47,3 +45,9 @@ class TestNode(unittest.TestCase):
...
@@ -47,3 +45,9 @@ class TestNode(unittest.TestCase):
self
.
assertEqual
(
str
(
l1
),
'-1'
)
self
.
assertEqual
(
str
(
l1
),
'-1'
)
l1
=
-
l1
l1
=
-
l1
self
.
assertEqual
(
str
(
l1
),
'--1'
)
self
.
assertEqual
(
str
(
l1
),
'--1'
)
def
test_kwargs_constructor
(
self
):
l1
,
l2
=
Leaf
(
1
),
Leaf
(
2
)
self
.
assertEqual
(
Node
(
'+'
,
l1
,
l2
,
negated
=
1
).
negated
,
1
)
self
.
assertEqual
(
Leaf
(
1
,
negated
=
2
).
negated
,
2
)
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