mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-14 00:53:25 +00:00
feat: calculator
This commit is contained in:
@ -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":
|
||||||
|
|||||||
Reference in New Issue
Block a user