Skip to content

Commit

Permalink
add assertion & simple unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
ppwwyyxx committed Dec 11, 2020
1 parent 83d6e03 commit 4f03400
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ jobs:
cd PythonAPI && python setup.py sdist
python -m pip install --progress-bar off dist/*.tar.gz
name: Install From Distribution
- run:
command: |
python tests/test_cases.py
name: Run Simple Test Cases

workflows:
main:
Expand Down
1 change: 1 addition & 0 deletions PythonAPI/pycocotools/_mask.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ def iou( dt, gt, pyiscrowd ):
gt = _preproc(gt)
m = _len(dt)
n = _len(gt)
assert len(pyiscrowd) == n, "iou(iscrowd=) must have the same length as gt"
if m == 0 or n == 0:
return []
if not type(dt) == type(gt):
Expand Down
25 changes: 25 additions & 0 deletions tests/test_cases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import unittest
import numpy as np
import pycocotools.mask as mask_util

def _encode(x):
return mask_util.encode(np.asfortranarray(x, np.uint8))

class TestToBBox(unittest.TestCase):
def testToBboxFullImage(self):
mask = np.array([[0, 1], [1, 1]])
bbox = mask_util.toBbox(_encode(mask))
self.assertTrue(
(bbox == np.array([0, 0, 2, 2], dtype="float32")).all(),
bbox)

def testToBboxNonFullImage(self):
mask = np.zeros((10, 10), dtype=np.uint8)
mask[2:4, 3:6] = 1
bbox = mask_util.toBbox(_encode(mask))
self.assertTrue(
(bbox == np.array([3, 2, 3, 2], dtype="float32")).all(),
bbox)

if __name__ == "__main__":
unittest.main()

0 comments on commit 4f03400

Please sign in to comment.