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_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()