Vec2 { public Vec2 swap(Vec2 vector) { if (vector == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "Vec2", "swap", "missingVector")); } double tmp = this.x; this.x = vector.x; vector.x = tmp; tmp = this.y; this.y = vector.y; vector.y = tmp; return this; } Vec2();  Vec2(double x, double y);  Vec2(Vec2 vector); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); float[] toArray(float[] result, int offset); double magnitude(); double magnitudeSquared(); double distanceTo(Vec2 vector); double distanceToSquared(Vec2 vector); Vec2 set(double x, double y); Vec2 set(Vec2 vector); Vec2 swap(Vec2 vector); Vec2 add(Vec2 vector); Vec2 subtract(Vec2 vector); Vec2 multiply(double scalar); Vec2 multiplyByMatrix(Matrix3 matrix); Vec2 divide(double divisor); Vec2 negate(); Vec2 normalize(); double dot(Vec2 vector); Vec2 mix(Vec2 vector, double weight); public double x; public double y; }
@Test public void testSwap() throws Exception { final double ux = 3d; final double uy = 4d; final double vx = 5d; final double vy = 6d; Vec2 u = new Vec2(ux, uy); Vec2 v = new Vec2(vx, vy); Vec2 w = u.swap(v); assertEquals("u.x", vx, u.x, 0d); assertEquals("u.y", vy, u.y, 0d); assertEquals("v.x", ux, v.x, 0d); assertEquals("v.y", uy, v.y, 0d); assertEquals("w == u", u, w); }
@Test(expected = IllegalArgumentException.class) public void testSwap_WithNull() throws Exception { Vec2 u = new Vec2(); u.swap(null); fail("Expected an IllegalArgumentException to be thrown."); }