diff --git a/fifth/fifth.py b/fifth/fifth.py index 6cb7088..46cfd67 100644 --- a/fifth/fifth.py +++ b/fifth/fifth.py @@ -7,6 +7,7 @@ class FifthStack: def __init__(self): self.stack: list[int] = [] self.commands: dict[str, Callable] = { + "help": self.help, "push": self.push, "pop": self.pop, "swap": self.swap, @@ -38,6 +39,10 @@ class FifthStack: print(f"ERROR: division by zero") self.stack.extend([a, b]) + def help(self): + print("Available commands:", ", ".join(cmd.upper() for cmd in self.commands.keys())) + print("Available operations:", ", ".join(self.binary_ops.keys())) + def push(self, value): try: self.stack.append(int(value)) @@ -80,6 +85,7 @@ class FifthStack: def main(): fifth = FifthStack() + fifth.help() while True: print(f"stack is {fifth.stack}") diff --git a/fifth/test_fifth.py b/fifth/test_fifth.py index c70433d..e2a15aa 100644 --- a/fifth/test_fifth.py +++ b/fifth/test_fifth.py @@ -147,7 +147,14 @@ def test_execute_dup_command(): assert stack.stack == [7, 7] -# Test edge cases +# Help and edge cases +def test_help(capsys): + stack = FifthStack() + stack.help() + captured = capsys.readouterr() + assert "Available commands:" in captured.out + assert "Available operations:" in captured.out + def test_execute_empty_command(): stack = FifthStack() stack.execute("") # Should do nothing