/* * 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.core.exceptions.Exception; import ml.math.Vector3D; /** * This is the test case for ml.math.Vector3D * * @author gregor */ public class Vector3DTest extends TestCase { public static void main(String[] args) { junit.awtui.TestRunner.run(Vector3DTest.class); } public void testVector3D() { Vector3D a=new Vector3D(); assertTrue(a!=null); } public void testAbs() { Vector3D a=new Vector3D(); a.X1=1.0; a.X2=1.0; a.X3=1.0; assertTrue(a.abs()==Math.sqrt(3)); } public void testNorm() { Vector3D a=new Vector3D(); a.X1=3.0; a.X2=0.0; a.X3=0.0; Vector3D b=new Vector3D(); b.X1=1.0; b.X2=0.0; b.X3=0.0; assertTrue(a.norm().equals(b)); } public void testEquals() { Vector3D a=new Vector3D(); a.X1=1.0; a.X2=1.0; a.X3=1.0; Vector3D b=a.clone(); assertTrue(a.equals(b)); assertTrue(b.equals(a)); } public void testAdd() { Vector3D a=new Vector3D(); a.X1=1.0; a.X2=1.0; a.X3=1.0; Vector3D b=a.clone(); Vector3D c=new Vector3D(); c.X1=2.0; c.X2=2.0; c.X3=2.0; assertTrue(a.add(b).equals(c)); assertTrue(b.add(a).equals(c)); } public void testSub() { Vector3D a=new Vector3D(); a.X1=1.0; a.X2=1.0; a.X3=1.0; Vector3D b=a.clone(); Vector3D c=new Vector3D(); c.X1=0.0; c.X2=0.0; c.X3=0.0; assertTrue(a.sub(b).equals(c)); assertTrue(b.sub(a).equals(c)); } public void testMultiplyScalar() { Vector3D a=new Vector3D(); a.X1=1.0; a.X2=1.0; a.X3=1.0; Vector3D c=new Vector3D(); c.X1=2.0; c.X2=2.0; c.X3=2.0; assertTrue(a.multiply(2).equals(c)); } public void testMultiplyVector() { Vector3D a=new Vector3D(); a.X1=1.0; a.X2=1.0; a.X3=1.0; Vector3D b=a.clone(); assertTrue(a.multiply(b)==3); } public void testCrossMultiply() { Vector3D a=new Vector3D(); Vector3D b; Vector3D c=new Vector3D(); a.X1=1.0; a.X2=1.0; a.X3=1.0; b=a.clone(); c.X1=0.0; c.X2=0.0; c.X3=0.0; assertTrue(a.crossMultiply(b).equals(c)); a.X1=1.0; a.X2=0.0; a.X3=0.0; b.X1=0.0; b.X2=1.0; b.X3=0.0; c.X1=0.0; c.X2=0.0; c.X3=1.0; assertTrue(a.crossMultiply(b).equals(c)); } public void testAngleTo() { Vector3D a=new Vector3D(); Vector3D b=new Vector3D(); a.clear(); a.X1=1.0; b.clear(); b.X2=1.0; try { assertTrue(a.angleTo(b)==Math.PI/2); } catch (Exception e) { assertTrue(false); } b.X2=0.0; try { assertFalse(a.angleTo(b)==Math.PI/2); // this line must throw an exception assertTrue(false); } catch (Exception e) { // this exception is wanted, do nothing here } } }