From 6612c35d4a055625b544d48c09081d080ab976a4 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Thu, 14 Jan 2021 00:16:36 +1100 Subject: [PATCH] Fix bug/typo leading to incorrect --ties prompt behaviour in Python --- pyRCV2/ties.py | 2 +- tests/test_ties.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pyRCV2/ties.py b/pyRCV2/ties.py index fd42690..cfc2f76 100644 --- a/pyRCV2/ties.py +++ b/pyRCV2/ties.py @@ -51,7 +51,7 @@ class TiesPrompt: print() - return l[i - 1] + return l[choice - 1] else: # pragma: no cover if self.buffer is not None: try: diff --git a/tests/test_ties.py b/tests/test_ties.py index 0ab89d0..f627721 100644 --- a/tests/test_ties.py +++ b/tests/test_ties.py @@ -22,13 +22,16 @@ from pyRCV2.ties import TiesBackwards, TiesForwards, TiesPrompt, TiesRandom import tests.util def test_prompt_py(monkeypatch): - monkeypatch.setattr('builtins.input', lambda _: '2') l = [ (Candidate('A'), CountCard()), (Candidate('B'), CountCard()), (Candidate('C'), CountCard()), ] t = TiesPrompt() + monkeypatch.setattr('builtins.input', lambda _: '1') + assert t.choose_lowest(l) == l[0] + assert t.choose_highest(l) == l[0] + monkeypatch.setattr('builtins.input', lambda _: '2') assert t.choose_lowest(l) == l[1] assert t.choose_highest(l) == l[1] @@ -39,6 +42,10 @@ def test_prompt_js(): ctx.eval('let raised = false; try { tie.choose_lowest(l); } catch (ex) { if (py.isinstance(ex, py.pyRCV2.ties.RequireInput)) { raised = true; } }') assert ctx.eval('raised') == True + ctx.eval('tie.buffer = "1";') + assert ctx.eval('tie.choose_lowest(l) === l[0]') + ctx.eval('tie.buffer = "1";') + assert ctx.eval('tie.choose_highest(l) === l[0]') ctx.eval('tie.buffer = "2";') assert ctx.eval('tie.choose_lowest(l) === l[1]') ctx.eval('tie.buffer = "2";')