Fix bug/typo leading to incorrect --ties prompt behaviour in Python
This commit is contained in:
parent
77c5cfca75
commit
6612c35d4a
@ -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:
|
||||
|
@ -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";')
|
||||
|
Reference in New Issue
Block a user