viff

changeset 758:5c83d5ff31fa

Added support for inequality tests of field elements. Previously the result was the comparison of object identities, which meant that GF256(1) != GF256(1) was True.
author Martin Geisler <mg@daimi.au.dk>
date Wed, 14 May 2008 16:15:51 +0200
parents 585e6f4c7c77
children 16fe2bd2edec
files viff/field.py
diffstat 1 files changed, 14 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/viff/field.py	Wed May 14 16:09:30 2008 +0200
     1.2 +++ b/viff/field.py	Wed May 14 16:15:51 2008 +0200
     1.3 @@ -257,6 +257,12 @@
     1.4              other = other.value
     1.5          return self.value == other
     1.6  
     1.7 +    def __ne__(self, other):
     1.8 +        """Inequality testing."""
     1.9 +        if isinstance(other, GF256):
    1.10 +            other = other.value
    1.11 +        return self.value != other
    1.12 +
    1.13      def __hash__(self):
    1.14          """Hash value."""
    1.15          return hash((self.field, self.value))
    1.16 @@ -463,6 +469,14 @@
    1.17              except AttributeError:
    1.18                  return self.value == other
    1.19  
    1.20 +        def __ne__(self, other):
    1.21 +            """Inequality test."""
    1.22 +            try:
    1.23 +                assert self.field is other.field, "Fields must be identical"
    1.24 +                return self.value != other.value
    1.25 +            except AttributeError:
    1.26 +                return self.value != other
    1.27 +
    1.28          def __cmp__(self, other):
    1.29              """Comparison."""
    1.30              try: