/* * Moonlight|3D Copyright (C) 2005 The Moonlight|3D team * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * Created on Jan 6, 2005 */ package ml.test; import junit.framework.TestCase; import ml.math.Matrix3; import ml.math.Vector3D; /** * This is the test case for ml.test.Matrix3 * * @author gregor */ public class Matrix3Test extends TestCase { public static void main(String[] args) { junit.awtui.TestRunner.run(Matrix3Test.class); } public void testMatrix3() { Matrix3 a=new Matrix3(); assertTrue(a.X!=null); for(int i=0;i<3;i++) { assertTrue(a.X[i]!=null); } } public void testClear() { Matrix3 a=new Matrix3(); a.clear(); for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { assertTrue(a.X[i][j]==0); } } } public void testEqual() { Matrix3 a=new Matrix3(); a.clear(); a.X[1][1]=2.0; Matrix3 b=new Matrix3(); b.clear(); assertTrue(a.equals(a)); assertTrue(!b.equals(a)); assertTrue(!a.equals(b)); } public void testClone() { Matrix3 a=new Matrix3(); a.clear(); a.X[1][1]=2.0; Matrix3 b=a.clone(); assertTrue(b.equals(a)); } public void testTranspose() { Matrix3 a, b; a=new Matrix3(); b=new Matrix3(); a.X[0][0]=1.0; a.X[0][1]=2.0; a.X[0][2]=3.0; a.X[1][0]=1.0; a.X[1][1]=2.0; a.X[1][2]=3.0; a.X[2][0]=1.0; a.X[2][1]=2.0; a.X[2][2]=3.0; b.X[0][0]=1.0; b.X[0][1]=1.0; b.X[0][2]=1.0; b.X[1][0]=2.0; b.X[1][1]=2.0; b.X[1][2]=2.0; b.X[2][0]=3.0; b.X[2][1]=3.0; b.X[2][2]=3.0; assertTrue(a.transpose().equals(b)); assertTrue(b.transpose().equals(a)); } public void testInvert() { Matrix3 a, b; a=new Matrix3(); a.X[0][0]=1.0; a.X[0][1]=0.0; a.X[0][2]=0.0; a.X[1][0]=0.0; a.X[1][1]=1.0; a.X[1][2]=0.0; a.X[2][0]=0.0; a.X[2][1]=0.0; a.X[2][2]=1.0; b=a.invert(); assertTrue(b.equals(a)); a.X[0][0]=1.0/3.0; b.X[0][0]=3.0; assertTrue(b.equals(a.invert())); } public void testDet() { Matrix3 a=new Matrix3(); a.X[0][0]=1.0; a.X[0][1]=2.0; a.X[0][2]=3.0; a.X[1][0]=1.0; a.X[1][1]=2.0; a.X[1][2]=3.0; a.X[2][0]=1.0; a.X[2][1]=2.0; a.X[2][2]=3.0; assertTrue(a.det()==0); } public void testAdd() { Matrix3 a, b, c; a=new Matrix3(); b=new Matrix3(); c=new Matrix3(); a.X[0][0]=1.0; a.X[0][1]=2.0; a.X[0][2]=3.0; a.X[1][0]=1.0; a.X[1][1]=2.0; a.X[1][2]=3.0; a.X[2][0]=1.0; a.X[2][1]=2.0; a.X[2][2]=3.0; b.X[0][0]=1.0; b.X[0][1]=1.0; b.X[0][2]=1.0; b.X[1][0]=2.0; b.X[1][1]=2.0; b.X[1][2]=2.0; b.X[2][0]=3.0; b.X[2][1]=3.0; b.X[2][2]=3.0; c.X[0][0]=2.0; c.X[0][1]=3.0; c.X[0][2]=4.0; c.X[1][0]=3.0; c.X[1][1]=4.0; c.X[1][2]=5.0; c.X[2][0]=4.0; c.X[2][1]=5.0; c.X[2][2]=6.0; assertTrue(a.add(b).equals(c)); } public void testSub() { Matrix3 a, b, c; a=new Matrix3(); b=new Matrix3(); c=new Matrix3(); a.X[0][0]=1.0; a.X[0][1]=2.0; a.X[0][2]=3.0; a.X[1][0]=1.0; a.X[1][1]=2.0; a.X[1][2]=3.0; a.X[2][0]=1.0; a.X[2][1]=2.0; a.X[2][2]=3.0; b.X[0][0]=1.0; b.X[0][1]=1.0; b.X[0][2]=1.0; b.X[1][0]=2.0; b.X[1][1]=2.0; b.X[1][2]=2.0; b.X[2][0]=3.0; b.X[2][1]=3.0; b.X[2][2]=3.0; c.X[0][0]= 0.0; c.X[0][1]= 1.0; c.X[0][2]=2.0; c.X[1][0]=-1.0; c.X[1][1]= 0.0; c.X[1][2]=1.0; c.X[2][0]=-2.0; c.X[2][1]=-1.0; c.X[2][2]=0.0; assertTrue(a.sub(b).equals(c)); } public void testMultiplyMatrix() { Matrix3 a, b, c; a=new Matrix3(); b=new Matrix3(); c=new Matrix3(); a.X[0][0]=1.0; a.X[0][1]=2.0; a.X[0][2]=3.0; a.X[1][0]=1.0; a.X[1][1]=2.0; a.X[1][2]=3.0; a.X[2][0]=1.0; a.X[2][1]=2.0; a.X[2][2]=6.0; b.X[0][0]=1.0; b.X[0][1]=1.0; b.X[0][2]=1.0; b.X[1][0]=2.0; b.X[1][1]=2.0; b.X[1][2]=2.0; b.X[2][0]=3.0; b.X[2][1]=3.0; b.X[2][2]=3.0; c.X[0][0]=14.0; c.X[0][1]=14.0; c.X[0][2]=14.0; c.X[1][0]=14.0; c.X[1][1]=14.0; c.X[1][2]=14.0; c.X[2][0]=23.0; c.X[2][1]=23.0; c.X[2][2]=23.0; assertTrue(a.multiply(b).equals(c)); } public void testMultiplyVector() { Matrix3 a=new Matrix3(); Vector3D b, c; b=new Vector3D(); c=new Vector3D(); a.X[0][0]=1.0; a.X[0][1]=2.0; a.X[0][2]=3.0; a.X[1][0]=1.0; a.X[1][1]=2.0; a.X[1][2]=3.0; a.X[2][0]=1.0; a.X[2][1]=2.0; a.X[2][2]=6.0; b.X1=1.0; b.X2=2.0; b.X3=3.0; c.X1=14.0; c.X2=14.0; c.X3=23.0; assertTrue(a.multiply(b).equals(c)); } public void testMultiplyScalar() { Matrix3 a, b; a=new Matrix3(); b=new Matrix3(); a.X[0][0]=1.0; a.X[0][1]=2.0; a.X[0][2]=3.0; a.X[1][0]=1.0; a.X[1][1]=2.0; a.X[1][2]=3.0; a.X[2][0]=1.0; a.X[2][1]=2.0; a.X[2][2]=3.0; b.X[0][0]=2.0; b.X[0][1]=4.0; b.X[0][2]=6.0; b.X[1][0]=2.0; b.X[1][1]=4.0; b.X[1][2]=6.0; b.X[2][0]=2.0; b.X[2][1]=4.0; b.X[2][2]=6.0; assertTrue(a.multiply(2.0).equals(b)); } }