Added some comments to BlockDataTest.testCycle.

Dieser Commit ist enthalten in:
TomyLobo 2013-05-24 02:03:08 +03:00
Ursprung ca06489e11
Commit 321e2246fc

Datei anzeigen

@ -73,8 +73,9 @@ public class BlockDataTest {
@Test @Test
public void testCycle() { public void testCycle() {
// Test monotony // Test monotony and continuity
for (int type = 0; type < 256; ++type) { for (int type = 0; type < 256; ++type) {
// Cloth isn't monotonous, and thus excluded.
if (type == BlockID.CLOTH) continue; if (type == BlockID.CLOTH) continue;
for (int data = 0; data < 16; ++data) { for (int data = 0; data < 16; ++data) {
@ -82,10 +83,12 @@ public class BlockDataTest {
final int cycled = BlockData.cycle(type, data, 1); final int cycled = BlockData.cycle(type, data, 1);
// If the cycle goes back (including -1), everything is ok.
if (cycled <= data) { if (cycled <= data) {
continue; continue;
} }
// If there's a gap in the cycle, there's a problem.
assertEquals(message, data + 1, cycled); assertEquals(message, data + 1, cycled);
} }
} }
@ -98,6 +101,7 @@ public class BlockDataTest {
} }
private static void testCycle(final int increment) { private static void testCycle(final int increment) {
// Iterate each block type and data value that wasn't part of a cycle yet.
for (int type = 0; type < 256; ++type) { for (int type = 0; type < 256; ++type) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
final TreeSet<Integer> datas = (TreeSet<Integer>) datasTemplate.clone(); final TreeSet<Integer> datas = (TreeSet<Integer>) datasTemplate.clone();
@ -108,12 +112,21 @@ public class BlockDataTest {
boolean first = true; boolean first = true;
while (true) { while (true) {
current = BlockData.cycle(type, current, increment); current = BlockData.cycle(type, current, increment);
// If the cycle immediately goes to -1, everything is ok.
if (first && current == -1) break; if (first && current == -1) break;
first = false; first = false;
message += "->" + current; message += "->" + current;
// If the cycle goes off limits (including -1), there's a problem.
assertTrue(message, current >= 0); assertTrue(message, current >= 0);
assertTrue(message, current < 16); assertTrue(message, current < 16);
// The cycle completes, everything is ok.
if (current == start) break; if (current == start) break;
// Mark the current element as walked.
assertTrue(message, datas.remove(current)); assertTrue(message, datas.remove(current));
} }
} }