def test_single_block_damage_packet(self): chunk = Chunk(2, 1) chunk.populated = True chunk.set_block((2, 4, 8), 1) chunk.set_metadata((2, 4, 8), 2) packet = chunk.get_damage_packet() self.assertEqual(packet, '\x35\x00\x00\x00\x22\x04\x00\x00\x00\x18\x01\x02')
class TestChunkBlocks(unittest.TestCase): def setUp(self): self.c = Chunk(0, 0) def test_trivial(self): pass def test_destroy(self): """ Test block destruction. """ self.c.set_block((0, 0, 0), 1) self.c.set_metadata((0, 0, 0), 1) self.c.destroy((0, 0, 0)) self.assertEqual(self.c.get_block((0, 0, 0)), 0) self.assertEqual(self.c.get_metadata((0, 0, 0)), 0) def test_sed(self): """ ``sed()`` should work. """ self.c.set_block((1, 1, 1), 1) self.c.set_block((2, 2, 2), 2) self.c.set_block((3, 3, 3), 3) self.c.sed(1, 3) self.assertEqual(self.c.get_block((1, 1, 1)), 3) self.assertEqual(self.c.get_block((2, 2, 2)), 2) self.assertEqual(self.c.get_block((3, 3, 3)), 3) def test_set_block_heightmap(self): """ Heightmaps work. """ self.c.populated = True self.c.set_block((0, 20, 0), 1) self.assertEqual(self.c.heightmap[0], 20) def test_set_block_heightmap_underneath(self): """ A block placed underneath the highest block will not alter the heightmap. """ self.c.populated = True self.c.set_block((0, 20, 0), 1) self.assertEqual(self.c.heightmap[0], 20) self.c.set_block((0, 10, 0), 1) self.assertEqual(self.c.heightmap[0], 20) def test_set_block_heightmap_destroyed(self): """ Upon destruction of the highest block, the heightmap will point at the next-highest block. """ self.c.populated = True self.c.set_block((0, 30, 0), 1) self.c.set_block((0, 10, 0), 1) self.c.destroy((0, 30, 0)) self.assertEqual(self.c.heightmap[0], 10)
class TestChunkBlocks(unittest.TestCase): def setUp(self): self.c = Chunk(0, 0) def test_trivial(self): pass def test_set_block(self): self.assertEqual(self.c.blocks[0], 0) self.c.set_block((0, 0, 0), 1) self.assertEqual(self.c.blocks[0], 1) def test_set_block_xyz_xzy(self): """ Test that set_block swizzles correctly. """ self.c.set_block((1, 0, 0), 1) self.c.set_block((0, 1, 0), 2) self.c.set_block((0, 0, 1), 3) self.assertEqual(self.c.blocks[2048], 1) self.assertEqual(self.c.blocks[1], 2) self.assertEqual(self.c.blocks[128], 3) def test_destroy(self): """ Test block destruction. """ self.c.set_block((0, 0, 0), 1) self.c.set_metadata((0, 0, 0), 1) self.c.destroy((0, 0, 0)) self.assertEqual(self.c.blocks[0], 0) self.assertEqual(self.c.metadata[0], 0) def test_sed(self): """ ``sed()`` should work. """ self.c.set_block((1, 1, 1), 1) self.c.set_block((2, 2, 2), 2) self.c.set_block((3, 3, 3), 3) self.c.sed(1, 3) self.assertEqual(self.c.get_block((1, 1, 1)), 3) self.assertEqual(self.c.get_block((2, 2, 2)), 2) self.assertEqual(self.c.get_block((3, 3, 3)), 3) def test_single_block_damage_packet(self): chunk = Chunk(2, 1) chunk.populated = True chunk.set_block((2, 4, 8), 1) chunk.set_metadata((2, 4, 8), 2) packet = chunk.get_damage_packet() self.assertEqual(packet, '\x35\x00\x00\x00\x22\x04\x00\x00\x00\x18\x01\x02') def test_set_block_correct_heightmap(self): """ Test heightmap update for a single column. """ self.c.populated = True self.assertEqual(self.c.heightmap[0], 0) self.c.set_block((0, 20, 0), 1) self.assertEqual(self.c.heightmap[0], 20) self.c.set_block((0, 10, 0), 1) self.assertEqual(self.c.heightmap[0], 20) self.c.set_block((0, 30, 0), 1) self.assertEqual(self.c.heightmap[0], 30) self.c.destroy((0, 10, 0)) self.assertEqual(self.c.heightmap[0], 30) self.c.destroy((0, 30, 0)) self.assertEqual(self.c.heightmap[0], 20)