"""Offline regressions for primary-only cultivation and bounded species retention.""" import copy from dataclasses import asdict import unittest from ranch_assistant.cultivation import quality_rank from ranch_assistant.model import Action, Catalog, EggRule, Planner, Policy, Snapshot SPECIES = 1030010 class SpeciesRetentionLimitsTests(unittest.TestCase): def setUp(self): self.catalog = Catalog() room_type = next(iter(self.catalog.data["room_info"])) self.catalog.data["room_info"][room_type]["maxNum"] = 20 self.snapshot = Snapshot({"master": {"id": 1}, "monsters": [], "teams": [], "stacks": [], "items": [], "rooms": [{"id": 1, "typeId": int(room_type)}, {"id": 2, "typeId": int(room_type)}]}) self.planner = Planner(self.catalog) def mon(self, mid, grades="CCCC", *, species=SPECIES, **values): info = self.catalog.monster(species) mon = {"id": mid, "typeId": species, "process": 3, "mode": 2, "level": 10, "feel": 0, "roomId": 1, "potentialLevel": 3, "exp": 451, "tpLevel": 0, "tpExp": 0, "lock": 0} for stat, grade in zip(("atk", "def", "hp", "dex"), grades): low, high = info[stat + "_grow_min"], info[stat + "_grow_max"] mon["g" + stat.capitalize()] = low + (high - low) * { "C": .1, "B": .375, "A": .625, "S": .9}[grade] return mon | values def policy(self, *, action="sell", count=1, **values): return Policy(**({"manual_eggs": True, "fill": False, "buy": False, "protect_star": 6, "protect_quality": 5, "keep_better_quality": False, "gift_auto_representative": True, "egg_rules": {str(SPECIES): asdict(EggRule(enabled=True, action=action, keep_count=count))}} | values)) def plan(self, rows, policy=None, *, managed=()): self.snapshot.raw["monsters"] = rows self.planner.managed.update(managed) return self.planner.plan(self.snapshot, policy or self.policy()) @staticmethod def sold(actions): return {mid for action in actions if action.kind == "sell" for mid in action.payload["monsterIds"]} @staticmethod def collected(actions): return {mid for action in actions if action.kind == "collect" for data in action.payload["datas"] for mid in data["monsterId"]} def screenshot(self): return [self.mon(910001, "SASS", level=20, potentialLevel=2, tpLevel=4, tpExp=999, exp=self.catalog.data["monster_level"]["20"], lock=1), self.mon(910002, "SASA"), self.mon(910003, "AASS"), self.mon(910004, "SASA"), self.mon(910005, "ASAS", level=9)] def test_screenshot_unmanaged_extras_are_trimmed_only_for_enabled_species(self): rows = self.screenshot() unrelated = self.mon(999, "SSSS", species=1030012) actions = self.plan(rows + [unrelated]) self.assertEqual(self.sold(actions), {row["id"] for row in rows[1:]}) self.assertEqual(self.planner.retained, {910001}) self.assertFalse(any(action.kind == "feed" for action in actions)) self.assertFalse(self.planner.managed, "Planning must not invent recorded ownership") def test_screenshot_tp_and_ordinary_caps_never_fall_back_to_duplicate(self): rows = self.screenshot() self.snapshot.raw["monsters"] = rows self.planner.managed.update(row["id"] for row in rows[1:]) target, _ = self.planner.same_species_feeding_target(rows[-1], self.snapshot, self.policy(action="feed")) self.assertIsNone(target) self.assertFalse(any(action.kind == "feed" for action in self.plan(rows, self.policy(action="feed")))) def test_old_keep_flags_and_counts_do_not_expand_or_disable_fixed_slots(self): for count in (0, 1, 2, 1000): for keep_better in (False, True): with self.subTest(count=count, keep_better=keep_better): self.setUp() rows = [self.mon(1, "AASA", level=30), self.mon(2, "SSAS"), self.mon(3, "SSAS", roomId=2), self.mon(4, "AASA")] policy = self.policy(count=count, keep_better_quality=keep_better) before = copy.deepcopy(asdict(policy)) actions = self.plan(rows, policy) self.assertEqual(self.planner.retained, {1, 2}) self.assertEqual(self.sold(actions), {3, 4}) self.assertEqual(asdict(policy), before) def test_quality_protection_does_not_keep_unlimited_managed_four_s(self): for threshold in (3, 6): with self.subTest(threshold=threshold): self.setUp() rows = [self.mon(1, "SSSS", level=30)] + [ self.mon(mid, "SSSS") for mid in (2, 3, 4)] actions = self.plan(rows, self.policy(count=1000, protect_quality=threshold), managed=(1, 2, 3, 4)) self.assertEqual(self.planner.retained, {1}) self.assertEqual(self.sold(actions), {2, 3, 4}) def test_backup_requires_strict_improvement_over_primary(self): rows = [self.mon(1, "SSAS", level=30), self.mon(2, "SSAS"), self.mon(3, "AASA")] self.assertEqual(self.sold(self.plan(rows)), {2, 3}) self.assertEqual(self.planner.retained, {1}) def test_equal_four_s_newcomer_dispatches_instead_of_becoming_tp_food(self): primary = self.mon(1, "SSSS", level=30, tpLevel=0, tpExp=0) newcomer = self.mon(2, "SSSS", process=2, roomId=None) self.snapshot.raw["stacks"] = [{"id": 1, "position": 0, "monsterId": 2}] policy = self.policy(action="feed") actions = self.plan([primary, newcomer], policy) self.assertEqual(self.sold(actions), {2}) self.assertEqual(self.collected(actions), set()) newcomer.update(process=3, roomId=1) actions = self.plan([primary, newcomer], policy) self.assertEqual(self.sold(actions), {2}) self.assertFalse(any(a.kind == "feed" for a in actions)) def test_rejected_better_quality_candidate_dispatches_and_hard_locks_still_win(self): for protected in (False, True): with self.subTest(protected=protected): self.setUp() rows = [self.mon(1, "AASA", level=30), self.mon(2, "SSSS"), self.mon(3, "SSAS", lock=int(protected))] policy = self.policy(action="feed") actions = self.plan(rows, policy, managed=(2, 3)) self.assertEqual(self.sold(actions), set() if protected else {3}) self.assertEqual(self.planner.disposition(rows[2], self.snapshot, policy), "keep" if protected else "sell") self.assertFalse(any(a.kind == "feed" for a in actions)) def test_backup_ranks_s_count_before_equal_weight_normalized_growth(self): rows = [self.mon(1, "CCCC", level=30), self.mon(2, "AAAC"), self.mon(3, "BBAA"), self.mon(4, "SSAS"), self.mon(5, "AASA")] self.assertGreater(quality_rank(self.catalog, rows[3]), quality_rank(self.catalog, rows[4])) self.assertEqual(self.sold(self.plan(rows)), {2, 3, 5}) self.assertEqual(self.planner.retained, {1, 4}) def test_backup_breaks_grade_ties_by_equal_weight_normalized_growth(self): primary = self.mon(1, level=30) better_atk, better_hp = self.mon(2, "AAAA"), self.mon(3, "AAAA") info = self.catalog.monster(SPECIES) better_atk["gAtk"] += .05 * (info["atk_grow_max"] - info["atk_grow_min"]) better_hp["gHp"] += .10 * (info["hp_grow_max"] - info["hp_grow_min"]) self.assertEqual(self.sold(self.plan([primary, better_atk, better_hp])), {2}) self.assertEqual(self.planner.retained, {1, 3}) def test_equal_s_count_uses_growth_without_extra_a_or_b_count_priority(self): rows = [self.mon(1, level=30), self.mon(2, "SACC"), self.mon(3, "SBBB")] self.assertLess(quality_rank(self.catalog, rows[1]), quality_rank(self.catalog, rows[2])) self.assertEqual(self.sold(self.plan(rows)), {2}) self.assertEqual(self.planner.retained, {1, 3}) def test_quality_tie_prefers_existing_ranch_backup_over_new_incubator(self): primary, backup = self.mon(1, level=30), self.mon(20, "SSAS") self.plan([primary, backup]) new = self.mon(10, "SSAS", process=2, roomId=None) self.snapshot.raw["stacks"] = [{"id": 1, "position": 0, "monsterId": 10}] actions = self.plan([new, backup, primary]) self.assertEqual(self.planner.retained, {1, 20}) self.assertEqual(self.sold(actions), {10}) self.assertEqual(self.collected(actions), set()) def test_equal_ranch_backups_use_oldest_id_independent_of_row_order(self): for order in ((30, 20, 10), (10, 30, 20)): with self.subTest(order=order): self.setUp() rows = [self.mon(1, level=30)] + [self.mon(mid, "SSAS") for mid in order] self.assertEqual(self.sold(self.plan(rows)), {20, 30}) self.assertEqual(self.planner.retained, {1, 10}) def test_better_incubator_dispatches_obsolete_backup_before_collection(self): primary, old = self.mon(1, level=30), self.mon(2, "SSAS") self.plan([primary, old]) new = self.mon(3, "SSSS", process=2, roomId=None) self.snapshot.raw["stacks"] = [{"id": 1, "position": 0, "monsterId": 3}] policy = self.policy(action="feed") actions = self.plan([primary, old, new], policy, managed=(2, 3)) self.assertEqual(self.sold(actions), {2}) self.assertEqual(self.collected(actions), set()) self.assertFalse(any(action.kind == "feed" for action in actions)) actions = self.plan([primary, new], policy) self.assertEqual(self.collected(actions), {3}) self.assertEqual(self.sold(actions), set()) def test_obsolete_backup_replacement_waits_when_dispatch_is_off(self): rows = [self.mon(1, level=30), self.mon(2, "SSAS"), self.mon(3, "SSSS", process=2, roomId=None)] actions = self.plan(rows, self.policy(dispatch=False), managed=(2, 3)) self.assertEqual(actions, []) self.assertIn("派遣", self.planner.statuses[2]) self.assertIn("关闭", self.planner.statuses[2]) def test_first_mature_incubator_is_collected_before_any_feeding(self): rows = [self.mon(2, "SSSS", process=2, roomId=None), self.mon(1, process=2, roomId=None)] self.snapshot.raw["stacks"] = [{"id": mid, "position": mid - 1, "monsterId": mid} for mid in (1, 2)] actions = self.plan(rows, self.policy(action="feed")) self.assertEqual(self.collected(actions), {1}) self.assertFalse(any(action.kind == "feed" for action in actions)) self.assertIn(1, self.planner.retained) def test_primary_can_consume_only_nonprotected_lower_quality_excess(self): rows = [self.mon(1, "AAAA", level=30, lock=1), self.mon(2, "SSSS"), self.mon(3)] actions = self.plan(rows, self.policy(action="feed"), managed=(2, 3)) self.assertEqual([a.payload for a in actions if a.kind == "feed"], [{"targetId": 1, "foods": [3]}]) self.assertEqual(self.planner.retained, {1, 2}) def test_legacy_same_species_feed_does_not_require_target_quality_above_fodder(self): rows = [self.mon(1, level=30, lock=1), self.mon(2, "SSAS")] policy = Policy(strategy="experience", fill=False, protect_star=6, protect_quality=5) actions = self.plan(rows, policy, managed=(2,)) self.assertEqual([a.payload for a in actions if a.kind == "feed"], [{"targetId": 1, "foods": [2]}]) def test_backup_is_food_protected_but_never_a_target(self): primary = self.mon(1, level=30, tpLevel=4, tpExp=999) backup, food = self.mon(2, "SSSS"), self.mon(3, "SSAS") self.snapshot.raw["monsters"] = [primary, backup, food] self.planner.managed.update((2, 3)) policy = self.policy(action="feed") self.assertTrue(self.planner.protected(backup, self.snapshot, policy)) target, reason = self.planner.same_species_feeding_target(food, self.snapshot, policy) self.assertIsNone(target, reason) self.assertNotIn(2, self.planner.tp_feed_targets) def test_same_species_selection_uses_only_primary_even_if_priority_favors_backup(self): primary, backup, food = self.mon(1, level=30), self.mon(2, "SSSS"), self.mon(3, "SSAS") self.snapshot.raw["monsters"] = [primary, backup, food] self.planner.managed.update((2, 3)) policy = self.policy(action="feed", breakthrough_targets={"2": 1}) target, _ = self.planner.same_species_feeding_target(food, self.snapshot, policy) self.assertIs(target, primary) def test_unavailable_primary_does_not_fall_back_to_available_duplicate(self): for unavailable in ({"inExploreTeam": True}, {"inBuild": True}): with self.subTest(unavailable=unavailable): self.setUp() rows = [self.mon(1, level=30, **unavailable), self.mon(2, "SSSS"), self.mon(3, "SSAS")] self.snapshot.raw["monsters"] = rows self.planner.managed.update((2, 3)) policy = self.policy(action="feed", feed_targets={"1": 1, "2": 2}) self.assertIsNone(self.planner.feeding_target(self.snapshot, policy)[0]) self.assertIsNone(self.planner.same_species_feeding_target(rows[-1], self.snapshot, policy)[0]) def test_manual_backup_only_is_skipped_without_changing_selection(self): rows = [self.mon(1, level=30), self.mon(2, "SSSS"), self.mon(3, "SSAS")] for values in ({"feed_targets": {"2": 1}}, {"feed_target": 2}): with self.subTest(values=values): self.snapshot.raw["monsters"] = rows policy = self.policy(action="feed", **values) before = copy.deepcopy(asdict(policy)) target, reason = self.planner.feeding_target(self.snapshot, policy) self.assertIsNone(target) self.assertIn("主培养", reason) self.assertIn("#1", reason) self.assertFalse(any(action.kind == "feed" for action in self.plan(rows, policy, managed=(2, 3)))) self.assertEqual(asdict(policy), before) def test_manual_capped_primary_skips_duplicate_and_may_use_other_species_primary(self): rows = [self.mon(1, level=30), self.mon(2, "SSSS"), self.mon(3, species=1002010)] self.snapshot.raw["monsters"] = rows policy = self.policy(feed_targets={"1": 1, "2": 2, "3": 3}) self.assertIs(self.planner.feeding_target(self.snapshot, policy)[0], rows[2]) del policy.feed_targets["3"] self.assertIsNone(self.planner.feeding_target(self.snapshot, policy)[0]) def test_all_hard_protections_survive_species_limit(self): flags = ({"lock": 1}, {"sysLock": 1}, {"equip1": 7}, {"entangle": 1}, {"inExploreTeam": 1}, {"inBuild": 1}, {"gAtk": None}) rows = [self.mon(1, level=30)] + [self.mon(mid, "SSAS", **values) for mid, values in enumerate(flags, 2)] rows += [self.mon(20, "SSAS"), self.mon(21, "CCCC")] self.snapshot.raw["teams"] = [{"id": 1, "monsters": [20]}] before = copy.deepcopy(rows) actions = self.plan(rows, managed=range(1, 22)) self.assertEqual(self.sold(actions), {21}) self.assertEqual(rows, before) for row in rows[1:-1]: self.assertIn("保护", self.planner.statuses[row["id"]]) def test_reserved_species_never_sells_or_feeds_extras(self): rows = [self.mon(1, level=30), self.mon(2, "SSAS"), self.mon(3)] actions = self.plan(rows, self.policy(reserved_types=[SPECIES]), managed=(2, 3)) self.assertFalse(any(a.kind in ("sell", "feed") for a in actions)) self.assertIn("委托", self.planner.statuses[3]) def test_active_exploration_roster_protects_extras_without_individual_flags(self): for members in ("910002", [910002], (910002,)): with self.subTest(members=members): self.setUp() rows = self.screenshot() # Status remains occupied until exploration rewards are claimed, # including when its end time has already passed. self.snapshot.raw["exploreTeams"] = [{"id": 7, "status": 1, "monsters": members, "endTime": 1}] actions = self.plan(rows, self.policy(action="feed"), managed=tuple(row["id"] for row in rows)) self.assertEqual(self.sold(actions), {910003, 910004, 910005}) self.assertEqual(self.planner.retained, {910001, 910002}) self.assertIn("保护", self.planner.statuses[910002]) self.assertFalse(any(a.kind == "feed" for a in actions)) def test_exploring_primary_without_individual_flag_is_never_feed_target(self): rows = self.screenshot() rows[0].update(level=19, exp=451, tpLevel=0, tpExp=0) self.snapshot.raw["monsters"] = rows self.snapshot.raw["exploreTeams"] = [{"id": 7, "status": "1", "monsters": "910001"}] self.planner.managed.update(row["id"] for row in rows[1:]) policy = self.policy(action="feed", feed_targets={"910001": 1}) self.assertIsNone(self.planner.feeding_target(self.snapshot, policy)[0]) self.assertIsNone(self.planner.same_species_feeding_target(rows[1], self.snapshot, policy)[0]) action = Action("feed", "busy primary", "monsterService/monsterIntensify", {"targetId": 910001, "foods": [910002]}) self.assertEqual(self.planner.batch_actions([action], self.snapshot, policy), []) def test_exploration_only_changes_invalidate_retention_cache(self): rows = self.screenshot() self.snapshot.raw["monsters"] = rows policy = self.policy() self.assertFalse(self.planner.protected(rows[1], self.snapshot, policy)) self.snapshot.raw["exploreTeams"] = [{"id": 7, "status": 1, "monsters": [910002]}] self.assertTrue(self.planner.protected(rows[1], self.snapshot, policy)) self.assertIn(910002, self.planner.retained) self.snapshot.raw["exploreTeams"][0]["status"] = 0 self.assertFalse(self.planner.protected(rows[1], self.snapshot, policy)) self.assertNotIn(910002, self.planner.retained) def test_dispatch_off_reports_unmanaged_extras_without_expanding_ownership(self): rows = self.screenshot() self.assertEqual(self.plan(rows, self.policy(dispatch=False)), []) self.assertIn("关闭", self.planner.statuses[910002]) self.assertFalse(self.planner.managed) def test_disabled_rules_and_disabled_automation_never_adopt_old_inventory(self): rows = self.screenshot() for policy in (self.policy(enabled=False), self.policy(egg_rules={str(SPECIES): asdict(EggRule(enabled=False))})): with self.subTest(policy=policy): self.assertEqual(self.plan(rows, policy), []) self.assertFalse(self.planner.managed) def test_stale_nonprimary_targets_do_not_override_species_slots(self): rows = [self.mon(1, level=30), self.mon(2, "SSSS"), self.mon(3, "SSAS"), self.mon(4)] policy = self.policy(action="feed", feed_targets={"3": 1}, breakthrough_targets={"4": 1}) actions = self.plan(rows, policy, managed=(2, 3, 4)) self.assertEqual(self.sold(actions), {3, 4}) self.assertFalse(any(a.kind == "feed" for a in actions)) self.assertFalse(self.planner.protected(rows[2], self.snapshot, policy)) self.assertFalse(self.planner.protected(rows[3], self.snapshot, policy)) def test_all_old_targets_and_star_threshold_are_soft_for_enabled_species(self): rows = self.screenshot() rows[2]["lock"] = 1 selected = {str(row["id"]): i for i, row in enumerate(rows, 1)} policy = self.policy(action="feed", protect_star=1, feed_targets=selected.copy(), gift_targets=selected.copy(), breakthrough_targets=selected.copy()) before = copy.deepcopy(asdict(policy)) actions = self.plan(rows, policy, managed=tuple(row["id"] for row in rows)) self.assertEqual(self.sold(actions), {910002, 910004, 910005}) self.assertEqual(self.planner.retained, {910001, 910003}) self.assertIn("保护", self.planner.statuses[910003]) self.assertEqual(asdict(policy), before) self.assertFalse(any(a.kind == "feed" for a in actions)) def test_batch_revalidates_primary_instead_of_trusting_supplied_feed_action(self): rows = [self.mon(1, level=30), self.mon(2, "SSSS"), self.mon(3, "SSAS")] self.snapshot.raw["monsters"] = rows self.planner.managed.update((2, 3)) action = Action("feed", "stale duplicate target", "monsterService/monsterIntensify", {"targetId": 2, "foods": [3]}) self.assertEqual(self.planner.batch_actions([action], self.snapshot, self.policy(action="feed", feed_targets={"2": 1})), []) def test_batch_never_consumes_primary_backup_unmanaged_or_locked_food(self): rows = [self.mon(1, "AAAA", level=29), self.mon(2, "SSSS"), self.mon(3), self.mon(4, lock=1), self.mon(5, species=1002010)] self.snapshot.raw["monsters"] = rows self.planner.managed.update((2, 3, 4)) policy = self.policy(action="feed", feed_targets={"1": 1}) actions = [Action("feed", "candidate", "monsterService/monsterIntensify", {"targetId": 1, "foods": [mid]}) for mid in (1, 2, 3, 4, 5)] self.assertEqual([a.payload for a in self.planner.batch_actions(actions, self.snapshot, policy)], [{"targetId": 1, "foods": [3]}]) def test_normal_experience_cap_still_allows_same_species_tp_on_primary(self): rows = [self.mon(1, "AAAA", level=30, tpLevel=2, tpExp=3), self.mon(2, "SSSS"), self.mon(3)] actions = self.plan(rows, self.policy(action="feed"), managed=(2, 3)) self.assertEqual([a.payload for a in actions if a.kind == "feed"], [{"targetId": 1, "foods": [3]}]) def test_keep_action_cannot_bypass_the_two_species_slots(self): rows = [self.mon(1, level=30), self.mon(2, "SSSS"), self.mon(3, "SSAS"), self.mon(4)] actions = self.plan(rows, self.policy(action="keep", count=1000)) self.assertEqual(self.sold(actions), {3, 4}) self.assertEqual(self.planner.retained, {1, 2}) def test_transient_food_collection_reserves_only_one_species_slot(self): rows = [self.mon(1, "SSAS", level=30)] + [ self.mon(mid, process=2, roomId=None) for mid in (2, 3, 4, 5)] self.snapshot.raw["stacks"] = [{"id": mid, "position": mid - 2, "monsterId": mid} for mid in (2, 3, 4, 5)] actions = self.plan(rows, self.policy(action="feed")) self.assertEqual(self.sold(actions), {3, 4, 5}) self.assertEqual(self.collected(actions), set()) rows = rows[:2] self.snapshot.raw["stacks"] = self.snapshot.raw["stacks"][:1] actions = self.plan(rows, self.policy(action="feed")) self.assertEqual(len(self.collected(actions)), 1) self.assertEqual(self.collected(actions), {2}) self.assertTrue(all(action.kind != "feed" for action in actions)) # A refreshed snapshot sees one transient food, never four admitted at once. rows[1].update(process=3, roomId=1) self.snapshot.raw["stacks"][0]["monsterId"] = 0 actions = self.plan(rows, self.policy(action="feed")) self.assertEqual(self.collected(actions), set()) self.assertTrue(any(action.kind == "feed" and action.payload["targetId"] == 1 for action in actions)) def test_primary_and_backup_block_extra_food_collection(self): rows = [self.mon(1, "AAAA", level=30), self.mon(2, "SSSS"), self.mon(3, process=2, roomId=None)] self.snapshot.raw["stacks"] = [{"id": 1, "position": 0, "monsterId": 3}] actions = self.plan(rows, self.policy(action="feed")) self.assertEqual(self.collected(actions), set()) self.assertEqual(self.sold(actions), {3}) def test_hard_protected_old_backup_blocks_replacement_at_two_ranch_members(self): rows = [self.mon(1, level=30), self.mon(2, "SSAS", lock=1), self.mon(3, "SSSS", process=2, roomId=None)] actions = self.plan(rows, managed=(2, 3)) self.assertEqual(actions, []) self.assertIn("保护", self.planner.statuses[2]) self.assertIn("两只", self.planner.statuses[3]) def test_unknown_primary_quality_pauses_cleanup_until_synchronized(self): rows = [self.mon(1, level=30, gAtk=None), self.mon(2, "SSSS"), self.mon(3, "SSAS")] actions = self.plan(rows, managed=(1, 2, 3)) self.assertFalse(any(a.kind in ("sell", "feed") for a in actions)) self.assertIn("同步", self.planner.statuses[3]) def test_saved_nonranch_primary_is_held_instead_of_promoting_backup(self): primary, backup = self.mon(30, level=30), self.mon(10, "SSSS") self.plan([primary, backup]) primary.update(process=2, mode=1, roomId=None) actions = self.plan([backup, primary], self.policy(action="feed"), managed=(10, 30)) self.assertEqual(self.planner.cultivation.select(self.snapshot), {}) self.assertIs(self.planner.representatives[str(SPECIES)], primary) self.assertIn(30, self.planner.retained) self.assertFalse(any(a.kind in ("feed", "sell", "collect") for a in actions)) self.assertIn("主培养", self.planner.statuses[10]) def test_confirmed_removed_primary_allows_selector_to_choose_new_primary(self): primary, backup = self.mon(30, level=30), self.mon(10, "SSSS") self.plan([primary, backup]) self.assertEqual(self.plan([backup], self.policy(action="feed"), managed=(10,)), []) self.assertIs(self.planner.representatives[str(SPECIES)], backup) self.assertEqual(self.planner.retained, {10}) def test_ordinary_cross_species_feed_farming_and_priorities_still_work(self): first = self.mon(1, "SSSS", level=30, species=1002010) second = self.mon(2, "SSSS", level=20, potentialLevel=3, species=1003010) foods = [self.mon(mid, species=1001010, level=1, exp=0) for mid in (3, 4, 5)] policy = Policy(strategy="experience", protect_star=6, protect_quality=5, fill=False, feed_targets={"1": 1, "2": 2}) actions = self.plan([first, second] + foods, policy, managed=(3, 4, 5)) self.assertEqual([a.payload for a in actions if a.kind == "feed"], [{"targetId": 2, "foods": [3, 4, 5]}]) if __name__ == "__main__": unittest.main()