You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
import pytest
|
|
|
|
|
|
|
|
import stuff
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
("n", "expected"),
|
|
|
|
[
|
|
|
|
(0, 0),
|
|
|
|
(1, 1),
|
|
|
|
(5, 2),
|
|
|
|
(4, 2),
|
|
|
|
(8, 2),
|
|
|
|
(9, 3),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_find_sqrt_ish(n: int, expected: int):
|
|
|
|
assert stuff.find_sqrt_ish(n) == expected
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
("n", "expected"),
|
|
|
|
[
|
|
|
|
(3, "III"),
|
|
|
|
(58, "LVIII"),
|
|
|
|
(1994, "MCMXCIV"),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_int_to_roman(n: int, expected: str):
|
|
|
|
assert stuff.Roman.i2r(n) == expected
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
("ops", "expected"),
|
|
|
|
[
|
|
|
|
(
|
|
|
|
(
|
|
|
|
[
|
|
|
|
("new",),
|
|
|
|
("push", -2),
|
|
|
|
("push", 0),
|
|
|
|
("push", -3),
|
|
|
|
("getMin",),
|
|
|
|
("pop",),
|
|
|
|
("top",),
|
|
|
|
("getMin",),
|
|
|
|
]
|
|
|
|
),
|
|
|
|
[
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
-3,
|
|
|
|
None,
|
|
|
|
0,
|
|
|
|
-2,
|
|
|
|
],
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_min_stack(ops: list[tuple[str] | tuple[str, int]], expected: list[int | None]):
|
|
|
|
returned: list[int | None] = []
|
|
|
|
inst: stuff.MinStack | None = None
|
|
|
|
|
|
|
|
for op in ops:
|
|
|
|
if len(op) == 1:
|
|
|
|
if op[0] == "new":
|
|
|
|
inst = stuff.MinStack()
|
|
|
|
returned.append(None)
|
|
|
|
continue
|
|
|
|
|
|
|
|
returned.append(getattr(inst, op[0])())
|
|
|
|
continue
|
|
|
|
|
|
|
|
method, arg = op
|
|
|
|
returned.append(getattr(inst, method)(arg))
|
|
|
|
|
|
|
|
assert returned == expected
|