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

add test for operators

parent 59da9320
No related branches found
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.
"""
class Operator:
"""
Operator class is a binary operator with a symbol, a precedence and an evaluation function.
"""
def __init__(self, symbol, precedence, evaluate_function):
self.symbol = symbol
self.precedence = precedence
......@@ -16,6 +19,7 @@ class Operator:
def __call__(self, left, right):
return self.evaluate_function(left, right)
STANDARD_OPERATORS = {
'+': Operator('+', 1, lambda a, b: a + b),
'-': Operator('-', 1, lambda a, b: a - b),
......@@ -27,6 +31,6 @@ def test_operator():
"""
Test the Operator class.
"""
operator = Operator('%', 1, lambda a, b: a % b)
assert repr(operator) == '%'
assert operator(15, 4) == 3
modulo = Operator('%', 1, lambda a, b: a % b)
assert repr(modulo) == '%'
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