Package elisa :: Package core :: Package tests :: Module test_utils_sorting
[hide private]
[frames] | no frames]

Source Code for Module elisa.core.tests.test_utils_sorting

 1  # Elisa - Home multimedia server 
 2  # Copyright (C) 2006-2008 Fluendo Embedded S.L. (www.fluendo.com). 
 3  # All rights reserved. 
 4  # 
 5  # This file is available under one of two license agreements. 
 6  # 
 7  # This file is licensed under the GPL version 3. 
 8  # See "LICENSE.GPL" in the root of this distribution including a special 
 9  # exception to use Elisa with Fluendo's plugins. 
10  # 
11  # The GPL part of Elisa is also available under a commercial licensing 
12  # agreement from Fluendo. 
13  # See "LICENSE.Elisa" in the root directory of this distribution package 
14  # for details on that license. 
15   
16  import copy 
17   
18  from twisted.trial import unittest 
19   
20  from elisa.core.utils import sorting 
21   
22 -class TestSorting(unittest.TestCase):
23
24 - def test_natural_sort(self):
25 # trivial 26 original = ["a2", "a1"] 27 expected = ["a1", "a2"] 28 29 sorting.natural_sort(original) 30 self.assertEquals(original, expected) 31 32 # mixed case 33 original = ["a2", "A1"] 34 expected = ["A1", "a2"] 35 36 sorting.natural_sort(original) 37 self.assertEquals(original, expected) 38 39 # spaces are equal 40 original = ["a 2", "a 1"] 41 expected = ["a 1", "a 2"] 42 43 sorting.natural_sort(original) 44 self.assertEquals(original, expected) 45 46 # more complicated 47 original = ["A13", "A1", "A2"] 48 expected = ["A1", "A2", "A13"] 49 50 sorting.natural_sort(original) 51 self.assertEquals(original, expected) 52 53 original = ["toto 12", "titi 42", "1 truc", "12 truc", "toto 1"] 54 expected = ["1 truc", "12 truc", "titi 42", "toto 1", "toto 12"] 55 56 sorting.natural_sort(original) 57 self.assertEquals(original, expected) 58 59 60 # examples from ASPN recipe "Natural string sorting" 61 # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/285264 62 original = ['ver-1.3.12', 'ver-1.3.3', 'ver-1.2.5', 'ver-1.2.15', \ 63 'ver-1.2.3', 'ver-1.2.1'] 64 expected = ['ver-1.2.1', 'ver-1.2.3', 'ver-1.2.5', 'ver-1.2.15', \ 65 'ver-1.3.3', 'ver-1.3.12'] 66 67 sorting.natural_sort(original) 68 self.assertEquals(original, expected) 69 70 original = ['C1H2', 'C1H4', 'C2H2', 'C2H6', 'C2N', 'C3H6'] 71 expected = ['C1H2', 'C1H4', 'C2H2', 'C2H6', 'C2N', 'C3H6'] 72 73 sorting.natural_sort(original) 74 self.assertEquals(original, expected) 75 76 original = ['Team 101', 'Team 58', 'Team 30', 'Team 1'] 77 expected = ['Team 1', 'Team 30', 'Team 58', 'Team 101'] 78 79 sorting.natural_sort(original) 80 self.assertEquals(original, expected) 81 82 original = ['a5', 'A7', 'a15', 'a9', 'A8'] 83 expected = ['a5', 'A7', 'A8', 'a9', 'a15'] 84 85 sorting.natural_sort(original) 86 self.assertEquals(original, expected)
87