00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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 }