annotate _test_lookup_list.py @ 428:52b4908d8971

simple example of theano
author Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
date Fri, 25 Jul 2008 16:59:57 -0400
parents 29f394813c3c
children
rev   line source
275
323909110d1c added test_lookup_list
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
1 from lookup_list import *
280
b39327d5506f passed test_lookup_list.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 275
diff changeset
2 import unittest
275
323909110d1c added test_lookup_list
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
3
280
b39327d5506f passed test_lookup_list.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 275
diff changeset
4 class T_LookUpList(unittest.TestCase):
b39327d5506f passed test_lookup_list.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 275
diff changeset
5 def test_LookupList(self):
b39327d5506f passed test_lookup_list.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 275
diff changeset
6 #test only the example in the doc???
b39327d5506f passed test_lookup_list.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 275
diff changeset
7 example = LookupList(['x','y','z'],[1,2,3])
b39327d5506f passed test_lookup_list.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 275
diff changeset
8 example['x'] = [1, 2, 3] # set or change a field
b39327d5506f passed test_lookup_list.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 275
diff changeset
9 x, y, z = example
b39327d5506f passed test_lookup_list.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 275
diff changeset
10 x = example[0]
b39327d5506f passed test_lookup_list.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 275
diff changeset
11 x = example["x"]
b39327d5506f passed test_lookup_list.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 275
diff changeset
12 assert example.keys()==['x','y','z']
b39327d5506f passed test_lookup_list.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 275
diff changeset
13 assert example.values()==[[1,2,3],2,3]
b39327d5506f passed test_lookup_list.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 275
diff changeset
14 assert example.items()==[('x',[1,2,3]),('y',2),('z',3)]
b39327d5506f passed test_lookup_list.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 275
diff changeset
15 example.append_keyval('u',0) # adds item with name 'u' and value 0
b39327d5506f passed test_lookup_list.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 275
diff changeset
16 assert len(example)==4 # number of items = 4 here
b39327d5506f passed test_lookup_list.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 275
diff changeset
17 example2 = LookupList(['v','w'], ['a','b'])
b39327d5506f passed test_lookup_list.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 275
diff changeset
18 example3 = LookupList(['x','y','z','u','v','w'], [[1, 2, 3],2,3,0,'a','b'])
b39327d5506f passed test_lookup_list.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 275
diff changeset
19 assert example+example2==example3
281
29f394813c3c use the unittest function to test that execption is raised
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 280
diff changeset
20 self.assertRaises(AssertionError,example.__add__,example)
280
b39327d5506f passed test_lookup_list.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 275
diff changeset
21 del example, example2, example3, x, y ,z
275
323909110d1c added test_lookup_list
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
22
323909110d1c added test_lookup_list
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
diff changeset
23 if __name__=='__main__':
280
b39327d5506f passed test_lookup_list.py to unittest
Frederic Bastien <bastienf@iro.umontreal.ca>
parents: 275
diff changeset
24 unittest.main()