@SuppressWarnings("MagicNumber") @Test public void checkDegreeBetweenPlayers() { GameProfile playerOne = new GameProfile(); GameProfile playerTwo = new GameProfile(); final double x1 = 100; playerOne.setX(x1); final double y1 = 100; playerOne.setY(y1); final double x2 = 150; playerTwo.setX(x2); final double y2 = 150; playerTwo.setY(y2); MoveActionStrategy actionStrategy = new MoveActionStrategy(gameServer); final double myDirection = 90; final double enemyDirection = 90; double playerOneDegree = Math.toDegrees(actionStrategy.getDegree(playerOne, myDirection, x2 - x1, y2 - y1)); double playerTwoDegree = Math.toDegrees(actionStrategy.getDegree(playerTwo, enemyDirection, -x2 + x1, -y2 + y1)); assertEquals("wrong degree for player 1", 45.0d, Math.floor(playerOneDegree), 0); assertEquals("wrong degree for player 2", 135.0d, Math.floor(playerTwoDegree), 0); }
private void assertTimestampsAreCloseEnough(long timestamp1, long timestamp2) { assertTrue( String.format( "timestamps %s and %s are not close enough diff: %s", timestamp1, timestamp2, Math.abs(timestamp1 - timestamp2)), Math.abs(timestamp1 - timestamp2) < 50); }