Back to index

python-biopython  1.60
Public Member Functions
test_trie.TestTrie Class Reference

List of all members.

Public Member Functions

def test_get_set
def test_prefix
def test_save
def test_get_approximate

Detailed Description

Definition at line 21 of file test_trie.py.


Member Function Documentation

Definition at line 108 of file test_trie.py.

00108 
00109     def test_get_approximate(self):
00110         # Found bug, doesn't handle insertions and deletions at end properly.
00111         trieobj = trie.trie()
00112         trieobj["hello"] = 1
00113         self.assertEqual(trieobj.get_approximate('he', 2), [])
00114         self.assertEqual(trieobj.get_approximate('he', 3), [('hello', 1, 3)])
00115         self.assertEqual(trieobj.get_approximate('hello me!', 3), [])
00116         self.assertEqual(trieobj.get_approximate('hello me!', 4), [('hello', 1, 4)])
00117         self.assertEqual(trieobj.get_approximate('hello me!', 5), [('hello', 1, 4)])
00118 

Definition at line 23 of file test_trie.py.

00023 
00024     def test_get_set(self):
00025         trieobj = trie.trie()
00026         trieobj["hello world"] = "s1"
00027         trieobj["bye"] = "s2"
00028         trieobj["hell sucks"] = "s3"
00029         trieobj["hebee"] = "s4"
00030         self.assertEqual(trieobj["hello world"], "s1")
00031         self.assertEqual(trieobj["bye"], "s2")
00032         self.assertEqual(trieobj["hell sucks"], "s3")
00033         self.assertEqual(trieobj["hebee"], "s4")
00034         trieobj["blah"] = "s5"
00035         self.assertEqual(trieobj["blah"], "s5")
00036         self.assertEqual(trieobj.get("foobar"), None)
00037         self.assertEqual(len(trieobj), 5)
00038         trieobj["blah"] = "snew"
00039         self.assertEqual(trieobj["blah"], "snew")

Definition at line 40 of file test_trie.py.

00040 
00041     def test_prefix(self):
00042         trieobj = trie.trie()
00043         trieobj["hello"] = 5
00044         trieobj["he"] = 7
00045         trieobj["hej"] = 9
00046         trieobj["foo"] = "bar"
00047         k = trieobj.keys()
00048         k.sort()
00049         self.assertEqual(k, ["foo", "he", "hej", "hello"])
00050         self.assertEqual(trieobj["hello"], 5)
00051         self.assertEqual(trieobj.get("bye"), None)
00052         self.assertEqual(trieobj.has_key("hello"), True)
00053         self.assertEqual(trieobj.has_key("he"), True)
00054         self.assertEqual(trieobj.has_key("bye"), False)
00055         self.assertEqual(trieobj.has_prefix("h"), True)
00056         self.assertEqual(trieobj.has_prefix("hel"), True)
00057         self.assertEqual(trieobj.has_prefix("foa"), False)
00058         self.assertEqual(trieobj.has_prefix("hello world"), False)
00059         self.assertEqual(len(trieobj), 4)
00060         k = trieobj.with_prefix("he")
00061         k.sort()
00062         self.assertEqual(k, ["he", "hej", "hello"])
00063         k = trieobj.with_prefix("l")
00064         self.assertEqual(k, [])
00065         k = trieobj.with_prefix("hej")
00066         self.assertEqual(k, ["hej"])
00067         k = trieobj.with_prefix("hejk")
00068         self.assertEqual(k, [])

Definition at line 69 of file test_trie.py.

00069 
00070     def test_save(self):
00071         import StringIO
00072         trieobj = trie.trie()
00073         trieobj["foo"] = 1
00074         k = trieobj.keys()
00075         self.assertEqual(k, ["foo"])
00076         v = trieobj.values()
00077         self.assertEqual(v, [1])
00078         self.assertEqual(trieobj.get("bar", 99), 99)
00079         trieobj["hello"] = '55a'
00080         self.assertEqual(trieobj.get_approximate("foo", 0), [("foo", 1, 0)])
00081         self.assertEqual(trieobj.get_approximate("foo", 1), [("foo", 1, 0)])
00082         self.assertEqual(trieobj.get_approximate("foa", 0), [])
00083         self.assertEqual(trieobj.get_approximate("foa", 1), [("foo", 1, 1)])
00084         x = trieobj.get_approximate("foa", 2)
00085         x.sort()
00086         self.assertEqual(x, [("foo", 1, 1), ("foo", 1, 2), ("foo", 1, 2)])
00087         # foo  foo-  foo-
00088         # foa  f-oa  fo-a
00089         # mismatch a->o
00090         # insertion after f, deletion of o
00091         # insertion after o, deletion of o
00092         x = trieobj.get_approximate("foo", 4)
00093         y = {}
00094         for z in x:
00095             y[z] = y.get(z, 0) + 1
00096         x = y.items()
00097         x.sort()
00098         self.assertEqual(x,[(('foo', 1, 0), 1), (('hello', '55a', 4), 6)])
00099         h = StringIO.StringIO()
00100         trie.save(h, trieobj)
00101         h.seek(0)
00102         trieobj = trie.load(h)
00103         k = trieobj.keys()
00104         self.assertTrue("foo" in k)
00105         self.assertTrue("hello" in k)
00106         self.assertEqual(repr(trieobj["foo"]), '1')
00107         self.assertEqual(repr(trieobj["hello"]), "'55a'")


The documentation for this class was generated from the following file: