Skip to content

Commit

Permalink
checks-ocr\test(back): #5 add calculate iou unit test
Browse files Browse the repository at this point in the history
- add `calculate_iou` unit test to `test_utils.py`
- add `unit-tests.yml` workflow
  • Loading branch information
este6an13 committed Feb 19, 2024
1 parent de489c9 commit 38d0e46
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Unit Tests

on:
push:
pull_request:

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Run tests with pytest
run: |
pytest test/unit/src
Empty file added test/unit/__init__.py
Empty file.
Empty file added test/unit/src/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions test/unit/src/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from src.utils import calculate_iou

import pytest

@pytest.mark.parametrize(
("box1", "box2", "expected"),
[
((0.1, 0.1, 0.5, 0.5), (0.1, 0.1, 0.5, 0.5), 1.0,),
((0.1, 0.1, 0.0, 0.0), (0.1, 0.1, 0.5, 0.5), 0.0,),
((0.2, 0.2, 0.0, 0.0), (0.2, 0.2, 0.1, 0.0), 1/3,),
],
)
def test_calculate_iou(box1: tuple, box2: tuple, expected: float) -> None:
iou = calculate_iou(box1, box2)
assert iou >= 0 and iou <= 1
assert pytest.approx(iou) == expected

0 comments on commit 38d0e46

Please sign in to comment.