Added a test case for BlockData.

Fixed some non-breaking inaccuracies to make the test case work.
This commit is contained in:
TomyLobo 2011-09-25 06:03:55 +02:00
parent 63fa72af5e
commit 93f36955ca
2 changed files with 71 additions and 14 deletions

View File

@ -145,13 +145,13 @@ public final class BlockData {
break;
case BlockID.TRAP_DOOR:
int open = data & 0x4;
int withoutOpen = data & ~0x4;
switch (withoutOpen) {
case 0: return 3 | open;
case 1: return 2 | open;
case 2: return 0 | open;
case 3: return 1 | open;
int withoutOrientation = data & ~0x3;
int orientation = data & 0x3;
switch (orientation) {
case 0: return 3 | withoutOrientation;
case 1: return 2 | withoutOrientation;
case 2: return 0 | withoutOrientation;
case 3: return 1 | withoutOrientation;
}
break;
@ -302,13 +302,13 @@ public final class BlockData {
break;
case BlockID.TRAP_DOOR:
int open = data & 0x4;
int withoutOpen = data & ~0x4;
switch (withoutOpen) {
case 3: return 0 | open;
case 2: return 1 | open;
case 0: return 2 | open;
case 1: return 3 | open;
int withoutOrientation = data & ~0x3;
int orientation = data & 0x3;
switch (orientation) {
case 3: return 0 | withoutOrientation;
case 2: return 1 | withoutOrientation;
case 0: return 2 | withoutOrientation;
case 1: return 3 | withoutOrientation;
}
case BlockID.PISTON_BASE:
@ -380,6 +380,10 @@ public final class BlockData {
case BlockID.TORCH:
case BlockID.REDSTONE_TORCH_OFF:
case BlockID.REDSTONE_TORCH_ON:
if (data > 4)
break;
/* FALL-THROUGH */
case BlockID.LEVER:
case BlockID.STONE_BUTTON:
switch (data & ~0x8) {
@ -470,6 +474,10 @@ public final class BlockData {
case BlockID.PUMPKIN:
case BlockID.JACKOLANTERN:
if (data > 3)
break;
/* FALL-THROUGH */
case BlockID.REDSTONE_REPEATER_OFF:
case BlockID.REDSTONE_REPEATER_ON:
switch (data & 0x3) {

View File

@ -0,0 +1,49 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.data;
import org.junit.*;
import com.sk89q.worldedit.CuboidClipboard.FlipDirection;
import static org.junit.Assert.*;
public class BlockDataTest {
@Test
public void testSlice() {
for (int type = 0; type < 256; ++type) {
for (int data = 0; data < 16; ++data) {
final String message = type+"/"+data;
assertEquals(message, data, BlockData.rotate90(type, BlockData.rotate90Reverse(type, data)));
assertEquals(message, data, BlockData.rotate90Reverse(type, BlockData.rotate90(type, data)));
int flipped = BlockData.flip(type, BlockData.flip(type, data, FlipDirection.WEST_EAST), FlipDirection.NORTH_SOUTH);
assertEquals(message, flipped, BlockData.rotate90(type, BlockData.rotate90(type, data)));
assertEquals(message, flipped, BlockData.rotate90Reverse(type, BlockData.rotate90Reverse(type, data)));
assertEquals(message, data, BlockData.flip(type, BlockData.flip(type, data, FlipDirection.NORTH_SOUTH), FlipDirection.NORTH_SOUTH));
assertEquals(message, data, BlockData.flip(type, BlockData.flip(type, data, FlipDirection.WEST_EAST), FlipDirection.WEST_EAST));
assertEquals(message, data, BlockData.flip(type, BlockData.flip(type, data, FlipDirection.UP_DOWN), FlipDirection.UP_DOWN));
}
}
}
}