mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-05 16:49:04 +00:00
Merge branch 'master' of https://github.com/apollo-rsps/apollo
This commit is contained in:
@@ -14,7 +14,7 @@ import com.google.common.base.Preconditions;
|
|||||||
public final class Position {
|
public final class Position {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of height levels.
|
* The number of height levels, (0, 3] inclusive.
|
||||||
*/
|
*/
|
||||||
public static final int HEIGHT_LEVELS = 4;
|
public static final int HEIGHT_LEVELS = 4;
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ public final class Position {
|
|||||||
* @param height The height.
|
* @param height The height.
|
||||||
*/
|
*/
|
||||||
public Position(int x, int y, int height) {
|
public Position(int x, int y, int height) {
|
||||||
Preconditions.checkArgument(height >= 0 && height < HEIGHT_LEVELS, "Height level out of bounds.");
|
Preconditions.checkElementIndex(height, HEIGHT_LEVELS, "Height must be [0, 3), received " + height + ".");
|
||||||
|
|
||||||
packed = height << 30 | (y & 0x7FFF) << 15 | x & 0x7FFF;
|
packed = height << 30 | (y & 0x7FFF) << 15 | x & 0x7FFF;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package org.apollo.game.model;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the {@link Position} class.
|
||||||
|
*
|
||||||
|
* @author Ryley
|
||||||
|
*/
|
||||||
|
public final class TestPosition {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the {@link Position#getHeight()} method.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testGetHeight() {
|
||||||
|
Position position = new Position(3222, 3222, 3);
|
||||||
|
Assert.assertEquals(3, position.getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the creation of an invalid {@link Position}.
|
||||||
|
*/
|
||||||
|
@Test(expected = IndexOutOfBoundsException.class)
|
||||||
|
public void testCreateNegativePosition() {
|
||||||
|
new Position(3222, 3222, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the creation of an invalid {@link Position}.
|
||||||
|
*/
|
||||||
|
@Test(expected = IndexOutOfBoundsException.class)
|
||||||
|
public void testCreateOutOfBoundsPosition() {
|
||||||
|
new Position(3222, 3222, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user