Esempio n. 1
0
 def matrix_to_multi_dim_timeseries_test(self):
     """Test to create a Timeseries from a Matrix."""
     rows = 5
     cols = 3
     data = [
                 [2.4, 4.5, 6.1],
                 [3.6, 3.2, 9.4],
                 [5.6, 3.2, 8.7],
                 [4.3, 7.1, 3.3],
                 [7.2, 9.6, 0.3]
             ]
     mtrx = Matrix(cols, rows)
     mtrx.initialize(data, True)
     ts = mtrx.to_multi_dim_timeseries()
     tsData = [
                 [0, [2.4, 4.5, 6.1]],
                 [1, [3.6, 3.2, 9.4]],
                 [2, [5.6, 3.2, 8.7]],
                 [3, [4.3, 7.1, 3.3]],
                 [4, [7.2, 9.6, 0.3]]
             ]
     exTs = MDTS.from_twodim_list(tsData, dimensions=3)
     # expecting that TimeSeries.from_twodom_list() works properly
     self.assertEqual(ts, exTs)
     # Changing entries of the timeseries, should not affect matrix
     row = 3
     ts[row] = [row, 4, 3, 1]
     for col in xrange(cols):
         self.assertEqual(mtrx.get_value(col, row), data[row][col])
Esempio n. 2
0
    def get_array_test(self):
        """Test if get_array method returns an array with the correct values."""
        rows = 2
        cols = 3
        data = [[1, 2, 3], [4, 5, 6]]
        matrix = Matrix(cols, rows)
        matrix.initialize(data, rowBased=True)

        for row in xrange(rows):
            for col in xrange(cols):
                self.assertEqual(matrix.get_value(col, row), data[row][col])
Esempio n. 3
0
    def get_value_test(self):
        """Test if the correct value of the Matrix is returned."""
        rows = 2
        cols = 3
        data = [[1, 2, 3], [4, 5, 6]]
        matrix = Matrix(cols, rows)
        matrix.initialize(data, rowBased=True)

        val1 = matrix.get_value(1, 0)
        val2 = matrix.get_value(2, 1)

        self.assertEqual(val1, 2)
        self.assertEqual(val2, 6)
Esempio n. 4
0
    def get_array_test(self):
        """Test if get_array method returns an array with the correct values."""
        rows = 2
        cols = 3
        data = [
                    [1, 2, 3],
                    [4, 5, 6]
                ]
        matrix = Matrix(cols, rows)
        matrix.initialize(data, rowBased=True)

        for row in xrange(rows):
            for col in xrange(cols):
                self.assertEqual(matrix.get_value(col, row), data[row][col])
Esempio n. 5
0
    def get_value_test(self):
        """Test if the correct value of the Matrix is returned."""
        rows = 2
        cols = 3
        data = [
                    [1, 2, 3],
                    [4, 5, 6]
                ]
        matrix = Matrix(cols, rows)
        matrix.initialize(data, rowBased=True)

        val1 = matrix.get_value(1, 0)
        val2 = matrix.get_value(2, 1)

        self.assertEqual(val1, 2)
        self.assertEqual(val2, 6)
Esempio n. 6
0
 def matrix_to_multi_dim_timeseries_test(self):
     """Test to create a Timeseries from a Matrix."""
     rows = 5
     cols = 3
     data = [[2.4, 4.5, 6.1], [3.6, 3.2, 9.4], [5.6, 3.2, 8.7],
             [4.3, 7.1, 3.3], [7.2, 9.6, 0.3]]
     mtrx = Matrix(cols, rows)
     mtrx.initialize(data, True)
     ts = mtrx.to_multi_dim_timeseries()
     tsData = [[0, [2.4, 4.5, 6.1]], [1, [3.6, 3.2, 9.4]],
               [2, [5.6, 3.2, 8.7]], [3, [4.3, 7.1, 3.3]],
               [4, [7.2, 9.6, 0.3]]]
     exTs = MDTS.from_twodim_list(tsData, dimensions=3)
     # expecting that TimeSeries.from_twodom_list() works properly
     self.assertEqual(ts, exTs)
     # Changing entries of the timeseries, should not affect matrix
     row = 3
     ts[row] = [row, 4, 3, 1]
     for col in xrange(cols):
         self.assertEqual(mtrx.get_value(col, row), data[row][col])
Esempio n. 7
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)
Esempio n. 8
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)