Coverage for src/fair_python_cookiecutter_demo/lib.py: 100%
19 statements
« prev ^ index » next coverage.py v7.6.0, created at 2024-08-01 13:34 +0000
« prev ^ index » next coverage.py v7.6.0, created at 2024-08-01 13:34 +0000
1"""Core functionality of fair-python-cookiecutter-demo.
3This module can be used directly, or the functionality can be
4exposed using some other interface, such as CLI, GUI or an API.
5"""
7from enum import Enum
10class CalcOperation(str, Enum):
11 """Supported operations of `calculate`."""
13 add = "add"
14 multiply = "multiply"
15 subtract = "subtract"
16 divide = "divide"
17 power = "power"
20def calculate(op: CalcOperation, x: int, y: int):
21 """Calculate result of an operation on two integer numbers."""
22 if not isinstance(op, CalcOperation):
23 raise ValueError(f"Unknown operation: {op}")
25 if op == CalcOperation.add:
26 return x + y
27 elif op == CalcOperation.multiply:
28 return x * y
29 elif op == CalcOperation.subtract:
30 return x - y
31 elif op == CalcOperation.divide:
32 return x // y
34 err = f"Operation {op} is not implemented!"
35 raise NotImplementedError(err)