MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_float_operation

Method test_float_operation

Lib/test/test_decimal.py:3986–4037  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3984
3985 @requires_IEEE_754
3986 def test_float_operation(self):
3987 Decimal = self.decimal.Decimal
3988 FloatOperation = self.decimal.FloatOperation
3989 localcontext = self.decimal.localcontext
3990
3991 with localcontext() as c:
3992 ##### trap is off by default
3993 self.assertFalse(c.traps[FloatOperation])
3994
3995 # implicit conversion sets the flag
3996 c.clear_flags()
3997 self.assertEqual(Decimal(7.5), 7.5)
3998 self.assertTrue(c.flags[FloatOperation])
3999
4000 c.clear_flags()
4001 self.assertEqual(c.create_decimal(7.5), 7.5)
4002 self.assertTrue(c.flags[FloatOperation])
4003
4004 # explicit conversion does not set the flag
4005 c.clear_flags()
4006 x = Decimal.from_float(7.5)
4007 self.assertFalse(c.flags[FloatOperation])
4008 # comparison sets the flag
4009 self.assertEqual(x, 7.5)
4010 self.assertTrue(c.flags[FloatOperation])
4011
4012 c.clear_flags()
4013 x = c.create_decimal_from_float(7.5)
4014 self.assertFalse(c.flags[FloatOperation])
4015 self.assertEqual(x, 7.5)
4016 self.assertTrue(c.flags[FloatOperation])
4017
4018 ##### set the trap
4019 c.traps[FloatOperation] = True
4020
4021 # implicit conversion raises
4022 c.clear_flags()
4023 self.assertRaises(FloatOperation, Decimal, 7.5)
4024 self.assertTrue(c.flags[FloatOperation])
4025
4026 c.clear_flags()
4027 self.assertRaises(FloatOperation, c.create_decimal, 7.5)
4028 self.assertTrue(c.flags[FloatOperation])
4029
4030 # explicit conversion is silent
4031 c.clear_flags()
4032 x = Decimal.from_float(7.5)
4033 self.assertFalse(c.flags[FloatOperation])
4034
4035 c.clear_flags()
4036 x = c.create_decimal_from_float(7.5)
4037 self.assertFalse(c.flags[FloatOperation])
4038
4039 def test_float_comparison(self):
4040 Decimal = self.decimal.Decimal

Callers

nothing calls this directly

Calls 10

localcontextFunction · 0.85
DecimalClass · 0.85
assertFalseMethod · 0.80
clear_flagsMethod · 0.80
assertTrueMethod · 0.80
create_decimalMethod · 0.80
assertEqualMethod · 0.45
from_floatMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected