1 /* 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package test.com.sun.javafx.geom; 27 28 import com.sun.javafx.geom.Vec3d; 29 import com.sun.javafx.geom.Vec3f; 30 import org.junit.Test; 31 32 import static org.junit.Assert.*; 33 34 /** 35 * PRELIMINARY unit tests for Vec3d. 36 * 37 * TODO: expand this to cover the entire class (RT-26882) 38 */ 39 public class Vec3dTest { 40 41 private static double EPSILON = 1e-10; 42 43 @Test 44 public void testDefaultContructor() { 45 Vec3d v3d = new Vec3d(); 46 assertEquals(0, v3d.x, 0); 47 assertEquals(0, v3d.y, 0); 48 assertEquals(0, v3d.z, 0); 49 } 50 51 @Test 52 public void testContructor1() { 53 Vec3d v3d = new Vec3d(1.0, 2.0, 3.0); 54 assertEquals(1, v3d.x, 0); 55 assertEquals(2, v3d.y, 0); 56 assertEquals(3, v3d.z, 0); 57 } 58 59 @Test 60 public void testContructor2() { 61 Vec3f v3f = new Vec3f(1f, 2f, 3f); 62 Vec3d v3d = new Vec3d(v3f); 63 assertEquals(1, v3d.x, 0); 64 assertEquals(2, v3d.y, 0); 65 assertEquals(3, v3d.z, 0); 66 } 67 68 @Test 69 public void testLength() { 70 Vec3d v3d = new Vec3d(); 71 double len = v3d.length(); 72 assertEquals(0, len, 0); 73 74 v3d = new Vec3d(1, 2, 3); 75 len = v3d.length(); 76 assertEquals(Math.sqrt(14.0), len, EPSILON); 77 78 v3d = new Vec3d(-1, 2, 3); 79 len = v3d.length(); 80 assertEquals(Math.sqrt(14.0), len, EPSILON); 81 82 v3d = new Vec3d(1, -0.2, -0.03); 83 len = v3d.length(); 84 assertEquals(Math.sqrt(1.0409), len, EPSILON); 85 86 v3d = new Vec3d(-0.1, -0.2, -0.3); 87 len = v3d.length(); 88 assertEquals(Math.sqrt(0.14), len, EPSILON); 89 } 90 91 }