Esempio n. 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, "")
Esempio n. 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)
Esempio n. 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"), [])
Esempio n. 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"), [])
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)