From 1d65f372c2e74bf5b75708f688dfadbb0efdad84 Mon Sep 17 00:00:00 2001 From: Michael Urman Date: Mon, 17 Apr 2006 02:16:50 +0000 Subject: [PATCH] Add intnum tests; test_cmp is failing right now and needs a source fix. svn path=/trunk/yasm/; revision=1499 --- tools/python-yasm/tests/Makefile.inc | 1 + tools/python-yasm/tests/__init__.py | 1 + tools/python-yasm/tests/test_intnum.py | 57 ++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 tools/python-yasm/tests/test_intnum.py diff --git a/tools/python-yasm/tests/Makefile.inc b/tools/python-yasm/tests/Makefile.inc index 440d4e1c..4286601d 100644 --- a/tools/python-yasm/tests/Makefile.inc +++ b/tools/python-yasm/tests/Makefile.inc @@ -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 diff --git a/tools/python-yasm/tests/__init__.py b/tools/python-yasm/tests/__init__.py index ed76de61..bb51143e 100644 --- a/tools/python-yasm/tests/__init__.py +++ b/tools/python-yasm/tests/__init__.py @@ -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 index 00000000..b700da70 --- /dev/null +++ b/tools/python-yasm/tests/test_intnum.py @@ -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) -- 2.50.0