Files
minecraft-bot/tests/test_crop_priority.py

86 lines
2.8 KiB
Python

import unittest
from munch import Munch
from mosfet.jobs.gather_crop import GatherCropStates
class TestCropSectionPriority(unittest.TestCase):
def setUp(self):
self.job = GatherCropStates(Munch())
self.job.bad_crops = []
def test_stays_in_active_patch_before_switching(self):
wheat_a = (0, 64, 0)
wheat_b = (1, 64, 0)
carrot_a = (10, 64, 0)
crop_types = {
wheat_a: 'wheat',
wheat_b: 'wheat',
carrot_a: 'carrots',
(10, 64, 1): 'carrots',
(10, 64, -1): 'carrots',
(11, 64, 0): 'carrots',
}
first, first_size = self.job._select_crop(
[wheat_a, carrot_a], crop_types, (0, 64, 0))
self.assertEqual(first, wheat_a)
self.assertEqual(first_size, 2)
self.job.init()
self.assertEqual(self.job.active_section_anchor, wheat_a)
# The carrot patch is now closer, but the bot should finish the wheat
# patch it already selected first.
next_crop, next_size = self.job._select_crop(
[wheat_b, carrot_a], crop_types, (10, 64, 0))
self.assertEqual(next_crop, wheat_b)
self.assertEqual(next_size, 2)
# Once the active patch has no mature candidates, move to the next one.
next_patch, next_patch_size = self.job._select_crop(
[carrot_a], crop_types, (10, 64, 0))
self.assertEqual(next_patch, carrot_a)
self.assertEqual(next_patch_size, 4)
def test_farther_section_wins_when_much_more_mature(self):
near_patch = {
(3, 64, 0), (2, 64, 0), (1, 64, 0), (0, 64, 0),
(3, 64, 1), (2, 64, 1), (1, 64, 1), (0, 64, 1),
(3, 64, 2), (2, 64, 2),
}
near_mature = (3, 64, 0)
far_patch = {
(4, 64, 0), (5, 64, 0), (4, 64, 1), (5, 64, 1),
}
crop_types = {position: 'wheat' for position in near_patch}
crop_types.update({position: 'carrots' for position in far_patch})
crop, size = self.job._select_crop(
[near_mature, *far_patch], crop_types, (0, 64, 0))
self.assertEqual(crop, (4, 64, 0))
self.assertEqual(size, len(far_patch))
self.assertEqual(self.job.active_section_maturity, (4, 4))
def test_unripe_same_species_blocks_keep_patch_connected(self):
mature = (0, 64, 0)
replanted = (1, 64, 0)
isolated = (4, 64, 0)
crop_types = {
mature: 'wheat',
replanted: 'wheat',
isolated: 'wheat',
}
crop, size = self.job._select_crop([mature, isolated], crop_types,
(0, 64, 0))
self.assertEqual(crop, mature)
self.assertEqual(size, 2)
self.assertEqual(self.job.active_section_anchor, mature)
if __name__ == '__main__':
unittest.main()