Exemplo n.º 1
0
    def test_print_matrix(self):
        """``print_matrix`` prints nested lists as nice matrices."""
        import sys
        from io import StringIO

        out = StringIO()
        sys.stdout = out
        pairwise2.print_matrix([
            [0.0, -1.0, -1.5, -2.0],
            [-1.0, 4.0, 3.0, 2.5],
            [-1.5, 3.0, 8.0, 7.0],
            [-2.0, 2.5, 7.0, 6.0],
            [-2.5, 2.0, 6.5, 11.0],
            [-3.0, 1.5, 6.0, 10.0],
        ])
        self.assertEqual(
            out.getvalue(),
            " 0.0  -1.0  -1.5  -2.0 \n"
            "-1.0   4.0   3.0   2.5 \n"
            "-1.5   3.0   8.0   7.0 \n"
            "-2.0   2.5   7.0   6.0 \n"
            "-2.5   2.0   6.5  11.0 \n"
            "-3.0   1.5   6.0  10.0 \n",
        )
        sys.stdout = sys.__stdout__
Exemplo n.º 2
0
    def test_print_matrix(self):
        """``print_matrix`` prints nested lists as nice matrices."""
        import sys

        try:  # Python 2
            from StringIO import StringIO
        except ImportError:  # Python 3
            from io import StringIO
        out = StringIO()
        sys.stdout = out
        pairwise2.print_matrix([[0.0, -1.0, -1.5, -2.0], [-1.0, 4.0, 3.0, 2.5],
                                [-1.5, 3.0, 8.0, 7.0], [-2.0, 2.5, 7.0, 6.0],
                                [-2.5, 2.0, 6.5, 11.0], [-3.0, 1.5, 6.0,
                                                         10.0]])
        self.assertEqual(
            out.getvalue(), ' 0.0  -1.0  -1.5  -2.0 \n'
            '-1.0   4.0   3.0   2.5 \n'
            '-1.5   3.0   8.0   7.0 \n'
            '-2.0   2.5   7.0   6.0 \n'
            '-2.5   2.0   6.5  11.0 \n'
            '-3.0   1.5   6.0  10.0 \n')
        sys.stdout = sys.__stdout__
Exemplo n.º 3
0
    def test_print_matrix(self):
        """``print_matrix`` prints nested lists as nice matrices."""
        import sys

        try:  # Python 2
            from StringIO import StringIO
        except ImportError:  # Python 3
            from io import StringIO
        out = StringIO()
        sys.stdout = out
        pairwise2.print_matrix([[0.0, -1.0, -1.5, -2.0], [-1.0, 4.0, 3.0, 2.5],
                                [-1.5, 3.0, 8.0, 7.0], [-2.0, 2.5, 7.0, 6.0],
                                [-2.5, 2.0, 6.5, 11.0],
                                [-3.0, 1.5, 6.0, 10.0]])
        self.assertEqual(out.getvalue(),
                         ' 0.0  -1.0  -1.5  -2.0 \n'
                         '-1.0   4.0   3.0   2.5 \n'
                         '-1.5   3.0   8.0   7.0 \n'
                         '-2.0   2.5   7.0   6.0 \n'
                         '-2.5   2.0   6.5  11.0 \n'
                         '-3.0   1.5   6.0  10.0 \n')
        sys.stdout = sys.__stdout__