示例#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, {})
示例#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, {})
示例#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"), [])
示例#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"), [])
示例#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, {})
示例#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, {})
示例#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))
示例#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)
示例#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))
示例#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)