bfb2eda1a1e2d6e1dae9920edc1f66d922c5ebd9
[htsworkflow.git] / htsworkflow / util / test / test_alphanum.py
1 import copy
2 import os
3 import unittest
4
5 from htsworkflow.util.alphanum import alphanum
6
7 class testAlphanum(unittest.TestCase):
8     def test_string(self):
9       unsorted = ['z5', 'b3', 'b10', 'a001', 'a2']
10       sorted = [ 'a001', 'a2', 'b3', 'b10', 'z5']
11       scratch = copy.copy(unsorted)
12       scratch.sort(alphanum)
13
14       for i in xrange(len(scratch)):
15         self.failIfEqual(scratch[i], unsorted[i])
16       for i in xrange(len(scratch)):
17         self.failUnlessEqual(scratch[i], sorted[i])
18
19     def test_numbers(self):
20       unsorted = [5,7,10,18,-1,3]
21       sorted = [-1,3,5,7,10,18]
22       scratch = copy.copy(unsorted)
23       scratch.sort(alphanum)
24
25       for i in xrange(len(scratch)):
26         self.failIfEqual(scratch[i], unsorted[i])
27       for i in xrange(len(scratch)):
28         self.failUnlessEqual(scratch[i], sorted[i])
29
30
31 def suite():
32     return unittest.makeSuite(testAlphanum, 'test')
33
34 if __name__ == "__main__":
35     unittest.main(defaultTest='suite')
36
37
38
39