示例#1
0
    def set_value_test(self):
        """Test if the new value is correctly set in the matrix."""
        rows = 2
        cols = 3
        data = [[1, 2, 3], [4, 5, 6]]
        matrix = Matrix(cols, rows)
        matrix.initialize(data, rowBased=True)
        # Change value at specified column/row
        matrix.set_value(1, 0, 10)
        matrix.set_value(2, 1, 9)

        # Test if the new value is set correctly
        self.assertEqual(matrix.matrix[1][0], 10)
        self.assertEqual(matrix.matrix[2][1], 9)
示例#2
0
    def set_value_test(self):
        """Test if the new value is correctly set in the matrix."""
        rows = 2
        cols = 3
        data = [
                    [1, 2, 3],
                    [4, 5, 6]
                ]
        matrix = Matrix(cols, rows)
        matrix.initialize(data, rowBased=True)
        # Change value at specified column/row
        matrix.set_value(1, 0, 10)
        matrix.set_value(2, 1, 9)

        # Test if the new value is set correctly
        self.assertEqual(matrix.matrix[1][0], 10)
        self.assertEqual(matrix.matrix[2][1], 9)
示例#3
0
    def equality_test(self):
        """Test the == operator for Matrix instances."""
        rows = 3
        cols = 2
        data = [[1, 2, 3], [4, 5, 6]]
        mtrx1 = Matrix(cols, rows)
        mtrx2 = Matrix(cols, rows)
        mtrx3 = Matrix(cols, rows)

        mtrx1.initialize(data, rowBased=False)
        mtrx2.initialize(data, rowBased=False)
        mtrx3.initialize(data, rowBased=False)

        # change value at one postion
        mtrx2.set_value(1, 2, 4)
        # same value as float -> Matrix should still be equal
        mtrx3.set_value(0, 1, 2.0)
        self.assertTrue(mtrx1 == mtrx3)
        self.assertTrue(mtrx1 != mtrx2)
        self.assertTrue(mtrx2 != mtrx3)
示例#4
0
    def copy_test(self):
        """Test to clone the Matrix."""
        # Initialize Test Objects
        rows = 2
        cols = 3
        data = [[1, 2, 3], [4, 5, 6]]
        mtrx = Matrix(cols, rows)
        mtrx.initialize(data, rowBased=True)
        mtrx.optimizationEnabled = True
        # Execute copy
        cp = copy(mtrx)

        # Test assertion
        self.assertEqual(cp, mtrx)

        # Changing values of mtrx should not affect cp
        mtrx.set_value(2, 0, 10)
        mtrx.optimizationEnabled = False
        self.assertNotEqual(cp, mtrx)
        self.assertNotEqual(mtrx.get_value(2, 0), cp.get_value(2, 0))
        self.assertTrue(cp.optimizationEnabled)
示例#5
0
    def equality_test(self):
        """Test the == operator for Matrix instances."""
        rows = 3
        cols = 2
        data = [
                    [1, 2, 3],
                    [4, 5, 6]
                ]
        mtrx1 = Matrix(cols, rows)
        mtrx2 = Matrix(cols, rows)
        mtrx3 = Matrix(cols, rows)

        mtrx1.initialize(data, rowBased=False)
        mtrx2.initialize(data, rowBased=False)
        mtrx3.initialize(data, rowBased=False)

        # change value at one postion
        mtrx2.set_value(1, 2, 4)
        # same value as float -> Matrix should still be equal
        mtrx3.set_value(0, 1, 2.0)
        self.assertTrue(mtrx1 == mtrx3)
        self.assertTrue(mtrx1 != mtrx2)
        self.assertTrue(mtrx2 != mtrx3)
示例#6
0
    def copy_test(self):
        """Test to clone the Matrix."""
        # Initialize Test Objects
        rows = 2
        cols = 3
        data = [
                    [1, 2, 3],
                    [4, 5, 6]
                ]
        mtrx = Matrix(cols, rows)
        mtrx.initialize(data, rowBased=True)
        mtrx.optimizationEnabled = True
        # Execute copy
        cp = copy(mtrx)

        # Test assertion
        self.assertEqual(cp, mtrx)

        # Changing values of mtrx should not affect cp
        mtrx.set_value(2, 0, 10)
        mtrx.optimizationEnabled = False
        self.assertNotEqual(cp, mtrx)
        self.assertNotEqual(mtrx.get_value(2, 0), cp.get_value(2, 0))
        self.assertTrue(cp.optimizationEnabled)