mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-04 12:06:41 +00:00
Added a new Location and added Entity.getLocation().
This commit is contained in:
156
src/test/java/com/sk89q/worldedit/util/LocationTest.java
Normal file
156
src/test/java/com/sk89q/worldedit/util/LocationTest.java
Normal file
@ -0,0 +1,156 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests {@link Location}.
|
||||
*/
|
||||
public class LocationTest {
|
||||
|
||||
private static final int TEST_VALUE = 10;
|
||||
private static final double EPSILON = 0.0001;
|
||||
|
||||
@Test
|
||||
public void testGetWorld() throws Exception {
|
||||
World world = mock(World.class);
|
||||
Location location = new Location(world);
|
||||
assertEquals(world, location.getWorld());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetWorld() throws Exception {
|
||||
World world1 = mock(World.class);
|
||||
World world2 = mock(World.class);
|
||||
Location location1 = new Location(world1);
|
||||
Location location2 = location1.setWorld(world2);
|
||||
assertEquals(world1, location1.getWorld());
|
||||
assertEquals(world2, location2.getWorld());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDirection() throws Exception {
|
||||
World world = mock(World.class);
|
||||
Vector direction = new Vector(1, 1, 1);
|
||||
Location location = new Location(world, new Vector(), direction);
|
||||
assertEquals(direction, location.getDirection());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetDirection() throws Exception {
|
||||
World world = mock(World.class);
|
||||
Vector direction1 = new Vector(1, 1, 1);
|
||||
Vector direction2 = new Vector(2, 2, 2);
|
||||
Location location1 = new Location(world, new Vector(), direction1);
|
||||
Location location2 = location1.setDirection(direction2);
|
||||
assertEquals(direction1, location1.getDirection());
|
||||
assertEquals(direction2, location2.getDirection());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToVector() throws Exception {
|
||||
World world = mock(World.class);
|
||||
Vector position = new Vector(1, 1, 1);
|
||||
Location location = new Location(world, position);
|
||||
assertEquals(position, location.toVector());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetX() throws Exception {
|
||||
World world = mock(World.class);
|
||||
Location location = new Location(world, new Vector(TEST_VALUE, 0, 0));
|
||||
assertEquals(TEST_VALUE, location.getX(), EPSILON);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBlockX() throws Exception {
|
||||
World world = mock(World.class);
|
||||
Location location = new Location(world, new Vector(TEST_VALUE, 0, 0));
|
||||
assertEquals(TEST_VALUE, location.getBlockX());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetX() throws Exception {
|
||||
World world = mock(World.class);
|
||||
Location location1 = new Location(world, new Vector());
|
||||
Location location2 = location1.setX(TEST_VALUE);
|
||||
assertEquals(0, location1.getX(), EPSILON);
|
||||
assertEquals(TEST_VALUE, location2.getX(), EPSILON);
|
||||
assertEquals(0, location2.getY(), EPSILON);
|
||||
assertEquals(0, location2.getZ(), EPSILON);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetY() throws Exception {
|
||||
World world = mock(World.class);
|
||||
Location location = new Location(world, new Vector(0, TEST_VALUE, 0));
|
||||
assertEquals(TEST_VALUE, location.getY(), EPSILON);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBlockY() throws Exception {
|
||||
World world = mock(World.class);
|
||||
Location location = new Location(world, new Vector(0, TEST_VALUE, 0));
|
||||
assertEquals(TEST_VALUE, location.getBlockY());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetY() throws Exception {
|
||||
World world = mock(World.class);
|
||||
Location location1 = new Location(world, new Vector());
|
||||
Location location2 = location1.setY(TEST_VALUE);
|
||||
assertEquals(0, location1.getY(), EPSILON);
|
||||
assertEquals(0, location2.getX(), EPSILON);
|
||||
assertEquals(TEST_VALUE, location2.getY(), EPSILON);
|
||||
assertEquals(0, location2.getZ(), EPSILON);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetZ() throws Exception {
|
||||
World world = mock(World.class);
|
||||
Location location = new Location(world, new Vector(0, 0, TEST_VALUE));
|
||||
assertEquals(TEST_VALUE, location.getZ(), EPSILON);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBlockZ() throws Exception {
|
||||
World world = mock(World.class);
|
||||
Location location = new Location(world, new Vector(0, 0, TEST_VALUE));
|
||||
assertEquals(TEST_VALUE, location.getBlockZ());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetZ() throws Exception {
|
||||
World world = mock(World.class);
|
||||
Location location1 = new Location(world, new Vector());
|
||||
Location location2 = location1.setZ(TEST_VALUE);
|
||||
assertEquals(0, location1.getZ(), EPSILON);
|
||||
assertEquals(0, location2.getX(), EPSILON);
|
||||
assertEquals(0, location2.getY(), EPSILON);
|
||||
assertEquals(TEST_VALUE, location2.getZ(), EPSILON);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user