summaryrefslogtreecommitdiffstats
path: root/flist.py
diff options
context:
space:
mode:
Diffstat (limited to 'flist.py')
-rw-r--r--flist.py208
1 files changed, 104 insertions, 104 deletions
diff --git a/flist.py b/flist.py
index 292112e..2035221 100644
--- a/flist.py
+++ b/flist.py
@@ -37,110 +37,110 @@ __all__ = ["Flist"]
from returncodes import RET_NOTEXIST
class Flist:
- """ This class is just an other wrapper around the python builtin list.
- It dosen't use exceptions 'cause exceptions suck ! """
- def __init__(self):
- self.L = []
-
- def __str__(self):
- ret = ''
- for I in self.L:
- ret += str(I.__class__)+' : '+I.getString()+' - '
- return 'Flist - '+ret
-
- def add(self, el):
- self.L.append(el)
- #return RET_OK # TzurTcH - no need
-
- def get(self, idx):
- if idx<0 or idx>=len(self.L):
- return RET_NOTEXIST
- return self.L[idx]
-
- def remove(self, idx):
- if idx<0 or idx>=len(self.L):
- return RET_NOTEXIST
- tmp,self.L = self.L[idx], self.L[:idx]+self.L[idx+1:]
- return tmp
-
- def removeFifo(self):
- if len(self.L) == 0:
- return RET_NOTEXIST
- tmp, self.L = self.L[0], self.L[1:]
- return tmp
-
- def removeStack(self):
- if len(self.L) == 0:
- return RET_NOTEXIST
- return self.L.pop()
-
- def getCount(self):
- return len(self.L)
-
+ """ This class is just an other wrapper around the python builtin list.
+ It dosen't use exceptions 'cause exceptions suck ! """
+ def __init__(self):
+ self.L = []
+
+ def __str__(self):
+ ret = ''
+ for I in self.L:
+ ret += str(I.__class__)+' : '+I.getString()+' - '
+ return 'Flist - '+ret
+
+ def add(self, el):
+ self.L.append(el)
+ #return RET_OK # TzurTcH - no need
+
+ def get(self, idx):
+ if idx<0 or idx>=len(self.L):
+ return RET_NOTEXIST
+ return self.L[idx]
+
+ def remove(self, idx):
+ if idx<0 or idx>=len(self.L):
+ return RET_NOTEXIST
+ tmp,self.L = self.L[idx], self.L[:idx]+self.L[idx+1:]
+ return tmp
+
+ def removeFifo(self):
+ if len(self.L) == 0:
+ return RET_NOTEXIST
+ tmp, self.L = self.L[0], self.L[1:]
+ return tmp
+
+ def removeStack(self):
+ if len(self.L) == 0:
+ return RET_NOTEXIST
+ return self.L.pop()
+
+ def getCount(self):
+ return len(self.L)
+
if __name__ == '__main__':
- import unittest
-
-
- class FlistTestCase(unittest.TestCase):
-
- def test1AddGetRemove(self):
- list = Flist()
- list.add("A")
- list.add("B")
- list.add("C")
- list.add("D")
- list.add("E")
- self.assertEquals(list.get(0),"A")
- self.assertEquals(list.get(1),"B")
- self.assertEquals(list.get(2),"C")
- self.assertEquals(list.get(3),"D")
- self.assertEquals(list.get(4),"E")
- self.assertEquals(list.remove(5),RET_NOTEXIST)
- self.assertEquals(list.remove(0),"A")
- self.assertEquals(list.remove(1),"C")
- self.assertEquals(list.remove(2),"E")
- self.assertEquals(list.remove(2),RET_NOTEXIST)
- self.assertEquals(list.remove(1),"D")
- self.assertEquals(list.remove(0),"B")
- self.assertEquals(list.remove(0),RET_NOTEXIST)
-
- def test2RemoveFifo(self):
- list = Flist()
- list.add("A")
- list.add("B")
- list.add("C")
- list.add("D")
- list.add("E")
- self.assertEquals(list.removeFifo(),"A")
- self.assertEquals(list.removeFifo(),"B")
- self.assertEquals(list.removeFifo(),"C")
- self.assertEquals(list.removeFifo(),"D")
- self.assertEquals(list.removeFifo(),"E")
- self.assertEquals(list.removeFifo(),RET_NOTEXIST)
-
- def test3RemoveStack(self):
- list = Flist()
- list.add("A")
- list.add("B")
- list.add("C")
- list.add("D")
- list.add("E")
- self.assertEquals(list.removeStack(),"E")
- self.assertEquals(list.removeStack(),"D")
- self.assertEquals(list.removeStack(),"C")
- self.assertEquals(list.removeStack(),"B")
- self.assertEquals(list.removeStack(),"A")
- self.assertEquals(list.removeStack(),RET_NOTEXIST)
-
- def test4GetCount(self):
- list = Flist()
- list.add("A")
- list.add("B")
- list.add("C")
- list.add("D")
- list.add("E")
- self.assertEquals(list.getCount(),5)
-
- unittest.main()
+ import unittest
+
+
+ class FlistTestCase(unittest.TestCase):
+
+ def test1AddGetRemove(self):
+ list = Flist()
+ list.add("A")
+ list.add("B")
+ list.add("C")
+ list.add("D")
+ list.add("E")
+ self.assertEquals(list.get(0),"A")
+ self.assertEquals(list.get(1),"B")
+ self.assertEquals(list.get(2),"C")
+ self.assertEquals(list.get(3),"D")
+ self.assertEquals(list.get(4),"E")
+ self.assertEquals(list.remove(5),RET_NOTEXIST)
+ self.assertEquals(list.remove(0),"A")
+ self.assertEquals(list.remove(1),"C")
+ self.assertEquals(list.remove(2),"E")
+ self.assertEquals(list.remove(2),RET_NOTEXIST)
+ self.assertEquals(list.remove(1),"D")
+ self.assertEquals(list.remove(0),"B")
+ self.assertEquals(list.remove(0),RET_NOTEXIST)
+
+ def test2RemoveFifo(self):
+ list = Flist()
+ list.add("A")
+ list.add("B")
+ list.add("C")
+ list.add("D")
+ list.add("E")
+ self.assertEquals(list.removeFifo(),"A")
+ self.assertEquals(list.removeFifo(),"B")
+ self.assertEquals(list.removeFifo(),"C")
+ self.assertEquals(list.removeFifo(),"D")
+ self.assertEquals(list.removeFifo(),"E")
+ self.assertEquals(list.removeFifo(),RET_NOTEXIST)
+
+ def test3RemoveStack(self):
+ list = Flist()
+ list.add("A")
+ list.add("B")
+ list.add("C")
+ list.add("D")
+ list.add("E")
+ self.assertEquals(list.removeStack(),"E")
+ self.assertEquals(list.removeStack(),"D")
+ self.assertEquals(list.removeStack(),"C")
+ self.assertEquals(list.removeStack(),"B")
+ self.assertEquals(list.removeStack(),"A")
+ self.assertEquals(list.removeStack(),RET_NOTEXIST)
+
+ def test4GetCount(self):
+ list = Flist()
+ list.add("A")
+ list.add("B")
+ list.add("C")
+ list.add("D")
+ list.add("E")
+ self.assertEquals(list.getCount(),5)
+
+ unittest.main()