Beispiel #1
0
    def test_init(self):
        """Trie init should create an empty trie."""

        t = Compressed_Trie()
        self.assertEqual(t.root.labels, [])
        self.assertEqual(t.root.children, {})
        self.assertEqual(t.root.key, "")
Beispiel #2
0
    def test_size(self):
        """size should return the number of nodes in the trie."""

        self.assertEqual(self.trie.size(), 10)

        #empty trie contins only root node
        t = Compressed_Trie()
        self.assertEqual(size(t), 1)
Beispiel #3
0
    def test_insert_find(self):
        """An added key should be found by find."""

        data = self.data
        t = Compressed_Trie()
        for (label, seq) in data.items():
            t.insert(seq, label)

        for (label, seq) in data.items():
            self.assertEqual(label in t.find(seq), True)
        self.assertEqual(t.find("abababa"), ["1", "6"])
        self.assertEqual(t.find("cacgchagc"), [])
Beispiel #4
0
    def test_insert_find(self):
        """An added key should be found by find."""

        data = self.data
        t = Compressed_Trie()
        for (label, seq) in data.iteritems():
            t.insert(seq, label)
    
        for  (label, seq) in data.iteritems():
            self.assertEqual(label in t.find(seq), True)
        self.assertEqual(t.find("abababa"), ["1","6"])
        self.assertEqual(t.find("cacgchagc"), [])
Beispiel #5
0
 def test_non_zero(self):
     """__non_zero__ should cehck for any data in the trie."""
     t = Compressed_Trie()
     self.assertEqual(t.__nonzero__(), False)
     self.assertEqual(self.trie.__nonzero__(), True)
Beispiel #6
0
    def test_len(self):
        """__len__ should return the number of seqs in the trie."""

        self.assertEqual(len(self.trie), 9)
        t = Compressed_Trie()
        self.assertEqual(len(t), 0)
Beispiel #7
0
 def test_non_zero(self):
     """__non_zero__ should cehck for any data in the trie."""
     t = Compressed_Trie()
     self.assertEqual(t.__nonzero__(), False)
     self.assertEqual(self.trie.__nonzero__(), True)