feat: calculator

This commit is contained in:
Dan Chen
2024-03-18 18:01:22 +08:00
parent 2612d5d370
commit f773627aa4

View File

@ -6,16 +6,16 @@ from blackbox.blackbox import Blackbox
class Calculator(Blackbox):
"""This class just for example, it show how to implement Blackbox interface."""
def valid(self, data: any) -> bool:
return isinstance(data, dict) and "operation" in data and "a" in data and "b" in data
return isinstance(data, dict) and "op" in data and "left" in data and "right" in data
def processing(self, data: dict) -> any:
if not self.valid(data):
raise ValueError("Invalid data")
a = data["a"]
b = data["b"]
op = data["operation"]
a = data["left"]
b = data["right"]
op = data["op"]
if op == "add":
return a + b
if op == "sub":