Пример #1
0
    def matrix_string_representation_with_precision_test(self):
        """Test if the precision is set correctly and used when printing a Matrix.
        """
        size = 2
        data = [
                    [1.0123343,    -2.012341234123],
                    [3.04674567566, 4.012341234120]
                ]
        mtrx = Matrix(size, size)
        mtrx.initialize(data, rowBased=True)
        mtrx.set_string_precision(4)
        rep = mtrx.__str__()
        # should print the number with 4 digits after decimal point
        self.assertTrue(rep.find(" 3.0467 ") >= 0)
        self.assertTrue(rep.find(" -2.0123") >= 0)

        # but should not print the full number
        self.assertFalse(rep.find(" 3.04674567566") >= 0)
        self.assertFalse(rep.find(" -2.012341234123 ") >= 0)

        # change precision
        mtrx.set_string_precision(2)
        rep = mtrx.__str__()
        print mtrx
        # should print the number with 2 digits after decimal point
        # numbers should be rounded
        self.assertTrue(rep.find(" 3.05 ") >= 0)
        self.assertTrue(rep.find(" -2.01") >= 0)
Пример #2
0
    def matrix_string_representation_with_precision_test(self):
        """Test if the precision is set correctly and used when printing a Matrix.
        """
        size = 2
        data = [[1.0123343, -2.012341234123], [3.04674567566, 4.012341234120]]
        mtrx = Matrix(size, size)
        mtrx.initialize(data, rowBased=True)
        mtrx.set_string_precision(4)
        rep = mtrx.__str__()
        # should print the number with 4 digits after decimal point
        self.assertTrue(rep.find(" 3.0467 ") >= 0)
        self.assertTrue(rep.find(" -2.0123") >= 0)

        # but should not print the full number
        self.assertFalse(rep.find(" 3.04674567566") >= 0)
        self.assertFalse(rep.find(" -2.012341234123 ") >= 0)

        # change precision
        mtrx.set_string_precision(2)
        rep = mtrx.__str__()
        print mtrx
        # should print the number with 2 digits after decimal point
        # numbers should be rounded
        self.assertTrue(rep.find(" 3.05 ") >= 0)
        self.assertTrue(rep.find(" -2.01") >= 0)
Пример #3
0
 def matrix_string_representation_test(self):
     """Test the String representation of a Matrix instance."""
     matrix = Matrix(2, 2)
     a = [[1, 2], [-3, 4]]
     matrix.initialize(a, rowBased=True)
     rep = matrix.__str__()
     self.assertTrue(rep.find("  1.0") >= 0)
     self.assertTrue(rep.find(" -3.0") >= 0)
     # only one space before a negative number
     self.assertFalse(rep.find("  -3.0") >= 0)
     self.assertTrue(rep.find("Matrix") >= 0)
Пример #4
0
 def matrix_string_representation_test(self):
     """Test the String representation of a Matrix instance."""
     matrix = Matrix(2, 2)
     a = [[1, 2], [-3, 4]]
     matrix.initialize(a, rowBased=True)
     rep = matrix.__str__()
     self.assertTrue(rep.find("  1.0") >= 0)
     self.assertTrue(rep.find(" -3.0") >= 0)
     # only one space before a negative number
     self.assertFalse(rep.find("  -3.0") >= 0)
     self.assertTrue(rep.find("Matrix") >= 0)