Ejemplo n.º 1
0
    def test_fixed(self):
        p = poly.Polynomial([1 / 2])
        assert_equal(str(p), '0.5')

        with printoptions(floatmode='fixed'):
            assert_equal(str(p), '0.50000000')

        with printoptions(floatmode='fixed', precision=4):
            assert_equal(str(p), '0.5000')
Ejemplo n.º 2
0
 def test_linewidth_printoption(self, lw, tgt):
     p = poly.Polynomial(
         [0, 10, 200, 3000, 40000, 500000, 600000, 70000, 8000, 900])
     with printoptions(linewidth=lw):
         assert_equal(str(p), tgt)
         for line in str(p).split('\n'):
             assert_(len(line) < lw)
Ejemplo n.º 3
0
 def test_non_finite(self):
     p = poly.Polynomial([nan, inf])
     assert str(p) == 'nan + inf x'
     assert p._repr_latex_() == r'$x \mapsto \text{nan} + \text{inf}\,x$'
     with printoptions(nanstr='NAN', infstr='INF'):
         assert str(p) == 'NAN + INF x'
         assert p._repr_latex_() == \
             r'$x \mapsto \text{NAN} + \text{INF}\,x$'
Ejemplo n.º 4
0
    def test_str(self):
        p = poly.Polynomial([1 / 2, 1 / 7, 1 / 7 * 10**8, 1 / 7 * 10**9])
        assert_equal(
            str(p), '0.5 + 0.14285714 x + 14285714.28571429 x**2 '
            '+ (1.42857143e+08) x**3')

        with printoptions(precision=3):
            assert_equal(
                str(p), '0.5 + 0.143 x + 14285714.286 x**2 '
                '+ (1.429e+08) x**3')
Ejemplo n.º 5
0
    def test_latex(self):
        p = poly.Polynomial([1 / 2, 1 / 7, 1 / 7 * 10**8, 1 / 7 * 10**9])
        assert_equal(
            p._repr_latex_(),
            r'$x \mapsto \text{0.5} + \text{0.14285714}\,x + '
            r'\text{14285714.28571429}\,x^{2} + '
            r'\text{(1.42857143e+08)}\,x^{3}$')

        with printoptions(precision=3):
            assert_equal(
                p._repr_latex_(), r'$x \mapsto \text{0.5} + \text{0.143}\,x + '
                r'\text{14285714.286}\,x^{2} + \text{(1.429e+08)}\,x^{3}$')
Ejemplo n.º 6
0
 def test_switch_to_exp(self):
     for i, s in enumerate(SWITCH_TO_EXP):
         with printoptions(precision=i):
             p = poly.Polynomial(
                 [1.23456789 * 10**-i for i in range(i // 2 + 3)])
             assert str(p).replace('\n', ' ') == s