diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2012-04-13 21:16:12 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2012-04-13 21:16:12 +0200 |
commit | eeb9927c89d6d2425a74c33ff8773bceba39af1c (patch) | |
tree | e5e770fc041fa27b6e13a78dc9c3dc3f75c7c213 /flisthash.py | |
parent | 99561b834dbd9d52b83aa7b0fb980431fa1aa056 (diff) | |
download | pyevenja-eeb9927c89d6d2425a74c33ff8773bceba39af1c.zip pyevenja-eeb9927c89d6d2425a74c33ff8773bceba39af1c.tar.gz |
Diffstat (limited to 'flisthash.py')
-rw-r--r-- | flisthash.py | 180 |
1 files changed, 90 insertions, 90 deletions
diff --git a/flisthash.py b/flisthash.py index 345cac4..5134931 100644 --- a/flisthash.py +++ b/flisthash.py @@ -38,96 +38,96 @@ from flist import Flist from fstringhash import FstringHash class FlistHash(Flist): - """ This class is a wrapper arounf the flist class, providing some search capabilities""" - - def __init__(self): - Flist.__init__(self) # force constructor - - def __str__(self): - return "\t"+Flist.__str__(self)+\ - "FlistHash - (null)\n" - - #def SearchPos(self,fstringHash): - # """/** Search the position of the stringhash name. - # Return the position in the list or None if not found. */""" - # ret = None - # print self.L - # for I in self.L: - # if I.equals(fstringHash): - # return self.L.index(I) - # return ret - - - def Search(self,fstringHash): - """/** Search if same name (stringhash) exist */""" - for I in self.L: - if I.equals(fstringHash): - return I - return None - - def addOrGet(self,fstringHash): - """/** If the same name exist in the list then get it from the list. - If not, add stringhash in the list then return None. */""" - pos = self.Search(fstringHash) - if pos <> None: - return pos - self.add(fstringHash) - return None - - def addOrRemove(self,fstringHash): - """/** If the same name exist in the list, then removes and return it. - If not, then add to the list and return None. */""" - pos = self.Search(fstringHash) - if pos <> None: - self.L.remove(pos) - return pos - self.add(fstringHash) - return None - + """ This class is a wrapper arounf the flist class, providing some search capabilities""" + + def __init__(self): + Flist.__init__(self) # force constructor + + def __str__(self): + return "\t"+Flist.__str__(self)+\ + "FlistHash - (null)\n" + + #def SearchPos(self,fstringHash): + # """/** Search the position of the stringhash name. + # Return the position in the list or None if not found. */""" + # ret = None + # print self.L + # for I in self.L: + # if I.equals(fstringHash): + # return self.L.index(I) + # return ret + + + def Search(self,fstringHash): + """/** Search if same name (stringhash) exist */""" + for I in self.L: + if I.equals(fstringHash): + return I + return None + + def addOrGet(self,fstringHash): + """/** If the same name exist in the list then get it from the list. + If not, add stringhash in the list then return None. */""" + pos = self.Search(fstringHash) + if pos <> None: + return pos + self.add(fstringHash) + return None + + def addOrRemove(self,fstringHash): + """/** If the same name exist in the list, then removes and return it. + If not, then add to the list and return None. */""" + pos = self.Search(fstringHash) + if pos <> None: + self.L.remove(pos) + return pos + self.add(fstringHash) + return None + if __name__ == '__main__': - import unittest - from OSconfig import START_ELEMENTS - - List = FlistHash() - - str=[FstringHash(),FstringHash(),FstringHash(),FstringHash(),FstringHash()] - STR=["TEST", "TEST1", "TEST", "TEST1", "TEST2"] - str[0].setString(STR[0]) - str[1].setString(STR[1]) - str[2].setString(STR[2]) - str[3].setString(STR[3]) - str[4].setString(STR[4]) - - class FlistHashTestCase(unittest.TestCase): - - def test1HashAddOrGet(self): - self.assertEquals(List.addOrGet(str[0]),None) - self.assertEquals(List.addOrGet(str[1]),None) - self.assertEquals(List.addOrGet(str[2]).equals(str[2]),True) - self.assertEquals(List.addOrGet(str[3]).equals(str[3]),True) - self.assertEquals(List.addOrGet(str[4]),None) - - def test2HashAddOrRemove(self): - self.assertEquals(List.addOrRemove(str[0]).equals(str[0]),True) - self.assertEquals(List.addOrRemove(str[1]).equals(str[1]),True) - self.assertEquals(List.addOrRemove(str[2]),None) - self.assertEquals(List.addOrRemove(str[3]),None) - self.assertEquals(List.addOrRemove(str[4]).equals(str[4]),True) - self.assertEquals(List.addOrRemove(str[2]).equals(str[2]),True) - self.assertEquals(List.addOrRemove(str[3]).equals(str[3]),True) - - def test3HashSearch(self): - for I in range (START_ELEMENTS+10): - buffer = "TEST%d"%I - str1 = FstringHash() - str1.setString(buffer) - self.assertEquals(List.addOrGet( str1),None) - buffer = "TEST%d"%(START_ELEMENTS-10) - str1 = FstringHash() - str1.setString(buffer) - self.assertEquals(List.Search(str1).getString(),"TEST%d"%(START_ELEMENTS-10)) - - - unittest.main() + import unittest + from OSconfig import START_ELEMENTS + + List = FlistHash() + + str=[FstringHash(),FstringHash(),FstringHash(),FstringHash(),FstringHash()] + STR=["TEST", "TEST1", "TEST", "TEST1", "TEST2"] + str[0].setString(STR[0]) + str[1].setString(STR[1]) + str[2].setString(STR[2]) + str[3].setString(STR[3]) + str[4].setString(STR[4]) + + class FlistHashTestCase(unittest.TestCase): + + def test1HashAddOrGet(self): + self.assertEquals(List.addOrGet(str[0]),None) + self.assertEquals(List.addOrGet(str[1]),None) + self.assertEquals(List.addOrGet(str[2]).equals(str[2]),True) + self.assertEquals(List.addOrGet(str[3]).equals(str[3]),True) + self.assertEquals(List.addOrGet(str[4]),None) + + def test2HashAddOrRemove(self): + self.assertEquals(List.addOrRemove(str[0]).equals(str[0]),True) + self.assertEquals(List.addOrRemove(str[1]).equals(str[1]),True) + self.assertEquals(List.addOrRemove(str[2]),None) + self.assertEquals(List.addOrRemove(str[3]),None) + self.assertEquals(List.addOrRemove(str[4]).equals(str[4]),True) + self.assertEquals(List.addOrRemove(str[2]).equals(str[2]),True) + self.assertEquals(List.addOrRemove(str[3]).equals(str[3]),True) + + def test3HashSearch(self): + for I in range (START_ELEMENTS+10): + buffer = "TEST%d"%I + str1 = FstringHash() + str1.setString(buffer) + self.assertEquals(List.addOrGet( str1),None) + buffer = "TEST%d"%(START_ELEMENTS-10) + str1 = FstringHash() + str1.setString(buffer) + self.assertEquals(List.Search(str1).getString(),"TEST%d"%(START_ELEMENTS-10)) + + + unittest.main() |