예제 #1
0
    def test_transpose(self):
        m = Matrix(3,2)
        m[0,0] = 0
        m[1,0] = 2
        m[2,0] = 4

        m[0,1] = 1
        m[1,1] = 3
        m[2,1] = 5
        
        mt = m.transpose( ) 
        
        self.assertEqual(m[0,0] , 0)
        self.assertEqual(m[1,0] , 2)
        self.assertEqual(m[2,0] , 4)

        self.assertEqual(m[0,1] , 1)
        self.assertEqual(m[1,1] , 3)
        self.assertEqual(m[2,1] , 5)

        self.assertEqual( mt.rows() , m.columns())
        self.assertEqual( mt.columns() , m.rows())
        self.assertEqual(mt[0,0] , 0)
        self.assertEqual(mt[1,0] , 1)

        self.assertEqual(mt[0,1] , 2)
        self.assertEqual(mt[1,1] , 3)

        self.assertEqual(mt[0,2] , 4)
        self.assertEqual(mt[1,2] , 5)
        
        m.transpose( inplace = True )
        self.assertEqual( m , mt )
예제 #2
0
    def test_matrix(self):
        m = Matrix(2, 3)

        self.assertEqual(m.rows(), 2)
        self.assertEqual(m.columns(), 3)

        self.assertEqual(m[(0, 0)], 0)

        m[(1, 1)] = 1.5
        self.assertEqual(m[(1, 1)], 1.5)

        m[1,0] = 5
        self.assertEqual(m[1, 0], 5)

        with self.assertRaises(TypeError):
            m[5] = 5

        with self.assertRaises(IndexError):
            m[2, 0] = 0

        with self.assertRaises(IndexError):
            m[0, 3] = 0