ExprMul::ExprMul(const ExprNode& left, const ExprNode& right) : ExprBinaryOp(left,right,mul_dim(left.dim,right.dim)) { }
void TestDim::mul() { Dim sca; Dim row2(Dim::row_vec(2)); Dim row3(Dim::row_vec(3)); Dim col2(Dim::col_vec(2)); Dim col3(Dim::col_vec(3)); Dim mat22(Dim::matrix(2,2)); Dim mat32(Dim::matrix(3,2)); Dim mat23(Dim::matrix(2,3)); Dim mat33(Dim::matrix(3,3)); CPPUNIT_ASSERT (mul_dim(sca,sca)==sca); CPPUNIT_ASSERT (mul_dim(sca,row2)==row2); CPPUNIT_ASSERT (mul_dim(sca,row3)==row3); CPPUNIT_ASSERT (mul_dim(sca,col2)==col2); CPPUNIT_ASSERT (mul_dim(sca,col3)==col3); CPPUNIT_ASSERT (mul_dim(sca,mat22)==mat22); CPPUNIT_ASSERT (mul_dim(sca,mat23)==mat23); CPPUNIT_ASSERT (mul_dim(sca,mat32)==mat32); CPPUNIT_ASSERT (mul_dim(sca,mat33)==mat33); CPPUNIT_ASSERT_THROW(mul_dim(row2,sca),DimException); CPPUNIT_ASSERT_THROW(mul_dim(row2,row2),DimException); CPPUNIT_ASSERT_THROW(mul_dim(row2,row3),DimException); CPPUNIT_ASSERT (mul_dim(row2,col2)==sca); CPPUNIT_ASSERT_THROW(mul_dim(row2,col3),DimException); CPPUNIT_ASSERT (mul_dim(row2,mat22)==row2); CPPUNIT_ASSERT_THROW(mul_dim(row2,mat32),DimException); CPPUNIT_ASSERT (mul_dim(row2,mat23)==row3); CPPUNIT_ASSERT_THROW(mul_dim(row2,mat33),DimException); CPPUNIT_ASSERT_THROW(mul_dim(row3,sca),DimException); CPPUNIT_ASSERT_THROW(mul_dim(row3,row2),DimException); CPPUNIT_ASSERT_THROW(mul_dim(row3,row3),DimException); CPPUNIT_ASSERT_THROW(mul_dim(row3,col2),DimException); CPPUNIT_ASSERT (mul_dim(row3,col3)==sca); CPPUNIT_ASSERT_THROW(mul_dim(row3,mat22),DimException); CPPUNIT_ASSERT (mul_dim(row3,mat32)==row2); CPPUNIT_ASSERT_THROW(mul_dim(row3,mat23),DimException); CPPUNIT_ASSERT (mul_dim(row3,mat33)==row3); CPPUNIT_ASSERT (mul_dim(col2,sca)==col2); CPPUNIT_ASSERT (mul_dim(col2,row2)==mat22); CPPUNIT_ASSERT (mul_dim(col2,row3)==mat23); CPPUNIT_ASSERT_THROW(mul_dim(col2,col2),DimException); CPPUNIT_ASSERT_THROW(mul_dim(col2,col3),DimException); CPPUNIT_ASSERT_THROW(mul_dim(col2,mat22),DimException); CPPUNIT_ASSERT_THROW(mul_dim(col2,mat32),DimException); CPPUNIT_ASSERT_THROW(mul_dim(col2,mat23),DimException); CPPUNIT_ASSERT_THROW(mul_dim(col2,mat33),DimException); CPPUNIT_ASSERT (mul_dim(col3,sca)==col3); CPPUNIT_ASSERT (mul_dim(col3,row2)==mat32); CPPUNIT_ASSERT (mul_dim(col3,row3)==mat33); CPPUNIT_ASSERT_THROW(mul_dim(col3,col2),DimException); CPPUNIT_ASSERT_THROW(mul_dim(col3,col3),DimException); CPPUNIT_ASSERT_THROW(mul_dim(col3,mat22),DimException); CPPUNIT_ASSERT_THROW(mul_dim(col3,mat32),DimException); CPPUNIT_ASSERT_THROW(mul_dim(col3,mat23),DimException); CPPUNIT_ASSERT_THROW(mul_dim(col3,mat33),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat22,sca),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat22,row2),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat22,row3),DimException); CPPUNIT_ASSERT (mul_dim(mat22,col2)==col2); CPPUNIT_ASSERT_THROW(mul_dim(mat22,col3),DimException); CPPUNIT_ASSERT (mul_dim(mat22,mat22)==mat22); CPPUNIT_ASSERT_THROW(mul_dim(mat22,mat32),DimException); CPPUNIT_ASSERT (mul_dim(mat22,mat23)==mat23); CPPUNIT_ASSERT_THROW(mul_dim(mat22,mat33),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat32,sca),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat32,row2),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat32,row3),DimException); CPPUNIT_ASSERT (mul_dim(mat32,col2)==col3); CPPUNIT_ASSERT_THROW(mul_dim(mat32,col3),DimException); CPPUNIT_ASSERT (mul_dim(mat32,mat22)==mat32); CPPUNIT_ASSERT_THROW(mul_dim(mat32,mat32),DimException); CPPUNIT_ASSERT (mul_dim(mat32,mat23)==mat33); CPPUNIT_ASSERT_THROW(mul_dim(mat32,mat33),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat23,sca),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat23,row2),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat23,row3),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat23,col2),DimException); CPPUNIT_ASSERT (mul_dim(mat23,col3)==col2); CPPUNIT_ASSERT_THROW(mul_dim(mat23,mat22),DimException); CPPUNIT_ASSERT (mul_dim(mat23,mat32)==mat22); CPPUNIT_ASSERT_THROW(mul_dim(mat23,mat23),DimException); CPPUNIT_ASSERT (mul_dim(mat23,mat33)==mat23); CPPUNIT_ASSERT_THROW(mul_dim(mat33,sca),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat33,row2),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat33,row3),DimException); CPPUNIT_ASSERT_THROW(mul_dim(mat33,col2),DimException); CPPUNIT_ASSERT (mul_dim(mat33,col3)==col3); CPPUNIT_ASSERT_THROW(mul_dim(mat33,mat22),DimException); CPPUNIT_ASSERT (mul_dim(mat33,mat32)==mat32); CPPUNIT_ASSERT_THROW(mul_dim(mat33,mat23),DimException); CPPUNIT_ASSERT (mul_dim(mat33,mat33)==mat33); }