Vector3Test.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2012 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
00005  * use this file except in compliance with the License. You may obtain a copy of
00006  * the License at
00007  *
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
00013  * License for the specific language governing permissions and limitations under
00014  * the License.
00015  */
00016 
00017 package org.ros.rosjava_geometry;
00018 
00019 import static org.junit.Assert.assertEquals;
00020 
00021 import org.junit.Test;
00022 
00026 public class Vector3Test {
00027 
00028   @Test
00029   public void testAdd() {
00030     Vector3 vector1 = new Vector3(1, 2, 3);
00031     Vector3 vector2 = new Vector3(2, 3, 4);
00032     Vector3 result = vector1.add(vector2);
00033     assertEquals(result.getX(), 3, 1e-9);
00034     assertEquals(result.getY(), 5, 1e-9);
00035     assertEquals(result.getZ(), 7, 1e-9);
00036   }
00037 
00038   @Test
00039   public void testSubtract() {
00040     Vector3 vector1 = new Vector3(1, 2, 3);
00041     Vector3 vector2 = new Vector3(2, 3, 4);
00042     Vector3 result = vector1.subtract(vector2);
00043     assertEquals(result.getX(), -1, 1e-9);
00044     assertEquals(result.getY(), -1, 1e-9);
00045     assertEquals(result.getZ(), -1, 1e-9);
00046   }
00047 
00048   @Test
00049   public void testInvert() {
00050     Vector3 result = new Vector3(1, 1, 1).invert();
00051     assertEquals(result.getX(), -1, 1e-9);
00052     assertEquals(result.getY(), -1, 1e-9);
00053     assertEquals(result.getZ(), -1, 1e-9);
00054   }
00055 
00056   @Test
00057   public void testDotProduct() {
00058     Vector3 vector1 = new Vector3(1, 2, 3);
00059     Vector3 vector2 = new Vector3(2, 3, 4);
00060     assertEquals(20.0, vector1.dotProduct(vector2), 1e-9);
00061   }
00062 
00063   @Test
00064   public void testLength() {
00065     assertEquals(2, new Vector3(2, 0, 0).getMagnitude(), 1e-9);
00066     assertEquals(2, new Vector3(0, 2, 0).getMagnitude(), 1e-9);
00067     assertEquals(2, new Vector3(0, 0, 2).getMagnitude(), 1e-9);
00068     assertEquals(Math.sqrt(3), new Vector3(1, 1, 1).getMagnitude(), 1e-9);
00069   }
00070 }


rosjava_core
Author(s):
autogenerated on Wed Aug 26 2015 16:06:49