Example #1
0
 def test_init(self):
     """Node init should construct the right structure"""
     # With no values should create a node with an empty list for values,
     # the provided key as key, and an empty dictionary as children
     n = _CompressedNode(self.key)
     self.assertEqual(n.values, [])
     self.assertEqual(n.key, self.key)
     self.assertEqual(n.children, {})
     # With values should create a node with the provided values list as
     # values, the provided key as key, and an empty dictionary as children
     n = _CompressedNode(self.key, self.values)
     self.assertEqual(n.values, self.values)
     self.assertEqual(n.key, self.key)
     self.assertEqual(n.children, {})
Example #2
0
 def test_init(self):
     """Node init should construct the right structure"""
     # With no values should create a node with an empty list for values,
     # the provided key as key, and an empty dictionary as children
     n = _CompressedNode(self.key)
     self.assertEqual(n.values, [])
     self.assertEqual(n.key, self.key)
     self.assertEqual(n.children, {})
     # With values should create a node with the provided values list as
     # values, the provided key as key, and an empty dictionary as children
     n = _CompressedNode(self.key, self.values)
     self.assertEqual(n.values, self.values)
     self.assertEqual(n.key, self.key)
     self.assertEqual(n.children, {})
Example #3
0
    def test_find(self):
        """The key could be found"""
        # Correctly retrieves the key stored in the calling node
        self.assertEqual(self.node.find("aba"), [1, 2])

        # Correctly retrieves the key stored in a node attached to calling one
        n = _CompressedNode(self.key, self.values)
        n.insert("abb", [3])
        self.assertEqual(n.find("aba"), [1, 2])
        self.assertEqual(n.find("abb"), [[3]])
        self.assertEqual(n.find("ab"), [])

        # Correctly retrieves an empty list for a non existent key
        self.assertEqual(n.find("cd"), [])
Example #4
0
    def test_find(self):
        """The key could be found"""
        # Correctly retrieves the key stored in the calling node
        self.assertEqual(self.node.find("aba"), [1, 2])

        # Correctly retrieves the key stored in a node attached to calling one
        n = _CompressedNode(self.key, self.values)
        n.insert("abb", [3])
        self.assertEqual(n.find("aba"), [1, 2])
        self.assertEqual(n.find("abb"), [[3]])
        self.assertEqual(n.find("ab"), [])

        # Correctly retrieves an empty list for a non existent key
        self.assertEqual(n.find("cd"), [])
Example #5
0
    def test_insert(self):
        """Correctly inserts a new key in the node"""
        n = _CompressedNode(self.key, self.values)
        n.insert("abb", [3])

        # A new node has been create with the common prefix
        self.assertEqual(n.key, "ab")
        self.assertEqual(n.values, [])
        # Tests the old node and the new one has been correctly added
        # as children
        exp_keys = set(["b", "a"])
        self.assertEqual(set(n.children.keys()), exp_keys)
        # Check that the children have the current values
        self.assertEqual(n.children["b"].key, "b")
        self.assertEqual(n.children["b"].values, [[3]])
        self.assertEqual(n.children["b"].children, {})

        self.assertEqual(n.children["a"].key, "a")
        self.assertEqual(n.children["a"].values, [1, 2])
        self.assertEqual(n.children["a"].children, {})
Example #6
0
    def test_insert(self):
        """Correctly inserts a new key in the node"""
        n = _CompressedNode(self.key, self.values)
        n.insert("abb", [3])

        # A new node has been create with the common prefix
        self.assertEqual(n.key, "ab")
        self.assertEqual(n.values, [])
        # Tests the old node and the new one has been correctly added
        # as children
        exp_keys = set(["b", "a"])
        self.assertEqual(set(n.children.keys()), exp_keys)
        # Check that the children have the current values
        self.assertEqual(n.children["b"].key, "b")
        self.assertEqual(n.children["b"].values, [[3]])
        self.assertEqual(n.children["b"].children, {})

        self.assertEqual(n.children["a"].key, "a")
        self.assertEqual(n.children["a"].values, [1, 2])
        self.assertEqual(n.children["a"].children, {})
Example #7
0
 def test_truth_value(self):
     """Non zero should check for any data on the node"""
     n = _CompressedNode("")
     self.assertFalse(bool(n))
     self.assertTrue(bool(self.node))
Example #8
0
 def setUp(self):
     """Set up test data for use in compresses node unit tests"""
     self.key = "aba"
     self.values = [1, 2]
     self.node = _CompressedNode(self.key, self.values)
Example #9
0
 def test_truth_value(self):
     """Non zero should check for any data on the node"""
     n = _CompressedNode("")
     self.assertFalse(bool(n))
     self.assertTrue(bool(self.node))
Example #10
0
 def setUp(self):
     """Set up test data for use in compresses node unit tests"""
     self.key = "aba"
     self.values = [1, 2]
     self.node = _CompressedNode(self.key, self.values)