~ubuntu-branches/ubuntu/karmic/python3.0/karmic

« back to all changes in this revision

Viewing changes to Lib/test/list_tests.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-02-16 17:18:23 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20090216171823-1d5cm5qnnjvmnzzm
Tags: 3.0.1-0ubuntu1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
439
439
        self.assertRaises(TypeError, u.sort, 42, 42)
440
440
 
441
441
        def revcmp(a, b):
442
 
            return cmp(b, a)
 
442
            if a == b:
 
443
                return 0
 
444
            elif a < b:
 
445
                return 1
 
446
            else: # a > b
 
447
                return -1
443
448
        u.sort(key=CmpToKey(revcmp))
444
449
        self.assertEqual(u, self.type2test([2,1,0,-1,-2]))
445
450
 
446
451
        # The following dumps core in unpatched Python 1.5:
447
452
        def myComparison(x,y):
448
 
            return cmp(x%3, y%7)
 
453
            xmod, ymod = x%3, y%7
 
454
            if xmod == ymod:
 
455
                return 0
 
456
            elif xmod < ymod:
 
457
                return -1
 
458
            else: # xmod > ymod
 
459
                return 1
449
460
        z = self.type2test(range(12))
450
461
        z.sort(key=CmpToKey(myComparison))
451
462
 
453
464
 
454
465
        def selfmodifyingComparison(x,y):
455
466
            z.append(1)
456
 
            return cmp(x, y)
 
467
            if x == y:
 
468
                return 0
 
469
            elif x < y:
 
470
                return -1
 
471
            else: # x > y
 
472
                return 1
457
473
        self.assertRaises(ValueError, z.sort, key=CmpToKey(selfmodifyingComparison))
458
474
 
459
475
        self.assertRaises(TypeError, z.sort, 42, 42, 42, 42)