Skip to content

Commit 839fc13

Browse files
Add CI and first unittest
1 parent 46a05c5 commit 839fc13

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

.github/workflows/test.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: test
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
name: ${{ matrix.os }} ${{ matrix.python-version }}
8+
runs-on: ${{ matrix.os }}
9+
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
os: [ubuntu-latest]
14+
python-version: ["3.10"]
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v2
19+
20+
- name: Setup miniconda
21+
uses: conda-incubator/setup-miniconda@v2
22+
with:
23+
activate-environment: sam
24+
mamba-version: "*"
25+
auto-update-conda: true
26+
environment-file: environment_cpu.yaml
27+
python-version: ${{ matrix.python-version }}
28+
auto-activate-base: false
29+
env:
30+
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
31+
32+
- name: Install package
33+
shell: bash -l {0}
34+
run: pip install --no-deps -e .
35+
36+
- name: Run tests
37+
shell: bash -l {0}
38+
run: python -m unittest discover -s test -v

test/__init__.py

Whitespace-only changes.

test/test_util.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import unittest
2+
3+
import numpy as np
4+
5+
6+
class TestUtil(unittest.TestCase):
7+
def test_compute_iou(self):
8+
from micro_sam.util import compute_iou
9+
10+
x1, x2 = np.zeros((32, 32), dtype="uint32"), np.zeros((32, 32), dtype="uint32")
11+
x1[:16] = 1
12+
x2[16:] = 1
13+
14+
self.assertTrue(np.isclose(compute_iou(x1, x1), 1.0))
15+
self.assertTrue(np.isclose(compute_iou(x1, x2), 0.0))
16+
17+
n_samples = 10
18+
for _ in range(n_samples):
19+
x1, x2 = (np.random.rand(32, 32) > 0.5), (np.random.rand(32, 32) > 0.5)
20+
self.assertTrue(0.0 < compute_iou(x1, x2) < 1.0)
21+
22+
23+
if __name__ == "__main__":
24+
unittest.main()

0 commit comments

Comments
 (0)