add help command
This commit is contained in:
parent
5349cd2fc9
commit
1146ef44e1
@ -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}")
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user