summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_decimal.py
diff options
context:
space:
mode:
authorFacundo Batista <facundobatista@gmail.com>2007-10-02 17:01:24 (GMT)
committerFacundo Batista <facundobatista@gmail.com>2007-10-02 17:01:24 (GMT)
commit1a191df14dc2f37933ef32f553fcaa7a5ac77cf7 (patch)
treeca894139a8f401a3ab8eaa158708920aa9b584c8 /Lib/test/test_decimal.py
parent31ba8480d823f2c424d77ccd8c446b79ca48c1ce (diff)
downloadcpython-1a191df14dc2f37933ef32f553fcaa7a5ac77cf7.zip
cpython-1a191df14dc2f37933ef32f553fcaa7a5ac77cf7.tar.gz
cpython-1a191df14dc2f37933ef32f553fcaa7a5ac77cf7.tar.bz2
Made the various is_* operations return booleans. This was discussed
with Cawlishaw by mail, and he basically confirmed that to these is_* operations, there's no need to return Decimal(0) and Decimal(1) if the language supports the False and True booleans. Also added a few tests for the these functions in extra.decTest, since they are mostly untested (apart from the doctests). Thanks Mark Dickinson
Diffstat (limited to 'Lib/test/test_decimal.py')
-rw-r--r--Lib/test/test_decimal.py52
1 files changed, 39 insertions, 13 deletions
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py
index 1647212..e4b0ae5 100644
--- a/Lib/test/test_decimal.py
+++ b/Lib/test/test_decimal.py
@@ -95,35 +95,61 @@ RoundingDict = {'ceiling' : ROUND_CEILING, #Maps test-case names to roundings.
# Name adapter to be able to change the Decimal and Context
# interface without changing the test files from Cowlishaw
-nameAdapter = {'toeng':'to_eng_string',
- 'tosci':'to_sci_string',
- 'samequantum':'same_quantum',
- 'tointegral':'to_integral_value',
- 'tointegralx':'to_integral_exact',
- 'remaindernear':'remainder_near',
- 'divideint':'divide_int',
- 'squareroot':'sqrt',
+nameAdapter = {'and':'logical_and',
'apply':'_apply',
'class':'number_class',
'comparesig':'compare_signal',
'comparetotal':'compare_total',
'comparetotmag':'compare_total_mag',
- 'copyabs':'copy_abs',
'copy':'copy_decimal',
+ 'copyabs':'copy_abs',
'copynegate':'copy_negate',
'copysign':'copy_sign',
- 'and':'logical_and',
- 'or':'logical_or',
- 'xor':'logical_xor',
+ 'divideint':'divide_int',
'invert':'logical_invert',
+ 'iscanonical':'is_canonical',
+ 'isfinite':'is_finite',
+ 'isinfinite':'is_infinite',
+ 'isnan':'is_nan',
+ 'isnormal':'is_normal',
+ 'isqnan':'is_qnan',
+ 'issigned':'is_signed',
+ 'issnan':'is_snan',
+ 'issubnormal':'is_subnormal',
+ 'iszero':'is_zero',
'maxmag':'max_mag',
'minmag':'min_mag',
'nextminus':'next_minus',
'nextplus':'next_plus',
'nexttoward':'next_toward',
+ 'or':'logical_or',
'reduce':'normalize',
+ 'remaindernear':'remainder_near',
+ 'samequantum':'same_quantum',
+ 'squareroot':'sqrt',
+ 'toeng':'to_eng_string',
+ 'tointegral':'to_integral_value',
+ 'tointegralx':'to_integral_exact',
+ 'tosci':'to_sci_string',
+ 'xor':'logical_xor',
}
+# The following functions return True/False rather than a Decimal instance
+
+LOGICAL_FUNCTIONS = (
+ 'is_canonical',
+ 'is_finite',
+ 'is_infinite',
+ 'is_nan',
+ 'is_normal',
+ 'is_qnan',
+ 'is_signed',
+ 'is_snan',
+ 'is_subnormal',
+ 'is_zero',
+ 'same_quantum',
+ )
+
# For some operations (currently exp, ln, log10, power), the decNumber
# reference implementation imposes additional restrictions on the
# context and operands. These restrictions are not part of the
@@ -321,7 +347,7 @@ class DecimalTest(unittest.TestCase):
print "--", self.context
try:
result = str(funct(*vals))
- if fname == 'same_quantum':
+ if fname in LOGICAL_FUNCTIONS:
result = str(int(eval(result))) # 'True', 'False' -> '1', '0'
except Signals, error:
self.fail("Raised %s in %s" % (error, s))