[pypy-commit] pypy decimal-libmpdec: More Context operations
amauryfa
noreply at buildbot.pypy.org
Sat May 17 11:56:45 CEST 2014
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: decimal-libmpdec
Changeset: r71549:4c93df5ea053
Date: 2014-05-11 15:00 +0200
http://bitbucket.org/pypy/pypy/changeset/4c93df5ea053/
Log: More Context operations
diff --git a/pypy/module/_decimal/interp_context.py b/pypy/module/_decimal/interp_context.py
--- a/pypy/module/_decimal/interp_context.py
+++ b/pypy/module/_decimal/interp_context.py
@@ -221,7 +221,12 @@
def add_w(self, space, w_x, w_y):
return self.binary_method(space, rmpdec.mpd_qadd, w_x, w_y)
-
+ def subtract_w(self, space, w_x, w_y):
+ return self.binary_method(space, rmpdec.mpd_qsub, w_x, w_y)
+ def multiply_w(self, space, w_x, w_y):
+ return self.binary_method(space, rmpdec.mpd_qmul, w_x, w_y)
+ def divide_w(self, space, w_x, w_y):
+ return self.binary_method(space, rmpdec.mpd_qdiv, w_x, w_y)
def descr_new_context(space, w_subtype, __args__):
@@ -250,6 +255,9 @@
create_decimal=interp2app(W_Context.create_decimal_w),
# Operations
add=interp2app(W_Context.add_w),
+ subtract=interp2app(W_Context.subtract_w),
+ multiply=interp2app(W_Context.multiply_w),
+ divide=interp2app(W_Context.divide_w),
)
diff --git a/pypy/module/_decimal/test/test_decimal.py b/pypy/module/_decimal/test/test_decimal.py
--- a/pypy/module/_decimal/test/test_decimal.py
+++ b/pypy/module/_decimal/test/test_decimal.py
@@ -449,5 +449,38 @@
raises(TypeError, c.add, '1', 1)
raises(TypeError, c.add, 1, '1')
-
+ def test_subtract(self):
+ Decimal = self.decimal.Decimal
+ Context = self.decimal.Context
+ c = Context()
+ d = c.subtract(Decimal(1), Decimal(2))
+ assert c.subtract(1, 2) == d
+ assert c.subtract(Decimal(1), 2) == d
+ assert c.subtract(1, Decimal(2)) == d
+ raises(TypeError, c.subtract, '1', 2)
+ raises(TypeError, c.subtract, 1, '2')
+
+ def test_multiply(self):
+ Decimal = self.decimal.Decimal
+ Context = self.decimal.Context
+
+ c = Context()
+ d = c.multiply(Decimal(1), Decimal(2))
+ assert c.multiply(1, 2)== d
+ assert c.multiply(Decimal(1), 2)== d
+ assert c.multiply(1, Decimal(2))== d
+ raises(TypeError, c.multiply, '1', 2)
+ raises(TypeError, c.multiply, 1, '2')
+
+ def test_divide(self):
+ Decimal = self.decimal.Decimal
+ Context = self.decimal.Context
+
+ c = Context()
+ d = c.divide(Decimal(1), Decimal(2))
+ assert c.divide(1, 2)== d
+ assert c.divide(Decimal(1), 2)== d
+ assert c.divide(1, Decimal(2))== d
+ raises(TypeError, c.divide, '1', 2)
+ raises(TypeError, c.divide, 1, '2')
More information about the pypy-commit
mailing list