-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_drawing_error.py
More file actions
34 lines (25 loc) · 1.04 KB
/
test_drawing_error.py
File metadata and controls
34 lines (25 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""Test cases for drawing_error.py functions."""
import numpy as np
import pandas as pd
import pytest
from scipy import integrate
from graphomotor.core import models
from graphomotor.features import drawing_error
def test_calculate_area_under_curve(monkeypatch: pytest.MonkeyPatch) -> None:
"""Test that the area under the curve is calculated correctly."""
x = np.linspace(-np.pi / 2, 6 * np.pi / 4, 100)
y1 = np.sin(x)
y2 = np.sin(x + np.pi)
expected_area, _ = integrate.quad(
lambda x: np.abs(np.sin(x) - np.sin(x + np.pi)), -np.pi / 2, 6 * np.pi / 4
)
class MockSpiral:
def __init__(self, data: pd.DataFrame, metadata: dict) -> None:
self.data = data
self.metadata = metadata
monkeypatch.setattr(models, "Spiral", MockSpiral)
calculated_area = drawing_error.calculate_area_under_curve(
models.Spiral(data=pd.DataFrame({"x": x, "y": y1}), metadata={}),
np.array([x, y2]).T,
)["area_under_curve"]
assert np.isclose(calculated_area, expected_area, rtol=1e-3)