Answer stability round 1: 0 🔴, 1 🟡 (0 misread); split the re-rank into the pure rank_moves, rank only just before, as the item says, and name ranking in the README and the protocol
This commit is contained in:
+34
-17
@@ -1,12 +1,13 @@
|
||||
import dataclasses
|
||||
import decimal
|
||||
import itertools
|
||||
import pathlib
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from do_epic.ranking import chain, EpicItem, ranked, RepoRanking, reranked
|
||||
from do_epic.ranking import chain, EpicItem, rank_moves, ranked, RepoRanking, reranked
|
||||
from failure import Failure
|
||||
from plan.todo_table import Item, parse_moves
|
||||
from do_epic.backend.fake import MemoryEpic
|
||||
@@ -157,23 +158,23 @@ class RankedTest(unittest.TestCase):
|
||||
|
||||
|
||||
class Recording(MemoryEpic):
|
||||
"""A MemoryEpic that keeps each rank asked of it, and refuses the one to rank the issue named in refused."""
|
||||
"""A MemoryEpic that keeps each rank asked of it, and refuses every rank of the issue named in refused."""
|
||||
refused: str | None = None
|
||||
asked: list[tuple[str, str, bool]]
|
||||
asked: list[tuple[str, str]]
|
||||
|
||||
def rank(self, key: str, other: str, after: bool = False) -> None | Failure:
|
||||
self.asked.append((key, other, after))
|
||||
return Failure("Jira answered 403") if key == self.refused else super().rank(key, other, after)
|
||||
def rank(self, key: str, before: str) -> None | Failure:
|
||||
self.asked.append((key, before))
|
||||
return Failure("Jira answered 403") if key == self.refused else super().rank(key, before)
|
||||
|
||||
|
||||
def epic(*people: int, issues: int = 4) -> Recording:
|
||||
"""An epic of child issues ABC-100 onwards, the loop's apart from those whose places are in people."""
|
||||
"""An epic whose child issues are ABC-100 onwards. The loop filed each of them, except those whose positions, counted from 0, are in people."""
|
||||
store = Recording("ABC-12")
|
||||
store.asked = []
|
||||
for place in range(issues):
|
||||
store.file("ABC-12", f"Item {place}.", "", ())
|
||||
if place in people:
|
||||
store.change(f"ABC-{100 + place}", by_loop=False)
|
||||
for position in range(issues):
|
||||
store.file("ABC-12", f"Item {position}.", "", ())
|
||||
if position in people:
|
||||
store.change(f"ABC-{100 + position}", by_loop=False)
|
||||
return store
|
||||
|
||||
|
||||
@@ -201,8 +202,8 @@ class RerankedTest(unittest.TestCase):
|
||||
|
||||
def test_ranks_only_the_issues_out_of_place(self) -> None:
|
||||
store = epic(issues=5)
|
||||
self.assertEqual(reranked(store, ["ABC-100", "ABC-101", "ABC-102", "ABC-104", "ABC-103"]), None)
|
||||
self.assertEqual(store.asked, [("ABC-103", "ABC-104", True)])
|
||||
self.assertEqual(reranked(store, ["ABC-100", "ABC-102", "ABC-101", "ABC-103", "ABC-104"]), None)
|
||||
self.assertEqual(store.asked, [("ABC-101", "ABC-103")])
|
||||
|
||||
def test_an_issue_the_order_doesnt_name_keeps_its_slot(self) -> None:
|
||||
store = epic()
|
||||
@@ -232,13 +233,13 @@ class RerankedTest(unittest.TestCase):
|
||||
def test_a_rank_the_tracker_refuses_stops_the_walk_and_names_the_order_to_finish_by_hand(self) -> None:
|
||||
store = epic()
|
||||
store.refused = "ABC-101"
|
||||
self.assertEqual(reranked(store, ["ABC-103", "ABC-102", "ABC-101", "ABC-100"]), Failure("cannot rank ABC-101 just before ABC-100: Jira answered 403; the re-rank stopped there, so rank the loop's issues in ABC-12's backlog by hand as ABC-103, ABC-102, ABC-101, ABC-100"))
|
||||
self.assertEqual(store.asked, [("ABC-100", "ABC-103", True), ("ABC-101", "ABC-100", False)])
|
||||
self.assertEqual(reranked(store, ["ABC-103", "ABC-102", "ABC-101", "ABC-100"]), Failure("cannot rank ABC-101 just before ABC-100: Jira answered 403; the re-rank stopped there, so rank the loop's issues in ABC-12's backlog by hand to come in this sequence: ABC-103, ABC-102, ABC-101, ABC-100"))
|
||||
self.assertEqual(store.asked, [("ABC-100", "ABC-103"), ("ABC-101", "ABC-100")])
|
||||
|
||||
def test_a_refused_rank_after_the_last_issue_names_it(self) -> None:
|
||||
def test_a_refused_rank_of_the_issue_due_last_names_it(self) -> None:
|
||||
store = epic()
|
||||
store.refused = "ABC-100"
|
||||
self.assertEqual(reranked(store, ["ABC-103", "ABC-102", "ABC-101", "ABC-100"]), Failure("cannot rank ABC-100 just after ABC-103: Jira answered 403; the re-rank stopped there, so rank the loop's issues in ABC-12's backlog by hand as ABC-103, ABC-102, ABC-101, ABC-100"))
|
||||
self.assertEqual(reranked(store, ["ABC-103", "ABC-102", "ABC-101", "ABC-100"]), Failure("cannot rank ABC-100 just before ABC-103: Jira answered 403; the re-rank stopped there, so rank the loop's issues in ABC-12's backlog by hand to come in this sequence: ABC-103, ABC-102, ABC-101, ABC-100"))
|
||||
|
||||
def test_a_read_that_fails_ranks_nothing(self) -> None:
|
||||
store = epic()
|
||||
@@ -247,5 +248,21 @@ class RerankedTest(unittest.TestCase):
|
||||
self.assertEqual(store.asked, [])
|
||||
|
||||
|
||||
class RankMovesTest(unittest.TestCase):
|
||||
def test_every_backlog_of_up_to_six_issues_reaches_its_target_moving_only_the_listed_keys(self) -> None:
|
||||
for size in range(7):
|
||||
backlog = [f"K-{n}" for n in range(size)]
|
||||
for listed in itertools.chain.from_iterable(itertools.combinations(backlog, count) for count in range(size + 1)):
|
||||
for order in itertools.permutations(listed):
|
||||
sequence = iter(order)
|
||||
target = [next(sequence) if key in listed else key for key in backlog]
|
||||
now = list(backlog)
|
||||
for rank in rank_moves(backlog, list(order)):
|
||||
self.assertIn(rank.key, listed)
|
||||
now.remove(rank.key)
|
||||
now.insert(now.index(rank.before), rank.key)
|
||||
self.assertEqual(now, target, (backlog, order))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user