@@ -0,0 +1,2495 @@
+# Copyright (C) 2011 by Paolo Capriotti %3Cp.capriotti@gmail.com%3E%0A#%0A# Permission is hereby granted, free of charge, to any person obtaining a copy%0A# of this software and associated documentation files (the %22Software%22), to deal%0A# in the Software without restriction, including without limitation the rights%0A# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell%0A# copies of the Software, and to permit persons to whom the Software is%0A# furnished to do so, subject to the following conditions:%0A#%0A# The above copyright notice and this permission notice shall be included in%0A# all copies or substantial portions of the Software.%0A#%0A# THE SOFTWARE IS PROVIDED %22AS IS%22, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR%0A# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,%0A# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE%0A# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER%0A# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,%0A# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN%0A# THE SOFTWARE.%0A%0Aimport unittest%0Afrom pledger.sorting import Sorting, MapSorting, ExpressionSorting%0Afrom pledger.parser import Parser%0Afrom datetime import date%0A%0A%0Aclass TestSorting(unittest.TestCase):%0A    def setUp(self):%0A        self.data = %5B3, 5, 1, 2, 7, 4, 9, 6, 0, 8%5D%0A        self.parser = Parser()%0A%0A    def testIdentitySorting(self):%0A        identity = Sorting(lambda x: x)%0A        self.assertEqual(self.data, identity(self.data))%0A%0A    def testSimpleSorting(self):%0A        s = Sorting(lambda x: sorted(x))%0A        self.assertEqual(range(10), s(self.data))%0A%0A    def testInvertedSorting(self):%0A        s = ~Sorting(lambda x: sorted(x))%0A        self.assertEqual(list(reversed(xrange(10))), s(self.data))%0A%0A    def testMapSorting(self):%0A        s = MapSorting(lambda x: x * (x - 4))%0A        self.assertEqual(%5B2, 3, 1, 4, 0, 5, 6, 7, 8, 9%5D, s(self.data))%0A%0A    def testExpressionSorting(self):%0A        s = ExpressionSorting(self.parser, %22record * (record - 4)%22)%0A        self.assertEqual(%5B2, 3, 1, 4, 0, 5, 6, 7, 8, 9%5D, s(self.data))%0A%0A    def testExpressionSortingWithDate(self):%0A        s = ExpressionSorting(self.parser, %22abs((record - date('2011/01/01')).days)%22)%0A        data = %5Bdate(2011, 2, 1), date(2010, 12, 15), date(2011, 9, 5), date(2010, 10, 2)%5D%0A        self.assertEqual(%0A            %5Bdate(2010, 12, 15), date(2011, 2, 1), date(2010, 10, 2), date(2011, 9, 5)%5D,%0A            s(data))%0A

Add sorting tests.