]> granicus.if.org Git - yasm/commitdiff
Add intnum tests; test_cmp is failing right now and needs a source fix.
authorMichael Urman <mu@tortall.net>
Mon, 17 Apr 2006 02:16:50 +0000 (02:16 -0000)
committerMichael Urman <mu@tortall.net>
Mon, 17 Apr 2006 02:16:50 +0000 (02:16 -0000)
svn path=/trunk/yasm/; revision=1499

tools/python-yasm/tests/Makefile.inc
tools/python-yasm/tests/__init__.py
tools/python-yasm/tests/test_intnum.py [new file with mode: 0644]

index 440d4e1c4c20e004fe90a3220dc576bd56d7cc2b..4286601d2429bd6d1120e14aae1cd214a987e135 100644 (file)
@@ -2,6 +2,7 @@
 
 EXTRA_DIST += tools/python-yasm/tests/python_test.sh
 EXTRA_DIST += tools/python-yasm/tests/__init__.py
+EXTRA_DIST += tools/python-yasm/tests/test_intnum.py
 EXTRA_DIST += tools/python-yasm/tests/test_symrec.py
 
 if HAVE_PYTHON
index ed76de61549b781415094ef3f553fe0a24cfbdbc..bb51143edaf4c9c8989a7e18392f1af828703c3e 100644 (file)
@@ -10,6 +10,7 @@ class Mock(object):
     # A generic mocking object.
     def __init__(self, **kwargs): self.__dict__.update(kwargs)
 
+import test_intnum
 import test_symrec
 
 class Result(unittest.TestResult):
diff --git a/tools/python-yasm/tests/test_intnum.py b/tools/python-yasm/tests/test_intnum.py
new file mode 100644 (file)
index 0000000..b700da7
--- /dev/null
@@ -0,0 +1,57 @@
+# $Id$
+from tests import TestCase, add
+from yasm import IntNum
+
+class TIntNum(TestCase):
+    legal_values = [
+        0, 1, -1, 2, -2, 17, -17,
+        2**31-1, -2**31, 2**31, 2**32-1, -2**32,
+        2**63-1, -2**63-1, 2**63, 2**64, -2**64,
+        2**127-1, -2**127
+    ]
+    overflow_values = [
+        2**127, -2**127-1
+    ]
+
+    def test_to_from(self):
+        for i in self.legal_values:
+            self.assertEquals(i, int(IntNum(i)))
+
+    def test_overflow(self):
+        for i in self.overflow_values:
+            self.assertRaises(OverflowError, IntNum, i)
+
+    def test_xor(self):
+        a = IntNum(-234)
+        b = IntNum(432)
+        c = a ^ b
+        self.assertEquals(a, -234)
+        self.assertEquals(b, 432)
+        self.assertEquals(c, -234 ^ 432)
+
+    def test_ixor(self):
+        a = IntNum(-234)
+        b = IntNum(432)
+        a ^= b; b ^= a; a ^= b
+        self.assertEquals(a, 432)
+        self.assertEquals(b, -234)
+
+    def test_cmp(self):
+        a = IntNum(-1)
+        b = IntNum(0)
+        c = IntNum(1)
+        self.assert_(a < b < c)
+        self.assert_(a <= b <= c)
+        self.assert_(c >= b >= a)
+        self.assert_(c > b > a)
+        self.assert_(a != b != c)
+
+    def test_abs(self):
+        a = IntNum(-1)
+        b = IntNum(0)
+        c = IntNum(1)
+
+        self.assertEquals(abs(a), abs(c))
+        self.assertEquals(abs(a) - abs(c), abs(b))
+
+add(TIntNum)