arcade-mcp/toolkits/math/tests/test_arithmetic.py
Eric Gustin ab889f9f1d
Lint all toolkits (#183)
# PR Description
* Adds/updates the following files to all toolkits:
    - `.pre-commit-config.yaml`
    - `.ruff.toml`
    - `LICENSE`
    - `Makefile`
    - `pyproject.toml`
* Lint all toolkits such that they pass `make check` and `make test` (a
total doozy). This includes adding some unit tests and evals.
* Github workflow for testing toolkits before merge into main (courtesy
of @sdreyer)
* Added a QOL improvement for tool developers for when they need to get
the context's auth token.
* Minor updates to `arcade new` template.
2024-12-20 09:49:45 -08:00

50 lines
893 B
Python

import pytest
from arcade.sdk.errors import ToolExecutionError
from arcade_math.tools.arithmetic import (
add,
divide,
multiply,
sqrt,
subtract,
sum_list,
sum_range,
)
def test_add():
assert add(1, 2) == 3
assert add(-1, 1) == 0
assert add(0.5, 10.9) == 11.4
def test_subtract():
assert subtract(2, 1) == 1
assert subtract(2, 3.5) == -1.5
def test_multiply():
assert multiply(2, 3) == 6
assert multiply(-1, 1.5) == -1.5
def test_divide():
assert divide(6, 3) == 2.0
assert divide(5, 2) == 2.5
with pytest.raises(ToolExecutionError):
divide(1, 0)
def test_sqrt():
assert sqrt(4) == 2.0
assert sqrt(9) == 3.0
def test_sum_list():
assert sum_list([1, 2, 3]) == 6
assert sum_list([0, -1.5, 1]) == -0.5
def test_sum_range():
assert sum_range(1, 3) == 6
assert sum_range(0, 10) == 55