fix: keep automatic cultivation on one stable primary per species
This commit is contained in:
@@ -55,20 +55,33 @@ class CultivationTests(unittest.TestCase):
|
||||
rows[1]["level"] = 12
|
||||
self.assertEqual(selector.select(self.snapshot)["1001010"]["id"], 2)
|
||||
|
||||
def test_ties_are_chosen_once_persisted_and_do_not_leak_to_other_role(self):
|
||||
def test_ties_preserve_older_ranch_member_across_refresh_restart_and_role_change(self):
|
||||
self.snapshot.raw["monsters"] = [monster(self.catalog, 1), monster(self.catalog, 2)]
|
||||
with workspace_temp() as folder:
|
||||
path = folder / "choices.json"
|
||||
with patch("ranch_assistant.cultivation.random.choice", side_effect=lambda choices: choices[-1]) as draw:
|
||||
selector = CultivationSelector(self.catalog, path)
|
||||
self.assertEqual(selector.select(self.snapshot)["1001010"]["id"], 2)
|
||||
selector.select(self.snapshot)
|
||||
self.assertEqual(draw.call_count, 1)
|
||||
with patch("ranch_assistant.cultivation.random.choice", side_effect=AssertionError("Re-selected an exact tie")):
|
||||
self.assertEqual(CultivationSelector(self.catalog, path).select(self.snapshot)["1001010"]["id"], 2)
|
||||
selector = CultivationSelector(self.catalog, path)
|
||||
self.assertEqual(selector.select(self.snapshot)["1001010"]["id"], 1)
|
||||
self.snapshot.raw["monsters"].reverse()
|
||||
self.assertEqual(selector.select(self.snapshot)["1001010"]["id"], 1)
|
||||
self.assertEqual(CultivationSelector(self.catalog, path).select(self.snapshot)["1001010"]["id"], 1)
|
||||
self.snapshot.raw["master"]["id"] += 1
|
||||
with patch("ranch_assistant.cultivation.random.choice", side_effect=lambda choices: choices[0]):
|
||||
self.assertEqual(CultivationSelector(self.catalog, path).select(self.snapshot)["1001010"]["id"], 1)
|
||||
self.snapshot.raw["monsters"] = [monster(self.catalog, 12), monster(self.catalog, 11)]
|
||||
self.assertEqual(CultivationSelector(self.catalog, path).select(self.snapshot)["1001010"]["id"], 11)
|
||||
|
||||
def test_present_non_ranch_primary_holds_but_confirmed_absence_promotes_once(self):
|
||||
primary, duplicate = monster(self.catalog, 1, level=20), monster(self.catalog, 2, level=10)
|
||||
self.snapshot.raw["monsters"] = [primary, duplicate]
|
||||
with workspace_temp() as folder:
|
||||
path = folder / "choices.json"
|
||||
selector = CultivationSelector(self.catalog, path)
|
||||
self.assertEqual(selector.select(self.snapshot)["1001010"]["id"], 1)
|
||||
primary["process"] = 2
|
||||
self.assertNotIn("1001010", selector.select(self.snapshot))
|
||||
self.assertEqual(selector.choices["1001010"], 1)
|
||||
self.assertNotIn("1001010", CultivationSelector(self.catalog, path).select(self.snapshot))
|
||||
self.snapshot.raw["monsters"].remove(primary)
|
||||
self.assertEqual(selector.select(self.snapshot)["1001010"]["id"], 2)
|
||||
self.assertEqual(CultivationSelector(self.catalog, path).select(self.snapshot)["1001010"]["id"], 2)
|
||||
|
||||
def test_cached_selection_uses_current_cooldown_and_bond_cap(self):
|
||||
self.snapshot.raw["monsters"] = [monster(self.catalog, 1)]
|
||||
@@ -80,17 +93,24 @@ class CultivationTests(unittest.TestCase):
|
||||
self.assertIs(chosen, updated.raw["monsters"][0])
|
||||
self.assertEqual((chosen["giftTime"], chosen["entangleLevel"]), (123456789, 2))
|
||||
|
||||
def test_better_growth_is_kept_independently_of_four_s_and_equal_or_worse_is_not(self):
|
||||
def test_better_backup_is_mandatory_despite_legacy_flags_and_equal_or_worse_is_not(self):
|
||||
representative = monster(self.catalog, 1, level=50, feel=90, scale=.3)
|
||||
hatched = monster(self.catalog, 2, level=1, scale=.4, process=2)
|
||||
self.snapshot.raw["monsters"] = [representative, hatched]
|
||||
planner = Planner(self.catalog)
|
||||
policy = Policy(strategy="gold", protect_star=6, protect_quality=6, keep_better_quality=True)
|
||||
self.assertEqual(planner.disposition(hatched, self.snapshot, policy), "keep")
|
||||
self.assertIn("同种培养代表 #1", planner.protection_reason(hatched, self.snapshot, policy))
|
||||
policy = Policy(manual_eggs=True, protect_star=6, protect_quality=5,
|
||||
gift_auto_representative=False, keep_better_quality=False,
|
||||
egg_rules={"1001010": asdict(EggRule(enabled=True, action="sell", keep_count=1))})
|
||||
for keep_better in (False, True):
|
||||
for keep_count in (0, 1, 4):
|
||||
with self.subTest(keep_better=keep_better, keep_count=keep_count):
|
||||
policy.keep_better_quality = keep_better
|
||||
policy.egg_rules["1001010"]["keep_count"] = keep_count
|
||||
self.assertEqual(planner.disposition(representative, self.snapshot, policy), "keep")
|
||||
self.assertEqual(planner.disposition(hatched, self.snapshot, policy), "keep")
|
||||
self.assertEqual(planner.retained, {1, 2})
|
||||
policy.keep_better_quality = False
|
||||
self.assertEqual(planner.disposition(hatched, self.snapshot, policy), "sell")
|
||||
policy.keep_better_quality = True
|
||||
policy.egg_rules["1001010"]["keep_count"] = 1
|
||||
for scale in (.3, .2):
|
||||
self.snapshot.raw["monsters"][1] = monster(self.catalog, 2, scale=scale, process=2)
|
||||
self.assertEqual(planner.disposition(self.snapshot.monsters[2], self.snapshot, policy), "sell")
|
||||
@@ -146,6 +166,10 @@ class CultivationTests(unittest.TestCase):
|
||||
self.assertAlmostEqual(growth_score(self.catalog, mon), .5, places=3)
|
||||
mon["gHp"] = self.catalog.monster(1001010)["hp_grow_max"]
|
||||
self.assertAlmostEqual(growth_score(self.catalog, mon), .625, places=3)
|
||||
self.assertGreater(quality_rank(self.catalog, graded_monster(self.catalog, 2, "SCCC")),
|
||||
quality_rank(self.catalog, graded_monster(self.catalog, 3, "AAAC")))
|
||||
self.assertGreater(quality_rank(self.catalog, graded_monster(self.catalog, 4, "SSBB")),
|
||||
quality_rank(self.catalog, graded_monster(self.catalog, 5, "SSAC")))
|
||||
|
||||
|
||||
class CultivationGuiTests(unittest.TestCase):
|
||||
|
||||
Reference in New Issue
Block a user