-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_trails_drawing_metrics.py
More file actions
84 lines (60 loc) · 2.95 KB
/
test_trails_drawing_metrics.py
File metadata and controls
84 lines (60 loc) · 2.95 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""Test cases for drawing_metrics.py functions."""
import numpy as np
import pandas as pd
import pytest
from graphomotor.core import models
from graphomotor.features.trails import drawing_metrics
from graphomotor.io import reader
def test_no_pen_lifts() -> None:
"""Test case with no pen lifts."""
df = pd.DataFrame({"line_number": [1, 1, 1, 1]})
drawing = models.Drawing(data=df, task_name="trails", metadata={"id": "5555555"})
result = drawing_metrics.detect_pen_lifts(drawing)
assert result == {"pen_lifts": 0}
def test_valid_pen_lifts() -> None:
"""Test case with valid pen lifts."""
df = pd.DataFrame({"line_number": [1, 2, 3, 4]})
drawing = models.Drawing(data=df, task_name="trails", metadata={"id": "5555555"})
result = drawing_metrics.detect_pen_lifts(drawing)
assert result == {"pen_lifts": 3}
def test_get_total_errors() -> None:
"""Test ValueError when total_number_of_errors column doesn't exist."""
invalid_df = pd.DataFrame({"some_other_column": [0, 1, 2]})
drawing = models.Drawing(
data=invalid_df, task_name="trails", metadata={"id": "5555555"}
)
with pytest.raises(
ValueError,
match="Drawing data does not contain 'total_number_of_errors' column.",
):
drawing_metrics.get_total_errors(drawing)
def test_valid_total_errors() -> None:
"""Test case with valid total_number_of_errors column."""
filepath = "tests/sample_data/[5000000]648b6b868819c1120b4f6ce3-trail4.csv"
drawing = reader.load_drawing_data(filepath)
result = drawing_metrics.get_total_errors(drawing)
assert result == {"total_errors": 1.0}
def test_smoothness_less_than_three_points() -> None:
"""Test smoothness calculation with less than three points."""
points = pd.DataFrame({"x": [0, 1], "y": [0, 1]})
assert drawing_metrics.calculate_smoothness(points) == 0.0
def test_smoothness_straight_line() -> None:
"""Collinear points should produce zero smoothness."""
points = pd.DataFrame({"x": [0, 1, 2, 3], "y": [0, 0, 0, 0]})
assert drawing_metrics.calculate_smoothness(points) == 0.0
def test_smoothness_single_right_angle() -> None:
"""A single 90-degree turn should produce an std of 0."""
points = pd.DataFrame({"x": [0, 1, 1], "y": [0, 0, 1]})
smoothness = drawing_metrics.calculate_smoothness(points)
assert smoothness == 0.0
def test_smoothness_varied_angles() -> None:
"""Test smoothness with two different angles to ensure std is computed correctly."""
points = pd.DataFrame({"x": [0, 1, 1, 2], "y": [0, 0, 1, 2]})
smoothness = drawing_metrics.calculate_smoothness(points)
expected = np.std([90, 45])
assert np.isclose(smoothness, expected)
def test_smoothness_zero_length_segments() -> None:
"""Zero-length segments should be skipped; no angles → smoothness 0."""
points = pd.DataFrame({"x": [0, 1, 1, 2], "y": [0, 0, 0, 0]})
smoothness = drawing_metrics.calculate_smoothness(points)
assert smoothness == 0.0