Ticket #9682: trac_9682_fix_perfectmatching_error_message_vf.patch

File trac_9682_fix_perfectmatching_error_message_vf.patch, 3.9 KB (added by vferay, 11 years ago)
  • sage/combinat/perfect_matching.py

    # HG changeset patch
    # User Valentin Feray <feray at labri.fr>
    # Date 1280898113 25200
    # Node ID 381e6da68c3699ad3548d02aab0a65fe432e5fa9
    # Parent  de336e4bb7de0af6d3daa67bca2c94099a1d3b32
    #9682: fixing error message and adding tests in perfect matchings
    
    diff --git a/sage/combinat/perfect_matching.py b/sage/combinat/perfect_matching.py
    a b REFERENCES: 
    5353#*****************************************************************************
    5454
    5555
    56 #from sage.combinat.permutation import Permutation_Class
    5756from sage.structure.unique_representation import UniqueRepresentation
    5857from sage.structure.parent import Parent
    5958from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
    from sage.structure.element import Eleme 
    6362from sage.misc.cachefunc import cached_method
    6463from sage.rings.integer import Integer
    6564from sage.misc.flatten import flatten
    66 from sage.combinat.permutation import Permutation
     65from sage.combinat.permutation import Permutation, Permutation_class
    6766from sage.sets.set import Set
    6867from sage.combinat.partition import Partition
    6968from sage.misc.misc_c import prod
    class PerfectMatching(ElementWrapper): 
    149148             sage: TestSuite(m).run()
    150149             sage: m=PerfectMatching([])
    151150             sage: TestSuite(m).run()
     151             sage: PerfectMatching(6)
     152             Traceback (most recent call last):
     153             ...
     154             ValueError: cannot convert p (= 6) to a PerfectMatching
     155             sage: PerfectMatching([(1,2,3)])
     156             Traceback (most recent call last):
     157             ...
     158             ValueError: [(1, 2, 3)] is not a valid perfect matching:
     159             all elements of the list must be pairs
     160             sage: PerfectMatching([(1,1)])
     161             Traceback (most recent call last):
     162             ...
     163             ValueError: [(1, 1)] is not a valid perfect matching:
     164             there are some repetitions
     165             sage: PerfectMatching(Permutation([4,2,1,3]))
     166             Traceback (most recent call last):
     167             ...
     168             ValueError: The permutation p (= [4, 2, 1, 3]) is not a fixed point free involution
    152169        """
    153170        # we have to extract from the argument p the set of objects of the
    154171        # matching and the list of pairs.
    class PerfectMatching(ElementWrapper): 
    159176            data=(map(tuple,p))
    160177            #check if the data are correct
    161178            if not all([len(t)==2 for t in data]):
    162                 raise ValueError, "%s is not a valid perfect matching: all elements of the list must be pairs"%p
     179                raise ValueError, ("%s is not a valid perfect matching:\n"
     180                    "all elements of the list must be pairs"%p)
    163181            if len(objects) < 2*len(data):
    164                 raise ValueError, "%s is not a valid perfect matching: there are some repetitions"%p
     182                raise ValueError, ("%s is not a valid perfect matching:\n"
     183                    "there are some repetitions"%p)
    165184        # Second case: p is a permutation or a list of integers, we have to
    166185        # check if it is a fix-point-free involution.
    167186        elif ((isinstance(p,list) and
    168187            all(map(lambda x: (isinstance(x,Integer) or isinstance(x,int)),p )))
    169             or isinstance(p,sage.combinat.permutation.Permutation_class)):
     188            or isinstance(p,Permutation_class)):
    170189            p=Permutation(p)
    171190            n=len(p)
    172191            if not(p.cycle_type()==[2 for i in range(n//2)]):
    173                 s="The permutation p (= %s) is not a fixpoint-free involution"%p
    174                 raise ValueError,s
     192                raise ValueError, ("The permutation p (= %s) is not a "
     193                        "fixed point free involution"%p)
    175194            objects=Set(range(1,n+1))
    176195            data=p.to_cycles()
    177196        # Third case: p is already a perfect matching, we return p directly