#!/bin/bash

# Exit on error
set -e

# Change to script directory
cd "$(dirname "$0")"

# Run tests with coverage
pytest tests/ \
    --cov=. \
    --cov-report=xml \
    --cov-report=term \
    -v

# Check test coverage threshold
coverage_threshold=80
current_coverage=$(coverage report | grep TOTAL | awk '{print $4}' | sed 's/%//')

if (( $(echo "$current_coverage < $coverage_threshold" | bc -l) )); then
    echo "Test coverage ($current_coverage%) is below threshold ($coverage_threshold%)"
    exit 1
fi

echo "All tests passed with coverage $current_coverage%" 