### Question:
AngleUtil { public static double calculateMeanAngle(double[] angles) { if (angles == null || angles.length == 0) { return 0; } if (angles.length == 1) { return angles[0]; } float sumSin = 0; float sumCos = 0; for (double angle : angles) { sumSin += Math.sin(Math.toRadians(angle)); sumCos += Math.cos(Math.toRadians(angle)); } return Math.toDegrees(Math.atan2(sumSin, sumCos)); }  static double calculateMeanAngle(double[] angles); static double calculateMeanAngle(List<Location> deviceLocations); static double angleDistance(double alpha, double beta);  }### Answer:
@Test public void calculateAngleMean_validAngles_correctAngle() throws Exception { double angles[] = {10, 350, 0, 20, 340}; double expectedAngle = 0; double actualAngle = calculateMeanAngle(angles); assertEquals(expectedAngle, actualAngle, 0.00001); angles = new double[]{10}; expectedAngle = 10; actualAngle = calculateMeanAngle(angles); assertEquals(expectedAngle, actualAngle, 0); angles = new double[]{0, 0, 90}; expectedAngle = 26.565; actualAngle = calculateMeanAngle(angles); assertEquals(expectedAngle, actualAngle, 0.0001); }
@Test public void calculateAngleMean_invalidAngles_correctAngle() throws Exception { double angles[] = null; double expectedAngle = 0; double actualAngle = calculateMeanAngle(angles); assertEquals(expectedAngle, actualAngle, 0); angles = new double[]{}; expectedAngle = 0; actualAngle = calculateMeanAngle(angles); assertEquals(expectedAngle, actualAngle, 0); }
@Test public void calculateAngleMean_negativeAngles_unequalAngles() throws Exception { double angles[] = new double[]{-90}; double negativeAngle = calculateMeanAngle(angles); angles = new double[]{270}; double positiveAngle = calculateMeanAngle(angles); assertNotEquals(negativeAngle, positiveAngle); }