MCPcopy Index your code
hub / github.com/python/cpython / test_quantize

Method test_quantize

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

Source from the content-addressed store, hash-verified

2769 "Decimal('10')")
2770
2771 def test_quantize(self):
2772 Decimal = self.decimal.Decimal
2773 Context = self.decimal.Context
2774 InvalidOperation = self.decimal.InvalidOperation
2775
2776 c = Context(Emax=99999, Emin=-99999)
2777 self.assertEqual(
2778 Decimal('7.335').quantize(Decimal('.01')),
2779 Decimal('7.34')
2780 )
2781 self.assertEqual(
2782 Decimal('7.335').quantize(Decimal('.01'), rounding=ROUND_DOWN),
2783 Decimal('7.33')
2784 )
2785 self.assertRaises(
2786 InvalidOperation,
2787 Decimal("10e99999").quantize, Decimal('1e100000'), context=c
2788 )
2789
2790 c = Context()
2791 d = Decimal("0.871831e800")
2792 x = d.quantize(context=c, exp=Decimal("1e797"), rounding=ROUND_DOWN)
2793 self.assertEqual(x, Decimal('8.71E+799'))
2794
2795 def test_complex(self):
2796 Decimal = self.decimal.Decimal

Callers

nothing calls this directly

Calls 5

quantizeMethod · 0.95
DecimalClass · 0.85
ContextClass · 0.70
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected