(self)
| 2741 | self.assertEqual(x, float(MyDecimal.from_float(x))) # roundtrip |
| 2742 | |
| 2743 | def test_create_decimal_from_float(self): |
| 2744 | Decimal = self.decimal.Decimal |
| 2745 | Context = self.decimal.Context |
| 2746 | Inexact = self.decimal.Inexact |
| 2747 | |
| 2748 | context = Context(prec=5, rounding=ROUND_DOWN) |
| 2749 | self.assertEqual( |
| 2750 | context.create_decimal_from_float(math.pi), |
| 2751 | Decimal('3.1415') |
| 2752 | ) |
| 2753 | context = Context(prec=5, rounding=ROUND_UP) |
| 2754 | self.assertEqual( |
| 2755 | context.create_decimal_from_float(math.pi), |
| 2756 | Decimal('3.1416') |
| 2757 | ) |
| 2758 | context = Context(prec=5, traps=[Inexact]) |
| 2759 | self.assertRaises( |
| 2760 | Inexact, |
| 2761 | context.create_decimal_from_float, |
| 2762 | math.pi |
| 2763 | ) |
| 2764 | self.assertEqual(repr(context.create_decimal_from_float(-0.0)), |
| 2765 | "Decimal('-0')") |
| 2766 | self.assertEqual(repr(context.create_decimal_from_float(1.0)), |
| 2767 | "Decimal('1')") |
| 2768 | self.assertEqual(repr(context.create_decimal_from_float(10)), |
| 2769 | "Decimal('10')") |
| 2770 | |
| 2771 | def test_quantize(self): |
| 2772 | Decimal = self.decimal.Decimal |
nothing calls this directly
no test coverage detected