Imported Upstream version 2008.1+svn1648
[opeanno-debian-packaging.git] / development / storagetest.py
blob7effd2ec816ea785c24f8df59e7e63774105b41a
1 # ###################################################
2 # Copyright (C) 2008 The OpenAnno Team
3 # team@openanno.org
4 # This file is part of OpenAnno.
6 # OpenAnno is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the
18 # Free Software Foundation, Inc.,
19 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 # ###################################################
22 try:
23 from storage import Storage
24 except ImportError:
25 print "This test has to ne run in the folder where storage.py is."
26 storage = Storage(5, 40)
28 print "Test1 - Adding 4 ressources with various amounts"
29 test = True
30 for i in range(1,5):
31 res = storage.alter_inventory(i, i*10)
32 print res
33 if res == 0:
34 print "Adding res %i with amount %i success" % (i, i*10)
35 else:
36 test = False
37 print "Adding res %i with amount %i failed" % (i, i*10)
38 print "Test1 passed" if test else "Test1 failed"
40 print "Test2 - Adding 1 ressource with an amount over maximum"
41 test = True
42 res = storage.alter_inventory(5, 50)
43 if res == 10:
44 print "Adding res %i with amount %i successfully returned 10" % (5, 50)
45 else:
46 test = False
47 print "Adding res %i with amount %i failed to return 10" % (5, 50)
48 print "Test2 passed" if test else "Test2 failed"
50 print "Test3 - Adding a ressource that is not in the inventory, but inventory is full."
51 test = True
52 res = storage.alter_inventory(6, 30)
53 if res == None:
54 print "Adding res %i with amount %i successfull returned None" % (6, 30)
55 else:
56 test = False
57 print "Adding res %i with amount %i failed to return None" % (6, 30)
58 print "Test3 passed" if test else "Test3 failed"
60 print "Test4 - Adding a ressource that is in the inventory allready."
61 test = True
62 res = storage.alter_inventory(1, 10)
63 if res == 0:
64 print "Adding res %i with amount %i successfull." % (1, 10)
65 else:
66 test = False
67 print "Adding res %i with amount %i failed." % (1, 10)
68 res = storage.alter_inventory(2, 30)
69 if res == 10:
70 print "Adding res %i with amount %i successfull." % (2, 20)
71 else:
72 test = False
73 print "Adding res %i with amount %i failed." % (2, 20)
74 print "Test4 passed" if test else "Test4 failed"
76 print "Test5 - Adding a ressource that is in the inventory allready."
77 test = True
78 res = storage.alter_inventory(1, -10)
79 if res == 0:
80 print "Adding res %i with amount %i successfull." % (1, -10)
81 else:
82 test = False
83 print "Adding res %i with amount %i failed." % (1, -10)
84 res = storage.alter_inventory(2, -70)
85 if res == 30:
86 print "Adding res %i with amount %i successfull." % (2, -70)
87 else:
88 test = False
89 print "Adding res %i with amount %i failed." % (2, -70)
90 print "Test5 passed" if test else "Test5 failed"
92 print storage.inventory