@Test public void testToVector3() { Vector4 x = new Vector4(3, 5, 6, 7); Vector3 y = new Vector3(3, 5, 6); assertTrue(x.toVector3().equals(y)); }
@Test public void testHashCode() { Vector4 x = new Vector4(5, 27, 1, 2); Vector4 y = new Vector4(5, -3, 0, 1); doAssertDouble(-1677538473, x.hashCode()); doAssertDouble(2032847703, y.hashCode()); }
@Test public void testNormalize() { Vector4 x = new Vector4(3, 4, 5, 6); Vector4 y = x.normalize(); doAssertDouble(0.323, y.x); doAssertDouble(0.431, y.y); doAssertDouble(1, y.length()); }
@Test public void testCompareTo() { assertTrue(Vector4.ZERO.compareTo(Vector4.ONE) < 0); Vector4 x = new Vector4(5, 3, 4, 6); Vector4 y = new Vector4(-2, 5, -2, 4); assertTrue(x.compareTo(y) >= 0); }
@Test public void testEquals() { Vector4 x = new Vector4(1, 1, 1, 1); Vector4 y = new Vector4(1, 1, 1, 1); Vector4 z = new Vector4(1, 2, 1, 1); assertTrue(x.equals(y)); assertFalse(x.equals(z)); }
@Test public void testAbs() { Vector4 x = new Vector4(1.4, -0.2, -2.4, 3.4); Vector4 y = x.abs(); doAssertDouble(1.4, y.x); doAssertDouble(0.2, y.y); doAssertDouble(2.4, y.z); doAssertDouble(3.4, y.w); }
@Test public void testFloor() { Vector4 x = new Vector4(1.4, -0.2, -2.4, 3.4); Vector4 y = x.floor(); doAssertDouble(1, y.x); doAssertDouble(-1, y.y); doAssertDouble(-3, y.z); doAssertDouble(3, y.w); }
@Test public void testCeil() { Vector4 x = new Vector4(1.4, -0.2, -2.4, 3.4); Vector4 y = x.ceil(); doAssertDouble(2, y.x); doAssertDouble(0, y.y); doAssertDouble(-2, y.z); doAssertDouble(4, y.w); }
@Test public void testDot() { Vector4 x = new Vector4(2, 3, 4, 5); doAssertDouble("x dot x should be 54", 54, x.dot(x)); x = new Vector4(3, 2, 4, 5); Vector4 y = new Vector4(4, -1, 4, 2); doAssertDouble("x dot y should be 36", 36, x.dot(y)); }
@Test public void testRound() { Vector4 x = new Vector4(1.4, -0.2, -2.4, 3.4); Vector4 y = x.round(); doAssertDouble(1, y.x); doAssertDouble(0, y.y); doAssertDouble(-2, y.z); doAssertDouble(3, y.w); }
@Test public void testAddDouble() { Vector4 a = new Vector4(1, -1, 3, 5); Vector4 c = a.add(2d, 6d, -2d, 5d); doAssertDouble(3, c.x); doAssertDouble(5, c.y); doAssertDouble(1, c.z); doAssertDouble(10, c.w); }
@Test public void testSubtractInt() { Vector4 a = new Vector4(1, -1, 4, -2); Vector4 c = a.subtract(2, 6, 4, 1); doAssertDouble(-1, c.x); doAssertDouble(-7, c.y); doAssertDouble(0, c.z); doAssertDouble(-3, c.w); }
@Test public void testSubtractDouble() { Vector4 a = new Vector4(1, -1, 4, -2); Vector4 c = a.subtract(2d, 6d, 4d, 1d); doAssertDouble(-1, c.x); doAssertDouble(-7, c.y); doAssertDouble(0, c.z); doAssertDouble(-3, c.w); }
@Test public void testSubtractFloat() { Vector4 a = new Vector4(1, -1, 4, -2); Vector4 c = a.subtract(2f, 6f, 4f, 1f); doAssertDouble(-1, c.x); doAssertDouble(-7, c.y); doAssertDouble(0, c.z); doAssertDouble(-3, c.w); }
@Test public void testAddInt() { Vector4 a = new Vector4(1, -1, 3, 5); Vector4 c = a.add(2, 6, -2, 5); doAssertDouble(3, c.x); doAssertDouble(5, c.y); doAssertDouble(1, c.z); doAssertDouble(10, c.w); }
@Test public void testDistance() { Vector4 x = new Vector4(2, 3, 4, 5); Vector4 y = new Vector4(1, 2, 3, 4); doAssertDouble(2, x.distance(y)); x = new Vector4(10, 3, 6, -5); y = new Vector4(7, 3, -2, 1); doAssertDouble(Math.sqrt(109), x.distance(y)); }
@Test public void testAddFloat() { Vector4 a = new Vector4(1, -1, 3, 5); Vector4 c = a.add(2f, 6f, -2f, 5f); doAssertDouble(3, c.x); doAssertDouble(5, c.y); doAssertDouble(1, c.z); doAssertDouble(10, c.w); }
@Test public void testToArray() { Vector4 x = new Vector4(5, 3, 6, 7); float[] r = x.toArray(); assertArrayEquals(new float[] {5, 3, 6, 7}, r, (float) eps); doAssertDouble(5, r[0]); doAssertDouble(3, r[1]); doAssertDouble(6, r[2]); doAssertDouble(7, r[3]); }
@Test public void testMultiplyVector4() { Vector4 a = new Vector4(1, -1, 4, 2); Vector4 b = new Vector4(2, 6, 4, 1); Vector4 c = a.multiply(b); doAssertDouble(2, c.x); doAssertDouble(-6, c.y); doAssertDouble(16, c.z); doAssertDouble(2, c.w); }
@Test public void testMultiplyFloat() { Vector4 a = new Vector4(1, -1, 4, 2); Vector4 b = a.multiply(2f, 6f, 4f, 1f); doAssertDouble(2, b.x); doAssertDouble(-6, b.y); doAssertDouble(16, b.z); doAssertDouble(2, b.w); Vector4 c = a.multiply(2.0F); doAssertDouble(2, c.x); doAssertDouble(-2, c.y); doAssertDouble(8, c.z); doAssertDouble(4, c.w); }
@Test public void testMultiplyDouble() { Vector4 a = new Vector4(1, -1, 4, 2); Vector4 b = a.multiply(2d, 6d, 4d, 1d); doAssertDouble(2, b.x); doAssertDouble(-6, b.y); doAssertDouble(16, b.z); doAssertDouble(2, b.w); Vector4 c = a.multiply(2.0d); doAssertDouble(2, c.x); doAssertDouble(-2, c.y); doAssertDouble(8, c.z); doAssertDouble(4, c.w); }
@Test public void testMultiplyInt() { Vector4 a = new Vector4(1, -1, 4, 2); Vector4 b = a.multiply(2, 6, 4, 1); doAssertDouble(2, b.x); doAssertDouble(-6, b.y); doAssertDouble(16, b.z); doAssertDouble(2, b.w); Vector4 c = a.multiply(2.0); doAssertDouble(2, c.x); doAssertDouble(-2, c.y); doAssertDouble(8, c.z); doAssertDouble(4, c.w); }
@Test public void testRand() { for (int i = 0; i < 100; ++i) { Vector4 x = Vector4.rand(); assertTrue(x.x >= -1); assertTrue(x.x <= 1); assertTrue(x.y >= -1); assertTrue(x.y <= 1); assertTrue(x.z >= -1); assertTrue(x.z <= 1); assertTrue(x.w >= -1); assertTrue(x.w <= 1); } }
@Test public void testPow() { Vector4 x = new Vector4(1, 2, 3, 4); Vector4 y = x.pow(3); doAssertDouble(1, y.x); doAssertDouble(8, y.y); doAssertDouble(27, y.z); doAssertDouble(64, y.w); x = new Vector4(1, 2, 3, 4); y = x.pow(2); doAssertDouble(1, y.x); doAssertDouble(4, y.y); doAssertDouble(9, y.z); doAssertDouble(16, y.w); x = new Vector4(25, 16, 9, 4); y = x.pow(0.5); doAssertDouble(5, y.x); doAssertDouble(4, y.y); doAssertDouble(3, y.z); doAssertDouble(2, y.w); }
@Test public void testMax() { Vector4 x = new Vector4(5, -15, 3, 1); Vector4 y = new Vector4(3, 2, 5, -1); assertEquals(new Vector4(5, 2, 5, 1), Vector4.max(x, y)); }
@Test public void testToString() { Vector4 x = new Vector4(3, 5, 0, 1); assertEquals("(3.0, 5.0, 0.0, 1.0)", x.toString()); }
@Test public void testLength() { Vector4 x = new Vector4(2, 3, 4, 5); doAssertDouble(Math.sqrt(54), x.length()); }
@Test public void testLengthSquared() { Vector4 x = new Vector4(2, 3, 4, 5); doAssertDouble(54, x.lengthSquared()); }