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 wrap: on
line diff
--- a/viff/field.py	Wed May 14 16:09:30 2008 +0200
+++ b/viff/field.py	Wed May 14 16:15:51 2008 +0200
@@ -257,6 +257,12 @@
             other = other.value
         return self.value == other
 
+    def __ne__(self, other):
+        """Inequality testing."""
+        if isinstance(other, GF256):
+            other = other.value
+        return self.value != other
+
     def __hash__(self):
         """Hash value."""
         return hash((self.field, self.value))
@@ -463,6 +469,14 @@
             except AttributeError:
                 return self.value == other
 
+        def __ne__(self, other):
+            """Inequality test."""
+            try:
+                assert self.field is other.field, "Fields must be identical"
+                return self.value != other.value
+            except AttributeError:
+                return self.value != other
+
         def __cmp__(self, other):
             """Comparison."""
             try: