Commit ab2d0af7 authored by Taddeus Kroes's avatar Taddeus Kroes

Added 'negated' keyword argument to node constructor.

parent aade5fc5
......@@ -3,11 +3,11 @@ from copy import deepcopy
class Node(object):
def __init__(self, value, *nodes):
def __init__(self, value, *nodes, **kwargs):
super(Node, self).__init__()
self.value, self.nodes = value, list(nodes)
self.is_leaf = False
self.negated = 0
self.negated = kwargs.get('negated', 0)
def __getitem__(self, n):
return self.nodes[n]
......@@ -43,8 +43,8 @@ class Node(object):
class Leaf(Node):
def __init__(self, value):
super(Leaf, self).__init__(value)
def __init__(self, value, **kwargs):
super(Leaf, self).__init__(value, **kwargs)
self.value = value
self.nodes = None
self.is_leaf = True
......
......@@ -3,6 +3,7 @@ import doctest
import node
from node import Node, Leaf
from line import generate_line
class TestNode(unittest.TestCase):
......@@ -15,9 +16,6 @@ class TestNode(unittest.TestCase):
self.l1 = Leaf('leaf 2')
self.node = Node('node', self.l0, self.l1)
def tearDown(self):
pass
def test_getitem(self):
assert self.node[0] == self.l0
......@@ -47,3 +45,9 @@ class TestNode(unittest.TestCase):
self.assertEqual(str(l1), '-1')
l1 = -l1
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)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment