Summary
The ROADMAP.md v0.5 milestone explicitly calls for property-based tests for pure functions. The pulseengine/core/price.py module contains three pure functions (compute_rsi, compute_roc, classify_trend) that are ideal candidates for hypothesis-based property testing.
Current test coverage uses only hand-crafted example inputs. Property-based tests will catch edge cases that example tests miss.
Functions to cover
compute_rsi(series, period)
Properties to verify:
- Output is always in
[0.0, 100.0]
- Returns
50.0 when len(series) < period + 1
- Returns
100.0 when all deltas are positive gains
compute_roc(series, period)
Properties to verify:
- Returns
0.0 when len(series) <= period
- Returns
0.0 when the first value is near zero
- Output is finite or
0.0 for all finite inputs
classify_trend(series)
Properties to verify:
- Always returns one of
{"uptrend", "downtrend", "sideways", "insufficient data"}
- Returns
"insufficient data" when len(series) < 8
- A strictly monotonically increasing series with sufficient data always returns
"uptrend"
Implementation
# tests/test_core.py
from hypothesis import given, strategies as st
import pandas as pd
@given(st.lists(st.floats(min_value=0.01, max_value=1e6, allow_nan=False), min_size=15, max_size=100))
def test_rsi_bounds(values):
series = pd.Series(values)
result = compute_rsi(series, period=14)
assert 0.0 <= result <= 100.0
Requirements
Add hypothesis to requirements-dev.txt.
Summary
The ROADMAP.md v0.5 milestone explicitly calls for property-based tests for pure functions. The
pulseengine/core/price.pymodule contains three pure functions (compute_rsi,compute_roc,classify_trend) that are ideal candidates forhypothesis-based property testing.Current test coverage uses only hand-crafted example inputs. Property-based tests will catch edge cases that example tests miss.
Functions to cover
compute_rsi(series, period)Properties to verify:
[0.0, 100.0]50.0whenlen(series) < period + 1100.0when all deltas are positive gainscompute_roc(series, period)Properties to verify:
0.0whenlen(series) <= period0.0when the first value is near zero0.0for all finite inputsclassify_trend(series)Properties to verify:
{"uptrend", "downtrend", "sideways", "insufficient data"}"insufficient data"whenlen(series) < 8"uptrend"Implementation
Requirements
Add
hypothesistorequirements-dev.txt.