Skip to content
Snippets Groups Projects
Commit 58dc91d0 authored by Florentin Labelle's avatar Florentin Labelle
Browse files

add test for operators

parent 59da9320
Branches
No related tags found
No related merge requests found
__*/
.pytest_cache
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
""" """
Operator module contains the Operator class and a list of standard operators. Operator module contains the Operator class and a list of standard operators.
""" """
class Operator: class Operator:
""" """
Operator class is a binary operator with a symbol, a precedence and an evaluation function. Operator class is a binary operator with a symbol, a precedence and an evaluation function.
""" """
def __init__(self, symbol, precedence, evaluate_function): def __init__(self, symbol, precedence, evaluate_function):
self.symbol = symbol self.symbol = symbol
self.precedence = precedence self.precedence = precedence
...@@ -16,6 +19,7 @@ class Operator: ...@@ -16,6 +19,7 @@ class Operator:
def __call__(self, left, right): def __call__(self, left, right):
return self.evaluate_function(left, right) return self.evaluate_function(left, right)
STANDARD_OPERATORS = { STANDARD_OPERATORS = {
'+': Operator('+', 1, lambda a, b: a + b), '+': Operator('+', 1, lambda a, b: a + b),
'-': Operator('-', 1, lambda a, b: a - b), '-': Operator('-', 1, lambda a, b: a - b),
...@@ -27,6 +31,6 @@ def test_operator(): ...@@ -27,6 +31,6 @@ def test_operator():
""" """
Test the Operator class. Test the Operator class.
""" """
operator = Operator('%', 1, lambda a, b: a % b) modulo = Operator('%', 1, lambda a, b: a % b)
assert repr(operator) == '%' assert repr(modulo) == '%'
assert operator(15, 4) == 3 assert modulo(15, 4) == 3
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment