Files
minecraft-bot/tests/test_indexed_search.py
T
2026-11-16 22:55:06 +00:00

62 lines
1.9 KiB
Python

import unittest
from munch import Munch
from mosfet.info import blocks
from mosfet.world import World
class IndexedSearchTests(unittest.TestCase):
def test_sand_search_targets_safe_blocks_in_3x3_slice_only(self):
sand_position = (1, 64, 1)
class SandChunks:
def get_block_at(self, x, y, z):
position = (x, y, z)
if position == sand_position:
return blocks.SAND
if y < sand_position[1]:
return blocks.STONE
return blocks.AIR
world = World(Munch(chunks=SandChunks()))
self.assertTrue(world.check_sand_slice((0, 64, 0)))
self.assertEqual(
world.find_sand((0, 64, 0), 2, (0, 64, 0)),
[sand_position])
sand_position = (2, 64, 0)
self.assertFalse(world.check_sand_slice((0, 64, 0)))
def test_index_deduplication_is_linear_and_sort_is_optional(self):
far = (10, 64, 0)
near = (1, 64, 0)
class FakeChunks:
def __init__(self):
self.reads = {}
@staticmethod
def indexed_positions(_block_ids):
return [far, near, far]
def get_block_at(self, *position):
position = tuple(position)
self.reads[position] = self.reads.get(position, 0) + 1
return blocks.STONE
chunks = FakeChunks()
world = World(Munch(chunks=chunks))
self.assertEqual(world.find_blocks_indexed(
(0, 64, 0), {blocks.STONE}, 50), [near, far])
self.assertEqual(chunks.reads, {far: 1, near: 1})
chunks.reads.clear()
self.assertEqual(world.find_blocks_indexed(
(0, 64, 0), {blocks.STONE}, 50, sort=False), [far, near])
self.assertEqual(chunks.reads, {far: 1, near: 1})
if __name__ == '__main__':
unittest.main()