feat: calculator

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

View File

@ -8,14 +8,14 @@ class Calculator(Blackbox):
"""This class just for example, it show how to implement Blackbox interface.""" """This class just for example, it show how to implement Blackbox interface."""
def valid(self, data: any) -> bool: 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: def processing(self, data: dict) -> any:
if not self.valid(data): if not self.valid(data):
raise ValueError("Invalid data") raise ValueError("Invalid data")
a = data["a"] a = data["left"]
b = data["b"] b = data["right"]
op = data["operation"] op = data["op"]
if op == "add": if op == "add":
return a + b return a + b
if op == "sub": if op == "sub":