Beispiel #1
0
 def test_root_node_creation(self):
     ''' test if the root node is being created properly '''
     node = FPTreeNode()
     self.assertTrue(node._root)  # is a root node
     self.assertEqual(node.count, 0)  # the count is 0
Beispiel #2
0
 def test_node_creation(self):
     ''' test if the normal node is being created properly '''
     node = FPTreeNode('item')
     self.assertFalse(node._root)  # is not a root node
     self.assertEqual(node.count, 1)  # the count is 1
     self.assertEqual(node.item, 'item')
Beispiel #3
0
 def setUp(self):
     self.node = FPTreeNode()
Beispiel #4
0
class FPTreeNodeTestCase(unittest.TestCase):
    def setUp(self):
        self.node = FPTreeNode()

    def test_node_creation(self):
        ''' test if the normal node is being created properly '''
        node = FPTreeNode('item')
        self.assertFalse(node._root)  # is not a root node
        self.assertEqual(node.count, 1)  # the count is 1
        self.assertEqual(node.item, 'item')

    def test_root_node_creation(self):
        ''' test if the root node is being created properly '''
        node = FPTreeNode()
        self.assertTrue(node._root)  # is a root node
        self.assertEqual(node.count, 0)  # the count is 0

    def test_has_child(self):
        ''' test if the has_child is working as expected '''
        self.node.add_child('item1')
        self.assertTrue(self.node.has_child('item1'))
        self.assertFalse(self.node.has_child('item2'))

    def test_get_child(self):
        ''' test if the get_child is working properly or not. '''
        child_node = self.node.add_child('child_node')
        other_child_node = self.node.get_child('child_node')
        self.assertEqual(child_node, other_child_node)

    def test_get_child_invalid(self):
        ''' test if the get_child is raises an exception when child is absent '''
        with self.assertRaises(KeyError):
            self.node.get_child('item1')

    def test_add_child(self):
        ''' test if add_child is working properly or not. '''
        self.node.add_child('child')
        self.assertTrue(self.node.has_child('child'))

    def test_add_child_existing(self):
        ''' test add_child when the child is already present. '''
        self.node.add_child('child')
        with self.assertRaises(ValueError):
            self.node.add_child('child')
 def setUp(self):
     self.node = FPTreeNode()
class FPTreeNodeTestCase(unittest.TestCase):
    def setUp(self):
        self.node = FPTreeNode()

    def test_node_creation(self):
        ''' test if the normal node is being created properly '''
        node = FPTreeNode('item')
        self.assertFalse(node._root)  # is not a root node
        self.assertEqual(node.count, 1)  # the count is 1
        self.assertEqual(node.item, 'item')

    def test_root_node_creation(self):
        ''' test if the root node is being created properly '''
        node = FPTreeNode()
        self.assertTrue(node._root)  # is a root node
        self.assertEqual(node.count, 0)  # the count is 0

    def test_has_child(self):
        ''' test if the has_child is working as expected '''
        self.node.add_child('item1')
        self.assertTrue(self.node.has_child('item1'))
        self.assertFalse(self.node.has_child('item2'))

    def test_get_child(self):
        ''' test if the get_child is working properly or not. '''
        child_node = self.node.add_child('child_node')
        other_child_node = self.node.get_child('child_node')
        self.assertEqual(child_node, other_child_node)

    def test_get_child_invalid(self):
        ''' test if the get_child is raises an exception when child is absent '''
        with self.assertRaises(KeyError):
            self.node.get_child('item1')

    def test_add_child(self):
        ''' test if add_child is working properly or not. '''
        self.node.add_child('child')
        self.assertTrue(self.node.has_child('child'))

    def test_add_child_existing(self):
        ''' test add_child when the child is already present. '''
        self.node.add_child('child')
        with self.assertRaises(ValueError):
            self.node.add_child('child')