use tkmath;

class matrix3d_tests extends TestCase {
   Matrix3d a,b,c,d,u,z;
   Vector3d v;
   pre() {
      u.init(1,0,0,0,1,0,0,0,1);
      z.init(0,0,0,0,0,0,0,0,0);
      a.init(1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f);
      b.init(1.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f,8.0f,9.0f);
      c.init(2.0f,2.0f,2.0f,2.0f,2.0f,2.0f,2.0f,2.0f,2.0f);
      d.init(1.0f,2.0f,3.0f,4.0f,5.0f,6.0f,7.0f,8.0f,10.0f);
      v.init("2.71828182845905","3.14159265358979",1.5f);
   }
   public method getAdd() {
      return a+b;
   }
   public method getSub() {
      return a-b;
   }
   public method getMul() {
      return a*u;
   }
   public method getMuld() {
      Matrix3d helper=b;
      helper.muld(3.5f);
      return helper;
   }
   public method getMulv() {
      return u.mulv(v);
   }
   public method getAbs() {
   	return a.abs;
   }
   public method getUnit() {
   	Matrix3d helper=a;
	helper.unit();
	return helper;
   }
   public method getInvert() {
   	Matrix3d helper=d;
	helper.invert(); //when this works, det() is also working correctly
	return helper;
   }
   public method getTranspose() {
      Matrix3d helper=b;
      helper.transpose();
      return helper;
   }
   public method testAdd() {
      Matrix3d res;
      res.init(2.0f,3.0f,4.0f,5.0f,6.0f,7.0f,8.0f,9.0f,10.0f);
      assertObject(getAdd(),res,""+a+"+"+b+"="+res);
   }
   public method testSub() {
      Matrix3d res;
      res.init(0.0f,-1.0f,-2.0f,-3.0f,-4.0f,-5.0f,-6.0f,-7.0f,-8.0f);
      assertObject(getSub(),res,""+a+"-"+b+"="+res);
   }
   public method testMul() {
      assertObject(getMul(),a,""+a+"*"+u+"="+a);
   }
   public method testMuld() {
      Matrix3d res;
      res.init(3.5f,7.0f,10.5f,14.0f,17.5f,21.0f,24.5f,28.0f,31.5f);
      assertObject(getMuld(),res,"3.5*"+b+"="+res);
   }
   public method testMulv() {
      assertObject(getMulv(),v,""+u+"*"+v+"="+v);
   }
   public method testAbs() {
      assertFloat(getAbs(),3.0f,"abs("+a+")=3.0f");
   }
   public method testUnit() {
   	Matrix3d res;
	Double val=1.0f;
	val=val/3.0f;
	res.initRow(0,val,val,val); 
	res.initRow(1,val,val,val); 
	res.initRow(2,val,val,val); 
	assertObject(getUnit(),res,""+a+" normalized to "+res);
   }
   public method testInvert() {
   	assertObject(d*getInvert(),u,""+d+"*"+getInvert()+"="+u);
   }
   public method testTranspose() {
   	Matrix3d res;
	res.initCol(0,1.0f,2.0f,3.0f);
	res.initCol(1,4.0f,5.0f,6.0f);
	res.initCol(2,7.0f,8.0f,9.0f);
	assertObject(getTranspose(),res,""+b+" transposed to "+res);
   }
}

